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