Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@hbrunn
Copy link
Member

@hbrunn hbrunn commented Oct 12, 2016

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 model to inform the module which
model should be shown, and a key domain for 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, so
the =? is your friend for expressions refering to the grouped fields.

Note that not all field types support the =? operator. For many2many
fields, 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.

@hbrunn hbrunn added this to the 8.0 milestone Oct 12, 2016
@@ -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).

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

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?

Copy link
Member Author

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]

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?

Copy link
Member Author

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

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)

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?

Copy link
Member Author

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

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.

Copy link
Member Author

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)

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?

@pedrobaeza
Copy link
Member

As information, Odoo 10.0 does this in core.

@hbrunn hbrunn force-pushed the 8.0-web_pivot_zoom branch from ed9b571 to 2d3c8d4 Compare November 26, 2019 17:12
@github-actions
Copy link

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.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Dec 12, 2021
@github-actions github-actions bot closed this Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review stale PR/Issue without recent activity, it'll be soon closed automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants