finished index page

started wit dashboad basicinfos
This commit is contained in:
Lukas-Heiligenbrunner 2020-02-18 22:21:10 +01:00
parent af321c8aad
commit b3960653ca
5 changed files with 71 additions and 28 deletions

View File

@ -0,0 +1,19 @@
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
} }
}
}

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
}

View File

@ -1,33 +1,18 @@
import org.w3c.dom.HTMLInputElement
import org.w3c.fetch.RequestInit
import org.w3c.xhr.XMLHttpRequest
import kotlin.browser.document
import kotlin.browser.window
fun main() {
val callurl = window.document.URL
if(callurl.contains("sec.html")){
document.write("Hello, in document 2!")
}else {
window.onload = {
window.onload = {
if (callurl.endsWith("/") || callurl.contains("index.html")) {
println("loaded sucessfully")
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 {
it.text().then { println(it) }
}
})
Index()
}
else if (callurl.contains("dashboard.html")) {
Dashboard()
}
else {
println("js called from undefined html file")
}
document.write("Hello, world!")
val req = Requester()
req.request()
}
}

View File

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

View File

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