@things-factory/pdf 10.1.255 → 10.1.257

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,15 +1,16 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import '@operato/input/ox-input-file.js';
3
3
  import '@operato/list-state/ox-page-state.js';
4
- import { client } from '@operato/graphql';
4
+ import { client, MutationController, QueryController } from '@operato/graphql';
5
5
  import { i18next, localize } from '@operato/i18n';
6
- import { navigate, PageView } from '@operato/shell';
6
+ import { navigate, PageView, DraftController } from '@operato/shell';
7
7
  import { ButtonStyles, DocumentPageStyles, FormFieldStyles } from '@operato/styles';
8
8
  import gql from 'graphql-tag';
9
9
  import { css, html, nothing } from 'lit';
10
10
  import { customElement, state } from 'lit/decorators.js';
11
11
  const FIELDS = 'id name description active state page_size watermark content_template header_template footer_template cover_template last_template';
12
12
  const PAGE_SIZES = ['A4', 'A3', 'A5', 'Letter', 'Legal', 'Tabloid'];
13
+ const reasonOf = (error) => error?.graphQLErrors?.[0]?.message ?? error?.errors?.[0]?.message ?? error?.message ?? String(error);
13
14
  const blank = () => ({ name: '', description: '', active: true, state: 'draft', page_size: 'A4', watermark: '', content_template: '', header_template: '', footer_template: '', cover_template: '', last_template: '' });
14
15
  /**
15
16
  * One PDF template: its parts are Handlebars HTML, written here or loaded from a file, and printed to a PDF with
@@ -19,11 +20,19 @@ let PDFTemplateEditor = class PDFTemplateEditor extends localize(i18next)(PageVi
19
20
  constructor() {
20
21
  super(...arguments);
21
22
  this.templateId = '';
22
- this.form = blank();
23
23
  this.sample = '{}';
24
24
  this.preview = '';
25
- this.busy = false;
26
- this.failure = '';
25
+ /* A preview being printed - a read on demand - and why it failed. */
26
+ this.previewing = false;
27
+ this.previewFailure = '';
28
+ /* The template the address names (ADR-0190). */
29
+ this.template = new QueryController(this, gql(`query ($id: String!) { PDFTemplate(id: $id) { ${FIELDS} } }`), {
30
+ variables: () => (this.templateId ? { id: this.templateId } : undefined)
31
+ });
32
+ this.creating = new MutationController(this, gql `mutation ($template: NewPDFTemplate!) { template: createPDFTemplate(pdfTemplate: $template) { id } }`, { showsError: true });
33
+ this.updating = new MutationController(this, gql `mutation ($id: String!, $patch: PDFTemplatePatch!) { template: updatePDFTemplate(id: $id, patch: $patch) { id } }`, { showsError: true, refetch: () => [this.template] });
34
+ /* The form as changed here over the template read (a blank one for a new template). */
35
+ this.draft = new DraftController(this, { read: () => this.stored, key: () => this.templateId });
27
36
  }
