add template to set Config for user with finanzer

fixed bugs
This commit is contained in:
Tim Gröger 2019-12-29 12:37:46 +01:00
parent 3d6d3259a5
commit 0dd2122a19
8 changed files with 113 additions and 79 deletions

View File

@ -1,9 +1,8 @@
<template>
<v-app-bar
app
flat
clipped-left
absolute
hide-on-scroll
color="blue accent-4"
class="elevation-4"
dark>

View File

@ -36,21 +36,15 @@
},
methods : {
mop () {
// eslint-disable-next-line no-console
console.log("user: ", this.user)
},
hasFocus () {
httpClient.searchUser(this.$store.getters.getToken, {searchString: this.searchString})
.then(response => {
// eslint-disable-next-line no-console
//console.log(response.data)
this.allUsers = response.data
for (let i = 0; i < this.allUsers.length; i++) {
this.allUsers[i].fullName = this.allUsers[i].firstname + " " + this.allUsers[i].lastname
}
// eslint-disable-next-line no-console
console.log("all users 2: ", this.allUsers)
})
},
addUser() {

View File

@ -141,8 +141,6 @@
return value < 0 ? 'red' : 'green'
},
getAllSum(sum, lastYear) {
// eslint-disable-next-line no-console
console.log(sum, lastYear)
return lastYear + sum
},
createYears() {
@ -158,8 +156,6 @@
},
// eslint-disable-next-line no-unused-vars
add(user) {
// eslint-disable-next-line no-console
console.log(this.selectedYear.value, this.type.value, this.selectedMonth.value)
if (this.type.value === 'amount') {
this.$emit("add:amount", {user: user, amount: this.amount, year: this.selectedYear.value, month: this.selectedMonth.value})
}

View File

@ -3,6 +3,37 @@
<v-toolbar tile>
<v-toolbar-title>{{user.lastname}}, {{user.firstname}}</v-toolbar-title>
</v-toolbar>
<v-card style="margin-top: 3px;">
<v-card-title>Konfiguration</v-card-title>
<v-card-text>
<v-form style="margin-left: 15px; margin-right: 15px">
<v-row>
<v-col>
<v-label>Status: </v-label>
</v-col>
<v-col>
<v-chip outlined :text-color="getLockedColor(user.locked)">{{user.locked ? 'Gesperrt': 'nicht Gesperrt'}}</v-chip>
</v-col>
<v-col>
<v-btn @click="lock">{{user.locked ? 'Entperren' : 'Sperren'}}</v-btn>
</v-col>
</v-row>
<v-divider style="margin-bottom: 15px;"/>
<v-row>
<v-col>
<v-text-field :rules="[isNumber]" label="Betrag des Sperrlimits in € (EURO)" v-model="limit"></v-text-field>
</v-col>
<v-col>
<v-select return-object v-model="autoLock" label="Automatische Sperre" :items="[{value: true, text: 'Aktiviert'}, {value: false, text: 'Deaktiviert'}]"
item-text="text" item-value="value"/>
</v-col>
</v-row>
<v-row>
<v-btn block @click="saveConfig">Speichern</v-btn>
</v-row>
</v-form>
</v-card-text>
</v-card>
<div v-for="year in years" :key="years.indexOf(year)">
<v-card style="margin-top: 3px;">
<v-card-title>{{year}}</v-card-title>
@ -46,29 +77,48 @@
},
data () {
return {
years: []
isNumber: value => !isNaN(value) || 'Betrag muss eine Zahl sein.',
limit: null,
autoLock: null,
}
},
created() {
this.createYears()
this.limit = (this.user.limit / 100).toFixed(2)
this.autoLock = {value: this.user.autoLock, text: this.user.autoLock? "Aktiviert" : "Deaktiviert"}
},
methods: {
createYears() {
// eslint-disable-next-line no-console
console.log(this.user.creditList)
for (let year in this.user.creditList) {
// eslint-disable-next-line no-console
this.years.unshift(parseInt(year))
}
},
getLastColor (value) {
return value < 0 ? 'red' : 'green'
},
getAllSum(sum, lastYear) {
// eslint-disable-next-line no-console
console.log(sum, lastYear)
return lastYear + sum
},
getLockedColor (value) {
return value ? 'red' : 'green'
},
lock() {
this.user.locked = !this.user.locked
this.$emit("do:lock", {user: this.user, locked: this.user.locked})
},
saveConfig() {
this.$emit("save:config", {user: this.user, limit: this.limit, autoLock: this.autoLock.value})
}
},
computed: {
years() {
let years = []
for (let year in this.user.creditList) {
years.unshift(parseInt(year))
}
return years
}
},
watch: {
user(newVal) {
this.limit = (newVal.limit / 100).toFixed(2)
this.autoLock = {value: newVal.autoLock, text: newVal.autoLock? "Aktiviert" : "Deaktiviert"}
}
}
}
</script>

