diff --git a/pom.xml b/pom.xml index 92be9b2..dcadfa7 100644 --- a/pom.xml +++ b/pom.xml @@ -14,14 +14,14 @@ org.springframework.boot spring-boot-starter-parent - 2.0.0.RELEASE + 2.1.6.RELEASE UTF-8 UTF-8 - 1.8 + 11 @@ -33,7 +33,6 @@ org.springframework.boot spring-boot-starter-web - org.springframework.boot spring-boot-devtools @@ -53,19 +52,8 @@ org.postgresql postgresql - runtime + 42.2.6 - - - - - - - - - - - @@ -80,5 +68,4 @@ - diff --git a/src/main/java/org/minager/core/config/JpaConfiguration.java b/src/main/java/org/minager/core/config/JpaConfiguration.java index 89a13c4..c42402a 100644 --- a/src/main/java/org/minager/core/config/JpaConfiguration.java +++ b/src/main/java/org/minager/core/config/JpaConfiguration.java @@ -15,7 +15,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EntityScan("org.minager") @EnableTransactionManagement @EnableJpaRepositories("org.minager") -@PropertySource("classpath:application.properties") +@PropertySource("classpath:application.yml") public class JpaConfiguration { @Value("${spring.datasource.driverClassName}") diff --git a/src/main/java/org/minager/core/constant/ResultCode.java b/src/main/java/org/minager/core/constant/ResultCode.java index a7098a9..e88ec6b 100644 --- a/src/main/java/org/minager/core/constant/ResultCode.java +++ b/src/main/java/org/minager/core/constant/ResultCode.java @@ -12,7 +12,7 @@ public enum ResultCode { val = pVal; } - public int val() { + public final int val() { return val; } } diff --git a/src/main/java/org/minager/serverhandling/ServerHandlingService.java b/src/main/java/org/minager/serverhandling/ServerHandlingService.java index 313aacf..c30cc77 100644 --- a/src/main/java/org/minager/serverhandling/ServerHandlingService.java +++ b/src/main/java/org/minager/serverhandling/ServerHandlingService.java @@ -1,59 +1,54 @@ package org.minager.serverhandling; -import java.io.IOException; - -import javax.servlet.http.HttpServletResponse; - import org.minager.core.constant.ResultCode; import org.minager.core.entities.business.SystemResult; import org.minager.core.services.business.SystemService; -import org.minager.core.utils.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + @Service public class ServerHandlingService { - + @Autowired private SystemService systemService; - - @Value("${minecraft.server.path}") - private String minecraftServerPath; - - @Value("${minecraft.server.shell.name}") - private String minecraftServerShellName; - - private String buildMinecraftServerShellPath() { - return StringUtils.concat(minecraftServerPath, - minecraftServerPath.charAt(minecraftServerPath.length() - 1) == '/' ? "" : '/', - minecraftServerShellName); - } - + + @Value("${minecraft.service.name}") + private String minecraftServiceName; + public int getStatus() { - final SystemResult shellResult = systemService.executeCommand(buildMinecraftServerShellPath(), "api_status"); - return Integer.parseInt(shellResult.getStdOut()); + final SystemResult shellResult = systemService.executeCommand("sudo service", minecraftServiceName, "status"); + return shellResult.getResultCode(); } - + private void startOrStopServer(final HttpServletResponse pResponse, final String pAction) throws IOException { - final SystemResult shellResult = systemService.executeCommand(buildMinecraftServerShellPath(), pAction); - - if(shellResult.getResultCode() == ResultCode.FAILED.val()) { - pResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); - } else if(shellResult.getResultCode() == ResultCode.STATE_UNCHANGED.val()) { + int serviceStatus = getStatus(); + if("start".equals(pAction) && serviceStatus == 0 + || "stop".equals(pAction) && serviceStatus != 0) { pResponse.sendError(HttpServletResponse.SC_CONFLICT); - } // else -> SUCCESS, so code 200 + } else { + final SystemResult shellResult = systemService.executeCommand("sudo service", minecraftServiceName, pAction); + + if(shellResult.getResultCode() == ResultCode.SUCCESS.val()) { + pResponse.setStatus(HttpServletResponse.SC_NO_CONTENT); + } else { // FAILED + pResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); + } + } } public void startServer(final HttpServletResponse pResponse) throws IOException { - startOrStopServer(pResponse, "api_start"); + startOrStopServer(pResponse, "start"); } public void stopServer(final HttpServletResponse pResponse) throws IOException { - startOrStopServer(pResponse, "api_stop"); + startOrStopServer(pResponse, "stop"); } public void restartServer(final HttpServletResponse pResponse) throws IOException { - startOrStopServer(pResponse, "api_restart"); + startOrStopServer(pResponse, "restart"); } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index afcd3c0..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,16 +0,0 @@ -# *********************************************** -# Hibernate database configuration -# *********************************************** -spring.datasource.driverClassName=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://localhost:5432/db_minager -spring.datasource.username=minager -spring.datasource.password=P@ssword -# Disable feature detection by this undocumented parameter. Check the org.hibernate.engine.jdbc.internal.JdbcServiceImpl.configure method for more details. -spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false - -# *********************************************** -# Application custom parameters -# *********************************************** -minager.version=1.0.0 -minecraft.server.path=/home/minecraft/server -minecraft.server.shell.name=minecraft-server.sh \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..d478eaf --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,21 @@ +minager: + version: 1.2.0 + +minecraft: + service: + name: minecraft + +spring: + datasource: + driverClassName: org.postgresql.Driver + url: jdbc:postgresql://localhost:5432/db_minager + username: minager + password: P@ssword + jpa: + open-in-view: false + properties: + hibernate: + temp: + # Disable feature detection by this undocumented parameter. + # Check the org.hibernate.engine.jdbc.internal.JdbcServiceImpl.configure method for more details. + use_jdbc_metadata_defaults: false \ No newline at end of file diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 0000000..6bbf448 --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,14 @@ + #*******& + #***************% + #*********************** + ***/*********************/* + *(************************# __ __ _ + ###*#*************$****#### | \/ (_) + #######/****/**$$$$$$$##### | \ / |_ _ __ __ _ __ _ ___ _ __ + ###########$$$$$$$$$$$$$$$$ | |\/| | | '_ \ / _` |/ _` |/ _ \ '__| + ###########$$$$$$$$$$$$$$$$ | | | | | | | | (_| | (_| | __/ | + ###########$$$$$$$$$$$$$$$$ |_| |_|_|_| |_|\__,_|\__, |\___|_| + ############$$$$$$$$$$$$$$# __/ | + ############$$$$$$$$$$$$$ |___/ + #########$$$$$$$$$$$ + ######($$$$$$$ \ No newline at end of file diff --git a/src/main/ts/angular.json b/src/main/ts/angular.json index 017ce96..31e835c 100644 --- a/src/main/ts/angular.json +++ b/src/main/ts/angular.json @@ -3,7 +3,7 @@ "version": 1, "newProjectRoot": "projects", "projects": { - "ts": { + "minager": { "root": "", "sourceRoot": "src", "projectType": "application", @@ -27,9 +27,12 @@ "src/assets" ], "styles": [ - "node_modules/font-awesome/scss/font-awesome.scss", - "node_modules/angular-bootstrap-md/scss/bootstrap/bootstrap.scss", - "node_modules/angular-bootstrap-md/scss/mdb-free.scss", + "node_modules/@fortawesome/fontawesome-free/scss/fontawesome.scss", + "node_modules/@fortawesome/fontawesome-free/scss/solid.scss", + "node_modules/@fortawesome/fontawesome-free/scss/regular.scss", + "node_modules/@fortawesome/fontawesome-free/scss/brands.scss", + "node_modules/angular-bootstrap-md/assets/scss/bootstrap/bootstrap.scss", + "node_modules/angular-bootstrap-md/assets/scss/mdb.scss", "src/styles.scss" ], "scripts": [ @@ -77,18 +80,18 @@ "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { - "browserTarget": "ts:build" + "browserTarget": "minager:build" }, "configurations": { "production": { - "browserTarget": "ts:build:production" + "browserTarget": "minager:build:production" } } }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { - "browserTarget": "ts:build" + "browserTarget": "minager:build" } }, "test": { @@ -122,7 +125,7 @@ } } }, - "ts-e2e": { + "minager-e2e": { "root": "e2e/", "projectType": "application", "architect": { @@ -130,11 +133,11 @@ "builder": "@angular-devkit/build-angular:protractor", "options": { "protractorConfig": "e2e/protractor.conf.js", - "devServerTarget": "ts:serve" + "devServerTarget": "minager:serve" }, "configurations": { "production": { - "devServerTarget": "ts:serve:production" + "devServerTarget": "minager:serve:production" } } }, @@ -150,5 +153,5 @@ } } }, - "defaultProject": "ts" + "defaultProject": "minager" } diff --git a/src/main/ts/package.json b/src/main/ts/package.json index 95676f4..85701a5 100644 --- a/src/main/ts/package.json +++ b/src/main/ts/package.json @@ -1,9 +1,9 @@ { "name": "ts", - "version": "0.0.0", + "version": "0.0.1", "scripts": { "ng": "ng", - "start": "ng serve", + "start": "ng serve --proxy-config proxy.conf.json", "build": "ng build", "test": "ng test", "lint": "ng lint", @@ -11,44 +11,44 @@ }, "private": true, "dependencies": { - "@angular/animations": "^6.1.0", - "@angular/common": "^6.1.0", - "@angular/compiler": "^6.1.0", - "@angular/core": "^6.1.0", - "@angular/forms": "^6.1.0", - "@angular/http": "^6.1.0", - "@angular/platform-browser": "^6.1.0", - "@angular/platform-browser-dynamic": "^6.1.0", - "@angular/router": "^6.1.0", - "@types/chart.js": "^2.7.36", - "angular-bootstrap-md": "^6.2.4", - "angular5-csv": "^0.2.10", - "chart.js": "^2.5.0", - "core-js": "^2.5.4", - "font-awesome": "^4.7.0", + "@angular/animations": "^8.2.1", + "@angular/common": "^8.2.1", + "@angular/compiler": "^8.2.1", + "@angular/core": "^8.2.1", + "@angular/forms": "^8.2.1", + "@angular/http": "^7.2.15", + "@angular/platform-browser": "^8.2.1", + "@angular/platform-browser-dynamic": "^8.2.1", + "@angular/router": "^8.2.1", + "@types/chart.js": "^2.7.56", + "@fortawesome/fontawesome-free": "^5.10.1", + "angular-bootstrap-md": "^8.1.1", + "chart.js": "^2.8.0", + "core-js": "^3.1.4", "hammerjs": "^2.0.8", - "rxjs": "~6.2.0", - "zone.js": "~0.8.26" + "rxjs": "~6.5.2", + "tslib": "^1.10.0", + "zone.js": "~0.10.1" }, "devDependencies": { - "@angular-devkit/build-angular": "~0.8.0", - "@angular/cli": "~6.2.3", - "@angular/compiler-cli": "^6.1.0", - "@angular/language-service": "^6.1.0", - "@types/jasmine": "~2.8.8", - "@types/jasminewd2": "~2.0.3", - "@types/node": "~8.9.4", - "codelyzer": "~4.3.0", - "jasmine-core": "~2.99.1", + "@angular-devkit/build-angular": "~0.802.1", + "@angular/cli": "~8.2.1", + "@angular/compiler-cli": "^8.2.1", + "@angular/language-service": "^8.2.1", + "@types/jasmine": "~3.4.0", + "@types/jasminewd2": "~2.0.6", + "@types/node": "~12.7.1", + "codelyzer": "~5.1.0", + "jasmine-core": "~3.4.0", "jasmine-spec-reporter": "~4.2.1", - "karma": "~3.0.0", - "karma-chrome-launcher": "~2.2.0", - "karma-coverage-istanbul-reporter": "~2.0.1", - "karma-jasmine": "~1.1.2", - "karma-jasmine-html-reporter": "^0.2.2", - "protractor": "~5.4.0", - "ts-node": "~7.0.0", - "tslint": "~5.11.0", - "typescript": "~2.9.2" + "karma": "~4.2.0", + "karma-chrome-launcher": "~3.0.0", + "karma-coverage-istanbul-reporter": "~2.1.0", + "karma-jasmine": "~2.0.1", + "karma-jasmine-html-reporter": "^1.4.2", + "protractor": "~5.4.2", + "ts-node": "~8.3.0", + "tslint": "~5.18.0", + "typescript": "~3.5.3" } } diff --git a/src/main/ts/proxy.conf.json b/src/main/ts/proxy.conf.json new file mode 100644 index 0000000..7d4976b --- /dev/null +++ b/src/main/ts/proxy.conf.json @@ -0,0 +1,6 @@ +{ + "/api": { + "target": "http://localhost:8080", + "secure": false + } +} diff --git a/src/main/ts/src/app/app.component.html b/src/main/ts/src/app/app.component.html index 1e9fd64..8309ae9 100644 --- a/src/main/ts/src/app/app.component.html +++ b/src/main/ts/src/app/app.component.html @@ -1,4 +1,5 @@ +
APP Version : {{appVersion}} - API Version : {{apiVersion}}
@@ -9,4 +10,4 @@ Veuillez contacter votre administrateur ou réessayer plus tard.

Chargement...

- \ No newline at end of file + diff --git a/src/main/ts/src/app/app.module.ts b/src/main/ts/src/app/app.module.ts index 7ce80c3..005277e 100644 --- a/src/main/ts/src/app/app.module.ts +++ b/src/main/ts/src/app/app.module.ts @@ -20,6 +20,8 @@ import { HeaderComponent } from './header/header.component'; import { ServerComponent } from './server/server.component'; import { LoginComponent } from './login/login.component'; import { DisconnectionComponent } from './disconnection/disconnection.component'; +import { NotificationsComponent } from './core/notifications/notifications.component'; +import { NotificationElement } from './core/notifications/notification-element/notification-element.component'; // ********************************************** // App Services @@ -40,7 +42,9 @@ import { TokenInterceptor } from './core/interceptors/token-interceptor'; HeaderComponent, ServerComponent, LoginComponent, - DisconnectionComponent + DisconnectionComponent, + NotificationsComponent, + NotificationElement ], imports: [ BrowserModule, diff --git a/src/main/ts/src/app/core/notifications/notification-class.ts b/src/main/ts/src/app/core/notifications/notification-class.ts new file mode 100644 index 0000000..b9a56df --- /dev/null +++ b/src/main/ts/src/app/core/notifications/notification-class.ts @@ -0,0 +1,26 @@ +/** + * Class which represents a notification class. + * It serves to set the notification appearence. + */ +export class NotificationClass { + /** + * Default constructor. + * @param {string} icon Class name of font-awsome icon. + * @param {string} clazz The class to set notification style. + */ + constructor( + public icon: string, + public clazz: string, + ) {} +} + +/** + * Constant instances of NotificationClass. + */ +export const NotificationClasses = Object.freeze({ + 'Error': new NotificationClass('exclamation-circle ', 'alert-danger'), + 'Warn': new NotificationClass('exclamation-triangle', 'alert-warning'), + 'Info': new NotificationClass('info-circle', 'alert-info'), + 'Success': new NotificationClass('check-circle', 'alert-success') +}); + diff --git a/src/main/ts/src/app/core/notifications/notification-element/notification-element.component.html b/src/main/ts/src/app/core/notifications/notification-element/notification-element.component.html new file mode 100644 index 0000000..5e7f8e5 --- /dev/null +++ b/src/main/ts/src/app/core/notifications/notification-element/notification-element.component.html @@ -0,0 +1,7 @@ + diff --git a/src/main/ts/src/app/core/notifications/notification-element/notification-element.component.ts b/src/main/ts/src/app/core/notifications/notification-element/notification-element.component.ts new file mode 100644 index 0000000..2c6fcd3 --- /dev/null +++ b/src/main/ts/src/app/core/notifications/notification-element/notification-element.component.ts @@ -0,0 +1,78 @@ +import { NotificationClass } from './../notification-class'; +import { Component, Input, OnInit, ViewChild, ElementRef } from '@angular/core'; + +/** + * Class which represents a notification in the notifications list. + */ +@Component({ + selector: 'app-notification-element', + templateUrl: 'notification-element.component.html', + styles: [` + #notification { + transition: all 0.7s ease-out; + position: relative; + } + .close { + position: absolute; + right: 7px; + top: 12px; + font-size: 19px; + opacity: 0; + } + #notification:hover .close { + opacity: 0.5; + } + `] +}) +export class NotificationElement implements OnInit { + /** + * The notification model. + */ + @Input() model: NotificationModel; + /** + * The notification DOM element. + */ + @ViewChild('notification', {static: true}) notification: ElementRef; + + /** + * Sets the DOM element in the model object and plays with opacity. + */ + ngOnInit(): void { + this.model.notification = this.notification; + + this.notification.nativeElement.style.opacity = 0; + setTimeout(() => { + this.notification.nativeElement.style.opacity = 1; + }, 100); + } +} + +/** + * Class which represents the notification model. + */ +export class NotificationModel { + /** + * Element which represents the DOM element of the notification element. + */ + notification: ElementRef; + + /** + * Default constructor. + * @param {string} content The message of the notification. + * @param {NotificationClass} notificationClass The category of the notification (info, error...). + */ + constructor( + public content: string, + public notificationClass: NotificationClass + ) {} + + /** + * Hides the notification DOM element. + */ + public hide(): void { + this.notification.nativeElement.style.opacity = 0; + setTimeout(() => { + this.notification.nativeElement.style.display = 'none'; + }, 800); + } +} diff --git a/src/main/ts/src/app/core/notifications/notifications.component.html b/src/main/ts/src/app/core/notifications/notifications.component.html new file mode 100644 index 0000000..9765310 --- /dev/null +++ b/src/main/ts/src/app/core/notifications/notifications.component.html @@ -0,0 +1,5 @@ +
+ +
+ diff --git a/src/main/ts/src/app/core/notifications/notifications.component.ts b/src/main/ts/src/app/core/notifications/notifications.component.ts new file mode 100644 index 0000000..64e2f10 --- /dev/null +++ b/src/main/ts/src/app/core/notifications/notifications.component.ts @@ -0,0 +1,108 @@ +import { NotificationClass, NotificationClasses } from './notification-class'; +import { NotificationModel } from './notification-element/notification-element.component'; +import { Component, OnInit } from '@angular/core'; + +/** + * Class which offers the notifications service. + */ +@Component({ + selector: 'app-notifications', + templateUrl: 'notifications.component.html', + styles: [` + #notification-container { + position: fixed; + top: 50px; + right: 20px; + width: 300px; + z-index: 1100; + } + `] +}) +export class NotificationsComponent implements OnInit { + /** + * Singleton of the notification service. + */ + private static component: NotificationsComponent; + + /** + * List of notifications model. + */ + notificationList: Array = []; + + /** + * Creates an error notification. + * @param {string} message The content of the notification. + */ + public static error(message: string): void { + NotificationsComponent.notif(message, NotificationClasses.Error); + } + + /** + * Creates a warning notification. + * @param {string} message The content of the notification. + */ + public static warn(message: string): void { + NotificationsComponent.notif(message, NotificationClasses.Warn); + } + + /** + * Creates an info notification. + * @param {string} message The content of the notification. + */ + public static info(message: string): void { + NotificationsComponent.notif(message, NotificationClasses.Info); + } + + /** + * Creates a success notification. + * @param {string} message The content of the notification. + */ + public static success(message: string): void { + NotificationsComponent.notif(message, NotificationClasses.Success); + } + + /** + * Create a notification. The {@code notifClass} param defines the category of + * the notification (info, error...). + * @param {string} message The content of the notification. + * @param {NotificationClass} notifClass The category of the notification. + */ + private static notif(message: string, notifClass: NotificationClass): void { + const elem = new NotificationModel(message, notifClass); + + NotificationsComponent.component.notificationList.push(elem); + + setTimeout(() => { + elem.hide(); + + setTimeout(() => { + NotificationsComponent.clearNotificationList(); + }, 900); + }, 4500); + } + + /** + * Clears the consumed notifications in the list. + * When a notification is created, a cooldown is set to hide it after a certain time period. + * In this cooldown, the notification have only its display as {@code none}, but the + * notification isn't remove from the list. This method removes it. + */ + private static clearNotificationList(): void { + NotificationsComponent.component.notificationList.forEach(elem => { + if (elem.notification.nativeElement.style.display === 'none') { + const index = NotificationsComponent.component.notificationList.indexOf(elem); + if (index > -1) { + NotificationsComponent.component.notificationList.splice(index, 1); + } + } + }); + } + + /** + * Set the reference of the singleton here because this component + * is created at the application startup. + */ + ngOnInit(): void { + NotificationsComponent.component = this; + } +} diff --git a/src/main/ts/src/app/header/header.component.html b/src/main/ts/src/app/header/header.component.html index e2c7bb0..54b85af 100644 --- a/src/main/ts/src/app/header/header.component.html +++ b/src/main/ts/src/app/header/header.component.html @@ -7,19 +7,22 @@ -
+ - Connexion + class="btn waves-effect waves-light" + mdbWavesEffect> + Connexion - Déconnexion + *ngIf="isAuthenticated()" + id="sign-out" + class="btn waves-effect waves-light" + mdbTooltip="Déconnexion" + placement="bottom" + mdbWavesEffect> + Déconnexion
- \ No newline at end of file + diff --git a/src/main/ts/src/app/header/header.component.ts b/src/main/ts/src/app/header/header.component.ts index 71bb193..8a1363e 100644 --- a/src/main/ts/src/app/header/header.component.ts +++ b/src/main/ts/src/app/header/header.component.ts @@ -10,10 +10,13 @@ import { environment } from '../../environments/environment'; width: 50px; height: 50px; } - a, a:visited { color: white; } + #sign-out:hover { + color: white; + background-color: #f44336 !important; + } `] }) export class HeaderComponent { diff --git a/src/main/ts/src/app/login/login.component.html b/src/main/ts/src/app/login/login.component.html index 14d4c5f..709f8f2 100644 --- a/src/main/ts/src/app/login/login.component.html +++ b/src/main/ts/src/app/login/login.component.html @@ -2,9 +2,9 @@

Connexion

-
+
-
-
+
- - +
-
-
-

{{loginError}}

-
-
-
-
\ No newline at end of file +
diff --git a/src/main/ts/src/app/login/login.component.ts b/src/main/ts/src/app/login/login.component.ts index ef979d6..436ab64 100644 --- a/src/main/ts/src/app/login/login.component.ts +++ b/src/main/ts/src/app/login/login.component.ts @@ -1,8 +1,9 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { User } from '../core/entities'; import { LoginService } from './login.service'; import { AuthService } from '../core/services/auth.service'; +import { NotificationsComponent } from '../core/notifications/notifications.component'; @Component({ selector: 'app-login', @@ -24,37 +25,34 @@ import { AuthService } from '../core/services/auth.service'; } `] }) -export class LoginComponent { +export class LoginComponent implements OnInit { model: User = new User('', '', '', '', undefined, ''); loginError; constructor( private loginService: LoginService, private authService: AuthService, - private router: Router + private router: Router, ) {} + ngOnInit(): void { + if (this.authService.isAuthenticated()) { + this.navigateToServerPage(); + } + } + submitLogin(): void { this.loginService.login(this.model).subscribe(user => { this.authService.setToken(user.token); this.authService.setUser(user); - this.router.navigate(['/server']); + this.navigateToServerPage(); }, error => { - this.setMessage('Email ou password incorrect.'); + console.error(error); + NotificationsComponent.error('Email ou password incorrect.'); }); } - setMessage(message: string): void { - this.loginError = message; - - const resultMsgDiv = document.getElementById('errorMsg'); - resultMsgDiv.style.maxHeight = '64px'; - - setTimeout(() => { - resultMsgDiv.style.maxHeight = '0px'; - setTimeout(() => { - this.loginError = undefined; - }, 550); - }, 3000); + private navigateToServerPage(): void { + this.router.navigate(['/server']); } } diff --git a/src/main/ts/src/app/server/server.component.html b/src/main/ts/src/app/server/server.component.html index 7617a34..65345f7 100644 --- a/src/main/ts/src/app/server/server.component.html +++ b/src/main/ts/src/app/server/server.component.html @@ -5,13 +5,12 @@

Serveur Minecraft

Status du serveur : - + Vérification - - + + {{serverStarted ? 'Démarré' : 'Éteint'}} - +
Adresse du serveur de jeu : @@ -26,44 +25,24 @@ Copié !
-
- - -
-
-

{{errorMsg}}

-
-
-
-
-

{{warnMsg}}

-
-
-
-
-

{{successMsg}}

-
-
- \ No newline at end of file + diff --git a/src/main/ts/src/app/server/server.component.ts b/src/main/ts/src/app/server/server.component.ts index c1806bf..2dd12db 100644 --- a/src/main/ts/src/app/server/server.component.ts +++ b/src/main/ts/src/app/server/server.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { ServerService } from './server.service'; import { AuthService } from '../core/services/auth.service'; +import { NotificationsComponent } from '../core/notifications/notifications.component'; @Component({ selector: 'app-server', @@ -16,15 +17,19 @@ import { AuthService } from '../core/services/auth.service'; margin-top: 25px; cursor: pointer; } + #action-btn-div { + text-align:center; + margin-top: 15px; + } + #action-btn-div button { + margin-right: 15px; + } `] }) export class ServerComponent implements OnInit { serverAddress = '176.188.217.1:54311'; serverStartedChecked = false; serverStarted = false; - errorMsg; - warnMsg; - successMsg; restarting = false; constructor( @@ -35,7 +40,7 @@ export class ServerComponent implements OnInit { ngOnInit(): void { this.serverService.getStatus().subscribe(pServerStatus => { this.serverStartedChecked = true; - this.serverStarted = pServerStatus === 1; + this.serverStarted = pServerStatus === 0; }); } @@ -47,10 +52,10 @@ export class ServerComponent implements OnInit { this.restarting = true; this.serverService.restartServer().subscribe(() => { - this.setMessage('Serveur redémarré.', 'successMsg'); + NotificationsComponent.success('Serveur redémarré.'); }, error => { - this.setMessage('Une erreur est survenue lors du redémarrage du serveur.', - 'errorMsg'); + console.error(error); + NotificationsComponent.error('Une erreur est survenue lors du redémarrage du serveur.'); }, () => { this.restarting = false; }); @@ -58,36 +63,18 @@ export class ServerComponent implements OnInit { startOrStopServer(): void { this.serverService[(this.serverStarted ? 'stop' : 'start') + 'Server']().subscribe(() => { - this.setMessage('Serveur ' + (this.serverStarted ? 'éteint' : 'démarré') + '.', 'successMsg'); + NotificationsComponent.success(`Serveur ${this.serverStarted ? 'éteint' : 'démarré'}.`); this.serverStarted = !this.serverStarted; }, error => { if (error.status === 409) { - this.setMessage('Le serveur est déjà ' - + (this.serverStarted ? 'éteint' : 'démarré') + '.', - 'warnMsg'); + NotificationsComponent.warn(`Le serveur est déjà ${this.serverStarted ? 'éteint' : 'démarré'}.`); } else { - this.setMessage('Une erreur est survenue lors ' - + (this.serverStarted ? 'de l\'extinction' : 'du démarrage') - + 'du serveur.', - 'errorMsg'); + NotificationsComponent.error(`Une erreur est survenue lors ${this.serverStarted + ? 'de l\'extinction' : 'du démarrage'} du serveur.`); } }); } - setMessage(message: string, type: string): void { - this[type] = message; - - const resultMsgDiv = document.getElementById(type); - resultMsgDiv.style.maxHeight = '64px'; - - setTimeout(() => { - resultMsgDiv.style.maxHeight = '0px'; - setTimeout(() => { - this[type] = undefined; - }, 550); - }, 3000); - } - copyToClipBoard(): void { document.addEventListener('copy', (e: ClipboardEvent) => { e.clipboardData.setData('text/plain', (this.serverAddress)); diff --git a/src/main/ts/src/assets/images/background.jpg b/src/main/ts/src/assets/images/background.jpg new file mode 100644 index 0000000..58067ef Binary files /dev/null and b/src/main/ts/src/assets/images/background.jpg differ diff --git a/src/main/ts/src/assets/images/background.png b/src/main/ts/src/assets/images/background.png deleted file mode 100644 index c13d5f4..0000000 Binary files a/src/main/ts/src/assets/images/background.png and /dev/null differ diff --git a/src/main/ts/src/environments/environment.ts b/src/main/ts/src/environments/environment.ts index 41d63dd..3a65b21 100644 --- a/src/main/ts/src/environments/environment.ts +++ b/src/main/ts/src/environments/environment.ts @@ -4,7 +4,7 @@ export const environment = { production: false, - appVersion: '1.0.1', + appVersion: '1.2.0', title: 'LOCAL' }; diff --git a/src/main/ts/src/polyfills.ts b/src/main/ts/src/polyfills.ts index d310405..4e46795 100644 --- a/src/main/ts/src/polyfills.ts +++ b/src/main/ts/src/polyfills.ts @@ -43,7 +43,7 @@ /** Evergreen browsers require these. **/ // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. -import 'core-js/es7/reflect'; +// import 'core-js/es7/reflect'; /** diff --git a/src/main/ts/src/styles.scss b/src/main/ts/src/styles.scss index fb5ddd6..18e2d3e 100644 --- a/src/main/ts/src/styles.scss +++ b/src/main/ts/src/styles.scss @@ -12,7 +12,7 @@ body { flex-direction: column; justify-content:space-between; min-height: 100%; - background-image: url("./assets/images/background.png"); + background-image: url("./assets/images/background.jpg"); background-color: #fff; background-position: center; background-repeat: no-repeat; @@ -21,4 +21,4 @@ body { .btn { border-radius: 10em; -} \ No newline at end of file +}