Browse Source

first release of web_dashboard_tile

pull/54/head
Markus Schneider 10 years ago
parent
commit
929be89389
  1. 1
      web_dashboard_tile/__init__.py
  2. 46
      web_dashboard_tile/__openerp__.py
  3. 2
      web_dashboard_tile/security/ir.model.access.csv
  4. 13
      web_dashboard_tile/security/rules.xml
  5. 75
      web_dashboard_tile/static/src/css/tile.css
  6. 105
      web_dashboard_tile/static/src/js/custom_js.js
  7. 12
      web_dashboard_tile/static/src/xml/custom_xml.xml
  8. 97
      web_dashboard_tile/tile.py
  9. 111
      web_dashboard_tile/tile.xml

1
web_dashboard_tile/__init__.py

@ -0,0 +1 @@
from . import tile

46
web_dashboard_tile/__openerp__.py

@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-2013 OpenERP s.a. (<http://openerp.com>).
# Copyright (C) 2014 initOS GmbH & Co. KG (<http://www.initos.com>).
# Author Markus Schneider <markus.schneider at initos.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"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'],
}

2
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

13
web_dashboard_tile/security/rules.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="payment_method_rule" model="ir.rule">
<field name="name">tile.owner</field>
<field name="model_id" ref="model_tile" />
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
<field name="domain_force">[('user_id','in',[False,user.id])]</field>
</record>
</data>
</openerp>

75
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;
}

105
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. (<http://www.openerp.com>)
// Copyright (C) 2014 initOS GmbH & Co. KG (<http://initos.com>)
//
// 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 <http://www.gnu.org/licenses/>.
//
//#############################################################################
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 <action/>
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"));
});
}
});
}

12
web_dashboard_tile/static/src/xml/custom_xml.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="SearchView.addtodashboard">
<t t-jquery="form" t-operation="after">
<div>
<label for="dashboard_tile_new_name">Tile:</label>
<input id="dashboard_tile_new_name" />
<button id="add_dashboard_tile">Okay</button>
</div>
</t>
</t>
</templates>

97
web_dashboard_tile/tile.py

@ -0,0 +1,97 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-2013 OpenERP s.a. (<http://openerp.com>).
# Copyright (C) 2014 initOS GmbH & Co. KG (<http://www.initos.com>).
# Author Markus Schneider <markus.schneider at initos.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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)

111
web_dashboard_tile/tile.xml

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="dashboard_tile_tree_view">
<field name="name">tile.tree</field>
<field name="model">tile</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Dashboard tiles">
<field name="name"/>
<field name="domain"/>
<field name="model_id"/>
<field name="action_id"/>
<field name="count"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="dashboard_tile_form_view">
<field name="name">tile.form</field>
<field name="model">tile</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Dashboard tiles" version="7.0">
<group>
<field name="name"/>
<field name="domain"/>
<field name="model_id"/>
<field name="user_id"/>
<field name="action_id"/>
<!-- field name="count"/> -->
</group>
</form>
</field>
</record>
<!-- CRM Lead Kanban View -->
<record model="ir.ui.view" id="dashboard_tile_kanban_view">
<field name="name">tile.kanban</field>
<field name="model">tile</field>
<field name="type">kanban</field>
<field name="arch" type="xml">
<kanban edit="false" create="false">
<field name="name"/>
<field name="domain"/>
<field name="model_id"/>
<field name="action_id"/>
<field name="count"/>
<field name="color"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_tile_color_#{kanban_getcolor(record.color.raw_value)} oe_dashbaord_tile oe_kanban_global_click" >
<div class="oe_dropdown_toggle oe_dropdown_kanban">
<span class="oe_e">í</span>
<ul class="oe_dropdown_menu">
<t t-if="widget.view.is_action_enabled('edit')"><li><a type="edit">Edit...</a></li></t>
<t t-if="widget.view.is_action_enabled('delete')"><li><a type="delete">Delete</a></li></t>
<li><ul class="oe_kanban_colorpicker" data-field="color"/></li>
</ul>
</div>
<div class="oe_kanban_content">
<a type="object" name="open_link" args="[]">
<div class="tile_label">
<b><field name="name"/></b>
</div>
<div style="padding-left: 0.5em; height: 115px;">
</div>
<div class="tile_count">
<span><field name="count"/></span>
</div>
</a>
</div>
<div class="oe_clear"></div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
<record model="ir.actions.act_window" id="actoin_tree_dashboard_tile">
<field name="name">Dashboard</field>
<field name="res_model">tile</field>
<field name="view_type">form</field>
<field name="view_mode">tree,kanban,form</field>
<field name="view_id" ref="dashboard_tile_tree_view"/>
</record>
<menuitem id="menue_dashboard_tile"
name="Dashboard Tile" parent="base.next_id_2"
action="actoin_tree_dashboard_tile" sequence="50"/>
<record model="ir.actions.act_window" id="actoin_kanban_dashboard_tile">
<field name="name">Dashboard</field>
<field name="res_model">tile</field>
<field name="view_type">form</field>
<field name="view_mode">kanban</field>
<field name="domain">['|',('user_id','=',False),('user_id','=',uid)]</field>
<field name="view_id" ref="dashboard_tile_tree_view"/>
</record>
<record id="mail_dashbaord" model="ir.ui.menu">
<field name="name">Dashboard</field>
<field name="sequence" eval="9"/>
<field name="action" ref="actoin_kanban_dashboard_tile"/>
<field name="parent_id" ref="mail.mail_feeds"/>
</record>
</data>
</openerp>
Loading…
Cancel
Save