Browse Source
Merge pull request #390 from savoirfairelinux/8.0_web_graph_sort
Merge pull request #390 from savoirfairelinux/8.0_web_graph_sort
[8.0] Add web_graph_sortpull/408/head
Sylvain LE GAL
8 years ago
committed by
GitHub
7 changed files with 257 additions and 0 deletions
-
68web_graph_sort/README.rst
-
4web_graph_sort/__init__.py
-
22web_graph_sort/__openerp__.py
-
BINweb_graph_sort/static/description/icon.png
-
29web_graph_sort/static/src/css/web_graph_sort.css
-
124web_graph_sort/static/src/js/web_graph_sort.js
-
10web_graph_sort/views/web_graph_sort.xml
@ -0,0 +1,68 @@ |
|||
.. 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 any pivot table. |
|||
|
|||
For example, if you have the invoicing module installed, go to Reporting -> Accounting -> Invoice Analysis |
|||
|
|||
#. Click on a column header. The table will be sorted by that column. |
|||
|
|||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas |
|||
:alt: Try me on Runbot |
|||
:target: https://runbot.odoo-community.org/runbot/162/8.0 |
|||
|
|||
Known issues / Roadmap |
|||
====================== |
|||
|
|||
* The columns are sorted according to the sum over the row. If you have multiple |
|||
accounting periods for example, if you click on the column header of the first semester, |
|||
the rows will still be sorted by the total for the year. |
|||
|
|||
Bug Tracker |
|||
=========== |
|||
|
|||
Bugs are tracked on `GitHub Issues |
|||
<https://github.com/OCA/web/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 <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* NDP Systèmes <http://www.ndp-systemes.fr> |
|||
* David Dufresne <david.dufresne@savoirfairelinux.com> |
|||
|
|||
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. |
@ -0,0 +1,4 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2015 NDP Systèmes (<http://www.ndp-systemes.fr>). |
|||
# © 2016 Savoir-faire Linux |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2015 NDP Systèmes (<http://www.ndp-systemes.fr>). |
|||
# © 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': 'Web', |
|||
'depends': ['web_graph'], |
|||
'data': [ |
|||
'views/web_graph_sort.xml', |
|||
], |
|||
'installable': True, |
|||
'auto_install': False, |
|||
} |
After Width: 128 | Height: 128 | Size: 8.2 KiB |
@ -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; |
|||
} |
@ -0,0 +1,124 @@ |
|||
/* |
|||
© 2015 NDP Systèmes (<http://www.ndp-systemes.fr>).
|
|||
© 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 = $('<tr>').append('<th>'); |
|||
var self = this; |
|||
|
|||
var measures = _.unique(_.map(measure_row, function(cell){return cell.text;})); |
|||
var measure_index = _.indexBy(self.measure_list, 'string'); |
|||
|
|||
var first_total_index = measure_row.length - measures.length; |
|||
var column_index = 0; |
|||
|
|||
_.each(measure_row, function (cell) { |
|||
var item = measure_index[cell.text]; |
|||
if(item){ |
|||
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 = $('<th>') |
|||
.addClass('measure_row') |
|||
.addClass('oe_sortable') |
|||
.attr('data-id', data_id) |
|||
.append("<div>" + cell.text + "</div>"); |
|||
|
|||
if (cell.is_bold) { |
|||
$cell.css('font-weight', 'bold'); |
|||
} |
|||
|
|||
if ( |
|||
column_index >= first_total_index && |
|||
self.pivot.sort !== null && |
|||
self.pivot.sort[0].indexOf(item.field) >= 0 |
|||
) { |
|||
$cell.addClass((self.pivot.sort[0].indexOf('-') === -1) ? "sortdown": "sortup"); |
|||
} |
|||
column_index += 1; |
|||
} |
|||
$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; |
|||
}); |
|||
}); |
|||
} |
|||
}); |
|||
}; |
@ -0,0 +1,10 @@ |
|||
<openerp> |
|||
<data> |
|||
<template id="assets_backend" name="web_graph_sort assets" inherit_id="web.assets_backend"> |
|||
<xpath expr="." position="inside"> |
|||
<link rel="stylesheet" href="/web_graph_sort/static/src/css/web_graph_sort.css"/> |
|||
<script type="text/javascript" src="/web_graph_sort/static/src/js/web_graph_sort.js"></script> |
|||
</xpath> |
|||
</template> |
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue