@rws-framework/client 2.17.2 → 2.18.1

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 (24) hide show
  1. package/package.json +1 -1
  2. package/src/components/rws/reformer/component.ts +36 -7
  3. package/src/components/rws/reformer/fields/boolean/component.ts +20 -0
  4. package/src/components/rws/reformer/fields/boolean/styles/layout.scss +5 -0
  5. package/src/components/rws/reformer/fields/boolean/template.html +6 -0
  6. package/src/components/rws/reformer/fields/date/component.ts +20 -0
  7. package/src/components/rws/reformer/fields/date/styles/layout.scss +5 -0
  8. package/src/components/rws/reformer/fields/date/template.html +7 -0
  9. package/src/components/rws/reformer/fields/number/component.ts +20 -0
  10. package/src/components/rws/reformer/fields/number/styles/layout.scss +5 -0
  11. package/src/components/rws/reformer/fields/number/template.html +7 -0
  12. package/src/components/rws/reformer/fields/text/component.ts +13 -2
  13. package/src/components/rws/reformer/fields/text/template.html +3 -3
  14. package/src/components/rws/reformer/styles/layout.scss +11 -0
  15. package/src/components/rws/reformer/template.html +17 -5
  16. package/src/components/rws/reformer/types/IReFormerTypes.ts +5 -0
  17. package/src/components/rws/rws-api-resource/component.ts +18 -20
  18. package/src/components/rws/rws-api-resource/styles/layout.scss +3 -1
  19. package/src/components/rws/rws-api-resource/template.html +26 -10
  20. package/src/components/rws/rws-api-resource/variants/form/component.ts +26 -0
  21. package/src/components/rws/rws-api-resource/variants/form/template.html +1 -1
  22. package/src/components/rws/rws-api-resource/variants/list/component.ts +34 -1
  23. package/src/components/rws/rws-api-resource/variants/list/template.html +11 -3
  24. package/src/components/rws/reformer/fields/_field.ts +0 -14
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/client",
3
3
  "private": false,
4
- "version": "2.17.2",
4
+ "version": "2.18.1",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "docs": "typedoc --tsconfig ./tsconfig.json"
@@ -1,29 +1,58 @@
1
1
  import { observable, attr } from '@microsoft/fast-element';
2
- import { IKDBTypesResponse } from '../../../types/IBackendCore';
2
+ import { IKDBTypeInfo, IKDBTypesResponse } from '../../../types/IBackendCore';
3
3
  import { RWSViewComponent} from '../../_component';
4
4
  import { RWSView} from '../../_decorator';
5
5
  import { ReFormerText } from './fields/text/component';
6
+ import { ReFormerDate } from './fields/date/component';
7
+ import { ReFormerNumber } from './fields/number/component';
8
+ import { ReFormerBoolean } from './fields/boolean/component';
6
9
 
10
+ ReFormerBoolean;
11
+ ReFormerNumber;
7
12
  ReFormerText;
13
+ ReFormerDate;
8
14
 
9
15
  @RWSView('rws-reformer')
10
16
  class ReFormer extends RWSViewComponent {
11
- @attr resourceName: string;
17
+ @attr resource: string;
12
18
 
13
19
  @observable fields: string[] | null = null;
20
+ @observable formFields: IKDBTypeInfo[];
21
+
14
22
  @observable modelTypes: IKDBTypesResponse;
23
+ @observable setForm: (key: string, val: any) => void = this.setFormField.bind(this);
24
+ @observable afterForm: (val: any) => Promise<void> = null;
25
+
26
+ private payload: {[key: string]: any} = {};
27
+
28
+ modelTypesChanged(oldVal:IKDBTypesResponse, newVal: IKDBTypesResponse)
29
+ {
30
+ if(newVal){
31
+ this.formFields = newVal.data.types.filter((item) => !['id', 'created_at', 'updated_at'].includes(item.fieldName))
32
+ }
33
+ }
15
34
 
16
- async connectedCallback(): Promise<void>
35
+ setFormField(key: string, val: HTMLFormElement)
17
36
  {
18
- this.modelTypes = await this.apiService.getResource(this.resourceName);
37
+ this.payload[key] = val.value;
19
38
  }
20
39
 
21
- setForm(key: string, val: any)
40
+ paintLabel(input: string): string
22
41
  {
23
- console.log('set reformer form', {key, val});
42
+ return input;
43
+ }
44
+
45
+ async sendForm()
46
+ {
47
+ const resource = await this.apiService.back.post(`${this.resource}:create`, this.payload);
48
+ this.payload = {};
49
+
50
+ if(this.afterForm){
51
+ this.afterForm(resource);
52
+ }
24
53
  }
25
54
  }
