From b13840f6131e852ec0989498eac54cc89839af39 Mon Sep 17 00:00:00 2001 From: Chris Veilleux Date: Wed, 10 Feb 2021 12:56:57 -0600 Subject: [PATCH 1/6] Add check for pantacor ID on edit and add device screens --- .../device-edit-card.component.html | 14 +++++++++++--- .../device-edit-card/device-edit-card.component.ts | 1 + .../pages/device-edit/device-edit.component.html | 1 + .../pages/device-edit/device-edit.component.ts | 2 ++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.html b/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.html index f019592..42e6a32 100644 --- a/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.html +++ b/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.html @@ -37,9 +37,17 @@ - - - + + + + + diff --git a/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.ts b/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.ts index 5edb24b..70f838f 100644 --- a/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.ts +++ b/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.ts @@ -27,6 +27,7 @@ import { FormGroup } from '@angular/forms'; export class DeviceEditCardComponent implements OnInit { @Input() deviceForm: FormGroup; @Input() addDevice = false; + @Input() pantacorId: string; @Output() saveChanges = new EventEmitter(); constructor() { } diff --git a/projects/account/src/app/modules/device/pages/device-edit/device-edit.component.html b/projects/account/src/app/modules/device/pages/device-edit/device-edit.component.html index ecb068b..66e39d7 100644 --- a/projects/account/src/app/modules/device/pages/device-edit/device-edit.component.html +++ b/projects/account/src/app/modules/device/pages/device-edit/device-edit.component.html @@ -2,6 +2,7 @@ *ngIf="device$ | async" [deviceForm]="deviceForm" [addDevice]="false" + [pantacorId]="pantacorId" (saveChanges)="onExit($event)" > diff --git a/projects/account/src/app/modules/device/pages/device-edit/device-edit.component.ts b/projects/account/src/app/modules/device/pages/device-edit/device-edit.component.ts index eea4e21..bb4e59d 100644 --- a/projects/account/src/app/modules/device/pages/device-edit/device-edit.component.ts +++ b/projects/account/src/app/modules/device/pages/device-edit/device-edit.component.ts @@ -38,6 +38,7 @@ export class DeviceEditComponent implements OnInit { public deviceForm: FormGroup; private deviceId: string; public device$ = new Observable(); + public pantacorId: string; private snackbarConfig = new MatSnackBarConfig(); constructor( @@ -57,6 +58,7 @@ export class DeviceEditComponent implements OnInit { switchMap((params: ParamMap) => this.deviceService.getDevice(params.get('deviceId'))), tap((device) => { this.deviceId = device.id; + this.pantacorId = device.pantacorConfig.pantacorId; this.buildDeviceForm(device); }) ); From 92844a24be1d1ca0df57b7551c73a50ac818df2a Mon Sep 17 00:00:00 2001 From: Chris Veilleux Date: Tue, 16 Feb 2021 15:23:51 -0600 Subject: [PATCH 2/6] Change the labels of the data displayed for devices and added ability to apply an update from Pantacor manually --- .../src/app/core/http/device.service.ts | 5 +++ .../device-display.component.html | 17 +++++++- .../device-display.component.scss | 8 ++++ .../device-display.component.ts | 42 ++++++++++++++++++- .../device-list/device-list.component.html | 3 -- .../src/app/shared/models/device.model.ts | 1 + 6 files changed, 70 insertions(+), 6 deletions(-) diff --git a/projects/account/src/app/core/http/device.service.ts b/projects/account/src/app/core/http/device.service.ts index e16206e..f455ac3 100644 --- a/projects/account/src/app/core/http/device.service.ts +++ b/projects/account/src/app/core/http/device.service.ts @@ -31,6 +31,7 @@ const deviceUrl = '/api/devices'; const geographyUrl = 'api/geographies'; const pairingCodeUrl = '/api/pairing-code'; const preferencesUrl = '/api/preferences'; +const softwareUpdateUrl = '/api/software-update'; const voicesUrl = '/api/voices'; const wakeWordUrl = '/api/wake-words'; @@ -100,4 +101,8 @@ export class DeviceService { getWakeWords() { return this.http.get(wakeWordUrl); } + + applySoftwareUpdate(pantacorUpdateId: string) { + return this.http.patch(softwareUpdateUrl, {deploymentId: pantacorUpdateId}); + } } diff --git a/projects/account/src/app/modules/device/components/card/device-display/device-display.component.html b/projects/account/src/app/modules/device/components/card/device-display/device-display.component.html index acf8919..8ff214b 100644 --- a/projects/account/src/app/modules/device/components/card/device-display/device-display.component.html +++ b/projects/account/src/app/modules/device/components/card/device-display/device-display.component.html @@ -11,13 +11,18 @@ [value]="getPlatform(device)" > - + + @@ -26,6 +31,14 @@ [value]="device.pantacorConfig.ipAddress" > + diff --git a/projects/account/src/app/modules/device/components/card/device-display/device-display.component.scss b/projects/account/src/app/modules/device/components/card/device-display/device-display.component.scss index ab78c9d..88d8070 100644 --- a/projects/account/src/app/modules/device/components/card/device-display/device-display.component.scss +++ b/projects/account/src/app/modules/device/components/card/device-display/device-display.component.scss @@ -1,6 +1,14 @@ +@import "~@angular/material/theming"; +@import 'mycroft-colors'; +@import 'components/buttons'; + mat-tab-group { mat-card-content { margin-top: 32px; height: 180px; + button { + @include action-button-primary; + background-color: mat-color($mycroft-accent, 'A100'); + } } } diff --git a/projects/account/src/app/modules/device/components/card/device-display/device-display.component.ts b/projects/account/src/app/modules/device/components/card/device-display/device-display.component.ts index 4bfc52c..f38beab 100644 --- a/projects/account/src/app/modules/device/components/card/device-display/device-display.component.ts +++ b/projects/account/src/app/modules/device/components/card/device-display/device-display.component.ts @@ -17,10 +17,13 @@ and limitations under the License. ***************************************************************************** */ import { Component, Input, OnInit } from '@angular/core'; +import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; import { faInfoCircle, faCog, faMapMarkerAlt } from '@fortawesome/free-solid-svg-icons'; import { Device } from '@account/models/device.model'; +import { DeviceService } from '@account/http/device.service'; +import { SnackbarComponent } from 'shared'; @Component({ selector: 'account-device-info', @@ -38,10 +41,22 @@ export class DeviceDisplayComponent implements OnInit { public infoIcon = faInfoCircle; public configIcon = faCog; public locationIcon = faMapMarkerAlt; + public softwareUpdateText: string; + public softwareUpdateDisabled: boolean; - constructor() { } + constructor( + private deviceService: DeviceService, + private snackbar: MatSnackBar + ) { } ngOnInit() { + if (!this.device.pantacorUpdateId) { + this.softwareUpdateText = 'NO UPDATES AVAILABLE'; + this.softwareUpdateDisabled = true; + } else { + this.softwareUpdateText = 'APPLY SOFTWARE UPDATE'; + this.softwareUpdateDisabled = false; + } } getPlatform(device: Device) { @@ -49,4 +64,29 @@ export class DeviceDisplayComponent implements OnInit { return knownPlatform ? knownPlatform.displayName : device.platform; } + openErrorSnackbar() { + const config = new MatSnackBarConfig(); + config.data = {type: 'error', message: 'An error occurred, device will not be updated.'}; + this.snackbar.openFromComponent(SnackbarComponent, config); + } + + openSuccessSnackbar() { + const config = new MatSnackBarConfig(); + config.duration = 3000; + config.data = {type: 'success', message: 'The update will be applied to your device momentarily'}; + this.snackbar.openFromComponent(SnackbarComponent, config); + } + + applySoftwareUpdate() { + this.deviceService.applySoftwareUpdate(this.device.pantacorUpdateId).subscribe( + () => { + this.openSuccessSnackbar(); + this.softwareUpdateText = 'NO UPDATES AVAILABLE'; + this.softwareUpdateDisabled = true; + + }, + () => { this.openErrorSnackbar(); } + ); + } + } diff --git a/projects/account/src/app/modules/device/pages/device-list/device-list.component.html b/projects/account/src/app/modules/device/pages/device-list/device-list.component.html index b820c0d..4366dc8 100644 --- a/projects/account/src/app/modules/device/pages/device-list/device-list.component.html +++ b/projects/account/src/app/modules/device/pages/device-list/device-list.component.html @@ -49,9 +49,6 @@ - diff --git a/projects/account/src/app/shared/models/device.model.ts b/projects/account/src/app/shared/models/device.model.ts index 08aad8a..9783033 100644 --- a/projects/account/src/app/shared/models/device.model.ts +++ b/projects/account/src/app/shared/models/device.model.ts @@ -40,4 +40,5 @@ export interface Device { voice: Voice; wakeWord: WakeWord; pantacorConfig: PantacorConfig; + pantacorUpdateId: string; } From a8b394323728072191b868c8792b4234e81d7eef Mon Sep 17 00:00:00 2001 From: Chris Veilleux Date: Wed, 17 Feb 2021 16:02:59 -0600 Subject: [PATCH 3/6] Fixed an issue where the apply update button was showing when it shouldn't on devices without a Pantacor config. --- .../card/device-display/device-display.component.html | 2 +- projects/account/src/app/shared/models/pantacorConfig.model.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/account/src/app/modules/device/components/card/device-display/device-display.component.html b/projects/account/src/app/modules/device/components/card/device-display/device-display.component.html index 8ff214b..b3ef95a 100644 --- a/projects/account/src/app/modules/device/components/card/device-display/device-display.component.html +++ b/projects/account/src/app/modules/device/components/card/device-display/device-display.component.html @@ -33,7 +33,7 @@