Merge lp:~openerp-dev/openobject-server/trunk-graph-schemas-fixes-xmo into lp:openobject-server

Proposed by Xavier (Open ERP)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-server/trunk-graph-schemas-fixes-xmo
Merge into: lp:openobject-server
Diff against target: 126 lines (+94/-11)
1 file modified
openerp/addons/base/rng/view.rng (+94/-11)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-graph-schemas-fixes-xmo
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Pending
Vo Minh Thu Pending
Review via email: mp+60789@code.launchpad.net

Description of the change

Tighten the subset of view schemas for the graph view:

* Explicitly specify possible values for arguments of `graph`
* Remove @color, which is unused and unspecified
* Specify `graph/field` as a self-contained element instead of referring to the global catch-all `field`, and specify the possible values for `field/@operator` and `field/@group`.
* Removed value `**` from `field/@operator` (it does not really seem to have any point). `*` might also be on the chopping block, not sure what use it could be apart from a ghetto `and`.
* graph[not(@type="bar")][field[@group]] does not validate anymore (having a grouping field in a pie chart makes no sense)
* Pie charts can't have more than 2 fields anymore

Issue remaining, but I have not found a way to solve it: theoretically, a bar chart should only accept:
* A base field used as the main axis (for grouping on)
* An optional grouping field (field[@group="True"])
* 1..n aggregate fields (for the columns, with an optional @operator)

My idea was to handle the last two cases with interleave and write something like:

    (element field {
         attribute group { "True" },
         field-attributes }?
    & element field {
         attribute operator { "+" | "*" | "min" | "max" }?
         field-attributes }+)

but it turns out RNG has a restriction against this pattern: you can't interleave elements with the same name.

For now, I've just created a group field, but that means you can put multiple group fields and no aggregate field in a bar graph view, which is not quite optimal.

I have yet to find a solution short of imposing order (e.g. mandating that the grouping field be the last one or the first one in the sequence).

To post a comment you must log in.
3412. By Xavier (Open ERP)

[IMP] there is already a named patterns for handling of access rights attribute(s)

3413. By Xavier (Open ERP)

[IMP] complete reimplementation of the graph schema, not perfect but hell of a lot better than the old one, methinks

Revision history for this message
Vo Minh Thu (thu) wrote :

Mmm... this is the kind of stuff that I would like to see merged but are quite hard to get right without looking through the source of the web client. The merge prop doesn't seem complete, for instance it lacks the graph type='line'.

Unmerged revisions

3413. By Xavier (Open ERP)

[IMP] complete reimplementation of the graph schema, not perfect but hell of a lot better than the old one, methinks

3412. By Xavier (Open ERP)

[IMP] there is already a named patterns for handling of access rights attribute(s)

3411. By Xavier (Open ERP)

[FIX] forgot @groups

3410. By Xavier (Open ERP)

[IMP] extract field definition for graphs, to correctly restrict attribute values

3409. By Xavier (Open ERP)

[REM] graph/html: unspecified, not clear where how it's supposed to rendering, unused. Reintroduce (correctly specified) if needed

3408. By Xavier (Open ERP)

[IMP] better specify range of values for graph/@orientation and graph/@type

3407. By Xavier (Open ERP)

