Skip to content

Commit 88dde6a

Browse files
committed
Update version to 0.4.2-STABLE; add dynamic dashboard name configuration and improve web service initialization
1 parent 316e926 commit 88dde6a

9 files changed

Lines changed: 77 additions & 25 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group = 'fr.sandro642.github'
8-
version = '0.4.1-STABLE'
8+
version = '0.4.2-STABLE'
99

1010
// Générer une classe de version automatiquement
1111
task generateVersionClass {

src/main/java/fr/sandro642/github/ConnectLib.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99
import fr.sandro642.github.jobs.JobGetInfos;
1010
import fr.sandro642.github.enums.ResourceType;
1111
import fr.sandro642.github.spring.Application;
12-
import fr.sandro642.github.spring.controller.DataController;
1312
import fr.sandro642.github.update.RetrieveLastVersion;
1413

15-
import java.util.ArrayList;
16-
import java.util.HashMap;
17-
import java.util.List;
18-
import java.util.Map;
14+
import java.util.*;
1915

2016
/**
2117
* ConnectLib is the main class of the ConnectorAPI library for Standard API.
@@ -53,7 +49,7 @@ public class ConnectLib {
5349
* @param resourceType the type of resource to initialize
5450
* @param routes the routes to be used in the ConnectLib
5551
*/
56-
public ConnectLib Init(ResourceType resourceType, LangType langType, Class<? extends Enum<?>>... routes) {
52+
public ConnectLib init(ResourceType resourceType, LangType langType, Class<? extends Enum<?>>... routes) {
5753
try {
5854
logger = new Logger();
5955
storeAndRetrieve = new StoreAndRetrieve();
@@ -126,9 +122,29 @@ public Map<String, String> getRoutesMap() {
126122
* Check if the ConnectLib supports web services.
127123
* This method starts the Spring application.
128124
*/
129-
public ConnectLib webServices() {
125+
public void webServices() {
126+
storeAndRetrieve.put(storeAndRetrieve.PORT, 3000);
127+
SpringApp().startApplication().subscribe();
128+
}
129+
130+
/**
131+
* Check if the ConnectLib supports web services on a specific port with a dashboard name.
132+
* This method starts the Spring application.
133+
* @param port the port number to run the web services on
134+
* If port is 0, the default port 3000 will be used
135+
* @param nameDashboard the name of the dashboard
136+
*/
137+
public void webServices(int port, String nameDashboard) {
138+
storeAndRetrieve.put(storeAndRetrieve.NAME_DASHBOARD, nameDashboard);
139+
140+
if (port == 0) {
141+
storeAndRetrieve.put(storeAndRetrieve.PORT, 3000);
142+
} else {
143+
storeAndRetrieve.put(storeAndRetrieve.PORT, port);
144+
}
145+
146+
130147
SpringApp().startApplication().subscribe();
131-
return this;
132148
}
133149

134150
/**

src/main/java/fr/sandro642/github/example/ExampleUsages.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public String getRoute() {
4343
public void initializeLib() {
4444

4545
// Optionally, you can specify routes if needed
46-
connectLib.Init(ResourceType.MAIN_RESOURCES, LangType.FRENCH, ExampleRoutes.class);
46+
connectLib.init(ResourceType.MAIN_RESOURCES, LangType.FRENCH, ExampleRoutes.class);
4747
// You can also initialize without specifying routes
48-
connectLib.Init(ResourceType.MAIN_RESOURCES, LangType.FRENCH);
48+
connectLib.init(ResourceType.MAIN_RESOURCES, LangType.FRENCH);
4949
}
5050

5151
// Example method to demonstrate usage

src/main/java/fr/sandro642/github/misc/StoreAndRetrieve.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class StoreAndRetrieve {
2020
*/
2121
public final String URL_KEY = "baseUrl";
2222
public final String FILE_LOCATION_KEY = "fileLocation";
23+
24+
public final String NAME_DASHBOARD = "nameDashboard";
25+
public final String PORT = String.valueOf(3000);
2326
public final HashMap<String, Object> store = new HashMap<>();
2427

2528
/**

src/main/java/fr/sandro642/github/spring/Application.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package fr.sandro642.github.spring;
22

3+
import fr.sandro642.github.ConnectLib;
34
import org.springframework.boot.Banner;
45
import org.springframework.boot.SpringApplication;
56
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import reactor.core.publisher.ConnectableFlux;
68
import reactor.core.publisher.Mono;
79
import reactor.core.scheduler.Schedulers;
810

@@ -19,6 +21,8 @@ public class Application {
1921
// Singleton instance
2022
private static Application instance;
2123

24+
private static final ConnectLib connectLib = new ConnectLib();
25+
2226
/**
2327
* Starts the Spring Boot application in a non-blocking manner.
2428
* @return a Mono that completes when the application has started
@@ -29,6 +33,7 @@ public Mono<Void> startApplication() {
2933
app.setBannerMode(Banner.Mode.OFF); // supprime le banner Spring
3034
app.setLogStartupInfo(false); // désactive l'info de démarrage
3135
Map<String, Object> props = new HashMap<>();
36+
props.put("server.port", connectLib.StoreAndRetrieve().get(connectLib.StoreAndRetrieve().PORT)); // définit le port du serveur
3237
props.put("logging.level.root", "OFF"); // coupe l'affichage des logs
3338
app.setDefaultProperties(props);
3439
app.run();

src/main/java/fr/sandro642/github/spring/controller/DataController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ public List<Request> getRequests() {
8989
return result;
9090
}
9191

92+
@GetMapping("/config")
93+
public Map<String, Object> getConfig() {
94+
Map<String, Object> config = new HashMap<>();
95+
config.put("nameDashboard", connectLib.StoreAndRetrieve().get(connectLib.StoreAndRetrieve().NAME_DASHBOARD));
96+
return config;
97+
}
98+
9299
/**
93100
* Endpoint to create a new request.
94101
* @param route the route for the request
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
server.port=3000
21
spring.application.name=ConnectLib Dashboard

src/main/resources/static/index.html

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>ConnectLib Dashboard</title>
6+
<title>Dashboard</title>
77
<style>
88
* {
99
margin: 0;
@@ -365,7 +365,7 @@
365365
<body>
366366
<div class="content-wrapper">
367367
<nav class="navbar">
368-
<div class="navbar-title">ConnectLib Dashboard</div>
368+
<div class="navbar-title", id="navbar-title"></div>
369369
</nav>
370370

371371
<div class="main-container">
@@ -381,14 +381,16 @@
381381
</div>
382382
<div class="sidebar-content">
383383
<div class="sidebar-item active" onclick="showSection('status')">
384-
<svg class="sidebar-item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
384+
<svg class="sidebar-item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor"
385+
stroke-width="2">
385386
<circle cx="12" cy="12" r="10"></circle>
386387
<path d="M12 6v6l4 2"></path>
387388
</svg>
388389
<span class="sidebar-item-text">Status</span>
389390
</div>
390391
<div class="sidebar-item" onclick="showSection('routes')">
391-
<svg class="sidebar-item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
392+
<svg class="sidebar-item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor"
393+
stroke-width="2">
392394
<circle cx="18" cy="5" r="3"></circle>
393395
<circle cx="6" cy="12" r="3"></circle>
394396
<circle cx="18" cy="19" r="3"></circle>
@@ -398,7 +400,8 @@
398400
<span class="sidebar-item-text">Routes</span>
399401
</div>
400402
<div class="sidebar-item" onclick="showSection('requests')">
401-
<svg class="sidebar-item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
403+
<svg class="sidebar-item-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor"
404+
stroke-width="2">
402405
<rect x="2" y="7" width="20" height="14" rx="2" ry="2"></rect>
403406
<path d="M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"></path>
404407
</svg>
@@ -450,7 +453,8 @@ <h2 class="section-title">Routes</h2>
450453
<div class="section-header">
451454
<h2 class="section-title">Requests</h2>
452455
<button class="refresh-btn" id="refresh-btn" onclick="refreshRequests()">
453-
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
456+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor"
457+
stroke-width="2">
454458
<polyline points="23 4 23 10 17 10"></polyline>
455459
<polyline points="1 20 1 14 7 14"></polyline>
456460
<path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"></path>
@@ -486,6 +490,23 @@ <h2 class="section-title">Requests</h2>
486490

487491
const API_BASE_URL = '/api';
488492

493+
async function loadConfig() {
494+
try {
495+
const response = await fetch(`${API_BASE_URL}/config`);
496+
const config = await response.json();
497+
498+
const navbarTitle = document.getElementById('navbar-title');
499+
500+
if (config && config.nameDashboard) {
501+
navbarTitle.textContent = config.nameDashboard;
502+
} else {
503+
navbarTitle.textContent = 'ConnectLib Dashboard';
504+
}
505+
} catch (error) {
506+
console.error('Error loading config:', error);
507+
}
508+
}
509+
489510
async function loadStatus() {
490511
try {
491512
const response = await fetch(`${API_BASE_URL}/status`);
@@ -594,6 +615,7 @@ <h2 class="section-title">Requests</h2>
594615
loadStatus();
595616
loadRoutes();
596617
loadRequests();
618+
loadConfig();
597619

598620
setInterval(() => {
599621
loadStatus();

src/test/java/fr/sandro642/github/test/MainTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public String getVersion() {
8383

8484
@Test
8585
public void initializeCAPI() {
86-
connectLib.Init(ResourceType.TEST_RESOURCES, LangType.ENGLISH, TestRoutes.class);
86+
connectLib.init(ResourceType.TEST_RESOURCES, LangType.ENGLISH, TestRoutes.class);
8787
}
8888

8989

9090
public static void main(String[] args) {
91-
connectLib.Init(ResourceType.TEST_RESOURCES, LangType.FRENCH, TestRoutes.class);
91+
connectLib.init(ResourceType.TEST_RESOURCES, LangType.FRENCH, TestRoutes.class);
9292
try {
9393
connectLib.Logger().showLogs();
9494

@@ -108,7 +108,7 @@ public static void main(String[] args) {
108108

109109
@Test
110110
public void testUseFullRoute() {
111-
connectLib.Init(ResourceType.TEST_RESOURCES, LangType.FRENCH, TestRoutes.class);
111+
connectLib.init(ResourceType.TEST_RESOURCES, LangType.FRENCH, TestRoutes.class);
112112

113113
connectLib.Logger().showLogs();
114114
try {
@@ -132,7 +132,7 @@ public void testUseFullRoute() {
132132

133133
@Test
134134
public void testLangType() {
135-
connectLib.Init(ResourceType.TEST_RESOURCES, LangType.ENGLISH, TestRoutes.class);
135+
connectLib.init(ResourceType.TEST_RESOURCES, LangType.ENGLISH, TestRoutes.class);
136136

137137
connectLib.Logger().showLogs();
138138

@@ -162,7 +162,7 @@ public void testLangType() {
162162
public void testSpecData() {
163163
try {
164164

165-
connectLib.Init(ResourceType.MAIN_RESOURCES, LangType.ENGLISH, TestRoutes.class);
165+
connectLib.init(ResourceType.MAIN_RESOURCES, LangType.ENGLISH, TestRoutes.class);
166166

167167
CompletableFuture<ApiFactory> apiFactoryCompletableFuture = connectLib.JobGetInfos()
168168
.getRoutes(TestCustomVersion.V1_API, MethodType.GET, TestRoutes.REQUEST_TOKEN)
@@ -186,8 +186,8 @@ public void testSpecData() {
186186
public void startAppServices() {
187187
try {
188188
connectLib.Logger().showLogs();
189-
connectLib.Init(ResourceType.TEST_RESOURCES, LangType.ENGLISH, TestRoutes.class)
190-
.webServices();
189+
connectLib.init(ResourceType.TEST_RESOURCES, LangType.ENGLISH, TestRoutes.class)
190+
.webServices(8080, "TestDashboard");
191191

192192
CompletableFuture<ApiFactory> apiFactoryCompletableFuture = connectLib.JobGetInfos()
193193
.getRoutes(MethodType.GET, TestRoutes.HELLO)

0 commit comments

Comments
 (0)