Compare commits

...

4 Commits

Author SHA1 Message Date
8a0396ab2d grab also version footer in dashboard 2020-02-25 11:31:26 +01:00
b3960653ca finished index page
started wit dashboad basicinfos
2020-02-18 22:21:10 +01:00
af321c8aad kotlinjs build improvement
test post fetch for index
2020-02-18 20:22:00 +01:00
16939c7b6a added kotlinjs buildscript and test output 2020-02-18 19:22:56 +01:00
18 changed files with 203 additions and 5 deletions

94
WebServer/build.gradle Normal file
View File

@ -0,0 +1,94 @@
//plugins {
// id 'org.jetbrains.kotlin.js' version '1.3.70-eap-184'
//}
//group 'org.example'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.3.61'
ext.web_dir = '../src/resources/wwwroot/js/'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin2js'
sourceSets {
main.java.srcDirs = ["src/js/"]
test.java.srcDirs = ["src/js/test"]
}
compileKotlin2Js {
kotlinOptions.outputFile = "${projectDir}/build/web/WasteInformationServer.js"
kotlinOptions.moduleKind = "plain"
kotlinOptions.sourceMap = true
}
compileTestKotlin2Js {
kotlinOptions.moduleKind = "plain"
kotlinOptions.sourceMap = true
}
repositories {
mavenCentral()
maven {
url "http://dl.bintray.com/kotlin/kotlin-eap-1.1"
}
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
}
clean.doFirst() {
delete("${web_dir}")
}
build.doLast() {
// Copy kotlin.js and kotlin-meta.js from jar into web directory
configurations.compile.each { File file ->
copy {
includeEmptyDirs = false
from zipTree(file.absolutePath)
into "${projectDir}/${web_dir}/lib"
include { fileTreeElement ->
def path = fileTreeElement.path
path.endsWith(".js") && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/"))
}
}
}
// Unpack build contents
// TODO Remove this step when a CDN link is available.
copy {
File artifact = new File("build/libs/${project.name}-${project.version}.jar")
includeEmptyDirs = false
from zipTree(artifact)
into "${web_dir}"
include { fileTreeElement ->
def path = fileTreeElement.path
!(path.startsWith("META-INF/") || path.startsWith("${project.name}"))
}
}
// Copy scripts to web directory
copy {
includeEmptyDirs = false
from new File("build/classes/main")
into "${web_dir}/lib"
}
copy {
includeEmptyDirs = false
from new File("build/classes/test")
into "${web_dir}/lib"
}
}

View File

@ -0,0 +1 @@
rootProject.name = 'WebServer'

View File

@ -0,0 +1,26 @@
import org.w3c.fetch.RequestInit
import kotlin.browser.document
import kotlin.browser.window
import kotlin.js.Json
class Dashboard {
init {
window.fetch("/senddata/wastedata", RequestInit(method = "POST", body = "action=getStartHeaderData")).then { it -> it.text().then {
println("response text is: "+it)
val json = JSON.parse<Json>(it)
document.getElementById("total-connection-labels")?.innerHTML = json["collectionnumber"] as String
document.getElementById("planed-collection-label")?.innerHTML = json["futurecollections"] as String
document.getElementById("finished-collection-label")?.innerHTML = json["finshedcollections"] as String
document.getElementById("total-city-number-label")?.innerHTML = json["citynumber"] as String
} }
window.fetch("/senddata/wastedata", RequestInit(method = "POST", body = "action=getversionandbuildtime")).then { it -> it.text().then {
val json = JSON.parse<Json>(it)
document.getElementById("version-footer-label")?.innerHTML = "<b>Version</b> " + json["version"] + " <b>Build</b> " + json["buildtime"] as String
} }
}
}

39
WebServer/src/js/Index.kt Normal file
View File

@ -0,0 +1,39 @@
import org.w3c.dom.HTMLInputElement
import org.w3c.fetch.RequestInit
import kotlin.browser.document
import kotlin.browser.window
import kotlin.js.Json
class Index {
init {
document.getElementById("loginbtn")?.addEventListener("click", {
it.preventDefault()
println("clicked!!!")
val username = document.getElementById("userfield") as HTMLInputElement
val passfield = document.getElementById("passfield") as HTMLInputElement
println(username.value)
console.log("fetch 'data.json' with 'post'")
window.fetch("/senddata/loginget", RequestInit(method = "POST", body = "username=${username.value}&password=${passfield.value}")).then { response ->
response.text().then { text ->
val json = JSON.parse<Json>(text)
if (json["status"] == "nodbconn") {
js("""Swal.fire({
type: "error",
title: 'No connection to Database',
html: 'Setup DB here --> <a href="index.html">click<a/>.'
})""")
}
if (json["accept"] == true) {
println("successfully logged in!")
document.cookie = "username=$username"
window.location.replace("dashboard.html")
}
}
}
})
}
// todo register pwa correctly
}

18
WebServer/src/js/Main.kt Normal file
View File

@ -0,0 +1,18 @@
import kotlin.browser.window
fun main() {
val callurl = window.document.URL
window.onload = {
if (callurl.endsWith("/") || callurl.contains("index.html")) {
println("loaded sucessfully")
Index()
}
else if (callurl.contains("dashboard.html")) {
Dashboard()
}
else {
println("js called from undefined html file")
}
}
}

View File

@ -0,0 +1,15 @@
import org.w3c.xhr.XMLHttpRequest
class Requester {
fun request(){
val test = XMLHttpRequest()
test.open("GET","https://api.ipify.org?format=json")
test.onload = {
println(test.responseText)
}
test.send()
}
}

View File

@ -49,6 +49,8 @@ task createProperties(dependsOn: processResources) {
} }
} }
tasks.processResources.dependsOn("WebServer:build")
task myJavadocs(type: Javadoc) { task myJavadocs(type: Javadoc) {
title = "JAVADOC WasteInformationServer" title = "JAVADOC WasteInformationServer"
source = sourceSets.main.allJava source = sourceSets.main.allJava

View File

@ -1,2 +1,3 @@
rootProject.name = 'WasteInformationServer' rootProject.name = 'WasteInformationServer'
include 'WebServer'

View File

@ -17,7 +17,7 @@ public class LoginState {
private String email; private String email;
private int permission; private int permission;
boolean loggedin = false; boolean loggedin = true;
public void logIn() { public void logIn() {
loggedin = true; loggedin = true;

View File

@ -448,8 +448,8 @@
<!-- OWN --> <!-- OWN -->
<script type="text/javascript" src="js/dashboard.js"></script> <script type="text/javascript" src="js/lib/kotlin.js"></script>
<script src="js/userManager.js"></script> <script type="text/javascript" src="js/WasteInformationServer.js"></script>
</body> </body>
</html> </html>

View File

@ -24,13 +24,15 @@
<!--Custom styles--> <!--Custom styles-->
<link rel="stylesheet" type="text/css" href="css/index.css"> <link rel="stylesheet" type="text/css" href="css/index.css">
<script type="text/javascript" src="js/index.js"></script>
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script> <script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
<link rel="manifest" href="/manifest.json"> <link rel="manifest" href="/manifest.json">
<link rel="icon" type="image/png" href="/favicon.png"> <link rel="icon" type="image/png" href="/favicon.png">
<script type="text/javascript" src="js/lib/kotlin.js"></script>
<script type="text/javascript" src="js/WasteInformationServer.js"></script>
</head> </head>
<body> <body>
<div class="container"> <div class="container">