Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#1272 closed enhancement (fixed)

Add support for using Formatters to SimpleExporter (aka. table exporter)

Reported by: Nicklas Nordborg Owned by: Nicklas Nordborg
Priority: critical Milestone: BASE 2.12
Component: web Version:
Keywords: Cc:

Description

The typical use case for a Formatter is to format a raw value into a nice displayable value. It is currently used on several list pages to format dates and numbers and to add color-coding to some values. A formatter can also be used as a value-converter that convert between units.

Currently, we have a problem with the SimpleExporter? in that it is limited to output the raw values only. This is usually not a problem but, for example, in ticket #1266 there is the problem with different internal and external coordinate system for BASE. It would be nice to have the TableExporter? to output A1,B2,C3 etc. instead of [0,0],[1,1],[2,2]. This would be possible if we could tell the SimpleExporter? to use certain Formatter:s.

I am thinking that this could be done from the index.jsp pages that already passes along the main query for generating the table. Something like this:

ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
final ItemQuery<Sample> query = Sample.getQuery();
cc.configureQuery(query, true);
cc.setQuery(query);
cc.setObject("formatter.bioWell.row", new WellRowFormatter());    // new code
cc.setObject("formatter.bioWell.row", new WellColumnFormatter()); // new code

And then, in the SimpleExporter?:

for (String column : columns)
{
  Object possibleFormatter = cc.getObject("formatter." + column);  // new code
  Formatter formatter = possibleFormatter instanceof Formatter ?   // new code
    (Formatter)possibleFormatter : defaultFormatter;               // new code

  ExportedProperty ep = ExportedProperty.parse(dc, column, columnPrefix, 
     annotatable, formatter, sameUnits);
  exportedProperties.add(ep);
  properties.add(ep.name);
}

The same technique can possible also be used to solve the export of child items discussed in ticket #1128. In that case the formatter of course need to be a lot more complex. Among other things it must contain the query that is needed to load the correct child items.

Change History (6)

comment:1 Changed 12 years ago by Jari Häkkinen

Would this also target the issue discussed in ticket:1259?

comment:2 Changed 12 years ago by Nicklas Nordborg

Yes. I am re-opening #1259.

comment:3 Changed 12 years ago by Nicklas Nordborg

Owner: changed from everyone to Nicklas Nordborg
Priority: majorcritical
Status: newassigned

comment:4 Changed 12 years ago by Nicklas Nordborg

Resolution: fixed
Status: assignedclosed

(In [4855]) Fixes #1272: Add support for using Formatters to SimpleExporter? (aka. table exporter)

Formatters should be stored in the current ItemContext? object as:

ItemContext.setObject("export.formatter.<propertyname>", formatter);

where <propertyname> is the name of the property that are exported. The formatter is cleared after the export and if the same context is used again a new formatter needs to be specified.

comment:5 Changed 12 years ago by Nicklas Nordborg

(In [4856]) References #1266, #1272: Bioplate coordinates are numbers but it would be better to have character-number pairs

A test of #1272. Fixes the export of wells from the Biomaterial LIMS -> Bioplates -> Biowell tab.

comment:6 Changed 12 years ago by Nicklas Nordborg

(In [4858]) References #1266, #1272: Bioplate coordinates are numbers but it would be better to have character-number pairs

A test of #1272. Fixes the display of well coordinates in the list on Biomaterial LIMS -> Bioplates -> Biowell tab.

Note: See TracTickets for help on using tickets.