@things-factory/operato-board 6.1.155 → 6.1.156

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.
@@ -12,10 +12,19 @@ export declare class AttachmentListPage extends AttachmentListPage_base {
12
12
  value: string;
13
13
  };
14
14
  board_topmenu: boolean;
15
+ exportable: {
16
+ name: string;
17
+ data: () => Promise<any>;
18
+ };
19
+ importable: {
20
+ handler: (data: any, file: any) => Promise<void>;
21
+ };
15
22
  };
16
23
  render(): import("lit-html").TemplateResult<1>;
17
24
  get grist(): import("@operato/data-grist").DataGrist;
18
25
  languageUpdated(i18next: any): void;
19
26
  pageInitialized(): Promise<void>;
27
+ exportHandler(): Promise<any>;
28
+ importHandler(data: any, file: any): Promise<void>;
20
29
  }
21
30
  export {};
@@ -2,9 +2,37 @@ import { __decorate, __metadata } from "tslib";
2
2
  import '@operato/attachment/ox-attachment-list.js';
3
3
  import { css, html } from 'lit';
4
4
  import { customElement, query } from 'lit/decorators.js';
5
+ import gql from 'graphql-tag';
5
6
  import { i18next, localize } from '@operato/i18n';
6
7
  import { PageView } from '@operato/shell';
7
8
  import { OxAttachmentList } from '@operato/attachment/ox-attachment-list.js';
9
+ import { client } from '@operato/graphql';
10
+ async function fetchDataFromURL(fileURL) {
11
+ try {
12
+ const response = await fetch(fileURL);
13
+ if (!response.ok) {
14
+ throw new Error('Network response was not ok');
15
+ }
16
+ const blob = await response.blob(); // 파일 데이터를 Blob으로 변환
17
+ if (blob.size === 0) {
18
+ throw new Error('Content is empty'); // Content가 비어 있으면 예외
19
+ }
20
+ return new Promise((resolve, reject) => {
21
+ const reader = new FileReader();
22
+ reader.onload = (event) => {
23
+ const dataURL = event.target.result;
24
+ resolve(dataURL);
25
+ };
26
+ reader.onerror = (event) => {
27
+ reject(event.error);
28
+ };
29
+ reader.readAsDataURL(blob); // Blob을 Data URL로 읽기
30
+ });
31
+ }
32
+ catch (error) {
33
+ throw error;
34
+ }
35
+ }
8
36
  let AttachmentListPage = class AttachmentListPage extends localize(i18next)(PageView) {
9
37
  get context() {
10
38
  var _a;
@@ -16,7 +44,14 @@ let AttachmentListPage = class AttachmentListPage extends localize(i18next)(Page
16
44
  },
17
45
  value: ((_a = this.grist) === null || _a === void 0 ? void 0 : _a.searchText) || ''
18
46
  },
19
- board_topmenu: true
47
+ board_topmenu: true,
48
+ exportable: {
49
+ name: i18next.t('title.attachment list'),
50
+ data: this.exportHandler.bind(this)
51
+ },
52
+ importable: {
53
+ handler: this.importHandler.bind(this)
54
+ }
20
55
  };
21
56
  }
22
57
  render() {
@@ -32,6 +67,48 @@ let AttachmentListPage = class AttachmentListPage extends localize(i18next)(Page
32
67
  await this.updateComplete;
33
68
  this.attachmentList.refreshAttachments();
34
69
  }
70
+ async exportHandler() {
71
+ const records = this.grist.data.records;
72
+ const data = {};
73
+ for (const record of records) {
74
+ const { id, name, mimetype, encoding, category, fullpath } = record;
75
+ try {
76
+ const dataURL = await fetchDataFromURL(fullpath);
77
+ id &&
78
+ (data[id] = {
79
+ id,
80
+ name,
81
+ mimetype,
82
+ encoding,
83
+ category,
84
+ contents: dataURL
85
+ });
86
+ }
87
+ catch (err) {
88
+ console.log(name, err);
89
+ }
90
+ }
91
+ return data;
92
+ }
93
+ async importHandler(data, file) {
94
+ await client.mutate({
95
+ mutation: gql `
96
+ mutation importAttachments($file: Upload!) {
97
+ importAttachments(file: $file) {
98
+ id
99
+ name
100
+ description
101
+ path
102
+ }
103
+ }
104
+ `,
105
+ variables: {
106
+ file
107
+ },
108
+ context: { hasUpload: true }
109
+ });
110
+ this.grist.fetch();
111
+ }
35
112
  };
