@things-factory/i18n-base 7.0.1-alpha.71 → 7.0.1-alpha.77

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.
@@ -0,0 +1,376 @@
1
+ import '@material/web/icon/icon.js'
2
+
3
+ import '@operato/data-grist'
4
+ import '@operato/context/ox-context-page-toolbar.js'
5
+ import '@operato/input/ox-input-select-buttons.js'
6
+
7
+ import { PropertyValues, css, html } from 'lit'
8
+ import { customElement, property, query, state } from 'lit/decorators.js'
9
+ import { connect } from 'pwa-helpers/connect-mixin.js'
10
+ import gql from 'graphql-tag'
11
+
12
+ import { store, PageView } from '@operato/shell'
13
+ import { client } from '@operato/graphql'
14
+ import { DataGrist, FetchOption, GristRecord } from '@operato/data-grist'
15
+ import { i18next, localize } from '@operato/i18n'
16
+ import { openPopup } from '@operato/layout'
17
+ import { CommonHeaderStyles, ScrollbarStyles } from '@operato/styles'
18
+ import { OxPrompt } from '@operato/popup/ox-prompt.js'
19
+ import { isMobileDevice } from '@operato/utils'
20
+
21
+ @customElement('terminology-page')
22
+ export class TerminologyPage extends connect(store)(localize(i18next)(PageView)) {
23
+ static styles = [
24
+ ScrollbarStyles,
25
+ CommonHeaderStyles,
26
+ css`
27
+ :host {
28
+ display: flex;
29
+ flex-direction: column;
30
+
31
+ overflow: hidden;
32
+
33
+ --grid-header-padding: 2px 0 2px 9px;
34
+ }
35
+
36
+ ox-grist {
37
+ overflow-y: auto;
38
+ flex: 1;
39
+ }
40
+ `
41
+ ]
42
+
43
+ @state() private gristConfig: any
44
+ @state() private mode: 'CARD' | 'GRID' | 'LIST' = isMobileDevice() ? 'CARD' : 'GRID'
45
+ @state() private state?: string[]
46
+
47
+ @query('ox-grist') private grist!: DataGrist
48
+
49
+ get context() {
50
+ return {
51
+ title: i18next.t('menu.Terminology'),
52
+ search: {
53
+ handler: (search: string) => {
54
+ this.grist.searchText = search
55
+ },
56
+ value: this.grist?.searchText || ''
57
+ },
58
+ filter: {
59
+ handler: () => {
60
+ this.grist.toggleHeadroom()
61
+ }
62
+ },
63
+ help: 'mfg-warehouse/term-page',
64
+ actions: [
65
+ {
66
+ title: i18next.t('button.delete'),
67
+ action: this.delete.bind(this),
68
+ icon: 'delete'
69
+ },
70
+ {
71
+ title: i18next.t('button.save'),
72
+ action: this.save.bind(this),
73
+ icon: 'save'
74
+ },
75
+ {
76
+ title: i18next.t('button.print'),
77
+ action: this.print.bind(this),
78
+ icon: 'print'
79
+ }
80
+ ],
81
+ exportable: {
82
+ name: i18next.t('button.export'),
83
+ data: this.exportHandler.bind(this)
84
+ },
85
+ toolbar: false
86
+ }
87
+ }
88
+
89
+ getFilterStatus() {
90
+ return [
91
+ {
92
+ display: '한국어',
93
+ value: 'ko-KR'
94
+ },
95
+ {
96
+ display: 'English',
97
+ value: 'en-US'
98
+ },
99
+ {
100
+ display: '中文',
101
+ value: 'zh-CN'
102
+ },
103
+ {
104
+ display: '日本語',
105
+ value: 'ja-JP'
106
+ }
107
+ ]
108
+ }
109
+
110
+ render() {
111
+ const mode = this.mode || (isMobileDevice() ? 'LIST' : 'GRID')
112
+
113
+ return html`
114
+ <ox-grist .mode=${mode} .config=${this.gristConfig} .fetchHandler=${this.fetchHandler.bind(this)}>
115
+ <div slot="headroom" class="header">
116
+ <div class="title">${i18next.t('title.Terminology')}</div>
117
+
118
+ <div class="filters">
119
+ <ox-input-select-buttons
120
+ .value=${this.state}
121
+ .options=${this.getFilterStatus()}
122
+ @change=${(e: CustomEvent) => {
123
+ this.state = (e.currentTarget as any)?.value
124
+ this.grist.fetch()
125
+ }}
126
+ ></ox-input-select-buttons>
127
+ </div>
128
+
129
+ <ox-context-page-toolbar class="actions" .context=${this.context}></ox-context-page-toolbar>
130
+ </div>
131
+ </ox-grist>
132
+ `
133
+ }
134
+
135
+ async pageInitialized(lifecycle) {
136
+ this.gristConfig = {
137
+ list: {
138
+ fields: ['name', 'description'],
139
+ details: ['active', 'updatedAt']
140
+ },
141
+ columns: [
142
+ { type: 'gutter', gutterName: 'sequence' },
143
+ { type: 'gutter', gutterName: 'row-selector', multiple: true },
144
+ {
145
+ type: 'string',
146
+ name: 'id',
147
+ header: i18next.t('label.id'),
148
+ hidden: true,
149
+ width: 0
150
+ },
151
+ {
152
+ type: 'string',
153
+ name: 'name',
154
+ header: i18next.t('label.name'),
155
+ record: {
156
+ editable: true
157
+ },
158
+ filter: 'search',
159
+ sortable: true,
160
+ width: 150
161
+ },
162
+ {
163
+ type: 'string',
164
+ name: 'locale',
165
+ header: i18next.t('label.locale'),
166
+ record: {
167
+ editable: true
168
+ },
169
+ width: 200
170
+ },
171
+ {
172
+ type: 'select',
173
+ name: 'category',
174
+ label: true,
175
+ header: i18next.t('label.category'),
176
+ record: {
177
+ editable: false,
178
+ options: [{ display: '', value: '' }, ...this.getFilterStatus()]
179
+ },
180
+ width: 100,
181
+ filter: true,
182
+ imex: true
183
+ },
184
+ {
185
+ type: 'string',
186
+ name: 'display',
187
+ label: true,
188
+ header: i18next.t('label.display'),
189
+ record: {
190
+ editable: true
191
+ },
192
+ filter: true,
193
+ sortable: true,
194
+ width: 250
195
+ },
196
+ {
197
+ type: 'resource-object',
198
+ name: 'updater',
199
+ header: i18next.t('label.updater'),
200
+ record: {
201
+ editable: false
202
+ },
203
+ sortable: true,
204
+ width: 120
205
+ },
206
+ {
207
+ type: 'datetime',
208
+ name: 'updatedAt',
209
+ header: i18next.t('label.updated_at'),
210
+ record: {
211
+ editable: false
212
+ },
213
+ sortable: true,
214
+ width: 180
215
+ }
216
+ ],
217
+ rows: {
218
+ appendable: false,
219
+ selectable: {
220
+ multiple: true
221
+ }
222
+ /*handlers: {
223
+ click: (columns, data, column, record, rowIndex) => {
224
+ // TODO Implement the desired sub-view(like item-view) and use it in the popup content after importing
225
+ const popup = openPopup(html`
226
+ <item-view item-id=${record.id} style="background-color: white;">
227
+ </item-view>
228
+ `, {
229
+ backdrop: true,
230
+ size: 'large',
231
+ title: i18next.t('text.item view')
232
+ })
233
+ popup.onclosed = () => {
234
+ this.grist.fetch()
235
+ }
236
+ }
237
+ }*/
238
+ },
239
+ sorters: [
240
+ {
241
+ name: 'name',
242
+ desc: true
243
+ }
244
+ ]
245
+ }
246
+
247
+ await this.updateComplete
248
+
249
+ this.grist.fetch()
250
+ }
251
+
252
+ async pageUpdated(changes: any, lifecycle: any) {
253
+ if (this.active) {
254
+ // do something here when this page just became as active
255
+ }
256
+ }
257
+
258
+ async fetchHandler({ page = 1, limit = 100, sortings = [], filters = [] }: FetchOption) {
259
+ let url = 'terminologies'
260
+ let selectFields = 'id,name,locale,category,display,created_at,updated_at,creator,updater'
261
+ let result = null as any // await ServiceUtil.searchByPagination(url, filters, sortings, page, limit, selectFields)
262
+
263
+ return {
264
+ total: result ? result.total : 0,
265
+ records: result ? result.items : []
266
+ }
267
+ }
268
+
269
+ exportHandler() {
270
+ let records = [] as GristRecord
271
+ if (this.grist.selected && this.grist.selected.length > 0) {
272
+ records = this.grist.selected
273
+ } else {
274
+ records = this.grist.data.records
275
+ }
276
+
277
+ var headerSetting = this.grist.compiledConfig.columns
278
+ .filter(column => column.type !== 'gutter' && column.record !== undefined && column.imex !== undefined)
279
+ .map(column => {
280
+ return column.imex === true
281
+ ? {
282
+ header: column.header.renderer(column),
283
+ key: column.name,
284
+ width: column.width,
285
+ type: column.type
286
+ }
287
+ : column.imex
288
+ })
289
+
290
+ var data = records.map(item => {
291
+ return {
292
+ id: item.id,
293
+ ...this.gristConfig.columns
294
+ .filter(column => column.type !== 'gutter' && column.record !== undefined && column.imex !== undefined)
295
+ .reduce((record, column) => {
296
+ const key = column.imex === true ? column.name : column.imex.key
297
+ record[key] = key
298
+ .split('.')
299
+ .reduce((obj, key) => (obj && obj[key] !== 'undefined' ? obj[key] : undefined), item)
300
+ return record
301
+ }, {})
302
+ }
303
+ })
304
+
305
+ return { header: headerSetting, data: data }
306
+ }
307
+
308
+ async delete() {
309
+ const selectedRecords = this.grist.selected
310
+
311
+ if (!selectedRecords || selectedRecords.length == 0) {
312
+ // showToast('info', i18next.t('text.NOTHING_SELECTED'))
313
+ } else {
314
+ const answer = null // await showAlertPopup('button.delete', 'text.are_you_sure', 'question', 'delete', 'cancel')
315
+
316
+ if (answer) {
317
+ let patches = selectedRecords.map(record => {
318
+ record['cud_flag_'] = 'd'
319
+ return record
320
+ })
321
+
322
+ return null // await ServiceUtil.deleteMultiple('terminologies/update_multiple', patches)
323
+ }
324
+ }
325
+ }
326
+
327
+ async save() {
328
+ let changedRecords = this.grist.dirtyRecords
329
+
330
+ if (!changedRecords || changedRecords.length == 0) {
331
+ // showToast('info', i18next.t('text.NOTHING_CHANGED'))
332
+ } else {
333
+ let metaFields = [
334
+ 'creator',
335
+ 'updater',
336
+ 'createdAt',
337
+ 'updatedAt',
338
+ '__dirty__',
339
+ '__dirtyfields__',
340
+ '__origin__',
341
+ '__seq__',
342
+ '__selected__'
343
+ ]
344
+
345
+ let patches = changedRecords.map(record => {
346
+ let patchData = record.id ? { id: record.id } : {}
347
+
348
+ for (let key in record) {
349
+ if (!metaFields.includes(key)) {
350
+ patchData[key] = record[key]
351
+ }
352
+ }
353
+
354
+ patchData['cud_flag_'] = record['__dirty__'] == 'M' ? 'u' : 'c'
355
+ return patchData
356
+ })
357
+
358
+ //await ServiceUtil.updateMultiple('terminologies/update_multiple', patches)
359
+ this.grist.fetch()
360
+ }
361
+ }
362
+
363
+ print() {
364
+ const selected = this.grist.selected
365
+ const ids = selected.map(record => record.id).join('|')
366
+
367
+ /* TODO Implement the desired functionality */
368
+
369
+ OxPrompt.open({
370
+ type: 'success',
371
+ title: i18next.t('text.completed'),
372
+ text: i18next.t('text.printed_successfully'),
373
+ confirmButton: { text: i18next.t('button.confirm') }
374
+ })
375
+ }
376
+ }
@@ -0,0 +1,7 @@
1
+ export default function route(page) {
2
+ switch (page) {
3
+ case 'terminology':
4
+ import('./page/terminology-page.js')
5
+ return page
6
+ }
7
+ }
@@ -0,0 +1,73 @@
1
+ import '@material/web/icon/icon.js';
2
+ import '@operato/data-grist';
3
+ import '@operato/context/ox-context-page-toolbar.js';
4
+ import '@operato/input/ox-input-select-buttons.js';
5
+ import { PageView } from '@operato/shell';
6
+ import { FetchOption } from '@operato/data-grist';
7
+ declare const TerminologyPage_base: (new (...args: any[]) => {
8
+ _storeUnsubscribe: import("redux").Unsubscribe;
9
+ connectedCallback(): void;
10
+ disconnectedCallback(): void;
11
+ stateChanged(_state: unknown): void;
12
+ readonly isConnected: boolean;
13
+ }) & (new (...args: any[]) => import("lit").LitElement) & typeof PageView;
14
+ export declare class TerminologyPage extends TerminologyPage_base {
15
+ static styles: import("lit").CSSResult[];
16
+ private gristConfig;
17
+ private mode;
18
+ private state?;
19
+ private grist;
20
+ get context(): {
21
+ title: string;
22
+ search: {
23
+ handler: (search: string) => void;
24
+ value: string;
25
+ };
26
+ filter: {
27
+ handler: () => void;
28
+ };
29
+ help: string;
30
+ actions: {
31
+ title: string;
32
+ action: () => void;
33
+ icon: string;
34
+ }[];
35
+ exportable: {
36
+ name: string;
37
+ data: () => {
38
+ header: (false | {
39
+ header: any;
40
+ key: string;
41
+ width: string | number | import("@operato/data-grist").ColumnWidthCallback | undefined;
42
+ type: string;
43
+ } | undefined)[];
44
+ data: any;
45
+ };
46
+ };
47
+ toolbar: boolean;
48
+ };
49
+ getFilterStatus(): {
50
+ display: string;
51
+ value: string;
52
+ }[];
53
+ render(): import("lit").TemplateResult<1>;
54
+ pageInitialized(lifecycle: any): Promise<void>;
55
+ pageUpdated(changes: any, lifecycle: any): Promise<void>;
56
+ fetchHandler({ page, limit, sortings, filters }: FetchOption): Promise<{
57
+ total: any;
58
+ records: any;
59
+ }>;
60
+ exportHandler(): {
61
+ header: (false | {
62
+ header: any;
63
+ key: string;
64
+ width: string | number | import("@operato/data-grist").ColumnWidthCallback | undefined;
65
+ type: string;
66
+ } | undefined)[];
67
+ data: any;
68
+ };
69
+ delete(): Promise<null | undefined>;
70
+ save(): Promise<void>;
71
+ print(): void;
72
+ }
73
+ export {};