@things-factory/rack-base 8.0.0-beta.8 → 8.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.
Files changed (44) hide show
  1. package/client/bootstrap.ts +1 -0
  2. package/client/pages/cell/cell-importer.ts +87 -0
  3. package/client/pages/cell/cell-list-page.ts +308 -0
  4. package/client/pages/rack/rack-importer.ts +87 -0
  5. package/client/pages/rack/rack-list-page.ts +312 -0
  6. package/client/route.ts +11 -0
  7. package/dist-server/tsconfig.tsbuildinfo +1 -1
  8. package/package.json +6 -6
  9. package/server/index.ts +1 -0
  10. package/server/migrations/index.ts +9 -0
  11. package/server/routes.ts +26 -0
  12. package/server/service/cell/cell-mutation.ts +133 -0
  13. package/server/service/cell/cell-query.ts +50 -0
  14. package/server/service/cell/cell-type.ts +96 -0
  15. package/server/service/cell/cell.ts +112 -0
  16. package/server/service/cell/index.ts +6 -0
  17. package/server/service/index.ts +22 -0
  18. package/server/service/rack/index.ts +6 -0
  19. package/server/service/rack/rack-mutation.ts +133 -0
  20. package/server/service/rack/rack-query.ts +64 -0
  21. package/server/service/rack/rack-type.ts +54 -0
  22. package/server/service/rack/rack.ts +76 -0
  23. package/dist-client/bootstrap.d.ts +0 -1
  24. package/dist-client/bootstrap.js +0 -2
  25. package/dist-client/bootstrap.js.map +0 -1
  26. package/dist-client/index.js +0 -2
  27. package/dist-client/index.js.map +0 -1
  28. package/dist-client/pages/cell/cell-importer.d.ts +0 -23
  29. package/dist-client/pages/cell/cell-importer.js +0 -94
  30. package/dist-client/pages/cell/cell-importer.js.map +0 -1
  31. package/dist-client/pages/cell/cell-list-page.d.ts +0 -54
  32. package/dist-client/pages/cell/cell-list-page.js +0 -290
  33. package/dist-client/pages/cell/cell-list-page.js.map +0 -1
  34. package/dist-client/pages/rack/rack-importer.d.ts +0 -23
  35. package/dist-client/pages/rack/rack-importer.js +0 -94
  36. package/dist-client/pages/rack/rack-importer.js.map +0 -1
  37. package/dist-client/pages/rack/rack-list-page.d.ts +0 -54
  38. package/dist-client/pages/rack/rack-list-page.js +0 -294
  39. package/dist-client/pages/rack/rack-list-page.js.map +0 -1
  40. package/dist-client/route.d.ts +0 -1
  41. package/dist-client/route.js +0 -11
  42. package/dist-client/route.js.map +0 -1
  43. package/dist-client/tsconfig.tsbuildinfo +0 -1
  44. /package/{dist-client/index.d.ts → client/index.ts} +0 -0
