Browse Source

prevent 0 duration

pull/1/head
Muhammad Sulaiman Yusuf 2 years ago
parent
commit
0c2684dc6d
  1. 40
      edit-mode/function/ganttConfig.js
  2. 19
      edit-mode/function/restActivityLink.js

40
edit-mode/function/ganttConfig.js

@ -138,12 +138,25 @@ function satuanLabel(task){
return "";
}
// use the default editor custom for end_date, but override set_value/get_value methods
var dateEditor = gantt.config.editor_types.date;
gantt.config.editor_types.end_date = gantt.mixin({
set_value: function(value, id, column, node){
var correctedValue = gantt.date.add(value, -1, "day");
return dateEditor.set_value.apply(this, [correctedValue, id, column, node]);
},
get_value: function(id, column, node) {
var selectedValue = dateEditor.get_value.apply(this, [id, column, node]);
return gantt.date.add(selectedValue, 1, "day");
},
}, dateEditor);
const editor = {
text: { type: "text", map_to: "text" },
kode_sortname: { type: "text", map_to: "kode_sortname" },
start_date: { type: "date", map_to: "start_date", min: new Date(2018, 0, 1) },
end_date: { type: "date", map_to: "end_date", min: new Date(2018, 0, 1) },
duration: { type: "duration", map_to: "duration", min: 1, max: 365, formatter: formatter },
duration: { type: "duration", map_to: "duration", min: 0, max: 365, formatter: formatter },
cost: { type: "number", map_to: "rencana_biaya", min: 0 },
costActual: { type: "number", map_to: "biaya_actual", min: 0 },
status: { type: "text", map_to: "status" },
@ -241,16 +254,15 @@ var allColumns = [
{ name: "kode_sortname", label: "Kode / Sortname",align: "center", min_width: 120, editor: editor.kode_sortname, resize: true },
{ name: "text", label: "Activity", tree: true, min_width: 150, editor: editor.text, resize: true },
{ name: "start_date", label: "Start Date", align: "center", min_width: 80, editor: editor.start_date, resize: true },
// { name: "end_date", label: "Finish Date", align: "center", min_width: 80, editor: editor.end_date, resize: true, template: function(task){
// var gridDateToStr = gantt.date.date_to_str("%Y-%m-%d");
// if (task.type == gantt.config.types.milestone) {
// return ''
// }
// else {
// return gridDateToStr(new Date(task.end_date.valueOf() - 1));
// }
// }},
{ name: "end_date", label: "Finish Date", align: "center", min_width: 80, editor: editor.end_date, resize: true },
{ name: "end_date", label: "Finish Date", align: "center", min_width: 80, editor: editor.end_date, resize: true, template: function(task){
var gridDateToStr = gantt.date.date_to_str("%Y-%m-%d");
if (task.type == gantt.config.types.milestone) {
return ''
}
else {
return gridDateToStr(new Date(task.end_date.valueOf() - 1));
}
}},
{ name: "duration", label: "Duration", align: "center", min_width: 50, resize: true },
{ name: "rencana_biaya", label: "Cost Planning", align: "center", min_width: 100, resize: true, template: function (text) {
if(!text.rencana_biaya){
@ -449,9 +461,9 @@ gantt.templates.task_class = function (start, end, task) {
}
};
// gantt.templates.task_end_date = function(date){
// return gantt.templates.task_date(new Date(date.valueOf() - 1));
// };
gantt.templates.task_end_date = function(date){
return gantt.templates.task_date(new Date(date.valueOf() - 1));
};
gantt.templates.rightside_text = function (start, end, task) {
if (task.planned_end) {

19
edit-mode/function/restActivityLink.js

@ -85,8 +85,23 @@ var dp = gantt.createDataProcessor(function(entity, action, data, id) {
break;
case "update":
if(entity=="task"){
data['start_date'] = moment(data.start_date).format("YYYY-MM-DD")+" 00:00:00+07";
data['end_date'] = moment(data.end_date).format("YYYY-MM-DD")+" 17:00:00+07";
let startDate = moment(data.start_date, "YYYY-MM-DD");
data['start_date'] = startDate.format("YYYY-MM-DD")+" 00:00:00+07";
let endDate = moment(data.end_date, "YYYY-MM-DD");
data['end_date'] = endDate.format("YYYY-MM-DD")+" 23:59:59+07";
if(startDate > endDate){
gantt.alert({
title:"Peringatan",
type:"alert-error",
text:"Tanggal selesai tidak bisa sebelum tanggal mulai!"
});
data['end_date'] = data['start_date'];
refresData(id);
return;
}
data['duration'] = moment.duration(endDate.diff(startDate)).asDays()+1;
if(data && data.parent){
data['parent_id'] = data.parent;

Loading…
Cancel
Save