diff --git a/src/app/error-page/error-page.component.ts b/src/app/error-page/error-page.component.ts index c479d1a..8371bf0 100644 --- a/src/app/error-page/error-page.component.ts +++ b/src/app/error-page/error-page.component.ts @@ -1,5 +1,6 @@ import { Component } from '@angular/core'; import { Router } from '@angular/router'; +import { IrisinterfaceService } from '../services/irisinterface.service'; @Component({ selector: 'app-error-page', @@ -7,7 +8,34 @@ import { Router } from '@angular/router'; styleUrls: ['./error-page.component.scss'], }) export class ErrorPageComponent { - constructor(private router: Router) {} + isServerOnline = false; + + constructor( + private router: Router, + private apiService: IrisinterfaceService + ) {} + + ngOnInit(): void { + this.checkIfServerOnline(); + const interval = setInterval(() => { + this.checkIfServerOnline(); + if (this.isServerOnline && this.router.url == '/error') { + this.router.navigate(['/']); + clearInterval(interval); + } + }, 1000); + } + + checkIfServerOnline() { + this.apiService.isServerOnline().subscribe({ + next: (data: any) => { + this.isServerOnline = true; + }, + error: (err) => { + this.isServerOnline = false; + }, + }); + } goToServerSettings() { this.router.navigate(['/settings/server']); diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 0e9d57e..f0e564a 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -25,10 +25,11 @@ export class HomeComponent { ngOnInit(): void { this.chapterManager.init(); this.checkIfServerOnline(); - setInterval(() => { + const interval = setInterval(() => { this.checkIfServerOnline(); if (!this.isServerOnline && this.router.url == '/') { this.router.navigate(['/error']); + clearInterval(interval); } }, 5000); } diff --git a/src/app/services/irisinterface.service.ts b/src/app/services/irisinterface.service.ts index 0b3518e..76551bb 100644 --- a/src/app/services/irisinterface.service.ts +++ b/src/app/services/irisinterface.service.ts @@ -9,6 +9,7 @@ import { LocalStorageService } from './local-storage.service'; providedIn: 'root', }) export class IrisinterfaceService { + public static protocol: string = 'http'; public static host: string = 'localhost'; public static port: number = 52773; @@ -23,7 +24,8 @@ export class IrisinterfaceService { isServerOnline() { return this.http .get( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -38,7 +40,8 @@ export class IrisinterfaceService { getVersion(): Observable { return this.http.get( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -56,7 +59,8 @@ export class IrisinterfaceService { // make request and handle 404 status return this.http .get( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -78,7 +82,8 @@ export class IrisinterfaceService { getAllChapters(): Observable { return this.http.get( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -89,7 +94,8 @@ export class IrisinterfaceService { verifyChapter(chapterName: string, password: string): Observable { return this.http .get( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -116,7 +122,8 @@ export class IrisinterfaceService { ): Observable { return this.http .get( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -152,7 +159,8 @@ export class IrisinterfaceService { ): Observable { return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -181,7 +189,8 @@ export class IrisinterfaceService { ): Observable { return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -208,7 +217,8 @@ export class IrisinterfaceService { ): Observable { return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -238,7 +248,8 @@ export class IrisinterfaceService { ): Observable { return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -267,7 +278,8 @@ export class IrisinterfaceService { name = name.replace(/ /g, '_'); return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -292,7 +304,8 @@ export class IrisinterfaceService { name = name.replace(/ /g, '_'); return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -311,7 +324,8 @@ export class IrisinterfaceService { getFile(name: string) { return this.http .get( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -332,7 +346,8 @@ export class IrisinterfaceService { translateText(text: string, to: string): Observable { return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -351,7 +366,8 @@ export class IrisinterfaceService { getAllImageNames(): Observable { return this.http .get( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -371,7 +387,8 @@ export class IrisinterfaceService { getAllFileNames(): Observable { return this.http .get( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -396,7 +413,8 @@ export class IrisinterfaceService { ): Observable { return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -431,7 +449,8 @@ export class IrisinterfaceService { ): Observable { return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -465,7 +484,8 @@ export class IrisinterfaceService { ): Observable { return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -499,7 +519,8 @@ export class IrisinterfaceService { ): Observable { return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + @@ -535,7 +556,8 @@ export class IrisinterfaceService { ): Observable { return this.http .post( - 'http://' + + IrisinterfaceService.protocol + + '://' + IrisinterfaceService.host + ':' + IrisinterfaceService.port + diff --git a/src/app/services/local-storage.service.ts b/src/app/services/local-storage.service.ts index c2e0457..9baa2d8 100644 --- a/src/app/services/local-storage.service.ts +++ b/src/app/services/local-storage.service.ts @@ -136,6 +136,19 @@ export class LocalStorageService { IrisinterfaceService.port = serverPort; } + getServerProtocol(): string { + let protocol = localStorage.getItem('serverProtocol'); + if (protocol == null) { + return 'http'; + } + return protocol; + } + + setServerProtocol(protocol: string) { + LocalStorageService.setLS('serverProtocol', protocol); + IrisinterfaceService.protocol = protocol; + } + getUserName(): string | null { return localStorage.getItem('userName'); } @@ -190,14 +203,24 @@ export class LocalStorageService { return null; } - addServerConnection(name: string, host: string, port: number) { + addServerConnection( + name: string, + host: string, + port: number, + protocol: string + ) { let serverConnections = this.getAllServerConnections(); for (let i = 0; i < serverConnections.length; i++) { if (serverConnections[i].name == name) { serverConnections.splice(i, 1); } } - serverConnections.push({ name: name, host: host, port: port }); + serverConnections.push({ + name: name, + host: host, + port: port, + protocol: protocol, + }); LocalStorageService.setLS( 'serverConnections', JSON.stringify(serverConnections) diff --git a/src/app/settings/settings-pages/server-settings/server-settings.component.html b/src/app/settings/settings-pages/server-settings/server-settings.component.html index 92b1452..82fc534 100644 --- a/src/app/settings/settings-pages/server-settings/server-settings.component.html +++ b/src/app/settings/settings-pages/server-settings/server-settings.component.html @@ -22,6 +22,13 @@

Connection Name

+
+

Protocol

+ +

Host

diff --git a/src/app/settings/settings-pages/server-settings/server-settings.component.ts b/src/app/settings/settings-pages/server-settings/server-settings.component.ts index a7a512c..c5a6c1c 100644 --- a/src/app/settings/settings-pages/server-settings/server-settings.component.ts +++ b/src/app/settings/settings-pages/server-settings/server-settings.component.ts @@ -11,6 +11,7 @@ import { NotificationComponent } from 'src/app/notification/notification.compone }) export class ServerSettingsComponent { connection: string = ''; + protocol: string = ''; name: string = ''; host: string = ''; port: number = 0; @@ -21,11 +22,13 @@ export class ServerSettingsComponent { ) { this.host = localStorageService.getServerHost(); this.port = localStorageService.getServerPort(); + this.protocol = localStorageService.getServerProtocol(); } connect() { this.localStorageService.setServerHost(this.host); this.localStorageService.setServerPort(this.port); + this.localStorageService.setServerProtocol(this.protocol); this.router.navigate(['/']); } @@ -49,7 +52,8 @@ export class ServerSettingsComponent { this.localStorageService.addServerConnection( this.name, this.host, - this.port + this.port, + this.protocol ); NotificationComponent.showNotification('Success', 'Connection saved!'); } @@ -59,6 +63,7 @@ export class ServerSettingsComponent { this.name = ''; this.host = this.localStorageService.getServerHost(); this.port = this.localStorageService.getServerPort(); + this.protocol = this.localStorageService.getServerProtocol(); return; } const con = this.localStorageService.getConnection(this.connection); @@ -66,6 +71,7 @@ export class ServerSettingsComponent { this.name = con.name; this.host = con.host; this.port = con.port; + this.protocol = con.protocol; } } @@ -75,12 +81,19 @@ export class ServerSettingsComponent { isCurrentConnection(): boolean { return ( - this.localStorageService.getServerHost() === this.host && - this.localStorageService.getServerPort() === this.port + IrisinterfaceService.host === this.host && + IrisinterfaceService.port === this.port && + IrisinterfaceService.protocol === this.protocol ); } getCurrentConnection(): string { - return IrisinterfaceService.host + ':' + IrisinterfaceService.port; + return ( + IrisinterfaceService.protocol + + '://' + + IrisinterfaceService.host + + ':' + + IrisinterfaceService.port + ); } }