26
55
 
27
56
  ReFormer.defineComponent();
28
57
 
29
- export { ReFormer };
58
+ export { ReFormer };
@@ -0,0 +1,20 @@
1
+ import RWSViewComponent from '../../../../_component';
2
+ import { RWSView} from '../../../../_decorator';
3
+ import { attr, observable } from '@microsoft/fast-element';
4
+
5
+ @RWSView('reformer-boolean')
6
+ class ReFormerBoolean extends RWSViewComponent {
7
+ @attr name: string;
8
+ @observable defaultValue: boolean = null;
9
+ @observable value: boolean = null;
10
+ @observable setForm: (field: string, value: any) => Promise<void>;
11
+
12
+ connectedCallback(): void {
13
+ super.connectedCallback();
14
+ this.value = this.defaultValue;
15
+ }
16
+ }
17
+
18
+ ReFormerBoolean.defineComponent();
19
+
20
+ export { ReFormerBoolean };
@@ -0,0 +1,5 @@
1
+ @import "@rws-mixins";
2
+
3
+ .re-former-boolean-input {
4
+ display: flex;
5
+ }
@@ -0,0 +1,6 @@
1
+ <sl-switch
2
+ name="${ x => x.name}"
3
+ id="re-former-field-${x => x.name}"
4
+ :value="${x => x.value}"
5
+ @change="${(x,c) => x.setForm(x.name, c.event.target)}"
6
+ ></sl-switch>
@@ -0,0 +1,20 @@
1
+ import RWSViewComponent from '../../../../_component';
2
+ import { RWSView} from '../../../../_decorator';
3
+ import { attr, observable } from '@microsoft/fast-element';
4
+
5
+ @RWSView('reformer-date')
6
+ class ReFormerDate extends RWSViewComponent {
7
+ @attr name: string;
8
+ @observable defaultValue: Date = null;
9
+ @observable value: Date = null;
10
+ @observable setForm: (field: string, value: any) => Promise<void>;
11
+
12
+ connectedCallback(): void {
13
+ super.connectedCallback();
14
+ this.value = this.defaultValue;
15
+ }
16
+ }
17
+
18
+ ReFormerDate.defineComponent();
19
+
20
+ export { ReFormerDate };
@@ -0,0 +1,5 @@
1
+ @import "@rws-mixins";
2
+
3
+ .re-former-date-input {
4
+ display: flex;
5
+ }
@@ -0,0 +1,7 @@
1
+ <sl-input
2
+ type="date"
3
+ name="${ x => x.name}"
4
+ id="re-former-field-${x => x.name}"
5
+ :value="${x => x.value}"
6
+ @change="${(x,c) => x.setForm(x.name, c.event.target)}"
7
+ ></sl-input>
@@ -0,0 +1,20 @@
1
+ import RWSViewComponent from '../../../../_component';
2
+ import { RWSView} from '../../../../_decorator';
3
+ import { attr, observable } from '@microsoft/fast-element';
4
+
5
+ @RWSView('reformer-number')
6
+ class ReFormerNumber extends RWSViewComponent {
7
+ @attr name: string;
8
+ @observable defaultValue: number = null;
9
+ @observable value: number = null;
10
+ @observable setForm: (field: string, value: any) => Promise<void>;
11
+
12
+ connectedCallback(): void {
13
+ super.connectedCallback();
14
+ this.value = this.defaultValue;
15
+ }
16
+ }
17
+
18
+ ReFormerNumber.defineComponent();
19
+
20
+ export { ReFormerNumber };
@@ -0,0 +1,5 @@
1
+ @import "@rws-mixins";
2
+
3
+ .re-former-number-input {
4
+ display: flex;
5
+ }
@@ -0,0 +1,7 @@
1
+ <sl-input
2
+ type="number"
3
+ name="${ x => x.name}"
4
+ id="re-former-field-${x => x.name}"
5
+ :value="${x => x.value}"
6
+ @change="${(x,c) => x.setForm(x.name, c.event.target)}"
7
+ ></sl-input>
@@ -1,8 +1,19 @@
1
+ import { attr, observable } from '@microsoft/fast-element';
2
+ import RWSViewComponent from '../../../../_component';
1
3
  import { RWSView} from '../../../../_decorator';
2
- import { ReFormerFieldComponent } from '../_field';
3
4
 
4
5
  @RWSView('reformer-text')
