Format User related stuff

This commit is contained in:
Marcel Schwarz 2020-07-21 22:57:58 +02:00
parent ebd5493e46
commit 3321f4a58a
3 changed files with 213 additions and 252 deletions

View File

@ -4,8 +4,6 @@
<div class="text-center ma-3"> <div class="text-center ma-3">
<p class="text-center logowhite--text" style="font-size:30pt">User to edit:</p> <p class="text-center logowhite--text" style="font-size:30pt">User to edit:</p>
<p class="text-center logowhite--text" style="font-size:30pt">{{username}}</p> <p class="text-center logowhite--text" style="font-size:30pt">{{username}}</p>
</div> </div>
</v-card> </v-card>
<v-card align-center> <v-card align-center>
@ -74,6 +72,7 @@
</template> </template>
<script> <script>
import {baseUri} from "../variables"; import {baseUri} from "../variables";
export default { export default {
name: "Edituser", name: "Edituser",
data: () => ({ data: () => ({
@ -92,7 +91,6 @@ export default {
var suc; var suc;
if (this.firstname != "" && this.lastname != "") { if (this.firstname != "" && this.lastname != "") {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () { xhttp.onreadystatechange = function () {
if ((this.status == 200) & (this.readyState == 4)) { if ((this.status == 200) & (this.readyState == 4)) {
suc = true; suc = true;
@ -100,7 +98,6 @@ export default {
}; };
xhttp.open("PATCH", link, false); xhttp.open("PATCH", link, false);
xhttp.setRequestHeader("Content-Type", "application/json"); xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt")); xhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
xhttp.send( xhttp.send(
"{" + "{" +
@ -115,7 +112,6 @@ export default {
} }
} else if (this.firstname != "") { } else if (this.firstname != "") {
var xhttpfirst = new XMLHttpRequest(); var xhttpfirst = new XMLHttpRequest();
xhttpfirst.onreadystatechange = function () { xhttpfirst.onreadystatechange = function () {
if ((this.status == 200) & (this.readyState == 4)) { if ((this.status == 200) & (this.readyState == 4)) {
suc = true; suc = true;
@ -123,17 +119,13 @@ export default {
}; };
xhttpfirst.open("PATCH", link, false); xhttpfirst.open("PATCH", link, false);
xhttpfirst.setRequestHeader("Content-Type", "application/json"); xhttpfirst.setRequestHeader("Content-Type", "application/json");
xhttpfirst.setRequestHeader( xhttpfirst.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
"Authorization",
sessionStorage.getItem("jwt")
);
xhttpfirst.send("{" + '"firstname": "' + this.firstname + '"}'); xhttpfirst.send("{" + '"firstname": "' + this.firstname + '"}');
if (suc == true) { if (suc == true) {
this.$router.push("/users"); this.$router.push("/users");
} }
} else if (this.lastname != "") { } else if (this.lastname != "") {
var xhttplast = new XMLHttpRequest(); var xhttplast = new XMLHttpRequest();
xhttplast.onreadystatechange = function () { xhttplast.onreadystatechange = function () {
if ((this.status == 200) & (this.readyState == 4)) { if ((this.status == 200) & (this.readyState == 4)) {
suc = true; suc = true;
@ -141,10 +133,7 @@ export default {
}; };
xhttplast.open("PATCH", link, false); xhttplast.open("PATCH", link, false);
xhttplast.setRequestHeader("Content-Type", "application/json"); xhttplast.setRequestHeader("Content-Type", "application/json");
xhttplast.setRequestHeader( xhttplast.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
"Authorization",
sessionStorage.getItem("jwt")
);
xhttplast.send("{" + '"lastname": "' + this.lastname + '"}'); xhttplast.send("{" + '"lastname": "' + this.lastname + '"}');
if (suc == true) { if (suc == true) {
this.$router.push("/users"); this.$router.push("/users");
@ -158,14 +147,11 @@ export default {
var link = sessionStorage.getItem("edituser"); var link = sessionStorage.getItem("edituser");
if (this.longitude != "" && this.latitude != "" && this.radius) { if (this.longitude != "" && this.latitude != "" && this.radius) {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () { xhttp.onreadystatechange = function () {
if ((this.status == 201) & (this.readyState == 4)) { if ((this.status == 201) & (this.readyState == 4)) {
var location = JSON.parse(xhttp.responseText); var location = JSON.parse(xhttp.responseText);
sessionStorage.setItem("locationlink", location._links.self.href); sessionStorage.setItem("locationlink", location._links.self.href);
} else if (this.readyState == 4) { } else if (this.readyState == 4) {
numericerror = true; numericerror = true;
document.getElementById("locationnotcomplete").innerHTML = "Only numeric values are allowed"; document.getElementById("locationnotcomplete").innerHTML = "Only numeric values are allowed";
} }
@ -185,9 +171,7 @@ export default {
'"}' '"}'
); );
if (numericerror == false) { if (numericerror == false) {
var xhttpadd = new XMLHttpRequest(); var xhttpadd = new XMLHttpRequest();
var suc; var suc;
xhttpadd.onreadystatechange = function () { xhttpadd.onreadystatechange = function () {
@ -197,10 +181,7 @@ export default {
}; };
xhttpadd.open("PATCH", link, false); xhttpadd.open("PATCH", link, false);
xhttpadd.setRequestHeader("Content-Type", "application/json"); xhttpadd.setRequestHeader("Content-Type", "application/json");
xhttpadd.setRequestHeader( xhttpadd.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
"Authorization",
sessionStorage.getItem("jwt")
);
xhttpadd.send( xhttpadd.send(
"{" + "{" +
'"location": "' + '"location": "' +
@ -230,13 +211,9 @@ export default {
} }
}; };
userxhttp.open("GET", sessionStorage.getItem("edituser"), false); userxhttp.open("GET", sessionStorage.getItem("edituser"), false);
userxhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt")); userxhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
userxhttp.send(null); userxhttp.send(null);
this.username = sessionStorage.getItem("usernameedit"); this.username = sessionStorage.getItem("usernameedit");
} }
}; };
</script> </script>

View File

@ -1,7 +1,8 @@
<template> <template>
<v-container fluid> <v-container fluid>
<div v-bind:key="user.username" v-for="user in users"> <div v-bind:key="user.username" v-for="user in users">
<UsersItems v-bind:user="user" v-on:edit-user="edituser" v-on:del-user="deluser" v-on:show-accounts="showAccounts"/> <UsersItems v-bind:user="user" v-on:edit-user="edituser" v-on:del-user="deluser"
v-on:show-accounts="showAccounts"/>
</div> </div>
<v-row> <v-row>
<v-col cols="5"></v-col> <v-col cols="5"></v-col>
@ -23,6 +24,7 @@
<script> <script>
import {baseUri} from "../variables.js"; import {baseUri} from "../variables.js";
import UsersItems from "./UsersItems.vue"; import UsersItems from "./UsersItems.vue";
export default { export default {
components: { components: {
UsersItems UsersItems
@ -36,9 +38,7 @@ export default {
}), }),
methods: { methods: {
edituser(userlink) { edituser(userlink) {
sessionStorage.setItem("edituser", userlink); sessionStorage.setItem("edituser", userlink);
this.$router.push("/edituser"); this.$router.push("/edituser");
}, },
deluser(selfLink) { deluser(selfLink) {
@ -49,18 +49,12 @@ export default {
} }
}; };
userxhttp.open("DELETE", selfLink, false); userxhttp.open("DELETE", selfLink, false);
userxhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
userxhttp.setRequestHeader(
"Authorization",
sessionStorage.getItem("jwt")
);
userxhttp.send(null); userxhttp.send(null);
}, },
showAccounts(username, uid) { showAccounts(username, uid) {
sessionStorage.setItem("timeTrackAccountListUser", username); sessionStorage.setItem("timeTrackAccountListUser", username);
sessionStorage.setItem("timeTrackAccountListUserId", uid); sessionStorage.setItem("timeTrackAccountListUserId", uid);
this.$router.push("/timetrackaccounts"); this.$router.push("/timetrackaccounts");
}, },
nextPage() { nextPage() {
@ -84,10 +78,7 @@ export default {
xhttp.onreadystatechange = function () { xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) { if (this.readyState == 4 && this.status == 200) {
var usersInformation = JSON.parse(xhttp.responseText); var usersInformation = JSON.parse(xhttp.responseText);
sessionStorage.setItem( sessionStorage.setItem("users", JSON.stringify(usersInformation._embedded.users));
"users",
JSON.stringify(usersInformation._embedded.users)
);
userLinks = usersInformation._links; userLinks = usersInformation._links;
} }
}; };

View File

@ -8,7 +8,6 @@
<img src="https://cdn.vuetifyjs.com/images/john.jpg" alt="John"/> <img src="https://cdn.vuetifyjs.com/images/john.jpg" alt="John"/>
</v-avatar> </v-avatar>
</v-col> </v-col>
<v-col cols="3"> <v-col cols="3">
<v-card color="background" elevation="0"> <v-card color="background" elevation="0">
<pre><v-icon color="primary">mdi-account</v-icon>{{" " + user.username}}</pre> <pre><v-icon color="primary">mdi-account</v-icon>{{" " + user.username}}</pre>
@ -26,12 +25,7 @@
</v-row> </v-row>
</v-list-item-content> </v-list-item-content>
<v-list-item-action> <v-list-item-action>
<v-speed-dial <v-speed-dial v-model="fab" transition="slide-x-reverse-transition" direction="left" open-on-hover>
v-model="fab"
transition="slide-x-reverse-transition"
direction="left"
open-on-hover
>
<template v-slot:activator> <template v-slot:activator>
<v-btn v-model="fab" color="background" elevation="0" dark fab> <v-btn v-model="fab" color="background" elevation="0" dark fab>
<v-icon v-if="fab">mdi-close</v-icon> <v-icon v-if="fab">mdi-close</v-icon>
@ -64,7 +58,6 @@ export default {
getUid(hrefTmp) { getUid(hrefTmp) {
var parts = hrefTmp.split("/"); var parts = hrefTmp.split("/");
return parts[4]; return parts[4];
} }
} }
}; };