Add server connection check to the front app.

This commit is contained in:
2018-09-30 12:44:05 +02:00
parent ba2c76ff06
commit e40caf2b86
7 changed files with 57 additions and 8 deletions

View File

@@ -0,0 +1,19 @@
package org.minager.info;
import org.minager.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api")
public class InfoController {
@Value("${minager.version}")
private String version;
@GetMapping("/version")
public String getVersion() {
return StringUtils.concat("\"", version, "\"");
}
}

View File

@@ -11,5 +11,6 @@ spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
# *********************************************** # ***********************************************
# Application custom parameters # Application custom parameters
# *********************************************** # ***********************************************
minager.version=0.0.1
minecraft.server.path=/home/minecraft/server minecraft.server.path=/home/minecraft/server
minecraft.server.shell.name=minecraft-server.sh minecraft.server.shell.name=minecraft-server.sh

View File

@@ -20,7 +20,6 @@
"@angular/platform-browser": "^6.1.0", "@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0", "@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0", "@angular/router": "^6.1.0",
"@ngtools/webpack": "^1.2.4",
"@types/chart.js": "^2.7.36", "@types/chart.js": "^2.7.36",
"angular-bootstrap-md": "^6.2.4", "angular-bootstrap-md": "^6.2.4",
"angular5-csv": "^0.2.10", "angular5-csv": "^0.2.10",

View File

@@ -1,6 +1,13 @@
<app-header></app-header> <app-header></app-header>
<main class="container"> <main class="container" *ngIf="!loading && connectedToApi">
<router-outlet></router-outlet> <router-outlet></router-outlet>
</main> </main>
<main class="container" *ngIf="!loading && !connectedToApi">
<h3>Vous n'êtes pas connecté au serveur.</h3>
Veuillez contacter votre administrateur ou réessayer plus tard.
</main>
<main class="container" *ngIf="loading">
<h3>Chargement...</h3>
</main>
<!-- <app-footer></app-footer> --> <!-- <app-footer></app-footer> -->

View File

@@ -1,10 +1,29 @@
import { Component } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { environment } from '../environments/environment';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
templateUrl: './app.component.html', templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'] styleUrls: ['./app.component.scss']
}) })
export class AppComponent { export class AppComponent implements OnInit {
title = 'app'; title = 'app';
loading = true;
apiVersion;
connectedToApi = false;
constructor(
private http: HttpClient
) {}
ngOnInit(): void {
this.http.get(`${environment.apiUrl}/api/version`).subscribe(pApiVersion => {
this.apiVersion = pApiVersion;
this.connectedToApi = true;
this.loading = false;
}, error => {
this.loading = false;
});
}
} }

View File

@@ -12,20 +12,21 @@
<button mdbBtn <button mdbBtn
*ngIf="serverStarted" *ngIf="serverStarted"
type="button" type="button"
color="primary" class="waves-light indigo btn-rounded"
class="waves-light"
[disabled]="restarting" [disabled]="restarting"
(click)="restartServer()" (click)="restartServer()"
mdbWavesEffect> mdbWavesEffect>
<i class="fa fa-refresh"></i>&nbsp;
Redémarrer Redémarrer
</button> </button>
<button mdbBtn <button mdbBtn
type="button" type="button"
class="waves-light" class="waves-light btn-rounded"
[ngClass]="serverStarted ? 'btn-danger' : 'btn-success'" [ngClass]="serverStarted ? 'red' : 'green'"
[disabled]="restarting" [disabled]="restarting"
(click)="startOrStopServer()" (click)="startOrStopServer()"
mdbWavesEffect> mdbWavesEffect>
<i class="fa" [ngClass]="serverStarted ? 'fa-stop-circle' : 'fa-play-circle'"></i>&nbsp;
{{serverStarted ? 'Éteindre' : 'Démarrer'}} {{serverStarted ? 'Éteindre' : 'Démarrer'}}
</button> </button>
</div> </div>

View File

@@ -1 +1,4 @@
/* You can add global styles to this file, and also import other style files */ /* You can add global styles to this file, and also import other style files */
.btn-rounded {
border-radius: 10em;
}