5
- class ReFormerText extends ReFormerFieldComponent {}
6
+ class ReFormerText extends RWSViewComponent {
7
+ @attr name: string;
8
+ @observable defaultValue: string = null;
9
+ @observable value: string = null;
10
+ @observable setForm: (field: string, value: any) => Promise<void>;
11
+
12
+ connectedCallback(): void {
13
+ super.connectedCallback();
14
+ this.value = this.defaultValue;
15
+ }
16
+ }
6
17
 
7
18
  ReFormerText.defineComponent();
8
19
 
@@ -1,7 +1,7 @@
1
1
  <sl-input
2
2
  type="text"
3
3
  name="${ x => x.name}"
4
- id="re-former-field-${x.name}"
5
- value="${x => x.defaultValue}"
6
- @change="${(x,c) => x.changeField(x.name, c.event.target)}"
4
+ id="re-former-field-${x => x.name}"
5
+ :value="${x => x.value}"
6
+ @sl-change="${(x,c) => x.setForm(x.name, c.event.target)}"
7
7
  ></sl-input>
@@ -2,4 +2,15 @@
2
2
 
3
3
  .re-former-container {
4
4
  display: flex;
5
+ flex-direction: column;
6
+
7
+ .form-field {
8
+ max-width: 30%;
9
+ margin-bottom: 15px;
10
+
11
+ label {
12
+ font-weight: bold;
13
+ text-transform: capitalize;
14
+ }
15
+ }
5
16
  }
@@ -1,7 +1,19 @@
1
- <div class="re-former-container">
2
- ${T.repeat(x => x.modelTypes.data.types, T.html`<div class="form-field">
1
+ <form class="re-former-container">
2
+ ${T.repeat(x => x.formFields, T.html`<div class="form-field">
3
+ <label for="re-former-field-${x => x.fieldName}">${ (x, c) => c.parent.paintLabel(x.fieldName)}</label>
3
4
  ${T.when(x => x.type === 'String', T.html`
4
- <re-former-text :setForm="${x => x.setForm.bind(x)}" name="${x => x.fieldName}"></re-former-text>
5
+ <reformer-text class="reformer-field-input" :value="${ (x, c) => !!c.parent.payload[x.fieldName] ? c.parent.payload[x.fieldName] : null}" :setForm="${(x, c) => c.parent.setForm}" name="${x => x.fieldName}"></re-former-text>
5
6
  `)}
6
- </div>`)}
7
- </div>
7
+ ${T.when(x => x.type === 'Date', T.html`
8
+ <reformer-date class="reformer-field-input" :value="${ (x, c) => !!c.parent.payload[x.fieldName] ? c.parent.payload[x.fieldName] : null}" :setForm="${(x, c) => c.parent.setForm}" name="${x => x.fieldName}"></re-former-date>
9
+ `)}
10
+ ${T.when(x => x.type === 'Number', T.html`
11
+ <reformer-number class="reformer-field-input" :value="${ (x, c) => !!c.parent.payload[x.fieldName] ? c.parent.payload[x.fieldName] : null}" :setForm="${(x, c) => c.parent.setForm}" name="${x => x.fieldName}"></re-former-number>
12
+ `)}
13
+ ${T.when(x => x.type === 'Boolean', T.html`
14
+ <reformer-boolean class="reformer-field-input" :value="${ (x, c) => !!c.parent.payload[x.fieldName] ? c.parent.payload[x.fieldName] : null}" :setForm="${(x, c) => c.parent.setForm}" name="${x => x.fieldName}"></re-former-boolean>
15
+ `)}
16
+ </div>`)}
17
+
18
+ <sl-button @click="${ (x, c) => x.sendForm() }" variant="primary" >Save</sl-button>
19
+ </div>
@@ -0,0 +1,5 @@
1
+ import { IKDBTypeInfo } from "../../../../types/IBackendCore";
2
+
3
+ export type IReFormerOrder = IKDBTypeInfo[] | IReFormerOrder[];
4
+
5
+ export type IReFormerMassOrdering = IReFormerOrder[];
@@ -1,4 +1,4 @@
1
- import { IKDBTypeInfo, IKDBTypesResponse } from '../../../types/IBackendCore';
1
+ import { IKDBTypesResponse } from '../../../types/IBackendCore';
2
2
  import { observable, attr } from '@microsoft/fast-element';
3
3
  import { RWSView } from '../../_decorator';
4
4
  import { RWSViewComponent } from '../../_component';
