finished index page
started wit dashboad basicinfos
This commit is contained in:
parent
af321c8aad
commit
b3960653ca
19
WebServer/src/js/Dashboard.kt
Normal file
19
WebServer/src/js/Dashboard.kt
Normal 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
39
WebServer/src/js/Index.kt
Normal 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
|
||||||
|
}
|
@ -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
|
import kotlin.browser.window
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val callurl = window.document.URL
|
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")
|
println("loaded sucessfully")
|
||||||
document.getElementById("loginbtn")?.addEventListener("click",{
|
Index()
|
||||||
it.preventDefault()
|
}
|
||||||
println("clicked!!!")
|
else if (callurl.contains("dashboard.html")) {
|
||||||
|
Dashboard()
|
||||||
val username = document.getElementById("userfield") as HTMLInputElement
|
}
|
||||||
val passfield = document.getElementById("passfield") as HTMLInputElement
|
else {
|
||||||
println(username.value)
|
println("js called from undefined html file")
|
||||||
|
|
||||||
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) }
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
document.write("Hello, world!")
|
|
||||||
|
|
||||||
val req = Requester()
|
|
||||||
req.request()
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -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;
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user