dufresnedavid
8 years ago
7 changed files with 234 additions and 0 deletions
-
57web_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
-
112web_graph_sort/static/src/js/web_graph_sort.js
-
10web_graph_sort/views/web_graph_sort.xml
@ -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 |
||||
|
<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': 'Technical', |
||||
|
'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,112 @@ |
|||||
|
/* |
||||
|
© 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; |
||||
|
_.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 = $('<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 (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; |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
}); |
||||
|
}; |
@ -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