Skip to content

Commit 3144c37

Browse files
committed
[Ui] Display formatted numerics in table and text-field-read-reactive
& fix suffix display in text-field-read-reactive
1 parent 3c1e5d8 commit 3144c37

File tree

3 files changed

+62
-15
lines changed

3 files changed

+62
-15
lines changed

vertigo-ui/src/main/java/io/vertigo/ui/impl/springmvc/util/UiUtil.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import io.vertigo.core.lang.WrappedException;
4242
import io.vertigo.core.locale.LocaleManager;
4343
import io.vertigo.core.node.Node;
44+
import io.vertigo.core.util.StringUtil;
4445
import io.vertigo.datamodel.data.definitions.DataDefinition;
4546
import io.vertigo.datamodel.data.definitions.DataField;
4647
import io.vertigo.datamodel.smarttype.SmartTypeManager;
@@ -351,7 +352,7 @@ public static String getIdField(final String uiListKey) {
351352
throw new VSystemException("Id field (or key field) must be set on the definition for entity '{0}' (needed to display the list '{1}' from context).", dtDefinition, uiListKey);
352353
}
353354

354-
return idFieldOpt.isPresent()?idFieldOpt.get().name():keyFieldOpt.get().name();
355+
return idFieldOpt.isPresent() ? idFieldOpt.get().name() : keyFieldOpt.get().name();
355356
}
356357

357358
/**
@@ -472,4 +473,34 @@ private static DataField getDataField(final String fieldPath) {
472473
return dtDefinition.getField(fieldName);
473474

474475
}
476+
477+
/**
478+
* Resolve the field name to be displayed, numeric fields use the formatted version with _fmt suffix.
479+
*
480+
* @param object the object name in the context
481+
* @param field the field name of the object
482+
* @return the resolved field name
483+
*/
484+
public static String resolveDisplayField(final String object, final String field) {
485+
if (StringUtil.isBlank(object) || StringUtil.isBlank(field)) {
486+
return null;
487+
}
488+
489+
if (field.contains("_")) {
490+
return field; // we don't modify the field if it already contains a modifier
491+
}
492+
493+
final var dataField = getDataField(object + "." + field);
494+
final var basicType = dataField.smartTypeDefinition().getBasicType();
495+
496+
switch (basicType) {
497+
case BigDecimal:
498+
case Double:
499+
case Integer:
500+
case Long:
501+
return field + "_fmt";
502+
default:
503+
return field;
504+
}
505+
}
475506
}

vertigo-ui/src/main/resources/io/vertigo/ui/components/inputs/text-field.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
</th:block>
4141
<th:block th:fragment="text-field-read-reactive(object, field, rowIndex, label, suffix, required, input_attrs, label_attrs)"
4242
th:assert="${object} != null and ${field} != null"
43-
th:with="mySuffix=${model.util.smartTypeUnit(object, field, suffix)}">
44-
<vu:include-data object="${object}" field="${field}"/>
43+
th:with="myDisplayField=${model.util.resolveDisplayField(object, field)},
44+
mySuffix=${model.util.smartTypeUnit(object, field, suffix)}">
45+
<vu:include-data object="${object}" field="${myDisplayField}"/>
4546
<vu:label-read label=${label} label_attrs="${label_attrs}" >
46-
<span th:attr="__${input_attrs}__" >{{[[${model.util.vueDataKey(object, field, rowIndex)}]]}}</span><span th:if="${mySuffix!=''}" th:v-if="|${model.util.contextGet(object, field, rowIndex)}!=''|" vu:text="${mySuffix}"></span>
47+
<span th:attr="__${input_attrs}__" >{{[[${model.util.vueDataKey(object, myDisplayField, rowIndex)}]]}}</span><template th:if="${mySuffix!=null}" th:v-if="|${model.util.vueDataKey(object, myDisplayField, rowIndex)} != null && ${model.util.vueDataKey(object, myDisplayField, rowIndex)} != ''|"><span vu:text="${mySuffix}"></span></template>
4748
</vu:label-read>
4849
</th:block>
Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1-
<th:block th:fragment="column-table(list, field, name, label, align, sortable, datetimeFormat, class, td_attrs)" vu:alias="column" vu:selector="${renderTableAsGrid == null || !renderTableAsGrid }"
2-
th:assert="${(field != null) or (name != null and label != null)}"
3-
th:with="columnName=${name != null ? name : field}, columnLabel=${label != null ? label : model.util.label(list + '.' + field)}, columnAlign=${model.util.smartTypeAlign(list, field, align)}, columnClass=${model.util.smartTypeCss(list, field, class, 'col_'+name)}, columnSortable=${sortable != null ? sortable : (field != null) }">
4-
<th:block th:with="objectKey=${model.vContext['componentStates']['__${componentId}__'].addObjectToList('columns', {'name': columnName, 'field': field, 'label': columnLabel, 'align': columnAlign, 'sortable': (modifiableTable!=null?false:columnSortable), 'classes':(class?:columnClass), 'headerClasses':(class?:columnClass) })},
1+
<th:block th:fragment="column-table(list, field, name, label, align, sortable, sortField, datetimeFormat, class, td_attrs)"
2+
vu:alias="column"
3+
vu:selector="${renderTableAsGrid == null || !renderTableAsGrid }"
4+
th:assert="${(field != null) or (name != null and label != null)}"
5+
th:with="columnName=${name != null ? name : field},
6+
columnLabel=${label != null ? label : model.util.label(list + '.' + field)},
7+
columnAlign=${model.util.smartTypeAlign(list, field, align)},
8+
columnClass=${model.util.smartTypeCss(list, field, class, 'col_'+name)},
9+
columnSortable=${sortable != null ? sortable : (field != null) },
10+
mySortField=${sortField?:field},
11+
myDisplayField=${model.util.resolveDisplayField(list, field)},
12+
mySuffix=${model.util.smartTypeUnit(list, field, null)}">
13+
<th:block th:with="objectKey=${model.vContext['componentStates']['__${componentId}__'].addObjectToList('columns', {'name': columnName, 'field': mySortField, 'label': columnLabel, 'align': columnAlign, 'sortable': (modifiableTable!=null?false:columnSortable), 'classes':(class?:columnClass), 'headerClasses':(class?:columnClass) })},
514
myDatetimeFormat=${datetimeFormat?:(field !=null ? model.util.getUiDatetimeFormat(list + '.' + field) : null)}">
615
<th:block th:if="${myDatetimeFormat != null}" th:attr="datetimeFormatKey=${objectKey.put('datetimeFormat', myDatetimeFormat)}" th:remove="all"></th:block>
716
</th:block>
8-
<vu:include-data th:if="${field != null}" object="${list}" field="${field}"/>
17+
<vu:include-data th:if="${myDisplayField != null}" object="${list}" field="${myDisplayField}"/>
18+
<vu:include-data th:if="${mySortField != null && mySortField != myDisplayField}" object="${list}" field="${mySortField}"/>
919
<q-td th:key="${columnName}" :props="props" th:with="label=null" th:attr="__${td_attrs}__" >
10-
<vu:content><th:block th:if="${field != null}">{{ props.row.[[${field}]] }}</th:block></vu:content><!--/* Default content */-->
20+
<vu:content><th:block th:if="${field != null}">{{ props.row.[[${myDisplayField}]] }}</th:block><template th:if="${mySuffix != null}" th:v-if="|props.row['${myDisplayField}'] != null && props.row['${myDisplayField}'] != ''|"><span vu:text="${mySuffix}"></span></template></vu:content><!--/* Default content */-->
1121
</q-td>
1222
</th:block>
1323

14-
<th:block th:fragment="column-grid(list, field, name, label, align, sortable, datetimeFormat, class, td_attrs)" vu:alias="column" vu:selector="${renderTableAsGrid?:false}"
15-
th:assert="${(field != null) or (name != null and label != null)}"
16-
th:with="columnName=${field != null ? field : name }, columnLabel=${label != null ? label : model.util.label('__${list + '.' + field}__')}" >
17-
<vu:include-data th:if="${field != null}" object="${list}" field="${field}"/>
24+
<th:block th:fragment="column-grid(list, field, name, label, align, sortable, sortField, datetimeFormat, class, td_attrs)"
25+
vu:alias="column"
26+
vu:selector="${renderTableAsGrid?:false}"
27+
th:assert="${(field != null) or (name != null and label != null)}"
28+
th:with="columnName=${field != null ? field : name },
29+
columnLabel=${label != null ? label : model.util.label('__${list + '.' + field}__')},
30+
myDisplayField=${model.util.resolveDisplayField(list, field)},
31+
mySuffix=${model.util.smartTypeUnit(list, field, null)}" >
32+
<vu:include-data th:if="${myDisplayField != null}" object="${list}" field="${myDisplayField}"/>
1833
<div class="q-table__grid-item-row" th:attr="__${td_attrs}__" >
1934
<div class="q-table__grid-item-title" vu:text="${columnLabel}"></div>
2035
<div class="q-table__grid-item-value" th:with="label=null">
21-
<vu:content><th:block th:if="${field != null}">{{ props.row.[[${field}]] }}</th:block></vu:content>
36+
<vu:content><th:block th:if="${field != null}">{{ props.row.[[${myDisplayField}]] }}</th:block><template th:if="${mySuffix != null}" th:v-if="|props.row['${myDisplayField}'] != null && props.row['${myDisplayField}'] != ''|"><span vu:text="${mySuffix}"></span></template></vu:content>
2237
</div>
2338
</div>
2439
</th:block>

0 commit comments

Comments
 (0)