View File

@ -15,16 +15,12 @@ class Service {
return axios.get(this.url+'bar', {headers: {Token: token}})
}
addAmountBar(token, data) {
// eslint-disable-next-line no-console
console.log("addAmountdata: ", data)
return axios.post(this.url+'baradd', {...data}, {headers: {Token: token}})
}
addAmountFinanzer(token, data) {
return axios.post(this.url+'finanzerAddAmount', {...data}, {headers: {Token: token}})
}
addCreditFinanzer(token, data) {
// eslint-disable-next-line no-console
console.log('data', data)
return axios.post(this.url+'finanzerAddCredit', {...data}, {headers: {Token: token}})
}
searchUser(token, data) {
@ -33,9 +29,16 @@ class Service {
getAllUser(token) {
return axios.get(this.url+'barGetUsers', {headers: {Token: token}})
}
lockUser(token, data) {
return axios.post(this.url+'finanzerLock', {...data}, {headers: {Token: token}})
}
finanzerSetConfig(token, data) {
return axios.post(this.url+'finanzerSetConfig', {...data}, {headers: {Token: token}})
}
}
const httpClient = new Service("http://localhost:5000/")
//const httpClient = new Service("http://192.168.5.118:5000/")
const httpClient = new Service("http://groeger-clan.duckdns.org:5000/")
//const httpClient = new Service("http://groeger-clan.duckdns.org:5000/")
export default httpClient

View File

@ -26,8 +26,6 @@ export default new Vuex.Store({
if (typeof(data) === typeof("")) {
data = JSON.parse(data)
}
// eslint-disable-next-line no-console
console.log("updateAccessToken data:", typeof (data), data)
if (data === null || data === undefined) {
state.user.username = null;
state.user.accessToken = null;
@ -36,8 +34,6 @@ export default new Vuex.Store({
this.state.user.username = data.username;
state.user.accessToken = data.accessToken;
state.user.group = data.group;
// eslint-disable-next-line no-console
console.log("state: ", state.user)
}
},
logout (state) {
@ -48,8 +44,6 @@ export default new Vuex.Store({
},
actions: {
doLogin({ commit }, loginData) {
// eslint-disable-next-line no-console
console.log("loginData:", loginData)
commit('loginStart');
httpClient.login(loginData)
.then(response => {
@ -69,8 +63,6 @@ export default new Vuex.Store({
})
},
fetchAccessToken({ commit }) {
// eslint-disable-next-line no-console
console.log("localStorage: ", localStorage.getItem('user'))
commit('updateAccessToken', localStorage.getItem('user'))
},
logout({ commit }) {

View File

@ -32,8 +32,6 @@
this. users = []
httpClient.getUserBar(this.$store.getters.getToken)
.then(response => {
// eslint-disable-next-line no-console
console.log(response.data)
for (let user in response.data) {
const lastId = this.users.length > 0 ? this.users[this.users.length - 1].id : 0
this.users.push({
@ -41,6 +39,7 @@
username: response.data[user].username,
firstname: response.data[user].firstname,
lastname: response.data[user].lastname,
locked: response.data[user].locked,
amount: response.data[user].amount,
type: response.data[user].type
})
@ -48,7 +47,7 @@
})
.catch(error => {
if (error.response) {
if (error.response.status == 401) {
if (error.response.status === 401) {
this.$store.dispatch('logout')
}
}
@ -64,20 +63,14 @@
addAmount(username, amount) {
httpClient.addAmountBar(this.$store.getters.getToken, {userId: username, amount: amount})
.then((response) => {
// eslint-disable-next-line no-console
console.log(response.data)
let user = this.users.find(user => {
// eslint-disable-next-line no-console
console.log(user)
return user.username === username ? user : false
})
user.amount = response.data.amount
})
.catch(error => {
if (error.response) {
if (error.response.status == 401) {
if (error.response.status === 401) {
this.$store.dispatch('logout')
}
}
@ -85,8 +78,6 @@
})
},
addCreditList(user) {
// eslint-disable-next-line no-console
console.log('addCreditlist: ', user)
if (!this.users.find(user1 => {
return user1.username === user.username
})) {

View File

@ -24,7 +24,7 @@
<Overview v-bind:users="users" @add:amount="addAmount" @add:credit="addCredit"/>
</v-content>
<v-content v-else>
<User v-bind:user="activeUser"/>
<User v-bind:user="activeUser" @do:lock="doLock" @save:config="saveConfig"/>
</v-content>
</div>
</template>
@ -51,8 +51,6 @@
},
methods: {
test (e) {
// eslint-disable-next-line no-console
console.log("event: ", e)
if (this.activeUser.username === e.username) {
this.activeUser = {username: null}
} else {
@ -121,31 +119,25 @@
getUser() {
httpClient.getFinanzerMain(this.$store.getters.getToken)
.then(response => {
// eslint-disable-next-line no-console
console.log("ich bin hier. response: ", response.data)
for (let user in response.data) {
// eslint-disable-next-line no-console
console.log("user: ", user)
const lastId = this.users.length > 0 ? this.users[this.users.length - 1].id : 0
// eslint-disable-next-line no-unused-vars
let list = {}
for (let creditList in response.data[user]['creditList']) {
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line no-console
console.log('creditList: ', creditList, response.data[user]['creditList'])
let amount = this.createAmount(response.data[user]['creditList'][creditList])
let credit = this.createCredit(response.data[user]['creditList'][creditList])
let sum = this.createSum(credit, amount)
list[creditList] = [{...credit}, {...amount}, {...sum}]
// eslint-disable-next-line no-console
console.log("creditList list:", creditList, list)
}
this.users.push({
id: lastId + 1,
username: response.data[user].username,
firstname: response.data[user].firstname,
lastname: response.data[user].lastname,
limit: response.data[user].limit,
locked: response.data[user].locked,
autoLock: response.data[user].autoLock,
creditList: list,
expand: false,
active: false
@ -153,7 +145,7 @@
}})
.catch(error => {
if (error.response) {
if (error.response.status == 401) {
if (error.response.status === 401) {
this.$store.dispatch('logout')
}
}
@ -169,34 +161,27 @@
})
// eslint-disable-next-line no-console
console.log("this.users: ", this.users)
console.log(this.users)
},
addAmount(data) {
httpClient.addAmountFinanzer(this.$store.getters.getToken, {userId: data.user.username, amount: data.amount * 100, year: data.year, month: data.month})
.then(response => {
// eslint-disable-next-line no-console
console.log(response.data)
let user = this.users.find(user => {return user.username === data.user.username})
let index = this.users.indexOf(user)
let list = {}
for (let creditList in response.data) {
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line no-console
console.log('creditList: ', creditList, response.data[creditList])
let amount = this.createAmount(response.data[creditList])
let credit = this.createCredit(response.data[creditList])
let sum = this.createSum(credit, amount)
list[creditList] = [{...credit}, {...amount}, {...sum}]
// eslint-disable-next-line no-console
console.log("creditList list:", creditList, list)
}
this.users[index].creditList = list
})
.catch(error => {
if (error.response) {
if (error.response.status == 401) {
if (error.response.status === 401) {
this.$store.dispatch('logout')
}
}
@ -207,29 +192,22 @@
httpClient.addCreditFinanzer(this.$store.getters.getToken, {userId: data.user.username, credit: data.credit * 100, year: data.year, month: data.month})
.then(response => {
// eslint-disable-next-line no-console
console.log(response.data)
let user = this.users.find(user => {return user.username === data.user.username})
let index = this.users.indexOf(user)
let list = {}
for (let creditList in response.data) {
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line no-console
console.log('creditList: ', creditList, response.data[creditList])
let amount = this.createAmount(response.data[creditList])
let credit = this.createCredit(response.data[creditList])
let sum = this.createSum(credit, amount)
list[creditList] = [{...credit}, {...amount}, {...sum}]
// eslint-disable-next-line no-console
console.log("creditList list:", creditList, list)
}
this.users[index].creditList = list
})
.catch(error => {
if (error.response) {
if (error.response.status == 401) {
if (error.response.status === 401) {
this.$store.dispatch('logout')
}
}
@ -240,6 +218,37 @@
for (let user in this.users) {
user.active = false
}
},
doLock(data) {
httpClient.lockUser(this.$store.getters.getToken, {userId: data.user.username, locked: data.locked})
.then(response => {
let user = this.users.find(user => {return user.username === data.user.username})
let index = this.users.indexOf(user)
this.users[index].locked = response.data.locked
})
.catch(error => {
if (error.response) {
if (error.response.status === 401) {
this.$store.dispatch('logout')
}
}
})
},
saveConfig(data) {
httpClient.finanzerSetConfig(this.$store.getters.getToken, {userId: data.user.username, limit: data.limit * 100, autoLock: data.autoLock})
.then(response => {
let user = this.users.find(user => {return user.username === data.user.username})
let index = this.users.indexOf(user)
this.users[index].limit = response.data.limit
this.users[index].autoLock = response.data.autoLock
})
.catch(error => {
if (error.response) {
if (error.response.status === 401) {
this.$store.dispatch('logout')
}
}
})
}
}