浏览代码

Merge pull request #2119 from netchampfaris/gantt

[gantt] fixes
version-14
Nabin Hait 8 年前
committed by GitHub
父节点
当前提交
1c617ad93c
共有 2 个文件被更改,包括 3 次插入168 次删除
  1. +3
    -4
      frappe/public/js/frappe/views/gantt.js
  2. +0
    -164
      frappe/public/js/frappe/views/ganttview.js

+ 3
- 4
frappe/public/js/frappe/views/gantt.js 查看文件

@@ -307,7 +307,7 @@ var Gantt = Class.extend({
secondary_text_y = me.opts.header_height - 25;

if(me.view_mode === 'Month') {
primary_text_x += me.opts.column_width/2;
primary_text_x += (date.daysInMonth() * me.opts.column_width/30)/2;
secondary_text_x += (me.opts.column_width * 12)/2;
}
if(me.view_mode === 'Week') {
@@ -315,6 +315,7 @@ var Gantt = Class.extend({
secondary_text_x += (me.opts.column_width * 4)/2;
}
if(me.view_mode === 'Day') {
primary_text_x += me.opts.column_width/2;
secondary_text_x += (me.opts.column_width * 30)/2;
}
if(me.view_mode === 'Quarter Day') {
@@ -511,10 +512,8 @@ var Bar = Class.extend({
prepare_values: function() {
this.x = this.compute_x();
this.y = this.compute_y();
this.duration = this.task._end.diff(this.task._start, 'hours')/this.gantt.step;
this.duration = (this.task._end.diff(this.task._start, 'hours') + 24)/this.gantt.step;
this.width = this.gantt.unit_width * this.duration;
if(this.gantt.view_mode === 'Month')
this.width = (this.gantt.unit_width/30) * (this.duration*this.gantt.step/24);
this.progress_width = this.gantt.unit_width * this.duration * (this.task.progress/100) || 0;
this.group = this.canvas.group().addClass('bar-wrapper');
this.bar_group = this.canvas.group().addClass('bar-group').appendTo(this.group);


+ 0
- 164
frappe/public/js/frappe/views/ganttview.js 查看文件

@@ -1,164 +0,0 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

frappe.provide("frappe.views.calendar");

frappe.views.GanttFactory = frappe.views.Factory.extend({
make: function(route) {
var me = this;
me.doctype = route[1];

frappe.require(['assets/frappe/js/lib/jQuery.Gantt/css/style.css',
'assets/frappe/js/lib/jQuery.Gantt/js/jquery.fn.gantt.js'], function() {

frappe.model.with_doctype(me.doctype, function() {
var page = me.make_page();
$(page).on("show", function() {
page.ganttview.set_filters_from_route_options();
});

var options = {
doctype: me.doctype,
parent: page
};
$.extend(options, frappe.views.calendar[me.doctype] || {});

page.ganttview = new frappe.views.Gantt(options);
});
});
}
});

frappe.views.Gantt = frappe.views.CalendarBase.extend({
init: function(opts) {
$.extend(this, opts);
this.make_page();
frappe.route_options ?
this.set_filters_from_route_options() :
this.refresh();
},
make_page: function() {
var module = locals.DocType[this.doctype].module,
me = this;

this.page = this.parent.page;
this.page.set_title(__("Gantt Chart") + " - " + __(this.doctype));
frappe.breadcrumbs.add(module, this.doctype);

this.page.set_secondary_action(__("Refresh"),
function() { me.refresh(); }, "icon-refresh")

this.page.add_field({fieldtype:"Date", label:"From",
fieldname:"start", "default": frappe.datetime.month_start(),
change: function() { me.refresh(); },
input_css: {"z-index": 3}});

this.page.add_field({fieldtype:"Date", label:"To",
fieldname:"end", "default": frappe.datetime.month_end(),
change: function() { me.refresh(); },
input_css: {"z-index": 3}});

this.add_filters();
this.wrapper = $("<div style='position:relative;z-index:1;'></div>").appendTo(this.page.main);

},
refresh: function() {
var me = this;
return frappe.call({
method: this.get_events_method,
type: "GET",
args: {
doctype: this.doctype,
start: this.page.fields_dict.start.get_parsed_value(),
end: this.page.fields_dict.end.get_parsed_value(),
filters: this.get_filters()
},
callback: function(r) {
$(me.wrapper).empty();
if(!r.message || !r.message.length) {
$(me.wrapper).html('<p class="text-muted" style="padding: 15px;">' + __('Nothing to show for this selection') + '</p>');
} else {
var gantt_area = $('<div class="gantt">').appendTo(me.wrapper);
gantt_area.gantt({
source: me.get_source(r),
navigate: "scroll",
scale: me.gantt_scale || "days",
minScale: "hours",
maxScale: "months",
itemsPerPage: 20,
onItemClick: function(data) {
frappe.set_route('Form', me.doctype, data.name);
},
onAddClick: function(dt, rowId) {
frappe.new_doc(me.doctype, true);
}
});
}
}
})

},
get_source: function(r) {
var source = [],
me = this;
// projects
$.each(r.message, function(i,v) {

v["title"] = v[me.field_map["title"]];

// description
v.desc = v.title
+ (v.name ? ("<br>" + v.name) : "");

$.each(v, function(key, value) {
if(!in_list(["name", "title", me.field_map["title"], "desc"], key) && value) {
var label = frappe.meta.get_label(me.doctype, key);
if(label) {
v.desc += "<br>" + label + ": " + value;
}
}
});

// standardize values
$.each(me.field_map, function(target, source) {
v[target] = v[source];
});

if(v.start && !v.end) {
v.end = new Date(v.start)
v.end.setHours(v.end.getHours() + 1);
}

// class
if(me.style_map) {
v.cssClass = me.style_map[v.status]
} else if(me.get_css_class) {
v.cssClass = me.get_css_class(v);
} else {
v.cssClass = frappe.utils.guess_style(v.status, "standard")
}

if(v.start && v.end) {
source.push({
name: v.title,
desc: v.status,
values: [{
name: v.title,
desc: v.desc,
from: '/Date('+moment(v.start).format("X")+'000)/',
to: '/Date('+moment(v.end).format("X")+'000)/',
customClass: {
'danger':'ganttRed',
'warning':'ganttOrange',
'info':'ganttBlue',
'success':'ganttGreen',
'':'ganttGray'
}[v.cssClass],
dataObj: v
}]
})
}
});
return source
}
});

正在加载...
取消
保存