Skip to content

Commit

Permalink
right-align and format using locale settings numeric values in HTML e…
Browse files Browse the repository at this point in the history
…xport too
  • Loading branch information
Dmitry Barashev committed Jan 21, 2022
1 parent 91c2abf commit acd7d5f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ of the License, or (at your option) any later version.
*/
package org.ganttproject.impex.htmlpdf;

import biz.ganttproject.app.InternationalizationKt;
import biz.ganttproject.core.model.task.TaskDefaultColumn;
import biz.ganttproject.core.table.ColumnList;
import com.google.common.base.Joiner;
Expand Down Expand Up @@ -172,7 +173,8 @@ protected String serializeTask(Task t, int depth) throws Exception {
textElement("duration", myAttrs, String.valueOf(t.getDuration().getLength()), handler);

addAttribute("id", TaskDefaultColumn.COST.getStub().getID(), myAttrs);
textElement("cost", myAttrs, String.valueOf(t.getCost().getValue()), handler);
addAttribute("alignment", "right", myAttrs);
textElement("cost", myAttrs, InternationalizationKt.getNumberFormat().format(t.getCost().getValue()), handler);

addAttribute("id", TaskDefaultColumn.ID.getStub().getID(), myAttrs);
textElement("task-id", myAttrs, String.valueOf(t.getTaskID()), handler);
Expand Down Expand Up @@ -234,8 +236,13 @@ protected String serializeTask(Task t, int depth) throws Exception {
CustomColumnsValues customValues = t.getCustomValues();
for (CustomPropertyDefinition def : taskManager.getCustomPropertyManager().getDefinitions()) {
Object value = customValues.getValue(def);
String valueAsString = value == null ? "" : value.toString();
String valueAsString = value == null ? "" : def.getPropertyClass().isNumeric() ? InternationalizationKt.getNumberFormat().format(value) : value.toString();
addAttribute("id", def.getID(), attrs);
if (def.getPropertyClass().isNumeric()) {
addAttribute("alignment", "right", attrs);
} else {
addAttribute("alignment", "left", attrs);
}
textElement("custom-field", attrs, valueAsString, handler);
}
}
Expand Down Expand Up @@ -284,17 +291,23 @@ protected void writeResources(HumanResourceManager resourceManager, TransformerH
addAttribute("id", "3", attrs);
textElement("phone", attrs, p.getPhone(), handler);
addAttribute("id", "5", attrs);
textElement("rate", attrs, p.getStandardPayRate().toPlainString(), handler);
textElement("rate", attrs, InternationalizationKt.getNumberFormat().format(p.getStandardPayRate()), handler);
addAttribute("id", "6", attrs);
textElement("totalCost", attrs, p.getTotalCost().toPlainString(), handler);
textElement("totalCost", attrs, InternationalizationKt.getNumberFormat().format(p.getTotalCost()), handler);
addAttribute("id", "7", attrs);
textElement("totalLoad", attrs, String.valueOf(p.getTotalLoad()), handler);
textElement("totalLoad", attrs, InternationalizationKt.getNumberFormat().format(p.getTotalLoad()), handler);

List<CustomProperty> customFields = p.getCustomProperties();
for (int j = 0; j < customFields.size(); j++) {
CustomProperty nextProperty = customFields.get(j);
addAttribute("id", nextProperty.getDefinition().getID(), attrs);
String value = nextProperty.getValueAsString();
CustomPropertyDefinition def = nextProperty.getDefinition();
addAttribute("id", def.getID(), attrs);
if (def.getPropertyClass().isNumeric()) {
addAttribute("alignment", "right", attrs);
} else {
addAttribute("alignment", "left", attrs);
}
String value = def.getPropertyClass().isNumeric() ? InternationalizationKt.getNumberFormat().format(nextProperty.getValue()) : nextProperty.getValueAsString();
textElement("custom-field", attrs, value, handler);
}
endPrefixedElement("resource", handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ h5.header {
<xsl:variable name="field-id" select="@id" />
<td valign="top" class="cell">
<xsl:for-each select='$current-resource//*[@id=$field-id]'>
<xsl:value-of select="text()" />
<div style="margin: 0; padding: 0; text-align: {@alignment};">
<xsl:value-of select="text()" />
</div>
</xsl:for-each>
</td>
</xsl:for-each>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ h5.header {
<td valign="top" class="cell">
<div style="margin:0; padding:0; padding-left:{$indent}">
<xsl:for-each select='$current-task//*[@id=$field-id]'>
<div style="margin: 0; padding: 0;">
<div style="margin: 0; padding: 0; text-align: {@alignment};">
<xsl:value-of select="text()" />
</div>
<xsl:if test="$field-id='tpd3' and $current-task/notes/text()">
Expand Down

0 comments on commit acd7d5f

Please sign in to comment.