From a2c248addddd654bfcd712a59d87f458b6161e87 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 7 Jun 2013 12:58:27 +0530 Subject: [PATCH] [projects] added ganttview, removed old timesheet --- public/css/ui/common.css | 1 + public/js/legacy/widgets/form/form.js | 6 +- public/js/lib/README.md | 6 +- public/js/lib/jQuery.Gantt/css/style.css | 6 +- public/js/wn/form/control.js | 2 + public/js/wn/router.js | 2 + public/js/wn/ui/appframe.js | 17 +++- public/js/wn/views/doclistview.js | 25 +++++- public/js/wn/views/formview.js | 2 +- public/js/wn/views/ganttview.js | 98 +++++++++++++++++++----- webnotes/model/bean.py | 4 +- 11 files changed, 136 insertions(+), 33 deletions(-) diff --git a/public/css/ui/common.css b/public/css/ui/common.css index 9cde02fb61..b1aecf7984 100644 --- a/public/css/ui/common.css +++ b/public/css/ui/common.css @@ -49,6 +49,7 @@ a { margin-bottom: 0px; border-radius: 0px; border-bottom: 1px solid #ddd; + min-height: 51px; } .appframe .navbar-form select, diff --git a/public/js/legacy/widgets/form/form.js b/public/js/legacy/widgets/form/form.js index 9c8a72adb6..4a738971d3 100644 --- a/public/js/legacy/widgets/form/form.js +++ b/public/js/legacy/widgets/form/form.js @@ -293,7 +293,7 @@ _f.Frm.prototype.set_footnote = function(txt) { _f.Frm.prototype.add_custom_button = function(label, fn, icon) { - this.appframe.add_button(label, fn, icon || "icon-arrow-right", true); + this.appframe.add_button(label, fn, icon || "icon-arrow-right"); } _f.Frm.prototype.clear_custom_buttons = function() { this.toolbar.refresh() @@ -440,9 +440,7 @@ _f.Frm.prototype.refresh = function(docname) { } // header - if(!this.meta.istable) { - this.refresh_header(); - } + this.refresh_header(); // call trigger this.script_manager.trigger("refresh"); diff --git a/public/js/lib/README.md b/public/js/lib/README.md index 72ac015780..58e09e9516 100644 --- a/public/js/lib/README.md +++ b/public/js/lib/README.md @@ -16,4 +16,8 @@ Download modules Changes images urls - from: url(images -- to: url(../lib/js/lib/jquery/bootstrap_theme/images \ No newline at end of file +- to: url(../lib/js/lib/jquery/bootstrap_theme/images + +## JQuery Gantt + +Not a very mature project. Please check css / js after updating \ No newline at end of file diff --git a/public/js/lib/jQuery.Gantt/css/style.css b/public/js/lib/jQuery.Gantt/css/style.css index 6089ff1859..9ed6779055 100644 --- a/public/js/lib/jQuery.Gantt/css/style.css +++ b/public/js/lib/jQuery.Gantt/css/style.css @@ -45,7 +45,7 @@ overflow: hidden; border-right: 1px solid #DDD; position: relative; - z-index: 20; + z-index: 2; } .fn-gantt .row, .row .fn-gantt .row { @@ -178,7 +178,7 @@ padding: 10px; position: absolute; display: none; - z-index: 11; + z-index: 2; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; @@ -189,7 +189,7 @@ height: 18px; margin: 4px 3px 3px 3px; position: absolute; - z-index: 10; + z-index: 1; text-align: center; -webkit-box-shadow: 0 0 1px rgba(0,0,0,0.25) inset; -moz-box-shadow: 0 0 1px rgba(0,0,0,0.25) inset; diff --git a/public/js/wn/form/control.js b/public/js/wn/form/control.js index da0126f8c1..7f119b966b 100644 --- a/public/js/wn/form/control.js +++ b/public/js/wn/form/control.js @@ -236,6 +236,8 @@ wn.ui.form.ControlData = wn.ui.form.ControlInput.extend({ .attr("placeholder", this.df.placeholder || "") if(this.doctype) this.$input.attr("data-doctype", this.doctype); + if(this.df.input_css) + this.$input.css(this.df.input_css); }, bind_change_event: function() { var me = this; diff --git a/public/js/wn/router.js b/public/js/wn/router.js index 5a2d79923e..de0e4b1483 100644 --- a/public/js/wn/router.js +++ b/public/js/wn/router.js @@ -3,6 +3,7 @@ // re-route map (for rename) wn.re_route = {}; wn.route_titles = {}; +wn.route_history = []; wn.view_factory = {}; wn.view_factories = []; @@ -27,6 +28,7 @@ wn.route = function() { wn._cur_route = window.location.hash; route = wn.get_route(); + wn.route_history.push(route); if(route[0] && wn.views[route[0] + "Factory"]) { // has a view generator, generate! diff --git a/public/js/wn/ui/appframe.js b/public/js/wn/ui/appframe.js index 9b15c1f2e6..b42abec47a 100644 --- a/public/js/wn/ui/appframe.js +++ b/public/js/wn/ui/appframe.js @@ -7,6 +7,7 @@ wn.ui.AppFrame = Class.extend({ init: function(parent, title, module) { this.set_document_title = true; this.buttons = {}; + this.fields_dict = {}; this.$w = $('
\
\ @@ -121,14 +122,22 @@ wn.ui.AppFrame = Class.extend({ }); } - if(meta.__calendar_js) { + if(wn.views.calendar[doctype]) { views.push({ icon: "icon-calendar", route: "Calendar/" + doctype, type: "calendar" }); } - + + if(wn.views.calendar[doctype] && wn.views.calendar[doctype]) { + views.push({ + icon: "icon-tasks", + route: "Gantt/" + doctype, + type: "gantt" + }); + } + if(wn.model.can_get_report(doctype)) { views.push({ icon: "icon-table", @@ -273,7 +282,9 @@ wn.ui.AppFrame = Class.extend({ "margin-left": "4px" }) .attr("title", df.label).tooltip(); - + if(df["default"]) + f.set_input(df["default"]) + this.fields_dict[df.fieldname || df.label] = f; return f; }, add_ripped_paper_effect: function(wrapper) { diff --git a/public/js/wn/views/doclistview.js b/public/js/wn/views/doclistview.js index ad64d8ef24..1febd07321 100644 --- a/public/js/wn/views/doclistview.js +++ b/public/js/wn/views/doclistview.js @@ -36,7 +36,7 @@ wn.views.DocListView = wn.ui.Listing.extend({ var me = this; $(this.page).on("show", function() { - me.dirty && me.run(); + me.refresh(); }); }, @@ -152,7 +152,27 @@ wn.views.DocListView = wn.ui.Listing.extend({ (me.listview.make_new_doc || me.make_new_doc)(me.doctype); }); - if((auto_run !== false) && (auto_run !== 0)) this.run(); + if((auto_run !== false) && (auto_run !== 0)) + this.refresh(); + }, + + refresh: function() { + var me = this; + if(wn.route_options) { + me.filter_list.clear_filters(); + $.each(wn.route_options, function(key, value) { + me.filter_list.add_filter(me.doctype, key, "=", value); + }) + wn.route_options = null; + me.run(); + } else if(me.dirty) { + me.run(); + } else { + if(new Date() - (me.last_updated_on || 0) > 30000) { + // older than 5 mins, refresh + me.run(); + } + } }, run: function(more) { @@ -164,6 +184,7 @@ wn.views.DocListView = wn.ui.Listing.extend({ me.set_filter(key, val, true); }); } + this.last_updated_on = new Date(); this._super(more); }, diff --git a/public/js/wn/views/formview.js b/public/js/wn/views/formview.js index 14bd06c19a..1119342203 100644 --- a/public/js/wn/views/formview.js +++ b/public/js/wn/views/formview.js @@ -47,7 +47,7 @@ wn.views.FormFactory = wn.views.Factory.extend({ } wn.container.change_to("Form/" + dt); - me.page.frm.refresh(dn); + wn.views.formview[dt].frm.refresh(dn); }); } diff --git a/public/js/wn/views/ganttview.js b/public/js/wn/views/ganttview.js index 46b16cabff..f5c47b749e 100644 --- a/public/js/wn/views/ganttview.js +++ b/public/js/wn/views/ganttview.js @@ -4,13 +4,18 @@ wn.views.GanttFactory = wn.views.Factory.extend({ make: function(route) { var me = this; wn.model.with_doctype(route[1], function() { + var page = me.make_page(); + $(page).on("show", function() { + me.set_filters_from_route_options(); + }); + var options = { doctype: route[1], - page: me.make_page() + page: page }; $.extend(options, wn.views.calendar[route[1]] || {}); - new wn.views.Gantt(options); + page.ganttview = new wn.views.Gantt(options); }); } }); @@ -23,16 +28,36 @@ wn.views.Gantt = Class.extend({ wn.require('lib/js/lib/jQuery.Gantt/js/jquery.fn.gantt.js'); this.make_page(); - this.make_chart(); - + wn.route_options ? + this.set_filters_from_route_options() : + this.refresh(); }, make_page: function() { - var module = locals.DocType[this.doctype].module; - this.page.appframe.set_title(wn._("Gantt Chart") + " - " + wn._(this.doctype)); - this.page.appframe.add_module_icon(module) - this.page.appframe.set_views_for(this.doctype, "gantt"); + var module = locals.DocType[this.doctype].module, + me = this; + + this.appframe = this.page.appframe; + this.appframe.set_title(wn._("Gantt Chart") + " - " + wn._(this.doctype)); + this.appframe.add_module_icon(module) + this.appframe.set_views_for(this.doctype, "gantt"); + + this.appframe.add_button("Refresh", + function() { me.refresh(); }, "icon-refresh") + + this.appframe.add_field({fieldtype:"Date", label:"From", + fieldname:"start", "default": wn.datetime.month_start(), input_css: {"z-index": 3}}); + + this.appframe.add_field({fieldtype:"Date", label:"To", + fieldname:"end", "default": wn.datetime.month_end(), input_css: {"z-index": 3}}); + + if(this.filters) { + $.each(this.filters, function(i, df) { + me.appframe.add_field(df); + return false; + }); + } }, - make_chart: function() { + refresh: function() { var parent = $(this.page) .find(".layout-main") .empty() @@ -45,19 +70,20 @@ wn.views.Gantt = Class.extend({ type: "GET", args: { doctype: this.doctype, - start: "2013-01-01", - end: "2014-01-01" + start: this.appframe.fields_dict.start.get_parsed_value(), + end: this.appframe.fields_dict.end.get_parsed_value(), + filters: this.get_filters() }, callback: function(r) { $(parent).empty(); if(!r.message.length) { - $(parent).html('
No Tasks Yet.
'); + $(parent).html('
Nothing to show.
'); } else { var gantt_area = $('
').appendTo(parent); gantt_area.gantt({ source: me.get_source(r), navigate: "scroll", - scale: "weeks", + scale: "day", minScale: "day", maxScale: "months", onItemClick: function(data) { @@ -72,6 +98,27 @@ wn.views.Gantt = Class.extend({ }) }, + set_filter: function(doctype, value) { + var me = this; + if(this.filters) { + $.each(this.filters, function(i, df) { + if(df.options===value) + me.appframe.fields_dict[df.fieldname].set_input(value); + return false; + }); + } + }, + get_filters: function() { + var filter_vals = {}, + me = this; + if(this.filters) { + $.each(this.filters, function(i, df) { + filter_vals[df.fieldname || df.label] = + me.appframe.fields_dict[df.fieldname || df.label].get_parsed_value(); + }); + } + return filter_vals; + }, get_source: function(r) { var source = [], me = this; @@ -85,11 +132,11 @@ wn.views.Gantt = Class.extend({ if(v.start && v.end) { source.push({ - name: v.project || " ", - desc: v.subject, + name: v.title, + desc: v.status, values: [{ name: v.title, - desc: v.status, + desc: v.title + "
" + v.status, from: '/Date("'+v.start+'")/', to: '/Date("'+v.end+'")/', customClass: { @@ -98,12 +145,27 @@ wn.views.Gantt = Class.extend({ 'info':'ganttBlue', 'success':'ganttGreen', '':'ganttGray' - }[me.style_map[v.status]], + }[me.style_map ? + me.style_map[v.status] : + wn.utils.guess_style(v.status, "standard")], dataObj: v }] }) } }); return source - } + }, + set_filters_from_route_options: function() { + var me = this; + if(wn.route_options) { + $.each(wn.route_options, function(k, value) { + if(me.appframe.fields_dict[k]) { + me.appframe.fields_dict[k].set_input(value); + me.refresh(); + return false; + }; + }) + wn.route_options = null; + } + } }); diff --git a/webnotes/model/bean.py b/webnotes/model/bean.py index 45c6344f86..82d4ab92f7 100644 --- a/webnotes/model/bean.py +++ b/webnotes/model/bean.py @@ -100,8 +100,10 @@ class Bean: self.obj.doc = self.doc def make_obj(self): - if self.obj: return self.obj + if self.obj: + return self.obj self.obj = webnotes.get_obj(doc=self.doc, doclist=self.doclist) + self.obj.bean = self self.controller = self.obj return self.obj