28
37
  static { this.styles = [
29
38
  DocumentPageStyles,
@@ -57,6 +66,17 @@ let PDFTemplateEditor = class PDFTemplateEditor extends localize(i18next)(PageVi
57
66
  }
58
67
  `
59
68
  ]; }
69
+ get stored() {
70
+ const { id, ...template } = this.template.data?.PDFTemplate ?? {};
71
+ return id ? { ...blank(), ...Object.fromEntries(Object.entries(template).map(([key, value]) => [key, value ?? ''])) } : blank();
72
+ }
73
+ get busy() {
74
+ return this.previewing || this.creating.pending || this.updating.pending;
75
+ }
76
+ get failure() {
77
+ const error = this.creating.error ?? this.updating.error;
78
+ return error ? reasonOf(error) : this.previewFailure;
79
+ }
60
80
  get context() {
61
81
  return {
62
82
  title: i18next.t('title.pdf-template'),
@@ -69,48 +89,20 @@ let PDFTemplateEditor = class PDFTemplateEditor extends localize(i18next)(PageVi
69
89
  if (!this.active || !(changes.active || changes.params))
70
90
  return;
71
91
  this.templateId = lifecycle?.params?.id ?? '';
72
- this.form = blank();
73
92
  this.preview = '';
74
- if (this.templateId)
75
- this.read();
76
93
  }
77
- async read() {
78
- const response = await client.query({ query: gql(`query ($id: String!) { PDFTemplate(id: $id) { ${FIELDS} } }`), variables: { id: this.templateId }, fetchPolicy: 'no-cache' });
79
- const { id, ...template } = response.data?.PDFTemplate ?? {};
80
- if (id)
81
- this.form = { ...blank(), ...Object.fromEntries(Object.entries(template).map(([key, value]) => [key, value ?? ''])) };
82
- }
83
- async run(work) {
94
+ async save() {
84
95
  if (this.busy)
85
96
  return;
86
- this.busy = true;
87
- this.failure = '';
97
+ this.previewFailure = '';
98
+ const id = this.templateId;
99
+ /* The save action is gone while it is out. */
100
+ const saving = this.draft.submit(sent => (id ? this.updating.run({ id, patch: sent }) : this.creating.run({ template: { ...blank(), ...sent } })));
88
101
  this.updateContext();
89
- try {
90
- await work();
91
- }
92
- catch (error) {
93
- this.failure = error?.graphQLErrors?.[0]?.message ?? error?.errors?.[0]?.message ?? error?.message ?? String(error);
94
- }
95
- finally {
96
- this.busy = false;
97
- this.updateContext();
98
- }
99
- }
100
- save() {
101
- return this.run(async () => {
102
- const id = this.templateId;
103
- const response = await client.mutate({
104
- mutation: gql(id
105
- ? `mutation ($id: String!, $patch: PDFTemplatePatch!) { template: updatePDFTemplate(id: $id, patch: $patch) { id } }`
106
- : `mutation ($template: NewPDFTemplate!) { template: createPDFTemplate(pdfTemplate: $template) { id } }`),
107
- variables: id ? { id, patch: this.form } : { template: this.form }
108
- });
109
- if (response.errors?.length)
110
- throw response;
111
- if (!id)
112
- navigate(`pdf-template-editor?id=${response.data.template.id}`);
113
- });
102
+ const saved = await saving;
103
+ this.updateContext();
104
+ if (saved && !id)
105
+ navigate(`pdf-template-editor?id=${saved.template.id}`);
114
106
  }
115
107
  /** The saved template printed with the sample data — save first to see a change. */
116
108
  showPreview() {
@@ -119,26 +111,42 @@ let PDFTemplateEditor = class PDFTemplateEditor extends localize(i18next)(PageVi
119
111
  this.preview = '';
120
112
  return;
121
113
  }
122
- return this.run(async () => {
114
+ if (this.busy)
115
+ return;
116
+ return this.printPreview();
117
+ }
118
+ async printPreview() {
119
+ this.previewing = true;
120
+ this.previewFailure = '';
121
+ this.updateContext();
122
+ try {
123
123
  const data = JSON.parse(this.sample || '{}');
124
124
  const response = await client.query({ query: gql `query ($id: String!, $data: Object) { renderPDF(templateId: $id, data: $data) }`, variables: { id: this.templateId, data }, fetchPolicy: 'no-cache' });
125
125
  if (response.errors?.length)
126
126
  throw response;
127
127
  const bytes = Uint8Array.from(atob(response.data.renderPDF), c => c.charCodeAt(0));
128
128
  this.preview = URL.createObjectURL(new Blob([bytes], { type: 'application/pdf' }));
129
- });
129
+ }
130
+ catch (error) {
131
+ this.previewFailure = reasonOf(error);
132
+ }
133
+ finally {
134
+ this.previewing = false;
135
+ this.updateContext();
136
+ }
130
137
  }
131
138
  /* Read here into the part's text, never uploaded: the picker is local and checks the type only. */
132
139
  async load(key, file) {
133
140
  if (file)
134
- this.form = { ...this.form, [key]: await file.text() };
141
+ this.draft.set(key, await file.text());
135
142
  }
136
143
  render() {
137
- const patch = (key, value) => (this.form = { ...this.form, [key]: value });
138
- const text = (key, label) => html `<label>${label}<input .value=${this.form[key] ?? ''} @input=${(e) => patch(key, e.target.value)} /></label>`;
144
+ const value = (key) => this.draft.value(key);
145
+ const patch = (key, given) => this.draft.set(key, given);
146
+ const text = (key, label) => html `<label>${label}<input .value=${value(key) ?? ''} @input=${(e) => patch(key, e.target.value)} /></label>`;
139
147
  const part = (key, label, wide = '') => html `<label class="wide"
140
148
  >${label}
141
- <textarea class=${wide} .value=${this.form[key] ?? ''} @input=${(e) => patch(key, e.target.value)}></textarea>
149
+ <textarea class=${wide} .value=${value(key) ?? ''} @input=${(e) => patch(key, e.target.value)}></textarea>
142
150
  <ox-input-file
143
151
  quiet
144
152
  local
@@ -155,8 +163,8 @@ let PDFTemplateEditor = class PDFTemplateEditor extends localize(i18next)(PageVi
155
163
  ${text('name', i18next.t('field.name'))}${text('description', i18next.t('field.description'))}
156
164
  <label
157
165
  >${i18next.t('field.page_size')}
158
- <select .value=${this.form.page_size} @change=${(e) => patch('page_size', e.target.value)}>
159
- ${PAGE_SIZES.map(size => html `<option value=${size} ?selected=${size === this.form.page_size}>${size}</option>`)}
166
+ <select .value=${value('page_size')} @change=${(e) => patch('page_size', e.target.value)}>
167
+ ${PAGE_SIZES.map(size => html `<option value=${size} ?selected=${size === value('page_size')}>${size}</option>`)}
160
168
  </select></label
161
169
  >
162
170
  ${text('watermark', i18next.t('field.watermark'))}
@@ -179,10 +187,6 @@ __decorate([
179
187
  state(),
180
188
  __metadata("design:type", Object)
181
189
  ], PDFTemplateEditor.prototype, "templateId", void 0);
182
- __decorate([
183
- state(),
184
- __metadata("design:type", Object)
185
- ], PDFTemplateEditor.prototype, "form", void 0);
186
190
  __decorate([
187
191
  state(),
188
192
  __metadata("design:type", Object)
@@ -194,11 +198,11 @@ __decorate([
194
198
  __decorate([
195
199
  state(),
196
200
  __metadata("design:type", Object)
197
- ], PDFTemplateEditor.prototype, "busy", void 0);
201
+ ], PDFTemplateEditor.prototype, "previewing", void 0);
198
202
  __decorate([
199
203
  state(),
200
204
  __metadata("design:type", Object)
201
- ], PDFTemplateEditor.prototype, "failure", void 0);
205
+ ], PDFTemplateEditor.prototype, "previewFailure", void 0);
202
206
  PDFTemplateEditor = __decorate([
203
207
  customElement('pdf-template-editor')
204
208
  ], PDFTemplateEditor);
@@ -1 +1 @@
1
- {"version":3,"file":"pdf-template-editor.js","sourceRoot":"","sources":["../../../client/pages/pdf-template/pdf-template-editor.ts"],"names":[],"mappings":";AAAA,OAAO,iCAAiC,CAAA;AACxC,OAAO,sCAAsC,CAAA;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACnF,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAExD,MAAM,MAAM,GAAG,oIAAoI,CAAA;AACnJ,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI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;;qDAAwB;AACf;IAAhB,KAAK,EAAE;;+CAA4C;AACnC;IAAhB,KAAK,EAAE;;iDAAsB;AACb;IAAhB,KAAK,EAAE;;kDAAqB;AACZ;IAAhB,KAAK,EAAE;;+CAAqB;AACZ;IAAhB,KAAK,EAAE;;kDAAqB;AAvClB,iBAAiB;IAD7B,aAAa,CAAC,qBAAqB,CAAC;GACxB,iBAAiB,CA6J7B","sourcesContent":["import '@operato/input/ox-input-file.js'\nimport '@operato/list-state/ox-page-state.js'\n\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { navigate, PageView } from '@operato/shell'\nimport { ButtonStyles, DocumentPageStyles, FormFieldStyles } from '@operato/styles'\nimport gql from 'graphql-tag'\nimport { css, html, nothing } from 'lit'\nimport { customElement, state } from 'lit/decorators.js'\n\nconst FIELDS = 'id name description active state page_size watermark content_template header_template footer_template cover_template last_template'\nconst PAGE_SIZES = ['A4', 'A3', 'A5', 'Letter', 'Legal', 'Tabloid']\nconst blank = () => ({ name: '', description: '', active: true, state: 'draft', page_size: 'A4', watermark: '', content_template: '', header_template: '', footer_template: '', cover_template: '', last_template: '' })\n\n/**\n * One PDF template: its parts are Handlebars HTML, written here or loaded from a file, and printed to a PDF with\n * sample data before it is used.\n */\n@customElement('pdf-template-editor')\nexport class PDFTemplateEditor extends localize(i18next)(PageView) {\n static styles = [\n DocumentPageStyles,\n FormFieldStyles,\n ButtonStyles,\n css`\n .form {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));\n gap: var(--spacing-large);\n }\n label {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-small);\n }\n label.wide {\n grid-column: 1 / -1;\n }\n textarea {\n font-family: monospace;\n min-height: 12em;\n }\n textarea.content {\n min-height: 40vh;\n }\n iframe {\n width: 100%;\n height: 80vh;\n border: 1px solid var(--md-sys-color-outline-variant);\n }\n `\n ]\n\n @state() private templateId = ''\n @state() private form: Record<string, any> = blank()\n @state() private sample = '{}'\n @state() private preview = ''\n @state() private busy = false\n @state() private failure = ''\n\n get context() {\n return {\n title: i18next.t('title.pdf-template'),\n menu: 'pdf-template-list-page',\n frame: 'document',\n actions: this.busy ? [] : [{ title: i18next.t('button.save'), icon: 'save', emphasis: { raised: true }, action: () => this.save() }]\n }\n }\n\n pageUpdated(changes: any, lifecycle: any) {\n if (!this.active || !(changes.active || changes.params)) return\n this.templateId = lifecycle?.params?.id ?? ''\n this.form = blank()\n this.preview = ''\n if (this.templateId) this.read()\n }\n\n private async read() {\n const response = await client.query({ query: gql(`query ($id: String!) { PDFTemplate(id: $id) { ${FIELDS} } }`), variables: { id: this.templateId }, fetchPolicy: 'no-cache' })\n const { id, ...template } = response.data?.PDFTemplate ?? {}\n if (id) this.form = { ...blank(), ...Object.fromEntries(Object.entries(template).map(([key, value]) => [key, value ?? ''])) }\n }\n\n private async run(work: () => Promise<void>) {\n if (this.busy) return\n this.busy = true\n this.failure = ''\n this.updateContext()\n try {\n await work()\n } catch (error: any) {\n this.failure = error?.graphQLErrors?.[0]?.message ?? error?.errors?.[0]?.message ?? error?.message ?? String(error)\n } finally {\n this.busy = false\n this.updateContext()\n }\n }\n\n private save() {\n return this.run(async () => {\n const id = this.templateId\n const response = await client.mutate({\n mutation: gql(\n id\n ? `mutation ($id: String!, $patch: PDFTemplatePatch!) { template: updatePDFTemplate(id: $id, patch: $patch) { id } }`\n : `mutation ($template: NewPDFTemplate!) { template: createPDFTemplate(pdfTemplate: $template) { id } }`\n ),\n variables: id ? { id, patch: this.form } : { template: this.form }\n })\n if (response.errors?.length) throw response\n if (!id) navigate(`pdf-template-editor?id=${response.data.template.id}`)\n })\n }\n\n /** The saved template printed with the sample data — save first to see a change. */\n private showPreview() {\n if (this.preview) {\n URL.revokeObjectURL(this.preview)\n this.preview = ''\n return\n }\n return this.run(async () => {\n const data = JSON.parse(this.sample || '{}')\n const response = await client.query({ query: gql`query ($id: String!, $data: Object) { renderPDF(templateId: $id, data: $data) }`, variables: { id: this.templateId, data }, fetchPolicy: 'no-cache' })\n if (response.errors?.length) throw response\n const bytes = Uint8Array.from(atob(response.data.renderPDF), c => c.charCodeAt(0))\n this.preview = URL.createObjectURL(new Blob([bytes], { type: 'application/pdf' }))\n })\n }\n\n /* Read here into the part's text, never uploaded: the picker is local and checks the type only. */\n private async load(key: string, file?: File) {\n if (file) this.form = { ...this.form, [key]: await file.text() }\n }\n\n render() {\n const patch = (key: string, value: any) => (this.form = { ...this.form, [key]: value })\n const text = (key: string, label: string) => html`<label>${label}<input .value=${this.form[key] ?? ''} @input=${(e: any) => patch(key, e.target.value)} /></label>`\n const part = (key: string, label: string, wide = '') => html`<label class=\"wide\"\n >${label}\n <textarea class=${wide} .value=${this.form[key] ?? ''} @input=${(e: any) => patch(key, e.target.value)}></textarea>\n <ox-input-file\n quiet\n local\n hide-filelist\n accept=\".html,.htm,text/html\"\n .label=${i18next.t('button.load-html-file')}\n @change=${(e: CustomEvent) => this.load(key, e.detail?.[0])}\n ></ox-input-file>\n </label>`\n return html`<div class=\"page\">\n ${this.failure ? html`<p class=\"notice crit\" role=\"alert\">${this.failure}</p>` : nothing}\n <section class=\"page-section\">\n <div class=\"form\">\n ${text('name', i18next.t('field.name'))}${text('description', i18next.t('field.description'))}\n <label\n >${i18next.t('field.page_size')}\n <select .value=${this.form.page_size} @change=${(e: any) => patch('page_size', e.target.value)}>\n ${PAGE_SIZES.map(size => html`<option value=${size} ?selected=${size === this.form.page_size}>${size}</option>`)}\n </select></label\n >\n ${text('watermark', i18next.t('field.watermark'))}\n ${part('content_template', i18next.t('field.content_template'), 'content')}${part('header_template', i18next.t('field.header_template'))}${part('footer_template', i18next.t('field.footer_template'))}${part('cover_template', i18next.t('field.cover_template'))}${part('last_template', i18next.t('field.last_template'))}\n </div>\n </section>\n ${this.templateId\n ? html`<section class=\"page-section\">\n <div class=\"form\">\n <label class=\"wide\">${i18next.t('field.pdf-sample-data')}<textarea .value=${this.sample} @input=${(e: any) => (this.sample = e.target.value)}></textarea></label>\n </div>\n <button ?disabled=${this.busy} @click=${() => this.showPreview()}>${i18next.t('button.pdf-preview')}</button>\n ${this.preview ? html`<iframe title=${i18next.t('button.pdf-preview')} src=${this.preview}></iframe>` : nothing}\n </section>`\n : nothing}\n </div>`\n }\n}\n"]}
1
+ {"version":3,"file":"pdf-template-editor.js","sourceRoot":"","sources":["../../../client/pages/pdf-template/pdf-template-editor.ts"],"names":[],"mappings":";AAAA,OAAO,iCAAiC,CAAA;AACxC,OAAO,sCAAsC,CAAA;AAE7C,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAC9E,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACnF,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAExD,MAAM,MAAM,GAAG,oIAAoI,CAAA;AACnJ,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;AACnE,MAAM,QAAQ,GAAG,CAAC,KAAU,EAAU,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAA;AAC7I,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE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AI,CAAC,UAAU;YACf,CAAC,CAAC,IAAI,CAAA;;oCAEsB,OAAO,CAAC,CAAC,CAAC,uBAAuB,CAAC,oBAAoB,IAAI,CAAC,MAAM,WAAW,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;;gCAE1H,IAAI,CAAC,IAAI,WAAW,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,oBAAoB,CAAC;cACjG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAA,iBAAiB,OAAO,CAAC,CAAC,CAAC,oBAAoB,CAAC,QAAQ,IAAI,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,OAAO;qBACtG;YACb,CAAC,CAAC,OAAO;WACN,CAAA;IACT,CAAC;;AA/IgB;IAAhB,KAAK,EAAE;;qDAAwB;AACf;IAAhB,KAAK,EAAE;;iDAAsB;AACb;IAAhB,KAAK,EAAE;;kDAAqB;AAEZ;IAAhB,KAAK,EAAE;;qDAA2B;AAClB;IAAhB,KAAK,EAAE;;yDAA4B;AAvCzB,iBAAiB;IAD7B,aAAa,CAAC,qBAAqB,CAAC;GACxB,iBAAiB,CAkL7B","sourcesContent":["import '@operato/input/ox-input-file.js'\nimport '@operato/list-state/ox-page-state.js'\n\nimport { client, MutationController, QueryController } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { navigate, PageView, DraftController } from '@operato/shell'\nimport { ButtonStyles, DocumentPageStyles, FormFieldStyles } from '@operato/styles'\nimport gql from 'graphql-tag'\nimport { css, html, nothing } from 'lit'\nimport { customElement, state } from 'lit/decorators.js'\n\nconst FIELDS = 'id name description active state page_size watermark content_template header_template footer_template cover_template last_template'\nconst PAGE_SIZES = ['A4', 'A3', 'A5', 'Letter', 'Legal', 'Tabloid']\nconst reasonOf = (error: any): string => error?.graphQLErrors?.[0]?.message ?? error?.errors?.[0]?.message ?? error?.message ?? String(error)\nconst blank = () => ({ name: '', description: '', active: true, state: 'draft', page_size: 'A4', watermark: '', content_template: '', header_template: '', footer_template: '', cover_template: '', last_template: '' })\n\n/**\n * One PDF template: its parts are Handlebars HTML, written here or loaded from a file, and printed to a PDF with\n * sample data before it is used.\n */\n@customElement('pdf-template-editor')\nexport class PDFTemplateEditor extends localize(i18next)(PageView) {\n static styles = [\n DocumentPageStyles,\n FormFieldStyles,\n ButtonStyles,\n css`\n .form {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));\n gap: var(--spacing-large);\n }\n label {\n display: flex;\n flex-direction: column;\n gap: var(--spacing-small);\n }\n label.wide {\n grid-column: 1 / -1;\n }\n textarea {\n font-family: monospace;\n min-height: 12em;\n }\n textarea.content {\n min-height: 40vh;\n }\n iframe {\n width: 100%;\n height: 80vh;\n border: 1px solid var(--md-sys-color-outline-variant);\n }\n `\n ]\n\n @state() private templateId = ''\n @state() private sample = '{}'\n @state() private preview = ''\n /* A preview being printed - a read on demand - and why it failed. */\n @state() private previewing = false\n @state() private previewFailure = ''\n\n /* The template the address names (ADR-0190). */\n private template = new QueryController(this, gql(`query ($id: String!) { PDFTemplate(id: $id) { ${FIELDS} } }`), {\n variables: () => (this.templateId ? { id: this.templateId } : undefined)\n })\n\n private creating = new MutationController(\n this,\n gql`mutation ($template: NewPDFTemplate!) { template: createPDFTemplate(pdfTemplate: $template) { id } }`,\n { showsError: true }\n )\n\n private updating = new MutationController(\n this,\n gql`mutation ($id: String!, $patch: PDFTemplatePatch!) { template: updatePDFTemplate(id: $id, patch: $patch) { id } }`,\n { showsError: true, refetch: () => [this.template] }\n )\n\n /* The form as changed here over the template read (a blank one for a new template). */\n private draft = new DraftController<Record<string, any>>(this, { read: () => this.stored, key: () => this.templateId })\n\n private get stored(): Record<string, any> {\n const { id, ...template } = this.template.data?.PDFTemplate ?? {}\n return id ? { ...blank(), ...Object.fromEntries(Object.entries(template).map(([key, value]) => [key, value ?? ''])) } : blank()\n }\n\n private get busy() {\n return this.previewing || this.creating.pending || this.updating.pending\n }\n\n private get failure() {\n const error: any = this.creating.error ?? this.updating.error\n return error ? reasonOf(error) : this.previewFailure\n }\n\n get context() {\n return {\n title: i18next.t('title.pdf-template'),\n menu: 'pdf-template-list-page',\n frame: 'document',\n actions: this.busy ? [] : [{ title: i18next.t('button.save'), icon: 'save', emphasis: { raised: true }, action: () => this.save() }]\n }\n }\n\n pageUpdated(changes: any, lifecycle: any) {\n if (!this.active || !(changes.active || changes.params)) return\n this.templateId = lifecycle?.params?.id ?? ''\n this.preview = ''\n }\n\n private async save() {\n if (this.busy) return\n this.previewFailure = ''\n const id = this.templateId\n /* The save action is gone while it is out. */\n const saving = this.draft.submit(sent => (id ? this.updating.run({ id, patch: sent }) : this.creating.run({ template: { ...blank(), ...sent } })))\n this.updateContext()\n const saved = await saving\n this.updateContext()\n if (saved && !id) navigate(`pdf-template-editor?id=${saved.template.id}`)\n }\n\n /** The saved template printed with the sample data — save first to see a change. */\n private showPreview() {\n if (this.preview) {\n URL.revokeObjectURL(this.preview)\n this.preview = ''\n return\n }\n if (this.busy) return\n return this.printPreview()\n }\n\n private async printPreview() {\n this.previewing = true\n this.previewFailure = ''\n this.updateContext()\n try {\n const data = JSON.parse(this.sample || '{}')\n const response = await client.query({ query: gql`query ($id: String!, $data: Object) { renderPDF(templateId: $id, data: $data) }`, variables: { id: this.templateId, data }, fetchPolicy: 'no-cache' })\n if (response.errors?.length) throw response\n const bytes = Uint8Array.from(atob(response.data.renderPDF), c => c.charCodeAt(0))\n this.preview = URL.createObjectURL(new Blob([bytes], { type: 'application/pdf' }))\n } catch (error: any) {\n this.previewFailure = reasonOf(error)\n } finally {\n this.previewing = false\n this.updateContext()\n }\n }\n\n /* Read here into the part's text, never uploaded: the picker is local and checks the type only. */\n private async load(key: string, file?: File) {\n if (file) this.draft.set(key, await file.text())\n }\n\n render() {\n const value = (key: string) => this.draft.value(key)\n const patch = (key: string, given: any) => this.draft.set(key, given)\n const text = (key: string, label: string) => html`<label>${label}<input .value=${value(key) ?? ''} @input=${(e: any) => patch(key, e.target.value)} /></label>`\n const part = (key: string, label: string, wide = '') => html`<label class=\"wide\"\n >${label}\n <textarea class=${wide} .value=${value(key) ?? ''} @input=${(e: any) => patch(key, e.target.value)}></textarea>\n <ox-input-file\n quiet\n local\n hide-filelist\n accept=\".html,.htm,text/html\"\n .label=${i18next.t('button.load-html-file')}\n @change=${(e: CustomEvent) => this.load(key, e.detail?.[0])}\n ></ox-input-file>\n </label>`\n return html`<div class=\"page\">\n ${this.failure ? html`<p class=\"notice crit\" role=\"alert\">${this.failure}</p>` : nothing}\n <section class=\"page-section\">\n <div class=\"form\">\n ${text('name', i18next.t('field.name'))}${text('description', i18next.t('field.description'))}\n <label\n >${i18next.t('field.page_size')}\n <select .value=${value('page_size')} @change=${(e: any) => patch('page_size', e.target.value)}>\n ${PAGE_SIZES.map(size => html`<option value=${size} ?selected=${size === value('page_size')}>${size}</option>`)}\n </select></label\n >\n ${text('watermark', i18next.t('field.watermark'))}\n ${part('content_template', i18next.t('field.content_template'), 'content')}${part('header_template', i18next.t('field.header_template'))}${part('footer_template', i18next.t('field.footer_template'))}${part('cover_template', i18next.t('field.cover_template'))}${part('last_template', i18next.t('field.last_template'))}\n </div>\n </section>\n ${this.templateId\n ? html`<section class=\"page-section\">\n <div class=\"form\">\n <label class=\"wide\">${i18next.t('field.pdf-sample-data')}<textarea .value=${this.sample} @input=${(e: any) => (this.sample = e.target.value)}></textarea></label>\n </div>\n <button ?disabled=${this.busy} @click=${() => this.showPreview()}>${i18next.t('button.pdf-preview')}</button>\n ${this.preview ? html`<iframe title=${i18next.t('button.pdf-preview')} src=${this.preview}></iframe>` : nothing}\n </section>`\n : nothing}\n </div>`\n }\n}\n"]}
@@ -328,7 +328,7 @@ let PDFTemplateListPage = class PDFTemplateListPage extends localize(i18next)(Sc
328
328
  }
329
329
  async creationCallback(pdfTemplate) {
330
330
  try {
331
- const response = await client.query({ query: gql `
331
+ const response = await client.mutate({ mutation: gql `
332
332
  mutation ($pdfTemplate: NewPDFTemplate!) { createPDFTemplate(pdfTemplate: $pdfTemplate) { id
333
333
  }
334
334
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pdf-template-list-page.js","sourceRoot":"","sources":["../../../client/pages/pdf-template/pdf-template-list-page.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,yCAAyC,CAAA;AAChD,OAAO,iCAAiC,CAAA;AACxC,OAAO,wCAAwC,CAAA;AAC/C,OAAO,0CAA0C,CAAA;AAEjD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACnI,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAgB,SAAS,EAAe,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAW,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAGtD,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,QAAQ,CAAC,OA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;QACnB,CAAC,CAAC,CAAA;IACF,CAAC;IAEA,KAAK,CAAC,aAAa,CAAC,OAAO;QAAQ,MAAM,KAAK,GAAG,SAAS,CACtD,IAAI,CAAA;;0BAEgB,OAAO;sBACX,GAAG,EAAE;YAAe,OAAO,CAAC,IAAI,EAAE,CAAA;YAC5C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QAC7B,CAAC;;OAEK,EACD,EAAU,QAAQ,EAAE,IAAI;YACtB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,2BAA2B,CAAC;SACnD,CACG,CAAA;QAED,KAAK,CAAC,QAAQ,GAAG,GAAG,EAAE;YAAS,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QACpD,CAAC,CAAA;IACD,CAAC;;AAhW4B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;wDAAiB;AAChB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDAAoE;AAEpE;IAA1B,KAAK,CAAC,UAAU,CAAC;8BAAiB,SAAS;kDAAA;AAxBjC,mBAAmB;IAD/B,aAAa,CAAC,wBAAwB,CAAC;GAC3B,mBAAmB,CAsX/B","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@material/web/button/elevated-button.js'\nimport '@operato/data-grist/ox-grist.js'\nimport '@operato/data-grist/ox-filters-form.js'\nimport '@operato/data-grist/ox-record-creator.js'\n\nimport { CommonButtonStyles, CommonHeaderStyles, CommonGristStyles, ScrollbarStyles, WorkSurfacePageStyles } from '@operato/styles'\nimport { navigate, PageView } from '@operato/shell'\nimport { css, html } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\nimport { ScopedElementsMixin } from '@open-wc/scoped-elements'\nimport { ColumnConfig, DataGrist, FetchOption } from '@operato/data-grist'\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { notify, openPopup } from '@operato/layout'\nimport { OxPopup, OxPrompt } from '@operato/popup'\nimport { isMobileDevice } from '@operato/utils'\n\nimport gql from 'graphql-tag'\n\nimport { PDFTemplateImporter } from './pdf-template-importer'\n\n@customElement('pdf-template-list-page')\nexport class PDFTemplateListPage extends localize(i18next)(ScopedElementsMixin(PageView)) { static styles = [\n /* The work surface frame for a list screen (ADR-0060 decision 8). */\n WorkSurfacePageStyles,\n ScrollbarStyles,\n CommonGristStyles,\n CommonHeaderStyles,\n css`\n :host {\n --grid-record-emphasized-background-color: #8b0000;\n --grid-record-emphasized-color: #ff6b6b;\n }\n\n ox-filters-form { flex: 1;\n }\n `\n ]\n\n static get scopedElements() { return { 'pdf-template-importer': PDFTemplateImporter\n }\n }\n\n @property({ type: Object }) gristConfig: any\n @property({ type: String }) mode: 'CARD' | 'GRID' | 'LIST' = isMobileDevice() ? 'CARD' : 'GRID'\n\n @query('ox-grist') private grist!: DataGrist\n\n get context() { return { title: i18next.t('title.pdf-template list'),\n search: { handler: (search: string) => { this.grist.searchText = search\n },\n value: this.grist.searchText\n },\n filter: { handler: () => { this.grist.toggleHeadroom()\n }\n },\n help: 'pdf/pdf-template',\n actions: [\n { title: i18next.t('button.save'),\n action: this._updatePDFTemplate.bind(this),\n ...CommonButtonStyles.save\n },\n { title: i18next.t('button.delete'),\n action: this._deletePDFTemplate.bind(this),\n ...CommonButtonStyles.delete\n }\n ],\n exportable: { name: i18next.t('title.pdf-template list'),\n data: this.exportHandler.bind(this)\n },\n importable: { handler: this.importHandler.bind(this)\n }\n }\n }\n\n render() { const mode = this.mode || (isMobileDevice() ? 'CARD' : 'GRID')\n\n return html`\n <ox-grist class=\"page-fill\" .mode=${mode} .config=${this.gristConfig} .fetchHandler=${this.fetchHandler.bind(this)}>\n <div slot=\"headroom\" class=\"header\">\n <div class=\"filters\">\n <ox-filters-form autofocus without-search></ox-filters-form>\n\n <div id=\"modes\">\n <md-icon @click=${() => (this.mode = 'GRID')} ?active=${mode == 'GRID'}>grid_on</md-icon>\n <md-icon @click=${() => (this.mode = 'LIST')} ?active=${mode == 'LIST'}>format_list_bulleted</md-icon>\n <md-icon @click=${() => (this.mode = 'CARD')} ?active=${mode == 'CARD'}>apps</md-icon>\n </div>\n\n <ox-record-creator id=\"add\" .callback=${this.creationCallback.bind(this)}>\n <button>\n <md-icon>add</md-icon>\n </button>\n </ox-record-creator>\n </div>\n </div>\n </ox-grist>\n `\n }\n\n async pageInitialized(lifecycle: any) { const kinds: string[] = ((await client.query({ query: gql`query { issuedDocumentKinds { kind } }` })).data?.issuedDocumentKinds ?? []).map((one: any) => one.kind)\n this.gristConfig = { list: { fields: ['name', 'description'],\n details: ['active', 'updatedAt']\n },\n columns: [\n { type: 'gutter', gutterName: 'sequence' },\n { type: 'gutter', gutterName: 'row-selector', multiple: true },\n /* The parts are HTML — written in the editor, with a file and a preview. */\n { type: 'gutter', gutterName: 'button', icon: 'edit_note', handlers: { click: (_c: any, _d: any, _col: any, record: any) => record?.id && navigate(`pdf-template-editor?id=${record.id}`) } },\n { type: 'string',\n name: 'name',\n header: i18next.t('field.name'),\n record: { editable: true\n },\n filter: 'search',\n sortable: true,\n width: 150\n },\n { type: 'string',\n name: 'description',\n header: i18next.t('field.description'),\n record: { editable: true\n },\n filter: 'search',\n width: 200\n },\n { type: 'checkbox',\n name: 'active',\n label: true,\n header: i18next.t('field.active'),\n record: { editable: true\n },\n filter: true,\n sortable: true,\n width: 60\n },\n /* The issued document kind this template prints for the domain, in place of the kind's template in code (ADR-0176). */\n { type: 'select',\n name: 'kind',\n label: true,\n header: i18next.t('field.issued-document-kind'),\n record: { editable: true,\n options: ['', ...kinds],\n renderer: (value: string) => (value ? i18next.t(`issued-document.${value}`, { defaultValue: value }) : '')\n },\n width: 160\n },\n { type: 'string',\n name: 'state',\n label: true,\n header: i18next.t('field.state'),\n record: { editable: true\n },\n width: 120\n },\n { type: 'template',\n name: 'content_template',\n label: true,\n header: i18next.t('field.content_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'header_template',\n label: true,\n header: i18next.t('field.header_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'footer_template',\n label: true,\n header: i18next.t('field.footer_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'cover_template',\n label: true,\n header: i18next.t('field.cover_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'last_template',\n label: true,\n header: i18next.t('field.last_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'select',\n name: 'page_size',\n label: true,\n header: i18next.t('field.page_size'),\n record: { editable: true,\n options: ['', 'A4', 'B4']\n },\n width: 120\n },\n { type: 'string',\n name: 'watermark',\n label: true,\n header: i18next.t('field.watermark'),\n record: { editable: true\n },\n width: 120\n },\n\n { type: 'resource-object',\n name: 'updater',\n header: i18next.t('field.updater'),\n record: { editable: false\n },\n sortable: true,\n width: 120\n },\n { type: 'datetime',\n name: 'updatedAt',\n header: i18next.t('field.updated_at'),\n record: { editable: false\n },\n sortable: true,\n width: 180\n }\n ],\n rows: { appendable: false,\n selectable: { multiple: true\n }\n },\n sorters: [\n { name: 'name'\n }\n ]\n }\n }\n\n async pageUpdated(changes: any, lifecycle: any) { if (this.active) { // do something here when this page just became as active\n }\n }\n\n async fetchHandler({ page = 1, limit = 100, sortings = [], filters = [] }: FetchOption) { const response = await client.query({ query: gql`\n query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) { responses: PDFTemplates(filters: $filters, pagination: $pagination, sortings: $sortings) { items { id\n name\n description\n active\n state\n kind\n content_template\n header_template\n footer_template\n cover_template\n last_template\n page_size\n watermark\n updater { id\n name\n }\n updatedAt\n }\n total\n }\n }\n `,\n variables: { filters,\n pagination: { page, limit },\n sortings\n }\n })\n\n return { total: response.data.responses.total || 0,\n records: response.data.responses.items || []\n }\n }\n\n async _deletePDFTemplate() { if (\n await OxPrompt.open({ title: i18next.t('text.are_you_sure'),\n text: i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }),\n confirmButton: { text: i18next.t('button.confirm') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n ) { const ids = this.grist.selected.map(record => record.id)\n if (ids && ids.length > 0) { const response = await client.mutate({ mutation: gql`\n mutation ($ids: [String!]!) { deletePDFTemplates(ids: $ids)\n }\n `,\n variables: { ids\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n notify({ message: i18next.t('text.info_x_successfully', { x: i18next.t('text.delete') })\n })\n }\n }\n }\n }\n\n async _updatePDFTemplate() { let patches = this.grist.dirtyRecords\n if (patches && patches.length) { patches = patches.map(patch => { let patchField: any = patch.id ? { id: patch.id } : {}\n const dirtyFields = patch.__dirtyfields__\n for (let key in dirtyFields) { patchField[key] = dirtyFields[key].after\n }\n patchField.cuFlag = patch.__dirty__\n\n return patchField\n })\n\n const response = await client.mutate({ mutation: gql`\n mutation ($patches: [PDFTemplatePatch!]!) { updateMultiplePDFTemplate(patches: $patches) { name\n }\n }\n `,\n variables: { patches\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n }\n }\n }\n\n async creationCallback(pdfTemplate) { try { const response = await client.query({ query: gql`\n mutation ($pdfTemplate: NewPDFTemplate!) { createPDFTemplate(pdfTemplate: $pdfTemplate) { id\n }\n }\n `,\n variables: { pdfTemplate\n },\n context: { hasUpload: true\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n document.dispatchEvent(\n new CustomEvent('notify', { detail: { message: i18next.t('text.data_created_successfully')\n }\n })\n )\n }\n\n return true\n } catch (ex) { console.error(ex)\n document.dispatchEvent(\n new CustomEvent('notify', { detail: { type: 'error',\n message: i18next.t('text.error')\n }\n })\n )\n return false\n }\n }\n\n async exportHandler() { const exportTargets = this.grist.selected.length ? this.grist.selected : this.grist.dirtyData.records\n const targetFieldSet = new Set(['id', 'name', 'description', 'active'])\n\n return exportTargets.map(pdfTemplate => { let tempObj = {}\n for (const field of targetFieldSet) { tempObj[field] = pdfTemplate[field]\n }\n\n return tempObj\n })\n }\n\n async importHandler(records) { const popup = openPopup(\n html`\n <pdf-template-importer\n .pdfTemplates=${records}\n @imported=${() => { history.back()\n this.grist.fetch()\n }}\n ></pdf-template-importer>\n `,\n { backdrop: true,\n size: 'large',\n title: i18next.t('title.import pdf-template')\n }\n )\n\n popup.onclosed = () => { this.grist.fetch()\n }\n }\n}\n"]}
1
+ {"version":3,"file":"pdf-template-list-page.js","sourceRoot":"","sources":["../../../client/pages/pdf-template/pdf-template-list-page.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,yCAAyC,CAAA;AAChD,OAAO,iCAAiC,CAAA;AACxC,OAAO,wCAAwC,CAAA;AAC/C,OAAO,0CAA0C,CAAA;AAEjD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACnI,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAgB,SAAS,EAAe,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAW,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,GAAG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K,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;gBAAS,OAAO,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;YACtF,CAAC;YAEI,OAAO,OAAO,CAAA;QACnB,CAAC,CAAC,CAAA;IACF,CAAC;IAEA,KAAK,CAAC,aAAa,CAAC,OAAO;QAAQ,MAAM,KAAK,GAAG,SAAS,CACtD,IAAI,CAAA;;0BAEgB,OAAO;sBACX,GAAG,EAAE;YAAe,OAAO,CAAC,IAAI,EAAE,CAAA;YAC5C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QAC7B,CAAC;;OAEK,EACD,EAAU,QAAQ,EAAE,IAAI;YACtB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,2BAA2B,CAAC;SACnD,CACG,CAAA;QAED,KAAK,CAAC,QAAQ,GAAG,GAAG,EAAE;YAAS,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QACpD,CAAC,CAAA;IACD,CAAC;;AAhW4B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;wDAAiB;AAChB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;iDAAoE;AAEpE;IAA1B,KAAK,CAAC,UAAU,CAAC;8BAAiB,SAAS;kDAAA;AAxBjC,mBAAmB;IAD/B,aAAa,CAAC,wBAAwB,CAAC;GAC3B,mBAAmB,CAsX/B","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@material/web/button/elevated-button.js'\nimport '@operato/data-grist/ox-grist.js'\nimport '@operato/data-grist/ox-filters-form.js'\nimport '@operato/data-grist/ox-record-creator.js'\n\nimport { CommonButtonStyles, CommonHeaderStyles, CommonGristStyles, ScrollbarStyles, WorkSurfacePageStyles } from '@operato/styles'\nimport { navigate, PageView } from '@operato/shell'\nimport { css, html } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\nimport { ScopedElementsMixin } from '@open-wc/scoped-elements'\nimport { ColumnConfig, DataGrist, FetchOption } from '@operato/data-grist'\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { notify, openPopup } from '@operato/layout'\nimport { OxPopup, OxPrompt } from '@operato/popup'\nimport { isMobileDevice } from '@operato/utils'\n\nimport gql from 'graphql-tag'\n\nimport { PDFTemplateImporter } from './pdf-template-importer'\n\n@customElement('pdf-template-list-page')\nexport class PDFTemplateListPage extends localize(i18next)(ScopedElementsMixin(PageView)) { static styles = [\n /* The work surface frame for a list screen (ADR-0060 decision 8). */\n WorkSurfacePageStyles,\n ScrollbarStyles,\n CommonGristStyles,\n CommonHeaderStyles,\n css`\n :host {\n --grid-record-emphasized-background-color: #8b0000;\n --grid-record-emphasized-color: #ff6b6b;\n }\n\n ox-filters-form { flex: 1;\n }\n `\n ]\n\n static get scopedElements() { return { 'pdf-template-importer': PDFTemplateImporter\n }\n }\n\n @property({ type: Object }) gristConfig: any\n @property({ type: String }) mode: 'CARD' | 'GRID' | 'LIST' = isMobileDevice() ? 'CARD' : 'GRID'\n\n @query('ox-grist') private grist!: DataGrist\n\n get context() { return { title: i18next.t('title.pdf-template list'),\n search: { handler: (search: string) => { this.grist.searchText = search\n },\n value: this.grist.searchText\n },\n filter: { handler: () => { this.grist.toggleHeadroom()\n }\n },\n help: 'pdf/pdf-template',\n actions: [\n { title: i18next.t('button.save'),\n action: this._updatePDFTemplate.bind(this),\n ...CommonButtonStyles.save\n },\n { title: i18next.t('button.delete'),\n action: this._deletePDFTemplate.bind(this),\n ...CommonButtonStyles.delete\n }\n ],\n exportable: { name: i18next.t('title.pdf-template list'),\n data: this.exportHandler.bind(this)\n },\n importable: { handler: this.importHandler.bind(this)\n }\n }\n }\n\n render() { const mode = this.mode || (isMobileDevice() ? 'CARD' : 'GRID')\n\n return html`\n <ox-grist class=\"page-fill\" .mode=${mode} .config=${this.gristConfig} .fetchHandler=${this.fetchHandler.bind(this)}>\n <div slot=\"headroom\" class=\"header\">\n <div class=\"filters\">\n <ox-filters-form autofocus without-search></ox-filters-form>\n\n <div id=\"modes\">\n <md-icon @click=${() => (this.mode = 'GRID')} ?active=${mode == 'GRID'}>grid_on</md-icon>\n <md-icon @click=${() => (this.mode = 'LIST')} ?active=${mode == 'LIST'}>format_list_bulleted</md-icon>\n <md-icon @click=${() => (this.mode = 'CARD')} ?active=${mode == 'CARD'}>apps</md-icon>\n </div>\n\n <ox-record-creator id=\"add\" .callback=${this.creationCallback.bind(this)}>\n <button>\n <md-icon>add</md-icon>\n </button>\n </ox-record-creator>\n </div>\n </div>\n </ox-grist>\n `\n }\n\n async pageInitialized(lifecycle: any) { const kinds: string[] = ((await client.query({ query: gql`query { issuedDocumentKinds { kind } }` })).data?.issuedDocumentKinds ?? []).map((one: any) => one.kind)\n this.gristConfig = { list: { fields: ['name', 'description'],\n details: ['active', 'updatedAt']\n },\n columns: [\n { type: 'gutter', gutterName: 'sequence' },\n { type: 'gutter', gutterName: 'row-selector', multiple: true },\n /* The parts are HTML — written in the editor, with a file and a preview. */\n { type: 'gutter', gutterName: 'button', icon: 'edit_note', handlers: { click: (_c: any, _d: any, _col: any, record: any) => record?.id && navigate(`pdf-template-editor?id=${record.id}`) } },\n { type: 'string',\n name: 'name',\n header: i18next.t('field.name'),\n record: { editable: true\n },\n filter: 'search',\n sortable: true,\n width: 150\n },\n { type: 'string',\n name: 'description',\n header: i18next.t('field.description'),\n record: { editable: true\n },\n filter: 'search',\n width: 200\n },\n { type: 'checkbox',\n name: 'active',\n label: true,\n header: i18next.t('field.active'),\n record: { editable: true\n },\n filter: true,\n sortable: true,\n width: 60\n },\n /* The issued document kind this template prints for the domain, in place of the kind's template in code (ADR-0176). */\n { type: 'select',\n name: 'kind',\n label: true,\n header: i18next.t('field.issued-document-kind'),\n record: { editable: true,\n options: ['', ...kinds],\n renderer: (value: string) => (value ? i18next.t(`issued-document.${value}`, { defaultValue: value }) : '')\n },\n width: 160\n },\n { type: 'string',\n name: 'state',\n label: true,\n header: i18next.t('field.state'),\n record: { editable: true\n },\n width: 120\n },\n { type: 'template',\n name: 'content_template',\n label: true,\n header: i18next.t('field.content_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'header_template',\n label: true,\n header: i18next.t('field.header_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'footer_template',\n label: true,\n header: i18next.t('field.footer_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'cover_template',\n label: true,\n header: i18next.t('field.cover_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'template',\n name: 'last_template',\n label: true,\n header: i18next.t('field.last_template'),\n record: { editable: true,\n options: { language: 'html'\n }\n },\n width: 120\n },\n { type: 'select',\n name: 'page_size',\n label: true,\n header: i18next.t('field.page_size'),\n record: { editable: true,\n options: ['', 'A4', 'B4']\n },\n width: 120\n },\n { type: 'string',\n name: 'watermark',\n label: true,\n header: i18next.t('field.watermark'),\n record: { editable: true\n },\n width: 120\n },\n\n { type: 'resource-object',\n name: 'updater',\n header: i18next.t('field.updater'),\n record: { editable: false\n },\n sortable: true,\n width: 120\n },\n { type: 'datetime',\n name: 'updatedAt',\n header: i18next.t('field.updated_at'),\n record: { editable: false\n },\n sortable: true,\n width: 180\n }\n ],\n rows: { appendable: false,\n selectable: { multiple: true\n }\n },\n sorters: [\n { name: 'name'\n }\n ]\n }\n }\n\n async pageUpdated(changes: any, lifecycle: any) { if (this.active) { // do something here when this page just became as active\n }\n }\n\n async fetchHandler({ page = 1, limit = 100, sortings = [], filters = [] }: FetchOption) { const response = await client.query({ query: gql`\n query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) { responses: PDFTemplates(filters: $filters, pagination: $pagination, sortings: $sortings) { items { id\n name\n description\n active\n state\n kind\n content_template\n header_template\n footer_template\n cover_template\n last_template\n page_size\n watermark\n updater { id\n name\n }\n updatedAt\n }\n total\n }\n }\n `,\n variables: { filters,\n pagination: { page, limit },\n sortings\n }\n })\n\n return { total: response.data.responses.total || 0,\n records: response.data.responses.items || []\n }\n }\n\n async _deletePDFTemplate() { if (\n await OxPrompt.open({ title: i18next.t('text.are_you_sure'),\n text: i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }),\n confirmButton: { text: i18next.t('button.confirm') },\n cancelButton: { text: i18next.t('button.cancel') }\n })\n ) { const ids = this.grist.selected.map(record => record.id)\n if (ids && ids.length > 0) { const response = await client.mutate({ mutation: gql`\n mutation ($ids: [String!]!) { deletePDFTemplates(ids: $ids)\n }\n `,\n variables: { ids\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n notify({ message: i18next.t('text.info_x_successfully', { x: i18next.t('text.delete') })\n })\n }\n }\n }\n }\n\n async _updatePDFTemplate() { let patches = this.grist.dirtyRecords\n if (patches && patches.length) { patches = patches.map(patch => { let patchField: any = patch.id ? { id: patch.id } : {}\n const dirtyFields = patch.__dirtyfields__\n for (let key in dirtyFields) { patchField[key] = dirtyFields[key].after\n }\n patchField.cuFlag = patch.__dirty__\n\n return patchField\n })\n\n const response = await client.mutate({ mutation: gql`\n mutation ($patches: [PDFTemplatePatch!]!) { updateMultiplePDFTemplate(patches: $patches) { name\n }\n }\n `,\n variables: { patches\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n }\n }\n }\n\n async creationCallback(pdfTemplate) { try { const response = await client.mutate({ mutation: gql`\n mutation ($pdfTemplate: NewPDFTemplate!) { createPDFTemplate(pdfTemplate: $pdfTemplate) { id\n }\n }\n `,\n variables: { pdfTemplate\n },\n context: { hasUpload: true\n }\n })\n\n if (!response.errors) { this.grist.fetch()\n document.dispatchEvent(\n new CustomEvent('notify', { detail: { message: i18next.t('text.data_created_successfully')\n }\n })\n )\n }\n\n return true\n } catch (ex) { console.error(ex)\n document.dispatchEvent(\n new CustomEvent('notify', { detail: { type: 'error',\n message: i18next.t('text.error')\n }\n })\n )\n return false\n }\n }\n\n async exportHandler() { const exportTargets = this.grist.selected.length ? this.grist.selected : this.grist.dirtyData.records\n const targetFieldSet = new Set(['id', 'name', 'description', 'active'])\n\n return exportTargets.map(pdfTemplate => { let tempObj = {}\n for (const field of targetFieldSet) { tempObj[field] = pdfTemplate[field]\n }\n\n return tempObj\n })\n }\n\n async importHandler(records) { const popup = openPopup(\n html`\n <pdf-template-importer\n .pdfTemplates=${records}\n @imported=${() => { history.back()\n this.grist.fetch()\n }}\n ></pdf-template-importer>\n `,\n { backdrop: true,\n size: 'large',\n title: i18next.t('title.import pdf-template')\n }\n )\n\n popup.onclosed = () => { this.grist.fetch()\n }\n }\n}\n"]}