From 6d89ee0154edc3a7398df5148cf845603c1462ef Mon Sep 17 00:00:00 2001 From: Cristiano Soleti Date: Mon, 2 Dec 2024 11:35:31 +0100 Subject: [PATCH 1/2] fix: issues with highlight system and todayDate. --- src/bar.js | 4 ++-- src/index.js | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/bar.js b/src/bar.js index f6be436..94f2926 100644 --- a/src/bar.js +++ b/src/bar.js @@ -305,7 +305,7 @@ export default class Bar { (timeout = setTimeout(() => { this.show_popup(e.offsetX || e.layerX); document.getElementById( - `${task_id}-highlight`, + `highlight-${task_id}`, ).style.display = 'block'; }, 200)), ); @@ -313,7 +313,7 @@ export default class Bar { $.on(this.group, 'mouseleave', () => { clearTimeout(timeout); this.gantt.popup?.hide?.(); - document.getElementById(`${task_id}-highlight`).style.display = + document.getElementById(`highlight-${task_id}`).style.display = 'none'; }); } diff --git a/src/index.js b/src/index.js index ae73f7a..7627505 100644 --- a/src/index.js +++ b/src/index.js @@ -689,13 +689,14 @@ export default class Gantt { } /** - * Compute the horizontal x-axis distance and associated date for the current date and view. - * - * @returns Object containing the x-axis distance and date of the current date, or null if the current date is out of the gantt range. - */ + * Compute the horizontal x-axis distance and associated date for the current date and view. + * + * @returns Object containing the x-axis distance and date of the current date, or null if the current date is out of the gantt range. + */ computeGridHighlightDimensions(view_mode) { const todayDate = new Date(); - if (todayDate < this.gantt_start || todayDate > this.gantt_end) return null; + if (todayDate < this.gantt_start || todayDate > this.gantt_end) + return null; let x = this.options.column_width / 2; @@ -703,10 +704,10 @@ export default class Gantt { return { x: x + - (date_utils.diff(today, this.gantt_start, 'hour') / + (date_utils.diff(todayDate, this.gantt_start, 'hour') / this.options.step) * this.options.column_width, - date: today, + date: todayDate, }; } @@ -746,7 +747,9 @@ export default class Gantt { this.view_is(VIEW_MODE.YEAR) ) { // Used as we must find the _end_ of session if view is not Day - const highlightDimensions = this.computeGridHighlightDimensions(this.options.view_mode); + const highlightDimensions = this.computeGridHighlightDimensions( + this.options.view_mode, + ); if (!highlightDimensions) return; const { x: left, date } = highlightDimensions; if (!this.dates.find((d) => d.getTime() == date.getTime())) return; @@ -1147,7 +1150,6 @@ export default class Gantt { } bar_wrapper.classList.add('active'); - if (this.popup) this.popup.parent.classList.add('hidden'); if (this.popup) this.popup.parent.classList.add('hidden'); @@ -1165,7 +1167,7 @@ export default class Gantt { ids = [parent_bar_id]; } bars = ids.map((id) => this.get_bar(id)); - + this.bar_being_dragged = parent_bar_id; bars.forEach((bar) => { From 440d717bc45b48f28ca3854176dadd1e0d9aa28b Mon Sep 17 00:00:00 2001 From: safwansamsudeen Date: Mon, 2 Dec 2024 17:33:36 +0530 Subject: [PATCH 2/2] format --- src/date_utils.js | 3 +-- src/index.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/date_utils.js b/src/date_utils.js index 695f83d..0dc6e36 100644 --- a/src/date_utils.js +++ b/src/date_utils.js @@ -6,7 +6,6 @@ const MINUTE = 'minute'; const SECOND = 'second'; const MILLISECOND = 'millisecond'; - export default { parse_duration(duration) { const regex = /([0-9]+)(y|m|d|h|min|s|ms)/gm; @@ -84,7 +83,7 @@ export default { month: 'long', }); const dateTimeFormatShort = new Intl.DateTimeFormat(lang, { - month: "short", + month: 'short', }); const month_name = dateTimeFormat.format(date); const month_name_capitalized = diff --git a/src/index.js b/src/index.js index 7627505..fc12e72 100644 --- a/src/index.js +++ b/src/index.js @@ -1167,7 +1167,7 @@ export default class Gantt { ids = [parent_bar_id]; } bars = ids.map((id) => this.get_bar(id)); - + this.bar_being_dragged = parent_bar_id; bars.forEach((bar) => {