From 640cfda39de346b122f58a36ba201f87486c75f1 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Fri, 13 Mar 2015 14:40:02 +0200 Subject: [PATCH 01/11] [ADD] web_last_viewed_records --- web_last_viewed_records/__init__.py | 0 web_last_viewed_records/__openerp__.py | 26 +++ .../static/src/css/main.css | 45 +++++ web_last_viewed_records/static/src/js/main.js | 174 ++++++++++++++++++ .../static/src/xml/main.xml | 24 +++ web_last_viewed_records/views.xml | 12 ++ 6 files changed, 281 insertions(+) create mode 100644 web_last_viewed_records/__init__.py create mode 100644 web_last_viewed_records/__openerp__.py create mode 100644 web_last_viewed_records/static/src/css/main.css create mode 100644 web_last_viewed_records/static/src/js/main.js create mode 100644 web_last_viewed_records/static/src/xml/main.xml create mode 100644 web_last_viewed_records/views.xml diff --git a/web_last_viewed_records/__init__.py b/web_last_viewed_records/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/web_last_viewed_records/__openerp__.py b/web_last_viewed_records/__openerp__.py new file mode 100644 index 000000000..88bef27dc --- /dev/null +++ b/web_last_viewed_records/__openerp__.py @@ -0,0 +1,26 @@ +{ + 'name' : 'Last viewed records', + 'version' : '1.0.0', + 'author' : 'Ivan Yelizariev', + 'category' : 'Base', + 'website' : 'https://yelizariev.github.io', + 'description': """ +The idea is taken from SugarCRM's "Last viewed" feature. + +This module doesn't affect on server performance, because it uses browser's localStorage to save history. But dissadvantage is that history is not synced accross browsers. + +FIXME: doesn't work in a res.config view + +Tested on 8.0 ab7b5d7732a7c222a0aea45bd173742acd47242d. + +Further information and discussion: https://yelizariev.github.io/odoo/module/2015/02/18/last-viewed-records.html + """, + 'depends' : ['web', 'mail'], + 'data':[ + 'views.xml', + ], + 'qweb' : [ + "static/src/xml/*.xml", + ], + 'installable': True +} diff --git a/web_last_viewed_records/static/src/css/main.css b/web_last_viewed_records/static/src/css/main.css new file mode 100644 index 000000000..7529374db --- /dev/null +++ b/web_last_viewed_records/static/src/css/main.css @@ -0,0 +1,45 @@ +.oe_last_viewed_item.selected{ + font-weight:bold; +} + +.openerp .oe_last_viewed_item .oe_e { + font-size: 22px; + font-weight: 300 !important; +} + +.openerp .oe_last_viewed_item .list:after, .openerp .oe_last_viewed_item .tree:after { + padding: 2px; + content: "i"; +} +.openerp .oe_last_viewed_item .form:after { + content: "m"; +} +.openerp .oe_last_viewed_item .graph:after { + font-family: "mnmliconsRegular" !important; + font-size: 21px; + font-weight: 300 !important; + content: "}"; + top: -2px; + position: relative; +} +.openerp .oe_last_viewed_item .gantt:after { + font-family: "mnmliconsRegular" !important; + font-size: 21px; + font-weight: 300 !important; + content: "y"; + top: -2px; + position: relative; +} +.openerp .oe_last_viewed_item .calendar:after { + content: "P"; +} +.openerp .oe_last_viewed_item .kanban:after { + content: "k"; +} +.openerp .oe_last_viewed_item .diagram:after { + content: "f"; +} +.oe_last_viewed_icon{ + font-family: "entypoRegular" !important; + font-size: 1.8em; +} \ No newline at end of file diff --git a/web_last_viewed_records/static/src/js/main.js b/web_last_viewed_records/static/src/js/main.js new file mode 100644 index 000000000..1d20925e7 --- /dev/null +++ b/web_last_viewed_records/static/src/js/main.js @@ -0,0 +1,174 @@ +openerp.web_last_viewed_records = function(instance){ + var QWeb = instance.web.qweb; + var _t = instance.web._t; + + instance.web.ActionManager.include({ + last_viewed_history_var: 'odoo_last_viewed', + last_viewed_history_size: 8, + init:function(){ + this._super.apply(this, arguments); + + this.last_viewed = []; + var last_viewed = this.load_last_viewed_history().last_viewed || []; + for (var i=last_viewed.length-1; i>=0; i--){ + this.unshift_last_viewed(last_viewed[i]); + } + }, + add_last_viewed: function(item){ + if (_.any(this.last_viewed, function(x){ + if (x['title'] != item['title'] || + x['view_type'] != item['view_type'] || + x['url']['model'] != item['url']['model']) + return false; + if (x['view_type'] == 'form' && x['id'] != item['id']) + return false; + return true; + })) + return; + + //save json data to localStorage + var data = this.load_last_viewed_history(); + data.last_viewed = data.last_viewed || [] + data.last_viewed.unshift(item); + data.last_viewed.splice(this.last_viewed_history_size); + this.save_last_viewed_history(data); + + this.unshift_last_viewed(item); + }, + unshift_last_viewed: function(item){ + var self = this; + this.last_viewed.unshift(item); + this.last_viewed.splice(this.last_viewed_history_size); + }, + load_last_viewed_history: function(){ + var data = localStorage[this.last_viewed_history_var] || '{}'; + return JSON.parse(data); + }, + save_last_viewed_history: function(data){ + localStorage[this.last_viewed_history_var] = JSON.stringify(data); + }, + // icon map: http://bistro.convergencecms.co/entypo + _model2icon: { + 'res.partner':'+', + 'crm.lead':'4', + 'sale.order':'l', + 'account.analytic.account':'7', + 'crm.phonecall':'!', + 'hr.employee':'.', + 'hr.applicant':'-', + 'project.project':'t', + 'project.task':'W', + 'account.invoice':'h', + 'ir.module.module':'Z', + 'hr_timesheet_sheet.sheet': 'N', + 'res.groups': ',', + 'res.company': '_', + 'res.user': 'ó', + 'gamification.challenge':'è', + 'gamification.badge':'8', + }, + get_last_viewed_title: function(){ + var titles = []; + for (var i = 0; i < this.last_viewed.length; i += 1) { + var item = this.last_viewed[i]; + var label = item.title; + var selected = false;//item.action.id == this.inner_action.id && item.action.res_id == this.inner_action.res_id; + var view_type = item.view_type; + var url = $.param(item.url); + var model = item.url.model; + var title = model; + + var icon = this._model2icon[model]; + if (!icon && /\.settings/.test(model)) + icon = 'c'; + if (icon) + icon = _.str.sprintf('%s', icon); + titles.push(_.str.sprintf('%s %s ', + title, + url, + selected && 'selected' || '', + icon || '', + label, + view_type != 'form' && view_type || '' + )); + } + return titles.join(' | '); + }, + }) + + instance.web.ViewManagerAction.include({ + try_add_last_viewed: function(view_type){ + var view = this.views[view_type]; + var act = view.options.action; + if (!act.type) + return false; + + if (act.target == 'new') + //skip widgets and popup forms + return false; + + var url = { + 'view_type': view_type, + 'model': act.res_model, + 'menu_id': act.menu_id, + 'action': act.id + } + var title = act.display_name; + var dr = view.controller.datarecord; + if (dr){ + title = dr.display_name || title; + if (view_type=='form'){ + url['id'] = dr.id; + } + } + if (view_type=='form' && !url['id']) + return false; + var last_viewed_item = { + 'title': title, + 'url': url, + 'view_type': view_type, + } + this.ActionManager.add_last_viewed(last_viewed_item); + + return true; + }, + do_create_view: function(view_type) { + var self = this; + + var res = this._super.apply(this, arguments); + + var view = this.views[view_type]; + + var exec = function(){ + if (self.active_view == view_type && self.try_add_last_viewed(view_type)){ + self.update_last_viewed_title() + } + } + exec(); + view.controller.on('change:title', this, function(){ + exec() + }) + + return res; + + }, + update_last_viewed_title: function(){ + this.$el.find('.oe_view_manager_last_viewed').html(this.get_action_manager().get_last_viewed_title()); + }, + set_title: function(){ + this._super.apply(this, arguments); + if (this.action.target!='new') + this.update_last_viewed_title(); + } + + }) + instance.mail.Wall.include({ + start: function() { + this._super(); + this.update_last_viewed_title(); + }, + update_last_viewed_title: function(){ + this.$el.find('.oe_view_manager_last_viewed').html(this.ActionManager.get_last_viewed_title()); + }, + }); +} diff --git a/web_last_viewed_records/static/src/xml/main.xml b/web_last_viewed_records/static/src/xml/main.xml new file mode 100644 index 000000000..b19c40ef7 --- /dev/null +++ b/web_last_viewed_records/static/src/xml/main.xml @@ -0,0 +1,24 @@ + + + + + + +
+ + + + + + + + + + + + + + + + + diff --git a/web_last_viewed_records/views.xml b/web_last_viewed_records/views.xml new file mode 100644 index 000000000..c553a2b86 --- /dev/null +++ b/web_last_viewed_records/views.xml @@ -0,0 +1,12 @@ + + + + + + + From dce2a862027e1ee1531eddaabaf317c6ed3e8017 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Fri, 13 Mar 2015 14:49:24 +0200 Subject: [PATCH 02/11] move description to README.rst --- web_last_viewed_records/README.rst | 9 +++++++++ web_last_viewed_records/__openerp__.py | 11 ----------- 2 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 web_last_viewed_records/README.rst diff --git a/web_last_viewed_records/README.rst b/web_last_viewed_records/README.rst new file mode 100644 index 000000000..649b3b723 --- /dev/null +++ b/web_last_viewed_records/README.rst @@ -0,0 +1,9 @@ +The idea is taken from SugarCRM's "Last viewed" feature. + +This module doesn't affect on server performance, because it uses browser's localStorage to save history. But dissadvantage is that history is not synced accross browsers. + +FIXME: doesn't work in a res.config view + +Tested on 8.0 ab7b5d7732a7c222a0aea45bd173742acd47242d. + +Further information and discussion: https://yelizariev.github.io/odoo/module/2015/02/18/last-viewed-records.html diff --git a/web_last_viewed_records/__openerp__.py b/web_last_viewed_records/__openerp__.py index 88bef27dc..83dab0f39 100644 --- a/web_last_viewed_records/__openerp__.py +++ b/web_last_viewed_records/__openerp__.py @@ -4,17 +4,6 @@ 'author' : 'Ivan Yelizariev', 'category' : 'Base', 'website' : 'https://yelizariev.github.io', - 'description': """ -The idea is taken from SugarCRM's "Last viewed" feature. - -This module doesn't affect on server performance, because it uses browser's localStorage to save history. But dissadvantage is that history is not synced accross browsers. - -FIXME: doesn't work in a res.config view - -Tested on 8.0 ab7b5d7732a7c222a0aea45bd173742acd47242d. - -Further information and discussion: https://yelizariev.github.io/odoo/module/2015/02/18/last-viewed-records.html - """, 'depends' : ['web', 'mail'], 'data':[ 'views.xml', From 67e7072c97bf24ccc14800d570466611d9c4fa9b Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Fri, 13 Mar 2015 14:51:26 +0200 Subject: [PATCH 03/11] add OCA to author --- web_last_viewed_records/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_last_viewed_records/__openerp__.py b/web_last_viewed_records/__openerp__.py index 83dab0f39..9d951584c 100644 --- a/web_last_viewed_records/__openerp__.py +++ b/web_last_viewed_records/__openerp__.py @@ -1,7 +1,7 @@ { 'name' : 'Last viewed records', 'version' : '1.0.0', - 'author' : 'Ivan Yelizariev', + 'author' : 'Ivan Yelizariev, Odoo Community Association (OCA)', 'category' : 'Base', 'website' : 'https://yelizariev.github.io', 'depends' : ['web', 'mail'], From 9045f88a46aab13d29c6486252dd48c7fd007fde Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Fri, 13 Mar 2015 17:41:40 +0200 Subject: [PATCH 04/11] whitespace cleanup --- web_last_viewed_records/__openerp__.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/web_last_viewed_records/__openerp__.py b/web_last_viewed_records/__openerp__.py index 9d951584c..52ce65563 100644 --- a/web_last_viewed_records/__openerp__.py +++ b/web_last_viewed_records/__openerp__.py @@ -1,14 +1,14 @@ { - 'name' : 'Last viewed records', - 'version' : '1.0.0', - 'author' : 'Ivan Yelizariev, Odoo Community Association (OCA)', - 'category' : 'Base', - 'website' : 'https://yelizariev.github.io', - 'depends' : ['web', 'mail'], - 'data':[ + 'name': 'Last viewed records', + 'version': '1.0.0', + 'author': 'Ivan Yelizariev, Odoo Community Association (OCA)', + 'category': 'Base', + 'website': 'https://yelizariev.github.io', + 'depends': ['web', 'mail'], + 'data': [ 'views.xml', ], - 'qweb' : [ + 'qweb': [ "static/src/xml/*.xml", ], 'installable': True From a9d9b085c7df3ffc2c25b94bc9525863552f203b Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Sat, 14 Mar 2015 12:52:32 +0200 Subject: [PATCH 05/11] update description --- web_last_viewed_records/README.rst | 47 ++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/web_last_viewed_records/README.rst b/web_last_viewed_records/README.rst index 649b3b723..4d7295c2e 100644 --- a/web_last_viewed_records/README.rst +++ b/web_last_viewed_records/README.rst @@ -1,9 +1,46 @@ -The idea is taken from SugarCRM's "Last viewed" feature. +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License -This module doesn't affect on server performance, because it uses browser's localStorage to save history. But dissadvantage is that history is not synced accross browsers. +Last viewed records +=================== -FIXME: doesn't work in a res.config view +The module shows links to last viewed records and pages. -Tested on 8.0 ab7b5d7732a7c222a0aea45bd173742acd47242d. +The module doesn't affect on server performance, because it uses +browser's localStorage to save history. But dissadvantage is that +history is not synced accross browsers. -Further information and discussion: https://yelizariev.github.io/odoo/module/2015/02/18/last-viewed-records.html +Usage +===== + +There are no any settings to configure. Just install module and continue to use odoo in a usual way. You will see links to last visited pages. + +For further information, please visit: + + * https://yelizariev.github.io/odoo/module/2015/02/18/last-viewed-records.html + +Known issues / Roadmap +====================== + + * FIXME: doesn't work in a res.config view + +Credits +======= + +Contributors +------------ + +* Ivan Yelizariev + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. From 0883fa22bfbeaa8ccca83b3ec4655a83d3fbabce Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Sat, 14 Mar 2015 12:52:56 +0200 Subject: [PATCH 06/11] [FIX] make explicit xml defining --- web_last_viewed_records/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_last_viewed_records/__openerp__.py b/web_last_viewed_records/__openerp__.py index 52ce65563..043e40ad7 100644 --- a/web_last_viewed_records/__openerp__.py +++ b/web_last_viewed_records/__openerp__.py @@ -9,7 +9,7 @@ 'views.xml', ], 'qweb': [ - "static/src/xml/*.xml", + "static/src/xml/main.xml", ], 'installable': True } From e81a2c44bfd0f8f6541abbb235865d87e1337d91 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Sat, 14 Mar 2015 12:54:59 +0200 Subject: [PATCH 07/11] [IMP] use Font Awesome instead of Entypo font for model icons --- .../static/src/css/main.css | 2 - web_last_viewed_records/static/src/js/main.js | 42 ++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/web_last_viewed_records/static/src/css/main.css b/web_last_viewed_records/static/src/css/main.css index 7529374db..48cfcf20a 100644 --- a/web_last_viewed_records/static/src/css/main.css +++ b/web_last_viewed_records/static/src/css/main.css @@ -40,6 +40,4 @@ content: "f"; } .oe_last_viewed_icon{ - font-family: "entypoRegular" !important; - font-size: 1.8em; } \ No newline at end of file diff --git a/web_last_viewed_records/static/src/js/main.js b/web_last_viewed_records/static/src/js/main.js index 1d20925e7..80d8b17c8 100644 --- a/web_last_viewed_records/static/src/js/main.js +++ b/web_last_viewed_records/static/src/js/main.js @@ -47,25 +47,29 @@ openerp.web_last_viewed_records = function(instance){ save_last_viewed_history: function(data){ localStorage[this.last_viewed_history_var] = JSON.stringify(data); }, - // icon map: http://bistro.convergencecms.co/entypo + // icon map: http://fortawesome.github.io/Font-Awesome/icons/ _model2icon: { - 'res.partner':'+', - 'crm.lead':'4', - 'sale.order':'l', - 'account.analytic.account':'7', - 'crm.phonecall':'!', - 'hr.employee':'.', - 'hr.applicant':'-', - 'project.project':'t', - 'project.task':'W', - 'account.invoice':'h', - 'ir.module.module':'Z', - 'hr_timesheet_sheet.sheet': 'N', - 'res.groups': ',', - 'res.company': '_', - 'res.user': 'ó', - 'gamification.challenge':'è', - 'gamification.badge':'8', + 'account.analytic.account':'fa-book', + 'account.invoice':'fa-pencil-square-o', + 'calendar.event':'fa-calendar', + 'crm.lead':'fa-star', + 'crm.phonecall':'fa-phone', + 'hr.employee':'fa-male', + 'hr.payslip':'fa-money', + 'hr_timesheet_sheet.sheet': 'fa-clock-o', + 'ir.attachment': 'fa-file-o', + 'ir.module.module':'fa-plus-circle', + 'product.product': 'fa-sitemap', + 'project.issue':'fa-bug', + 'project.project':'fa-folder', + 'project.task':'fa-tasks', + 'purchase.order':'fa-shopping-cart', + 'purchase.order.line':'fa-shopping-cart', + 'res.company': 'fa-building-o', + 'res.groups': 'fa-users', + 'res.partner':'fa-user', + 'res.user': 'fa-user-plus', + 'sale.order':'fa-strikethrough', }, get_last_viewed_title: function(){ var titles = []; @@ -82,7 +86,7 @@ openerp.web_last_viewed_records = function(instance){ if (!icon && /\.settings/.test(model)) icon = 'c'; if (icon) - icon = _.str.sprintf('%s', icon); + icon = _.str.sprintf('', icon); titles.push(_.str.sprintf('%s %s ', title, url, From 0d0364e586fe4507d615d34bc2ff67c77611bc7a Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Mon, 16 Mar 2015 12:36:33 +0200 Subject: [PATCH 08/11] [FIX] delete unused variables --- web_last_viewed_records/static/src/js/main.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/web_last_viewed_records/static/src/js/main.js b/web_last_viewed_records/static/src/js/main.js index 80d8b17c8..59efd8d49 100644 --- a/web_last_viewed_records/static/src/js/main.js +++ b/web_last_viewed_records/static/src/js/main.js @@ -1,7 +1,4 @@ openerp.web_last_viewed_records = function(instance){ - var QWeb = instance.web.qweb; - var _t = instance.web._t; - instance.web.ActionManager.include({ last_viewed_history_var: 'odoo_last_viewed', last_viewed_history_size: 8, From 2505429dc9965a2ede89e4ede2c812e4b6579825 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Mon, 16 Mar 2015 12:42:53 +0200 Subject: [PATCH 09/11] clean xml indents --- .../static/src/xml/main.xml | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/web_last_viewed_records/static/src/xml/main.xml b/web_last_viewed_records/static/src/xml/main.xml index b19c40ef7..d2bcaa93a 100644 --- a/web_last_viewed_records/static/src/xml/main.xml +++ b/web_last_viewed_records/static/src/xml/main.xml @@ -1,24 +1,23 @@ - + - - +
- - - + + + - - - - - - - - - - - + + + + + + + + + + + From 97332bcd6406c177bb6a1f627fb38ae055a26829 Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Mon, 16 Mar 2015 12:57:49 +0200 Subject: [PATCH 10/11] Check existence of a localStorage variable. In browsers without localStorage variable links to viewed records are stored only for current browser session (i.e. until user close browser tab) --- web_last_viewed_records/static/src/js/main.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web_last_viewed_records/static/src/js/main.js b/web_last_viewed_records/static/src/js/main.js index 59efd8d49..2da84b1b5 100644 --- a/web_last_viewed_records/static/src/js/main.js +++ b/web_last_viewed_records/static/src/js/main.js @@ -1,4 +1,9 @@ openerp.web_last_viewed_records = function(instance){ + var localStorage = {}; + if (typeof window.localStorage !== "undefined"){ + localStorage = window.localStorage; + } + instance.web.ActionManager.include({ last_viewed_history_var: 'odoo_last_viewed', last_viewed_history_size: 8, From d53959772916e69570a9b2ebd3fb3d7dfb7a51ae Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Tue, 17 Mar 2015 13:21:18 +0200 Subject: [PATCH 11/11] [FIX] do FontAwesome icon's display property to inline instead of inline-block, because nbsp symbol doesn't work with inline-block --- web_last_viewed_records/static/src/css/main.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web_last_viewed_records/static/src/css/main.css b/web_last_viewed_records/static/src/css/main.css index 48cfcf20a..d9ae9a363 100644 --- a/web_last_viewed_records/static/src/css/main.css +++ b/web_last_viewed_records/static/src/css/main.css @@ -39,5 +39,6 @@ .openerp .oe_last_viewed_item .diagram:after { content: "f"; } -.oe_last_viewed_icon{ +.oe_last_viewed_icon.fa{ + display: inline; } \ No newline at end of file