Select time scale, make weekends and function to load link tasks
This commit is contained in:
parent
97dfcc5c38
commit
68f0352da1
|
@ -14,20 +14,12 @@ angular.module('myApp.gantt.dhxgantt-directive', [])
|
|||
gantt.parse(collection, "json");
|
||||
}, true);
|
||||
|
||||
//size of gantt
|
||||
$scope.$watch(function() {
|
||||
return $element[0].offsetWidth + "." + $element[0].offsetHeight;
|
||||
}, function() {
|
||||
gantt.setSizes();
|
||||
});
|
||||
|
||||
//init gantt
|
||||
gantt.config.columns = [
|
||||
{name:"text", label:"Task name", width:"250px", tree:true },
|
||||
{name:"start_date", label:"Start time", align: "center" },
|
||||
{name:"end_date", label:"End date", align: "center" },
|
||||
{name:"duration", label:"Duration", align: "center" },
|
||||
{name:"assigned", label:"Assigned to", align: "center", width:100,
|
||||
{name:"text", label:"Task", width: 300, tree:true },
|
||||
{name:"start_date", label:"Start", align: "center" },
|
||||
{name:"end_date", label:"Finish", align: "center" },
|
||||
{name:"assigned", label:"Assigned to", align: "center",
|
||||
template: function(item) {
|
||||
if (!item.users) return "Nobody";
|
||||
return item.users.join(", ");
|
||||
|
@ -35,6 +27,66 @@ angular.module('myApp.gantt.dhxgantt-directive', [])
|
|||
}
|
||||
];
|
||||
|
||||
function setScaleConfig(value){
|
||||
switch (value) {
|
||||
case "1":
|
||||
gantt.config.scale_unit = "day";
|
||||
gantt.config.step = 1;
|
||||
gantt.config.date_scale = "%d %M";
|
||||
gantt.config.subscales = [];
|
||||
gantt.config.scale_height = 27;
|
||||
gantt.templates.date_scale = null;
|
||||
break;
|
||||
case "2":
|
||||
var weekScaleTemplate = function(date){
|
||||
var dateToStr = gantt.date.date_to_str("%d %M");
|
||||
var endDate = gantt.date.add(gantt.date.add(date, 1, "week"), -1, "day");
|
||||
return dateToStr(date) + " - " + dateToStr(endDate);
|
||||
};
|
||||
|
||||
gantt.config.scale_unit = "week";
|
||||
gantt.config.step = 1;
|
||||
gantt.templates.date_scale = weekScaleTemplate;
|
||||
gantt.config.subscales = [
|
||||
{unit:"day", step:1, date:"%D" }
|
||||
];
|
||||
gantt.config.scale_height = 50;
|
||||
break;
|
||||
case "3":
|
||||
gantt.config.scale_unit = "month";
|
||||
gantt.config.date_scale = "%F, %Y";
|
||||
gantt.config.subscales = [
|
||||
{unit:"day", step:1, date:"%j, %D" }
|
||||
];
|
||||
gantt.config.scale_height = 50;
|
||||
gantt.templates.date_scale = null;
|
||||
break;
|
||||
case "4":
|
||||
gantt.config.scale_unit = "year";
|
||||
gantt.config.step = 1;
|
||||
gantt.config.date_scale = "%Y";
|
||||
gantt.config.min_column_width = 50;
|
||||
|
||||
gantt.config.scale_height = 90;
|
||||
gantt.templates.date_scale = null;
|
||||
|
||||
var monthScaleTemplate = function(date){
|
||||
var dateToStr = gantt.date.date_to_str("%M");
|
||||
var endDate = gantt.date.add(date, 2, "month");
|
||||
return dateToStr(date) + " - " + dateToStr(endDate);
|
||||
};
|
||||
|
||||
gantt.config.subscales = [
|
||||
{unit:"month", step:3, template:monthScaleTemplate},
|
||||
{unit:"month", step:1, date:"%M" }
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setScaleConfig('1');
|
||||
|
||||
|
||||
gantt.templates.scale_cell_class = function(date){
|
||||
if(date.getDay()==0||date.getDay()==6){
|
||||
return "weekend";
|
||||
|
@ -46,28 +98,31 @@ angular.module('myApp.gantt.dhxgantt-directive', [])
|
|||
}
|
||||
};
|
||||
|
||||
gantt.templates.grid_row_class = function(start, end, item){
|
||||
return item.$level==0?"gantt_project":""
|
||||
}
|
||||
gantt.templates.task_row_class = function(start, end, item){
|
||||
return item.$level==0?"gantt_project":""
|
||||
}
|
||||
gantt.templates.task_class = function(start, end, item){
|
||||
return item.$level==0?"gantt_project":""
|
||||
}
|
||||
gantt.config.grid_width = 580;
|
||||
gantt.init($element[0]);
|
||||
|
||||
gantt.config.scale_unit = "month";
|
||||
gantt.config.step = 1;
|
||||
gantt.config.date_scale = "%F, %Y";
|
||||
gantt.config.min_column_width = 50;
|
||||
gantt.config.duration_unit = "hour";
|
||||
var func = function(e) {
|
||||
e = e || window.event;
|
||||
var el = e.target || e.srcElement;
|
||||
var value = el.value;
|
||||
setScaleConfig(value);
|
||||
gantt.render();
|
||||
};
|
||||
|
||||
gantt.config.scale_height = 80;
|
||||
|
||||
var weekScaleTemplate = function(date){
|
||||
var dateToStr = gantt.date.date_to_str("%d %M");
|
||||
var endDate = gantt.date.add(gantt.date.add(date, 1, "week"), -1, "day");
|
||||
return dateToStr(date) + " - " + dateToStr(endDate);
|
||||
};
|
||||
|
||||
gantt.config.subscales = [
|
||||
{unit:"week", step:1, template:weekScaleTemplate},
|
||||
{unit:"day", step:1, date:"%D" }
|
||||
];
|
||||
|
||||
gantt.config.grid_width = 580;
|
||||
gantt.init($element[0]);
|
||||
var els = document.getElementsByName("scale");
|
||||
for (var i = 0; i < els.length; i++) {
|
||||
els[i].onclick = func;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default" name="scale" value="1">Day</button>
|
||||
<button type="button" class="btn btn-default" name="scale" value="2">Week</button>
|
||||
<button type="button" class="btn btn-default" name="scale" value="3">Month</button>
|
||||
<button type="button" class="btn btn-default" name="scale" value="4">Year</button>
|
||||
</div>
|
||||
|
||||
<div class="span12">
|
||||
<div dhxgantt data="tasks" style="height:750px; width:100%;"></div>
|
||||
</div>
|
||||
|
|
85
gantt.js
85
gantt.js
|
@ -1,9 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
var scripts = document.getElementsByTagName("script");
|
||||
var currentScriptPath = scripts[scripts.length-1].src;
|
||||
|
||||
angular.module('myApp.gantt.gantt_view', ['ngRoute'])
|
||||
.config(['$routeProvider', function($routeProvider) {
|
||||
$routeProvider.when('/gantt_view', {
|
||||
templateUrl: 'gantt/gantt.html',
|
||||
templateUrl: currentScriptPath.substring(0, currentScriptPath.lastIndexOf('/') + 1)
|
||||
+ 'gantt.html',
|
||||
controller: 'GanttViewCtrl'
|
||||
});
|
||||
}])
|
||||
|
@ -18,16 +22,16 @@ angular.module('myApp.gantt.gantt_view', ['ngRoute'])
|
|||
$scope.tasks = {
|
||||
data:[],
|
||||
links:[],
|
||||
task_ids:[],
|
||||
};
|
||||
|
||||
$scope.error=function(data){
|
||||
console.log(data)
|
||||
}
|
||||
|
||||
$scope._search_read=function(domain){
|
||||
var fields=['id', 'rec_name', 'planned_start_date','planned_end_date',
|
||||
'effort', 'parent','predecessors','assigned_employee']
|
||||
$scope._tasks=function(domain){
|
||||
var fields=['id', 'work.name','type', 'planned_start_date',
|
||||
'planned_end_date', 'effort', 'parent','predecessors',
|
||||
'assigned_employee.rec_name', 'state']
|
||||
var offset=undefined
|
||||
var limit=undefined
|
||||
var order=undefined
|
||||
|
@ -43,25 +47,58 @@ angular.module('myApp.gantt.gantt_view', ['ngRoute'])
|
|||
};
|
||||
|
||||
$scope.add_task=function(task){
|
||||
var t = {}
|
||||
var t = {};
|
||||
t.id = task.id;
|
||||
t.text = task.rec_name;
|
||||
t.start_date = task.planned_start_date || new Date();
|
||||
t.duration = task.effort || 0;
|
||||
t.parent = task.parent;
|
||||
t.end_date = task.planned_end_date;
|
||||
t.users = [task.assigned_employee];
|
||||
$scope.tasks.data.push(t);
|
||||
t.text = task["work.name"];
|
||||
|
||||
if (task.predecessors > 0 ){
|
||||
var l = {}
|
||||
l.source=task.predecessors;
|
||||
l.target=task.id;
|
||||
l.type='0';
|
||||
$scope.tasks.links.push(l);
|
||||
if( task.type == 'milestone' ){
|
||||
t.type = gantt.config.types.milestone
|
||||
} else if( task.type == 'project'){
|
||||
t.type = gantt.config.types.project
|
||||
}
|
||||
|
||||
t.progres = 0;
|
||||
if(t.state = 'closed'){
|
||||
t.progres=1;
|
||||
}
|
||||
|
||||
t.start_date = task.planned_start_date || new Date();
|
||||
t.parent = task.parent;
|
||||
if(task.type == 'task'){
|
||||
t.duration = task.effort || 0;
|
||||
t.end_date = task.planned_end_date;
|
||||
t.users = [task["assigned_employee.rec_name"]];
|
||||
}
|
||||
$scope.tasks.data.push(t);
|
||||
};
|
||||
|
||||
$scope.add_link=function(link){
|
||||
var l = {}
|
||||
l.id = link.id;
|
||||
l.source=link.predecessor;
|
||||
l.target=link.successor;
|
||||
l.type="1";
|
||||
$scope.tasks.links.push(l);
|
||||
}
|
||||
|
||||
$scope._links=function(domain){
|
||||
var fields=['id', 'predecessor', 'successor']
|
||||
var offset=undefined
|
||||
var limit=undefined
|
||||
var order=undefined
|
||||
session.rpc('model.project.predecessor_successor.search_read', [domain, offset, limit, order, fields] , {})
|
||||
.success(function(data){
|
||||
for(var x in data){
|
||||
$scope.add_link(data[x])
|
||||
}
|
||||
})
|
||||
.error(function(data){
|
||||
$scope.error(data);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
$scope.error=function(data){
|
||||
console.log("error");
|
||||
console.log(data);
|
||||
|
@ -69,10 +106,16 @@ angular.module('myApp.gantt.gantt_view', ['ngRoute'])
|
|||
|
||||
$scope.get_tasks=function(){
|
||||
var domain=[('helpdesk','=',false)];
|
||||
var read = true;
|
||||
$scope._search_read(domain);
|
||||
$scope._tasks(domain);
|
||||
};
|
||||
|
||||
$scope.get_links=function(){
|
||||
var domain=[('helpdesk','=',false),('helpdesk','=',null)];
|
||||
$scope._links(domain);
|
||||
}
|
||||
|
||||
$scope.get_tasks();
|
||||
$scope.get_links();
|
||||
}]);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue