unit values only displayed if given

This commit is contained in:
Gesina Schwalbe 2021-01-16 23:47:05 +01:00
parent bbf9c35a6b
commit 4c902500c9

View file

@ -2,25 +2,32 @@
{{!-- INLINE PARTIAL DEFINITIONS --}} {{!-- INLINE PARTIAL DEFINITIONS --}}
{{!-- ======================================================================== --}} {{!-- ======================================================================== --}}
{{!-- {{!--
!-- Two templates for displaying values with unit. !-- Base template to display a value with unit.
!-- @param unitDatum: the object to display; must have a value and a unit attribute !-- @param unitDatum: the object to display; must have a value and a unit attribute
!-- @param localizationString !-- @param localizationString
!-- @param config: the config object !-- @param unitNames: mapping of allowed unitDatum.unit values to localized unit name
!-- @param unitAbbrs: mapping of allowed unitDatum.unit values to unit abbreviation
--}}
{{#*inline "unit"}}
<div class="unit-data-pair item-num-val"
title="{{localize localizationString}} [{{lookup unitNames unitDatum.unit}}]" >
{{#if unitDatum.value }}
{{unitDatum.value}}{{lookup unitAbbrs unitDatum.unit}}
{{else}}-{{/if}}
</div>
{{/inline}}
{{!--
!-- Two templates based on the "unit" template for displaying values with unit.
!-- Both accept a `config` object holding the unitNames and unitAbbr instead of
!-- directly handing over the latter two.
--}} --}}
{{#*inline "temporalUnit"}} {{#*inline "temporalUnit"}}
<div class="unit-data-pair item-num-val" {{> unit unitNames=config.temporalUnits unitAbbrs=config.temporalUnitsAbbr unitDatum=unitDatum localizationString=localizationString}}
title="{{localize localizationString}} [{{lookup config.temporalUnits unitDatum.unit}}]" >
{{unitDatum.value}}{{lookup config.temporalUnitsAbbr unitDatum.unit}}
</div>
{{/inline}} {{/inline}}
{{#*inline "distanceUnit"}} {{#*inline "distanceUnit"}}
<div class="unit-data-pair item-num-val" {{> unit unitNames=config.distanceUnits unitAbbrs=config.distanceUnitsAbbr unitDatum=unitDatum localizationString=localizationString}}
title="{{localize localizationString}} [{{lookup config.distanceUnits unitDatum.unit}}]" >
{{unitDatum.value}}{{lookup config.distanceUnitsAbbr unitDatum.unit}}
</div>
{{/inline}} {{/inline}}