Skip to content
This repository was archived by the owner on Jul 26, 2022. It is now read-only.

Commit ae60b70

Browse files
committed
Initial commit
0 parents  commit ae60b70

File tree

7 files changed

+220
-0
lines changed

7 files changed

+220
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea/
2+
*.iml
3+
4+
dependency-reduced-pom.xml

core/pom.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>webinterface</artifactId>
7+
<groupId>eu.thesystems.project.cloudnet</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>core</artifactId>
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<groupId>org.apache.maven.plugins</groupId>
17+
<artifactId>maven-compiler-plugin</artifactId>
18+
<configuration>
19+
<source>8</source>
20+
<target>8</target>
21+
</configuration>
22+
</plugin>
23+
</plugins>
24+
</build>
25+
26+
27+
</project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package eu.thesystems.cloudnet.webinterface;
2+
3+
import de.dytanic.cloudnet.driver.module.ModuleLifeCycle;
4+
import de.dytanic.cloudnet.driver.module.ModuleTask;
5+
import de.dytanic.cloudnet.module.NodeCloudNetModule;
6+
import eu.thesystems.cloudnet.webinterface.module.WIExtension;
7+
import eu.thesystems.cloudnet.webinterface.module.WIExtensionElement;
8+
9+
import java.util.ArrayList;
10+
import java.util.Arrays;
11+
import java.util.Collection;
12+
import java.util.concurrent.atomic.AtomicReference;
13+
14+
public class CloudNetWebInterface extends NodeCloudNetModule {
15+
16+
private final Collection<WIExtension> extensions = new ArrayList<>();
17+
18+
public void registerExtension(WIExtension extension) {
19+
this.extensions.add(extension);
20+
}
21+
22+
@ModuleTask(event = ModuleLifeCycle.STARTED)
23+
public void startModule() {
24+
25+
WIExtensionElement pasteResult = WIExtensionElement.createTextDisplay("paste_result", null);
26+
27+
AtomicReference<String> pasteTarget = new AtomicReference<>();
28+
WIExtensionElement pasteInput = WIExtensionElement.createTextInput("target", "Target service", pasteTarget::set);
29+
30+
this.registerExtension(new WIExtension("cloudnet_report_module", Arrays.asList(
31+
pasteInput,
32+
WIExtensionElement.createSupplyButton("create_paste", "Paste log of the node", o -> {
33+
boolean all = pasteTarget.get() == null || pasteTarget.get().trim().isEmpty();
34+
// create paste and set link to pasteResult.updateText
35+
}),
36+
pasteResult
37+
), "CloudNet Report"));
38+
39+
}
40+
41+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package eu.thesystems.cloudnet.webinterface.module;
2+
3+
import java.util.Collection;
4+
5+
public class WIExtension {
6+
7+
private final String key;
8+
private final Collection<WIExtensionElement> elements;
9+
private String displayName;
10+
11+
public WIExtension(String key, Collection<WIExtensionElement> elements, String displayName) {
12+
this.key = key;
13+
this.elements = elements;
14+
this.displayName = displayName;
15+
}
16+
17+
public String getKey() {
18+
return this.key;
19+
}
20+
21+
public Collection<WIExtensionElement> getElements() {
22+
return this.elements;
23+
}
24+
25+
public String getDisplayName() {
26+
return this.displayName;
27+
}
28+
29+
public void updateDisplayName(String displayName) {
30+
this.displayName = displayName;
31+
// TODO send to clients
32+
}
33+
34+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package eu.thesystems.cloudnet.webinterface.module;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Nullable;
5+
6+
import java.util.function.Consumer;
7+
8+
public class WIExtensionElement {
9+
10+
private final Type type;
11+
private final Action clickAction;
12+
private final String key;
13+
private final transient Consumer<Object> clickHandler;
14+
private final String targetKey;
15+
private String text;
16+
17+
private WIExtensionElement(Type type, Action clickAction, String key, Consumer<Object> clickHandler, String targetKey, String text) {
18+
this.type = type;
19+
this.clickAction = clickAction;
20+
this.key = key;
21+
this.clickHandler = clickHandler;
22+
this.targetKey = targetKey;
23+
this.text = text;
24+
}
25+
26+
public static WIExtensionElement createSupplyButton(@NotNull String key, @Nullable String initialText, @NotNull Consumer<Object> clickHandler) { // TODO Replace Object with Javalin WebSocket Connection
27+
return new WIExtensionElement(Type.BUTTON, Action.EXECUTE_JAVA, key, clickHandler, null, initialText);
28+
}
29+
30+
public static WIExtensionElement createModalButton(@NotNull String key, @Nullable String initialText, @NotNull String targetKey) {
31+
return new WIExtensionElement(Type.BUTTON, Action.OPEN_MODAL, key, null, targetKey, initialText);
32+
}
33+
34+
public static WIExtensionElement createTextDisplay(@NotNull String key, @Nullable String initialText) {
35+
return new WIExtensionElement(Type.TEXT_DISPLAY, null, key, null, null, initialText);
36+
}
37+
38+
public static WIExtensionElement createTextInput(@NotNull String key, @Nullable String placeholder, @NotNull Consumer<String> textHandler) {
39+
return new WIExtensionElement(Type.TEXT_INPUT, Action.EXECUTE_JAVA, key, o -> textHandler.accept(String.valueOf(o)), null, placeholder);
40+
}
41+
42+
// TODO Modal
43+
44+
public void updateText(String text) {
45+
this.text = text;
46+
// TODO send to clients
47+
}
48+
49+
public Type getType() {
50+
return this.type;
51+
}
52+
53+
public Action getClickAction() {
54+
return this.clickAction;
55+
}
56+
57+
public String getKey() {
58+
return this.key;
59+
}
60+
61+
public String getText() {
62+
return this.text;
63+
}
64+
65+
public enum Action {
66+
EXECUTE_JAVA, OPEN_MODAL
67+
}
68+
69+
public enum Type {
70+
BUTTON, TEXT_DISPLAY, TEXT_INPUT, MODAL
71+
}
72+
73+
}

core/src/main/resources/module.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"group": "eu.thesystems.cloudnet",
3+
"name": "webinterface",
4+
"version": "1.0",
5+
"authors": [
6+
"TheSystems"
7+
]
8+
}

pom.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>eu.thesystems.project.cloudnet</groupId>
8+
<artifactId>webinterface</artifactId>
9+
<packaging>pom</packaging>
10+
<version>1.0-SNAPSHOT</version>
11+
12+
<modules>
13+
<module>core</module>
14+
<module>core</module>
15+
</modules>
16+
17+
<repositories>
18+
<repository>
19+
<id>cloudnet-releases</id>
20+
<url>https://repo.cloudnetservice.eu/repository/releases/</url>
21+
</repository>
22+
</repositories>
23+
24+
<dependencies>
25+
<dependency>
26+
<groupId>de.dytanic.cloudnet</groupId>
27+
<artifactId>cloudnet</artifactId>
28+
<version>3.3.0-RELEASE</version>
29+
<scope>provided</scope>
30+
</dependency>
31+
</dependencies>
32+
33+
</project>

0 commit comments

Comments
 (0)