Commit b67d9930d3da0580680ba29c03d49a7ba638a44b

Authored by Vladyslav_Prykhodko
1 parent cf899b6f

UI: Refactoring

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