diff --git a/board_user/__init__.py b/board_user/__init__.py new file mode 100755 index 0000000..5305644 --- /dev/null +++ b/board_user/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models \ No newline at end of file diff --git a/board_user/__manifest__.py b/board_user/__manifest__.py new file mode 100755 index 0000000..0456606 --- /dev/null +++ b/board_user/__manifest__.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +{ + 'name': "Dashboard per user", + + 'summary': """ + This module helps you to see other's user dashboard""", + + 'description': """ + Long description of module's purpose + """, + + 'license': 'AGPL-3', + + 'author': "Apanda", + 'support': "ryantsoa@gmail.com", + + 'category': 'Uncategorized', + 'version': '1.0', + + # any module necessary for this one to work correctly + 'depends': ['base', 'board'], + + # always loaded + 'data': [ + 'security/board_users.xml', + 'security/ir.model.access.csv', + 'views/board_users_view.xml', + 'views/assets_backend.xml', + ], + 'qweb': ['static/src/xml/board.xml'], + 'images': ['static/description/cover.gif'], +} \ No newline at end of file diff --git a/board_user/models/__init__.py b/board_user/models/__init__.py new file mode 100755 index 0000000..0f37786 --- /dev/null +++ b/board_user/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import board_users \ No newline at end of file diff --git a/board_user/models/board_users.py b/board_user/models/board_users.py new file mode 100755 index 0000000..adc6f2b --- /dev/null +++ b/board_user/models/board_users.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +from odoo import tools +from odoo import models, fields, api + +class board_user(models.Model): + _name = 'board.users' + _auto = False + + user_id = fields.Many2one('res.users', string='User', readonly=True) + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + create or replace view board_users as ( + select + min(i.id) as id, + i.user_id as user_id + from + ir_ui_view_custom as i + group by + i.user_id + ) + """) + +class Board(models.AbstractModel): + _inherit = 'board.board' + + @api.model + def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): + user_dashboard = self.env.context.get('user_dashboard') + if user_dashboard: + self = self.with_env(self.env(user=user_dashboard)) + res = super(Board, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) + return res \ No newline at end of file diff --git a/board_user/security/board_users.xml b/board_user/security/board_users.xml new file mode 100755 index 0000000..c969722 --- /dev/null +++ b/board_user/security/board_users.xml @@ -0,0 +1,10 @@ + + + + All dashboards + the user will have an access to the the menu all dashboards + + + + + \ No newline at end of file diff --git a/board_user/security/ir.model.access.csv b/board_user/security/ir.model.access.csv new file mode 100755 index 0000000..c36e25d --- /dev/null +++ b/board_user/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 +access_board_user_board_user,board_user.board_user,model_board_users,board_user.all_dashboards,1,0,0,0 \ No newline at end of file diff --git a/board_user/static/description/all_dashboards.gif b/board_user/static/description/all_dashboards.gif new file mode 100755 index 0000000..9651b04 Binary files /dev/null and b/board_user/static/description/all_dashboards.gif differ diff --git a/board_user/static/description/cover.gif b/board_user/static/description/cover.gif new file mode 100755 index 0000000..dcd63de Binary files /dev/null and b/board_user/static/description/cover.gif differ diff --git a/board_user/static/description/icon.png b/board_user/static/description/icon.png new file mode 100755 index 0000000..cf71a9e Binary files /dev/null and b/board_user/static/description/icon.png differ diff --git a/board_user/static/description/index.html b/board_user/static/description/index.html new file mode 100755 index 0000000..8fc903d --- /dev/null +++ b/board_user/static/description/index.html @@ -0,0 +1,25 @@ +
+
+

See all dashboards of each user

+

Get the list of users who sets up a dashboard.

+
+ +
+
+
+ +
+
+

Settings

+
+ +

+ Set which users can see others dashboards. + +

+
+
+ +
+
+
\ No newline at end of file diff --git a/board_user/static/description/settings.gif b/board_user/static/description/settings.gif new file mode 100755 index 0000000..3cad58b Binary files /dev/null and b/board_user/static/description/settings.gif differ diff --git a/board_user/static/src/js/abstract_controller_inherit.js b/board_user/static/src/js/abstract_controller_inherit.js new file mode 100755 index 0000000..2ea08c8 --- /dev/null +++ b/board_user/static/src/js/abstract_controller_inherit.js @@ -0,0 +1,46 @@ +odoo.define('web.AbstractControllerBoardUser', function (require) { +"use strict"; + +var AbstractController = require('web.AbstractController'); + +AbstractController.include({ + + _onOpenRecord: function (event) { + event.stopPropagation(); + var record = this.model.get(event.data.id, {raw: true}); + var self = this; + var res_id = record.res_id; + var model = this.modelName; + if (model == "board.users"){ + self._rpc({ + model: 'ir.model.data', + method: 'xmlid_to_res_model_res_id', + args:["board.board_my_dash_view"], + }) + .then(function (data) { + self.do_action({ + name: "Dashboard", + type: "ir.actions.act_window", + res_model: "board.board", + views: [[data[1], 'form']], + usage: 'menu', + context: {'user_dashboard': record.data.user_id}, + view_type: 'form', + view_mode: 'form', + }); + }); + } + + else{ + self.trigger_up('switch_view', { + view_type: 'form', + res_id: res_id, + mode: event.data.mode || 'readonly', + model: model + }); + } + }, + +}); + +}); \ No newline at end of file diff --git a/board_user/static/src/js/board_view_inherit.js b/board_user/static/src/js/board_view_inherit.js new file mode 100755 index 0000000..75db0fe --- /dev/null +++ b/board_user/static/src/js/board_view_inherit.js @@ -0,0 +1,78 @@ +odoo.define('web.BoardBoardUser', function (require) { +"use strict"; + + var BoardView = require('board.BoardView'); + var core = require('web.core'); + var QWeb = core.qweb; + var Domain = require('web.Domain'); + BoardView.prototype.config.Renderer.include({ + _renderTagBoard: function (node) { + var self = this; + // we add the o_dashboard class to the renderer's $el. This means that + // this function has a side effect. This is ok because we assume that + // once we have a '' tag, we are in a special dashboard mode. + this.$el.addClass('o_dashboard'); + this.trigger_up('enable_dashboard'); + + var hasAction = _.detect(node.children, function (column) { + return _.detect(column.children,function (element){ + return element.tag === "action"? element: false; + }); + }); + if (!hasAction) { + return $(QWeb.render('DashBoard.NoContent')); + } + + // We should start with three columns available + node = $.extend(true, {}, node); + + // no idea why master works without this, but whatever + if (!('layout' in node.attrs)) { + node.attrs.layout = node.attrs.style; + } + for (var i = node.children.length; i < 3; i++) { + node.children.push({ + tag: 'column', + attrs: {}, + children: [] + }); + } + + // register actions, alongside a generated unique ID + _.each(node.children, function (column, column_index) { + _.each(column.children, function (action, action_index) { + action.attrs.id = 'action_' + column_index + '_' + action_index; + self.actionsDescr[action.attrs.id] = action.attrs; + }); + }); + var state_context = self.state.context; + if (state_context.hasOwnProperty('user_dashboard')){ + node.perm_close = self.state.context.uid === self.state.context.user_dashboard; + } + else{ + node.perm_close = true; + } + var $html = $('
').append($(QWeb.render('DashBoard', {node: node}))); + + // render each view + _.each(this.actionsDescr, function (action) { + self.defs.push(self._createController({ + $node: $html.find('.oe_action[data-id=' + action.id + '] .oe_content'), + actionID: _.str.toNumber(action.name), + context: action.context, + domain: Domain.prototype.stringToArray(action.domain, {}), + viewType: action.view_mode, + })); + }); + $html.find('.oe_dashboard_column').sortable({ + connectWith: '.oe_dashboard_column', + handle: '.oe_header', + scroll: false + }).bind('sortstop', function () { + self.trigger_up('save_dashboard'); + }); + return $html; + }, + }); + +}); \ No newline at end of file diff --git a/board_user/static/src/xml/board.xml b/board_user/static/src/xml/board.xml new file mode 100755 index 0000000..0f8f530 --- /dev/null +++ b/board_user/static/src/xml/board.xml @@ -0,0 +1,26 @@ + + diff --git a/board_user/views/assets_backend.xml b/board_user/views/assets_backend.xml new file mode 100755 index 0000000..564ecb9 --- /dev/null +++ b/board_user/views/assets_backend.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/board_user/views/board_users_view.xml b/board_user/views/board_users_view.xml new file mode 100755 index 0000000..c26f630 --- /dev/null +++ b/board_user/views/board_users_view.xml @@ -0,0 +1,28 @@ + + + + + + board_user list + board.users + + + + + + + + + + + + All dashboards per user + board.users + tree,form + + + + + + \ No newline at end of file