Board user

This commit is contained in:
projectsodoo 2020-12-25 21:04:59 +05:30
parent 4006cc006a
commit a3691ad7fe
16 changed files with 298 additions and 0 deletions

3
board_user/__init__.py Executable file
View File

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models

32
board_user/__manifest__.py Executable file
View File

@ -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'],
}

3
board_user/models/__init__.py Executable file
View File

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import board_users

View File

@ -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

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="all_dashboards" model="res.groups">
<field name="name">All dashboards </field>
<field name="comment">the user will have an access to the the menu all dashboards</field>
<field name="category_id" ref="base.module_category_usability"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>
</odoo>

View File

@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_board_user_board_user board_user.board_user model_board_users board_user.all_dashboards 1 0 0 0

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -0,0 +1,25 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<h2 class="oe_slogan" style="color:#875A7B;">See all dashboards of each user</h2>
<h3 class="oe_slogan">Get the list of users who sets up a dashboard.</h3>
<div class="oe_demo oe_picture oe_screenshot">
<img src="all_dashboards.gif">
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<h2 class="oe_slogan" style="color:#875A7B;">Settings</h2>
<div class="oe_span6 text-justify oe_mt32">
<span class="fa fa-cog fa-2x pull-left"/>
<p class="oe_mb32" style="margin-left:48px;">
Set which users can see others dashboards.
</p>
</div>
<div class="oe_span6">
<img class="oe_picture oe_screenshot" src="settings.gif">
</div>
</div>
</section>

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

View File

@ -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
});
}
},
});
});

View File

@ -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 '<board>' 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 = $('<div>').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;
},
});
});

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<template>
<t t-extend="DashBoard">
<t t-jquery=".oe_dashboard_links" t-operation="attributes">
<attribute name="t-if">node.perm_close</attribute>
</t>
<t t-jquery="t[t-call='DashBoard.action']" t-operation="replace">
<t t-if="node.perm_close">
<t t-foreach="column.children" t-as="action" t-if="action.tag == 'action'" t-call="DashBoard.action"/>
</t>
<t t-else="">
<t t-foreach="column.children" t-as="action" t-if="action.tag == 'action'" t-call="DashBoard.action.no_close"/>
</t>
</t>
</t>
<t t-name="DashBoard.action.no_close">
<div t-att-data-id="action.attrs.id" class="oe_action">
<h2 t-attf-class="oe_header #{action.attrs.string ? '' : 'oe_header_empty'}">
<span class="oe_header_txt"> <t t-esc="action.attrs.string"/> </span>
<input class = "oe_header_text" type="text"/>
<t t-if="!action.attrs.string">&amp;nbsp;</t>
</h2>
<div class="oe_content"/>
</div>
</t>
</template>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_backend" name="board_users_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/board_user/static/src/js/abstract_controller_inherit.js"></script>
<script type="text/javascript" src="/board_user/static/src/js/board_view_inherit.js"></script>
</xpath>
</template>
</odoo>

View File

@ -0,0 +1,28 @@
<odoo>
<data>
<!-- explicit list view definition -->
<record model="ir.ui.view" id="board_user_list">
<field name="name">board_user list</field>
<field name="model">board.users</field>
<field name="arch" type="xml">
<tree edit="false">
<field name="user_id"/>
</tree>
</field>
</record>
<!-- actions opening views on models -->
<record model="ir.actions.act_window" id="board_user_action">
<field name="name">All dashboards per user</field>
<field name="res_model">board.users</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="All dashboards" id="board_user_menu" parent="base.menu_board_root"
action="board_user_action"/>
</data>
</odoo>