@idevs/corelib 0.0.78 → 0.0.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,13 +17,7 @@ export declare class CheckboxFormatter implements Formatter {
|
|
|
17
17
|
format(ctx: FormatterContext): string;
|
|
18
18
|
}
|
|
19
19
|
export declare class LookupFormatter implements Formatter {
|
|
20
|
-
items: Array<{
|
|
21
|
-
[key: string]: any;
|
|
22
|
-
}>;
|
|
23
|
-
idField: string;
|
|
24
|
-
textField: string;
|
|
25
20
|
lookupKey: string;
|
|
26
|
-
constructor();
|
|
27
21
|
format(ctx: FormatterContext): string;
|
|
28
22
|
}
|
|
29
23
|
export declare class DateMonthFormatter implements Formatter {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Decorators } from '@serenity-is/corelib';
|
|
8
|
-
import {
|
|
8
|
+
import { getLookup, htmlEncode } from '@serenity-is/corelib/q';
|
|
9
9
|
let ZeroDisplayFormatter = class ZeroDisplayFormatter {
|
|
10
10
|
constructor() {
|
|
11
11
|
this.displayText = '';
|
|
@@ -67,26 +67,24 @@ CheckboxFormatter = __decorate([
|
|
|
67
67
|
], CheckboxFormatter);
|
|
68
68
|
export { CheckboxFormatter };
|
|
69
69
|
let LookupFormatter = class LookupFormatter {
|
|
70
|
-
constructor() {
|
|
71
|
-
getLookupAsync(this.lookupKey).then(data => {
|
|
72
|
-
this.items = data.items;
|
|
73
|
-
this.idField = data.idField;
|
|
74
|
-
this.textField = data.textField;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
70
|
format(ctx) {
|
|
78
71
|
const src = ctx.value;
|
|
79
72
|
if (!src)
|
|
80
73
|
return '';
|
|
81
74
|
if (!this.lookupKey)
|
|
82
75
|
return src;
|
|
76
|
+
const lookup = getLookup(this.lookupKey);
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
const items = lookup.items;
|
|
79
|
+
const idField = lookup.idField;
|
|
80
|
+
const textField = lookup.textField;
|
|
83
81
|
const idList = src.toString().split(',');
|
|
84
82
|
return idList
|
|
85
83
|
.map(x => {
|
|
86
|
-
const g =
|
|
84
|
+
const g = items.find(i => i[idField] == x);
|
|
87
85
|
if (!g)
|
|
88
86
|
return x;
|
|
89
|
-
return htmlEncode(g[
|
|
87
|
+
return htmlEncode(g[textField]);
|
|
90
88
|
})
|
|
91
89
|
.join(', ');
|
|
92
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../src/formatters/formatters.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../src/formatters/formatters.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEjD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAO9D,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAC/B;QACE,IAAI,CAAC,WAAW,GAAG,EAAE,CAAA;IACvB,CAAC;IAKD,MAAM,CAAC,GAAqB;QAC1B,MAAM,GAAG,GAAG,GAAG,CAAC,KAAe,CAAA;QAE/B,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAA;QAC7D,IAAI,KAAK,IAAI,CAAC,EAAE;YACd,OAAO,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;SACpC;QAED,OAAO,UAAU,CAAC,GAAG,CAAC,CAAA;IACxB,CAAC;CACF,CAAA;AAZQ;IADN,UAAU,CAAC,MAAM,EAAE;yDACM;AANf,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EAAE,CAAA;QAEpD,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACvE,CAAC;CACF,CAAA;AAdQ;IADN,UAAU,CAAC,MAAM,EAAE;mDACwB;AAGrC;IADN,UAAU,CAAC,MAAM,EAAE;kDACM;AALf,kBAAkB;IAD9B,UAAU,CAAC,iBAAiB,CAAC,0BAA0B,CAAC;GAC5C,kBAAkB,CAgB9B;SAhBY,kBAAkB;AAkB/B,MAAM,OAAO,eAAe;IAC1B,gEAAgE;IACzD,MAAM,CAAC,IAAI,KAAK,CAAC;CACzB","sourcesContent":["import { Decorators } from '@serenity-is/corelib'\nimport { FormatterContext } from '@serenity-is/sleekgrid'\nimport { getLookup, htmlEncode } from '@serenity-is/corelib/q'\n\nexport type Formatter = {\n format(ctx: FormatterContext): string\n}\n\n@Decorators.registerFormatter('Idevs.ZeroDisplayFormatter')\nexport class ZeroDisplayFormatter implements Formatter {\n constructor() {\n this.displayText = ''\n }\n\n @Decorators.option()\n public displayText: string\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as string\n\n const value = parseFloat(String(src || '0').replace(',', ''))\n if (value == 0) {\n return htmlEncode(this.displayText)\n }\n\n return htmlEncode(src)\n }\n}\n\n@Decorators.registerFormatter('Idevs.CheckboxFormatter')\nexport class CheckboxFormatter implements Formatter {\n constructor() {\n this.cssClass = 'text-center fs-2 text-gray-1'\n this.trueText = '1'\n this.falseText = '0'\n this.trueValueIcon = 'mdi mdi-checkbox-marked-outline'\n this.falseValueIcon = 'mdi mdi-checkbox-blank-outline'\n }\n\n @Decorators.option()\n public trueText: string\n\n @Decorators.option()\n public falseText: string\n\n @Decorators.option()\n public cssClass: string\n\n @Decorators.option()\n public trueValueIcon: string\n\n @Decorators.option()\n public falseValueIcon: string\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as string\n if (src == this.trueText) {\n return `<i class=\"${this.trueValueIcon} ${this.cssClass}\"></i>`\n } else if (src == this.falseText) {\n return `<i class=\"${this.falseValueIcon} ${this.cssClass}\"></i>`\n } else {\n return htmlEncode(src)\n }\n }\n}\n\n@Decorators.registerFormatter('Idevs.LookupFormatter')\nexport class LookupFormatter implements Formatter {\n @Decorators.option()\n public lookupKey: string\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as string\n if (!src) return ''\n\n if (!this.lookupKey) return src\n\n const lookup = getLookup(this.lookupKey)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const items = lookup.items as Array<{ [key: string]: any }>\n const idField = lookup.idField\n const textField = lookup.textField\n const idList = src.toString().split(',')\n\n return idList\n .map(x => {\n const g = items.find(i => i[idField] == x)\n if (!g) return x\n\n return htmlEncode(g[textField])\n })\n .join(', ')\n }\n}\n\n@Decorators.registerFormatter('Idevs.DateMonthFormatter')\nexport class DateMonthFormatter implements Formatter {\n @Decorators.option()\n public display: '2-digit' | 'short' | 'long'\n\n @Decorators.option()\n public locale: 'en' | 'th'\n\n format(ctx: FormatterContext): string {\n const src = ctx.value as number\n if (!src) return ''\n\n const locale = this.locale ?? 'en'\n const options = { month: this.display ?? '2-digit' }\n\n return new Date(2000, src - 1, 1).toLocaleDateString(locale, options)\n }\n}\n\nexport class idevsFormatters {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n public static load() { }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Decorators } from '@serenity-is/corelib'
|
|
2
2
|
import { FormatterContext } from '@serenity-is/sleekgrid'
|
|
3
|
-
import {
|
|
3
|
+
import { getLookup, htmlEncode } from '@serenity-is/corelib/q'
|
|
4
4
|
|
|
5
5
|
export type Formatter = {
|
|
6
6
|
format(ctx: FormatterContext): string
|
|
@@ -66,36 +66,28 @@ export class CheckboxFormatter implements Formatter {
|
|
|
66
66
|
|
|
67
67
|
@Decorators.registerFormatter('Idevs.LookupFormatter')
|
|
68
68
|
export class LookupFormatter implements Formatter {
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
-
items: Array<{ [key: string]: any }>
|
|
71
|
-
idField: string
|
|
72
|
-
textField: string
|
|
73
|
-
|
|
74
69
|
@Decorators.option()
|
|
75
70
|
public lookupKey: string
|
|
76
71
|
|
|
77
|
-
constructor() {
|
|
78
|
-
getLookupAsync(this.lookupKey).then(data => {
|
|
79
|
-
this.items = data.items
|
|
80
|
-
this.idField = data.idField
|
|
81
|
-
this.textField = data.textField
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
|
|
85
72
|
format(ctx: FormatterContext): string {
|
|
86
73
|
const src = ctx.value as string
|
|
87
74
|
if (!src) return ''
|
|
88
75
|
|
|
89
76
|
if (!this.lookupKey) return src
|
|
90
77
|
|
|
78
|
+
const lookup = getLookup(this.lookupKey)
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
+
const items = lookup.items as Array<{ [key: string]: any }>
|
|
81
|
+
const idField = lookup.idField
|
|
82
|
+
const textField = lookup.textField
|
|
91
83
|
const idList = src.toString().split(',')
|
|
92
84
|
|
|
93
85
|
return idList
|
|
94
86
|
.map(x => {
|
|
95
|
-
const g =
|
|
87
|
+
const g = items.find(i => i[idField] == x)
|
|
96
88
|
if (!g) return x
|
|
97
89
|
|
|
98
|
-
return htmlEncode(g[
|
|
90
|
+
return htmlEncode(g[textField])
|
|
99
91
|
})
|
|
100
92
|
.join(', ')
|
|
101
93
|
}
|