diff --git a/data/main.js.gz b/data/main.js.gz index 04cefd5..714e198 100644 Binary files a/data/main.js.gz and b/data/main.js.gz differ diff --git a/src/angular/osww-frontend/package-lock.json b/src/angular/osww-frontend/package-lock.json index e63d64a..1bd4848 100644 --- a/src/angular/osww-frontend/package-lock.json +++ b/src/angular/osww-frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "osww-frontend", - "version": "0.1.0", + "version": "0.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "osww-frontend", - "version": "0.1.0", + "version": "0.2.0", "dependencies": { "@angular/animations": "^14.2.0", "@angular/cdk": "^13.0.0", diff --git a/src/angular/osww-frontend/package.json b/src/angular/osww-frontend/package.json index d23183e..6677753 100644 --- a/src/angular/osww-frontend/package.json +++ b/src/angular/osww-frontend/package.json @@ -1,6 +1,6 @@ { "name": "osww-frontend", - "version": "0.1.0", + "version": "0.2.0", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/src/angular/osww-frontend/src/app/api.service.ts b/src/angular/osww-frontend/src/app/api.service.ts index 2a0c0a2..929820f 100644 --- a/src/angular/osww-frontend/src/app/api.service.ts +++ b/src/angular/osww-frontend/src/app/api.service.ts @@ -1,6 +1,6 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; +import { environment } from '../environments/environment'; import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject'; @@ -41,40 +41,21 @@ export class ApiService { constructor(private http: HttpClient) { } - static getWindowHref(_window: typeof window): string { - if (_window.location.href.includes('192')) { - - // remove single trailing '/' from ip - const sanitizedHref = - _window.location.href.substring(_window.location.href.length - 1) === '/' ? - _window.location.href.substring(0, _window.location.href.length - 1) : - _window.location.href - - return sanitizedHref; - } - - return 'http://winderoo.local'; - } - - private constructURL(URL: string): string { - if (URL != this.DEFUALT_URL) { - return URL + "/api/"; - } - - return this.DEFUALT_URL + '/api/'; + static constructURL(): string { + return environment.apiUrl + "/api/"; } getShouldRefresh() { return this.shouldRefresh$.asObservable(); } - getStatus(URL: string) { - return this.http.get(this.constructURL(URL) + 'status'); + getStatus() { + return this.http.get(ApiService.constructURL() + 'status'); } - updatePowerState(URL: string, powerState: boolean) { + updatePowerState(powerState: boolean) { let powerStateToNum; - const baseURL = this.constructURL(URL); + const baseURL = ApiService.constructURL(); if (powerState) { powerStateToNum = 1; @@ -89,9 +70,9 @@ export class ApiService { return this.http.post(constructedURL, null, { observe:'response' }); } - updateTimerState(URL: string, timerState: boolean) { + updateTimerState(timerState: boolean) { let timerStateToNum; - const baseURL = this.constructURL(URL); + const baseURL = ApiService.constructURL(); console.log(timerState) if (timerState) { timerStateToNum = 1; @@ -106,8 +87,8 @@ export class ApiService { return this.http.post(constructedURL, null, { observe: 'response' }); } - updateState(URL: string, update: Update) { - const baseURL = this.constructURL(URL); + updateState(update: Update) { + const baseURL = ApiService.constructURL(); const constructedURL = baseURL + 'update?action=' + update.action + '&' @@ -119,7 +100,7 @@ export class ApiService { return this.http.post(constructedURL, null, { observe: 'response' }); } - resetDevice(URL: string) { - return this.http.get(this.constructURL(URL) + 'reset'); + resetDevice() { + return this.http.get(ApiService.constructURL() + 'reset'); } } diff --git a/src/angular/osww-frontend/src/app/header/header.component.html b/src/angular/osww-frontend/src/app/header/header.component.html index 1947ee3..7b1912c 100644 --- a/src/angular/osww-frontend/src/app/header/header.component.html +++ b/src/angular/osww-frontend/src/app/header/header.component.html @@ -28,7 +28,7 @@ - + diff --git a/src/angular/osww-frontend/src/app/header/header.component.ts b/src/angular/osww-frontend/src/app/header/header.component.ts index 25adb91..73e1989 100644 --- a/src/angular/osww-frontend/src/app/header/header.component.ts +++ b/src/angular/osww-frontend/src/app/header/header.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, ViewContainerRef } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { MatDialog, MatDialogRef } from '@angular/material/dialog'; import { ApiService } from '../api.service'; import { TranslateService, TranslateModule } from '@ngx-translate/core'; @@ -50,7 +50,7 @@ export class HeaderComponent implements OnInit { } updateWinderEnabledState($state: any) { - this.apiService.updatePowerState(ApiService.getWindowHref(window), $state).subscribe( + this.apiService.updatePowerState($state).subscribe( (data) => { this.apiService.isWinderEnabled$.next($state); @@ -78,7 +78,7 @@ export class ResetDialog { public translateService: TranslateService) {} confirmReset(): void { - this.apiService.resetDevice(ApiService.getWindowHref(window)).subscribe(); + this.apiService.resetDevice().subscribe(); } closeDialog(): void { diff --git a/src/angular/osww-frontend/src/app/settings/settings.component.ts b/src/angular/osww-frontend/src/app/settings/settings.component.ts index 8591d1a..73fef1b 100644 --- a/src/angular/osww-frontend/src/app/settings/settings.component.ts +++ b/src/angular/osww-frontend/src/app/settings/settings.component.ts @@ -107,7 +107,7 @@ export class SettingsComponent implements OnInit, AfterViewChecked { } getData(): void { - this.apiService.getStatus(ApiService.getWindowHref(window)).subscribe((data) => { + this.apiService.getStatus().subscribe((data) => { this.upload.activityState = data.status; this.upload.rpd = data.rotationsPerDay; this.upload.direction = data.direction; @@ -213,7 +213,7 @@ export class SettingsComponent implements OnInit, AfterViewChecked { timerEnabled: this.upload.isTimerEnabledNum, } - this.apiService.updateState(ApiService.getWindowHref(window), body).subscribe((response) => { + this.apiService.updateState(body).subscribe((response) => { if (response.status == 204) { this.getData(); } @@ -273,7 +273,7 @@ export class SettingsComponent implements OnInit, AfterViewChecked { updateTimerEnabledState($state: any) { this.upload.isTimerEnabledNum = $state; - this.apiService.updateTimerState(ApiService.getWindowHref(window), $state).subscribe( + this.apiService.updateTimerState($state).subscribe( (data) => { this.mapTimerEnabledState($state) }); diff --git a/src/angular/osww-frontend/src/environments/environment.prod.ts b/src/angular/osww-frontend/src/environments/environment.prod.ts index 3612073..28132ba 100644 --- a/src/angular/osww-frontend/src/environments/environment.prod.ts +++ b/src/angular/osww-frontend/src/environments/environment.prod.ts @@ -1,3 +1,4 @@ export const environment = { - production: true + production: true, + apiUrl: 'http://winderoo.local', }; diff --git a/src/angular/osww-frontend/src/environments/environment.ts b/src/angular/osww-frontend/src/environments/environment.ts index f56ff47..e207ff5 100644 --- a/src/angular/osww-frontend/src/environments/environment.ts +++ b/src/angular/osww-frontend/src/environments/environment.ts @@ -3,7 +3,8 @@ // The list of file replacements can be found in `angular.json`. export const environment = { - production: false + production: false, + apiUrl: 'http://winderoo.local', }; /*