-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[ADD] web_pivot_zoom #440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ADD] web_pivot_zoom #440
Conversation
| @@ -0,0 +1,205 @@ | |||
| //-*- coding: utf-8 -*- | |||
| //© 2016 Therp BV <http://therp.nl> | |||
| //License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you use this syntax?
| ); | ||
| }, | ||
| _web_pivot_zoom_action: function( | ||
| model, domain, current_field, row_header, col_header |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you passing the col_header here if you are not using it later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a precaution for the future - we might need it later, and then it would be a pity to have to change the api. I usually try to make my code extensible by default
| i + self.pivot_options.measures.length | ||
| ]; | ||
| }); | ||
| var model = this.graph_view._web_pivot_zoom[current_field.field] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are using this expression two times, also 4 lines below, can you give it a meaningful name and declare it once instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do that as soon as the the amount of lines to define the function exceeds the amount of lines the function replaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK perhaps it's just a matter of taste, but improving code readibility and adding DRY trumps the number of lines IMO
| row_header = this.pivot.get_header(row_id), | ||
| col_header = this.pivot.get_header(col_id), | ||
| measure_values = this.pivot.get_values( | ||
| Math.min(col_id, row_id), Math.max(col_id, row_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you just use col_id, row_id here? Does it have to be in order of id's, and if yes, can you document why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has nothing to do with database ids, those is how the internal datastructure works: https://github.com/OCA/OCB/blob/8.0/addons/web_graph/static/src/js/pivot_table.js#L88 - I can add a link to that, but I'd expect interested readers to read this piece of code themselves
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there are also no OCA guidelines on documenting code, it's your choice how you do it and my responsibility to study the code and supply you a PR with docstrings on every part.
That said, other contributors and reviewers will be productive on your code much faster if the meaning of a piece of code is self-evident from the naming of the variables and functions, and if that is not possible, carry a small note of explanation. The same way you expect junior OCA contributors to polish their contribution to make things as easy as possible for the senior reviewer, the senior contributor could also strive to make life easier for junior contributors and reviewers - all in the interest of producing better code with less bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right. the thing is that I seriously started a commit addressing that, but what I came up with won't help, because I either reproduced the whole code in natural language, or write too little, and then you need to code anyways.
Now it's just the link above.
| col_headers, col_value, group | ||
| ), | ||
| values = self.get_values( | ||
| Math.min(col.id, row.id), Math.max(col.id, row.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are repeating this trick again here - maybe clearer to define a common function that does this, and comments why it is so?
|
As information, Odoo 10.0 does this in core. |
ed9b571 to
2d3c8d4
Compare
|
There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days. |
Zoom in pivot views
This module was written to allow your users to zoom into cells in pivot views
by simply clicking a cell in question.
Installation
Don't install this module manually, it won't do anything. A module that uses it
will pull it as dependency.
Usage
To use this module, you need to:
. depend on this module
. in your measure elements in your pivot view, declare an options dictionary
as in::
The options dictionary must have a key
modelto inform the module whichmodel should be shown, and a key
domainfor the domain to be used.The domain is subject to evaluation, so you can use the grouped values in
there. Note that if a field is not grouped, it will evaluate as
None, sothe
=?is your friend for expressions refering to the grouped fields.Note that not all field types support the
=?operator. For many2manyfields, you'd have to use a construction like
('many2many_field', many2many_field and '=' or '!=', many2many_field)to simulate this to some degree.
Consult the demo data for an example, there, a graph view is added to the
users model, and clicking cells sends you to partners with the company in
question.
Measures with a configuration enabling zooming will have a small link icon next to the column title.