jquery_gantt_rails 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +74 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/jquery_gantt_rails.iml +9 -0
- data/.idea/misc.xml +22 -0
- data/.idea/modules.xml +9 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.ruby-version.rb +1 -0
- data/Gemfile +3 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/jquery_gantt_rails.gemspec +20 -0
- data/lib/jquery_gantt_rails/version.rb +3 -0
- data/lib/jquery_gantt_rails/version.rb~ +3 -0
- data/lib/jquery_gantt_rails.rb +9 -0
- data/vendor/assets/javascripts/jquery_gantt/README.md +28 -0
- data/vendor/assets/javascripts/jquery_gantt/add.gif +0 -0
- data/vendor/assets/javascripts/jquery_gantt/alert.gif +0 -0
- data/vendor/assets/javascripts/jquery_gantt/closeBig.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/del.gif +0 -0
- data/vendor/assets/javascripts/jquery_gantt/edit.gif +0 -0
- data/vendor/assets/javascripts/jquery_gantt/gantt.css +323 -0
- data/vendor/assets/javascripts/jquery_gantt/gantt.html +547 -0
- data/vendor/assets/javascripts/jquery_gantt/ganttDrawer.js +752 -0
- data/vendor/assets/javascripts/jquery_gantt/ganttGridEditor.js +518 -0
- data/vendor/assets/javascripts/jquery_gantt/ganttMaster.js +702 -0
- data/vendor/assets/javascripts/jquery_gantt/ganttTask.js +947 -0
- data/vendor/assets/javascripts/jquery_gantt/ganttUtilities.js +237 -0
- data/vendor/assets/javascripts/jquery_gantt/gantt_compact.css +323 -0
- data/vendor/assets/javascripts/jquery_gantt/hasExternalDeps.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/JST/jquery.JST.js +167 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/date.js +584 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/dateField/images/next.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/dateField/images/prev.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/dateField/jquery.dateField.css +88 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/dateField/jquery.dateField.js +212 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/i18nJs.js +140 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/jquery.livequery.min.js +11 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/jquery.timers.js +142 -0
- data/vendor/assets/javascripts/jquery_gantt/libs/platform.js +954 -0
- data/vendor/assets/javascripts/jquery_gantt/linkArrow.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/milestone.png +0 -0
- data/vendor/assets/javascripts/jquery_gantt/platform.css +346 -0
- data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.eot +0 -0
- data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.otf +0 -0
- data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.svg +152 -0
- data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.ttf +0 -0
- data/vendor/assets/javascripts/jquery_gantt/teamwork-regular-webfont.woff +0 -0
- data/vendor/assets/javascripts/jquery_gantt/teamworkFont.css +16 -0
- data/vendor/assets/javascripts/jquery_gantt/twGanttSmall.png +0 -0
- metadata +107 -0
@@ -0,0 +1,947 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2012-2013 Open Lab
|
3
|
+
Written by Roberto Bicchierai and Silvia Chelazzi http://roberto.open-lab.com
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
*/
|
23
|
+
|
24
|
+
/**
|
25
|
+
* A method to instantiate valid task models from
|
26
|
+
* raw data.
|
27
|
+
*/
|
28
|
+
function TaskFactory() {
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Build a new Task
|
32
|
+
*/
|
33
|
+
this.build = function(id, name, code, level, start, duration) {
|
34
|
+
// Set at beginning of day
|
35
|
+
var adjusted_start = computeStart(start);
|
36
|
+
var calculated_end = computeEndByDuration(adjusted_start, duration);
|
37
|
+
|
38
|
+
return new Task(id, name, code, level, adjusted_start, calculated_end, duration);
|
39
|
+
};
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
function Task(id, name, code, level, start, end, duration) {
|
44
|
+
this.id = id;
|
45
|
+
this.name = name;
|
46
|
+
this.code = code;
|
47
|
+
this.level = level;
|
48
|
+
this.status = "STATUS_UNDEFINED";
|
49
|
+
|
50
|
+
this.start = start
|
51
|
+
this.duration = duration;
|
52
|
+
this.end = end;
|
53
|
+
|
54
|
+
this.startIsMilestone = false;
|
55
|
+
this.endIsMilestone = false;
|
56
|
+
|
57
|
+
this.collapsed = false;
|
58
|
+
|
59
|
+
this.rowElement; //row editor html element
|
60
|
+
this.ganttElement; //gantt html element
|
61
|
+
this.master;
|
62
|
+
|
63
|
+
this.assigs = [];
|
64
|
+
}
|
65
|
+
|
66
|
+
Task.prototype.clone = function () {
|
67
|
+
var ret = {};
|
68
|
+
for (var key in this) {
|
69
|
+
if (typeof(this[key]) != "function") {
|
70
|
+
ret[key] = this[key];
|
71
|
+
}
|
72
|
+
}
|
73
|
+
return ret;
|
74
|
+
};
|
75
|
+
|
76
|
+
Task.prototype.getAssigsString = function () {
|
77
|
+
var ret = "";
|
78
|
+
for (var i=0;i<this.assigs.length;i++) {
|
79
|
+
var ass = this.assigs[i];
|
80
|
+
var res = this.master.getResource(ass.resourceId);
|
81
|
+
if (res) {
|
82
|
+
ret = ret + (ret == "" ? "" : ", ") + res.name;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
return ret;
|
86
|
+
};
|
87
|
+
|
88
|
+
Task.prototype.createAssignment = function (id, resourceId, roleId, effort) {
|
89
|
+
var assig = new Assignment(id, resourceId, roleId, effort);
|
90
|
+
this.assigs.push(assig);
|
91
|
+
return assig;
|
92
|
+
};
|
93
|
+
|
94
|
+
|
95
|
+
//<%---------- SET PERIOD ---------------------- --%>
|
96
|
+
Task.prototype.setPeriod = function (start, end) {
|
97
|
+
//console.debug("setPeriod ",this.name,new Date(start),new Date(end));
|
98
|
+
//var profilerSetPer = new Profiler("gt_setPeriodJS");
|
99
|
+
|
100
|
+
if (start instanceof Date) {
|
101
|
+
start = start.getTime();
|
102
|
+
}
|
103
|
+
|
104
|
+
if (end instanceof Date) {
|
105
|
+
end = end.getTime();
|
106
|
+
}
|
107
|
+
|
108
|
+
var originalPeriod = {
|
109
|
+
start: this.start,
|
110
|
+
end: this.end,
|
111
|
+
duration: this.duration
|
112
|
+
};
|
113
|
+
|
114
|
+
//console.debug("setStart",date,date instanceof Date);
|
115
|
+
var wantedStartMillis = start;
|
116
|
+
|
117
|
+
//cannot start after end
|
118
|
+
if (start > end) {
|
119
|
+
start = end;
|
120
|
+
}
|
121
|
+
|
122
|
+
//set a legal start
|
123
|
+
start = computeStart(start);
|
124
|
+
|
125
|
+
//if depends -> start is set to max end + lag of superior
|
126
|
+
var sups = this.getSuperiors();
|
127
|
+
if (sups && sups.length > 0) {
|
128
|
+
|
129
|
+
var supEnd = 0;
|
130
|
+
for (var i=0;i<sups.length;i++) {
|
131
|
+
var link = sups[i];
|
132
|
+
supEnd = Math.max(supEnd, incrementDateByWorkingDays(link.from.end, link.lag));
|
133
|
+
}
|
134
|
+
//if changed by depends move it
|
135
|
+
if (computeStart(supEnd) != start) {
|
136
|
+
return this.moveTo(supEnd + 1, false);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
var somethingChanged = false;
|
141
|
+
|
142
|
+
//move date to closest day
|
143
|
+
var date = new Date(start);
|
144
|
+
|
145
|
+
if (this.start != start || this.start != wantedStartMillis) {
|
146
|
+
this.start = start;
|
147
|
+
somethingChanged = true;
|
148
|
+
}
|
149
|
+
|
150
|
+
//set end
|
151
|
+
var wantedEndMillis = end;
|
152
|
+
|
153
|
+
end = computeEnd(end);
|
154
|
+
|
155
|
+
if (this.end != end || this.end != wantedEndMillis) {
|
156
|
+
this.end = end;
|
157
|
+
somethingChanged = true;
|
158
|
+
}
|
159
|
+
|
160
|
+
this.duration = recomputeDuration(this.start, this.end);
|
161
|
+
|
162
|
+
//profilerSetPer.stop();
|
163
|
+
|
164
|
+
//nothing changed exit
|
165
|
+
if (!somethingChanged)
|
166
|
+
return true;
|
167
|
+
|
168
|
+
//external dependencies: exit with error
|
169
|
+
if (this.hasExternalDep) {
|
170
|
+
this.master.setErrorOnTransaction(GanttMaster.messages["TASK_HAS_EXTERNAL_DEPS"] + "\n" + this.name, this);
|
171
|
+
return false;
|
172
|
+
}
|
173
|
+
|
174
|
+
var todoOk = true;
|
175
|
+
|
176
|
+
//I'm restricting
|
177
|
+
var deltaPeriod = originalPeriod.duration - this.duration;
|
178
|
+
var restricting = deltaPeriod > 0;
|
179
|
+
var restrictingStart = restricting && (originalPeriod.start < this.start);
|
180
|
+
var restrictingEnd = restricting && (originalPeriod.end > this.end);
|
181
|
+
|
182
|
+
//console.debug( " originalPeriod.duration "+ originalPeriod.duration +" deltaPeriod "+deltaPeriod+" "+"restricting "+restricting);
|
183
|
+
|
184
|
+
if (restricting) {
|
185
|
+
//loops children to get boundaries
|
186
|
+
var children = this.getChildren();
|
187
|
+
var bs = Infinity;
|
188
|
+
var be = 0;
|
189
|
+
for (var i=0;i<children.length;i++) {
|
190
|
+
|
191
|
+
ch = children[i];
|
192
|
+
//console.debug("restricting: test child "+ch.name+" "+ch.end)
|
193
|
+
if (restrictingEnd) {
|
194
|
+
be = Math.max(be, ch.end);
|
195
|
+
} else {
|
196
|
+
bs = Math.min(bs, ch.start);
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
if (restrictingEnd) {
|
201
|
+
//console.debug("restricting end ",be, this.end);
|
202
|
+
this.end = Math.max(be, this.end);
|
203
|
+
} else {
|
204
|
+
//console.debug("restricting start");
|
205
|
+
this.start = Math.min(bs, this.start);
|
206
|
+
}
|
207
|
+
|
208
|
+
this.duration = recomputeDuration(this.start, this.end);
|
209
|
+
} else {
|
210
|
+
|
211
|
+
//check global boundaries
|
212
|
+
if (this.start < this.master.minEditableDate || this.end > this.master.maxEditableDate) {
|
213
|
+
this.master.setErrorOnTransaction(GanttMaster.messages["CHANGE_OUT_OF_SCOPE"], this);
|
214
|
+
todoOk = false;
|
215
|
+
}
|
216
|
+
|
217
|
+
//console.debug("set period: somethingChanged",this);
|
218
|
+
if (todoOk && !updateTree(this)) {
|
219
|
+
todoOk = false;
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
if (todoOk) {
|
224
|
+
//and now propagate to inferiors
|
225
|
+
var infs = this.getInferiors();
|
226
|
+
if (infs && infs.length > 0) {
|
227
|
+
for (var i=0;i<infs.length;i++) {
|
228
|
+
var link = infs[i];
|
229
|
+
todoOk = link.to.moveTo(end, false); //this is not the right date but moveTo checks start
|
230
|
+
if (!todoOk)
|
231
|
+
break;
|
232
|
+
}
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
return todoOk;
|
237
|
+
};
|
238
|
+
|
239
|
+
|
240
|
+
//<%---------- MOVE TO ---------------------- --%>
|
241
|
+
Task.prototype.moveTo = function (start, ignoreMilestones) {
|
242
|
+
//console.debug("moveTo ",this,start,ignoreMilestones);
|
243
|
+
//var profiler = new Profiler("gt_task_moveTo");
|
244
|
+
|
245
|
+
if (start instanceof Date) {
|
246
|
+
start = start.getTime();
|
247
|
+
}
|
248
|
+
|
249
|
+
var originalPeriod = {
|
250
|
+
start:this.start,
|
251
|
+
end:this.end
|
252
|
+
};
|
253
|
+
|
254
|
+
var wantedStartMillis = start;
|
255
|
+
|
256
|
+
//set a legal start
|
257
|
+
start = computeStart(start);
|
258
|
+
|
259
|
+
//if start is milestone cannot be move
|
260
|
+
if (!ignoreMilestones && this.startIsMilestone && start != this.start) {
|
261
|
+
//notify error
|
262
|
+
this.master.setErrorOnTransaction(GanttMaster.messages["START_IS_MILESTONE"], this);
|
263
|
+
return false;
|
264
|
+
} else if (this.hasExternalDep) {
|
265
|
+
//notify error
|
266
|
+
this.master.setErrorOnTransaction(GanttMaster.messages["TASK_HAS_EXTERNAL_DEPS"], this);
|
267
|
+
return false;
|
268
|
+
}
|
269
|
+
|
270
|
+
//if depends start is set to max end + lag of superior
|
271
|
+
var sups = this.getSuperiors();
|
272
|
+
if (sups && sups.length > 0) {
|
273
|
+
var supEnd = 0;
|
274
|
+
for (var i=0;i<sups.length;i++) {
|
275
|
+
var link = sups[i];
|
276
|
+
supEnd = Math.max(supEnd, incrementDateByWorkingDays(link.from.end, link.lag));
|
277
|
+
}
|
278
|
+
start = supEnd + 1;
|
279
|
+
}
|
280
|
+
//set a legal start
|
281
|
+
start = computeStart(start);
|
282
|
+
|
283
|
+
var end = computeEndByDuration(start, this.duration);
|
284
|
+
|
285
|
+
if (this.start != start || this.start != wantedStartMillis) {
|
286
|
+
//in case of end is milestone it never changes, but recompute duration
|
287
|
+
if (!ignoreMilestones && this.endIsMilestone) {
|
288
|
+
end = this.end;
|
289
|
+
this.duration = recomputeDuration(start, end);
|
290
|
+
}
|
291
|
+
this.start = start;
|
292
|
+
this.end = end;
|
293
|
+
//profiler.stop();
|
294
|
+
|
295
|
+
//check global boundaries
|
296
|
+
if (this.start < this.master.minEditableDate || this.end > this.master.maxEditableDate) {
|
297
|
+
this.master.setErrorOnTransaction(GanttMaster.messages["CHANGE_OUT_OF_SCOPE"], this);
|
298
|
+
return false;
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
var panDelta = originalPeriod.start - this.start;
|
303
|
+
//console.debug("panDelta",panDelta);
|
304
|
+
//loops children to shift them
|
305
|
+
var children = this.getChildren();
|
306
|
+
for (var i=0;i<children.length;i++) {
|
307
|
+
ch = children[i];
|
308
|
+
if (!ch.moveTo(ch.start - panDelta, false)) {
|
309
|
+
return false;
|
310
|
+
}
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
//console.debug("set period: somethingChanged",this);
|
315
|
+
if (!updateTree(this)) {
|
316
|
+
return false;
|
317
|
+
}
|
318
|
+
|
319
|
+
|
320
|
+
//and now propagate to inferiors
|
321
|
+
var infs = this.getInferiors();
|
322
|
+
if (infs && infs.length > 0) {
|
323
|
+
for (var i=0;i<infs.length;i++) {
|
324
|
+
var link = infs[i];
|
325
|
+
|
326
|
+
//this is not the right date but moveTo checks start
|
327
|
+
if (!link.to.moveTo(end, false)) {
|
328
|
+
return false;
|
329
|
+
}
|
330
|
+
}
|
331
|
+
}
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
return true;
|
336
|
+
};
|
337
|
+
|
338
|
+
|
339
|
+
function updateTree(task) {
|
340
|
+
//console.debug("updateTree ",task);
|
341
|
+
var error;
|
342
|
+
|
343
|
+
//try to enlarge parent
|
344
|
+
var p = task.getParent();
|
345
|
+
|
346
|
+
//no parent:exit
|
347
|
+
if (!p)
|
348
|
+
return true;
|
349
|
+
|
350
|
+
|
351
|
+
var newStart = p.start;
|
352
|
+
var newEnd = p.end;
|
353
|
+
|
354
|
+
if (p.start > task.start) {
|
355
|
+
if (p.startIsMilestone) {
|
356
|
+
task.master.setErrorOnTransaction(GanttMaster.messages["START_IS_MILESTONE"] + "\n" + p.name, task);
|
357
|
+
return false;
|
358
|
+
} else if (p.depends) {
|
359
|
+
task.master.setErrorOnTransaction(GanttMaster.messages["TASK_HAS_CONSTRAINTS"] + "\n" + p.name, task);
|
360
|
+
return false;
|
361
|
+
}
|
362
|
+
|
363
|
+
newStart = task.start;
|
364
|
+
}
|
365
|
+
|
366
|
+
if (p.end < task.end) {
|
367
|
+
if (p.endIsMilestone) {
|
368
|
+
task.master.setErrorOnTransaction(GanttMaster.messages["END_IS_MILESTONE"] + "\n" + p.name, task);
|
369
|
+
return false;
|
370
|
+
}
|
371
|
+
|
372
|
+
newEnd = task.end;
|
373
|
+
}
|
374
|
+
|
375
|
+
//propagate updates if needed
|
376
|
+
if (newStart != p.start || newEnd != p.end) {
|
377
|
+
//has external deps ?
|
378
|
+
if (p.hasExternalDep) {
|
379
|
+
task.master.setErrorOnTransaction(GanttMaster.messages["TASK_HAS_EXTERNAL_DEPS"] + "\n" + p.name, task);
|
380
|
+
return false;
|
381
|
+
}
|
382
|
+
|
383
|
+
return p.setPeriod(newStart, newEnd);
|
384
|
+
}
|
385
|
+
|
386
|
+
|
387
|
+
return true;
|
388
|
+
}
|
389
|
+
|
390
|
+
//<%---------- CHANGE STATUS ---------------------- --%>
|
391
|
+
Task.prototype.changeStatus = function(newStatus) {
|
392
|
+
//console.debug("changeStatus: "+this.name+" from "+this.status+" -> "+newStatus);
|
393
|
+
//compute descendant for identify a cone where status changes propagate
|
394
|
+
var cone = this.getDescendant();
|
395
|
+
|
396
|
+
function propagateStatus(task, newStatus, manuallyChanged, propagateFromParent, propagateFromChildren) {
|
397
|
+
var oldStatus = task.status;
|
398
|
+
|
399
|
+
//no changes exit
|
400
|
+
if(newStatus == oldStatus){
|
401
|
+
return true;
|
402
|
+
}
|
403
|
+
//console.debug("propagateStatus: "+task.name + " from " + task.status + " to " + newStatus + " " + (manuallyChanged?" a manella":"")+(propagateFromParent?" da parent":"")+(propagateFromChildren?" da children":""));
|
404
|
+
|
405
|
+
var todoOk = true;
|
406
|
+
task.status = newStatus;
|
407
|
+
|
408
|
+
//xxxx -> STATUS_DONE may activate dependent tasks, both suspended and undefined. Will set to done all descendants.
|
409
|
+
//STATUS_FAILED -> STATUS_DONE do nothing if not forced by hand
|
410
|
+
if (newStatus == "STATUS_DONE") {
|
411
|
+
|
412
|
+
if ((manuallyChanged || oldStatus != "STATUS_FAILED")) { //cannot change for cascade when failed
|
413
|
+
|
414
|
+
//can be closed only if superiors are already done
|
415
|
+
var sups = task.getSuperiors();
|
416
|
+
for (var i=0;i<sups.length;i++) {
|
417
|
+
if (cone.indexOf(sups[i].from) < 0) {
|
418
|
+
if (sups[i].from.status != "STATUS_DONE") {
|
419
|
+
if (manuallyChanged || propagateFromParent)
|
420
|
+
task.master.setErrorOnTransaction(GanttMaster.messages["GANTT_ERROR_DEPENDS_ON_OPEN_TASK"] + "\n" + sups[i].from.name + " -> " + task.name);
|
421
|
+
todoOk = false;
|
422
|
+
break;
|
423
|
+
}
|
424
|
+
}
|
425
|
+
}
|
426
|
+
|
427
|
+
if (todoOk) {
|
428
|
+
//todo set progress to 100% if set on config
|
429
|
+
|
430
|
+
var chds = task.getChildren();
|
431
|
+
//set children as done
|
432
|
+
for (var i=0;i<chds.length;i++)
|
433
|
+
propagateStatus(chds[i], "STATUS_DONE", false,true,false);
|
434
|
+
|
435
|
+
//set inferiors as active if outside the cone
|
436
|
+
propagateToInferiors(cone, task.getInferiors(), "STATUS_ACTIVE");
|
437
|
+
}
|
438
|
+
} else {
|
439
|
+
todoOk = false;
|
440
|
+
}
|
441
|
+
|
442
|
+
|
443
|
+
// STATUS_UNDEFINED -> STATUS_ACTIVE all children become active, if they have no dependencies.
|
444
|
+
// STATUS_SUSPENDED -> STATUS_ACTIVE sets to active all children and their descendants that have no inhibiting dependencies.
|
445
|
+
// STATUS_DONE -> STATUS_ACTIVE all those that have dependencies must be set to suspended.
|
446
|
+
// STATUS_FAILED -> STATUS_ACTIVE nothing happens: child statuses must be reset by hand.
|
447
|
+
} else if (newStatus == "STATUS_ACTIVE") {
|
448
|
+
|
449
|
+
if ((manuallyChanged || oldStatus != "STATUS_FAILED")) { //cannot change for cascade when failed
|
450
|
+
|
451
|
+
//activate parent if closed
|
452
|
+
var par=task.getParent();
|
453
|
+
if (par && par.status != "STATUS_ACTIVE") {
|
454
|
+
todoOk=propagateStatus(par,"STATUS_ACTIVE",false,false,true);
|
455
|
+
}
|
456
|
+
|
457
|
+
if(todoOk){
|
458
|
+
//can be active only if superiors are already done
|
459
|
+
var sups = task.getSuperiors();
|
460
|
+
for (var i=0;i<sups.length;i++) {
|
461
|
+
if (sups[i].from.status != "STATUS_DONE") {
|
462
|
+
if (manuallyChanged || propagateFromChildren)
|
463
|
+
task.master.setErrorOnTransaction(GanttMaster.messages["GANTT_ERROR_DEPENDS_ON_OPEN_TASK"] + "\n" + sups[i].from.name + " -> " + task.name);
|
464
|
+
todoOk = false;
|
465
|
+
break;
|
466
|
+
}
|
467
|
+
}
|
468
|
+
}
|
469
|
+
|
470
|
+
if (todoOk) {
|
471
|
+
var chds = task.getChildren();
|
472
|
+
if (oldStatus == "STATUS_UNDEFINED" || oldStatus == "STATUS_SUSPENDED") {
|
473
|
+
//set children as active
|
474
|
+
for (var i=0;i<chds.length;i++)
|
475
|
+
if (chds[i].status != "STATUS_DONE" )
|
476
|
+
propagateStatus(chds[i], "STATUS_ACTIVE", false,true,false);
|
477
|
+
}
|
478
|
+
|
479
|
+
//set inferiors as suspended
|
480
|
+
var infs = task.getInferiors();
|
481
|
+
for (var i=0;i<infs.length;i++)
|
482
|
+
propagateStatus(infs[i].to, "STATUS_SUSPENDED", false,false,false);
|
483
|
+
}
|
484
|
+
} else {
|
485
|
+
todoOk = false;
|
486
|
+
}
|
487
|
+
|
488
|
+
// xxxx -> STATUS_SUSPENDED all active children and their active descendants become suspended. when not failed or forced
|
489
|
+
// xxxx -> STATUS_UNDEFINED all active children and their active descendants become suspended. when not failed or forced
|
490
|
+
} else if (newStatus == "STATUS_SUSPENDED" || newStatus == "STATUS_UNDEFINED") {
|
491
|
+
if (manuallyChanged || oldStatus != "STATUS_FAILED") { //cannot change for cascade when failed
|
492
|
+
|
493
|
+
//suspend parent if not active
|
494
|
+
var par=task.getParent();
|
495
|
+
if (par && par.status != "STATUS_ACTIVE") {
|
496
|
+
todoOk=propagateStatus(par,newStatus,false,false,true);
|
497
|
+
}
|
498
|
+
|
499
|
+
|
500
|
+
var chds = task.getChildren();
|
501
|
+
//set children as active
|
502
|
+
for (var i=0;i<chds.length;i++){
|
503
|
+
if (chds[i].status != "STATUS_DONE")
|
504
|
+
propagateStatus(chds[i], newStatus, false,true,false);
|
505
|
+
}
|
506
|
+
|
507
|
+
//set inferiors as STATUS_SUSPENDED or STATUS_UNDEFINED
|
508
|
+
propagateToInferiors(cone, task.getInferiors(), newStatus);
|
509
|
+
} else {
|
510
|
+
todoOk = false;
|
511
|
+
}
|
512
|
+
|
513
|
+
// xxxx -> STATUS_FAILED children and dependent failed
|
514
|
+
} else if (newStatus == "STATUS_FAILED") {
|
515
|
+
var chds = task.getChildren();
|
516
|
+
//set children as failed
|
517
|
+
for (var i=0;i<chds.length;i++)
|
518
|
+
propagateStatus(chds[i], "STATUS_FAILED", false,true,false);
|
519
|
+
|
520
|
+
//set inferiors as active
|
521
|
+
//set children as done
|
522
|
+
propagateToInferiors(cone, task.getInferiors(), "STATUS_FAILED");
|
523
|
+
}
|
524
|
+
if (!todoOk){
|
525
|
+
task.status = oldStatus;
|
526
|
+
//console.debug("status rolled back: "+task.name + " to " + oldStatus);
|
527
|
+
}
|
528
|
+
|
529
|
+
return todoOk;
|
530
|
+
}
|
531
|
+
|
532
|
+
/**
|
533
|
+
* A helper method to traverse an array of 'inferior' tasks
|
534
|
+
* and signal a status change.
|
535
|
+
*/
|
536
|
+
function propagateToInferiors(cone, infs, status) {
|
537
|
+
for (var i=0;i<infs.length;i++) {
|
538
|
+
if (cone.indexOf(infs[i].to) < 0) {
|
539
|
+
propagateStatus(infs[i].to, status, false, false, false);
|
540
|
+
}
|
541
|
+
}
|
542
|
+
}
|
543
|
+
|
544
|
+
var todoOk = true;
|
545
|
+
var oldStatus = this.status;
|
546
|
+
|
547
|
+
todoOk = propagateStatus(this, newStatus, true,false,false);
|
548
|
+
|
549
|
+
if (!todoOk)
|
550
|
+
this.status = oldStatus;
|
551
|
+
|
552
|
+
return todoOk;
|
553
|
+
};
|
554
|
+
|
555
|
+
Task.prototype.synchronizeStatus=function(){
|
556
|
+
var oldS=this.status;
|
557
|
+
this.status="";
|
558
|
+
return this.changeStatus(oldS);
|
559
|
+
};
|
560
|
+
|
561
|
+
Task.prototype.isLocallyBlockedByDependencies=function(){
|
562
|
+
var sups = this.getSuperiors();
|
563
|
+
var blocked=false;
|
564
|
+
for (var i=0;i<sups.length;i++) {
|
565
|
+
if (sups[i].from.status != "STATUS_DONE") {
|
566
|
+
blocked=true;
|
567
|
+
break;
|
568
|
+
}
|
569
|
+
}
|
570
|
+
return blocked;
|
571
|
+
};
|
572
|
+
|
573
|
+
//<%---------- TASK STRUCTURE ---------------------- --%>
|
574
|
+
Task.prototype.getRow = function() {
|
575
|
+
ret = -1;
|
576
|
+
if (this.master)
|
577
|
+
ret = this.master.tasks.indexOf(this);
|
578
|
+
return ret;
|
579
|
+
};
|
580
|
+
|
581
|
+
|
582
|
+
Task.prototype.getParents = function() {
|
583
|
+
var ret;
|
584
|
+
if (this.master) {
|
585
|
+
var topLevel = this.level;
|
586
|
+
var pos = this.getRow();
|
587
|
+
ret = [];
|
588
|
+
for (var i = pos; i >= 0; i--) {
|
589
|
+
var par = this.master.tasks[i];
|
590
|
+
if (topLevel > par.level) {
|
591
|
+
topLevel = par.level;
|
592
|
+
ret.push(par);
|
593
|
+
}
|
594
|
+
}
|
595
|
+
}
|
596
|
+
return ret;
|
597
|
+
};
|
598
|
+
|
599
|
+
|
600
|
+
Task.prototype.getParent = function() {
|
601
|
+
var ret;
|
602
|
+
if (this.master) {
|
603
|
+
for (var i = this.getRow(); i >= 0; i--) {
|
604
|
+
var par = this.master.tasks[i];
|
605
|
+
if (this.level > par.level) {
|
606
|
+
ret = par;
|
607
|
+
break;
|
608
|
+
}
|
609
|
+
}
|
610
|
+
}
|
611
|
+
return ret;
|
612
|
+
};
|
613
|
+
|
614
|
+
|
615
|
+
Task.prototype.isParent = function() {
|
616
|
+
var ret = false;
|
617
|
+
if (this.master) {
|
618
|
+
var pos = this.getRow();
|
619
|
+
if (pos < this.master.tasks.length - 1)
|
620
|
+
ret = this.master.tasks[pos + 1].level > this.level;
|
621
|
+
}
|
622
|
+
return ret;
|
623
|
+
};
|
624
|
+
|
625
|
+
|
626
|
+
Task.prototype.getChildren = function() {
|
627
|
+
var ret = [];
|
628
|
+
if (this.master) {
|
629
|
+
var pos = this.getRow();
|
630
|
+
for (var i = pos + 1; i < this.master.tasks.length; i++) {
|
631
|
+
var ch = this.master.tasks[i];
|
632
|
+
if (ch.level == this.level + 1)
|
633
|
+
ret.push(ch);
|
634
|
+
else if (ch.level <= this.level) // exit loop if parent or brother
|
635
|
+
break;
|
636
|
+
}
|
637
|
+
}
|
638
|
+
return ret;
|
639
|
+
};
|
640
|
+
|
641
|
+
|
642
|
+
Task.prototype.getDescendant = function() {
|
643
|
+
var ret = [];
|
644
|
+
if (this.master) {
|
645
|
+
var pos = this.getRow();
|
646
|
+
for (var i = pos + 1; i < this.master.tasks.length; i++) {
|
647
|
+
var ch = this.master.tasks[i];
|
648
|
+
if (ch.level > this.level)
|
649
|
+
ret.push(ch);
|
650
|
+
else
|
651
|
+
break;
|
652
|
+
}
|
653
|
+
}
|
654
|
+
return ret;
|
655
|
+
};
|
656
|
+
|
657
|
+
|
658
|
+
Task.prototype.getSuperiors = function() {
|
659
|
+
var ret = [];
|
660
|
+
var task = this;
|
661
|
+
if (this.master) {
|
662
|
+
ret = this.master.links.filter(function(link) {
|
663
|
+
return link.to == task;
|
664
|
+
});
|
665
|
+
}
|
666
|
+
return ret;
|
667
|
+
};
|
668
|
+
|
669
|
+
|
670
|
+
Task.prototype.getInferiors = function() {
|
671
|
+
var ret = [];
|
672
|
+
var task = this;
|
673
|
+
if (this.master) {
|
674
|
+
ret = this.master.links.filter(function(link) {
|
675
|
+
return link.from == task;
|
676
|
+
});
|
677
|
+
}
|
678
|
+
return ret;
|
679
|
+
};
|
680
|
+
|
681
|
+
|
682
|
+
Task.prototype.deleteTask = function() {
|
683
|
+
//delete both dom elements
|
684
|
+
this.rowElement.remove();
|
685
|
+
this.ganttElement.remove();
|
686
|
+
|
687
|
+
//remove children
|
688
|
+
var chd = this.getChildren();
|
689
|
+
for (var i=0;i<chd.length;i++) {
|
690
|
+
//add removed child in list
|
691
|
+
if(!chd[i].isNew())
|
692
|
+
this.master.deletedTaskIds.push(chd[i].id);
|
693
|
+
chd[i].deleteTask();
|
694
|
+
}
|
695
|
+
|
696
|
+
if(!this.isNew())
|
697
|
+
this.master.deletedTaskIds.push(this.id);
|
698
|
+
|
699
|
+
|
700
|
+
//remove from in-memory collection
|
701
|
+
this.master.tasks.splice(this.getRow(), 1);
|
702
|
+
|
703
|
+
//remove from links
|
704
|
+
var task = this;
|
705
|
+
this.master.links = this.master.links.filter(function(link) {
|
706
|
+
return link.from != task && link.to != task;
|
707
|
+
});
|
708
|
+
};
|
709
|
+
|
710
|
+
|
711
|
+
Task.prototype.isNew=function(){
|
712
|
+
return (this.id+"").indexOf("tmp_")==0;
|
713
|
+
};
|
714
|
+
|
715
|
+
//<%------------------------------------------ INDENT/OUTDENT --------------------------------%>
|
716
|
+
Task.prototype.indent = function() {
|
717
|
+
//console.debug("indent", this);
|
718
|
+
//a row above must exist
|
719
|
+
var row = this.getRow();
|
720
|
+
|
721
|
+
//no row no party
|
722
|
+
if (row <=0)
|
723
|
+
return false;
|
724
|
+
|
725
|
+
var ret = false;
|
726
|
+
var taskAbove = this.master.tasks[row - 1];
|
727
|
+
var newLev = this.level + 1;
|
728
|
+
if (newLev <= taskAbove.level + 1) {
|
729
|
+
ret = true;
|
730
|
+
//trick to get parents after indent
|
731
|
+
this.level++;
|
732
|
+
var futureParents = this.getParents();
|
733
|
+
this.level--;
|
734
|
+
var oldLevel = this.level;
|
735
|
+
for (var i = row; i < this.master.tasks.length; i++) {
|
736
|
+
var desc = this.master.tasks[i];
|
737
|
+
if (desc.level > oldLevel || desc == this) {
|
738
|
+
desc.level++;
|
739
|
+
//remove links from descendant to my parents
|
740
|
+
this.master.links = this.master.links.filter(function(link) {
|
741
|
+
var linkToParent = false;
|
742
|
+
if (link.to == desc)
|
743
|
+
linkToParent = futureParents.indexOf(link.from) >= 0;
|
744
|
+
else if (link.from == desc)
|
745
|
+
linkToParent = futureParents.indexOf(link.to) >= 0;
|
746
|
+
return !linkToParent;
|
747
|
+
});
|
748
|
+
} else
|
749
|
+
break;
|
750
|
+
}
|
751
|
+
//recompute depends string
|
752
|
+
this.master.updateDependsStrings();
|
753
|
+
//enlarge parent using a fake set period
|
754
|
+
this.setPeriod(this.start + 1, this.end + 1);
|
755
|
+
|
756
|
+
//force status check
|
757
|
+
this.synchronizeStatus();
|
758
|
+
}
|
759
|
+
return ret;
|
760
|
+
};
|
761
|
+
|
762
|
+
|
763
|
+
Task.prototype.outdent = function() {
|
764
|
+
//console.debug("outdent", this);
|
765
|
+
|
766
|
+
//a level must be >1 -> cannot escape from root
|
767
|
+
if (this.level <= 1)
|
768
|
+
return false;
|
769
|
+
|
770
|
+
var ret = false;
|
771
|
+
var oldLevel = this.level;
|
772
|
+
|
773
|
+
ret = true;
|
774
|
+
var row = this.getRow();
|
775
|
+
for (var i = row; i < this.master.tasks.length; i++) {
|
776
|
+
var desc = this.master.tasks[i];
|
777
|
+
if (desc.level > oldLevel || desc == this) {
|
778
|
+
desc.level--;
|
779
|
+
} else
|
780
|
+
break;
|
781
|
+
}
|
782
|
+
|
783
|
+
var task = this;
|
784
|
+
var chds = this.getChildren();
|
785
|
+
//remove links from me to my new children
|
786
|
+
this.master.links = this.master.links.filter(function(link) {
|
787
|
+
var linkExist = (link.to == task && chds.indexOf(link.from) >= 0 || link.from == task && chds.indexOf(link.to) >= 0);
|
788
|
+
return !linkExist;
|
789
|
+
});
|
790
|
+
|
791
|
+
|
792
|
+
//enlarge me if inherited children are larger
|
793
|
+
for (var i=0;i<chds.length;i++) {
|
794
|
+
//remove links from me to my new children
|
795
|
+
chds[i].setPeriod(chds[i].start + 1, chds[i].end + 1);
|
796
|
+
}
|
797
|
+
|
798
|
+
//enlarge parent using a fake set period
|
799
|
+
this.setPeriod(this.start + 1, this.end + 1);
|
800
|
+
|
801
|
+
//force status check
|
802
|
+
this.synchronizeStatus();
|
803
|
+
return ret;
|
804
|
+
};
|
805
|
+
|
806
|
+
|
807
|
+
//<%------------------------------------------ MOVE UP / MOVE DOWN --------------------------------%>
|
808
|
+
Task.prototype.moveUp = function() {
|
809
|
+
//console.debug("moveUp", this);
|
810
|
+
var ret = false;
|
811
|
+
|
812
|
+
//a row above must exist
|
813
|
+
var row = this.getRow();
|
814
|
+
|
815
|
+
//no row no party
|
816
|
+
if (row <=0)
|
817
|
+
return false;
|
818
|
+
|
819
|
+
//find new row
|
820
|
+
var newRow;
|
821
|
+
for (newRow = row - 1; newRow >= 0; newRow--) {
|
822
|
+
if (this.master.tasks[newRow].level <= this.level)
|
823
|
+
break;
|
824
|
+
}
|
825
|
+
|
826
|
+
//is a parent or a brother
|
827
|
+
if (this.master.tasks[newRow].level == this.level) {
|
828
|
+
ret = true;
|
829
|
+
//compute descendant
|
830
|
+
var descNumber = 0;
|
831
|
+
for (var i = row + 1; i < this.master.tasks.length; i++) {
|
832
|
+
var desc = this.master.tasks[i];
|
833
|
+
if (desc.level > this.level) {
|
834
|
+
descNumber++;
|
835
|
+
} else {
|
836
|
+
break;
|
837
|
+
}
|
838
|
+
}
|
839
|
+
//move in memory
|
840
|
+
var blockToMove = this.master.tasks.splice(row, descNumber + 1);
|
841
|
+
var top = this.master.tasks.splice(0, newRow);
|
842
|
+
this.master.tasks = [].concat(top, blockToMove, this.master.tasks);
|
843
|
+
//move on dom
|
844
|
+
var rows = this.master.editor.element.find("tr[taskId]");
|
845
|
+
var domBlockToMove = rows.slice(row, row + descNumber + 1);
|
846
|
+
rows.eq(newRow).before(domBlockToMove);
|
847
|
+
|
848
|
+
//recompute depends string
|
849
|
+
this.master.updateDependsStrings();
|
850
|
+
} else {
|
851
|
+
this.master.setErrorOnTransaction(GanttMaster.messages["TASK_MOVE_INCONSISTENT_LEVEL"], this);
|
852
|
+
ret = false;
|
853
|
+
}
|
854
|
+
return ret;
|
855
|
+
};
|
856
|
+
|
857
|
+
|
858
|
+
Task.prototype.moveDown = function() {
|
859
|
+
//console.debug("moveDown", this);
|
860
|
+
|
861
|
+
//a row below must exist, and cannot move root task
|
862
|
+
var row = this.getRow();
|
863
|
+
if (row >= this.master.tasks.length - 1 || row==0)
|
864
|
+
return false;
|
865
|
+
|
866
|
+
var ret = false;
|
867
|
+
|
868
|
+
//find nearest brother
|
869
|
+
var newRow;
|
870
|
+
for (newRow = row + 1; newRow < this.master.tasks.length; newRow++) {
|
871
|
+
if (this.master.tasks[newRow].level <= this.level)
|
872
|
+
break;
|
873
|
+
}
|
874
|
+
|
875
|
+
//is brother
|
876
|
+
if (this.master.tasks[newRow].level == this.level) {
|
877
|
+
ret = true;
|
878
|
+
//find last desc
|
879
|
+
for (newRow = newRow + 1; newRow < this.master.tasks.length; newRow++) {
|
880
|
+
if (this.master.tasks[newRow].level <= this.level)
|
881
|
+
break;
|
882
|
+
}
|
883
|
+
|
884
|
+
//compute descendant
|
885
|
+
var descNumber = 0;
|
886
|
+
for (var i = row + 1; i < this.master.tasks.length; i++) {
|
887
|
+
var desc = this.master.tasks[i];
|
888
|
+
if (desc.level > this.level) {
|
889
|
+
descNumber++;
|
890
|
+
} else {
|
891
|
+
break;
|
892
|
+
}
|
893
|
+
}
|
894
|
+
|
895
|
+
//move in memory
|
896
|
+
var blockToMove = this.master.tasks.splice(row, descNumber + 1);
|
897
|
+
var top = this.master.tasks.splice(0, newRow - descNumber - 1);
|
898
|
+
this.master.tasks = [].concat(top, blockToMove, this.master.tasks);
|
899
|
+
|
900
|
+
|
901
|
+
//move on dom
|
902
|
+
var rows = this.master.editor.element.find("tr[taskId]");
|
903
|
+
var aft = rows.eq(newRow - 1);
|
904
|
+
var domBlockToMove = rows.slice(row, row + descNumber + 1);
|
905
|
+
aft.after(domBlockToMove);
|
906
|
+
|
907
|
+
//recompute depends string
|
908
|
+
this.master.updateDependsStrings();
|
909
|
+
}
|
910
|
+
|
911
|
+
return ret;
|
912
|
+
};
|
913
|
+
|
914
|
+
|
915
|
+
//<%------------------------------------------------------------------------ LINKS OBJECT ---------------------------------------------------------------%>
|
916
|
+
function Link(taskFrom, taskTo, lagInWorkingDays) {
|
917
|
+
this.from = taskFrom;
|
918
|
+
this.to = taskTo;
|
919
|
+
this.lag = lagInWorkingDays;
|
920
|
+
}
|
921
|
+
|
922
|
+
|
923
|
+
//<%------------------------------------------------------------------------ ASSIGNMENT ---------------------------------------------------------------%>
|
924
|
+
function Assignment(id, resourceId, roleId, effort) {
|
925
|
+
this.id = id;
|
926
|
+
this.resourceId = resourceId;
|
927
|
+
this.roleId = roleId;
|
928
|
+
this.effort = effort;
|
929
|
+
}
|
930
|
+
|
931
|
+
|
932
|
+
//<%------------------------------------------------------------------------ RESOURCE ---------------------------------------------------------------%>
|
933
|
+
function Resource(id, name) {
|
934
|
+
this.id = id;
|
935
|
+
this.name = name;
|
936
|
+
}
|
937
|
+
|
938
|
+
|
939
|
+
//<%------------------------------------------------------------------------ ROLE ---------------------------------------------------------------%>
|
940
|
+
function Role(id, name) {
|
941
|
+
this.id = id;
|
942
|
+
this.name = name;
|
943
|
+
}
|
944
|
+
|
945
|
+
|
946
|
+
|
947
|
+
|