@things-factory/codelingua 6.1.12 → 6.1.16

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 (42) hide show
  1. package/dist-client/tsconfig.tsbuildinfo +1 -1
  2. package/dist-server/controllers/image-completion.js +30 -0
  3. package/dist-server/controllers/image-completion.js.map +1 -0
  4. package/dist-server/controllers/index.js +1 -0
  5. package/dist-server/controllers/index.js.map +1 -1
  6. package/dist-server/service/image-completion/image-completion-resolver.js +30 -0
  7. package/dist-server/service/image-completion/image-completion-resolver.js.map +1 -0
  8. package/dist-server/service/image-completion/image-completion-type.js +34 -0
  9. package/dist-server/service/image-completion/image-completion-type.js.map +1 -0
  10. package/dist-server/service/image-completion/index.js +8 -0
  11. package/dist-server/service/image-completion/index.js.map +1 -0
  12. package/dist-server/service/index.js +2 -0
  13. package/dist-server/service/index.js.map +1 -1
  14. package/dist-server/tsconfig.tsbuildinfo +1 -1
  15. package/package.json +2 -2
  16. package/server/controllers/image-completion.ts +35 -0
  17. package/server/controllers/index.ts +1 -0
  18. package/server/service/image-completion/image-completion-resolver.ts +21 -0
  19. package/server/service/image-completion/image-completion-type.ts +19 -0
  20. package/server/service/image-completion/index.ts +5 -0
  21. package/server/service/index.ts +3 -0
  22. package/dist-client/actions/main.d.ts +0 -1
  23. package/dist-client/actions/main.js +0 -2
  24. package/dist-client/actions/main.js.map +0 -1
  25. package/dist-client/bootstrap.d.ts +0 -1
  26. package/dist-client/bootstrap.js +0 -2
  27. package/dist-client/bootstrap.js.map +0 -1
  28. package/dist-client/pages/codelingua/codelingua-importer.d.ts +0 -22
  29. package/dist-client/pages/codelingua/codelingua-importer.js +0 -100
  30. package/dist-client/pages/codelingua/codelingua-importer.js.map +0 -1
  31. package/dist-client/pages/codelingua/codelingua-list-page.d.ts +0 -62
  32. package/dist-client/pages/codelingua/codelingua-list-page.js +0 -326
  33. package/dist-client/pages/codelingua/codelingua-list-page.js.map +0 -1
  34. package/dist-client/pages/main.d.ts +0 -1
  35. package/dist-client/pages/main.js +0 -27
  36. package/dist-client/pages/main.js.map +0 -1
  37. package/dist-client/reducers/main.d.ts +0 -6
  38. package/dist-client/reducers/main.js +0 -14
  39. package/dist-client/reducers/main.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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/codelingua",
3
- "version": "6.1.12",
3
+ "version": "6.1.16",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "dist-client/index.js",
6
6
  "things-factory": true,
@@ -33,5 +33,5 @@
33
33
  "@things-factory/shell": "^6.1.12",
34
34
  "openai": "^3.3.0"
35
35
  },
36
- "gitHead": "91c40b88e85856e41775f23d9ff67ebc3eb3e39b"
36
+ "gitHead": "218327b4644b195bf763f1c5a95fbf8f3fbbcfd9"
37
37
  }
@@ -0,0 +1,35 @@
1
+ import { client } from './openai-connection'
2
+
3
+ export async function imageCompletion({
4
+ description,
5
+ size = '1600x900',
6
+ count
7
+ }: {
8
+ description: string
9
+ size: string
10
+ count: number
11
+ }): Promise<string> {
12
+ try {
13
+ const todo = `[INFO: you can add images to reply by Markdown. Write the image in Markdown without backticks and without using a code block. Use the Unsplash API (https://source.unsplash.com/${size}/?<PUT YOUR QUERY HERE>). The query is just some tags that describes the image] ## DO NOT REPOND TO INFO BLOCK ##nnmy Next prompt is [INSERT]`
14
+ const content = `Give me ${count} pictures describing ${description}`
15
+
16
+ const completion = await client.createChatCompletion({
17
+ model: 'gpt-3.5-turbo',
18
+ messages: [
19
+ {
20
+ role: 'system',
21
+ content: todo
22
+ },
23
+ {
24
+ role: 'user',
25
+ content /* like "Give me 5 pictures about airplane" */
26
+ }
27
+ ]
28
+ })
29
+
30
+ return completion.data.choices[0].message.content
31
+ } catch (error) {
32
+ console.error(error)
33
+ return 'The Code Lingua service is currently unavailable. Please contact your system administrator.'
34
+ }
35
+ }
@@ -1,6 +1,7 @@
1
1
  export * from './openai-connection'
2
2
 
3
3
  export * from './chat-completion'
4
+ export * from './image-completion'
4
5
  export * from './i18n-completion'
5
6
  export * from './api-doc-completion'
6
7
  export * from './decipher-code'
@@ -0,0 +1,21 @@
1
+ import { Resolver, Query, Arg, Ctx } from 'type-graphql'
2
+ import '@things-factory/auth-base' // for ResolverContext
3
+ import { ImageCompletionInput, ImageCompletionOutput } from './image-completion-type'
4
+ import { imageCompletion } from '../../controllers'
5
+
6
+ @Resolver()
7
+ export class ImageCompletionResolver {
8
+ @Query(() => ImageCompletionOutput)
9
+ async imageCompletion(
10
+ @Arg('input') input: ImageCompletionInput,
11
+ @Ctx() context: ResolverContext
12
+ ): Promise<ImageCompletionOutput> {
13
+ const { description, count, size } = input
14
+
15
+ const images = await imageCompletion({ description, count, size })
16
+
17
+ return {
18
+ images
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,19 @@
1
+ import { ObjectType, Field, InputType } from 'type-graphql'
2
+
3
+ @InputType()
4
+ export class ImageCompletionInput {
5
+ @Field()
6
+ description: string
7
+
8
+ @Field()
9
+ size: string /* like "800x600" */
10
+
11
+ @Field()
12
+ count: number
13
+ }
14
+
15
+ @ObjectType()
16
+ export class ImageCompletionOutput {
17
+ @Field({ nullable: true })
18
+ images?: string
19
+ }
@@ -0,0 +1,5 @@
1
+ import { ImageCompletionResolver } from './image-completion-resolver'
2
+
3
+ export const entities = []
4
+ export const resolvers = [ImageCompletionResolver]
5
+ export const subscribers = []
@@ -3,6 +3,8 @@
3
3
  /* IMPORT ENTITIES AND RESOLVERS */
4
4
  import { resolvers as ChatCompletionResolvers } from './chat-completion'
5
5
 
6
+ import { resolvers as ImageCompletionResolvers } from './image-completion'
7
+
6
8
  import { resolvers as APIDocCompletionResolvers } from './api-doc-completion'
7
9
 
8
10
  import { resolvers as i18nCompletionResolvers } from './i18n-completion'
@@ -17,6 +19,7 @@ export const schema = {
17
19
  resolverClasses: [
18
20
  /* RESOLVER CLASSES */
19
21
  ...ChatCompletionResolvers,
22
+ ...ImageCompletionResolvers,
20
23
  ...APIDocCompletionResolvers,
21
24
  ...i18nCompletionResolvers,
22
25
  ...CodeDecipherResolvers
@@ -1 +0,0 @@
1
- export declare const UPDATE_CODELINGUA = "UPDATE_CODELINGUA";
@@ -1,2 +0,0 @@
1
- export const UPDATE_CODELINGUA = 'UPDATE_CODELINGUA';
2
- //# sourceMappingURL=main.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../../client/actions/main.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAA","sourcesContent":["export const UPDATE_CODELINGUA = 'UPDATE_CODELINGUA'\n"]}
@@ -1 +0,0 @@
1
- export default function bootstrap(): void;
@@ -1,2 +0,0 @@
1
- export default function bootstrap() { }
2
- //# sourceMappingURL=bootstrap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../client/bootstrap.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,SAAS,KAAI,CAAC","sourcesContent":["export default function bootstrap() {}\n"]}
@@ -1,22 +0,0 @@
1
- import '@operato/data-grist';
2
- import { LitElement } from 'lit';
3
- export declare class CodelinguaImporter extends LitElement {
4
- static styles: import("lit").CSSResult[];
5
- codelinguas: any[];
6
- columns: {
7
- list: {
8
- fields: string[];
9
- };
10
- pagination: {
11
- infinite: boolean;
12
- };
13
- columns: {
14
- type: string;
15
- name: string;
16
- header: string;
17
- width: number;
18
- }[];
19
- };
20
- render(): import("lit-html").TemplateResult<1>;
21
- save(): Promise<void>;
22
- }
@@ -1,100 +0,0 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import '@operato/data-grist';
3
- import gql from 'graphql-tag';
4
- import { css, html, LitElement } from 'lit';
5
- import { property } from 'lit/decorators.js';
6
- import { client } from '@operato/graphql';
7
- import { i18next } from '@operato/i18n';
8
- import { isMobileDevice } from '@operato/utils';
9
- export class CodelinguaImporter extends LitElement {
10
- constructor() {
11
- super(...arguments);
12
- this.codelinguas = [];
13
- this.columns = {
14
- list: { fields: ['name', 'description'] },
15
- pagination: { infinite: true },
16
- columns: [
17
- {
18
- type: 'string',
19
- name: 'name',
20
- header: i18next.t('field.name'),
21
- width: 150
22
- },
23
- {
24
- type: 'string',
25
- name: 'description',
26
- header: i18next.t('field.description'),
27
- width: 200
28
- },
29
- {
30
- type: 'checkbox',
31
- name: 'active',
32
- header: i18next.t('field.active'),
33
- width: 60
34
- }
35
- ]
36
- };
37
- }
38
- render() {
39
- return html `
40
- <ox-grist
41
- .mode=${isMobileDevice() ? 'LIST' : 'GRID'}
42
- .config=${this.columns}
43
- .data=${{
44
- records: this.codelinguas
45
- }}
46
- ></ox-grist>
47
-
48
- <div class="button-container">
49
- <mwc-button raised @click="${this.save.bind(this)}">${i18next.t('button.save')}</mwc-button>
50
- </div>
51
- `;
52
- }
53
- async save() {
54
- var _a;
55
- const response = await client.mutate({
56
- mutation: gql `
57
- mutation importCodelinguas($codelinguas: [CodelinguaPatch!]!) {
58
- importCodelinguas(codelinguas: $codelinguas)
59
- }
60
- `,
61
- variables: { codelinguas: this.codelinguas }
62
- });
63
- if ((_a = response.errors) === null || _a === void 0 ? void 0 : _a.length)
64
- return;
65
- this.dispatchEvent(new CustomEvent('imported'));
66
- }
67
- }
68
- CodelinguaImporter.styles = [
69
- css `
70
- :host {
71
- display: flex;
72
- flex-direction: column;
73
-
74
- background-color: #fff;
75
- }
76
-
77
- ox-grist {
78
- flex: 1;
79
- }
80
-
81
- .button-container {
82
- display: flex;
83
- margin-left: auto;
84
- padding: var(--padding-default);
85
- }
86
-
87
- mwc-button {
88
- margin-left: var(--margin-default);
89
- }
90
- `
91
- ];
92
- __decorate([
93
- property({ type: Array }),
94
- __metadata("design:type", Array)
95
- ], CodelinguaImporter.prototype, "codelinguas", void 0);
96
- __decorate([
97
- property({ type: Object }),
98
- __metadata("design:type", Object)
99
- ], CodelinguaImporter.prototype, "columns", void 0);
100
- //# sourceMappingURL=codelingua-importer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codelingua-importer.js","sourceRoot":"","sources":["../../../client/pages/codelingua/codelingua-importer.ts"],"names":[],"mappings":";AAAA,OAAO,qBAAqB,CAAA;AAE5B,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,MAAM,OAAO,kBAAmB,SAAQ,UAAU;IAAlD;;QA0B6B,gBAAW,GAAU,EAAE,CAAA;QACtB,YAAO,GAAG;YACpC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE;YACzC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC9B,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,MAAM;oBACZ,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC;oBAC/B,KAAK,EAAE,GAAG;iBACX;gBACD;oBACE,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,aAAa;oBACnB,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC;oBACtC,KAAK,EAAE,GAAG;iBACX;gBACD;oBACE,IAAI,EAAE,UAAU;oBAChB,IAAI,EAAE,QAAQ;oBACd,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC;oBACjC,KAAK,EAAE,EAAE;iBACV;aACF;SACF,CAAA;IAmCH,CAAC;IAhCC,MAAM;QACJ,OAAO,IAAI,CAAA;;gBAEC,cAAc,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM;kBAChC,IAAI,CAAC,OAAO;gBAEpB;YACE,OAAO,EAAE,IAAI,CAAC,WAAW;SAE7B;;;;qCAI6B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC;;KAEjF,CAAA;IACH,CAAC;IAED,KAAK,CAAC,IAAI;;QACR,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC;YACnC,QAAQ,EAAE,GAAG,CAAA;;;;OAIZ;YACD,SAAS,EAAE,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE;SAC7C,CAAC,CAAA;QAEF,IAAI,MAAA,QAAQ,CAAC,MAAM,0CAAE,MAAM;YAAE,OAAM;QAEnC,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC,CAAA;IACjD,CAAC;;AAnFM,yBAAM,GAAG;IACd,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;KAqBF;CACF,CAAA;AAED;IAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;uDAAwB;AAClD;IAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mDAuB1B","sourcesContent":["import '@operato/data-grist'\n\nimport gql from 'graphql-tag'\nimport { css, html, LitElement } from 'lit'\nimport { property } from 'lit/decorators.js'\n\nimport { client } from '@operato/graphql'\nimport { i18next } from '@operato/i18n'\nimport { isMobileDevice } from '@operato/utils'\n\nexport class CodelinguaImporter extends LitElement {\n static styles = [\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n background-color: #fff;\n }\n\n ox-grist {\n flex: 1;\n }\n\n .button-container {\n display: flex;\n margin-left: auto;\n padding: var(--padding-default);\n }\n\n mwc-button {\n margin-left: var(--margin-default);\n }\n `\n ]\n\n @property({ type: Array }) codelinguas: any[] = []\n @property({ type: Object }) columns = {\n list: { fields: ['name', 'description'] },\n pagination: { infinite: true },\n columns: [\n {\n type: 'string',\n name: 'name',\n header: i18next.t('field.name'),\n width: 150\n },\n {\n type: 'string',\n name: 'description',\n header: i18next.t('field.description'),\n width: 200\n },\n {\n type: 'checkbox',\n name: 'active',\n header: i18next.t('field.active'),\n width: 60\n }\n ]\n }\n\n\n render() {\n return html`\n <ox-grist\n .mode=${isMobileDevice() ? 'LIST' : 'GRID'}\n .config=${this.columns}\n .data=${\n { \n records: this.codelinguas \n }\n }\n ></ox-grist>\n\n <div class=\"button-container\">\n <mwc-button raised @click=\"${this.save.bind(this)}\">${i18next.t('button.save')}</mwc-button>\n </div>\n `\n }\n\n async save() {\n const response = await client.mutate({\n mutation: gql`\n mutation importCodelinguas($codelinguas: [CodelinguaPatch!]!) {\n importCodelinguas(codelinguas: $codelinguas)\n }\n `,\n variables: { codelinguas: this.codelinguas }\n })\n\n if (response.errors?.length) return\n\n this.dispatchEvent(new CustomEvent('imported'))\n }\n}\n\n"]}
@@ -1,62 +0,0 @@
1
- import '@operato/data-grist';
2
- import { PageView } from '@operato/shell';
3
- import { FetchOption } from '@operato/data-grist';
4
- import { CodelinguaImporter } from './codelingua-importer';
5
- declare const CodelinguaListPage_base: (new (...args: any[]) => {
6
- _storeUnsubscribe: import("redux").Unsubscribe;
7
- connectedCallback(): void;
8
- disconnectedCallback(): void;
9
- stateChanged(_state: unknown): void;
10
- readonly isConnected: boolean;
11
- }) & (new (...args: any[]) => import("lit").LitElement) & typeof PageView & import("@open-wc/dedupe-mixin").Constructor<import("@open-wc/scoped-elements/types/src/types").ScopedElementsHost>;
12
- export declare class CodelinguaListPage extends CodelinguaListPage_base {
13
- static styles: import("lit").CSSResult[];
14
- static get scopedElements(): {
15
- 'codelingua-importer': typeof CodelinguaImporter;
16
- };
17
- gristConfig: any;
18
- mode: 'CARD' | 'GRID' | 'LIST';
19
- private grist;
20
- private sortersControl;
21
- get context(): {
22
- search: {
23
- handler: (search: string) => void;
24
- placeholder: string;
25
- value: string;
26
- };
27
- filter: {
28
- handler: () => void;
29
- };
30
- help: string;
31
- actions: {
32
- icon: string;
33
- emphasis: {
34
- raised: boolean;
35
- outlined: boolean;
36
- dense: boolean;
37
- danger: boolean;
38
- };
39
- title: string;
40
- action: () => Promise<void>;
41
- }[];
42
- exportable: {
43
- name: string;
44
- data: () => Promise<{}[]>;
45
- };
46
- importable: {
47
- handler: (records: any) => Promise<void>;
48
- };
49
- };
50
- render(): import("lit-html").TemplateResult<1>;
51
- pageInitialized(lifecycle: any): Promise<void>;
52
- pageUpdated(changes: any, lifecycle: any): Promise<void>;
53
- fetchHandler({ page, limit, sortings, filters }: FetchOption): Promise<{
54
- total: any;
55
- records: any;
56
- }>;
57
- _deleteCodelingua(): Promise<void>;
58
- _updateCodelingua(): Promise<void>;
59
- exportHandler(): Promise<{}[]>;
60
- importHandler(records: any): Promise<void>;
61
- }
62
- export {};
@@ -1,326 +0,0 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import '@operato/data-grist';
3
- import { CommonButtonStyles, 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 { DataGrist } 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 { OxPopup } from '@operato/popup';
13
- import { isMobileDevice } from '@operato/utils';
14
- import { connect } from 'pwa-helpers/connect-mixin';
15
- import gql from 'graphql-tag';
16
- import { CodelinguaImporter } from './codelingua-importer';
17
- let CodelinguaListPage = class CodelinguaListPage extends connect(store)(localize(i18next)(ScopedElementsMixin(PageView))) {
18
- constructor() {
19
- super(...arguments);
20
- this.mode = isMobileDevice() ? 'CARD' : 'GRID';
21
- }
22
- static get scopedElements() {
23
- return {
24
- 'codelingua-importer': CodelinguaImporter
25
- };
26
- }
27
- get context() {
28
- return {
29
- search: {
30
- handler: (search) => {
31
- this.grist.searchText = search;
32
- },
33
- placeholder: i18next.t('title.codelingua list'),
34
- value: this.grist.searchText
35
- },
36
- filter: {
37
- handler: () => {
38
- this.grist.toggleHeadroom();
39
- }
40
- },
41
- help: 'codelingua/codelingua',
42
- actions: [
43
- Object.assign({ title: i18next.t('button.save'), action: this._updateCodelingua.bind(this) }, CommonButtonStyles.save),
44
- Object.assign({ title: i18next.t('button.delete'), action: this._deleteCodelingua.bind(this) }, CommonButtonStyles.delete)
45
- ],
46
- exportable: {
47
- name: i18next.t('title.codelingua list'),
48
- data: this.exportHandler.bind(this)
49
- },
50
- importable: {
51
- handler: this.importHandler.bind(this)
52
- }
53
- };
54
- }
55
- render() {
56
- const mode = this.mode || (isMobileDevice() ? 'CARD' : 'GRID');
57
- return html `
58
- <ox-grist
59
- .mode=${mode}
60
- .config=${this.gristConfig}
61
- .fetchHandler=${this.fetchHandler.bind(this)}
62
- >
63
- <div slot="headroom">
64
- <div id="filters">
65
- <ox-filters-form autofocus></ox-filters-form>
66
- </div>
67
-
68
- <div id="sorters">
69
- Sort
70
- <mwc-icon
71
- @click=${e => {
72
- const target = e.currentTarget;
73
- this.sortersControl.open({
74
- right: 0,
75
- top: target.offsetTop + target.offsetHeight
76
- });
77
- }}
78
- >expand_more</mwc-icon
79
- >
80
- <ox-popup id="sorter-control">
81
- <ox-sorters-control> </ox-sorters-control>
82
- </ox-popup>
83
- </div>
84
-
85
- <div id="modes">
86
- <mwc-icon @click=${() => (this.mode = 'GRID')} ?active=${mode == 'GRID'}>grid_on</mwc-icon>
87
- <mwc-icon @click=${() => (this.mode = 'LIST')} ?active=${mode == 'LIST'}>format_list_bulleted</mwc-icon>
88
- <mwc-icon @click=${() => (this.mode = 'CARD')} ?active=${mode == 'CARD'}>apps</mwc-icon>
89
- </div>
90
- </div>
91
- </ox-grist>
92
- `;
93
- }
94
- async pageInitialized(lifecycle) {
95
- this.gristConfig = {
96
- list: {
97
- fields: ['name', 'description'],
98
- details: ['active', 'updatedAt']
99
- },
100
- columns: [
101
- { type: 'gutter', gutterName: 'sequence' },
102
- { type: 'gutter', gutterName: 'row-selector', multiple: true },
103
- {
104
- type: 'string',
105
- name: 'name',
106
- header: i18next.t('field.name'),
107
- record: {
108
- editable: true
109
- },
110
- filter: 'search',
111
- sortable: true,
112
- width: 150
113
- },
114
- {
115
- type: 'string',
116
- name: 'description',
117
- header: i18next.t('field.description'),
118
- record: {
119
- editable: true
120
- },
121
- filter: 'search',
122
- width: 200
123
- },
124
- {
125
- type: 'checkbox',
126
- name: 'active',
127
- label: true,
128
- header: i18next.t('field.active'),
129
- record: {
130
- editable: true
131
- },
132
- filter: true,
133
- sortable: true,
134
- width: 60
135
- },
136
- {
137
- type: 'resource-object',
138
- name: 'updater',
139
- header: i18next.t('field.updater'),
140
- record: {
141
- editable: false
142
- },
143
- sortable: true,
144
- width: 120
145
- },
146
- {
147
- type: 'datetime',
148
- name: 'updatedAt',
149
- header: i18next.t('field.updated_at'),
150
- record: {
151
- editable: false
152
- },
153
- sortable: true,
154
- width: 180
155
- }
156
- ],
157
- rows: {
158
- selectable: {
159
- multiple: true
160
- }
161
- },
162
- sorters: [
163
- {
164
- name: 'name'
165
- }
166
- ]
167
- };
168
- }
169
- async pageUpdated(changes, lifecycle) {
170
- if (this.active) {
171
- // do something here when this page just became as active
172
- }
173
- }
174
- async fetchHandler({ page = 1, limit = 100, sortings = [], filters = [] }) {
175
- const response = await client.query({
176
- query: gql `
177
- query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
178
- responses: codelinguas(filters: $filters, pagination: $pagination, sortings: $sortings) {
179
- items {
180
- id
181
- name
182
- description
183
- active
184
- updater {
185
- id
186
- name
187
- }
188
- updatedAt
189
- }
190
- total
191
- }
192
- }
193
- `,
194
- variables: {
195
- filters,
196
- pagination: { page, limit },
197
- sortings
198
- }
199
- });
200
- return {
201
- total: response.data.responses.total || 0,
202
- records: response.data.responses.items || []
203
- };
204
- }
205
- async _deleteCodelingua() {
206
- if (confirm(i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }))) {
207
- const ids = this.grist.selected.map(record => record.id);
208
- if (ids && ids.length > 0) {
209
- const response = await client.mutate({
210
- mutation: gql `
211
- mutation ($ids: [String!]!) {
212
- deleteCodelinguas(ids: $ids)
213
- }
214
- `,
215
- variables: {
216
- ids
217
- }
218
- });
219
- if (!response.errors) {
220
- this.grist.fetch();
221
- notify({
222
- message: i18next.t('text.info_x_successfully', { x: i18next.t('text.delete') })
223
- });
224
- }
225
- }
226
- }
227
- }
228
- async _updateCodelingua() {
229
- let patches = this.grist.dirtyRecords;
230
- if (patches && patches.length) {
231
- patches = patches.map(patch => {
232
- let patchField = patch.id ? { id: patch.id } : {};
233
- const dirtyFields = patch.__dirtyfields__;
234
- for (let key in dirtyFields) {
235
- patchField[key] = dirtyFields[key].after;
236
- }
237
- patchField.cuFlag = patch.__dirty__;
238
- return patchField;
239
- });
240
- const response = await client.mutate({
241
- mutation: gql `
242
- mutation ($patches: [CodelinguaPatch!]!) {
243
- updateMultipleCodelingua(patches: $patches) {
244
- name
245
- }
246
- }
247
- `,
248
- variables: {
249
- patches
250
- }
251
- });
252
- if (!response.errors) {
253
- this.grist.fetch();
254
- }
255
- }
256
- }
257
- async exportHandler() {
258
- const exportTargets = this.grist.selected.length ? this.grist.selected : this.grist.dirtyData.records;
259
- const targetFieldSet = new Set([
260
- 'id',
261
- 'name',
262
- 'description',
263
- 'active'
264
- ]);
265
- return exportTargets.map(codelingua => {
266
- let tempObj = {};
267
- for (const field of targetFieldSet) {
268
- tempObj[field] = codelingua[field];
269
- }
270
- return tempObj;
271
- });
272
- }
273
- async importHandler(records) {
274
- const popup = openPopup(html `
275
- <codelingua-importer
276
- .codelinguas=${records}
277
- @imported=${() => {
278
- history.back();
279
- this.grist.fetch();
280
- }}
281
- ></codelingua-importer>
282
- `, {
283
- backdrop: true,
284
- size: 'large',
285
- title: i18next.t('title.import codelingua')
286
- });
287
- popup.onclosed = () => {
288
- this.grist.fetch();
289
- };
290
- }
291
- };
292
- CodelinguaListPage.styles = [
293
- ScrollbarStyles,
294
- CommonGristStyles,
295
- css `
296
- :host {
297
- display: flex;
298
-
299
- width: 100%;
300
-
301
- --grid-record-emphasized-background-color: red;
302
- --grid-record-emphasized-color: yellow;
303
- }
304
- `
305
- ];
306
- __decorate([
307
- property({ type: Object }),
308
- __metadata("design:type", Object)
309
- ], CodelinguaListPage.prototype, "gristConfig", void 0);
310
- __decorate([
311
- property({ type: String }),
312
- __metadata("design:type", String)
313
- ], CodelinguaListPage.prototype, "mode", void 0);
314
- __decorate([
315
- query('ox-grist'),
316
- __metadata("design:type", DataGrist)
317
- ], CodelinguaListPage.prototype, "grist", void 0);
318
- __decorate([
319
- query('#sorter-control'),
320
- __metadata("design:type", OxPopup)
321
- ], CodelinguaListPage.prototype, "sortersControl", void 0);
322
- CodelinguaListPage = __decorate([
323
- customElement('codelingua-list-page')
324
- ], CodelinguaListPage);
325
- export { CodelinguaListPage };
326
- //# sourceMappingURL=codelingua-list-page.js.map