orbeon / orbeon-forms

Orbeon Forms is an open source web forms solution. It includes an XForms engine, the Form Builder web-based form editor, and the Form Runner runtime.
http://www.orbeon.com/
GNU Lesser General Public License v2.1
511 stars 220 forks source link

Summary page Excel export: consider formatting numbers #6330

Open ebruchez opened 1 month ago

ebruchez commented 1 month ago

Following #6323.

Right now, they are just output as is.

ebruchez commented 1 month ago

number.xbl uses this to compute the formatted value:

string-join(
    (
        fr:component-param-value('prefix'),
        NumberSupport:getDisplayValueJava(
            xxf:binding('fr-number'),
            fr:component-param-value('decimal-separator'),
            fr:component-param-value('grouping-separator'),
            fr:component-param-value('prefix'),
            fr:component-param-value('digits-after-decimal'),
            string(fr:component-param-value('round-when-formatting')) = 'true',
            string(fr:component-param-value('round-when-storing'))    = 'true'
        ),
        fr:component-param-value('suffix')
    ),
    ' '
)
ebruchez commented 1 month ago

Ideally, the Summary page/export should obtain the field's format information as well, but we don't have a function to do this yet.

We could easily reuse componentParamValue(), but this would require having a PartAnalysis available. On the Summary page, this is not the case. The static state of the form should/could be in the static state cache, but we don't have a way to know or obtain this information right now!

Could we:

Now the above is not even that great, because the format of the value is known by the component at runtime, and it could ue xxbl:format but not necessarily.

Other solutions:

  1. Reimplement that logic in the Summary page.
  2. Have Form Builder add format information at design time for use by the Summary page later.
  3. Have the Summary page run a small xxf:dynamic with concrete instances of the fields, and ask them for their formats. This could be costly.
ebruchez commented 1 month ago

fr:time does it better: the configured format is on the control as output-format="[h01]:[m] [PN,2-2]". While for fr:number, each component is individually set on the control, as round-when-formatting="true" grouping-separator="'", etc.

The idea for fr:time was that we didn't think that overriding individual components made sense, so they are all together.

If the component or Form Builder also output an output-format, or just switched to it, the Summary page's job would be easier. We could standardize on output-format. This should include:

ebruchez commented 1 month ago

Reaching the conclusion that creating an xxf:dynamic might be the cleanest and most versatile solution for the Summary page! This would also avoid special-casing controls in the Summary page as we do now.

However, for the Excel export, we are not running a form, so we wouldn't be able to do that. The Summary page could pass the formats, if it can somehow extract them from the running form. However, if we were to ever want to publicly expose a separate Summary Page Excel Export API endpoint, we wouldn't be able to automatically determine the formats.

ebruchez commented 1 month ago

Tasks: