diff --git a/web_dashboard_tile/__init__.py b/web_dashboard_tile/__init__.py new file mode 100644 index 00000000..386e21ce --- /dev/null +++ b/web_dashboard_tile/__init__.py @@ -0,0 +1 @@ +from . import tile diff --git a/web_dashboard_tile/__openerp__.py b/web_dashboard_tile/__openerp__.py new file mode 100644 index 00000000..02ca929d --- /dev/null +++ b/web_dashboard_tile/__openerp__.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-2013 OpenERP s.a. (). +# Copyright (C) 2014 initOS GmbH & Co. KG (). +# Author Markus Schneider +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + "name": "Dashboard Tile", + "version": "0.3", + "depends": ['web', 'board'], + 'author': 'initOS GmbH & Co. KG', + "category": "", + 'license': 'AGPL-3', + "description": """ + + """, + "summary": "Add tile to dashboard", + 'data': ['tile.xml', + 'security/ir.model.access.csv', + 'security/rules.xml'], + 'css': ['static/src/css/tile.css'], + 'demo': [ + ], + 'test': [ + ], + 'installable': True, + 'auto_install': False, + 'js': ['static/src/js/custom_js.js'], + 'qweb': ['static/src/xml/custom_xml.xml'], +} diff --git a/web_dashboard_tile/security/ir.model.access.csv b/web_dashboard_tile/security/ir.model.access.csv new file mode 100644 index 00000000..aedacd2e --- /dev/null +++ b/web_dashboard_tile/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +tile_user,tile_user,model_tile,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/web_dashboard_tile/security/rules.xml b/web_dashboard_tile/security/rules.xml new file mode 100644 index 00000000..ff28cbc1 --- /dev/null +++ b/web_dashboard_tile/security/rules.xml @@ -0,0 +1,13 @@ + + + + + + tile.owner + + + [('user_id','in',[False,user.id])] + + + + diff --git a/web_dashboard_tile/static/src/css/tile.css b/web_dashboard_tile/static/src/css/tile.css new file mode 100644 index 00000000..06c23705 --- /dev/null +++ b/web_dashboard_tile/static/src/css/tile.css @@ -0,0 +1,75 @@ +.openerp .oe_kanban_view .oe_dashbaord_tile{ + width: 150px; + height: 150px; + border: 0; + border-radius: 0; +} +.openerp .oe_kanban_view .oe_dashbaord_tile .tile_count{ + font-size: 48px; + font-weight: bold; + position: absolute; + left: 9px; + bottom: 9px; +} +.openerp .oe_kanban_view .oe_dashbaord_tile .tile_label{ + padding: 9px; + font-size: 15px; +} +.openerp .oe_kanban_view .oe_dashbaord_tile a{ + color: #fff; +} +.openerp .oe_kanban_view .oe_dashbaord_tile.oe_tile_color_, +.openerp .oe_kanban_view .oe_dashbaord_tile.oe_tile_color_ a, +.openerp .oe_kanban_view .oe_dashbaord_tile .oe_dropdown_menu a{ + color: #000; +} +.openerp .oe_kanban_view .oe_tile_color_1, +.openerp .oe_dashbaord_tile a.oe_kanban_color_1{ + background: #CD2513; + color: #fff; +} +.openerp .oe_kanban_view .oe_tile_color_2, +.openerp .oe_dashbaord_tile a.oe_kanban_color_2{ + background: #CDC713; + color: #fff; +} +.openerp .oe_kanban_view .oe_tile_color_3, +.openerp .oe_dashbaord_tile a.oe_kanban_color_3{ + background: #57158A; + color: #fff; +} +.openerp .oe_kanban_view .oe_tile_color_4, +.openerp .oe_dashbaord_tile a.oe_kanban_color_4{ + background: #0E9B2D; + color: #fff; +} +.openerp .oe_kanban_view .oe_tile_color_5, +.openerp .oe_dashbaord_tile a.oe_kanban_color_5{ + background: #7F0C00; + color: #fff; +} +.openerp .oe_kanban_view .oe_tile_color_6, +.openerp .oe_dashbaord_tile a.oe_kanban_color_6{ + background: #7F7B00; + color: #fff; +} +.openerp .oe_kanban_view .oe_tile_color_7, +.openerp .oe_dashbaord_tile a.oe_kanban_color_7{ + background: #320455; + color: #fff; +} +.openerp .oe_kanban_view .oe_tile_color_8, +.openerp .oe_dashbaord_tile a.oe_kanban_color_8{ + background: #CD6E13; + color: #fff; +} +.openerp .oe_kanban_view .oe_tile_color_9, +.openerp .oe_dashbaord_tile a.oe_kanban_color_9{ + background: #0E6C7E; + color: #fff; +} +.openerp .oe_kanban_view .oe_tile_color_0, +.openerp .oe_dashbaord_tile a.oe_kanban_color_0{ + background: #006015; + color: #fff; +} \ No newline at end of file diff --git a/web_dashboard_tile/static/src/js/custom_js.js b/web_dashboard_tile/static/src/js/custom_js.js new file mode 100644 index 00000000..f5a80538 --- /dev/null +++ b/web_dashboard_tile/static/src/js/custom_js.js @@ -0,0 +1,105 @@ +// @@@ web_dashboard_tile custom JS @@@ +//############################################################################# +// +// Copyright (C) 2010-2013 OpenERP s.a. () +// Copyright (C) 2014 initOS GmbH & Co. KG () +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +//############################################################################# + +openerp.web_dashboard_tile = function (instance) +{ +var QWeb = instance.web.qweb, + _t = instance.web._t, + _lt = instance.web._lt; +_.mixin({ + sum: function (obj) { return _.reduce(obj, function (a, b) { return a + b; }, 0); } +}); + var module = instance.board.AddToDashboard; + + module.include({ + start: function () { + this._super(); + var self = this; + this.$('#add_dashboard_tile').on('click', this, function (){ + self.save_tile(); + }) + }, + render_data: function(dashboard_choices){ + var selection = instance.web.qweb.render( + "SearchView.addtodashboard.selection", { + selections: dashboard_choices}); + this.$("form input").before(selection) + }, + save_tile: function () { + var self = this; + var getParent = this.getParent(); + var view_parent = this.getParent().getParent(); + if (! view_parent.action || ! this.$el.find("select").val()) { + this.do_warn("Can't find dashboard action"); + return; + } + + var $name = this.$('#dashboard_tile_new_name'); + + this.tile = new instance.web.Model('tile'); + + var private_filter = !this.$('#oe_searchview_custom_public').prop('checked'); + if (_.isEmpty($name.val())){ + this.do_warn(_t("Error"), _t("Filter name is required.")); + return false; + } + var search = this.view.build_search_data(); + var context = new instance.web.CompoundContext(getParent.dataset.get_context() || []); + var domain = new instance.web.CompoundDomain(getParent.dataset.get_domain() || []); + _.each(search.contexts, context.add, context); + _.each(search.domains, domain.add, domain); + + var c = instance.web.pyeval.eval('context', context); + for(var k in c) { + if (c.hasOwnProperty(k) && /^search_default_/.test(k)) { + delete c[k]; + } + } + // TODO: replace this 6.1 workaround by attribute on + c.dashboard_merge_domains_contexts = false; + var d = instance.web.pyeval.eval('domain', domain); + + context.add({ + group_by: instance.web.pyeval.eval('groupbys', search.groupbys || []) + }); + // Don't save user_context keys in the custom filter, otherwise end + // up with e.g. wrong uid or lang stored *and used in subsequent + // reqs* + var ctx = context; + _(_.keys(instance.session.user_context)).each(function (key) { + delete ctx[key]; + }); + var filter = { + name: $name.val(), + user_id: private_filter ? instance.session.uid : false, + model_id: self.view.model, + //context: context, + domain: d, + action_id: view_parent.action.id, + }; + // FIXME: current context? + return self.tile.call('add', [filter]).done(function (id) { + self.do_warn(_t("Success"), _t("Tile is created")); + }); + + } + }); +} diff --git a/web_dashboard_tile/static/src/xml/custom_xml.xml b/web_dashboard_tile/static/src/xml/custom_xml.xml new file mode 100644 index 00000000..124f2446 --- /dev/null +++ b/web_dashboard_tile/static/src/xml/custom_xml.xml @@ -0,0 +1,12 @@ + + + + +
+ + + +
+
+
+
diff --git a/web_dashboard_tile/tile.py b/web_dashboard_tile/tile.py new file mode 100644 index 00000000..323db992 --- /dev/null +++ b/web_dashboard_tile/tile.py @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-2013 OpenERP s.a. (). +# Copyright (C) 2014 initOS GmbH & Co. KG (). +# Author Markus Schneider +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import orm, fields +import random + + +class tile(orm.Model): + _name = 'tile' + + def _get_tile_count(self, cr, uid, ids, field_name, field_value, + arg, context=None): + result = {} + records = self.browse(cr, uid, ids) + for r in records: + model = self.pool.get(r.model_id.model) + result[r.id] = model.search_count(cr, uid, eval(r.domain), context) + return result + + _columns = { + 'name': fields.char('Tile Name'), + 'model_id': fields.many2one('ir.model', 'Model'), + 'user_id': fields.many2one('res.users', 'User'), + 'domain': fields.text('Domain'), + 'action_id': fields.many2one('ir.actions.act_window', 'Action'), + 'count': fields.function(_get_tile_count, type='int', String='Count', + readonly=True), + 'color': fields.char('Kanban Color') + } + + _defaults = { + 'domain': '[]', + 'color': 0, + } + + def open_link(self, cr, uid, ids, context=None): + + tile_id = ids[0] + tile_object = self.browse(cr, uid, tile_id, context=context) + + if not context: + context = {} + + if tile_object.action_id: + act_obj = self.pool.get('ir.actions.act_window') + result = act_obj.read(cr, uid, [tile_object.action_id.id], + context=context)[0] + #FIXME: restore original Domain + Filter would be better + result['domain'] = tile_object.domain + return result + + # we have no action_id stored, + # so try to load a default tree view + return { + 'name': tile_object.name, + 'view_type': 'form', + 'view_mode': 'tree', + 'view_id': [False], + 'res_model': tile_object.model_id.model, + 'type': 'ir.actions.act_window', + 'context': context, + 'nodestroy': True, + 'target': 'current', + 'domain': tile_object.domain, + } + + def add(self, cr, uid, vals, context=None): + #TODO: check if string + if 'model_id' in vals: + # need to relace model_name with its id + model_ids = self.pool.get('ir.model').search(cr, uid, + [('model', '=', + vals['model_id'])]) + vals['model_id'] = model_ids[0] + if 'color' not in vals: + vals['color'] = random.randint(1, 10) + return self.create(cr, uid, vals, context) diff --git a/web_dashboard_tile/tile.xml b/web_dashboard_tile/tile.xml new file mode 100644 index 00000000..07274a26 --- /dev/null +++ b/web_dashboard_tile/tile.xml @@ -0,0 +1,111 @@ + + + + + tile.tree + tile + tree + + + + + + + + + + + + + tile.form + tile + form + +
+ + + + + + + + +
+
+
+ + + + tile.kanban + tile + kanban + + + + + + + + + + +
+
+ í +
+ +
+
+
+
+
+
+
+ + + Dashboard + tile + form + tree,kanban,form + + + + + + + Dashboard + tile + form + kanban + ['|',('user_id','=',False),('user_id','=',uid)] + + + + + Dashboard + + + + + +
+