@@ -15,38 +15,36 @@ RWSResourceFormComponent;
15
15
  class RWSApiResource extends RWSViewComponent {
16
16
  @attr resource: string;
17
17
  @attr resourceLabel: string = null;
18
-
18
+
19
+ @attr createEntryLabel = 'Create entry';
20
+ @attr listEntryLabel = 'Entries list';
21
+
22
+ @attr createEnabled = 'true';
19
23
  @attr emptyLabel: string = 'No records';
20
24
 
21
25
  @observable dbModelData: IKDBTypesResponse = null;
22
- @observable resourceList: any[] = [];
23
- @observable columns: IFlexTableColumn[] = [];
24
26
 
27
+ @observable viewType: 'list' | 'form' = 'list';
28
+
25
29
  @observable fields: string[] = [];
26
30
  @observable extraFormatters: {[header_key: string] : IExtraColumnFormatter} = {};
27
31
  @observable headerTranslations: {[header_key: string] : string} = {};
28
32
 
29
- @observable actions: ActionType[] = [];
33
+ @observable listActions: ActionType[] = [];
34
+
35
+ @observable back: (resource: any) => Promise<void> = async (resource: any) => {
36
+ this.viewType = 'list';
37
+ };
30
38
 
31
39
  async connectedCallback(): Promise<void>
32
40
  {
33
41
  super.connectedCallback();
42
+ this.dbModelData = await this.apiService.getResource(this.resource);
43
+ }
34
44
 
35
- this.dbModelData = await this.apiService.getResource(this.resource);
36
- this.resourceList = await this.apiService.back.get(`${this.resource}:list`);
37
-
38
- const makeColumns: IFlexTableColumn[] = [];
39
-
40
- for(const key in Object.keys(this.dbModelData.data.types)){
41
- const responseObject: IKDBTypeInfo = this.dbModelData.data.types[key];
42
-
43
- makeColumns.push({
44
- key: responseObject.fieldName,
45
- header: responseObject.fieldName,
46
- });
47
- }
48
-
49
- this.columns = makeColumns;
45
+ toggleForm()
46
+ {
47
+ this.viewType = this.viewType === 'form' ? 'list' : 'form';
50
48
  }
51
49
  }
52
50
 
@@ -1,5 +1,7 @@
1
1
  @import "@rws-mixins";
2
2
 
3
3
  .rws-api-container {
4
-
4
+ .rws-api-controls{
5
+ margin-bottom: 15px;
6
+ }
5
7
  }
@@ -1,13 +1,29 @@
1
1
  <div class="rws-api-container">
2
2
  ${T.when(x => x.resourceLabel, T.html`<h3>${x => x.resourceLabel}</h3>`)}
3
- ${x => console.log(x.columns)}
4
- ${T.when(x => x.columns.length, T.html`<rws-table
5
- emptyLabel="${x => x.emptyLabel}"
6
- :columns="${x => x.columns}"
7
- :data="${x => x.resourceList}"
8
- :fields="${x => x.fields}"
9
- :actions="${x => x.actions}"
10
- :extraFormatters="${x => x.extraFormatters}"
11
- :headerTranslations="${x => x.headerTranslations}">
12
- </rws-table>`)}
3
+
4
+ <div class="rws-api-controls">
5
+ ${T.when(x => x.createEnabled === 'true', T.html`<sl-button @click="${ (x, c) => x.toggleForm() }" variant="secondary" >
6
+ ${T.when(x => x.viewType === 'list', T.html`<span>${ x => x.createEntryLabel }</span>`)}
7
+ ${T.when(x => x.viewType === 'form', T.html`<span>${ x => x.listEntryLabel }</span>`)}
8
+ </sl-button>`)}
9
+ </div>
10
+
11
+ <div class="rws-api-content">
12
+ ${T.when(x => x.dbModelData && x.viewType === 'list', T.html`<rws-resource-list
13
+ resource="${x => x.resource}"
14
+ emptyLabel="${x => x.emptyLabel}"
15
+ :dbModelData="${x => x.dbModelData}"
16
+ :fields="${x => x.fields}"
17
+ :actions="${x => x.listActions}"
18
+ :extraFormatters="${x => x.extraFormatters}"
19
+ :headerTranslations="${x => x.headerTranslations}"
20
+ >
21
+ </rws-resource-list>`)}
22
+
23
+ ${T.when(x => x.viewType === 'form', T.html`<rws-resource-form
24
+ resource="${x => x.resource}"
25
+ :dbModelData="${x => x.dbModelData}"
26
+ :back="${x => x.back}"
27
+ ></rws-resource-form> `)}
28
+ </div>
13
29
  </div>
@@ -1,9 +1,35 @@
1
+ import { attr, observable } from '@microsoft/fast-element';
2
+ import { IKDBTypesResponse } from '../../../../../types/IBackendCore';
1
3
  import { RWSViewComponent} from '../../../../_component';
