From 1094e8812add245b622b0b6f91864f60a06e602b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Thu, 19 Dec 2013 11:48:55 +0100
Subject: [PATCH] display gantt by job & by station

---
 dream/platform/static/src/dream_launcher.js | 57 +++++++++++++++++----
 1 file changed, 48 insertions(+), 9 deletions(-)

diff --git a/dream/platform/static/src/dream_launcher.js b/dream/platform/static/src/dream_launcher.js
index 73992ccd..eae041e9 100644
--- a/dream/platform/static/src/dream_launcher.js
+++ b/dream/platform/static/src/dream_launcher.js
@@ -330,6 +330,13 @@
 
               // display demo graph.
               $("#graph_zone").show();
+
+              // temporary hack
+              var now = new Date();
+              now.setHours(0);
+              now.setMinutes(0);
+              now.setSeconds(0);
+
               var blockage_data = [],
                 waiting_data = [],
                 failure_data = [],
@@ -349,16 +356,29 @@
                     "Step No."
                   ]
                 ],
+                start_date = new Date(now.getTime()),
                 gantt_data = {
-                  data: [],
+                  data: [
+                  {
+                    id: "by_job",
+                    text: "By Job",
+                    start_date: start_date,
+                    duration: 0,
+                    project: 1,
+                    open: true
+                  },
+                  {
+                    id: "by_station",
+                    text: "By Station",
+                    start_date: start_date,
+                    duration: 0,
+                    project: 1,
+                    open: true
+                  }
+                  ],
                   link: []
                 };
 
-              // temporary hack
-              var now = new Date();
-              now.setHours(0);
-              now.setMinutes(0);
-              now.setSeconds(0);
 
               $.each(data['success'].elementList, function (idx, obj) {
                 if (obj.results.working_ratio !== undefined) {
@@ -392,14 +412,14 @@
                 if (obj._class === 'Dream.Job') {
                   var property_dict = obj.extraPropertyDict;
                   var duration = 0;
-                  var start_date = new Date(now.getTime());
                   gantt_data.data.push({
                     id: obj['id'],
                     text: property_dict['name'],
                     start_date: start_date,
                     duration: obj['results'].completionTime,
                     project: 1,
-                    open: true
+                    open: false,
+                    parent: "by_job"
                   });
                   $.each(obj['results']['schedule'], function (i, schedule) {
                     spreadsheet_data.push([
@@ -428,7 +448,25 @@
                         duration: duration,
                         parent: obj['id']
                       });
-                    }
+                      gantt_data.data.push({
+                        id: 'job.' + obj['id'] + '.' + schedule['stepNumber'],
+                        text: obj['id'],
+                        start_date: task_start_date,
+                        duration: duration,
+                        parent: schedule['stationId'],
+                        by_station:1,
+                      });
+                    };
+                  });
+                } else {
+                  gantt_data.data.push({
+                    id: obj['id'],
+                    text: obj['id'],
+                    start_date: now,
+                    duration: 0,
+                    project: 1,
+                    open: false,
+                    parent: "by_station"
                   });
                 }
               });
@@ -480,6 +518,7 @@
                 try {
                   gantt.clearAll();
                 } catch (e) {}
+
                 var gantt_output_height = 35 * (gantt_data.data.length + 1) + 1;
                 $('#gantt_output').height(gantt_output_height).show().dhx_gantt({
                   data: gantt_data,
-- 
2.30.9