Commit 079ae5fd8f17bb7b6f788372e7734bc5e03a8796
1 parent
2a5ba8e8
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 | 69 | |
70 | 70 | this.config.cellActionDescriptors.push( |
71 | 71 | { |
72 | - name: this.translate.instant('resource.export'), | |
72 | + name: this.translate.instant('resource.download'), | |
73 | 73 | icon: 'file_download', |
74 | 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 | 118 | return this.config; |
119 | 119 | } |
120 | 120 | |
121 | - exportResource($event: Event, resource: ResourceInfo) { | |
121 | + downloadResource($event: Event, resource: ResourceInfo) { | |
122 | 122 | if ($event) { |
123 | 123 | $event.stopPropagation(); |
124 | 124 | } |
... | ... | @@ -127,8 +127,8 @@ export class ResourcesLibraryTableConfigResolver implements Resolve<EntityTableC |
127 | 127 | |
128 | 128 | onResourceAction(action: EntityAction<ResourceInfo>): boolean { |
129 | 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 | 132 | return true; |
133 | 133 | } |
134 | 134 | return false; | ... | ... |
... | ... | @@ -18,16 +18,26 @@ |
18 | 18 | <div class="tb-details-buttons" fxLayout.xs="column"> |
19 | 19 | <button mat-raised-button color="primary" fxFlex.xs |
20 | 20 | [disabled]="(isLoading$ | async)" |
21 | - (click)="onEntityAction($event, 'uploadResource')" | |
21 | + (click)="onEntityAction($event, 'downloadResource')" | |
22 | 22 | [fxShow]="!isEdit"> |
23 | - {{'resource.export' | translate }} | |
23 | + {{ 'resource.download' | translate }} | |
24 | 24 | </button> |
25 | 25 | <button mat-raised-button color="primary" fxFlex.xs |
26 | 26 | [disabled]="(isLoading$ | async)" |
27 | 27 | (click)="onEntityAction($event, 'delete')" |
28 | 28 | [fxShow]="!hideDelete() && !isEdit"> |
29 | - {{'resource.delete' | translate }} | |
29 | + {{ 'resource.delete' | translate }} | |
30 | 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 | 41 | </div> |
32 | 42 | <div class="mat-padding" fxLayout="column"> |
33 | 43 | <form [formGroup]="entityForm"> |
... | ... | @@ -47,7 +57,7 @@ |
47 | 57 | {{ 'resource.title-required' | translate }} |
48 | 58 | </mat-error> |
49 | 59 | </mat-form-field> |
50 | - <tb-file-input | |
60 | + <tb-file-input *ngIf="isAdd" | |
51 | 61 | formControlName="data" |
52 | 62 | required |
53 | 63 | [readAsBinary]="true" |
... | ... | @@ -59,6 +69,12 @@ |
59 | 69 | [existingFileName]="entityForm.get('fileName')?.value" |
60 | 70 | (fileNameChanged)="entityForm?.get('fileName').patchValue($event)"> |
61 | 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 | 78 | </fieldset> |
63 | 79 | </form> |
64 | 80 | </div> | ... | ... |
... | ... | @@ -30,6 +30,7 @@ import { |
30 | 30 | ResourceTypeTranslationMap |
31 | 31 | } from '@shared/models/resource.models'; |
32 | 32 | import { pairwise, startWith, takeUntil } from 'rxjs/operators'; |
33 | +import { ActionNotificationShow } from "@core/notification/notification.actions"; | |
33 | 34 | |
34 | 35 | @Component({ |
35 | 36 | selector: 'tb-resources-library', |
... | ... | @@ -88,26 +89,29 @@ export class ResourcesLibraryComponent extends EntityComponent<Resource> impleme |
88 | 89 | } |
89 | 90 | |
90 | 91 | buildForm(entity: Resource): FormGroup { |
91 | - return this.fb.group( | |
92 | + const form = this.fb.group( | |
92 | 93 | { |
94 | + title: [entity ? entity.title : '', []], | |
93 | 95 | resourceType: [{ |
94 | 96 | value: entity?.resourceType ? entity.resourceType : ResourceType.LWM2M_MODEL, |
95 | - disabled: this.isEdit | |
97 | + disabled: !this.isAdd | |
96 | 98 | }, [Validators.required]], |
97 | - data: [entity ? entity.data : null, [Validators.required]], | |
98 | 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 | 108 | updateForm(entity: Resource) { |
105 | - this.entityForm.patchValue({resourceType: entity.resourceType}); | |
106 | 109 | if (this.isEdit) { |
107 | 110 | this.entityForm.get('resourceType').disable({emitEvent: false}); |
111 | + this.entityForm.get('fileName').disable({emitEvent: false}); | |
108 | 112 | } |
109 | 113 | this.entityForm.patchValue({ |
110 | - data: entity.data, | |
114 | + resourceType: entity.resourceType, | |
111 | 115 | fileName: entity.fileName, |
112 | 116 | title: entity.title |
113 | 117 | }); |
... | ... | @@ -132,4 +136,15 @@ export class ResourcesLibraryComponent extends EntityComponent<Resource> impleme |
132 | 136 | convertToBase64File(data: string): string { |
133 | 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 | 120 | entityViews: helpBaseUrl + '/docs/user-guide/ui/entity-views', |
121 | 121 | entitiesImport: helpBaseUrl + '/docs/user-guide/bulk-provisioning', |
122 | 122 | rulechains: helpBaseUrl + '/docs/user-guide/ui/rule-chains', |
123 | + resources: helpBaseUrl + '/docs/user-guide/ui/resources', | |
123 | 124 | dashboards: helpBaseUrl + '/docs/user-guide/ui/dashboards', |
124 | 125 | otaUpdates: helpBaseUrl + '/docs/user-guide/ui/ota-updates', |
125 | 126 | widgetsBundles: helpBaseUrl + '/docs/user-guide/ui/widget-library#bundles', | ... | ... |
... | ... | @@ -2309,20 +2309,23 @@ |
2309 | 2309 | }, |
2310 | 2310 | "resource": { |
2311 | 2311 | "add": "Add Resource", |
2312 | + "copyId": "Copy resource Id", | |
2312 | 2313 | "delete": "Delete resource", |
2313 | 2314 | "delete-resource-text": "Be careful, after the confirmation the resource will become unrecoverable.", |
2314 | 2315 | "delete-resource-title": "Are you sure you want to delete the resource '{{resourceTitle}}'?", |
2315 | 2316 | "delete-resources-action-title": "Delete { count, plural, 1 {1 resource} other {# resources} }", |
2316 | 2317 | "delete-resources-text": "Be careful, after the confirmation all selected resources will be removed.", |
2317 | 2318 | "delete-resources-title": "Are you sure you want to delete { count, plural, 1 {1 resource} other {# resources} }?", |
2319 | + "download": "Download resource", | |
2318 | 2320 | "drop-file": "Drop a resource file or click to select a file to upload.", |
2319 | 2321 | "empty": "Resource is empty", |
2320 | - "export": "Export resource", | |
2322 | + "file-name": "File name", | |
2323 | + "idCopiedMessage": "Resource Id has been copied to clipboard", | |
2321 | 2324 | "no-resource-matching": "No resource matching '{{widgetsBundle}}' were found.", |
2322 | 2325 | "no-resource-text": "No resources found", |
2323 | 2326 | "open-widgets-bundle": "Open widgets bundle", |
2324 | 2327 | "resource": "Resource", |
2325 | - "resource-library-details": "Resource library details", | |
2328 | + "resource-library-details": "Resource details", | |
2326 | 2329 | "resource-type": "Resource type", |
2327 | 2330 | "resources-library": "Resources library", |
2328 | 2331 | "search": "Search resources", | ... | ... |
... | ... | @@ -1994,7 +1994,6 @@ |
1994 | 1994 | "delete-resources-title": "确定要删除 { count, plural, 1 {# 个资源} other {# 个资源} }?", |
1995 | 1995 | "drop-file": "拖拽资源文件或单击以选择要上传的文件。", |
1996 | 1996 | "empty": "资源为空", |
1997 | - "export": "导出资源", | |
1998 | 1997 | "no-resource-matching": "找不到与 '{{widgetsBundle}}' 匹配的资源。", |
1999 | 1998 | "no-resource-text": "找不到资源", |
2000 | 1999 | "open-widgets-bundle": "打开部件库", | ... | ... |