@@ -0,0 +1,312 @@
1
+ import '@operato/data-grist'
2
+
3
+ import { CommonButtonStyles, CommonHeaderStyles, CommonGristStyles, ScrollbarStyles } from '@operato/styles'
4
+ import { PageView, store } from '@operato/shell'
5
+ import { css, html } from 'lit'
6
+ import { customElement, property, query } from 'lit/decorators.js'
7
+ import { ScopedElementsMixin } from '@open-wc/scoped-elements'
8
+ import { ColumnConfig, DataGrist, FetchOption } from '@operato/data-grist'
9
+ import { client } from '@operato/graphql'
10
+ import { i18next, localize } from '@operato/i18n'
11
+ import { notify, openPopup } from '@operato/layout'
12
+ import { isMobileDevice } from '@operato/utils'
13
+
14
+ import { connect } from 'pwa-helpers/connect-mixin'
15
+ import gql from 'graphql-tag'
16
+
17
+ import { RackImporter } from './rack-importer'
18
+
19
+ @customElement('rack-list-page')
20
+ export class RackListPage extends connect(store)(localize(i18next)(ScopedElementsMixin(PageView))) {
21
+ static styles = [
22
+ ScrollbarStyles,
23
+ CommonGristStyles,
24
+ CommonHeaderStyles,
25
+ css`
26
+ :host {
27
+ display: flex;
28
+
29
+ width: 100%;
30
+
31
+ --grid-record-emphasized-background-color: #8b0000;
32
+ --grid-record-emphasized-color: #ff6b6b;
33
+ }
34
+
35
+ ox-grist {
36
+ overflow-y: auto;
37
+ flex: 1;
38
+ }
39
+
40
+ ox-filters-form {
41
+ flex: 1;
42
+ }
43
+ `
44
+ ]
45
+
46
+ static get scopedElements() {
47
+ return {
48
+ 'rack-importer': RackImporter
49
+ }
50
+ }
51
+
52
+ @property({ type: Object }) gristConfig: any
53
+ @property({ type: String }) mode: 'CARD' | 'GRID' | 'LIST' = isMobileDevice() ? 'CARD' : 'GRID'
54
+
55
+ @query('ox-grist') private grist!: DataGrist
56
+
57
+ get context() {
58
+ return {
59
+ title: i18next.t('title.rack list'),
60
+ help: 'rack-base/rack',
61
+ actions: [
62
+ {
63
+ title: i18next.t('button.save'),
64
+ action: this._updateRack.bind(this),
65
+ ...CommonButtonStyles.save
66
+ },
67
+ {
68
+ title: i18next.t('button.delete'),
69
+ action: this._deleteRack.bind(this),
70
+ ...CommonButtonStyles.delete
71
+ }
72
+ ],
73
+ exportable: {
74
+ name: i18next.t('title.rack list'),
75
+ data: this.exportHandler.bind(this)
76
+ },
77
+ importable: {
78
+ handler: this.importHandler.bind(this)
79
+ }
80
+ }
81
+ }
82
+
83
+ render() {
84
+ const mode = this.mode || (isMobileDevice() ? 'CARD' : 'GRID')
85
+
86
+ return html`
87
+ <ox-grist .mode=${mode} .config=${this.gristConfig} .fetchHandler=${this.fetchHandler.bind(this)}>
88
+ <div slot="headroom" class="header">
89
+ <div class="filters">
90
+ <ox-filters-form autofocus></ox-filters-form>
91
+
92
+ <div id="modes">
93
+ <md-icon @click=${() => (this.mode = 'GRID')} ?active=${mode == 'GRID'}>grid_on</md-icon>
94
+ <md-icon @click=${() => (this.mode = 'LIST')} ?active=${mode == 'LIST'}>format_list_bulleted</md-icon>
95
+ <md-icon @click=${() => (this.mode = 'CARD')} ?active=${mode == 'CARD'}>apps</md-icon>
96
+ </div>
97
+ </div>
98
+ </div>
99
+ </ox-grist>
100
+ `
101
+ }
102
+
103
+ async pageInitialized(lifecycle: any) {
104
+ this.gristConfig = {
105
+ list: {
106
+ fields: ['name', 'description'],
107
+ details: ['active', 'updatedAt']
108
+ },
109
+ columns: [
110
+ { type: 'gutter', gutterName: 'sequence' },
111
+ { type: 'gutter', gutterName: 'row-selector', multiple: true },
112
+ {
113
+ type: 'string',
114
+ name: 'name',
115
+ header: i18next.t('field.name'),
116
+ record: {
117
+ editable: true
118
+ },
119
+ filter: 'search',
120
+ sortable: true,
121
+ width: 150
122
+ },
123
+ {
124
+ type: 'string',
125
+ name: 'description',
126
+ header: i18next.t('field.description'),
127
+ record: {
128
+ editable: true
129
+ },
130
+ filter: 'search',
131
+ width: 200
132
+ },
133
+ {
134
+ type: 'checkbox',
135
+ name: 'active',
136
+ label: true,
137
+ header: i18next.t('field.active'),
138
+ record: {
139
+ editable: true
140
+ },
141
+ filter: true,
142
+ sortable: true,
143
+ width: 60
144
+ },
145
+ {
146
+ type: 'resource-object',
147
+ name: 'updater',
148
+ header: i18next.t('field.updater'),
149
+ record: {
150
+ editable: false
151
+ },
152
+ sortable: true,
153
+ width: 120
154
+ },
155
+ {
156
+ type: 'datetime',
157
+ name: 'updatedAt',
158
+ header: i18next.t('field.updated_at'),
159
+ record: {
160
+ editable: false
161
+ },
162
+ sortable: true,
163
+ width: 180
164
+ }
165
+ ],
166
+ rows: {
167
+ selectable: {
168
+ multiple: true
169
+ }
170
+ },
171
+ sorters: [
172
+ {
173
+ name: 'name'
174
+ }
175
+ ]
176
+ }
177
+ }
178
+
179
+ async pageUpdated(changes: any, lifecycle: any) {
180
+ if (this.active) {
181
+ // do something here when this page just became as active
182
+ }
183
+ }
184
+
185
+ async fetchHandler({ page = 1, limit = 100, sortings = [], filters = [] }: FetchOption) {
186
+ const response = await client.query({
187
+ query: gql`
188
+ query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
189
+ responses: racks(filters: $filters, pagination: $pagination, sortings: $sortings) {
190
+ items {
191
+ id
192
+ name
193
+ description
194
+ active
195
+ updater {
196
+ id
197
+ name
198
+ }
199
+ updatedAt
200
+ }
201
+ total
202
+ }
203
+ }
204
+ `,
205
+ variables: {
206
+ filters,
207
+ pagination: { page, limit },
208
+ sortings
209
+ }
210
+ })
211
+
212
+ return {
213
+ total: response.data.responses.total || 0,
214
+ records: response.data.responses.items || []
215
+ }
216
+ }
217
+
218
+ async _deleteRack() {
219
+ if (confirm(i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }))) {
220
+ const ids = this.grist.selected.map(record => record.id)
221
+ if (ids && ids.length > 0) {
222
+ const response = await client.mutate({
223
+ mutation: gql`
224
+ mutation ($ids: [String!]!) {
225
+ deleteRacks(ids: $ids)
226
+ }
227
+ `,
228
+ variables: {
229
+ ids
230
+ }
231
+ })
232
+
233
+ if (!response.errors) {
234
+ this.grist.fetch()
235
+ notify({
236
+ message: i18next.t('text.info_x_successfully', { x: i18next.t('text.delete') })
237
+ })
238
+ }
239
+ }
240
+ }
241
+ }
242
+
243
+ async _updateRack() {
244
+ let patches = this.grist.dirtyRecords
245
+ if (patches && patches.length) {
246
+ patches = patches.map(patch => {
247
+ let patchField: any = patch.id ? { id: patch.id } : {}
248
+ const dirtyFields = patch.__dirtyfields__
249
+ for (let key in dirtyFields) {
250
+ patchField[key] = dirtyFields[key].after
251
+ }
252
+ patchField.cuFlag = patch.__dirty__
253
+
254
+ return patchField
255
+ })
256
+
257
+ const response = await client.mutate({
258
+ mutation: gql`
259
+ mutation ($patches: [RackPatch!]!) {
260
+ updateMultipleRack(patches: $patches) {
261
+ name
262
+ }
263
+ }
264
+ `,
265
+ variables: {
266
+ patches
267
+ }
268
+ })
269
+
270
+ if (!response.errors) {
271
+ this.grist.fetch()
272
+ }
273
+ }
274
+ }
275
+
276
+ async exportHandler() {
277
+ const exportTargets = this.grist.selected.length ? this.grist.selected : this.grist.dirtyData.records
278
+ const targetFieldSet = new Set(['id', 'name', 'description', 'active'])
279
+
280
+ return exportTargets.map(rack => {
281
+ let tempObj = {}
282
+ for (const field of targetFieldSet) {
283
+ tempObj[field] = rack[field]
284
+ }
285
+
286
+ return tempObj
287
+ })
288
+ }
289
+
290
+ async importHandler(records) {
291
+ const popup = openPopup(
292
+ html`
293
+ <rack-importer
294
+ .racks=${records}
295
+ @imported=${() => {
296
+ history.back()
297
+ this.grist.fetch()
298
+ }}
299
+ ></rack-importer>
300
+ `,
301
+ {
302
+ backdrop: true,
303
+ size: 'large',
304
+ title: i18next.t('title.import rack')
305
+ }
306
+ )
307
+
308
+ popup.onclosed = () => {
309
+ this.grist.fetch()
310
+ }
311
+ }
312
+ }
@@ -0,0 +1,11 @@
1
+ export default function route(page: string) {
2
+ switch (page) {
3
+ case 'cell-list-page':
4
+ import('./pages/cell/cell-list-page')
5
+ return page
6
+
7
+ case 'rack-list':
8
+ import('./pages/rack/rack-list-page')
9
+ return page
10
+ }
11
+ }