@things-factory/code-ui 8.0.5 → 9.0.0-beta.12

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.
@@ -1,288 +0,0 @@
1
- import './code-management-detail'
2
- import '@operato/data-grist/ox-grist.js'
3
- import '@operato/data-grist/ox-filters-form.js'
4
- import '@operato/data-grist/ox-sorters-control.js'
5
- import '@operato/data-grist/ox-record-creator.js'
6
- import '@operato/context/ox-context-page-toolbar.js'
7
-
8
- import gql from 'graphql-tag'
9
- import { css, html } from 'lit'
10
- import { customElement, property, query, state } from 'lit/decorators.js'
11
-
12
- import { openPopup } from '@operato/layout'
13
- import { i18next, localize } from '@operato/i18n'
14
- import { client } from '@operato/graphql'
15
- import { PageView } from '@operato/shell'
16
- import { CommonButtonStyles, CommonGristStyles, CommonHeaderStyles, ScrollbarStyles } from '@operato/styles'
17
- import { isMobileDevice } from '@operato/utils'
18
- import { DataGrist, FetchOption } from '@operato/data-grist'
19
-
20
- import { OxPrompt } from '@operato/popup/ox-prompt.js'
21
-
22
- @customElement('code-management')
23
- export class CodeManagement extends localize(i18next)(PageView) {
24
- static styles = [
25
- ScrollbarStyles,
26
- CommonGristStyles,
27
- CommonHeaderStyles,
28
- css`
29
- :host {
30
- display: flex;
31
-
32
- width: 100%;
33
-
34
- --grid-record-emphasized-background-color: #8b0000;
35
- --grid-record-emphasized-color: #ff6b6b;
36
- }
37
-
38
- ox-grist {
39
- overflow-y: auto;
40
- flex: 1;
41
- }
42
-
43
- .header {
44
- grid-template-areas: 'filters actions';
45
- }
46
- `
47
- ]
48
-
49
- @state() config?: any
50
- @state() data?: any
51
- @state() mode: 'LIST' | 'GRID' = isMobileDevice() ? 'LIST' : 'GRID'
52
-
53
- @query('ox-grist') grist!: DataGrist
54
-
55
- render() {
56
- let mode = this.mode
57
-
58
- return html`
59
- <ox-grist .mode=${mode} auto-fetch .config=${this.config} .fetchHandler=${this.fetchHandler.bind(this)}>
60
- <div slot="headroom" class="header">
61
- <div class="filters">
62
- <ox-filters-form autofocus without-search></ox-filters-form>
63
- </div>
64
-
65
- <ox-context-page-toolbar class="actions" .context=${this.context}> </ox-context-page-toolbar>
66
- </div>
67
- </ox-grist>
68
- `
69
- }
70
-
71
- get context() {
72
- return {
73
- title: i18next.t('title.code-management'),
74
- search: {
75
- handler: (search: string) => {
76
- this.grist.searchText = search
77
- },
78
- value: this.grist?.searchText || ''
79
- },
80
- filter: {
81
- handler: () => {
82
- this.grist.toggleHeadroom()
83
- }
84
- },
85
- actions: [
86
- {
87
- title: i18next.t('button.save'),
88
- action: this.save.bind(this),
89
- ...CommonButtonStyles.save
90
- },
91
- {
92
- title: i18next.t('button.delete'),
93
- action: this.delete.bind(this),
94
- ...CommonButtonStyles.delete
95
- }
96
- ],
97
- help: 'code/code-management',
98
- toolbar: false
99
- }
100
- }
101
-
102
- pageUpdated(_changed, _lifecycle) {
103
- if (this.active) {
104
- this.grist.fetch()
105
- }
106
- }
107
-
108
- pageInitialized() {
109
- this.config = {
110
- rows: { selectable: { multiple: true } },
111
- pagination: { pages: [50, 100, 200] },
112
- columns: [
113
- { type: 'gutter', gutterName: 'dirty' },
114
- { type: 'gutter', gutterName: 'sequence' },
115
- { type: 'gutter', gutterName: 'row-selector', multiple: true },
116
- {
117
- type: 'gutter',
118
- gutterName: 'button',
119
- icon: 'reorder',
120
- handlers: {
121
- click: (_columns, _data, _column, record, _rowIndex) => {
122
- if (record.id && record.name) this.openCodeDetail(record.id, record.name)
123
- }
124
- }
125
- },
126
- {
127
- type: 'string',
128
- name: 'name',
129
- header: i18next.t('field.common-code'),
130
- record: { editable: true, align: 'left' },
131
- sortable: true,
132
- filter: 'search',
133
- width: 375
134
- },
135
- {
136
- type: 'string',
137
- name: 'description',
138
- header: i18next.t('field.description'),
139
- record: { editable: true, align: 'left' },
140
- sortable: true,
141
- filter: 'search',
142
- width: 500
143
- },
144
- {
145
- type: 'object',
146
- name: 'updater',
147
- header: i18next.t('field.updater'),
148
- record: { editable: false },
149
- sortable: true,
150
- width: 90
151
- },
152
- {
153
- type: 'datetime',
154
- name: 'updatedAt',
155
- header: i18next.t('field.updated_at'),
156
- record: { editable: false },
157
- sortable: true,
158
- width: 180
159
- }
160
- ]
161
- }
162
- }
163
-
164
- async fetchHandler({ filters, page, limit, sorters = [{ name: 'name' }, { name: 'updatedAt' }] }: FetchOption) {
165
- const response = await client.query({
166
- query: gql`
167
- query CommonCodes($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
168
- commonCodes(filters: $filters, pagination: $pagination, sortings: $sortings) {
169
- items {
170
- id
171
- name
172
- description
173
- updatedAt
174
- updater {
175
- id
176
- name
177
- description
178
- }
179
- }
180
- total
181
- }
182
- }
183
- `,
184
- variables: {
185
- filters,
186
- pagination: { page, limit },
187
- sorters
188
- }
189
- })
190
-
191
- return {
192
- total: response.data.commonCodes.total || 0,
193
- records: response.data.commonCodes.items || []
194
- }
195
- }
196
-
197
- async save() {
198
- const patches = this.getPatches()
199
- if (!patches?.length) {
200
- return this.showToast(i18next.t('text.nothing_changed'))
201
- }
202
-
203
- const response = await client.mutate({
204
- mutation: gql`
205
- mutation UpdateMultipleCommonCode($patches: [CommonCodePatch!]!) {
206
- updateMultipleCommonCode(patches: $patches) {
207
- name
208
- }
209
- }
210
- `,
211
- variables: { patches }
212
- })
213
-
214
- if (!response.errors) {
215
- this.showToast(i18next.t('text.data_updated_successfully'))
216
- this.grist.fetch()
217
- }
218
- }
219
-
220
- async delete() {
221
- const ids = this.grist.selected.map(record => record.id)
222
- if (!ids?.length) {
223
- return this.showToast(i18next.t('text.there_is_nothing_to_delete'))
224
- }
225
-
226
- if (
227
- await OxPrompt.open({
228
- type: 'warning',
229
- title: i18next.t('button.delete'),
230
- text: i18next.t('text.are_you_sure'),
231
- confirmButton: { text: i18next.t('button.delete') },
232
- cancelButton: { text: i18next.t('button.cancel') }
233
- })
234
- ) {
235
- const response = await client.mutate({
236
- mutation: gql`
237
- mutation DeleteCommonCodes($ids: [String!]!) {
238
- deleteCommonCodes(ids: $ids)
239
- }
240
- `,
241
- variables: {
242
- ids
243
- }
244
- })
245
-
246
- if (!response.errors) {
247
- OxPrompt.open({
248
- type: 'success',
249
- title: i18next.t('text.completed'),
250
- text: i18next.t('text.data_deleted_successfully'),
251
- confirmButton: { text: i18next.t('button.confirm') }
252
- })
253
-
254
- this.grist.fetch()
255
- }
256
- }
257
- }
258
-
259
- getPatches() {
260
- let patches = this.grist.dirtyRecords
261
- if (patches && patches.length) {
262
- patches = patches.map(code => {
263
- let patchField: any = code.id ? { id: code.id } : {}
264
- const dirtyFields = code.__dirtyfields__
265
- for (let key in dirtyFields) {
266
- patchField[key] = dirtyFields[key].after
267
- }
268
- patchField.cuFlag = code.__dirty__
269
-
270
- return patchField
271
- })
272
- }
273
-
274
- return patches
275
- }
276
-
277
- openCodeDetail(codeId, codeName) {
278
- openPopup(html` <code-management-detail .codeId="${codeId}"></code-management-detail> `, {
279
- backdrop: true,
280
- size: 'large',
281
- title: `${i18next.t('title.code-management-detail')} - ${codeName}`
282
- })
283
- }
284
-
285
- showToast(message) {
286
- document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))
287
- }
288
- }
package/client/route.ts DELETED
@@ -1,7 +0,0 @@
1
- export default function route(page) {
2
- switch (page) {
3
- case 'codes':
4
- import('./pages/code-management')
5
- return page
6
- }
7
- }
package/server/index.ts DELETED
File without changes