Merge remote-tracking branch 'origin/dev' into test

pull/5/merge
Chris Veilleux 2022-03-15 09:57:47 -05:00
commit 5fcace39f6
7 changed files with 62 additions and 39 deletions

View File

@ -15,3 +15,27 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
import { HttpErrorResponse } from '@angular/common/http';
import { environment } from '@account/environments/environment';
import { throwError } from 'rxjs';
export function handleError(error: HttpErrorResponse) {
if (error.status === 401) {
console.log(error);
window.location.href = environment.mycroftUrls.singleSignOn + '/login?redirect=' + window.location.href;
} else if (error.error instanceof ErrorEvent) {
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred:', error.error.message);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong,
console.error(
`Backend returned code ${error.status}, ` +
`body was: ${error.error}`);
}
return throwError(
'Something bad happened; please try again later.');
}

View File

@ -18,13 +18,15 @@ and limitations under the License.
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { AccountDefaults } from '@account/models/defaults.model';
import { AccountPreferences } from '@account/models/preferences.model';
import { Device } from '@account/models/device.model';
import { DeviceAttribute } from '@account/models/deviceAttribute.model';
import { FormGroup } from '@angular/forms';
import { AccountDefaults } from '@account/models/defaults.model';
import { Observable } from 'rxjs';
import { handleError } from '@account/app/app.service';
const defaultsUrl = '/api/defaults';
const deviceUrl = '/api/devices';
@ -44,7 +46,9 @@ export class DeviceService {
}
getDevices(): Observable<Device[]> {
return this.http.get<Device[]>(deviceUrl);
return this.http.get<Device[]>(deviceUrl).pipe(
catchError(handleError)
);
}
getDevice(deviceId: string): Observable<Device> {
@ -68,7 +72,9 @@ export class DeviceService {
}
getAccountPreferences() {
return this.http.get<AccountPreferences>(preferencesUrl);
return this.http.get<AccountPreferences>(preferencesUrl).pipe(
catchError(handleError)
);
}
updateAccountPreferences(preferencesForm: FormGroup): Observable<any> {
@ -84,7 +90,9 @@ export class DeviceService {
}
getAccountDefaults() {
return this.http.get<AccountDefaults>(defaultsUrl);
return this.http.get<AccountDefaults>(defaultsUrl).pipe(
catchError(handleError)
);
}
validatePairingCode(pairingCode: string): Observable<any> {

View File

@ -16,15 +16,16 @@ See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, throwError } from 'rxjs';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { Account } from '@account/models/account.model';
import { environment } from '../../../environments/environment';
import { MembershipType } from '@account/models/membership.model';
import { handleError } from '@account/app/app.service';
// URLs for the http requests
@ -57,32 +58,12 @@ export class ProfileService {
constructor(private http: HttpClient) {
}
handleError(error: HttpErrorResponse) {
if (error.status === 401) {
console.log(error);
window.location.href = environment.mycroftUrls.singleSignOn + '/login?redirect=' + window.location.href;
} else if (error.error instanceof ErrorEvent) {
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred:', error.error.message);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong,
console.error(
`Backend returned code ${error.status}, ` +
`body was: ${error.error}`);
}
return throwError(
'Something bad happened; please try again later.');
}
/**
* API call to retrieve account info to display.
*/
getAccount(): Observable<Account> {
return this.http.get<Account>(ACCOUNT_URL).pipe(
catchError(this.handleError)
catchError(handleError)
);
}
@ -92,7 +73,7 @@ export class ProfileService {
updateAccount(accountChanges: any) {
return this.http.patch(ACCOUNT_URL, accountChanges).pipe(
catchError(this.handleError)
catchError(handleError)
);
}

View File

@ -19,7 +19,9 @@ and limitations under the License.
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { handleError } from '@account/app/app.service';
import { SkillFamily } from '@account/models/skill_family.model';
import { SkillSettings } from '@account/models/skill-settings.model';
@ -44,7 +46,9 @@ export class SkillService {
}
getSkills(): Observable<SkillFamily[]> {
return this.http.get<SkillFamily[]>(accountSkillUrl);
return this.http.get<SkillFamily[]>(accountSkillUrl).pipe(
catchError(handleError)
);
}
getSkillSettings(skillFamilyName: string): Observable<SkillSettings[]> {

View File

@ -9,8 +9,10 @@
[required]="true"
>
</account-geography-card>
<account-voice-card [voiceForm]="defaultsForm"></account-voice-card>
<account-wake-word-card [wakeWordForm]="defaultsForm">x</account-wake-word-card>
<!-- Temporarily commented out for MVP. Only available wake word is "Hey Mycroft". -->
<!-- Only available voice is the Mimic 3 British Male voice. -->
<!-- <account-voice-card [voiceForm]="defaultsForm"></account-voice-card>-->
<!-- <account-wake-word-card [wakeWordForm]="defaultsForm">x</account-wake-word-card>-->
</mat-card-content>
<mat-card-actions *ngIf="!addingDevice" align="right">
<button mat-button (click)="onSave()" [disabled]="!defaultsForm.valid">SAVE</button>

View File

@ -26,11 +26,13 @@
[value]="device.coreVersion"
>
</account-display-field>
<account-display-field *ngIf="device.pantacorConfig.pantacorId"
[label]="'IP Address'"
[value]="device.pantacorConfig.ipAddress"
>
</account-display-field>
<!-- This is temporarily commented out because the IP address can change and not get -->
<!-- properly communicated to Selene. Add back to display when this is fixed. -->
<!-- <account-display-field *ngIf="device.pantacorConfig.pantacorId"-->
<!-- [label]="'IP Address'"-->
<!-- [value]="device.pantacorConfig.ipAddress"-->
<!-- >-->
<!-- </account-display-field>-->
<button
mat-flat-button
*ngIf="device.pantacorConfig.autoUpdate === false" (click)="applySoftwareUpdate()"

View File

@ -38,8 +38,10 @@
</mat-card>
<account-geography-card [geoForm]="deviceForm" [required]="true"></account-geography-card>
<account-voice-card [voiceForm]="deviceForm"></account-voice-card>
<account-wake-word-card [wakeWordForm]="deviceForm"></account-wake-word-card>
<!-- Temporarily commented out for MVP. Only available wake word is "Hey Mycroft". -->
<!-- Only available voice is the Mimic 3 British Male voice. -->
<!-- <account-voice-card [voiceForm]="deviceForm"></account-voice-card>-->
<!-- <account-wake-word-card [wakeWordForm]="deviceForm"></account-wake-word-card>-->
<account-software-release-card
*ngIf="pantacorId"
[softwareReleaseForm]="deviceForm"