Commit b67d9930d3da0580680ba29c03d49a7ba638a44b

Authored by Vladyslav_Prykhodko
1 parent cf899b6f

UI: Refactoring

@@ -36,8 +36,6 @@ import { PageLink } from '@shared/models/page/page-link'; @@ -36,8 +36,6 @@ import { PageLink } from '@shared/models/page/page-link';
36 import { OtaUpdateComponent } from '@home/pages/ota-update/ota-update.component'; 36 import { OtaUpdateComponent } from '@home/pages/ota-update/ota-update.component';
37 import { EntityAction } from '@home/models/entity/entity-component.models'; 37 import { EntityAction } from '@home/models/entity/entity-component.models';
38 import { FileSizePipe } from '@shared/pipe/file-size.pipe'; 38 import { FileSizePipe } from '@shared/pipe/file-size.pipe';
39 -import { ClipboardService } from 'ngx-clipboard';  
40 -import { ActionNotificationShow } from '@core/notification/notification.actions';  
41 import { Store } from '@ngrx/store'; 39 import { Store } from '@ngrx/store';
42 import { AppState } from '@core/core.state'; 40 import { AppState } from '@core/core.state';
43 41
@@ -51,8 +49,7 @@ export class OtaUpdateTableConfigResolve implements Resolve<EntityTableConfig<Ot @@ -51,8 +49,7 @@ export class OtaUpdateTableConfigResolve implements Resolve<EntityTableConfig<Ot
51 private datePipe: DatePipe, 49 private datePipe: DatePipe,
52 private store: Store<AppState>, 50 private store: Store<AppState>,
53 private otaPackageService: OtaPackageService, 51 private otaPackageService: OtaPackageService,
54 - private fileSize: FileSizePipe,  
55 - private clipboardService: ClipboardService) { 52 + private fileSize: FileSizePipe) {
56 this.config.entityType = EntityType.OTA_PACKAGE; 53 this.config.entityType = EntityType.OTA_PACKAGE;
57 this.config.entityComponent = OtaUpdateComponent; 54 this.config.entityComponent = OtaUpdateComponent;
58 this.config.entityTranslations = entityTypeTranslations.get(EntityType.OTA_PACKAGE); 55 this.config.entityTranslations = entityTypeTranslations.get(EntityType.OTA_PACKAGE);
@@ -67,11 +64,11 @@ export class OtaUpdateTableConfigResolve implements Resolve<EntityTableConfig<Ot @@ -67,11 +64,11 @@ export class OtaUpdateTableConfigResolve implements Resolve<EntityTableConfig<Ot
67 new EntityTableColumn<OtaPackageInfo>('type', 'ota-update.package-type', '20%', entity => { 64 new EntityTableColumn<OtaPackageInfo>('type', 'ota-update.package-type', '20%', entity => {
68 return this.translate.instant(OtaUpdateTypeTranslationMap.get(entity.type)); 65 return this.translate.instant(OtaUpdateTypeTranslationMap.get(entity.type));
69 }), 66 }),
70 - new EntityTableColumn<OtaPackageInfo>('url', 'ota-update.url', '20%', entity => { 67 + new EntityTableColumn<OtaPackageInfo>('url', 'ota-update.direct-url', '20%', entity => {
71 return entity.url && entity.url.length > 20 ? `${entity.url.slice(0, 20)}…` : ''; 68 return entity.url && entity.url.length > 20 ? `${entity.url.slice(0, 20)}…` : '';
72 }, () => ({}), true, () => ({}), () => undefined, false, 69 }, () => ({}), true, () => ({}), () => undefined, false,
73 { 70 {
74 - name: this.translate.instant('ota-update.copy-checksum'), 71 + name: this.translate.instant('ota-update.copy-direct-url'),
75 icon: 'content_paste', 72 icon: 'content_paste',
76 style: { 73 style: {
77 'font-size': '16px', 74 'font-size': '16px',
@@ -41,10 +41,18 @@ @@ -41,10 +41,18 @@
41 ngxClipboard 41 ngxClipboard
42 (cbOnSuccess)="onPackageChecksumCopied()" 42 (cbOnSuccess)="onPackageChecksumCopied()"
43 [cbContent]="entity?.checksum" 43 [cbContent]="entity?.checksum"
44 - [fxShow]="!isEdit"> 44 + [fxShow]="!isEdit && entity?.checksum">
45 <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> 45 <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
46 <span translate>ota-update.copy-checksum</span> 46 <span translate>ota-update.copy-checksum</span>
47 </button> 47 </button>
  48 + <button mat-raised-button
  49 + ngxClipboard
  50 + (cbOnSuccess)="onPackageDirectUrlCopied()"
  51 + [cbContent]="entity?.url"
  52 + [fxShow]="!isEdit && entity?.url">
  53 + <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
  54 + <span translate>ota-update.copy-direct-url</span>
  55 + </button>
48 </div> 56 </div>
49 </div> 57 </div>
50 <div class="mat-padding" fxLayout="column" fxLayoutGap="8px"> 58 <div class="mat-padding" fxLayout="column" fxLayoutGap="8px">
@@ -137,12 +145,12 @@ @@ -137,12 +145,12 @@
137 </section> 145 </section>
138 <section *ngIf="entityForm.get('resource').value === 'url'" style="margin-top: 8px"> 146 <section *ngIf="entityForm.get('resource').value === 'url'" style="margin-top: 8px">
139 <mat-form-field class="mat-block"> 147 <mat-form-field class="mat-block">
140 - <mat-label translate>ota-update.url</mat-label> 148 + <mat-label translate>ota-update.direct-url</mat-label>
141 <input matInput formControlName="url" 149 <input matInput formControlName="url"
142 type="text" 150 type="text"
143 [required]="entityForm.get('resource').value === 'url'"> 151 [required]="entityForm.get('resource').value === 'url'">
144 <mat-error *ngIf="entityForm.get('url').hasError('required')" translate> 152 <mat-error *ngIf="entityForm.get('url').hasError('required')" translate>
145 - ota-update.url-required 153 + ota-update.direct-url-required
146 </mat-error> 154 </mat-error>
147 </mat-form-field> 155 </mat-form-field>
148 </section> 156 </section>
@@ -160,6 +160,17 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O @@ -160,6 +160,17 @@ export class OtaUpdateComponent extends EntityComponent<OtaPackage> implements O
160 })); 160 }));
161 } 161 }
162 162
  163 + onPackageDirectUrlCopied() {
  164 + this.store.dispatch(new ActionNotificationShow(
  165 + {
  166 + message: this.translate.instant('ota-update.checksum-copied-message'),
  167 + type: 'success',
  168 + duration: 750,
  169 + verticalPosition: 'bottom',
  170 + horizontalPosition: 'right'
  171 + }));
  172 + }
  173 +
