UI: Refactoring

This commit is contained in:
Vladyslav_Prykhodko 2021-06-07 10:49:04 +03:00
parent cf899b6ffd
commit b67d9930d3
6 changed files with 32 additions and 24 deletions

View File

@ -36,8 +36,6 @@ import { PageLink } from '@shared/models/page/page-link';
import { OtaUpdateComponent } from '@home/pages/ota-update/ota-update.component'; import { OtaUpdateComponent } from '@home/pages/ota-update/ota-update.component';
import { EntityAction } from '@home/models/entity/entity-component.models'; import { EntityAction } from '@home/models/entity/entity-component.models';
import { FileSizePipe } from '@shared/pipe/file-size.pipe'; import { FileSizePipe } from '@shared/pipe/file-size.pipe';
import { ClipboardService } from 'ngx-clipboard';
import { ActionNotificationShow } from '@core/notification/notification.actions';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
@ -51,8 +49,7 @@ export class OtaUpdateTableConfigResolve implements Resolve<EntityTableConfig<Ot
private datePipe: DatePipe, private datePipe: DatePipe,
private store: Store<AppState>, private store: Store<AppState>,
private otaPackageService: OtaPackageService, private otaPackageService: OtaPackageService,
private fileSize: FileSizePipe, private fileSize: FileSizePipe) {
private clipboardService: ClipboardService) {
this.config.entityType = EntityType.OTA_PACKAGE; this.config.entityType = EntityType.OTA_PACKAGE;
this.config.entityComponent = OtaUpdateComponent; this.config.entityComponent = OtaUpdateComponent;
this.config.entityTranslations = entityTypeTranslations.get(EntityType.OTA_PACKAGE); this.config.entityTranslations = entityTypeTranslations.get(EntityType.OTA_PACKAGE);
@ -67,11 +64,11 @@ export class OtaUpdateTableConfigResolve implements Resolve<EntityTableConfig<Ot
new EntityTableColumn<OtaPackageInfo>('type', 'ota-update.package-type', '20%', entity => { new EntityTableColumn<OtaPackageInfo>('type', 'ota-update.package-type', '20%', entity => {
return this.translate.instant(OtaUpdateTypeTranslationMap.get(entity.type)); return this.translate.instant(OtaUpdateTypeTranslationMap.get(entity.type));
}), }),
new EntityTableColumn<OtaPackageInfo>('url', 'ota-update.url', '20%', entity => { new EntityTableColumn<OtaPackageInfo>('url', 'ota-update.direct-url', '20%', entity => {
return entity.url && entity.url.length > 20 ? `${entity.url.slice(0, 20)}` : ''; return entity.url && entity.url.length > 20 ? `${entity.url.slice(0, 20)}` : '';
}, () => ({}), true, () => ({}), () => undefined, false, }, () => ({}), true, () => ({}), () => undefined, false,
{ {
name: this.translate.instant('ota-update.copy-checksum'), name: this.translate.instant('ota-update.copy-direct-url'),
icon: 'content_paste', icon: 'content_paste',
style: { style: {
'font-size': '16px', 'font-size': '16px',

View File

@ -41,10 +41,18 @@
ngxClipboard ngxClipboard
(cbOnSuccess)="onPackageChecksumCopied()" (cbOnSuccess)="onPackageChecksumCopied()"
[cbContent]="entity?.checksum" [cbContent]="entity?.checksum"
[fxShow]="!isEdit"> [fxShow]="!isEdit && entity?.checksum">
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
<span translate>ota-update.copy-checksum</span> <span translate>ota-update.copy-checksum</span>
</button> </button>
<button mat-raised-button
ngxClipboard
(cbOnSuccess)="onPackageDirectUrlCopied()"
[cbContent]="entity?.url"
[fxShow]="!isEdit && entity?.url">
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
<span translate>ota-update.copy-direct-url</span>
</button>
</div> </div>
</div> </div>
<div class="mat-padding" fxLayout="column" fxLayoutGap="8px"> <div class="mat-padding" fxLayout="column" fxLayoutGap="8px">
@ -137,12 +145,12 @@
</section> </section>
<section *ngIf="entityForm.get('resource').value === 'url'" style="margin-top: 8px"> <section *ngIf="entityForm.get('resource').value === 'url'" style="margin-top: 8px">
<mat-form-field class="mat-block"> <mat-form-field class="mat-block">
<mat-label translate>ota-update.url</mat-label> <mat-label translate>ota-update.direct-url</mat-label>
<input matInput formControlName="url" <input matInput formControlName="url"
type="text" type="text"
[required]="entityForm.get('resource').value === 'url'"> [required]="entityForm.get('resource').value === 'url'">
<mat-error *ngIf="entityForm.get('url').hasError('required')" translate> <mat-error *ngIf="entityForm.get('url').hasError('required')" translate>
ota-update.url-required ota-update.direct-url-required
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
</section> </section>

View File

@ -160,6 +160,17 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
})); }));
} }
onPackageDirectUrlCopied() {
this.store.dispatch(new ActionNotificationShow(
{
message: this.translate.instant('ota-update.checksum-copied-message'),
type: 'success',
duration: 750,
verticalPosition: 'bottom',
horizontalPosition: 'right'
}));
}
prepareFormValue(formValue: any): any { prepareFormValue(formValue: any): any {
delete formValue.resource; delete formValue.resource;
delete formValue.generateChecksum; delete formValue.generateChecksum;

View File

@ -16,12 +16,9 @@
--> -->
<button mat-icon-button <button mat-icon-button
#tooltip
[disabled]="disabled" [disabled]="disabled"
[matTooltip]="matTooltipText" [matTooltip]="matTooltipText"
[matTooltipPosition]="matTooltipPosition" [matTooltipPosition]="matTooltipPosition"
(mouseenter)="immediatePropagation($event)"
(mouseleave)="immediatePropagation($event)"
(click)="copy($event)"> (click)="copy($event)">
<mat-icon [svgIcon]="mdiIconSymbol" [ngStyle]="style" [ngClass]="{'copied': copied}"> <mat-icon [svgIcon]="mdiIconSymbol" [ngStyle]="style" [ngClass]="{'copied': copied}">
{{ iconSymbol }} {{ iconSymbol }}

View File

@ -14,9 +14,9 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
import { ClipboardService } from 'ngx-clipboard'; import { ClipboardService } from 'ngx-clipboard';
import { MatTooltip, TooltipPosition } from '@angular/material/tooltip'; import { TooltipPosition } from '@angular/material/tooltip';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@Component({ @Component({
@ -53,15 +53,13 @@ export class CopyButtonComponent {
style: {[key: string]: any} = {}; style: {[key: string]: any} = {};
@Output() @Output()
successCopied: EventEmitter<string>; successCopied = new EventEmitter<string>();
constructor(private clipboardService: ClipboardService, constructor(private clipboardService: ClipboardService,
private translate: TranslateService, private translate: TranslateService,
private cd: ChangeDetectorRef) { private cd: ChangeDetectorRef) {
} }
@ViewChild('tooltip', {static: true}) tooltip: MatTooltip;
copy($event: Event): void { copy($event: Event): void {
$event.stopPropagation(); $event.stopPropagation();
if (this.timer) { if (this.timer) {
@ -71,11 +69,9 @@ export class CopyButtonComponent {
this.successCopied.emit(this.copyText); this.successCopied.emit(this.copyText);
this.copedIcon = 'done'; this.copedIcon = 'done';
this.copied = true; this.copied = true;
this.tooltip.show();
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
this.copedIcon = null; this.copedIcon = null;
this.copied = false; this.copied = false;
this.tooltip.hide();
this.cd.detectChanges(); this.cd.detectChanges();
}, 1500); }, 1500);
} }
@ -96,7 +92,4 @@ export class CopyButtonComponent {
return this.copied ? 'below' : this.tooltipPosition; return this.copied ? 'below' : this.tooltipPosition;
} }
immediatePropagation($event: Event): void {
this.copied ? $event.stopImmediatePropagation(): '';
}
} }

View File

@ -2165,6 +2165,7 @@
"chose-software-distributed-device": "Choose software that will be distributed to the devices", "chose-software-distributed-device": "Choose software that will be distributed to the devices",
"content-type": "Content type", "content-type": "Content type",
"copy-checksum": "Copy checksum", "copy-checksum": "Copy checksum",
"copy-direct-url": "Copy direct URL",
"copyId": "Copy package Id", "copyId": "Copy package Id",
"copied": "Copied!", "copied": "Copied!",
"delete": "Delete package", "delete": "Delete package",
@ -2173,6 +2174,9 @@
"delete-ota-updates-text": "Be careful, after the confirmation all selected OTA updates will be removed.", "delete-ota-updates-text": "Be careful, after the confirmation all selected OTA updates will be removed.",
"delete-ota-updates-title": "Are you sure you want to delete { count, plural, 1 {1 OTA update} other {# OTA updates} }?", "delete-ota-updates-title": "Are you sure you want to delete { count, plural, 1 {1 OTA update} other {# OTA updates} }?",
"description": "Description", "description": "Description",
"direct-url": "Direct URL",
"direct-url-copied-message": "Package direct URL has been copied to clipboard",
"direct-url-required": "Direct URL is required",
"download": "Download package", "download": "Download package",
"drop-file": "Drop a package file or click to select a file to upload.", "drop-file": "Drop a package file or click to select a file to upload.",
"file-name": "File name", "file-name": "File name",
@ -2197,8 +2201,6 @@
"firmware": "Firmware", "firmware": "Firmware",
"software": "Software" "software": "Software"
}, },
"url": "Direct URL",
"url-required": "Direct URL is required",
"version": "Version", "version": "Version",
"version-required": "Version is required.", "version-required": "Version is required.",
"warning-after-save-no-edit": "Once the package is uploaded, you will not be able to modify title, version, device profile and package type." "warning-after-save-no-edit": "Once the package is uploaded, you will not be able to modify title, version, device profile and package type."