36
113
  AttachmentListPage.styles = [
37
114
  css `
@@ -1 +1 @@
1
- {"version":3,"file":"attachment-list-page.js","sourceRoot":"","sources":["../../client/pages/attachment-list-page.ts"],"names":[],"mappings":";AAAA,OAAO,2CAA2C,CAAA;AAElD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,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ment/ox-attachment-list.js'\n\nimport { css, html } from 'lit'\nimport { customElement, query } from 'lit/decorators.js'\n\nimport { i18next, localize } from '@operato/i18n'\nimport { PageView } from '@operato/shell'\nimport { OxAttachmentList } from '@operato/attachment/ox-attachment-list.js'\n\n@customElement('attachment-list-page')\nexport class AttachmentListPage extends localize(i18next)(PageView) {\n static styles = [\n css`\n :host {\n display: flex;\n }\n `\n ]\n\n @query('ox-attachment-list') attachmentList!: OxAttachmentList\n\n get context() {\n return {\n title: i18next.t('title.attachment list'),\n search: {\n handler: search => {\n this.grist.searchText = search\n },\n value: this.grist?.searchText || ''\n },\n board_topmenu: true\n }\n }\n\n render() {\n return html` <ox-attachment-list .creatable=${true} without-search></ox-attachment-list> `\n }\n\n get grist() {\n return this.attachmentList.grist\n }\n\n languageUpdated(i18next) {\n this.attachmentList.requestUpdate()\n }\n\n async pageInitialized() {\n await this.updateComplete\n\n this.attachmentList.refreshAttachments()\n }\n}\n"]}
1
+ {"version":3,"file":"attachment-list-page.js","sourceRoot":"","sources":["../../client/pages/attachment-list-page.ts"],"names":[],"mappings":";AAAA,OAAO,2CAA2C,CAAA;AAElD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,KAAK,UAAU,gBAAgB,CAAC,OAAe;IAC7C,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,CAAA;QAErC,IAAI,CAAC,QAAQ,CAAC,EAAE,E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A;aACvB;SACF;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI;QAC5B,MAAM,MAAM,CAAC,MAAM,CAAC;YAClB,QAAQ,EAAE,GAAG,CAAA;;;;;;;;;OASZ;YACD,SAAS,EAAE;gBACT,IAAI;aACL;YACD,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;SAC7B,CAAC,CAAA;QAEF,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;;AA9FM,yBAAM,GAAG;IACd,GAAG,CAAA;;;;KAIF;CACF,CAAA;AAED;IAAC,KAAK,CAAC,oBAAoB,CAAC;8BAAkB,gBAAgB;0DAAA;AATnD,kBAAkB;IAD9B,aAAa,CAAC,sBAAsB,CAAC;GACzB,kBAAkB,CAgG9B;SAhGY,kBAAkB","sourcesContent":["import '@operato/attachment/ox-attachment-list.js'\n\nimport { css, html } from 'lit'\nimport { customElement, query } from 'lit/decorators.js'\nimport gql from 'graphql-tag'\n\nimport { i18next, localize } from '@operato/i18n'\nimport { PageView } from '@operato/shell'\nimport { OxAttachmentList } from '@operato/attachment/ox-attachment-list.js'\nimport { client } from '@operato/graphql'\n\nasync function fetchDataFromURL(fileURL: string) {\n try {\n const response = await fetch(fileURL)\n\n if (!response.ok) {\n throw new Error('Network response was not ok')\n }\n\n const blob = await response.blob() // 파일 데이터를 Blob으로 변환\n\n if (blob.size === 0) {\n throw new Error('Content is empty') // Content가 비어 있으면 예외\n }\n\n return new Promise((resolve, reject) => {\n const reader = new FileReader()\n\n reader.onload = (event: any) => {\n const dataURL = event.target.result\n resolve(dataURL)\n }\n\n reader.onerror = (event: any) => {\n reject(event.error)\n }\n\n reader.readAsDataURL(blob) // Blob을 Data URL로 읽기\n })\n } catch (error) {\n throw error\n }\n}\n\n@customElement('attachment-list-page')\nexport class AttachmentListPage extends localize(i18next)(PageView) {\n static styles = [\n css`\n :host {\n display: flex;\n }\n `\n ]\n\n @query('ox-attachment-list') attachmentList!: OxAttachmentList\n\n get context() {\n return {\n title: i18next.t('title.attachment list'),\n search: {\n handler: search => {\n this.grist.searchText = search\n },\n value: this.grist?.searchText || ''\n },\n board_topmenu: true,\n exportable: {\n name: i18next.t('title.attachment list'),\n data: this.exportHandler.bind(this)\n },\n importable: {\n handler: this.importHandler.bind(this)\n }\n }\n }\n\n render() {\n return html` <ox-attachment-list .creatable=${true} without-search></ox-attachment-list> `\n }\n\n get grist() {\n return this.attachmentList.grist\n }\n\n languageUpdated(i18next) {\n this.attachmentList.requestUpdate()\n }\n\n async pageInitialized() {\n await this.updateComplete\n\n this.attachmentList.refreshAttachments()\n }\n\n async exportHandler() {\n const records = this.grist.data.records\n const data = {} as any\n\n for (const record of records) {\n const { id, name, mimetype, encoding, category, fullpath } = record\n\n try {\n const dataURL = await fetchDataFromURL(fullpath)\n\n id &&\n (data[id!] = {\n id,\n name,\n mimetype,\n encoding,\n category,\n contents: dataURL\n })\n } catch (err) {\n console.log(name, err)\n }\n }\n\n return data\n }\n\n async importHandler(data, file) {\n await client.mutate({\n mutation: gql`\n mutation importAttachments($file: Upload!) {\n importAttachments(file: $file) {\n id\n name\n description\n path\n }\n }\n `,\n variables: {\n file\n },\n context: { hasUpload: true }\n })\n\n this.grist.fetch()\n }\n}\n"]}