diff --git a/web_graph_sort/README.rst b/web_graph_sort/README.rst new file mode 100644 index 00000000..cfbfa110 --- /dev/null +++ b/web_graph_sort/README.rst @@ -0,0 +1,57 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============== +Web Graph Sort +============== + +This module allows to sort pivot tables. + +Usage +===== + +To use this module, you need to: + +#. Go to ... + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/web/8.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* NDP Systèmes +* David Dufresne + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://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 https://odoo-community.org. diff --git a/web_graph_sort/__init__.py b/web_graph_sort/__init__.py new file mode 100644 index 00000000..e855da69 --- /dev/null +++ b/web_graph_sort/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © 2015 NDP Systèmes (). +# © 2016 Savoir-faire Linux +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/web_graph_sort/__openerp__.py b/web_graph_sort/__openerp__.py new file mode 100644 index 00000000..96f6614c --- /dev/null +++ b/web_graph_sort/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2015 NDP Systèmes (). +# © 2016 Savoir-faire Linux +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': "Web Graph Sort", + 'version': '8.0.1.0.0', + 'author': ( + "NDP Systèmes, " + "Savoir-faire Linux, " + "Odoo Community Association (OCA)" + ), + 'license': 'AGPL-3', + 'category': 'Technical', + 'depends': ['web_graph'], + 'data': [ + 'views/web_graph_sort.xml', + ], + 'installable': True, + 'auto_install': False, +} diff --git a/web_graph_sort/static/description/icon.png b/web_graph_sort/static/description/icon.png new file mode 100644 index 00000000..243a194d Binary files /dev/null and b/web_graph_sort/static/description/icon.png differ diff --git a/web_graph_sort/static/src/css/web_graph_sort.css b/web_graph_sort/static/src/css/web_graph_sort.css new file mode 100644 index 00000000..50d04f93 --- /dev/null +++ b/web_graph_sort/static/src/css/web_graph_sort.css @@ -0,0 +1,29 @@ +.openerp .graph_main_content th.oe_sortable { + cursor: pointer; +} + +.openerp .graph_main_content th.oe_sortable div::after { + border-color: #000 transparent; + border-style: solid; + border-width: 0 4px 4px; + content: ""; + margin-right: 6px; + margin-top: 7px; + visibility: hidden; +} + +.openerp .graph_main_content th.sortup div::after { + float: right; + opacity: 0.6; + visibility: visible; +} + +.openerp .graph_main_content th.sortdown div::after { + border-color: #000 transparent; + border-style: solid solid none; + border-width: 4px 4px medium; + box-shadow: none; + float: right; + opacity: 0.6; + visibility: visible; +} diff --git a/web_graph_sort/static/src/js/web_graph_sort.js b/web_graph_sort/static/src/js/web_graph_sort.js new file mode 100644 index 00000000..4419ae5f --- /dev/null +++ b/web_graph_sort/static/src/js/web_graph_sort.js @@ -0,0 +1,112 @@ +/* + © 2015 NDP Systèmes (). + © 2016 Savoir-faire Linux + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +*/ + +openerp.web_graph_sort = function(instance) { + var _lt = openerp.web._lt; + var _t = openerp.web._t; + + var graph_events = instance.web_graph.Graph.events; + + instance.web_graph.Graph.include({ + + init: function(){ + this.events['click thead th.oe_sortable[data-id]'] = 'sort_by_column'; + this._super.apply(this, arguments); + }, + + draw_measure_row: function (measure_row) { + var $row = $('').append(''); + var self = this; + _.each(measure_row, function (cell) { + _.each(self.measure_list,function(item){ + if(item.string === cell.text) { + var data_id; + if ( + self.pivot.sort !== null && + self.pivot.sort[0].indexOf(item.field) >= 0 && + self.pivot.sort[0].indexOf('-') === -1 + ){ + data_id = "-" + item.field; + } + else { + data_id = item.field; + } + + var $cell = $('') + .addClass('measure_row') + .addClass('oe_sortable') + .attr('data-id', data_id) + .append("
" + cell.text + "
"); + + if (cell.is_bold) { + $cell.css('font-weight', 'bold'); + } + if (self.pivot.sort !== null && self.pivot.sort[0].indexOf(item.field) >= 0) { + $cell.addClass((self.pivot.sort[0].indexOf('-') === -1) ? "sortdown":"sortup"); + } + $row.append($cell); + } + }); + }); + this.$thead.append($row); + }, + + sort_by_column: function (e) { + e.stopPropagation(); + var $column = $(e.currentTarget); + var col_name = $column.data('id'); + this.pivot.sort = [col_name]; + this.pivot.update_data().then(this.proxy('display_data')); + } + }); + + instance.web_graph.PivotTable.include({ + sort : null, + get_groups: function (groupbys, fields, domain) { + var self = this; + var result = this.model.query(_.without(fields, '__count')); + if(this.sort !== null) { + result=result.order_by(this.sort); + } + return result.filter(domain) + .context(this.context) + .lazy(false) + .group_by(groupbys) + .then(function (groups) { + return groups.filter(function (group) { + return group.attributes.length > 0; + }).map(function (group) { + var attrs = group.attributes, + grouped_on = attrs.grouped_on instanceof Array ? attrs.grouped_on : [attrs.grouped_on], + raw_grouped_on = grouped_on.map(function (f) { + return self.raw_field(f); + }); + if (grouped_on.length === 1) { + attrs.value = [attrs.value]; + } + attrs.value = _.range(grouped_on.length).map(function (i) { + var grp = grouped_on[i], + field = self.fields[grp]; + + // This part was modified from original function in the web_graph module. + if (attrs.value[i] === false) { + return _t('Undefined'); + } else if (attrs.value[i] instanceof Array) { + return attrs.value[i][1]; + } else if (field && field.type === 'selection') { + var selected = _.where(field.selection, {0: attrs.value[i]})[0]; + return selected ? selected[1] : attrs.value[i]; + } + return attrs.value[i]; + }); + attrs.aggregates.__count = group.attributes.length; + attrs.grouped_on = raw_grouped_on; + return group; + }); + }); + } + }); +}; diff --git a/web_graph_sort/views/web_graph_sort.xml b/web_graph_sort/views/web_graph_sort.xml new file mode 100644 index 00000000..431624dd --- /dev/null +++ b/web_graph_sort/views/web_graph_sort.xml @@ -0,0 +1,10 @@ + + + + +