2
4
  import { RWSView} from '../../../../_decorator';
5
+ import { IReFormerMassOrdering } from '../../../reformer/types/IReFormerTypes';
3
6
 
4
7
 
5
8
  @RWSView('rws-resource-form')
6
9
  class RWSResourceFormComponent extends RWSViewComponent {
10
+ @attr resource: string;
11
+
12
+ @observable dbModelData: IKDBTypesResponse = null;
13
+ @observable formOrdering: IReFormerMassOrdering = [];
14
+ @observable back: (resource: any) => Promise<void>;
15
+
16
+ connectedCallback(): void
17
+ {
18
+ super.connectedCallback();
19
+ this.createOrdering();
20
+ }
21
+
22
+ setForm()
23
+ {
24
+
25
+ }
26
+
27
+ createOrdering()
28
+ {
29
+ for(const type of this.dbModelData.data.types){
30
+ this.formOrdering.push(type as unknown as IReFormerMassOrdering);
31
+ }
32
+ }
7
33
  }
8
34
 
9
35
  RWSResourceFormComponent.defineComponent();
@@ -1,3 +1,3 @@
1
1
  <div id="resource-form">
2
-
2
+ <rws-reformer :modelTypes="${ x => x.dbModelData}" resource="${x => x.resource}" :afterForm="${x => x.back}"></rws-reformer>
3
3
  </div>
@@ -1,9 +1,42 @@
1
1
  import { RWSViewComponent} from '../../../../_component';
2
2
  import { RWSView} from '../../../../_decorator';
3
-
3
+ import { observable, attr } from '@microsoft/fast-element';
4
+ import { ActionType, IExtraColumnFormatter, IFlexTableColumn } from '../../../rws-table/component';
5
+ import { IKDBTypeInfo, IKDBTypesResponse } from '../../../../../types/IBackendCore';
4
6
 
5
7
  @RWSView('rws-resource-list')
6
8
  class RWSResourceListComponent extends RWSViewComponent {
9
+ @attr resource: string;
10
+ @attr emptyLabel: string = 'No records';
11
+
12
+ @observable dbModelData: IKDBTypesResponse = null;
13
+ @observable resourceList: any[] = [];
14
+ @observable columns: IFlexTableColumn[] = [];
15
+
16
+ @observable fields: string[] = [];
17
+ @observable extraFormatters: {[header_key: string] : IExtraColumnFormatter} = {};
18
+ @observable headerTranslations: {[header_key: string] : string} = {};
19
+
20
+ @observable actions: ActionType[] = [];
21
+
22
+ async connectedCallback()
23
+ {
24
+ super.connectedCallback();
25
+ const makeColumns: IFlexTableColumn[] = [];
26
+
27
+ for(const key in Object.keys(this.dbModelData.data.types)){
28
+ const responseObject: IKDBTypeInfo = this.dbModelData.data.types[key];
29
+
30
+ makeColumns.push({
31
+ key: responseObject.fieldName,
32
+ header: responseObject.fieldName,
33
+ });
34
+ }
35
+
36
+ this.columns = makeColumns;
37
+
38
+ this.resourceList = await this.apiService.back.get(`${this.resource}:list`);
39
+ }
7
40
  }
8
41
 
9
42
  RWSResourceListComponent.defineComponent();
@@ -1,3 +1,11 @@
1
- <div id="resource-list">
2
-
3
- </div>
1
+ <div class="resource-list">
2
+ ${T.when(x => x.columns.length, T.html`<rws-table
3
+ emptyLabel="${x => x.emptyLabel}"
4
+ :columns="${x => x.columns}"
5
+ :data="${x => x.resourceList}"
6
+ :fields="${x => x.fields}"
7
+ :actions="${x => x.actions}"
8
+ :extraFormatters="${x => x.extraFormatters}"
9
+ :headerTranslations="${x => x.headerTranslations}">
10
+ </rws-table>`)}
11
+ </div>
@@ -1,14 +0,0 @@
1
- import { observable, attr } from "@microsoft/fast-element";
2
- import RWSViewComponent from "../../../_component";
3
- import { IReFormerField } from "../../../../types/IReFormerField";
4
-
5
- export abstract class ReFormerFieldComponent extends RWSViewComponent implements IReFormerField {
6
- @attr name: string;
7
- @observable defaultValue: any;
8
- @observable setForm: (field: string, value: any) => Promise<void>;
9
-
10
- changeField(key: string, value: any)
11
- {
12
- this.setForm(key, value);
13
- }
14
- }