163 prepareFormValue(formValue: any): any { 174 prepareFormValue(formValue: any): any {
164 delete formValue.resource; 175 delete formValue.resource;
165 delete formValue.generateChecksum; 176 delete formValue.generateChecksum;
@@ -16,12 +16,9 @@ @@ -16,12 +16,9 @@
16 16
17 --> 17 -->
18 <button mat-icon-button 18 <button mat-icon-button
19 - #tooltip  
20 [disabled]="disabled" 19 [disabled]="disabled"
21 [matTooltip]="matTooltipText" 20 [matTooltip]="matTooltipText"
22 [matTooltipPosition]="matTooltipPosition" 21 [matTooltipPosition]="matTooltipPosition"
23 - (mouseenter)="immediatePropagation($event)"  
24 - (mouseleave)="immediatePropagation($event)"  
25 (click)="copy($event)"> 22 (click)="copy($event)">
26 <mat-icon [svgIcon]="mdiIconSymbol" [ngStyle]="style" [ngClass]="{'copied': copied}"> 23 <mat-icon [svgIcon]="mdiIconSymbol" [ngStyle]="style" [ngClass]="{'copied': copied}">
27 {{ iconSymbol }} 24 {{ iconSymbol }}
@@ -14,9 +14,9 @@ @@ -14,9 +14,9 @@
14 /// limitations under the License. 14 /// limitations under the License.
15 /// 15 ///
16 16
17 -import { ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; 17 +import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
18 import { ClipboardService } from 'ngx-clipboard'; 18 import { ClipboardService } from 'ngx-clipboard';
19 -import { MatTooltip, TooltipPosition } from '@angular/material/tooltip'; 19 +import { TooltipPosition } from '@angular/material/tooltip';
20 import { TranslateService } from '@ngx-translate/core'; 20 import { TranslateService } from '@ngx-translate/core';
21 21
22 @Component({ 22 @Component({
@@ -53,15 +53,13 @@ export class CopyButtonComponent { @@ -53,15 +53,13 @@ export class CopyButtonComponent {
53 style: {[key: string]: any} = {}; 53 style: {[key: string]: any} = {};
54 54
55 @Output() 55 @Output()
56 - successCopied: EventEmitter<string>; 56 + successCopied = new EventEmitter<string>();
57 57
58 constructor(private clipboardService: ClipboardService, 58 constructor(private clipboardService: ClipboardService,
59 private translate: TranslateService, 59 private translate: TranslateService,
60 private cd: ChangeDetectorRef) { 60 private cd: ChangeDetectorRef) {
61 } 61 }
62 62
63 - @ViewChild('tooltip', {static: true}) tooltip: MatTooltip;  
64 -  
65 copy($event: Event): void { 63 copy($event: Event): void {
66 $event.stopPropagation(); 64 $event.stopPropagation();
67 if (this.timer) { 65 if (this.timer) {
@@ -71,11 +69,9 @@ export class CopyButtonComponent { @@ -71,11 +69,9 @@ export class CopyButtonComponent {
71 this.successCopied.emit(this.copyText); 69 this.successCopied.emit(this.copyText);
72 this.copedIcon = 'done'; 70 this.copedIcon = 'done';
73 this.copied = true; 71 this.copied = true;
74 - this.tooltip.show();  
75 this.timer = setTimeout(() => { 72 this.timer = setTimeout(() => {
76 this.copedIcon = null; 73 this.copedIcon = null;
77 this.copied = false; 74 this.copied = false;
78 - this.tooltip.hide();  
79 this.cd.detectChanges(); 75 this.cd.detectChanges();
80 }, 1500); 76 }, 1500);
81 } 77 }
@@ -96,7 +92,4 @@ export class CopyButtonComponent { @@ -96,7 +92,4 @@ export class CopyButtonComponent {
96 return this.copied ? 'below' : this.tooltipPosition; 92 return this.copied ? 'below' : this.tooltipPosition;
97 } 93 }
98 94
99 - immediatePropagation($event: Event): void {  
100 - this.copied ? $event.stopImmediatePropagation(): '';  
101 - }  
102 } 95 }
@@ -2165,6 +2165,7 @@ @@ -2165,6 +2165,7 @@
2165 "chose-software-distributed-device": "Choose software that will be distributed to the devices", 2165 "chose-software-distributed-device": "Choose software that will be distributed to the devices",
2166 "content-type": "Content type", 2166 "content-type": "Content type",
2167 "copy-checksum": "Copy checksum", 2167 "copy-checksum": "Copy checksum",
  2168 + "copy-direct-url": "Copy direct URL",
2168 "copyId": "Copy package Id", 2169 "copyId": "Copy package Id",
2169 "copied": "Copied!", 2170 "copied": "Copied!",
2170 "delete": "Delete package", 2171 "delete": "Delete package",
@@ -2173,6 +2174,9 @@ @@ -2173,6 +2174,9 @@
2173 "delete-ota-updates-text": "Be careful, after the confirmation all selected OTA updates will be removed.", 2174 "delete-ota-updates-text": "Be careful, after the confirmation all selected OTA updates will be removed.",
2174 "delete-ota-updates-title": "Are you sure you want to delete { count, plural, 1 {1 OTA update} other {# OTA updates} }?", 2175 "delete-ota-updates-title": "Are you sure you want to delete { count, plural, 1 {1 OTA update} other {# OTA updates} }?",
2175 "description": "Description", 2176 "description": "Description",
  2177 + "direct-url": "Direct URL",
  2178 + "direct-url-copied-message": "Package direct URL has been copied to clipboard",
  2179 + "direct-url-required": "Direct URL is required",
2176 "download": "Download package", 2180 "download": "Download package",
2177 "drop-file": "Drop a package file or click to select a file to upload.", 2181 "drop-file": "Drop a package file or click to select a file to upload.",
2178 "file-name": "File name", 2182 "file-name": "File name",
@@ -2197,8 +2201,6 @@ @@ -2197,8 +2201,6 @@
2197 "firmware": "Firmware", 2201 "firmware": "Firmware",
2198 "software": "Software" 2202 "software": "Software"
2199 }, 2203 },
2200 - "url": "Direct URL",  
2201 - "url-required": "Direct URL is required",  
2202 "version": "Version", 2204 "version": "Version",
2203 "version-required": "Version is required.", 2205 "version-required": "Version is required.",
2204 "warning-after-save-no-edit": "Once the package is uploaded, you will not be able to modify title, version, device profile and package type." 2206 "warning-after-save-no-edit": "Once the package is uploaded, you will not be able to modify title, version, device profile and package type."