Format TimetrackAccount related things

This commit is contained in:
Marcel Schwarz 2020-07-21 21:59:44 +02:00
parent 286d1c7fda
commit ebd5493e46
3 changed files with 162 additions and 168 deletions

View File

@ -1,5 +1,5 @@
<template > <template>
<v-container id = "createAccountListen"> <v-container id="createAccountListen">
<v-card align-center> <v-card align-center>
<p class="text-center logowhite--text" style="font-size:30pt">Details</p> <p class="text-center logowhite--text" style="font-size:30pt">Details</p>
@ -37,32 +37,33 @@
</v-container> </v-container>
</template> </template>
<script> <script>
import { baseUri } from "../variables"; import {baseUri} from "../variables";
export default {
name: "CreateTimeTrackAccount",
data: () => ({
user: sessionStorage.getItem("timeTrackAccountListUserId"),
newname: "",
newrevenue: "",
newdescription: "",
}),
methods: { export default {
addAccount() { name: "CreateTimeTrackAccount",
if (this.newname != "" || this.newrevenue != "" || this.newdescription != "") { data: () => ({
var xhttp = new XMLHttpRequest(); user: sessionStorage.getItem("timeTrackAccountListUserId"),
var suc; newname: "",
xhttp.onreadystatechange = function() { newrevenue: "",
if ((this.status == 201) & (this.readyState == 4)) { newdescription: "",
suc = true; }),
}
};
xhttp.open("POST", baseUri + "/accounts", false);
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt")); methods: {
xhttp.send( addAccount() {
"{" + if (this.newname != "" || this.newrevenue != "" || this.newdescription != "") {
var xhttp = new XMLHttpRequest();
var suc;
xhttp.onreadystatechange = function () {
if ((this.status == 201) & (this.readyState == 4)) {
suc = true;
}
};
xhttp.open("POST", baseUri + "/accounts", false);
xhttp.setRequestHeader("Content-Type", "application/json");
xhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
xhttp.send(
"{" +
'"user": "' + '"user": "' +
this.user + this.user +
'", "revenue": "' + '", "revenue": "' +
@ -72,22 +73,22 @@ export default {
'", "description": "' + '", "description": "' +
this.newdescription + this.newdescription +
'"}' '"}'
); );
if (suc == true ) { if (suc == true) {
this.$router.push("/timetrackaccounts"); this.$router.push("/timetrackaccounts");
}
} }
} },
}, },
}, mounted() {
mounted() { var listen = document.getElementById('createAccountListen');
var listen = document.getElementById('createAccountListen'); listen.addEventListener("keyup", e => {
listen.addEventListener("keyup", e => { if (e.keyCode === 13) {
if (e.keyCode === 13) { e.preventDefault();
e.preventDefault();
this.addAccount(); this.addAccount();
} }
}); });
} }
}; };
</script> </script>

View File

@ -1,5 +1,5 @@
<template > <template>
<v-container id = "editAccountListen"> <v-container id="editAccountListen">
<v-card align-center> <v-card align-center>
<div class="text-center ma-3"> <div class="text-center ma-3">
<p class="text-center logowhite--text" style="font-size:30pt">Account to edit:</p> <p class="text-center logowhite--text" style="font-size:30pt">Account to edit:</p>
@ -45,35 +45,35 @@
</template> </template>
<script> <script>
export default { export default {
name: "EditTimeTrackAccount", name: "EditTimeTrackAccount",
data: () => ({ data: () => ({
name: "", name: "",
revenue: "", revenue: "",
description: "", description: "",
newname: "", newname: "",
newrevenue: "", newrevenue: "",
newdescription: "", newdescription: "",
}), }),
methods: { methods: {
editAccount() { editAccount() {
var link = sessionStorage.getItem("timeTrackAccountEditSelfLink"); var link = sessionStorage.getItem("timeTrackAccountEditSelfLink");
if (this.newname != this.name || this.newrevenue != this.revenue || this.newdescription != this.description) { if (this.newname != this.name || this.newrevenue != this.revenue || this.newdescription != this.description) {
var xhttp = new XMLHttpRequest(); var xhttp = new XMLHttpRequest();
var suc; var suc;
xhttp.onreadystatechange = function() { xhttp.onreadystatechange = function () {
if ((this.status == 200) & (this.readyState == 4)) { if ((this.status == 200) & (this.readyState == 4)) {
suc =true; suc = true;
} }
}; };
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(
"{" + "{" +
'"name": "' + '"name": "' +
this.newname + this.newname +
'", "revenue": "' + '", "revenue": "' +
@ -81,49 +81,49 @@ export default {
'", "description": "' + '", "description": "' +
this.newdescription + this.newdescription +
'"}' '"}'
); );
if(suc ==true){ if (suc == true) {
this.$router.push( "/timetrackaccounts"); this.$router.push("/timetrackaccounts");
}
} }
} },
}, },
}, created() {
created() { var accountxhttp = new XMLHttpRequest();
var accountxhttp = new XMLHttpRequest(); var account;
var account;
accountxhttp.onreadystatechange = function() { accountxhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) { if (this.readyState == 4 && this.status == 200) {
account = JSON.parse(accountxhttp.responseText); account = JSON.parse(accountxhttp.responseText);
} }
}; };
accountxhttp.open( accountxhttp.open(
"GET", "GET",
sessionStorage.getItem("timeTrackAccountEditSelfLink"), sessionStorage.getItem("timeTrackAccountEditSelfLink"),
false false
); );
accountxhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt")); accountxhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
accountxhttp.send(null); accountxhttp.send(null);
this.name = account.name; this.name = account.name;
this.revenue = account.revenue; this.revenue = account.revenue;
this.description = account.description; this.description = account.description;
this.newname = account.name; this.newname = account.name;
this.newrevenue = account.revenue; this.newrevenue = account.revenue;
this.newdescription = account.description; this.newdescription = account.description;
}, },
mounted() { mounted() {
var listen = document.getElementById('editAccountListen'); var listen = document.getElementById('editAccountListen');
listen.addEventListener("keyup", e => { listen.addEventListener("keyup", e => {
if (e.keyCode === 13) { if (e.keyCode === 13) {
e.preventDefault(); e.preventDefault();
this.editAccount(); this.editAccount();
} }
}); });
} }
}; };
</script> </script>

