Commit fbba8819 authored by jingnan's avatar jingnan 👀

Merge branch 'dev' of http://94.191.100.41/tfmom/tf-mom-web into dev

parents 2e877113 11e901de
(function(){ (function() {
var apiUrl = 'https://export.dhtmlx.com/gantt'
var apiUrl = "https://export.dhtmlx.com/gantt";
var templates = [ var templates = [
"leftside_text", 'leftside_text',
"rightside_text", 'rightside_text',
"task_text", 'task_text',
"progress_text", 'progress_text',
"task_class" 'task_class'
]; ]
function xdr(url, pack, cb){ function xdr(url, pack, cb) {
if (gantt.env.isIE){ if (gantt.env.isIE) {
gantt.env.isIE = false; gantt.env.isIE = false
gantt.ajax.post(url, pack, cb); gantt.ajax.post(url, pack, cb)
gantt.env.isIE = true; gantt.env.isIE = true
} else { } else {
gantt.ajax.post(url, pack, cb); gantt.ajax.post(url, pack, cb)
} }
} }
function defaults(obj, std){ function defaults(obj, std) {
for (var key in std) for (var key in std) {
if (!obj[key]) if (!obj[key]) { obj[key] = std[key] }
obj[key] = std[key]; }
return obj; return obj
} }
//compatibility for new versions of gantt // compatibility for new versions of gantt
if(!gantt.ajax){ if (!gantt.ajax) {
if(window.dhtmlxAjax){ if (window.dhtmlxAjax) {
gantt.ajax = window.dhtmlxAjax; gantt.ajax = window.dhtmlxAjax
}else if(window.dhx4){ } else if (window.dhx4) {
gantt.ajax = window.dhx4.ajax; gantt.ajax = window.dhx4.ajax
} }
} }
function mark_columns(base){ function mark_columns(base) {
var columns = base.config.columns; var columns = base.config.columns
if (columns) if (columns) {
for (var i = 0; i < columns.length; i++) { for (var i = 0; i < columns.length; i++) {
if (columns[i].template) if (columns[i].template) { columns[i].$template = true }
columns[i].$template = true; }
} }
} }
function add_export_methods(gantt) {
var color_box = null
var color_hash = {}
function add_export_methods(gantt){ function get_styles(css) {
var color_box = null; if (!color_box) {
var color_hash = {}; var color_box = document.createElement('DIV')
color_box.style.cssText = 'position:absolute; display:none;'
function get_styles(css){ document.body.appendChild(color_box)
if (!color_box){
var color_box = document.createElement("DIV");
color_box.style.cssText = "position:absolute; display:none;";
document.body.appendChild(color_box);
} }
if (color_hash[css]) if (color_hash[css]) { return color_hash[css] }
return color_hash[css];
color_box.className = css; color_box.className = css
return (color_hash[css] = get_color(color_box, "color")+";"+get_color(color_box, "backgroundColor")); return (color_hash[css] = get_color(color_box, 'color') + ';' + get_color(color_box, 'backgroundColor'))
} }
function getMinutesWorktimeSettings(parsedRanges) {
function getMinutesWorktimeSettings(parsedRanges){ var minutes = []
var minutes = []; parsedRanges.forEach(function(range) {
parsedRanges.forEach(function(range){ minutes.push(range.startMinute)
minutes.push(range.startMinute); minutes.push(range.endMinute)
minutes.push(range.endMinute); })
}); return minutes
return minutes;
} }
gantt._getWorktimeSettings = function() { gantt._getWorktimeSettings = function() {
var defaultWorkTimes = { var defaultWorkTimes = {
hours : [0, 24], hours: [0, 24],
minutes: null, minutes: null,
dates : {0:true, 1:true, 2:true, 3:true, 4:true, 5:true, 6:true} dates: { 0: true, 1: true, 2: true, 3: true, 4: true, 5: true, 6: true }
}; }
var time; var time
if(!gantt.config.work_time){ if (!gantt.config.work_time) {
time = defaultWorkTimes; time = defaultWorkTimes
}else{ } else {
var wTime = gantt._working_time_helper; var wTime = gantt._working_time_helper
if (wTime && wTime.get_calendar) { if (wTime && wTime.get_calendar) {
time = wTime.get_calendar(); time = wTime.get_calendar()
} else if (wTime) { } else if (wTime) {
time = { time = {
hours : wTime.hours, hours: wTime.hours,
minutes: null, minutes: null,
dates : wTime.dates dates: wTime.dates
}; }
} else if (gantt.config.worktimes && gantt.config.worktimes.global) { } else if (gantt.config.worktimes && gantt.config.worktimes.global) {
var settings = gantt.config.worktimes.global; var settings = gantt.config.worktimes.global
if(settings.parsed){ if (settings.parsed) {
var minutes = getMinutesWorktimeSettings(settings.parsed.hours); var minutes = getMinutesWorktimeSettings(settings.parsed.hours)
time = { time = {
hours : null, hours: null,
minutes: minutes, minutes: minutes,
dates : {} dates: {}
};
for(var i in settings.parsed.dates){
if(Array.isArray(settings.parsed.dates[i])){
time.dates[i] = getMinutesWorktimeSettings(settings.parsed.dates[i]);
}else{
time.dates[i] = settings.parsed.dates[i];
} }
for (var i in settings.parsed.dates) {
if (Array.isArray(settings.parsed.dates[i])) {
time.dates[i] = getMinutesWorktimeSettings(settings.parsed.dates[i])
} else {
time.dates[i] = settings.parsed.dates[i]
} }
}else{ }
} else {
time = { time = {
hours : settings.hours, hours: settings.hours,
minutes: null, minutes: null,
dates : settings.dates dates: settings.dates
}; }
} }
} else { } else {
time = defaultWorkTimes; time = defaultWorkTimes
}; }
} }
return time; return time
}; }
gantt.exportToPDF = function(config){ gantt.exportToPDF = function(config) {
if (config && config.raw){ if (config && config.raw) {
config = defaults(config, { config = defaults(config, {
name:"gantt.pdf", data:this._serialize_html() name: 'gantt.pdf', data: this._serialize_html()
}); })
} else { } else {
config = defaults((config || {}), { config = defaults((config || {}), {
name:"gantt.pdf", name: 'gantt.pdf',
data:this._serialize_all(), data: this._serialize_all(),
config:this.config config: this.config
}); })
fix_columns(gantt, config.config.columns); fix_columns(gantt, config.config.columns)
} }
config.version = this.version; config.version = this.version
this._send_to_export(config, "pdf"); this._send_to_export(config, 'pdf')
}; }
gantt.exportToPNG = function(config){ gantt.exportToPNG = function(config) {
if (config && config.raw){ if (config && config.raw) {
config = defaults(config, { config = defaults(config, {
name:"gantt.png", data:this._serialize_html() name: 'gantt.png', data: this._serialize_html()
}); })
} else { } else {
config = defaults((config || {}), { config = defaults((config || {}), {
name:"gantt.png", name: 'gantt.png',
data:this._serialize_all(), data: this._serialize_all(),
config:this.config config: this.config
}); })
fix_columns(gantt, config.config.columns); fix_columns(gantt, config.config.columns)
} }
config.version = this.version; config.version = this.version
this._send_to_export(config, "png"); this._send_to_export(config, 'png')
}; }
gantt.getTableData = function(config) {
if (config && config.raw) {
config = defaults(config, {
name: 'gantt.png', data: this._serialize_html()
})
} else {
config = defaults((config || {}), {
name: 'gantt.png',
data: this._serialize_all(),
config: this.config
})
fix_columns(gantt, config.config.columns)
}
gantt.exportToICal = function(config){ return config
}
gantt.exportToICal = function(config) {
config = defaults((config || {}), { config = defaults((config || {}), {
name:"gantt.ical", name: 'gantt.ical',
data:this._serialize_plain().data, data: this._serialize_plain().data,
version:this.version version: this.version
}); })
this._send_to_export(config, "ical"); this._send_to_export(config, 'ical')
}; }
function eachTaskTimed(start, end){ function eachTaskTimed(start, end) {
return function(code, parent, master){ return function(code, parent, master) {
parent = parent || this.config.root_id; parent = parent || this.config.root_id
master = master || this; master = master || this
var branch = this.getChildren(parent); var branch = this.getChildren(parent)
if (branch) if (branch) {
for (var i=0; i<branch.length; i++){ for (var i = 0; i < branch.length; i++) {
var item = this._pull[branch[i]]; var item = this._pull[branch[i]]
if ((!start || item.end_date > start) && (!end || item.start_date < end)) if ((!start || item.end_date > start) && (!end || item.start_date < end)) { code.call(master, item) }
code.call(master, item);
if (this.hasChild(item.id)) if (this.hasChild(item.id)) { this.eachTask(code, item.id, master) }
this.eachTask(code, item.id, master); }
}
} }
};
} }
gantt.exportToExcel = function(config){ gantt.exportToExcel = function(config) {
config = config || {}; config = config || {}
var tasks, dates; var tasks, dates
var state, scroll; var state, scroll
if (config.start || config.end){ if (config.start || config.end) {
state = this.getState(); state = this.getState()
dates = [ this.config.start_date, this.config.end_date ]; dates = [this.config.start_date, this.config.end_date]
scroll = this.getScrollState(); scroll = this.getScrollState()
var convert = this.date.str_to_date(this.config.date_format); var convert = this.date.str_to_date(this.config.date_format)
tasks = this.eachTask; tasks = this.eachTask
if (config.start) if (config.start) { this.config.start_date = convert(config.start) }
this.config.start_date = convert(config.start); if (config.end) { this.config.end_date = convert(config.end) }
if (config.end)
this.config.end_date = convert(config.end);
this.render(); this.render()
this.eachTask = eachTaskTimed(this.config.start_date, this.config.end_date); this.eachTask = eachTaskTimed(this.config.start_date, this.config.end_date)
} }
this._no_progress_colors =config.visual === "base-colors"; this._no_progress_colors = config.visual === 'base-colors'
config = defaults(config, { config = defaults(config, {
name:"gantt.xlsx", name: 'gantt.xlsx',
title:"Tasks", title: 'Tasks',
data:this._serialize_table(config).data, data: this._serialize_table(config).data,
columns:this._serialize_columns({ rawDates: true }), columns: this._serialize_columns({ rawDates: true }),
version:this.version version: this.version
}); })
if (config.visual) if (config.visual) { config.scales = this._serialize_scales(config) }
config.scales = this._serialize_scales(config);
this._send_to_export(config, "excel"); this._send_to_export(config, 'excel')
if (config.start || config.end){ if (config.start || config.end) {
this.config.start_date = state.min_date; this.config.start_date = state.min_date
this.config.end_date = state.max_date; this.config.end_date = state.max_date
this.eachTask = tasks; this.eachTask = tasks
this.render(); this.render()
this.scrollTo(scroll.x, scroll.y); this.scrollTo(scroll.x, scroll.y)
this.config.start_date = dates[0]; this.config.start_date = dates[0]
this.config.end_date = dates[1]; this.config.end_date = dates[1]
}
} }
};
gantt.exportToJSON = function(config){ gantt.exportToJSON = function(config) {
config = defaults((config || {}), { config = defaults((config || {}), {
name:"gantt.json", name: 'gantt.json',
data:this._serialize_all(), data: this._serialize_all(),
config: this.config, config: this.config,
columns:this._serialize_columns(), columns: this._serialize_columns(),
worktime : gantt._getWorktimeSettings(), worktime: gantt._getWorktimeSettings(),
version:this.version version: this.version
}); })
this._send_to_export(config, "json"); this._send_to_export(config, 'json')
}; }
function sendImportAjax(config){ function sendImportAjax(config) {
var url = config.server || apiUrl; var url = config.server || apiUrl
var store = config.store || 0; var store = config.store || 0
var formData = config.data; var formData = config.data
var callback = config.callback; var callback = config.callback
formData.append("type", "excel-parse"); formData.append('type', 'excel-parse')
formData.append("data", JSON.stringify({ formData.append('data', JSON.stringify({
sheet: config.sheet || 0 sheet: config.sheet || 0
})); }))
if(store) if (store) { formData.append('store', store) }
formData.append("store", store);
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function (e) { xhr.onreadystatechange = function(e) {
if(xhr.readyState == 4 && xhr.status == 0){// network error if (xhr.readyState == 4 && xhr.status == 0) { // network error
if(callback){ if (callback) {
callback(null); callback(null)
}
} }
} }
};
xhr.onload = function() { xhr.onload = function() {
var fail = xhr.status > 400; var fail = xhr.status > 400
var info = null; var info = null
if (!fail){ if (!fail) {
try{ try {
info = JSON.parse(xhr.responseText); info = JSON.parse(xhr.responseText)
}catch(e){} } catch (e) {}
} }
if(callback){ if (callback) {
callback(info); callback(info)
}
} }
};
xhr.open('POST', url, true); xhr.open('POST', url, true)
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
xhr.send(formData); xhr.send(formData)
} }
gantt.importFromExcel = function(config){ gantt.importFromExcel = function(config) {
var formData = config.data; var formData = config.data
if(formData instanceof FormData){ if (formData instanceof FormData) {
}else if(formData instanceof File){ } else if (formData instanceof File) {
var data = new FormData(); var data = new FormData()
data.append("file", formData); data.append('file', formData)
config.data = data; config.data = data
}
sendImportAjax(config)
} }
sendImportAjax(config);
};
gantt._msp_config = function(config){
if (config.project) gantt._msp_config = function(config) {
for (var i in config.project){ if (config.project) {
if (!config._custom_data) for (var i in config.project) {
config._custom_data = {}; if (!config._custom_data) { config._custom_data = {} }
config._custom_data[i] = config.project[i](this.config); config._custom_data[i] = config.project[i](this.config)
}
} }
if (config.tasks) if (config.tasks) {
for (var j = 0; j < config.data.length; j++){ for (var j = 0; j < config.data.length; j++) {
var el = this.getTask(config.data[j].id); var el = this.getTask(config.data[j].id)
if (!el._custom_data) if (!el._custom_data) { el._custom_data = {} }
el._custom_data = {}; for (var i in config.tasks) { el._custom_data[i] = config.tasks[i](el, this.config) }
for (var i in config.tasks) }
el._custom_data[i] = config.tasks[i](el, this.config);
} }
delete config.project; delete config.project
delete config.tasks; delete config.tasks
config.time = gantt._getWorktimeSettings(); config.time = gantt._getWorktimeSettings()
var p_dates = this.getSubtaskDates(); var p_dates = this.getSubtaskDates()
var format = this.date.date_to_str("%d-%m-%Y %H:%i:%s"); var format = this.date.date_to_str('%d-%m-%Y %H:%i:%s')
config.start_end = { config.start_end = {
start_date: format(p_dates.start_date), start_date: format(p_dates.start_date),
end_date: format(p_dates.end_date) end_date: format(p_dates.end_date)
}; }
}; }
gantt._msp_data = function(){ gantt._msp_data = function() {
var old_xml_format = this.templates.xml_format; var old_xml_format = this.templates.xml_format
var old_format_date = this.templates.format_date; var old_format_date = this.templates.format_date
this.templates.xml_format = this.date.date_to_str("%d-%m-%Y %H:%i:%s"); this.templates.xml_format = this.date.date_to_str('%d-%m-%Y %H:%i:%s')
this.templates.format_date = this.date.date_to_str("%d-%m-%Y %H:%i:%s"); this.templates.format_date = this.date.date_to_str('%d-%m-%Y %H:%i:%s')
var data = this._serialize_all(); var data = this._serialize_all()
this.templates.xml_format = old_xml_format; this.templates.xml_format = old_xml_format
this.templates.format_date = old_format_date; this.templates.format_date = old_format_date
return data; return data
}; }
gantt._ajax_to_export = function(data, type, callback){ gantt._ajax_to_export = function(data, type, callback) {
delete data.callback; delete data.callback
var url = data.server || apiUrl; var url = data.server || apiUrl
var pack = "type="+type+"&store=1&data="+encodeURIComponent(JSON.stringify(data)); var pack = 'type=' + type + '&store=1&data=' + encodeURIComponent(JSON.stringify(data))
var cb = function(loader){ var cb = function(loader) {
var xdoc = loader.xmlDoc || loader; var xdoc = loader.xmlDoc || loader
var fail = xdoc.status > 400; var fail = xdoc.status > 400
var info = null; var info = null
if (!fail){ if (!fail) {
try{ try {
info = JSON.parse(xdoc.responseText); info = JSON.parse(xdoc.responseText)
}catch(e){} } catch (e) {}
}
callback(info)
} }
callback(info);
};
xdr(url, pack, cb); xdr(url, pack, cb)
}; }
gantt._send_to_export = function(data, type){ gantt._send_to_export = function(data, type) {
var convert = this.date.date_to_str(this.config.date_format || this.config.xml_date); var convert = this.date.date_to_str(this.config.date_format || this.config.xml_date)
if (data.config){ if (data.config) {
data.config = this.copy(data.config); data.config = this.copy(data.config)
mark_columns(data, type); mark_columns(data, type)
if(data.config.start_date && data.config.end_date){ if (data.config.start_date && data.config.end_date) {
if(data.config.start_date instanceof Date){ if (data.config.start_date instanceof Date) {
data.config.start_date = convert(data.config.start_date) data.config.start_date = convert(data.config.start_date)
} }
if(data.config.end_date instanceof Date){ if (data.config.end_date instanceof Date) {
data.config.end_date = convert(data.config.end_date) data.config.end_date = convert(data.config.end_date)
} }
} }
} }
if (data.callback) if (data.callback) { return gantt._ajax_to_export(data, type, data.callback) }
return gantt._ajax_to_export(data, type, data.callback);
var form = this._create_hidden_form(); var form = this._create_hidden_form()
form.firstChild.action = data.server || apiUrl; form.firstChild.action = data.server || apiUrl
form.firstChild.childNodes[0].value = JSON.stringify(data); form.firstChild.childNodes[0].value = JSON.stringify(data)
form.firstChild.childNodes[1].value = type; form.firstChild.childNodes[1].value = type
form.firstChild.submit(); form.firstChild.submit()
}; }
gantt._create_hidden_form = function(){ gantt._create_hidden_form = function() {
if (!this._hidden_export_form){ if (!this._hidden_export_form) {
var t = this._hidden_export_form = document.createElement("div"); var t = this._hidden_export_form = document.createElement('div')
t.style.display = "none"; t.style.display = 'none'
t.innerHTML = "<form method='POST' target='_blank'><textarea name='data' style='width:0px; height:0px;' readonly='true'></textarea><input type='hidden' name='type' value=''></form>"; t.innerHTML = "<form method='POST' target='_blank'><textarea name='data' style='width:0px; height:0px;' readonly='true'></textarea><input type='hidden' name='type' value=''></form>"
document.body.appendChild(t); document.body.appendChild(t)
}
return this._hidden_export_form
} }
return this._hidden_export_form;
};
//patch broken json serialization in gantt 2.1 // patch broken json serialization in gantt 2.1
var original = gantt.json._copyObject; var original = gantt.json._copyObject
function copy_object_base(obj){ function copy_object_base(obj) {
var copy = {}; var copy = {}
for (var key in obj){ for (var key in obj) {
if (key.charAt(0) == "$") if (key.charAt(0) == '$') { continue }
continue; copy[key] = obj[key]
copy[key] = obj[key];
} }
var formatDate = gantt.templates.xml_format || gantt.templates.format_date; var formatDate = gantt.templates.xml_format || gantt.templates.format_date
copy.start_date = formatDate(copy.start_date); copy.start_date = formatDate(copy.start_date)
if (copy.end_date) if (copy.end_date) { copy.end_date = formatDate(copy.end_date) }
copy.end_date = formatDate(copy.end_date);
return copy; return copy
} }
function copy_object_plain(obj){ function copy_object_plain(obj) {
var text = gantt.templates.task_text(obj.start_date, obj.end_date, obj); var text = gantt.templates.task_text(obj.start_date, obj.end_date, obj)
var copy = copy_object_base(obj); var copy = copy_object_base(obj)
copy.text = text || copy.text; copy.text = text || copy.text
return copy; return copy
} }
function get_color(node, style){ function get_color(node, style) {
var value = node.currentStyle ? node.currentStyle[style] : getComputedStyle(node, null)[style]; var value = node.currentStyle ? node.currentStyle[style] : getComputedStyle(node, null)[style]
var rgb = value.replace(/\s/g,'').match(/^rgba?\((\d+),(\d+),(\d+)/i); var rgb = value.replace(/\s/g, '').match(/^rgba?\((\d+),(\d+),(\d+)/i)
return ((rgb && rgb.length === 4) ? return ((rgb && rgb.length === 4)
("0" + parseInt(rgb[1],10).toString(16)).slice(-2) + ? ('0' + parseInt(rgb[1], 10).toString(16)).slice(-2) +
("0" + parseInt(rgb[2],10).toString(16)).slice(-2) + ('0' + parseInt(rgb[2], 10).toString(16)).slice(-2) +
("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : value).replace("#",""); ('0' + parseInt(rgb[3], 10).toString(16)).slice(-2) : value).replace('#', '')
} }
// Excel interprets UTC time as local time in every timezone, send local time instead of actual UTC time. // Excel interprets UTC time as local time in every timezone, send local time instead of actual UTC time.
// https://github.com/SheetJS/js-xlsx/issues/126#issuecomment-60531614 // https://github.com/SheetJS/js-xlsx/issues/126#issuecomment-60531614
var toISOstring = gantt.date.date_to_str("%Y-%m-%dT%H:%i:%s.000Z"); var toISOstring = gantt.date.date_to_str('%Y-%m-%dT%H:%i:%s.000Z')
// excel serialization // excel serialization
function copy_object_table(obj){ function copy_object_table(obj) {
var copy = copy_object_columns(obj, copy_object_plain(obj)); var copy = copy_object_columns(obj, copy_object_plain(obj))
if (copy.start_date) if (copy.start_date) { copy.start_date = toISOstring(obj.start_date) }
copy.start_date = toISOstring(obj.start_date); if (copy.end_date) { copy.end_date = toISOstring(obj.end_date) }
if (copy.end_date)
copy.end_date = toISOstring(obj.end_date);
// private gantt._day_index_by_date was replaced by public gantt.columnIndexByDate in gantt 5.0 // private gantt._day_index_by_date was replaced by public gantt.columnIndexByDate in gantt 5.0
var getDayIndex = gantt._day_index_by_date ? gantt._day_index_by_date : gantt.columnIndexByDate; var getDayIndex = gantt._day_index_by_date ? gantt._day_index_by_date : gantt.columnIndexByDate
copy.$start = getDayIndex.call(gantt, obj.start_date); copy.$start = getDayIndex.call(gantt, obj.start_date)
copy.$end = getDayIndex.call(gantt, obj.end_date); copy.$end = getDayIndex.call(gantt, obj.end_date)
copy.$level = obj.$level; copy.$level = obj.$level
copy.$type = obj.$rendered_type; copy.$type = obj.$rendered_type
var tmps = gantt.templates; var tmps = gantt.templates
copy.$text = tmps.task_text(obj.start, obj.end_date, obj); copy.$text = tmps.task_text(obj.start, obj.end_date, obj)
copy.$left = tmps.leftside_text ? tmps.leftside_text(obj.start, obj.end_date, obj) : ""; copy.$left = tmps.leftside_text ? tmps.leftside_text(obj.start, obj.end_date, obj) : ''
copy.$right = tmps.rightside_text ? tmps.rightside_text(obj.start, obj.end_date, obj) : ""; copy.$right = tmps.rightside_text ? tmps.rightside_text(obj.start, obj.end_date, obj) : ''
return copy; return copy
} }
function copy_object_colors(obj){ function copy_object_colors(obj) {
var copy = copy_object_table(obj); var copy = copy_object_table(obj)
var node = gantt.getTaskNode(obj.id); var node = gantt.getTaskNode(obj.id)
if (node && node.firstChild){ if (node && node.firstChild) {
var color = get_color((gantt._no_progress_colors ? node : node.firstChild), "backgroundColor"); var color = get_color((gantt._no_progress_colors ? node : node.firstChild), 'backgroundColor')
if (color == "363636") if (color == '363636') { color = get_color(node, 'backgroundColor') }
color = get_color(node, "backgroundColor");
copy.$color = color; copy.$color = color
} else if (obj.color) } else if (obj.color) { copy.$color = obj.color }
copy.$color = obj.color;
return copy; return copy
} }
function copy_object_columns(obj, copy){ function copy_object_columns(obj, copy) {
for(var i=0; i<gantt.config.columns.length; i++){ for (var i = 0; i < gantt.config.columns.length; i++) {
var ct = gantt.config.columns[i].template; var ct = gantt.config.columns[i].template
if (ct) { if (ct) {
var val = ct(obj); var val = ct(obj)
if (val instanceof Date) if (val instanceof Date) { val = gantt.templates.date_grid(val, obj) }
val = gantt.templates.date_grid(val, obj); copy['_' + i] = val
copy["_"+i] = val;
} }
} }
return copy; return copy
} }
function copy_object_all(obj){ function copy_object_all(obj) {
var copy = copy_object_base(obj); var copy = copy_object_base(obj)
//serialize all text templates // serialize all text templates
for (var i = 0; i < templates.length; i++){ for (var i = 0; i < templates.length; i++) {
var template = gantt.templates[templates[i]]; var template = gantt.templates[templates[i]]
if (template) if (template) { copy['$' + i] = template(obj.start_date, obj.end_date, obj) }
copy["$"+i] = template(obj.start_date, obj.end_date, obj);
} }
copy_object_columns(obj, copy); copy_object_columns(obj, copy)
copy.open = obj.$open; copy.open = obj.$open
return copy; return copy
} }
function fix_columns(gantt, columns){ function fix_columns(gantt, columns) {
for (var i = 0; i < columns.length; i++) { for (var i = 0; i < columns.length; i++) {
columns[i].label = columns[i].label || gantt.locale.labels["column_"+columns[i].name]; columns[i].label = columns[i].label || gantt.locale.labels['column_' + columns[i].name]
if (typeof columns[i].width == "string") columns[i].width = columns[i].width*1; if (typeof columns[i].width === 'string') columns[i].width = columns[i].width * 1
} }
} }
gantt._serialize_html = function(){ gantt._serialize_html = function() {
var smartScales = gantt.config.smart_scales; var smartScales = gantt.config.smart_scales
var smartRendering = gantt.config.smart_rendering; var smartRendering = gantt.config.smart_rendering
if(smartScales || smartRendering){ if (smartScales || smartRendering) {
gantt.config.smart_rendering = false; gantt.config.smart_rendering = false
gantt.config.smart_scales = false; gantt.config.smart_scales = false
gantt.render(); gantt.render()
} }
var html = this.$container.parentNode.innerHTML; var html = this.$container.parentNode.innerHTML
if(smartScales || smartRendering){ if (smartScales || smartRendering) {
gantt.config.smart_scales = smartScales; gantt.config.smart_scales = smartScales
gantt.config.smart_rendering = smartRendering; gantt.config.smart_rendering = smartRendering
gantt.render(); gantt.render()
} }
return html; return html
}; }
gantt._serialize_all = function(){ gantt._serialize_all = function() {
gantt.json._copyObject = copy_object_all; gantt.json._copyObject = copy_object_all
var data = export_serialize(); var data = export_serialize()
gantt.json._copyObject = original; gantt.json._copyObject = original
return data; return data
}; }
gantt._serialize_plain = function(){ gantt._serialize_plain = function() {
var oldXmlFormat = gantt.templates.xml_format; var oldXmlFormat = gantt.templates.xml_format
var oldFormatDate = gantt.templates.format_date; var oldFormatDate = gantt.templates.format_date
gantt.templates.xml_format = gantt.date.date_to_str("%Y%m%dT%H%i%s", true); gantt.templates.xml_format = gantt.date.date_to_str('%Y%m%dT%H%i%s', true)
gantt.templates.format_date = gantt.date.date_to_str("%Y%m%dT%H%i%s", true); gantt.templates.format_date = gantt.date.date_to_str('%Y%m%dT%H%i%s', true)
gantt.json._copyObject = copy_object_plain; gantt.json._copyObject = copy_object_plain
var data = export_serialize(); var data = export_serialize()
gantt.templates.xml_format = oldXmlFormat; gantt.templates.xml_format = oldXmlFormat
gantt.templates.format_date = oldFormatDate; gantt.templates.format_date = oldFormatDate
gantt.json._copyObject = original; gantt.json._copyObject = original
delete data.links; delete data.links
return data; return data
}; }
function get_raw() { function get_raw() {
// support Gantt < 5.0 // support Gantt < 5.0
if (gantt._scale_helpers) { if (gantt._scale_helpers) {
var scales = gantt._get_scales(), var scales = gantt._get_scales()
min_width = gantt.config.min_column_width, var min_width = gantt.config.min_column_width
autosize_min_width = gantt._get_resize_options().x ? Math.max(gantt.config.autosize_min_width, 0) : config.$task.offsetWidth, var autosize_min_width = gantt._get_resize_options().x ? Math.max(gantt.config.autosize_min_width, 0) : config.$task.offsetWidth
height = config.config.scale_height - 1; var height = config.config.scale_height - 1
return gantt._scale_helpers.prepareConfigs(scales, min_width, autosize_min_width, height); return gantt._scale_helpers.prepareConfigs(scales, min_width, autosize_min_width, height)
} else { // Gantt >= 5.0 } else { // Gantt >= 5.0
var timeline = gantt.$ui.getView("timeline"); var timeline = gantt.$ui.getView('timeline')
if (timeline) { if (timeline) {
var availWidth = timeline.$config.width; var availWidth = timeline.$config.width
if (gantt.config.autosize == "x" || gantt.config.autosize == "xy") { if (gantt.config.autosize == 'x' || gantt.config.autosize == 'xy') {
availWidth = Math.max(gantt.config.autosize_min_width, 0); availWidth = Math.max(gantt.config.autosize_min_width, 0)
} }
var state = gantt.getState(), var state = gantt.getState()
scales = timeline._getScales(), var scales = timeline._getScales()
min_width = gantt.config.min_column_width, var min_width = gantt.config.min_column_width
height = gantt.config.scale_height-1, var height = gantt.config.scale_height - 1
rtl = gantt.config.rtl; var rtl = gantt.config.rtl
return timeline.$scaleHelper.prepareConfigs(scales, min_width, availWidth, height, state.min_date, state.max_date, rtl); return timeline.$scaleHelper.prepareConfigs(scales, min_width, availWidth, height, state.min_date, state.max_date, rtl)
} }
} }
} }
gantt._serialize_table = function(config){ gantt._serialize_table = function(config) {
gantt.json._copyObject = config.visual ? copy_object_colors : copy_object_table; gantt.json._copyObject = config.visual ? copy_object_colors : copy_object_table
var data = export_serialize(); var data = export_serialize()
gantt.json._copyObject = original; gantt.json._copyObject = original
delete data.links; delete data.links
if (config.cellColors){ if (config.cellColors) {
var css = this.templates.timeline_cell_class || this.templates.task_cell_class; var css = this.templates.timeline_cell_class || this.templates.task_cell_class
if (css){ if (css) {
var raw = get_raw(); var raw = get_raw()
var steps = raw[0].trace_x; var steps = raw[0].trace_x
for (var i=1; i<raw.length; i++) for (var i = 1; i < raw.length; i++) {
if (raw[i].trace_x.length > steps.length) if (raw[i].trace_x.length > steps.length) { steps = raw[i].trace_x }
steps = raw[i].trace_x; }
for (var i=0; i<data.data.length; i++){ for (var i = 0; i < data.data.length; i++) {
data.data[i].styles = []; data.data[i].styles = []
var task = this.getTask(data.data[i].id); var task = this.getTask(data.data[i].id)
for (var j = 0; j < steps.length; j++) { for (var j = 0; j < steps.length; j++) {
var date = steps[j]; var date = steps[j]
var cell_css = css(task, date); var cell_css = css(task, date)
if (cell_css) if (cell_css) { data.data[i].styles.push({ index: j, styles: get_styles(cell_css) }) }
data.data[i].styles.push({ index: j, styles: get_styles(cell_css) }); }
} }
} }
} }
return data
} }
return data;
};
gantt._serialize_scales = function(config){ gantt._serialize_scales = function(config) {
var scales = []; var scales = []
var raw = get_raw(); var raw = get_raw()
var min = Infinity; var min = Infinity
var max = 0; var max = 0
for (var i=0; i<raw.length; i++) min = Math.min(min, raw[i].col_width); for (var i = 0; i < raw.length; i++) min = Math.min(min, raw[i].col_width)
for (var i=0; i<raw.length; i++){ for (var i = 0; i < raw.length; i++) {
var start = 0; var start = 0
var end = 0; var end = 0
var row = []; var row = []
scales.push(row); scales.push(row)
var step = raw[i]; var step = raw[i]
max = Math.max(max, step.trace_x.length); max = Math.max(max, step.trace_x.length)
var template = step.format || step.template || (step.date ? gantt.date.date_to_str(step.date) : gantt.config.date_scale); var template = step.format || step.template || (step.date ? gantt.date.date_to_str(step.date) : gantt.config.date_scale)
for (var j = 0; j < step.trace_x.length; j++) { for (var j = 0; j < step.trace_x.length; j++) {
var date = step.trace_x[j]; var date = step.trace_x[j]
end = start + Math.round(step.width[j]/min); end = start + Math.round(step.width[j] / min)
var scale_cell = { text: template(date), start: start, end: end }; var scale_cell = { text: template(date), start: start, end: end }
if (config.cellColors){ if (config.cellColors) {
var css = step.css || this.templates.scale_cell_class; var css = step.css || this.templates.scale_cell_class
if (css){ if (css) {
var scale_css = css(date); var scale_css = css(date)
if (scale_css) if (scale_css) { scale_cell.styles = get_styles(scale_css) }
scale_cell.styles=get_styles(scale_css);
} }
} }
row.push(scale_cell); row.push(scale_cell)
start = end; start = end
} }
} }
return { width:max, height:scales.length, data:scales }; return { width: max, height: scales.length, data: scales }
}; }
gantt._serialize_columns = function(config){ gantt._serialize_columns = function(config) {
gantt.exportMode = true; gantt.exportMode = true
var columns = []; var columns = []
var cols = gantt.config.columns; var cols = gantt.config.columns
var ccount = 0; var ccount = 0
for (var i = 0; i < cols.length; i++){ for (var i = 0; i < cols.length; i++) {
if (cols[i].name == "add" || cols[i].name == "buttons") continue; if (cols[i].name == 'add' || cols[i].name == 'buttons') continue
columns[ccount] = { columns[ccount] = {
id: ((cols[i].template) ? ("_"+i) : cols[i].name), id: ((cols[i].template) ? ('_' + i) : cols[i].name),
header: cols[i].label || gantt.locale.labels["column_"+cols[i].name], header: cols[i].label || gantt.locale.labels['column_' + cols[i].name],
width: (cols[i].width ? Math.floor(cols[i].width/4) : "") width: (cols[i].width ? Math.floor(cols[i].width / 4) : '')
}; }
if (cols[i].name == "duration") if (cols[i].name == 'duration') { columns[ccount].type = 'number' }
columns[ccount].type = "number"; if (cols[i].name == 'start_date' || cols[i].name == 'end_date') {
if (cols[i].name == "start_date" || cols[i].name == "end_date"){ columns[ccount].type = 'date'
columns[ccount].type = "date"; if (config && config.rawDates) { columns[ccount].id = cols[i].name }
if (config && config.rawDates)
columns[ccount].id = cols[i].name;
} }
ccount++; ccount++
} }
gantt.exportMode = false; gantt.exportMode = false
return columns; return columns
}; }
function export_serialize(){ function export_serialize() {
gantt.exportMode = true; gantt.exportMode = true
var xmlFormat = gantt.templates.xml_format; var xmlFormat = gantt.templates.xml_format
var formatDate = gantt.templates.format_date; var formatDate = gantt.templates.format_date
// use configuration date format for serialization so date could be parsed on the export // use configuration date format for serialization so date could be parsed on the export
// required when custom format date function is defined // required when custom format date function is defined
gantt.templates.xml_format = gantt.templates.xml_format =
gantt.templates.format_date = gantt.templates.format_date =
gantt.date.date_to_str(gantt.config.date_format || gantt.config.xml_date); gantt.date.date_to_str(gantt.config.date_format || gantt.config.xml_date)
var data = gantt.serialize(); var data = gantt.serialize()
gantt.templates.xml_format = xmlFormat; gantt.templates.xml_format = xmlFormat
gantt.templates.format_date = formatDate; gantt.templates.format_date = formatDate
gantt.exportMode = false; gantt.exportMode = false
return data; return data
} }
} }
add_export_methods(gantt); add_export_methods(gantt)
if (window.Gantt && Gantt.plugin) if (window.Gantt && Gantt.plugin) { Gantt.plugin(add_export_methods) }
Gantt.plugin(add_export_methods); })();
})();
(function () { (function() {
var apiUrl = "https://export.dhtmlx.com/gantt"; var apiUrl = 'https://export.dhtmlx.com/gantt'
function set_level(data) { function set_level(data) {
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
if (data[i].parent == 0) { if (data[i].parent == 0) {
data[i]._lvl = 1; data[i]._lvl = 1
} }
for (var j = i + 1; j < data.length; j++) { for (var j = i + 1; j < data.length; j++) {
if (data[i].id == data[j].parent) { if (data[i].id == data[j].parent) {
data[j]._lvl = data[i]._lvl + 1; data[j]._lvl = data[i]._lvl + 1
} }
} }
} }
...@@ -747,184 +734,178 @@ ...@@ -747,184 +734,178 @@
} }
function clear_rec_links(data) { function clear_rec_links(data) {
set_level(data.data); set_level(data.data)
var tasks = {}; var tasks = {}
for (var i = 0; i < data.data.length; i++) { for (var i = 0; i < data.data.length; i++) {
tasks[data.data[i].id] = data.data[i]; tasks[data.data[i].id] = data.data[i]
} }
var links = {}; var links = {}
for (i = 0; i < data.links.length; i++) { for (i = 0; i < data.links.length; i++) {
var link = data.links[i]; var link = data.links[i]
if(gantt.isTaskExists(link.source) && gantt.isTaskExists(link.target) && if (gantt.isTaskExists(link.source) && gantt.isTaskExists(link.target) &&
tasks[link.source] && tasks[link.target]){ tasks[link.source] && tasks[link.target]) {
links[link.id] = link; links[link.id] = link
} }
} }
for (i in links) { for (i in links) {
make_links_same_level(links[i], tasks); make_links_same_level(links[i], tasks)
} }
var skippedLinks = {}; var skippedLinks = {}
for (i in tasks) { for (i in tasks) {
clear_circ_dependencies(tasks[i], links, tasks, {}, skippedLinks, null); clear_circ_dependencies(tasks[i], links, tasks, {}, skippedLinks, null)
} }
for (i in links) { for (i in links) {
clear_links_same_level(links, tasks); clear_links_same_level(links, tasks)
} }
for (i = 0; i < data.links.length; i++) { for (i = 0; i < data.links.length; i++) {
if (!links[data.links[i].id]) { if (!links[data.links[i].id]) {
data.links.splice(i, 1); data.links.splice(i, 1)
i--; i--
} }
} }
clear_level(data.data); clear_level(data.data)
} }
function clear_circ_dependencies(task, links, tasks, usedTasks, skippedLinks, prevLink) { function clear_circ_dependencies(task, links, tasks, usedTasks, skippedLinks, prevLink) {
var sources = task.$_source; var sources = task.$_source
if (!sources) return; if (!sources) return
if (usedTasks[task.id]) { if (usedTasks[task.id]) {
on_circ_dependency_find(prevLink, links, usedTasks, skippedLinks); on_circ_dependency_find(prevLink, links, usedTasks, skippedLinks)
} }
usedTasks[task.id] = true; usedTasks[task.id] = true
var targets = {}; var targets = {}
for (var i = 0; i < sources.length; i++) { for (var i = 0; i < sources.length; i++) {
if (skippedLinks[sources[i]]) continue; if (skippedLinks[sources[i]]) continue
var curLink = links[sources[i]]; var curLink = links[sources[i]]
var targetTask = tasks[curLink._target]; var targetTask = tasks[curLink._target]
if (targets[targetTask.id]) { // two link from one task to another if (targets[targetTask.id]) { // two link from one task to another
on_circ_dependency_find(curLink, links, usedTasks, skippedLinks); on_circ_dependency_find(curLink, links, usedTasks, skippedLinks)
} }
targets[targetTask.id] = true; targets[targetTask.id] = true
clear_circ_dependencies(targetTask, links, tasks, usedTasks, skippedLinks, curLink); clear_circ_dependencies(targetTask, links, tasks, usedTasks, skippedLinks, curLink)
} }
usedTasks[task.id] = false; usedTasks[task.id] = false
} }
function on_circ_dependency_find(link, links, usedTasks, skippedLinks) { function on_circ_dependency_find(link, links, usedTasks, skippedLinks) {
if (link) { if (link) {
if (gantt.callEvent("onExportCircularDependency", [link.id, link])) { if (gantt.callEvent('onExportCircularDependency', [link.id, link])) {
delete links[link.id]; delete links[link.id]
} }
delete usedTasks[link._source]; delete usedTasks[link._source]
delete usedTasks[link._target]; delete usedTasks[link._target]
skippedLinks[link.id] = true; skippedLinks[link.id] = true
} }
} }
function make_links_same_level(link, tasks) { function make_links_same_level(link, tasks) {
var task, var task
targetLvl, var targetLvl
linkT = { var linkT = {
target: tasks[link.target], target: tasks[link.target],
source: tasks[link.source] source: tasks[link.source]
}; }
if (linkT.target._lvl != linkT.source._lvl) { if (linkT.target._lvl != linkT.source._lvl) {
if (linkT.target._lvl < linkT.source._lvl) { if (linkT.target._lvl < linkT.source._lvl) {
task = "source"; task = 'source'
targetLvl = linkT.target._lvl targetLvl = linkT.target._lvl
} } else {
else { task = 'target'
task = "target"; targetLvl = linkT.source._lvl
targetLvl = linkT.source._lvl;
} }
do { do {
var parent = tasks[linkT[task].parent]; var parent = tasks[linkT[task].parent]
if (!parent) break; if (!parent) break
linkT[task] = parent; linkT[task] = parent
} while (linkT[task]._lvl < targetLvl); } while (linkT[task]._lvl < targetLvl)
var sourceParent = tasks[linkT.source.parent], var sourceParent = tasks[linkT.source.parent]
targetParent = tasks[linkT.target.parent]; var targetParent = tasks[linkT.target.parent]
while (sourceParent && targetParent && sourceParent.id != targetParent.id) { while (sourceParent && targetParent && sourceParent.id != targetParent.id) {
linkT.source = sourceParent; linkT.source = sourceParent
linkT.target = targetParent; linkT.target = targetParent
sourceParent = tasks[linkT.source.parent]; sourceParent = tasks[linkT.source.parent]
targetParent = tasks[linkT.target.parent]; targetParent = tasks[linkT.target.parent]
} }
} }
link._target = linkT.target.id; link._target = linkT.target.id
link._source = linkT.source.id; link._source = linkT.source.id
if (!linkT.target.$_target) if (!linkT.target.$_target) { linkT.target.$_target = [] }
linkT.target.$_target = []; linkT.target.$_target.push(link.id)
linkT.target.$_target.push(link.id);
if (!linkT.source.$_source) if (!linkT.source.$_source) { linkT.source.$_source = [] }
linkT.source.$_source = []; linkT.source.$_source.push(link.id)
linkT.source.$_source.push(link.id);
} }
function clear_links_same_level(links, tasks) { function clear_links_same_level(links, tasks) {
for (var link in links) { for (var link in links) {
delete links[link]._target; delete links[link]._target
delete links[link]._source; delete links[link]._source
} }
for (var task in tasks) { for (var task in tasks) {
delete tasks[task].$_source; delete tasks[task].$_source
delete tasks[task].$_target; delete tasks[task].$_target
} }
} }
function customProjectProperties(data, config) {
function customProjectProperties(data, config){
if (config && config.project) { if (config && config.project) {
for (var i in config.project) { for (var i in config.project) {
if (!gantt.config.$custom_data) if (!gantt.config.$custom_data) { gantt.config.$custom_data = {} }
gantt.config.$custom_data = {}; gantt.config.$custom_data[i] = typeof config.project[i] === 'function' ? config.project[i](gantt.config) : config.project[i]
gantt.config.$custom_data[i] = typeof config.project[i] == "function" ? config.project[i](gantt.config) : config.project[i];
} }
delete config.project; delete config.project
} }
} }
function customTaskProperties(data, config){ function customTaskProperties(data, config) {
if (config && config.tasks) { if (config && config.tasks) {
data.data.forEach(function (el) { data.data.forEach(function(el) {
for (var i in config.tasks) { for (var i in config.tasks) {
if (!el.$custom_data) if (!el.$custom_data) { el.$custom_data = {} }
el.$custom_data = {}; el.$custom_data[i] = typeof config.tasks[i] === 'function' ? config.tasks[i](el, gantt.config) : config.tasks[i]
el.$custom_data[i] = typeof config.tasks[i] == "function" ? config.tasks[i](el, gantt.config) : config.tasks[i];
} }
}); })
delete config.tasks; delete config.tasks
} }
} }
function exportConfig(data, config){ function exportConfig(data, config) {
var p_name = config.name || 'gantt.xml'; var p_name = config.name || 'gantt.xml'
delete config.name; delete config.name
gantt.config.custom = config; gantt.config.custom = config
var time = gantt._getWorktimeSettings(); var time = gantt._getWorktimeSettings()
var p_dates = gantt.getSubtaskDates(); var p_dates = gantt.getSubtaskDates()
if (p_dates.start_date && p_dates.end_date) { if (p_dates.start_date && p_dates.end_date) {
var formatDate = gantt.templates.format_date || gantt.templates.xml_format; var formatDate = gantt.templates.format_date || gantt.templates.xml_format
gantt.config.start_end = { gantt.config.start_end = {
start_date: formatDate(p_dates.start_date), start_date: formatDate(p_dates.start_date),
end_date: formatDate(p_dates.end_date) end_date: formatDate(p_dates.end_date)
}; }
} }
var manual = config.auto_scheduling === undefined ? false : !!config.auto_scheduling; var manual = config.auto_scheduling === undefined ? false : !!config.auto_scheduling
var res = { var res = {
callback: config.callback || null, callback: config.callback || null,
...@@ -933,125 +914,120 @@ ...@@ -933,125 +914,120 @@
manual: manual, manual: manual,
name: p_name, name: p_name,
worktime: time worktime: time
}; }
for(var i in config) res[i] = config[i]; for (var i in config) res[i] = config[i]
return res; return res
} }
function add_export_methods(gantt) { function add_export_methods(gantt) {
gantt._ms_export = {}; gantt._ms_export = {}
gantt.exportToMSProject = function (config) { gantt.exportToMSProject = function(config) {
config = config || {}; config = config || {}
config.skip_circular_links = config.skip_circular_links === undefined ? true : !!config.skip_circular_links; config.skip_circular_links = config.skip_circular_links === undefined ? true : !!config.skip_circular_links
var oldXmlFormat = this.templates.xml_format; var oldXmlFormat = this.templates.xml_format
var oldFormatDate = this.templates.format_date; var oldFormatDate = this.templates.format_date
var oldXmlDate = this.config.xml_date; var oldXmlDate = this.config.xml_date
var oldDateFormat = this.config.date_format; var oldDateFormat = this.config.date_format
var exportServiceDateFormat = "%d-%m-%Y %H:%i:%s"; var exportServiceDateFormat = '%d-%m-%Y %H:%i:%s'
this.config.xml_date = exportServiceDateFormat; this.config.xml_date = exportServiceDateFormat
this.config.date_format = exportServiceDateFormat; this.config.date_format = exportServiceDateFormat
this.templates.xml_format = this.date.date_to_str(exportServiceDateFormat); this.templates.xml_format = this.date.date_to_str(exportServiceDateFormat)
this.templates.format_date = this.date.date_to_str(exportServiceDateFormat); this.templates.format_date = this.date.date_to_str(exportServiceDateFormat)
var data = this._serialize_all(); var data = this._serialize_all()
customProjectProperties(data, config); customProjectProperties(data, config)
customTaskProperties(data, config); customTaskProperties(data, config)
if (config.skip_circular_links) { if (config.skip_circular_links) {
clear_rec_links(data); clear_rec_links(data)
} }
config = exportConfig(data, config); config = exportConfig(data, config)
this._send_to_export(config, config.type || "msproject"); this._send_to_export(config, config.type || 'msproject')
this.config.xml_date = oldXmlDate; this.config.xml_date = oldXmlDate
this.config.date_format = oldDateFormat; this.config.date_format = oldDateFormat
this.templates.xml_format = oldXmlFormat; this.templates.xml_format = oldXmlFormat
this.templates.format_date = oldFormatDate; this.templates.format_date = oldFormatDate
this.config.$custom_data = null; this.config.$custom_data = null
this.config.custom = null; this.config.custom = null
}; }
gantt.exportToPrimaveraP6 = function(config){ gantt.exportToPrimaveraP6 = function(config) {
config.type = "primaveraP6"; config.type = 'primaveraP6'
return gantt.exportToMSProject(config); return gantt.exportToMSProject(config)
}; }
function sendImportAjax(config){ function sendImportAjax(config) {
var url = config.server || apiUrl; var url = config.server || apiUrl
var store = config.store || 0; var store = config.store || 0
var formData = config.data; var formData = config.data
var callback = config.callback; var callback = config.callback
var settings = {}; var settings = {}
if(config.durationUnit) settings.durationUnit = config.durationUnit if (config.durationUnit) settings.durationUnit = config.durationUnit
if(config.projectProperties) settings.projectProperties = config.projectProperties; if (config.projectProperties) settings.projectProperties = config.projectProperties
if(config.taskProperties) settings.taskProperties = config.taskProperties; if (config.taskProperties) settings.taskProperties = config.taskProperties
formData.append("type", config.type || "msproject-parse"); formData.append('type', config.type || 'msproject-parse')
formData.append("data", JSON.stringify(settings)); formData.append('data', JSON.stringify(settings))
if(store) if (store) { formData.append('store', store) }
formData.append("store", store);
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function (e) { xhr.onreadystatechange = function(e) {
if(xhr.readyState == 4 && xhr.status == 0){// network error if (xhr.readyState == 4 && xhr.status == 0) { // network error
if(callback){ if (callback) {
callback(null); callback(null)
}
} }
} }
};
xhr.onload = function() { xhr.onload = function() {
var fail = xhr.status > 400
var info = null
var fail = xhr.status > 400; if (!fail) {
var info = null; try {
info = JSON.parse(xhr.responseText)
if (!fail){ } catch (e) {}
try{
info = JSON.parse(xhr.responseText);
}catch(e){}
} }
if(callback){ if (callback) {
callback(info); callback(info)
}
} }
}; xhr.open('POST', url, true)
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
xhr.open('POST', url, true); xhr.send(formData)
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.send(formData);
} }
gantt.importFromMSProject = function(config){ gantt.importFromMSProject = function(config) {
var formData = config.data; var formData = config.data
if(formData instanceof FormData){ if (formData instanceof FormData) {
}else if(formData instanceof File){ } else if (formData instanceof File) {
var data = new FormData(); var data = new FormData()
data.append("file", formData); data.append('file', formData)
config.data = data; config.data = data
} }
sendImportAjax(config); sendImportAjax(config)
};
gantt.importFromPrimaveraP6 = function(config){
config.type = "primaveraP6-parse";
return gantt.importFromMSProject(config);
};
} }
add_export_methods(gantt); gantt.importFromPrimaveraP6 = function(config) {
if (window.Gantt && Gantt.plugin) config.type = 'primaveraP6-parse'
Gantt.plugin(add_export_methods); return gantt.importFromMSProject(config)
}
}
})(); add_export_methods(gantt)
\ No newline at end of file if (window.Gantt && Gantt.plugin) { Gantt.plugin(add_export_methods) }
})()
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"dependencies": { "dependencies": {
"axios": "^0.19.2", "axios": "^0.19.2",
"bpmn-js": "^7.0.0", "bpmn-js": "^7.0.0",
"csv-exportor": "^1.0.2",
"camunda-bpmn-moddle": "^4.4.0", "camunda-bpmn-moddle": "^4.4.0",
"lodash.foreach": "^4.5.0", "lodash.foreach": "^4.5.0",
"moment": "^2.26.0", "moment": "^2.26.0",
......
...@@ -91,7 +91,7 @@ export default { ...@@ -91,7 +91,7 @@ export default {
'extMaterialId': r.jobResponse.jobOrder.extMaterialId, 'extMaterialId': r.jobResponse.jobOrder.extMaterialId,
'extMaterialIdType': r.jobResponse.jobOrder.extMaterialIdType, 'extMaterialIdType': r.jobResponse.jobOrder.extMaterialIdType,
'arrivalDate': r.jobResponse.jobOrder.arrivalDate, 'arrivalDate': r.jobResponse.jobOrder.arrivalDate,
// 'reqAmount': r.usableAmount, 'reqAmount': r.usableAmount,
'airModel': r.jobResponse.jobOrder.airModel, 'airModel': r.jobResponse.jobOrder.airModel,
'sorties': r.jobResponse.jobOrder.sorties, 'sorties': r.jobResponse.jobOrder.sorties,
'manufacturer': r.jobResponse.jobOrder.manufacturer, 'manufacturer': r.jobResponse.jobOrder.manufacturer,
......
...@@ -5,14 +5,14 @@ export default { ...@@ -5,14 +5,14 @@ export default {
} }
}, },
mounted() { mounted() {
this.initGantt() this.gantt && this.initGantt()
}, },
methods: { methods: {
initGantt() { initGantt() {
this.setColumnsConfig() this.setColumnsConfig()
this.configLayout() this.usePlugins()
this.gantt.init(this.ganttElId)
this.gantt.i18n.setLocale('cn') this.gantt.i18n.setLocale('cn')
this.configLayout()
}, },
setColumnsConfig() { setColumnsConfig() {
this.gantt.config.columns = this.columns this.gantt.config.columns = this.columns
......
...@@ -33,15 +33,7 @@ export default { ...@@ -33,15 +33,7 @@ export default {
}, },
methods: { methods: {
search() {
},
export() {
},
save() {
}
} }
} }
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
<dee-tools mode="normal" :tools="tools" /> <dee-tools mode="normal" :tools="tools" />
</div> </div>
<div class="content-model"> <div class="content-model">
<step v-show="viewType === 'ExtPosition'" :show-flag="viewType === 'ExtPosition'" :node="node" /> <step ref="ExtPosition" v-show="viewType === 'ExtPosition'" :show-flag="viewType === 'ExtPosition'" :node="node" />
<unit v-show="viewType === 'unit'" :show-flag="viewType === 'unit'" :node="node" /> <unit ref="unit" v-show="viewType === 'unit'" :show-flag="viewType === 'unit'" :node="node" />
<view2 v-show="viewType === 'AircraftSorties'" :show-flag="viewType === 'AircraftSorties'" :node="node" /> <view2 ref="AircraftSorties" v-show="viewType === 'AircraftSorties'" :show-flag="viewType === 'AircraftSorties'" :node="node" />
</div> </div>
</div> </div>
</template> </template>
...@@ -101,14 +101,14 @@ export default { ...@@ -101,14 +101,14 @@ export default {
getData(params) { getData(params) {
this.node = params this.node = params
}, },
import() { export() {
this.$refs[this.viewType].export()
}, },
save() { save() {
this.$refs[this.viewType].save()
}, },
config() { config() {
this.$refs[this.viewType].config()
} }
} }
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<script> <script>
import config from './config' import config from './config'
import data from './data' import data from './data'
import CsvExportor from 'csv-exportor'
export default { export default {
name: 'TfMomWebStep', name: 'TfMomWebStep',
mixins: [config, data], mixins: [config, data],
...@@ -35,10 +36,10 @@ export default { ...@@ -35,10 +36,10 @@ export default {
computed: { computed: {
columns() { columns() {
return [ return [
{ name: 'index', label: '节点', width: 60, align: 'center', resize: true }, { name: 'index', label: '节点', width: 30, align: 'center', resize: true },
{ name: 'text', label: '站位号', width: 160, align: 'center', resize: true }, { name: 'text', label: '站位号', width: 40, align: 'center', resize: true },
{ name: 'duration', label: '工期(天)', width: 100, align: 'center', resize: true, editor: { type: 'number', map_to: 'duration', min: 0, max: 100 }}, { name: 'duration', label: '工期(天)', width: 30, align: 'center', resize: true, editor: { type: 'number', map_to: 'duration', min: 0, max: 100 }},
{ name: '', label: '前置', width: 150, align: 'center', resize: true, template: (task) => { { name: '', label: '前置', width: 40, align: 'center', resize: true, template: (task) => {
var links = task.$target var links = task.$target
var labels = [] var labels = []
for (var i = 0; i < links.length; i++) { for (var i = 0; i < links.length; i++) {
...@@ -49,7 +50,8 @@ export default { ...@@ -49,7 +50,8 @@ export default {
} }
} }
return '<span>' + labels.join(',') + '</span>' return '<span>' + labels.join(',') + '</span>'
} },
editor: { type: 'custom_datepicker_editor' }
} }
] ]
} }
...@@ -76,7 +78,8 @@ export default { ...@@ -76,7 +78,8 @@ export default {
id: item.id, id: item.id,
parenId: link && link.prevNodeId || '', parenId: link && link.prevNodeId || '',
start_date: '2007-1-1', start_date: '2007-1-1',
duration: item.workHour ? (item.workHour / 8) : 0 type: 'task',
duration: item.workHour ? Number(item.workHour / 8) : 0
}) })
if (link) { if (link) {
params.links.push({ params.links.push({
...@@ -90,9 +93,9 @@ export default { ...@@ -90,9 +93,9 @@ export default {
}) })
} }
}) })
this.params = JSON.parse(JSON.stringify(params)) this.params = params
this.gantt.clearAll() this.gantt.clearAll()
this.gantt.parse(params) this.gantt.parse(this.params)
}, },
getData() { getData() {
this.currentId = this.node.id this.currentId = this.node.id
...@@ -120,7 +123,6 @@ export default { ...@@ -120,7 +123,6 @@ export default {
}, },
configLayout() { configLayout() {
const ganttAg = this.gantt const ganttAg = this.gantt
const that = this
const getInput = function(node) { const getInput = function(node) {
return node.querySelector('input') return node.querySelector('input')
} }
...@@ -194,8 +196,7 @@ export default { ...@@ -194,8 +196,7 @@ export default {
ganttAg.ext.zoom.init(zoomConfig) ganttAg.ext.zoom.init(zoomConfig)
// 允许通过拖放来调整任务大小 // 允许通过拖放来调整任务大小
ganttAg.config.drag_resize = true ganttAg.config.drag_resize = true
ganttAg.config.highlight_critical_path = false ganttAg.config.highlight_critical_path = true
ganttAg.config.editor_types.custom_datepicker_editor = { ganttAg.config.editor_types.custom_datepicker_editor = {
show: function(id, column, config, placeholder) { show: function(id, column, config, placeholder) {
var html = var html =
...@@ -212,7 +213,7 @@ export default { ...@@ -212,7 +213,7 @@ export default {
focus: function(node) {}, focus: function(node) {},
set_value: function(value, id, column, node) { set_value: function(value, id, column, node) {
// eslint-disable-next-line eqeqeq // eslint-disable-next-line eqeqeq
var data = that.data.links var data = ganttAg.getTableData().data.links
.filter((p) => p.target === id) .filter((p) => p.target === id)
.map((p) => ganttAg.getWBSCode(ganttAg.getTask(p.source))) .map((p) => ganttAg.getWBSCode(ganttAg.getTask(p.source)))
ganttAg.getWBSCode(ganttAg.getTask(id)) ganttAg.getWBSCode(ganttAg.getTask(id))
...@@ -277,17 +278,17 @@ export default { ...@@ -277,17 +278,17 @@ export default {
// 删除连接后触发 // 删除连接后触发
ganttAg.attachEvent('onAfterLinkDelete', function(id, item) { ganttAg.attachEvent('onAfterLinkDelete', function(id, item) {
var target = ganttAg.getTask(item.target) var target = ganttAg.getTask(item.target)
console.log(ganttAg, target)
var targetLength = target.$target.length var targetLength = target.$target.length
if (!targetLength) { if (!targetLength) {
var data = { var data = {
links: this.gantt.getTableData().data.links, links: ganttAg.getTableData().data.links,
data: this.gantt.getTableData().data.data.map((p) => { data: ganttAg.getTableData().data.data.map((p) => {
delete p.end_date delete p.end_date
p.start_date = new Date(2007, 0, 1) p.start_date = new Date(2007, 0, 1)
return p return p
}) })
} }
ganttAg.clearAll()
ganttAg.parse(data) ganttAg.parse(data)
} }
}) })
...@@ -298,8 +299,86 @@ export default { ...@@ -298,8 +299,86 @@ export default {
} }
return true return true
}) })
ganttAg.attachEvent('onAfterBatchUpdate', function(action) {
console.log('onAfterBatchUpdate')
// your code here
})
ganttAg.attachEvent('onAutoScheduleCircularLink', function(groups) {
console.log(groups, 'onAutoScheduleCircularLink')
// any custom logic here
})
ganttAg.attachEvent('onAfterTaskAutoSchedule', function(task, start, link, predecessor) {
console.log(task, start, link, predecessor, 'onAfterTaskAutoSchedule')
})
this.$nextTick(() => {
ganttAg.init(this.ganttElId)
})
},
export(mode) {
if (mode === 'png') {
this.gantt.exportToPNG({
locale: 'CN',
name: 'AG600.png'
// data: this.tasks
})
} else if (mode === 'pdf') {
this.gantt.exportToPDF({
name: 'AG600.pdf'
})
} else {
var dd = this.gantt.getTableData()
const tableData = dd.data.data.filter(p => !p.priority).map((p) => {
return {
index: p.index,
text: p.text,
duration: Math.round(p.duration),
predecessors: Object.values(p)
.filter((item) => item.toString().includes('<span>'))[0]
.replace('<span>', '')
.replace('</span>', '')
}
})
const header = ['节点', '站位号', '工期(天)', '前置']
CsvExportor.downloadCsv(tableData, { header }, '站位路线.csv')
}
},
save() {
const tasks = this.gantt.getTableData().data.data
const links = this.gantt.getTableData().data.links
const params = this.ganttData.map(item => {
const routes = item.extProcessExecutorRoutes.map(r => {
return {
id: r.id,
operator: 'REMOVE'
}
})
const task = tasks.find(r => r.id === item.id)
if (item.extProcessExecutorRoutes) {
const link = links.find(r => r.target === item.id)
if (link) {
routes.push({
operator: 'ADD',
subTypeName: 'ExtProcessExecutorRoute',
prevNodeIdType: 'ExtPosition',
currNodeIdType: 'ExtPosition',
currNodeId: Number(link.target),
prevNodeId: Number(link.source),
isCritical: link.isCritical
})
}
}
return {
id: item.id,
operator: 'MODIFY',
subTypeName: 'ExtPosition',
workHour: task && (task.duration * 8) || 0,
extProcessExecutorRoutes: routes
}
})
this.$api.recursion('ExtPosition', params, true).then(() => {
this.getData()
})
} }
} }
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment