Merge pull request #4749 from vvlladd28/improvement/resources/table

UI: Refactoring resource: add help link; improvement text and view
This commit is contained in:
Igor Kulikov 2021-06-18 16:33:25 +03:00 committed by GitHub
commit d582f5b85f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 20 deletions

View File

@ -69,10 +69,10 @@ export class ResourcesLibraryTableConfigResolver implements Resolve<EntityTableC
this.config.cellActionDescriptors.push( this.config.cellActionDescriptors.push(
{ {
name: this.translate.instant('resource.export'), name: this.translate.instant('resource.download'),
icon: 'file_download', icon: 'file_download',
isEnabled: () => true, isEnabled: () => true,
onAction: ($event, entity) => this.exportResource($event, entity) onAction: ($event, entity) => this.downloadResource($event, entity)
} }
); );
@ -118,7 +118,7 @@ export class ResourcesLibraryTableConfigResolver implements Resolve<EntityTableC
return this.config; return this.config;
} }
exportResource($event: Event, resource: ResourceInfo) { downloadResource($event: Event, resource: ResourceInfo) {
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
@ -127,8 +127,8 @@ export class ResourcesLibraryTableConfigResolver implements Resolve<EntityTableC
onResourceAction(action: EntityAction<ResourceInfo>): boolean { onResourceAction(action: EntityAction<ResourceInfo>): boolean {
switch (action.action) { switch (action.action) {
case 'uploadResource': case 'downloadResource':
this.exportResource(action.event, action.entity); this.downloadResource(action.event, action.entity);
return true; return true;
} }
return false; return false;

View File

@ -18,9 +18,9 @@
<div class="tb-details-buttons" fxLayout.xs="column"> <div class="tb-details-buttons" fxLayout.xs="column">
<button mat-raised-button color="primary" fxFlex.xs <button mat-raised-button color="primary" fxFlex.xs
[disabled]="(isLoading$ | async)" [disabled]="(isLoading$ | async)"
(click)="onEntityAction($event, 'uploadResource')" (click)="onEntityAction($event, 'downloadResource')"
[fxShow]="!isEdit"> [fxShow]="!isEdit">
{{'resource.export' | translate }} {{ 'resource.download' | translate }}
</button> </button>
<button mat-raised-button color="primary" fxFlex.xs <button mat-raised-button color="primary" fxFlex.xs
[disabled]="(isLoading$ | async)" [disabled]="(isLoading$ | async)"
@ -28,6 +28,16 @@
[fxShow]="!hideDelete() && !isEdit"> [fxShow]="!hideDelete() && !isEdit">
{{ 'resource.delete' | translate }} {{ 'resource.delete' | translate }}
</button> </button>
<div fxLayout="row" fxLayout.xs="column">
<button mat-raised-button
ngxClipboard
(cbOnSuccess)="onResourceIdCopied()"
[cbContent]="entity?.id?.id"
[fxShow]="!isEdit">
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
<span translate>resource.copyId</span>
</button>
</div>
</div> </div>
<div class="mat-padding" fxLayout="column"> <div class="mat-padding" fxLayout="column">
<form [formGroup]="entityForm"> <form [formGroup]="entityForm">
@ -47,7 +57,7 @@
{{ 'resource.title-required' | translate }} {{ 'resource.title-required' | translate }}
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
<tb-file-input <tb-file-input *ngIf="isAdd"
formControlName="data" formControlName="data"
required required
[readAsBinary]="true" [readAsBinary]="true"
@ -59,6 +69,12 @@
[existingFileName]="entityForm.get('fileName')?.value" [existingFileName]="entityForm.get('fileName')?.value"
(fileNameChanged)="entityForm?.get('fileName').patchValue($event)"> (fileNameChanged)="entityForm?.get('fileName').patchValue($event)">
</tb-file-input> </tb-file-input>
<div *ngIf="!isAdd" fxLayout="row" fxLayoutGap.gt-md="8px" fxLayoutGap.sm="8px" fxLayout.xs="column" fxLayout.md="column">
<mat-form-field fxFlex>
<mat-label translate>resource.file-name</mat-label>
<input matInput formControlName="fileName" type="text">
</mat-form-field>
</div>
</fieldset> </fieldset>
</form> </form>
</div> </div>

View File

@ -30,6 +30,7 @@ import {
ResourceTypeTranslationMap ResourceTypeTranslationMap
} from '@shared/models/resource.models'; } from '@shared/models/resource.models';
import { pairwise, startWith, takeUntil } from 'rxjs/operators'; import { pairwise, startWith, takeUntil } from 'rxjs/operators';
import { ActionNotificationShow } from "@core/notification/notification.actions";
@Component({ @Component({
selector: 'tb-resources-library', selector: 'tb-resources-library',
@ -88,26 +89,29 @@ export class ResourcesLibraryComponent extends EntityComponent<Resource> impleme
} }
buildForm(entity: Resource): FormGroup { buildForm(entity: Resource): FormGroup {
return this.fb.group( const form = this.fb.group(
{ {
title: [entity ? entity.title : '', []],
resourceType: [{ resourceType: [{
value: entity?.resourceType ? entity.resourceType : ResourceType.LWM2M_MODEL, value: entity?.resourceType ? entity.resourceType : ResourceType.LWM2M_MODEL,
disabled: this.isEdit disabled: !this.isAdd
}, [Validators.required]], }, [Validators.required]],
data: [entity ? entity.data : null, [Validators.required]],
fileName: [entity ? entity.fileName : null, [Validators.required]], fileName: [entity ? entity.fileName : null, [Validators.required]],
title: [entity ? entity.title : '', []]
} }
); );
if (this.isAdd) {
form.addControl('data', this.fb.control(null, Validators.required));
}
return form
} }
updateForm(entity: Resource) { updateForm(entity: Resource) {
this.entityForm.patchValue({resourceType: entity.resourceType});
if (this.isEdit) { if (this.isEdit) {
this.entityForm.get('resourceType').disable({emitEvent: false}); this.entityForm.get('resourceType').disable({emitEvent: false});
this.entityForm.get('fileName').disable({emitEvent: false});
} }
this.entityForm.patchValue({ this.entityForm.patchValue({
data: entity.data, resourceType: entity.resourceType,
fileName: entity.fileName, fileName: entity.fileName,
title: entity.title title: entity.title
}); });
@ -132,4 +136,15 @@ export class ResourcesLibraryComponent extends EntityComponent<Resource> impleme
convertToBase64File(data: string): string { convertToBase64File(data: string): string {
return window.btoa(data); return window.btoa(data);
} }
onResourceIdCopied() {
this.store.dispatch(new ActionNotificationShow(
{
message: this.translate.instant('resource.idCopiedMessage'),
type: 'success',
duration: 750,
verticalPosition: 'bottom',
horizontalPosition: 'right'
}));
}
} }

View File

@ -120,6 +120,7 @@ export const HelpLinks = {
entityViews: helpBaseUrl + '/docs/user-guide/ui/entity-views', entityViews: helpBaseUrl + '/docs/user-guide/ui/entity-views',
entitiesImport: helpBaseUrl + '/docs/user-guide/bulk-provisioning', entitiesImport: helpBaseUrl + '/docs/user-guide/bulk-provisioning',
rulechains: helpBaseUrl + '/docs/user-guide/ui/rule-chains', rulechains: helpBaseUrl + '/docs/user-guide/ui/rule-chains',
resources: helpBaseUrl + '/docs/user-guide/ui/resources',
dashboards: helpBaseUrl + '/docs/user-guide/ui/dashboards', dashboards: helpBaseUrl + '/docs/user-guide/ui/dashboards',
otaUpdates: helpBaseUrl + '/docs/user-guide/ui/ota-updates', otaUpdates: helpBaseUrl + '/docs/user-guide/ui/ota-updates',
widgetsBundles: helpBaseUrl + '/docs/user-guide/ui/widget-library#bundles', widgetsBundles: helpBaseUrl + '/docs/user-guide/ui/widget-library#bundles',

View File

@ -61,6 +61,6 @@ export interface Resource extends ResourceInfo {
} }
export interface Resources extends ResourceInfo { export interface Resources extends ResourceInfo {
data: string|string[]; data: Array<string>;
fileName: string|string[]; fileName: Array<string>;
} }

View File

@ -2309,20 +2309,23 @@
}, },
"resource": { "resource": {
"add": "Add Resource", "add": "Add Resource",
"copyId": "Copy resource Id",
"delete": "Delete resource", "delete": "Delete resource",
"delete-resource-text": "Be careful, after the confirmation the resource will become unrecoverable.", "delete-resource-text": "Be careful, after the confirmation the resource will become unrecoverable.",
"delete-resource-title": "Are you sure you want to delete the resource '{{resourceTitle}}'?", "delete-resource-title": "Are you sure you want to delete the resource '{{resourceTitle}}'?",
"delete-resources-action-title": "Delete { count, plural, 1 {1 resource} other {# resources} }", "delete-resources-action-title": "Delete { count, plural, 1 {1 resource} other {# resources} }",
"delete-resources-text": "Be careful, after the confirmation all selected resources will be removed.", "delete-resources-text": "Be careful, after the confirmation all selected resources will be removed.",
"delete-resources-title": "Are you sure you want to delete { count, plural, 1 {1 resource} other {# resources} }?", "delete-resources-title": "Are you sure you want to delete { count, plural, 1 {1 resource} other {# resources} }?",
"download": "Download resource",
"drop-file": "Drop a resource file or click to select a file to upload.", "drop-file": "Drop a resource file or click to select a file to upload.",
"empty": "Resource is empty", "empty": "Resource is empty",
"export": "Export resource", "file-name": "File name",
"idCopiedMessage": "Resource Id has been copied to clipboard",
"no-resource-matching": "No resource matching '{{widgetsBundle}}' were found.", "no-resource-matching": "No resource matching '{{widgetsBundle}}' were found.",
"no-resource-text": "No resources found", "no-resource-text": "No resources found",
"open-widgets-bundle": "Open widgets bundle", "open-widgets-bundle": "Open widgets bundle",
"resource": "Resource", "resource": "Resource",
"resource-library-details": "Resource library details", "resource-library-details": "Resource details",
"resource-type": "Resource type", "resource-type": "Resource type",
"resources-library": "Resources library", "resources-library": "Resources library",
"search": "Search resources", "search": "Search resources",

View File

@ -1994,7 +1994,6 @@
"delete-resources-title": "确定要删除 { count, plural, 1 {# 个资源} other {# 个资源} }?", "delete-resources-title": "确定要删除 { count, plural, 1 {# 个资源} other {# 个资源} }?",
"drop-file": "拖拽资源文件或单击以选择要上传的文件。", "drop-file": "拖拽资源文件或单击以选择要上传的文件。",
"empty": "资源为空", "empty": "资源为空",
"export": "导出资源",
"no-resource-matching": "找不到与 '{{widgetsBundle}}' 匹配的资源。", "no-resource-matching": "找不到与 '{{widgetsBundle}}' 匹配的资源。",
"no-resource-text": "找不到资源", "no-resource-text": "找不到资源",
"open-widgets-bundle": "打开部件库", "open-widgets-bundle": "打开部件库",