Add server connection check to the front app.
This commit is contained in:
19
src/main/java/org/minager/info/InfoController.java
Normal file
19
src/main/java/org/minager/info/InfoController.java
Normal 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, "\"");
|
||||
}
|
||||
}
|
||||
@@ -11,5 +11,6 @@ spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
|
||||
# ***********************************************
|
||||
# Application custom parameters
|
||||
# ***********************************************
|
||||
minager.version=0.0.1
|
||||
minecraft.server.path=/home/minecraft/server
|
||||
minecraft.server.shell.name=minecraft-server.sh
|
||||
@@ -20,7 +20,6 @@
|
||||
"@angular/platform-browser": "^6.1.0",
|
||||
"@angular/platform-browser-dynamic": "^6.1.0",
|
||||
"@angular/router": "^6.1.0",
|
||||
"@ngtools/webpack": "^1.2.4",
|
||||
"@types/chart.js": "^2.7.36",
|
||||
"angular-bootstrap-md": "^6.2.4",
|
||||
"angular5-csv": "^0.2.10",
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
<app-header></app-header>
|
||||
<main class="container">
|
||||
<main class="container" *ngIf="!loading && connectedToApi">
|
||||
<router-outlet></router-outlet>
|
||||
</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> -->
|
||||
|
||||
|
||||
@@ -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({
|
||||
selector: 'app-root',
|
||||
templateUrl: './app.component.html',
|
||||
styleUrls: ['./app.component.scss']
|
||||
})
|
||||
export class AppComponent {
|
||||
export class AppComponent implements OnInit {
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,20 +12,21 @@
|
||||
<button mdbBtn
|
||||
*ngIf="serverStarted"
|
||||
type="button"
|
||||
color="primary"
|
||||
class="waves-light"
|
||||
class="waves-light indigo btn-rounded"
|
||||
[disabled]="restarting"
|
||||
(click)="restartServer()"
|
||||
mdbWavesEffect>
|
||||
<i class="fa fa-refresh"></i>
|
||||
Redémarrer
|
||||
</button>
|
||||
<button mdbBtn
|
||||
type="button"
|
||||
class="waves-light"
|
||||
[ngClass]="serverStarted ? 'btn-danger' : 'btn-success'"
|
||||
class="waves-light btn-rounded"
|
||||
[ngClass]="serverStarted ? 'red' : 'green'"
|
||||
[disabled]="restarting"
|
||||
(click)="startOrStopServer()"
|
||||
mdbWavesEffect>
|
||||
<i class="fa" [ngClass]="serverStarted ? 'fa-stop-circle' : 'fa-play-circle'"></i>
|
||||
{{serverStarted ? 'Éteindre' : 'Démarrer'}}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
.btn-rounded {
|
||||
border-radius: 10em;
|
||||
}
|
||||
Reference in New Issue
Block a user