View File

@ -10,7 +10,7 @@
<v-row> <v-row>
<v-col cols="6"></v-col> <v-col cols="6"></v-col>
<v-col cols="1"> <v-col cols="1">
<v-btn v-if="loggedIn == 'true'" fab color="primary" @click="createTimeTrackAccount()"> <v-btn v-if="loggedIn == 'true'" fab color="primary" @click="createTimeTrackAccount()">
<v-icon>mdi-plus</v-icon> <v-icon>mdi-plus</v-icon>
</v-btn> </v-btn>
</v-col> </v-col>
@ -20,73 +20,66 @@
</template> </template>
<script> <script>
import { baseUri} from "../variables.js"; import {baseUri} from "../variables.js";
import TimeTrackAccountItem from "./TimeTrackAccountItem.vue"; import TimeTrackAccountItem from "./TimeTrackAccountItem.vue";
export default { export default {
name: "TimeTrackAccounts", name: "TimeTrackAccounts",
components: { components: {
TimeTrackAccountItem TimeTrackAccountItem
}, },
data() { data() {
return { return {
timeTrackAccounts: "", timeTrackAccounts: "",
loggedIn: sessionStorage.getItem("loggedin") loggedIn: sessionStorage.getItem("loggedin")
}; };
}, },
methods: { methods: {
deleteTimeTrackAccount(selfLink) { deleteTimeTrackAccount(selfLink) {
var accountxhttp = new XMLHttpRequest();
accountxhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 204) {
location.reload();
}
};
accountxhttp.open("DELETE", selfLink, false);
accountxhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
accountxhttp.send(null);
},
editTimeTrackAccount(selfLink) {
sessionStorage.setItem("timeTrackAccountEditSelfLink", selfLink);
this.$router.push("/edittimetrackaccount");
},
createTimeTrackAccount() {
this.$router.push("/createtimetrackaccount");
}
},
created() {
var accounts;
var timeTrackAccountsTMP;
var accountxhttp = new XMLHttpRequest(); var accountxhttp = new XMLHttpRequest();
accountxhttp.onreadystatechange = function() { accountxhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 204) { if (this.readyState == 4 && this.status == 200) {
location.reload(); accounts = JSON.parse(accountxhttp.responseText);
timeTrackAccountsTMP = accounts._embedded.accounts;
} }
}; };
accountxhttp.open("DELETE", selfLink , false); accountxhttp.open(
"GET",
accountxhttp.setRequestHeader( baseUri +
"Authorization",
sessionStorage.getItem("jwt")
);
accountxhttp.send(null);
},
editTimeTrackAccount(selfLink) {
sessionStorage.setItem("timeTrackAccountEditSelfLink", selfLink);
this.$router.push( "/edittimetrackaccount");
},
createTimeTrackAccount() {
this.$router.push( "/createtimetrackaccount");
}
},
created() {
var accounts;
var timeTrackAccountsTMP;
var accountxhttp = new XMLHttpRequest();
accountxhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
accounts = JSON.parse(accountxhttp.responseText);
timeTrackAccountsTMP = accounts._embedded.accounts;
}
};
accountxhttp.open(
"GET",
baseUri +
"/accounts/search/findByUsername?username=" + "/accounts/search/findByUsername?username=" +
sessionStorage.getItem("timeTrackAccountListUser"), sessionStorage.getItem("timeTrackAccountListUser"),
false false
); );
accountxhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt")); accountxhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
accountxhttp.send(null);
accountxhttp.send(null); this.timeTrackAccounts = timeTrackAccountsTMP;
}
this.timeTrackAccounts = timeTrackAccountsTMP; };
}
};
</script> </script>
<style scoped> <style scoped>
</style> </style>