SUPPORT-8413: replace various suffix text formatter with ts script; fix pages
This commit is contained in:
parent
87ca9879a0
commit
1c9236460a
4 changed files with 192 additions and 139 deletions
|
|
@ -1,38 +0,0 @@
|
|||
package ru.micord.ervu.component.formatter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ru.cg.webbpm.modules.standard_annotations.validation.NotNull;
|
||||
|
||||
/**
|
||||
* @author gulnaz
|
||||
*/
|
||||
// A field formatter for integer values appending a suffix
|
||||
// depending on the last digit of the value
|
||||
public class VariousSuffixFieldFormatter implements FieldFormatter<String, Integer> {
|
||||
|
||||
@NotNull
|
||||
public String oneDigitSuffix;
|
||||
|
||||
@NotNull
|
||||
public String fromTwoToFourDigitSuffix;
|
||||
|
||||
@NotNull
|
||||
public String otherDigitSuffix;
|
||||
|
||||
private final List<Integer> excludedNumbers = List.of(11, 12, 13, 14);
|
||||
|
||||
@Override
|
||||
public String format(Integer value) {
|
||||
int lastDigit = Math.abs(value) % 10;
|
||||
int lastDigits = Math.abs(value) % 100;
|
||||
String suffix = excludedNumbers.contains(lastDigits)
|
||||
? otherDigitSuffix
|
||||
: lastDigit == 1
|
||||
? oneDigitSuffix
|
||||
: lastDigit > 1 && lastDigit < 5
|
||||
? fromTwoToFourDigitSuffix
|
||||
: otherDigitSuffix;
|
||||
return value + " " + suffix;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
import {NotNull, TextFormatter, Visible} from "@webbpm/base-package";
|
||||
|
||||
// A text formatter for integer values appending a prefix and/or suffix
|
||||
// depending on the last digit of the value
|
||||
export class NumberPrefixSuffixTextFormatter implements TextFormatter {
|
||||
|
||||
@NotNull()
|
||||
public hasPrefix: boolean;
|
||||
|
||||
@Visible("hasPrefix == true")
|
||||
@NotNull("hasPrefix == true")
|
||||
public oneDigitPrefix: string;
|
||||
@Visible("hasPrefix == true")
|
||||
@NotNull("hasPrefix == true")
|
||||
public otherDigitPrefix: string;
|
||||
|
||||
@NotNull()
|
||||
public hasSuffix: boolean;
|
||||
|
||||
@Visible("hasSuffix == true")
|
||||
@NotNull("hasSuffix == true")
|
||||
public oneDigitSuffix: string;
|
||||
@Visible("hasSuffix == true")
|
||||
@NotNull("hasSuffix == true")
|
||||
public fromTwoToFourDigitSuffix: string;
|
||||
@Visible("hasSuffix == true")
|
||||
@NotNull("hasSuffix == true")
|
||||
public otherDigitSuffix: string;
|
||||
|
||||
private excludedNumbers: number[] = [11, 12, 13, 14];
|
||||
|
||||
format(value: string): string {
|
||||
if (value) {
|
||||
let number = Number.parseInt(value);
|
||||
let lastDigit = Math.abs(number) % 10;
|
||||
let lastDigits = Math.abs(number) % 100;
|
||||
let prefix = "";
|
||||
|
||||
if (this.hasPrefix) {
|
||||
prefix = (this.excludedNumbers.includes(lastDigits)
|
||||
? this.oneDigitPrefix
|
||||
: lastDigit == 1
|
||||
? this.oneDigitPrefix
|
||||
: this.otherDigitPrefix) + " ";
|
||||
}
|
||||
let suffix = "";
|
||||
|
||||
if (this.hasSuffix) {
|
||||
suffix = " " + (this.excludedNumbers.includes(lastDigits)
|
||||
? this.otherDigitSuffix
|
||||
: lastDigit == 1
|
||||
? this.oneDigitSuffix
|
||||
: lastDigit > 1 && lastDigit < 5
|
||||
? this.fromTwoToFourDigitSuffix
|
||||
: this.otherDigitSuffix);
|
||||
}
|
||||
return prefix + value + suffix;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
@ -2010,7 +2010,6 @@
|
|||
<componentRootId>c3fc56e5-4aec-44e3-92ed-5fb7b6a68519</componentRootId>
|
||||
<name>FS - 1.1.2 (Временные меры)</name>
|
||||
<container>true</container>
|
||||
<expanded>false</expanded>
|
||||
<childrenReordered>false</childrenReordered>
|
||||
<scripts id="46f20297-81d1-4786-bb17-2a78ca6fda6f">
|
||||
<properties>
|
||||
|
|
@ -2779,6 +2778,59 @@
|
|||
<simple>null</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>textFormatter</key>
|
||||
<value>
|
||||
<complex>
|
||||
<entry>
|
||||
<key>fromTwoToFourDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"ограничения"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>hasPrefix</key>
|
||||
<value>
|
||||
<simple>true</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>hasSuffix</key>
|
||||
<value>
|
||||
<simple>true</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>oneDigitPrefix</key>
|
||||
<value>
|
||||
<simple>"и еще"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>oneDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"ограничение"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>otherDigitPrefix</key>
|
||||
<value>
|
||||
<simple>"и еще"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>otherDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"ограничений"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
</complex>
|
||||
<implRef type="TS">
|
||||
<className>NumberPrefixSuffixTextFormatter</className>
|
||||
<packageName>ervu.component.text</packageName>
|
||||
</implRef>
|
||||
</value>
|
||||
</entry>
|
||||
</properties>
|
||||
</scripts>
|
||||
<scripts id="737b67e2-295f-4356-a1e1-9419344d8c85"/>
|
||||
|
|
@ -2804,50 +2856,9 @@
|
|||
<entry>
|
||||
<key>formatters</key>
|
||||
<value>
|
||||
<item id="283156ac-c135-4e3c-9c54-ac07253c4b06" removed="false">
|
||||
<value>
|
||||
<complex>
|
||||
<entry>
|
||||
<key>fromTwoToFourDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"ограничения"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>oneDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"ограничение"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>otherDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"ограничений"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
</complex>
|
||||
<implRef type="JAVA">
|
||||
<className>VariousSuffixFieldFormatter</className>
|
||||
<packageName>ru.micord.ervu.component.formatter</packageName>
|
||||
</implRef>
|
||||
</value>
|
||||
</item>
|
||||
<item id="4ffe131f-0f57-4b97-b9c5-8ea18da0d374" removed="false">
|
||||
<value>
|
||||
<complex>
|
||||
<entry>
|
||||
<key>prefix</key>
|
||||
<value>
|
||||
<simple>"и еще"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
</complex>
|
||||
<implRef type="JAVA">
|
||||
<className>TextPrefixFormatter</className>
|
||||
<packageName>ru.micord.ervu.component.formatter</packageName>
|
||||
</implRef>
|
||||
</value>
|
||||
</item>
|
||||
<item id="283156ac-c135-4e3c-9c54-ac07253c4b06" removed="true"/>
|
||||
<item id="4ffe131f-0f57-4b97-b9c5-8ea18da0d374" removed="true"/>
|
||||
<expanded>false</expanded>
|
||||
</value>
|
||||
</entry>
|
||||
</properties>
|
||||
|
|
@ -6142,6 +6153,41 @@
|
|||
<simple>null</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>textFormatter</key>
|
||||
<value>
|
||||
<complex>
|
||||
<entry>
|
||||
<key>fromTwoToFourDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"дня"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>hasSuffix</key>
|
||||
<value>
|
||||
<simple>true</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>oneDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"день"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>otherDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"дней"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
</complex>
|
||||
<implRef type="TS">
|
||||
<className>NumberPrefixSuffixTextFormatter</className>
|
||||
<packageName>ervu.component.text</packageName>
|
||||
</implRef>
|
||||
</value>
|
||||
</entry>
|
||||
</properties>
|
||||
</scripts>
|
||||
<scripts id="737b67e2-295f-4356-a1e1-9419344d8c85"/>
|
||||
|
|
@ -6167,35 +6213,9 @@
|
|||
<entry>
|
||||
<key>formatters</key>
|
||||
<value>
|
||||
<item id="52c3daa2-5186-4611-9fa5-9946142424f0" removed="false">
|
||||
<value>
|
||||
<complex>
|
||||
<entry>
|
||||
<key>fromTwoToFourDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"дня"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>oneDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"день"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>otherDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"дней"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
</complex>
|
||||
<implRef type="JAVA">
|
||||
<className>VariousSuffixFieldFormatter</className>
|
||||
<packageName>ru.micord.ervu.component.formatter</packageName>
|
||||
</implRef>
|
||||
</value>
|
||||
</item>
|
||||
<item id="52c3daa2-5186-4611-9fa5-9946142424f0" removed="true"/>
|
||||
<item id="d614e9fe-d4e5-42c9-85d6-72e964904bc2" removed="true"/>
|
||||
<expanded>false</expanded>
|
||||
</value>
|
||||
</entry>
|
||||
</properties>
|
||||
|
|
|
|||
|
|
@ -2274,6 +2274,41 @@
|
|||
<simple>null</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>textFormatter</key>
|
||||
<value>
|
||||
<complex>
|
||||
<entry>
|
||||
<key>fromTwoToFourDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"дня"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>hasSuffix</key>
|
||||
<value>
|
||||
<simple>true</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>oneDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"день"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>otherDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"дней"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
</complex>
|
||||
<implRef type="TS">
|
||||
<className>NumberPrefixSuffixTextFormatter</className>
|
||||
<packageName>ervu.component.text</packageName>
|
||||
</implRef>
|
||||
</value>
|
||||
</entry>
|
||||
</properties>
|
||||
</scripts>
|
||||
<scripts id="737b67e2-295f-4356-a1e1-9419344d8c85"/>
|
||||
|
|
@ -2299,35 +2334,9 @@
|
|||
<entry>
|
||||
<key>formatters</key>
|
||||
<value>
|
||||
<item id="52c3daa2-5186-4611-9fa5-9946142424f0" removed="false">
|
||||
<value>
|
||||
<complex>
|
||||
<entry>
|
||||
<key>fromTwoToFourDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"дня"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>oneDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"день"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>otherDigitSuffix</key>
|
||||
<value>
|
||||
<simple>"дней"</simple>
|
||||
</value>
|
||||
</entry>
|
||||
</complex>
|
||||
<implRef type="JAVA">
|
||||
<className>VariousSuffixFieldFormatter</className>
|
||||
<packageName>ru.micord.ervu.component.formatter</packageName>
|
||||
</implRef>
|
||||
</value>
|
||||
</item>
|
||||
<item id="52c3daa2-5186-4611-9fa5-9946142424f0" removed="true"/>
|
||||
<item id="d614e9fe-d4e5-42c9-85d6-72e964904bc2" removed="true"/>
|
||||
<expanded>false</expanded>
|
||||
</value>
|
||||
</entry>
|
||||
</properties>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue