@things-factory/pdf 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 (29) hide show
  1. package/client/bootstrap.js +6 -0
  2. package/client/pages/pdf-release/pdf-release-importer.ts +87 -0
  3. package/client/pages/pdf-release/pdf-release-list-page.ts +398 -0
  4. package/client/pages/pdf-template/pdf-template-importer.ts +87 -0
  5. package/client/pages/pdf-template/pdf-template-list-page.ts +491 -0
  6. package/client/route.ts +11 -0
  7. package/client/tsconfig.json +13 -0
  8. package/dist-client/tsconfig.tsbuildinfo +1 -1
  9. package/dist-server/tsconfig.tsbuildinfo +1 -1
  10. package/package.json +4 -4
  11. package/server/controller/pdf-service.ts +35 -0
  12. package/server/index.ts +3 -0
  13. package/server/routers/pdf-private-router.ts +85 -0
  14. package/server/routers/pdf-public-router.ts +80 -0
  15. package/server/routers/proxy-router.ts +9 -0
  16. package/server/routes.ts +19 -0
  17. package/server/service/index.ts +38 -0
  18. package/server/service/pdf-generate/pdf-generate-resolver.ts +81 -0
  19. package/server/service/pdf-release/index.ts +7 -0
  20. package/server/service/pdf-release/pdf-release-mutation.ts +138 -0
  21. package/server/service/pdf-release/pdf-release-query.ts +51 -0
  22. package/server/service/pdf-release/pdf-release-type.ts +55 -0
  23. package/server/service/pdf-release/pdf-release.ts +103 -0
  24. package/server/service/pdf-template/index.ts +7 -0
  25. package/server/service/pdf-template/pdf-template-mutation.ts +138 -0
  26. package/server/service/pdf-template/pdf-template-query.ts +51 -0
  27. package/server/service/pdf-template/pdf-template-type.ts +87 -0
  28. package/server/service/pdf-template/pdf-template.ts +108 -0
  29. package/server/tsconfig.json +10 -0
