diff --git a/angular.json b/angular.json index f5cceaf..035e55d 100644 --- a/angular.json +++ b/angular.json @@ -47,13 +47,7 @@ "maximumError": "8kB" } ], - "outputHashing": "all", - "fileReplacements": [ - { - "replace": "src/environments/environment.ts", - "with": "src/environments/environment.prod.ts" - } - ] + "outputHashing": "all" }, "development": { "optimization": false, diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 32f15d7..0fc0674 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -4,6 +4,7 @@ import { AuthGuard } from './auth.guard'; import { Login } from './login/login'; export const routes: Routes = [ - { path: "home", component: Home, canActivate: [AuthGuard] }, - { path: "login", component: Login } + { path: "home", component: Home, canActivate: [AuthGuard], title: "MCSC | Home" }, + { path: "login", component: Login, title: "MCSC | Login" }, + { path: "**", redirectTo: "home"}, ]; diff --git a/src/app/app.ts b/src/app/app.ts index 525e654..9bcfdc3 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -1,8 +1,5 @@ -import { Component, signal, OnInit } from '@angular/core'; +import { Component, signal } from '@angular/core'; import { RouterOutlet } from '@angular/router'; -import { environment } from '../environments/environment'; - -const { API_URL } = environment; @Component({ selector: 'app-root', @@ -10,10 +7,6 @@ const { API_URL } = environment; templateUrl: './app.html', styleUrl: './app.scss', }) -export class App implements OnInit { - protected readonly title = signal('mc-server-starter-frontend'); - - ngOnInit() { - console.log(API_URL); - } +export class App { + protected readonly title = signal('MC Server Control'); } diff --git a/src/app/auth.service.ts b/src/app/auth.service.ts index 27d5e0e..e4f5902 100644 --- a/src/app/auth.service.ts +++ b/src/app/auth.service.ts @@ -1,9 +1,6 @@ import { inject, Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Router } from '@angular/router'; -import { environment } from '../environments/environment'; - -const { API_URL } = environment; @Injectable({ providedIn: 'root' }) export class AuthService { @@ -12,8 +9,8 @@ export class AuthService { private http: HttpClient = inject(HttpClient) private router: Router = inject(Router) - login(username: string, password: string) { - return this.http.post<{ token: string }>(`${API_URL}/login`, { username, password }); + login(username: string, password: string, url: string) { + return this.http.post<{ token: string }>(`${url}/login`, { username, password }); } saveToken(token: string) { @@ -25,7 +22,7 @@ export class AuthService { } isLoggedIn(): boolean { - return !!this.getToken(); + return !!this.getToken() && !!localStorage.getItem("serverIp"); } logout() { diff --git a/src/app/home/home.html b/src/app/home/home.html index ef90d35..a4ec335 100644 --- a/src/app/home/home.html +++ b/src/app/home/home.html @@ -1,23 +1,34 @@
- @if (running !== null) { -
- Server is {{ running ? 'RUNNING' : 'STOPPED' }} -
- } @else { -
- Status UNKNOWN -
- } - - @if (loading) { - - } @else if (running !== null) { - - } + + + + {{ serverIp }} + + + +
+ @if (running !== null) { +

+ Server is {{ running ? "RUNNING" : "STOPPED" }} +

+ } @else { +

Status UNKNOWN

+ } @if (loading) { +
+ + +
+ } + +
+
+
diff --git a/src/app/home/home.scss b/src/app/home/home.scss index f807638..9a1af3a 100644 --- a/src/app/home/home.scss +++ b/src/app/home/home.scss @@ -22,3 +22,26 @@ .unknown { color: #9e9e9e; /* Grey */ } + +.control-content { + display: flex; + flex-direction: column; + align-items: center; +} + +.control-button { + height: 4em; +} + +.overlay { + position: fixed; + top: 0; + left: 0; + width: 100vw; + height: 100vh; + background: rgba(0, 0, 0, 0.5); // dim effect + display: flex; + justify-content: center; + align-items: center; + z-index: 1000; // ensure it’s above everything else +} diff --git a/src/app/home/home.ts b/src/app/home/home.ts index 260341c..e20ff92 100644 --- a/src/app/home/home.ts +++ b/src/app/home/home.ts @@ -22,6 +22,7 @@ import { ServerService } from '../server.service'; export class Home implements OnInit { running: boolean | null = null; loading = false; + serverIp = localStorage.getItem("serverIp") private serverService: ServerService = inject(ServerService) diff --git a/src/app/login/login.html b/src/app/login/login.html index 1eb33de..c06da04 100644 --- a/src/app/login/login.html +++ b/src/app/login/login.html @@ -2,6 +2,11 @@

Login

+ + Server-IP + + + Username diff --git a/src/app/login/login.ts b/src/app/login/login.ts index 0068f72..d79c495 100644 --- a/src/app/login/login.ts +++ b/src/app/login/login.ts @@ -27,6 +27,7 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; export class Login { username = ''; password = ''; + serverIp = ''; errorMessage = ''; loading = false; @@ -37,11 +38,12 @@ export class Login { this.errorMessage = ''; this.loading = true; - this.authService.login(this.username, this.password).subscribe({ + this.authService.login(this.username, this.password, this.serverIp).subscribe({ next: (res) => { this.authService.saveToken(res.token) this.loading = false; this.router.navigateByUrl('/home'); + localStorage.setItem("serverIp", this.serverIp) }, error: (err) => { this.loading = false; diff --git a/src/app/server.service.ts b/src/app/server.service.ts index f40be26..6ff223b 100644 --- a/src/app/server.service.ts +++ b/src/app/server.service.ts @@ -1,9 +1,8 @@ import { inject, Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { AuthService } from './auth.service'; -import { environment } from '../environments/environment'; -const { API_URL } = environment; +const API_URL = localStorage.getItem("serverIp"); @Injectable({ providedIn: 'root' }) export class ServerService { diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts deleted file mode 100644 index fa00297..0000000 --- a/src/environments/environment.prod.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const environment = { - API_URL: "https://178.38.172.39", -}; diff --git a/src/environments/environment.ts b/src/environments/environment.ts deleted file mode 100644 index 9fa706a..0000000 --- a/src/environments/environment.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const environment = { - API_URL: "http://localhost:3000" -};