[REM] @color attribute on graph view: unused and unusable

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/rng/view.rng'
2--- openerp/addons/base/rng/view.rng 2010-12-27 10:41:55 +0000
3+++ openerp/addons/base/rng/view.rng 2011-05-13 13:36:00 +0000
4@@ -434,7 +434,6 @@
5 <rng:optional><rng:attribute name="bold"/></rng:optional>
6 <rng:optional><rng:attribute name="avg"/></rng:optional>
7 <rng:optional><rng:attribute name="select"/></rng:optional>
8- <rng:optional><rng:attribute name="group"/></rng:optional>
9 <rng:optional><rng:attribute name="operator"/></rng:optional>
10 <rng:optional><rng:attribute name="colspan"/></rng:optional>
11 <rng:optional><rng:attribute name="nolabel"/></rng:optional>
12@@ -520,20 +519,104 @@
13 </rng:element>
14 </rng:define>
15
16+ <rng:define name="graph-field-attrs">
17+ <!-- attributes common to all graph fields -->
18+ <rng:attribute name="name"/>
19+ <rng:optional>
20+ <rng:attribute name="string"/>
21+ </rng:optional>
22+ <rng:ref name="access_rights"/>
23+ </rng:define>
24+
25+ <rng:define name="graph-field-aggregate">
26+ <!-- Aggregate field, for building pie sections of individual columns -->
27+ <rng:ref name="graph-field-attrs"/>
28+ <rng:optional>
29+ <rng:attribute name="operator">
30+ <rng:choice>
31+ <rng:value>+</rng:value>
32+ <rng:value>*</rng:value>
33+ <rng:value>min</rng:value>
34+ <rng:value>max</rng:value>
35+ </rng:choice>
36+ </rng:attribute>
37+ </rng:optional>
38+ </rng:define>
39+
40 <rng:define name="graph">
41- <rng:element name="graph">
42- <rng:optional><rng:attribute name="string" /></rng:optional>
43- <rng:optional><rng:attribute name="orientation" /></rng:optional>
44- <rng:optional><rng:attribute name="type" /></rng:optional>
45- <rng:optional><rng:attribute name="color"/></rng:optional>
46+ <rng:element name="graph">
47+ <rng:attribute name="string"/>
48+ <rng:choice>
49+ <!-- pie and bar graph types don't make the same allowances
50+ as far as fields go, build them into different patterns
51+ -->
52+ <rng:group>
53+ <!-- pie chart -->
54+ <rng:optional>
55+ <rng:attribute name="type">
56+ <rng:value>pie</rng:value>
57+ </rng:attribute>
58+ </rng:optional>
59+ <rng:element name="field">
60+ <rng:ref name="graph-field-attrs"/>
61+ </rng:element>
62+ <rng:element name="field">
63+ <rng:ref name="graph-field-aggregate"/>
64+ </rng:element>
65+ </rng:group>
66+ <rng:group>
67+ <!-- bar chart -->
68+ <rng:attribute name="type">
69+ <rng:value>bar</rng:value>
70+ </rng:attribute>
71+ <rng:optional>
72+ <rng:attribute name="orientation">
73+ <rng:choice>
74+ <rng:value>vertical</rng:value>
75+ <rng:value>horizontal</rng:value>
76+ </rng:choice>
77+ </rng:attribute>
78+ </rng:optional>
79+ <rng:element name="field">
80+ <rng:ref name="graph-field-attrs"/>
81+ </rng:element>
82+ <!-- the rest of the pattern should be an interleave of a
83+ single group field and 1..n aggregate fields, but
84+ this leads to a restriction error in the RNG
85+ execution: "Element or text conflicts in interleave"
86+
87+ Two elements within the same <rng:interleave> can not
88+ share a name class (Jing yields the clearer error
89+ message 'overlapping element names in operands of
90+ "interleave"'), so it is not possible to interleave
91+ two "field" elements which only differ by their
92+ content (attribute content, at that), which is what
93+ we need here: (field {graph}? & field {aggregate}+)
94+
95+ Instead, we'll go with a oneOrMore choice (which is
96+ not completely correct, as it allows both multiple
97+ group fields and no aggregate field at all).
98+
99+ Need schematron.
100+ -->
101 <rng:oneOrMore>
102- <rng:ref name="field"/>
103+ <rng:choice>
104+ <rng:element name="field">
105+ <rng:ref name="graph-field-aggregate"/>
106+ </rng:element>
107+ <rng:element name="field">
108+ <rng:ref name="graph-field-attrs"/>
109+ <rng:attribute name="group">
110+ <rng:value>True</rng:value>
111+ </rng:attribute>
112+ </rng:element>
113+ </rng:choice>
114 </rng:oneOrMore>
115- <rng:zeroOrMore>
116- <rng:ref name="html"/>
117- </rng:zeroOrMore>
118- </rng:element>
119+ </rng:group>
120+ </rng:choice>
121+ </rng:element>
122 </rng:define>
123+
124
125 <rng:define name="button">
126 <rng:element name="button">