@@ -0,0 +1,6 @@
1
+ import { OxGristEditorCode } from '@operato/app/grist-editor/ox-grist-editor-code.js'
2
+ import { registerEditor as registerGristEditor, registerRenderer as registerGristRenderer } from '@operato/data-grist'
3
+
4
+ export default function bootstrap() {
5
+ registerGristEditor('template', OxGristEditorCode)
6
+ }
@@ -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 PdfReleaseImporter extends LitElement {
14
+ static styles = [
15
+ CommonHeaderStyles,
16
+ css`
17
+ :host {
18
+ display: flex;
19
+ flex-direction: column;
20
+
21
+ background-color: #fff;
22
+ }
23
+
24
+ ox-grist {
25
+ flex: 1;
26
+ }
27
+ `
28
+ ]
29
+
30
+ @property({ type: Array }) pdfReleases: 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.pdfReleases
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 importPdfReleases($pdfReleases: [PdfReleasePatch!]!) {
77
+ importPdfReleases(pdfReleases: $pdfReleases)
78
+ }
79
+ `,
80
+ variables: { pdfReleases: this.pdfReleases }
81
+ })
82
+
83
+ if (response.errors?.length) return
84
+
85
+ this.dispatchEvent(new CustomEvent('imported'))
86
+ }
87
+ }
@@ -0,0 +1,398 @@
1
+ import '@material/web/icon/icon.js'
2
+ import '@material/web/button/elevated-button.js'
3
+ import '@operato/data-grist/ox-grist.js'
4
+ import '@operato/data-grist/ox-filters-form.js'
5
+ import '@operato/data-grist/ox-record-creator.js'
6
+
7
+ import { CommonButtonStyles, CommonHeaderStyles, CommonGristStyles, ScrollbarStyles } from '@operato/styles'
8
+ import { PageView, store } from '@operato/shell'
9
+ import { css, html } from 'lit'
10
+ import { customElement, property, query } from 'lit/decorators.js'
11
+ import { ScopedElementsMixin } from '@open-wc/scoped-elements'
12
+ import { ColumnConfig, DataGrist, FetchOption } from '@operato/data-grist'
13
+ import { client } from '@operato/graphql'
14
+ import { i18next, localize } from '@operato/i18n'
15
+ import { notify, openPopup } from '@operato/layout'
16
+ import { OxPopup, OxPrompt } from '@operato/popup'
17
+ import { isMobileDevice } from '@operato/utils'
18
+
19
+ import { connect } from 'pwa-helpers/connect-mixin'
20
+ import gql from 'graphql-tag'
21
+
22
+ import { PdfReleaseImporter } from './pdf-release-importer'
23
+
24
+ @customElement('pdf-release-list-page')
25
+ export class PdfReleaseListPage extends connect(store)(localize(i18next)(ScopedElementsMixin(PageView))) {
26
+
27
+ static styles = [
28
+ ScrollbarStyles,
29
+ CommonGristStyles,
30
+ CommonHeaderStyles,
31
+ css`
32
+ :host {
33
+ display: flex;
34
+
35
+ width: 100%;
36
+
37
+ --grid-record-emphasized-background-color: #8B0000;
38
+ --grid-record-emphasized-color: #FF6B6B;
39
+ }
40
+
41
+ ox-grist {
42
+ overflow-y: auto;
43
+ flex: 1;
44
+ }
45
+
46
+ ox-filters-form {
47
+ flex: 1;
48
+ }
49
+ `
50
+ ]
51
+
52
+ static get scopedElements() {
53
+ return {
54
+ 'pdf-release-importer': PdfReleaseImporter
55
+ }
56
+ }
57
+
58
+ @property({ type: Object }) gristConfig: any
59
+ @property({ type: String }) mode: 'CARD' | 'GRID' | 'LIST' = isMobileDevice() ? 'CARD' : 'GRID'
60
+
61
+ @query('ox-grist') private grist!: DataGrist
62
+
63
+ get context() {
64
+ return {
65
+ title: i18next.t('title.pdf-release list'),
66
+ search: {
67
+ handler: (search: string) => {
68
+ this.grist.searchText = search
69
+ },
70
+ value: this.grist.searchText
71
+ },
72
+ filter: {
73
+ handler: () => {
74
+ this.grist.toggleHeadroom()
75
+ }
76
+ },
77
+ help: 'pdf/pdf-release',
78
+ actions: [
79
+ {
80
+ title: i18next.t('button.save'),
81
+ action: this._updatePdfRelease.bind(this),
82
+ ...CommonButtonStyles.save
83
+ },
84
+ {
85
+ title: i18next.t('button.delete'),
86
+ action: this._deletePdfRelease.bind(this),
87
+ ...CommonButtonStyles.delete
88
+ }
89
+ ],
90
+ exportable: {
91
+ name: i18next.t('title.pdf-release list'),
92
+ data: this.exportHandler.bind(this)
93
+ },
94
+ importable: {
95
+ handler: this.importHandler.bind(this)
96
+ }
97
+ }
98
+ }
99
+
100
+ render() {
101
+ const mode = this.mode || (isMobileDevice() ? 'CARD' : 'GRID')
102
+
103
+ return html`
104
+ <ox-grist
105
+ .mode=${mode}
106
+ .config=${this.gristConfig}
107
+ .fetchHandler=${this.fetchHandler.bind(this)}
108
+ >
109
+ <div slot="headroom" class="header">
110
+ <div class="filters">
111
+ <ox-filters-form autofocus without-search></ox-filters-form>
112
+
113
+ <div id="modes">
114
+ <md-icon @click=${() => (this.mode = 'GRID')} ?active=${mode == 'GRID'}>grid_on</md-icon>
115
+ <md-icon @click=${() => (this.mode = 'LIST')} ?active=${mode == 'LIST'}>format_list_bulleted</md-icon>
116
+ <md-icon @click=${() => (this.mode = 'CARD')} ?active=${mode == 'CARD'}>apps</md-icon>
117
+ </div>
118
+
119
+ <ox-record-creator id="add" .callback=${this.creationCallback.bind(this)}>
120
+ <button>
121
+ <md-icon>add</md-icon>
122
+ </button>
123
+ </ox-record-creator>
124
+
125
+ </div>
126
+ </div>
127
+ </ox-grist>
128
+ `
129
+ }
130
+
131
+ async pageInitialized(lifecycle: any) {
132
+ this.gristConfig = {
133
+ list: {
134
+ fields: ['name', 'description'],
135
+ details: ['active', 'updatedAt']
136
+ },
137
+ columns: [
138
+ { type: 'gutter', gutterName: 'sequence' },
139
+ { type: 'gutter', gutterName: 'row-selector', multiple: true },
140
+ {
141
+ type: 'string',
142
+ name: 'name',
143
+ header: i18next.t('field.name'),
144
+ record: {
145
+ editable: true
146
+ },
147
+ filter: 'search',
148
+ sortable: true,
149
+ width: 150
150
+ },
151
+ {
152
+ type: 'string',
153
+ name: 'description',
154
+ header: i18next.t('field.description'),
155
+ record: {
156
+ editable: true
157
+ },
158
+ filter: 'search',
159
+ width: 200
160
+ },
161
+ {
162
+ type: 'checkbox',
163
+ name: 'active',
164
+ label: true,
165
+ header: i18next.t('field.active'),
166
+ record: {
167
+ editable: true
168
+ },
169
+ filter: true,
170
+ sortable: true,
171
+ width: 60
172
+ },
173
+ {
174
+ type: 'resource-object',
175
+ name: 'updater',
176
+ header: i18next.t('field.updater'),
177
+ record: {
178
+ editable: false
179
+ },
180
+ sortable: true,
181
+ width: 120
182
+ },
183
+ {
184
+ type: 'datetime',
185
+ name: 'updatedAt',
186
+ header: i18next.t('field.updated_at'),
187
+ record: {
188
+ editable: false
189
+ },
190
+ sortable: true,
191
+ width: 180
192
+ }
193
+ ],
194
+ rows: {
195
+ appendable: false,
196
+ selectable: {
197
+ multiple: true
198
+ }
199
+ },
200
+ sorters: [
201
+ {
202
+ name: 'name'
203
+ }
204
+ ]
205
+ }
206
+ }
207
+
208
+ async pageUpdated(changes: any, lifecycle: any) {
209
+ if (this.active) {
210
+ // do something here when this page just became as active
211
+ }
212
+ }
213
+
214
+ async fetchHandler({ page = 1, limit = 100, sortings = [], filters = [] }: FetchOption) {
215
+ const response = await client.query({
216
+ query: gql`
217
+ query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
218
+ responses: pdfReleases(filters: $filters, pagination: $pagination, sortings: $sortings) {
219
+ items {
220
+ id
221
+ name
222
+ description
223
+ active
224
+ updater {
225
+ id
226
+ name
227
+ }
228
+ updatedAt
229
+ }
230
+ total
231
+ }
232
+ }
233
+ `,
234
+ variables: {
235
+ filters,
236
+ pagination: { page, limit },
237
+ sortings
238
+ }
239
+ })
240
+
241
+ return {
242
+ total: response.data.responses.total || 0,
243
+ records: response.data.responses.items || []
244
+ }
245
+ }
246
+
247
+ async _deletePdfRelease() {
248
+ if (
249
+ await OxPrompt.open({
250
+ title: i18next.t('text.are_you_sure'),
251
+ text: i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }),
252
+ confirmButton: { text: i18next.t('button.confirm') },
253
+ cancelButton: { text: i18next.t('button.cancel') }
254
+ })
255
+ ) {
256
+ const ids = this.grist.selected.map(record => record.id)
257
+ if (ids && ids.length > 0) {
258
+ const response = await client.mutate({
259
+ mutation: gql`
260
+ mutation ($ids: [String!]!) {
261
+ deletePdfReleases(ids: $ids)
262
+ }
263
+ `,
264
+ variables: {
265
+ ids
266
+ }
267
+ })
268
+
269
+ if (!response.errors) {
270
+ this.grist.fetch()
271
+ notify({
272
+ message: i18next.t('text.info_x_successfully', { x: i18next.t('text.delete') })
273
+ })
274
+ }
275
+ }
276
+ }
277
+ }
278
+
279
+ async _updatePdfRelease() {
280
+ let patches = this.grist.dirtyRecords
281
+ if (patches && patches.length) {
282
+ patches = patches.map(patch => {
283
+ let patchField: any = patch.id ? { id: patch.id } : {}
284
+ const dirtyFields = patch.__dirtyfields__
285
+ for (let key in dirtyFields) {
286
+ patchField[key] = dirtyFields[key].after
287
+ }
288
+ patchField.cuFlag = patch.__dirty__
289
+
290
+ return patchField
291
+ })
292
+
293
+ const response = await client.mutate({
294
+ mutation: gql`
295
+ mutation ($patches: [PdfReleasePatch!]!) {
296
+ updateMultiplePdfRelease(patches: $patches) {
297
+ name
298
+ }
299
+ }
300
+ `,
301
+ variables: {
302
+ patches
303
+ }
304
+ })
305
+
306
+ if (!response.errors) {
307
+ this.grist.fetch()
308
+ }
309
+ }
310
+ }
311
+
312
+ async creationCallback(pdfRelease) {
313
+ try {
314
+ const response = await client.query({
315
+ query: gql`
316
+ mutation ($pdfRelease: NewPdfRelease!) {
317
+ createPdfRelease(pdfRelease: $pdfRelease) {
318
+ id
319
+ }
320
+ }
321
+ `,
322
+ variables: {
323
+ pdfRelease
324
+ },
325
+ context: {
326
+ hasUpload: true
327
+ }
328
+ })
329
+
330
+ if (!response.errors) {
331
+ this.grist.fetch()
332
+ document.dispatchEvent(
333
+ new CustomEvent('notify', {
334
+ detail: {
335
+ message: i18next.t('text.data_created_successfully')
336
+ }
337
+ })
338
+ )
339
+ }
340
+
341
+ return true
342
+ } catch (ex) {
343
+ console.error(ex)
344
+ document.dispatchEvent(
345
+ new CustomEvent('notify', {
346
+ detail: {
347
+ type: 'error',
348
+ message: i18next.t('text.error')
349
+ }
350
+ })
351
+ )
352
+ return false
353
+ }
354
+ }
355
+
356
+ async exportHandler() {
357
+ const exportTargets = this.grist.selected.length ? this.grist.selected : this.grist.dirtyData.records
358
+ const targetFieldSet = new Set([
359
+ 'id',
360
+ 'name',
361
+ 'description',
362
+ 'active'
363
+ ])
364
+
365
+ return exportTargets.map(pdfRelease => {
366
+ let tempObj = {}
367
+ for (const field of targetFieldSet) {
368
+ tempObj[field] = pdfRelease[field]
369
+ }
370
+
371
+ return tempObj
372
+ })
373
+ }
374
+
375
+ async importHandler(records) {
376
+ const popup = openPopup(
377
+ html`
378
+ <pdf-release-importer
379
+ .pdfReleases=${records}
380
+ @imported=${() => {
381
+ history.back()
382
+ this.grist.fetch()
383
+ }}
384
+ ></pdf-release-importer>
385
+ `,
386
+ {
387
+ backdrop: true,
388
+ size: 'large',
389
+ title: i18next.t('title.import pdf-release')
390
+ }
391
+ )
392
+
393
+ popup.onclosed = () => {
394
+ this.grist.fetch()
395
+ }
396
+ }
397
+ }
398
+
@@ -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 PDFTemplateImporter extends LitElement {
14
+ static styles = [
15
+ CommonHeaderStyles,
16
+ css`
17
+ :host {
18
+ display: flex;
19
+ flex-direction: column;
20
+
21
+ background-color: #fff;
22
+ }
23
+
24
+ ox-grist {
25
+ flex: 1;
26
+ }
27
+ `
28
+ ]
29
+
30
+ @property({ type: Array }) pdfTemplates: 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.pdfTemplates
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 importPDFTemplates($pdfTemplates: [PDFTemplatePatch!]!) {
77
+ importPDFTemplates(pdfTemplates: $pdfTemplates)
78
+ }
79
+ `,
80
+ variables: { pdfTemplates: this.pdfTemplates }
81
+ })
82
+
83
+ if (response.errors?.length) return
84
+
85
+ this.dispatchEvent(new CustomEvent('imported'))
86
+ }
87
+ }