@idevs/corelib 0.0.96 → 1.0.0
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.
- package/CHANGELOG.md +737 -0
- package/README.md +221 -24
- package/dist/editors/checkboxButtonEditor.d.ts +3 -1
- package/dist/editors/checkboxButtonEditor.d.ts.map +1 -0
- package/dist/editors/checkboxButtonEditor.js +28 -18
- package/dist/editors/checkboxButtonEditor.js.map +1 -1
- package/dist/editors/dateMonthEditor.d.ts +3 -1
- package/dist/editors/dateMonthEditor.d.ts.map +1 -0
- package/dist/editors/dateMonthEditor.js +14 -7
- package/dist/editors/dateMonthEditor.js.map +1 -1
- package/dist/editors/index.d.ts +2 -1
- package/dist/editors/index.d.ts.map +1 -0
- package/dist/editors/index.js +18 -2
- package/dist/editors/index.js.map +1 -1
- package/dist/formatters/formatters.d.ts +2 -1
- package/dist/formatters/formatters.d.ts.map +1 -0
- package/dist/formatters/formatters.js +39 -25
- package/dist/formatters/formatters.js.map +1 -1
- package/dist/formatters/index.d.ts +2 -1
- package/dist/formatters/index.d.ts.map +1 -0
- package/dist/formatters/index.js +17 -1
- package/dist/formatters/index.js.map +1 -1
- package/dist/globals/index.d.ts +16 -9
- package/dist/globals/index.d.ts.map +1 -0
- package/dist/globals/index.js +65 -105
- package/dist/globals/index.js.map +1 -1
- package/dist/helpers/custom-fonts.d.ts +4 -0
- package/dist/helpers/custom-fonts.d.ts.map +1 -0
- package/dist/helpers/custom-fonts.js +14 -0
- package/dist/helpers/custom-fonts.js.map +1 -0
- package/dist/helpers/dialogHelper.d.ts +6 -9
- package/dist/helpers/dialogHelper.d.ts.map +1 -0
- package/dist/helpers/dialogHelper.js +17 -10
- package/dist/helpers/dialogHelper.js.map +1 -1
- package/dist/helpers/excelExportHelper.d.ts +2 -1
- package/dist/helpers/excelExportHelper.d.ts.map +1 -0
- package/dist/helpers/excelExportHelper.js +7 -4
- package/dist/helpers/excelExportHelper.js.map +1 -1
- package/dist/helpers/gridHelper.d.ts +2 -1
- package/dist/helpers/gridHelper.d.ts.map +1 -0
- package/dist/helpers/gridHelper.js +14 -9
- package/dist/helpers/gridHelper.js.map +1 -1
- package/dist/helpers/index.d.ts +2 -1
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +20 -4
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/pdfExportHelper.d.ts +10 -1
- package/dist/helpers/pdfExportHelper.d.ts.map +1 -0
- package/dist/helpers/pdfExportHelper.js +169 -7
- package/dist/helpers/pdfExportHelper.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -5
- package/dist/index.js.map +1 -1
- package/dist/types/common.d.ts +12 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +3 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/export.d.ts +50 -0
- package/dist/types/export.d.ts.map +1 -0
- package/dist/types/export.js +24 -0
- package/dist/types/export.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/ui/DropdownToolButton.d.ts +2 -1
- package/dist/ui/DropdownToolButton.d.ts.map +1 -0
- package/dist/ui/DropdownToolButton.js +15 -11
- package/dist/ui/DropdownToolButton.js.map +1 -1
- package/dist/ui/ToggleToolButton.d.ts +2 -1
- package/dist/ui/ToggleToolButton.d.ts.map +1 -0
- package/dist/ui/ToggleToolButton.js +7 -3
- package/dist/ui/ToggleToolButton.js.map +1 -1
- package/dist/ui/index.d.ts +2 -1
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +18 -2
- package/dist/ui/index.js.map +1 -1
- package/dist/utils/date.d.ts +16 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +85 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/dom.d.ts +13 -0
- package/dist/utils/dom.d.ts.map +1 -0
- package/dist/utils/dom.js +78 -0
- package/dist/utils/dom.js.map +1 -0
- package/dist/utils/format.d.ts +22 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +100 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +49 -26
- package/dist/ui/ToolDropdownButton.d.ts +0 -49
- package/dist/ui/ToolDropdownButton.js +0 -230
- package/dist/ui/ToolDropdownButton.js.map +0 -1
- package/src/editors/checkboxButtonEditor.ts +0 -184
- package/src/editors/dateMonthEditor.ts +0 -47
- package/src/editors/index.ts +0 -2
- package/src/formatters/formatters.ts +0 -181
- package/src/formatters/index.ts +0 -1
- package/src/globals/index.ts +0 -385
- package/src/helpers/dialogHelper.ts +0 -143
- package/src/helpers/excelExportHelper.ts +0 -29
- package/src/helpers/gridHelper.ts +0 -107
- package/src/helpers/html2pdf.d.ts +0 -19
- package/src/helpers/index.ts +0 -4
- package/src/helpers/pdfExportHelper.ts +0 -63
- package/src/index.ts +0 -5
- package/src/tsconfig.json +0 -29
- package/src/ui/DropdownToolButton.ts +0 -305
- package/src/ui/ToggleToolButton.ts +0 -71
- package/src/ui/index.ts +0 -2
- /package/{css → dist/css}/idevs.dropdown.css +0 -0
- /package/{css → dist/css}/idevs.print.css +0 -0
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
/* eslint-disable @typescript-eslint/adjacent-overload-signatures */
|
|
3
|
-
// reference: https://github-wiki-see.page/m/serenity-is/Serenity/wiki/CheckBox-Group-Editor
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
Decorators,
|
|
7
|
-
EditorProps,
|
|
8
|
-
EditorWidget,
|
|
9
|
-
Enum,
|
|
10
|
-
EnumKeyAttribute,
|
|
11
|
-
EnumTypeRegistry,
|
|
12
|
-
Fluent,
|
|
13
|
-
IReadOnly,
|
|
14
|
-
getCustomAttributes,
|
|
15
|
-
getLookup,
|
|
16
|
-
isEmptyOrNull,
|
|
17
|
-
toId,
|
|
18
|
-
tryGetText,
|
|
19
|
-
} from '@serenity-is/corelib'
|
|
20
|
-
|
|
21
|
-
export type CheckboxButtonEditorOptions = {
|
|
22
|
-
enumKey?: string
|
|
23
|
-
enumType?: any
|
|
24
|
-
lookupKey?: string
|
|
25
|
-
isStringId?: boolean
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@Decorators.registerEditor('CheckboxButtonEditor')
|
|
29
|
-
export class CheckboxButtonEditor<P extends CheckboxButtonEditorOptions = CheckboxButtonEditorOptions>
|
|
30
|
-
extends EditorWidget<P>
|
|
31
|
-
implements IReadOnly
|
|
32
|
-
{
|
|
33
|
-
private _items: Array<{ [key: string]: any }>
|
|
34
|
-
private readonly _idField: string
|
|
35
|
-
private readonly _textField: string
|
|
36
|
-
private readonly _isStringId: boolean
|
|
37
|
-
|
|
38
|
-
static override createDefaultElement() {
|
|
39
|
-
return Fluent('div').getNode()
|
|
40
|
-
}
|
|
41
|
-
declare readonly domNode: HTMLElement
|
|
42
|
-
|
|
43
|
-
constructor(props: EditorProps<P>) {
|
|
44
|
-
super(props)
|
|
45
|
-
|
|
46
|
-
if (isEmptyOrNull(this.options.enumKey) && this.options.enumType == null && isEmptyOrNull(this.options.lookupKey)) {
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this._isStringId = this.options.isStringId
|
|
51
|
-
|
|
52
|
-
if (!isEmptyOrNull(this.options.lookupKey)) {
|
|
53
|
-
const lookup = getLookup(this.options.lookupKey)
|
|
54
|
-
this._idField = lookup.idField
|
|
55
|
-
this._textField = lookup.textField
|
|
56
|
-
this.set_items(lookup.items as Array<{ [key: string]: any }>)
|
|
57
|
-
} else {
|
|
58
|
-
const enumType = this.options.enumType || EnumTypeRegistry.get(this.options.enumKey)
|
|
59
|
-
let enumKey = this.options.enumKey
|
|
60
|
-
|
|
61
|
-
if (enumKey == null && enumType != null) {
|
|
62
|
-
const enumKeyAttr = getCustomAttributes(enumType, EnumKeyAttribute, false)
|
|
63
|
-
if (enumKeyAttr.length > 0) {
|
|
64
|
-
enumKey = enumKeyAttr[0].value
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const values = Enum.getValues(enumType)
|
|
68
|
-
for (const x of values) {
|
|
69
|
-
const name = Enum.toString(enumType, x)
|
|
70
|
-
this.addCheckbox(x.toString(), tryGetText('Enums.' + enumKey + '.' + name) ?? name)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
this.domNode.classList.add('d-flex', 'flex-wrap')
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
protected renderCheckboxes() {
|
|
78
|
-
const childDivs = this.domNode.querySelectorAll('div')
|
|
79
|
-
childDivs.forEach(function (child) {
|
|
80
|
-
this.domNode.removeChild(child)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
for (const item of this._items) {
|
|
84
|
-
const textValue = item[this._textField]
|
|
85
|
-
const text = textValue == null ? '' : textValue.toString()
|
|
86
|
-
const idValue = item[this._idField]
|
|
87
|
-
const id = idValue == null ? '' : idValue.toString()
|
|
88
|
-
this.addCheckbox(id, text)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
protected addCheckbox(value: string, text: string) {
|
|
93
|
-
const div = $('<div class="col-12 col-sm-6 col-md-4 col-xl-3" />')
|
|
94
|
-
const label = $('<label/>').text(text.replace(/, /g, ',').replace(/,/g, ', '))
|
|
95
|
-
$('<input type="checkbox" class="me-2" />')
|
|
96
|
-
.attr('name', this.uniqueName)
|
|
97
|
-
.attr('id', this.uniqueName + '_' + value)
|
|
98
|
-
.attr('value', value)
|
|
99
|
-
.prependTo(label)
|
|
100
|
-
label.appendTo(div)
|
|
101
|
-
div.appendTo(this.domNode)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
get_items(): Array<{ [key: string]: any }> {
|
|
105
|
-
return this._items
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
get items(): Array<{ [key: string]: any }> {
|
|
109
|
-
return this.get_items()
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
set_items(value: Array<{ [key: string]: any }>) {
|
|
113
|
-
this._items = value
|
|
114
|
-
this.renderCheckboxes()
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
set items(v: Array<{ [key: string]: any }>) {
|
|
118
|
-
this.set_items(v)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
get_value() {
|
|
122
|
-
const val: string[] = []
|
|
123
|
-
const inputs = this.domNode.querySelectorAll('input:checked')
|
|
124
|
-
|
|
125
|
-
inputs.forEach((input: HTMLInputElement) => {
|
|
126
|
-
val.push(this._isStringId ? input.value : toId(input.value))
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
return val.join(',')
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
get value(): string {
|
|
133
|
-
return this.get_value()
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
set_value(value: string): void {
|
|
137
|
-
if (value !== this.get_value()) {
|
|
138
|
-
let values: unknown[] = []
|
|
139
|
-
if (!isEmptyOrNull(value)) {
|
|
140
|
-
values = this._isStringId ? value.split(',') : value.split(',').map(p => Number(p))
|
|
141
|
-
}
|
|
142
|
-
const inputs = this.domNode.querySelectorAll<HTMLInputElement>('input')
|
|
143
|
-
inputs.forEach(input => {
|
|
144
|
-
input.checked = false
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
values.forEach(v => {
|
|
148
|
-
const checks = Array.from(inputs).filter(input => (input as HTMLInputElement).value === v)
|
|
149
|
-
if (checks.length > 0) {
|
|
150
|
-
;(checks[0] as HTMLInputElement).checked = true
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
set value(v: string) {
|
|
157
|
-
this.set_value(v)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
get_readOnly(): boolean {
|
|
161
|
-
return this.domNode.getAttribute('disabled') != null
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
set_readOnly(value: boolean): void {
|
|
165
|
-
if (this.get_readOnly() !== value) {
|
|
166
|
-
if (value) {
|
|
167
|
-
this.domNode.setAttribute('disabled', 'disabled')
|
|
168
|
-
this.domNode.querySelectorAll<HTMLInputElement>('input').forEach(input => {
|
|
169
|
-
input.setAttribute('disabled', 'disabled')
|
|
170
|
-
})
|
|
171
|
-
} else {
|
|
172
|
-
this.domNode.removeAttribute('disabled')
|
|
173
|
-
this.domNode.querySelectorAll<HTMLInputElement>('input').forEach(input => {
|
|
174
|
-
input.removeAttribute('disabled')
|
|
175
|
-
})
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export class idevsEditors {
|
|
182
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
183
|
-
public static load() {}
|
|
184
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Decorators, EditorProps, SelectEditor, SelectEditorOptions, indexOf } from '@serenity-is/corelib'
|
|
2
|
-
|
|
3
|
-
@Decorators.registerEditor('DateMonthEditor')
|
|
4
|
-
export class DateMonthEditor<P extends DateMonthEditorOptions = DateMonthEditorOptions> extends SelectEditor<P> {
|
|
5
|
-
private months: string[]
|
|
6
|
-
|
|
7
|
-
constructor(props: EditorProps<P>) {
|
|
8
|
-
super(props)
|
|
9
|
-
|
|
10
|
-
this.updateItems()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get valueAsMonth() {
|
|
14
|
-
return indexOf(this.months, x => x == this.value)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
getItems() {
|
|
18
|
-
const opt = this.options as DateMonthEditorOptions
|
|
19
|
-
|
|
20
|
-
if (opt.items != null && opt.items.length >= 1) {
|
|
21
|
-
return opt.items
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const today = new Date()
|
|
25
|
-
this.months = []
|
|
26
|
-
const locale = opt.locale ?? 'en'
|
|
27
|
-
const options = { month: opt.display ?? '2-digit' }
|
|
28
|
-
const upperCase = opt.upperCase ?? false
|
|
29
|
-
|
|
30
|
-
for (let i = 0; i <= 11; i++) {
|
|
31
|
-
let m = new Date(today.getFullYear(), i, 1).toLocaleDateString(locale, options)
|
|
32
|
-
if (upperCase) {
|
|
33
|
-
m = m.toUpperCase()
|
|
34
|
-
}
|
|
35
|
-
this.months.push(m)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return this.months
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
43
|
-
export interface DateMonthEditorOptions extends SelectEditorOptions {
|
|
44
|
-
display?: '2-digit' | 'short' | 'long'
|
|
45
|
-
locale?: 'en' | 'th'
|
|
46
|
-
upperCase?: boolean
|
|
47
|
-
}
|
package/src/editors/index.ts
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { Decorators } from '@serenity-is/corelib'
|
|
2
|
-
import { FormatterContext } from '@serenity-is/sleekgrid'
|
|
3
|
-
import { getLookup, htmlEncode } from '@serenity-is/corelib'
|
|
4
|
-
|
|
5
|
-
export type Formatter = {
|
|
6
|
-
format(ctx: FormatterContext): string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
@Decorators.registerFormatter('Idevs.ZeroDisplayFormatter')
|
|
10
|
-
export class ZeroDisplayFormatter implements Formatter {
|
|
11
|
-
constructor(public readonly props: { displayText?: string } = {}) {
|
|
12
|
-
this.props ??= {}
|
|
13
|
-
this.props.displayText ??= ''
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get displayText() {
|
|
17
|
-
return this.props.displayText
|
|
18
|
-
}
|
|
19
|
-
set displayText(value: string) {
|
|
20
|
-
this.props.displayText = value
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
format(ctx: FormatterContext): string {
|
|
24
|
-
return ZeroDisplayFormatter.format(ctx.value, this.displayText)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static format(src: string, displayText?: string): string {
|
|
28
|
-
const value = parseFloat(String(src || '0').replace(',', ''))
|
|
29
|
-
if (value == 0) {
|
|
30
|
-
return htmlEncode(displayText)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return htmlEncode(src)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@Decorators.registerFormatter('Idevs.CheckboxFormatter')
|
|
38
|
-
export class CheckboxFormatter implements Formatter {
|
|
39
|
-
constructor(
|
|
40
|
-
public readonly props: {
|
|
41
|
-
trueText?: string
|
|
42
|
-
falseText?: string
|
|
43
|
-
cssClass?: string
|
|
44
|
-
trueValueIcon?: string
|
|
45
|
-
falseValueIcon?: string
|
|
46
|
-
},
|
|
47
|
-
) {
|
|
48
|
-
this.props.cssClass ??= 'text-center fs-2 text-gray-1'
|
|
49
|
-
this.props.trueText ??= '1'
|
|
50
|
-
this.props.falseText ??= '0'
|
|
51
|
-
this.props.trueValueIcon ??= 'mdi mdi-checkbox-marked-outline'
|
|
52
|
-
this.props.falseValueIcon ??= 'mdi mdi-checkbox-blank-outline'
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get cssClass() {
|
|
56
|
-
return this.props.cssClass
|
|
57
|
-
}
|
|
58
|
-
set cssClass(value: string) {
|
|
59
|
-
this.props.cssClass = value
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get trueText() {
|
|
63
|
-
return this.props.trueText
|
|
64
|
-
}
|
|
65
|
-
set trueText(value: string) {
|
|
66
|
-
this.props.trueText = value
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
get falseText() {
|
|
70
|
-
return this.props.falseText
|
|
71
|
-
}
|
|
72
|
-
set falseText(value: string) {
|
|
73
|
-
this.props.falseText = value
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
get trueValueIcon() {
|
|
77
|
-
return this.props.trueValueIcon
|
|
78
|
-
}
|
|
79
|
-
set trueValueIcon(value: string) {
|
|
80
|
-
this.props.trueValueIcon = value
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
get falseValueIcon() {
|
|
84
|
-
return this.props.falseValueIcon
|
|
85
|
-
}
|
|
86
|
-
set falseValueIcon(value: string) {
|
|
87
|
-
this.props.falseValueIcon = value
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
format(ctx: FormatterContext): string {
|
|
91
|
-
return CheckboxFormatter.format(
|
|
92
|
-
ctx.value,
|
|
93
|
-
this.cssClass,
|
|
94
|
-
this.trueText,
|
|
95
|
-
this.falseText,
|
|
96
|
-
this.trueValueIcon,
|
|
97
|
-
this.falseValueIcon,
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
static format(
|
|
102
|
-
src: string,
|
|
103
|
-
cssClass?: string,
|
|
104
|
-
trueText?: string,
|
|
105
|
-
falseText?: string,
|
|
106
|
-
trueValueIcon?: string,
|
|
107
|
-
falseValueIcon?: string,
|
|
108
|
-
): string {
|
|
109
|
-
if (src == trueText) {
|
|
110
|
-
return `<i class="${trueValueIcon} ${cssClass}"></i>`
|
|
111
|
-
} else if (src == falseText) {
|
|
112
|
-
return `<i class="${falseValueIcon} ${cssClass}"></i>`
|
|
113
|
-
} else {
|
|
114
|
-
return htmlEncode(src)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
@Decorators.registerFormatter('Idevs.LookupFormatter')
|
|
120
|
-
export class LookupFormatter implements Formatter {
|
|
121
|
-
constructor(public readonly props: { lookupKey?: string } = {}) {
|
|
122
|
-
this.props ??= {}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
get lookupKey() {
|
|
126
|
-
return this.props.lookupKey
|
|
127
|
-
}
|
|
128
|
-
set lookupKey(value: string) {
|
|
129
|
-
this.props.lookupKey = value
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
format(ctx: FormatterContext): string {
|
|
133
|
-
return LookupFormatter.format(ctx.value, this.lookupKey)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
static format(src: any, lookupKey?: string): string {
|
|
137
|
-
if (!src) return ''
|
|
138
|
-
|
|
139
|
-
if (!lookupKey) return src
|
|
140
|
-
|
|
141
|
-
const lookup = getLookup(lookupKey)
|
|
142
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
143
|
-
const items = lookup.items as Array<{ [key: string]: any }>
|
|
144
|
-
const idField = lookup.idField
|
|
145
|
-
const textField = lookup.textField
|
|
146
|
-
const idList = src.toString().split(',')
|
|
147
|
-
|
|
148
|
-
return idList
|
|
149
|
-
.map((x: any) => {
|
|
150
|
-
const g = items.find(i => i[idField] == x)
|
|
151
|
-
if (!g) return x
|
|
152
|
-
|
|
153
|
-
return htmlEncode(g[textField])
|
|
154
|
-
})
|
|
155
|
-
.join(', ')
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
@Decorators.registerFormatter('Idevs.DateMonthFormatter')
|
|
160
|
-
export class DateMonthFormatter implements Formatter {
|
|
161
|
-
@Decorators.option()
|
|
162
|
-
public display: '2-digit' | 'short' | 'long'
|
|
163
|
-
|
|
164
|
-
@Decorators.option()
|
|
165
|
-
public locale: 'en' | 'th'
|
|
166
|
-
|
|
167
|
-
format(ctx: FormatterContext): string {
|
|
168
|
-
const src = ctx.value as number
|
|
169
|
-
if (!src) return ''
|
|
170
|
-
|
|
171
|
-
const locale = this.locale ?? 'en'
|
|
172
|
-
const options = { month: this.display ?? '2-digit' }
|
|
173
|
-
|
|
174
|
-
return new Date(2000, src - 1, 1).toLocaleDateString(locale, options)
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export class idevsFormatters {
|
|
179
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
180
|
-
public static load() {}
|
|
181
|
-
}
|
package/src/formatters/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './formatters'
|