From a2539b659f87f5bf3a403a9ef6717aa52fc6a0af Mon Sep 17 00:00:00 2001
From: Ziad-I <68874104+Ziad-I@users.noreply.github.com>
Date: Thu, 8 Aug 2024 19:24:44 +0300
Subject: [PATCH] split addGanttElement function into smaller functions
for code organization and readability
---
.../bonsai/bim/data/webui/static/js/gantt.js | 316 +++++++++---------
1 file changed, 163 insertions(+), 153 deletions(-)
diff --git a/src/bonsai/bonsai/bim/data/webui/static/js/gantt.js b/src/bonsai/bonsai/bim/data/webui/static/js/gantt.js
index e4b00c30c0..5481a6d6db 100644
--- a/src/bonsai/bonsai/bim/data/webui/static/js/gantt.js
+++ b/src/bonsai/bonsai/bim/data/webui/static/js/gantt.js
@@ -165,6 +165,162 @@ function handleDefaultData(data) {
// Function to add a new gantt with data and filename
function addGanttElement(blenderId, tasks, workSched, filename) {
+ function createWorkSchedDiv(blenderId, workSched) {
+ const workSchedDiv = $("
").attr("id", "workSched" + blenderId);
+ const scheduleTable = $("")
+ .addClass("no-print table-description")
+ .attr("id", "workSchedTable-" + blenderId)
+ .hide();
+
+ $.each(workSched, (key, value) => {
+ value = value ? value : "null";
+ $("
")
+ .append($(" | ").text(key))
+ .append($(" | ").text(value))
+ .appendTo(scheduleTable);
+ });
+
+ const toggleButton = $("")
+ .text("Show Schedule Info")
+ .addClass("btn no-print")
+ .on("click", function () {
+ scheduleTable.toggle();
+ const buttonText = scheduleTable.is(":visible")
+ ? "Hide Schedule Info"
+ : "Show Schedule Info";
+ toggleButton.text(buttonText);
+ });
+
+ workSchedDiv.append(toggleButton);
+ workSchedDiv.append(scheduleTable);
+
+ return workSchedDiv;
+ }
+
+ function createGanttInfoDiv(blenderId, workSched) {
+ const ganttInfoDiv = $("")
+ .addClass("gantt-info")
+ .attr("id", "gantt-info-" + blenderId);
+
+ const scheduleName = $("").text("Schedule: " + workSched.Name);
+ const createdOn = $("")
+ .text("Created: " + new Date(workSched.CreationDate).toLocaleDateString())
+ .css("float", "right");
+
+ ganttInfoDiv.append(scheduleName);
+ ganttInfoDiv.append(createdOn);
+
+ return ganttInfoDiv;
+ }
+
+ function createGantt(blenderId, tasks) {
+ const ganttDiv = $("")
+ .addClass("gantt-chart")
+ .attr("id", "gantt-" + blenderId);
+
+ let g = new JSGantt.GanttChart(ganttDiv[0], "week");
+ g.setOptions({
+ vCaptionType: "Caption", // Set to Show Caption : None,Caption,Resource,Duration,Complete,
+ vQuarterColWidth: 36,
+ vDateTaskDisplayFormat: "day dd month yyyy", // Shown in tool tip box
+ vDayMajorDateDisplayFormat: "mon yyyy - Week ww", // Set format to dates in the "Major" header of the "Day" view
+ vWeekMinorDateDisplayFormat: "dd mon", // Set format to display dates in the "Minor" header of the "Week" view
+ vLang: "en",
+ vShowTaskInfoLink: 1, // Show link in tool tip (0/1)
+ vShowEndWeekDate: 0, // Show/Hide the date for the last day of the week in header for daily
+ vUseSingleCell: 10000, // Set the threshold cell per table row (Helps performance for large data.
+ vFormatArr: ["Day", "Week", "Month", "Quarter"], // Even with setUseSingleCell using Hour format on such a large chart can cause issues in some browsers,
+ vShowRes: true, // Disable the resource column.
+ vShowComp: false, // Disable the completion column.
+ vShowDur: false, // Disable the duration column, because jsgantt doesn't calculate durations the way we want.
+ vAdditionalHeaders: {
+ ifcduration: { title: "Duration" },
+ resourceUsage: { title: "Resource Usage" },
+ },
+ vUseToolTip: true, // Disable tooltips.
+ vTooltipTemplate: generateTooltip,
+ vTotalHeight: 900,
+
+ vEventsChange: {
+ taskname: editValue, // if you need to use the this scope, do: editValue.bind(this)
+ res: editValue,
+ dur: editValue,
+ comp: editValue,
+ start: editValue,
+ end: editValue,
+ planstart: editValue,
+ planend: editValue,
+ cost: editValue,
+ additional_category: editValue,
+ },
+ });
+
+ JSGantt.addJSONTask(g, tasks);
+ g.setEditable(true);
+ g.Draw();
+
+ connectedClients[blenderId]["gantt"] = g;
+
+ return ganttDiv;
+ }
+
+ function createPrint(blenderId) {
+ const printButton = $("