Commit d582f5b85ff36952c56c1e668099284686f4973b
Committed by
GitHub
Merge pull request #4749 from vvlladd28/improvement/resources/table
UI: Refactoring resource: add help link; improvement text and view
Showing
7 changed files
with
54 additions
and
20 deletions
@@ -69,10 +69,10 @@ export class ResourcesLibraryTableConfigResolver implements Resolve<EntityTableC | @@ -69,10 +69,10 @@ export class ResourcesLibraryTableConfigResolver implements Resolve<EntityTableC | ||
69 | 69 | ||
70 | this.config.cellActionDescriptors.push( | 70 | this.config.cellActionDescriptors.push( |
71 | { | 71 | { |
72 | - name: this.translate.instant('resource.export'), | 72 | + name: this.translate.instant('resource.download'), |
73 | icon: 'file_download', | 73 | icon: 'file_download', |
74 | isEnabled: () => true, | 74 | isEnabled: () => true, |
75 | - onAction: ($event, entity) => this.exportResource($event, entity) | 75 | + onAction: ($event, entity) => this.downloadResource($event, entity) |
76 | } | 76 | } |
77 | ); | 77 | ); |
78 | 78 | ||
@@ -118,7 +118,7 @@ export class ResourcesLibraryTableConfigResolver implements Resolve<EntityTableC | @@ -118,7 +118,7 @@ export class ResourcesLibraryTableConfigResolver implements Resolve<EntityTableC | ||
118 | return this.config; | 118 | return this.config; |
119 | } | 119 | } |
120 | 120 | ||
121 | - exportResource($event: Event, resource: ResourceInfo) { | 121 | + downloadResource($event: Event, resource: ResourceInfo) { |
122 | if ($event) { | 122 | if ($event) { |
123 | $event.stopPropagation(); | 123 | $event.stopPropagation(); |
124 | } | 124 | } |
@@ -127,8 +127,8 @@ export class ResourcesLibraryTableConfigResolver implements Resolve<EntityTableC | @@ -127,8 +127,8 @@ export class ResourcesLibraryTableConfigResolver implements Resolve<EntityTableC | ||
127 | 127 | ||
128 | onResourceAction(action: EntityAction<ResourceInfo>): boolean { | 128 | onResourceAction(action: EntityAction<ResourceInfo>): boolean { |
129 | switch (action.action) { | 129 | switch (action.action) { |
130 | - case 'uploadResource': | ||
131 | - this.exportResource(action.event, action.entity); | 130 | + case 'downloadResource': |
131 | + this.downloadResource(action.event, action.entity); | ||
132 | return true; | 132 | return true; |
133 | } | 133 | } |
134 | return false; | 134 | return false; |
@@ -18,16 +18,26 @@ | @@ -18,16 +18,26 @@ | ||
18 | <div class="tb-details-buttons" fxLayout.xs="column"> | 18 | <div class="tb-details-buttons" fxLayout.xs="column"> |
19 | <button mat-raised-button color="primary" fxFlex.xs | 19 | <button mat-raised-button color="primary" fxFlex.xs |
20 | [disabled]="(isLoading$ | async)" | 20 | [disabled]="(isLoading$ | async)" |
21 | - (click)="onEntityAction($event, 'uploadResource')" | 21 | + (click)="onEntityAction($event, 'downloadResource')" |
22 | [fxShow]="!isEdit"> | 22 | [fxShow]="!isEdit"> |
23 | - {{'resource.export' | translate }} | 23 | + {{ 'resource.download' | translate }} |
24 | </button> | 24 | </button> |
25 | <button mat-raised-button color="primary" fxFlex.xs | 25 | <button mat-raised-button color="primary" fxFlex.xs |
26 | [disabled]="(isLoading$ | async)" | 26 | [disabled]="(isLoading$ | async)" |
27 | (click)="onEntityAction($event, 'delete')" | 27 | (click)="onEntityAction($event, 'delete')" |
28 | [fxShow]="!hideDelete() && !isEdit"> | 28 | [fxShow]="!hideDelete() && !isEdit"> |
29 | - {{'resource.delete' | translate }} | 29 | + {{ 'resource.delete' | translate }} |
30 | </button> | 30 | </button> |
31 | + <div fxLayout="row" fxLayout.xs="column"> | ||
32 | + <button mat-raised-button | ||
33 | + ngxClipboard | ||
34 | + (cbOnSuccess)="onResourceIdCopied()" | ||
35 | + [cbContent]="entity?.id?.id" | ||
36 | + [fxShow]="!isEdit"> | ||
37 | + <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> | ||
38 | + <span translate>resource.copyId</span> | ||
39 | + </button> | ||
40 | + </div> | ||
31 | </div> | 41 | </div> |
32 | <div class="mat-padding" fxLayout="column"> | 42 | <div class="mat-padding" fxLayout="column"> |
33 | <form [formGroup]="entityForm"> | 43 | <form [formGroup]="entityForm"> |
@@ -47,7 +57,7 @@ | @@ -47,7 +57,7 @@ | ||
47 | {{ 'resource.title-required' | translate }} | 57 | {{ 'resource.title-required' | translate }} |
48 | </mat-error> | 58 | </mat-error> |
49 | </mat-form-field> | 59 | </mat-form-field> |
50 | - <tb-file-input | 60 | + <tb-file-input *ngIf="isAdd" |
51 | formControlName="data" | 61 | formControlName="data" |
52 | required | 62 | required |
53 | [readAsBinary]="true" | 63 | [readAsBinary]="true" |
@@ -59,6 +69,12 @@ | @@ -59,6 +69,12 @@ | ||
59 | [existingFileName]="entityForm.get('fileName')?.value" | 69 | [existingFileName]="entityForm.get('fileName')?.value" |
60 | (fileNameChanged)="entityForm?.get('fileName').patchValue($event)"> | 70 | (fileNameChanged)="entityForm?.get('fileName').patchValue($event)"> |
61 | </tb-file-input> | 71 | </tb-file-input> |
72 | + <div *ngIf="!isAdd" fxLayout="row" fxLayoutGap.gt-md="8px" fxLayoutGap.sm="8px" fxLayout.xs="column" fxLayout.md="column"> | ||
73 | + <mat-form-field fxFlex> | ||
74 | + <mat-label translate>resource.file-name</mat-label> | ||
75 | + <input matInput formControlName="fileName" type="text"> | ||
76 | + </mat-form-field> | ||
77 | + </div> | ||
62 | </fieldset> | 78 | </fieldset> |
63 | </form> | 79 | </form> |
64 | </div> | 80 | </div> |
@@ -30,6 +30,7 @@ import { | @@ -30,6 +30,7 @@ import { | ||
30 | ResourceTypeTranslationMap | 30 | ResourceTypeTranslationMap |
31 | } from '@shared/models/resource.models'; | 31 | } from '@shared/models/resource.models'; |
32 | import { pairwise, startWith, takeUntil } from 'rxjs/operators'; | 32 | import { pairwise, startWith, takeUntil } from 'rxjs/operators'; |
33 | +import { ActionNotificationShow } from "@core/notification/notification.actions"; | ||
33 | 34 | ||
34 | @Component({ | 35 | @Component({ |
35 | selector: 'tb-resources-library', | 36 | selector: 'tb-resources-library', |
@@ -88,26 +89,29 @@ export class ResourcesLibraryComponent extends EntityComponent<Resource> impleme | @@ -88,26 +89,29 @@ export class ResourcesLibraryComponent extends EntityComponent<Resource> impleme | ||
88 | } | 89 | } |
89 | 90 | ||
90 | buildForm(entity: Resource): FormGroup { | 91 | buildForm(entity: Resource): FormGroup { |
91 | - return this.fb.group( | 92 | + const form = this.fb.group( |
92 | { | 93 | { |
94 | + title: [entity ? entity.title : '', []], | ||
93 | resourceType: [{ | 95 | resourceType: [{ |
94 | value: entity?.resourceType ? entity.resourceType : ResourceType.LWM2M_MODEL, | 96 | value: entity?.resourceType ? entity.resourceType : ResourceType.LWM2M_MODEL, |
95 | - disabled: this.isEdit | 97 | + disabled: !this.isAdd |
96 | }, [Validators.required]], | 98 | }, [Validators.required]], |
97 | - data: [entity ? entity.data : null, [Validators.required]], | ||
98 | fileName: [entity ? entity.fileName : null, [Validators.required]], | 99 | fileName: [entity ? entity.fileName : null, [Validators.required]], |
99 | - title: [entity ? entity.title : '', []] | ||
100 | } | 100 | } |
101 | ); | 101 | ); |
102 | + if (this.isAdd) { | ||
103 | + form.addControl('data', this.fb.control(null, Validators.required)); | ||
104 | + } | ||
105 | + return form | ||
102 | } | 106 | } |
103 | 107 | ||
104 | updateForm(entity: Resource) { | 108 | updateForm(entity: Resource) { |
105 | - this.entityForm.patchValue({resourceType: entity.resourceType}); | ||
106 | if (this.isEdit) { | 109 | if (this.isEdit) { |
107 | this.entityForm.get('resourceType').disable({emitEvent: false}); | 110 | this.entityForm.get('resourceType').disable({emitEvent: false}); |
111 | + this.entityForm.get('fileName').disable({emitEvent: false}); | ||
108 | } | 112 | } |
109 | this.entityForm.patchValue({ | 113 | this.entityForm.patchValue({ |
110 | - data: entity.data, | 114 | + resourceType: entity.resourceType, |
111 | fileName: entity.fileName, | 115 | fileName: entity.fileName, |
112 | title: entity.title | 116 | title: entity.title |
113 | }); | 117 | }); |
@@ -132,4 +136,15 @@ export class ResourcesLibraryComponent extends EntityComponent<Resource> impleme | @@ -132,4 +136,15 @@ export class ResourcesLibraryComponent extends EntityComponent<Resource> impleme | ||
132 | convertToBase64File(data: string): string { | 136 | convertToBase64File(data: string): string { |
133 | return window.btoa(data); | 137 | return window.btoa(data); |
134 | } | 138 | } |
139 | + | ||
140 | + onResourceIdCopied() { | ||
141 | + this.store.dispatch(new ActionNotificationShow( | ||
142 | + { | ||
143 | + message: this.translate.instant('resource.idCopiedMessage'), | ||
144 | + type: 'success', | ||
145 | + duration: 750, | ||
146 | + verticalPosition: 'bottom', | ||
147 | + horizontalPosition: 'right' | ||
148 | + })); | ||
149 | + } | ||
135 | } | 150 | } |
@@ -120,6 +120,7 @@ export const HelpLinks = { | @@ -120,6 +120,7 @@ export const HelpLinks = { | ||
120 | entityViews: helpBaseUrl + '/docs/user-guide/ui/entity-views', | 120 | entityViews: helpBaseUrl + '/docs/user-guide/ui/entity-views', |
121 | entitiesImport: helpBaseUrl + '/docs/user-guide/bulk-provisioning', | 121 | entitiesImport: helpBaseUrl + '/docs/user-guide/bulk-provisioning', |
122 | rulechains: helpBaseUrl + '/docs/user-guide/ui/rule-chains', | 122 | rulechains: helpBaseUrl + '/docs/user-guide/ui/rule-chains', |
123 | + resources: helpBaseUrl + '/docs/user-guide/ui/resources', | ||
123 | dashboards: helpBaseUrl + '/docs/user-guide/ui/dashboards', | 124 | dashboards: helpBaseUrl + '/docs/user-guide/ui/dashboards', |
124 | otaUpdates: helpBaseUrl + '/docs/user-guide/ui/ota-updates', | 125 | otaUpdates: helpBaseUrl + '/docs/user-guide/ui/ota-updates', |
125 | widgetsBundles: helpBaseUrl + '/docs/user-guide/ui/widget-library#bundles', | 126 | widgetsBundles: helpBaseUrl + '/docs/user-guide/ui/widget-library#bundles', |
@@ -61,6 +61,6 @@ export interface Resource extends ResourceInfo { | @@ -61,6 +61,6 @@ export interface Resource extends ResourceInfo { | ||
61 | } | 61 | } |
62 | 62 | ||
63 | export interface Resources extends ResourceInfo { | 63 | export interface Resources extends ResourceInfo { |
64 | - data: string|string[]; | ||
65 | - fileName: string|string[]; | 64 | + data: Array<string>; |
65 | + fileName: Array<string>; | ||
66 | } | 66 | } |
@@ -2309,20 +2309,23 @@ | @@ -2309,20 +2309,23 @@ | ||
2309 | }, | 2309 | }, |
2310 | "resource": { | 2310 | "resource": { |
2311 | "add": "Add Resource", | 2311 | "add": "Add Resource", |
2312 | + "copyId": "Copy resource Id", | ||
2312 | "delete": "Delete resource", | 2313 | "delete": "Delete resource", |
2313 | "delete-resource-text": "Be careful, after the confirmation the resource will become unrecoverable.", | 2314 | "delete-resource-text": "Be careful, after the confirmation the resource will become unrecoverable.", |
2314 | "delete-resource-title": "Are you sure you want to delete the resource '{{resourceTitle}}'?", | 2315 | "delete-resource-title": "Are you sure you want to delete the resource '{{resourceTitle}}'?", |
2315 | "delete-resources-action-title": "Delete { count, plural, 1 {1 resource} other {# resources} }", | 2316 | "delete-resources-action-title": "Delete { count, plural, 1 {1 resource} other {# resources} }", |
2316 | "delete-resources-text": "Be careful, after the confirmation all selected resources will be removed.", | 2317 | "delete-resources-text": "Be careful, after the confirmation all selected resources will be removed.", |
2317 | "delete-resources-title": "Are you sure you want to delete { count, plural, 1 {1 resource} other {# resources} }?", | 2318 | "delete-resources-title": "Are you sure you want to delete { count, plural, 1 {1 resource} other {# resources} }?", |
2319 | + "download": "Download resource", | ||
2318 | "drop-file": "Drop a resource file or click to select a file to upload.", | 2320 | "drop-file": "Drop a resource file or click to select a file to upload.", |
2319 | "empty": "Resource is empty", | 2321 | "empty": "Resource is empty", |
2320 | - "export": "Export resource", | 2322 | + "file-name": "File name", |
2323 | + "idCopiedMessage": "Resource Id has been copied to clipboard", | ||
2321 | "no-resource-matching": "No resource matching '{{widgetsBundle}}' were found.", | 2324 | "no-resource-matching": "No resource matching '{{widgetsBundle}}' were found.", |
2322 | "no-resource-text": "No resources found", | 2325 | "no-resource-text": "No resources found", |
2323 | "open-widgets-bundle": "Open widgets bundle", | 2326 | "open-widgets-bundle": "Open widgets bundle", |
2324 | "resource": "Resource", | 2327 | "resource": "Resource", |
2325 | - "resource-library-details": "Resource library details", | 2328 | + "resource-library-details": "Resource details", |
2326 | "resource-type": "Resource type", | 2329 | "resource-type": "Resource type", |
2327 | "resources-library": "Resources library", | 2330 | "resources-library": "Resources library", |
2328 | "search": "Search resources", | 2331 | "search": "Search resources", |
@@ -1994,7 +1994,6 @@ | @@ -1994,7 +1994,6 @@ | ||
1994 | "delete-resources-title": "确定要删除 { count, plural, 1 {# 个资源} other {# 个资源} }?", | 1994 | "delete-resources-title": "确定要删除 { count, plural, 1 {# 个资源} other {# 个资源} }?", |
1995 | "drop-file": "拖拽资源文件或单击以选择要上传的文件。", | 1995 | "drop-file": "拖拽资源文件或单击以选择要上传的文件。", |
1996 | "empty": "资源为空", | 1996 | "empty": "资源为空", |
1997 | - "export": "导出资源", | ||
1998 | "no-resource-matching": "找不到与 '{{widgetsBundle}}' 匹配的资源。", | 1997 | "no-resource-matching": "找不到与 '{{widgetsBundle}}' 匹配的资源。", |
1999 | "no-resource-text": "找不到资源", | 1998 | "no-resource-text": "找不到资源", |
2000 | "open-widgets-bundle": "打开部件库", | 1999 | "open-widgets-bundle": "打开部件库", |