From 88abb2599a32c3f7fdf41d7bb78de77c8bdb649f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 29 Dec 2019 21:35:32 +0100 Subject: [PATCH] finanzer can add useres to DB in usercontent for finanzer, he can add amount or credit too bug fixes --- src/components/baruser/CreditLists.vue | 2 - src/components/finanzer/Overview.vue | 13 +++- src/components/finanzer/User.vue | 78 +++++++++++++++++++ src/plugins/restService.js | 3 + src/store/index.js | 1 - src/views/BarView.vue | 1 - src/views/FinanzerView.vue | 100 +++++++++++++++++++++---- src/views/Login.vue | 1 - 8 files changed, 178 insertions(+), 21 deletions(-) diff --git a/src/components/baruser/CreditLists.vue b/src/components/baruser/CreditLists.vue index ff69bab..bf0627d 100644 --- a/src/components/baruser/CreditLists.vue +++ b/src/components/baruser/CreditLists.vue @@ -79,8 +79,6 @@ } }, created() { - // eslint-disable-next-line no-console - console.log(this.users) }, methods: { addAmount(username, amount) { diff --git a/src/components/finanzer/Overview.vue b/src/components/finanzer/Overview.vue index 188b024..3521d18 100644 --- a/src/components/finanzer/Overview.vue +++ b/src/components/finanzer/Overview.vue @@ -45,6 +45,14 @@ + + + Status: + + + {{user.locked ? 'Gesperrt': 'nicht Gesperrt'}} + + Geld transferieren @@ -144,7 +152,7 @@ return lastYear + sum }, createYears() { - for (let year = 2000; year <= new Date().getFullYear(); year++) { + for (let year = new Date().getFullYear(); year >= 2000; year--) { this.years.push({value: year, text: year}) } }, @@ -185,6 +193,9 @@ this.filteredUsers = [...this.filteredUsers.filter(user => { return user.firstname.toLowerCase().includes(this.filter.toLowerCase()) || user.lastname.toLowerCase().includes(this.filter.toLowerCase()) })] + }, + getLockedColor (value) { + return value ? 'red' : 'green' } }, computed: { diff --git a/src/components/finanzer/User.vue b/src/components/finanzer/User.vue index 422bcc9..3b7de68 100644 --- a/src/components/finanzer/User.vue +++ b/src/components/finanzer/User.vue @@ -34,6 +34,37 @@ + + Geld transferieren + + + + + + + + + + + + + + + + + + + + Hinzufügen + +
{{year}} @@ -80,12 +111,36 @@ isNumber: value => !isNaN(value) || 'Betrag muss eine Zahl sein.', limit: null, autoLock: null, + amount: null, + selectYears: [], + months: [ + {value: 1, text: 'Januar'}, + {value: 2, text: 'Februar'}, + {value: 3, text: 'März'}, + {value: 4, text:'April'}, + {value: 5, text: 'Mai'}, + {value: 6, text: 'Juni'}, + {value: 7, text: 'Juli'}, + {value: 8, text: 'August'}, + {value: 9, text: 'September'}, + {value: 10, text: 'Oktober'}, + {value: 11, text: 'November'}, + {value: 12, text: 'Dezember'} + ], + type: {value: 'credit', text: 'Guthaben'}, + selectedYear: {value: new Date().getFullYear(), text: new Date().getFullYear()}, + selectedMonth: {value: new Date().getMonth() + 1, text: ["Januar", "Februar", "März", "April", "Mai", "Juni", + "Juli", "August", "September", "Oktober", "November", "Dezember" + ][new Date().getMonth()]} } }, created() { this.limit = (this.user.limit / 100).toFixed(2) this.autoLock = {value: this.user.autoLock, text: this.user.autoLock? "Aktiviert" : "Deaktiviert"} + for (let year = new Date().getFullYear(); year >= 2000; year--) { + this.selectYears.push({value: year, text: year}) + } }, methods: { getLastColor (value) { @@ -103,6 +158,29 @@ }, saveConfig() { this.$emit("save:config", {user: this.user, limit: this.limit, autoLock: this.autoLock.value}) + }, + add() { + if (this.type.value === 'amount') { + this.$emit("add:amount", {user: this.user, amount: this.amount, year: this.selectedYear.value, month: this.selectedMonth.value}) + } + if (this.type.value === 'credit') { + this.$emit("add:credit", {user: this.user, credit: this.amount, year: this.selectedYear.value, month: this.selectedMonth.value}) + } + + this.createDefault() + + }, + createDefault() { + // eslint-disable-next-line no-unused-vars + let year = new Date().getFullYear() + // eslint-disable-next-line no-unused-vars + let month = new Date().getMonth() + this.amount = null + this.type = {value: 'credit', text: 'Guthaben'} + this.selectedYear = {value: new Date().getFullYear(), text: new Date().getFullYear()} + this.selectedMonth = {value: new Date().getMonth() + 1, text: ["Januar", "Februar", "März", "April", "Mai", "Juni", + "Juli", "August", "September", "Oktober", "November", "Dezember" + ][new Date().getMonth()]} } }, computed: { diff --git a/src/plugins/restService.js b/src/plugins/restService.js index 8116027..ebb646f 100644 --- a/src/plugins/restService.js +++ b/src/plugins/restService.js @@ -38,6 +38,9 @@ class Service { finanzerSetConfig(token, data) { return axios.post(this.url+'finanzerSetConfig', {...data}, {headers: {Token: token}}) } + finanzerAddUser(token, data) { + return axios.post(this.url+'finanzerAddUser', {...data}, {headers: {Token: token}}) + } } const httpClient = new Service("http://localhost:5000/") diff --git a/src/store/index.js b/src/store/index.js index 8d4f7b4..c62f69d 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -22,7 +22,6 @@ export default new Vuex.Store({ state.loginError = errorMessage; }, updateAccessToken (state, data) { - // eslint-disable-next-line no-console if (typeof(data) === typeof("")) { data = JSON.parse(data) } diff --git a/src/views/BarView.vue b/src/views/BarView.vue index 4ade2f8..1605cda 100644 --- a/src/views/BarView.vue +++ b/src/views/BarView.vue @@ -28,7 +28,6 @@ }, methods: { getUser() { - // eslint-disable-next-line no-console this. users = [] httpClient.getUserBar(this.$store.getters.getToken) .then(response => { diff --git a/src/views/FinanzerView.vue b/src/views/FinanzerView.vue index 70ddb36..262b6da 100644 --- a/src/views/FinanzerView.vue +++ b/src/views/FinanzerView.vue @@ -19,12 +19,32 @@ {{user.lastname}}, {{user.firstname}} + - +
@@ -40,6 +60,14 @@ components: {User, Overview, TitleBar}, created() { this.getUser() + httpClient.searchUser(this.$store.getters.getToken, {searchString: ""}) + .then(response => { + 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 + } + }) }, data () { return { @@ -47,6 +75,8 @@ activeUser: { username: null, }, + allUsers: [], + user: null } }, methods: { @@ -54,7 +84,7 @@ if (this.activeUser.username === e.username) { this.activeUser = {username: null} } else { - this.activeUser = {...e} + this.activeUser = e } }, createAmount(creditList) { @@ -159,9 +189,6 @@ if (a.firstname < b.firstname) return -1 return 0 }) - - // eslint-disable-next-line no-console - 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}) @@ -171,13 +198,15 @@ let index = this.users.indexOf(user) let list = {} for (let creditList in response.data) { - - 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}] + if (creditList !== 'locked') { + 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}] + } } this.users[index].creditList = list + this.users[index].locked = response.data.locked }) .catch(error => { if (error.response) { @@ -187,6 +216,7 @@ } this.users = [] }) + this.users.find(a => {return a.username === this.activeUser.username}) }, addCredit(data) { @@ -197,13 +227,15 @@ let index = this.users.indexOf(user) let list = {} for (let creditList in response.data) { - - 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}] + if (creditList !== 'locked') { + 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}] + } } this.users[index].creditList = list + this.users[index].locked = response.data.locked }) .catch(error => { if (error.response) { @@ -213,6 +245,7 @@ } this.users = [] }) + this.users.find(a => {return a.username === this.activeUser.username}) }, deactivateAllUser() { for (let user in this.users) { @@ -249,6 +282,43 @@ } } }) + }, + addUser() { + httpClient.finanzerAddUser(this.$store.getters.getToken, {userId: this.user.username}) + .then(response => { + for (let username in response.data) { + let existUser = this.users.find(a => {return a.username === username}) + let list = {} + for (let creditList in response.data[username]['creditList']) { + let amount = this.createAmount(response.data[username]['creditList'][creditList]) + let credit = this.createCredit(response.data[username]['creditList'][creditList]) + let sum = this.createSum(credit, amount) + list[creditList] = [{...credit}, {...amount}, {...sum}] + } + if (existUser) { + existUser.firstname = response.data[username].firstname + existUser.lastname = response.data[username].lastname + existUser.limit = response.data[username].limit + existUser.locked = response.data[username].locked + existUser.autoLock = response.data[username].autoLock + existUser.creditList = list + } else { + const lastId = this.users.length > 0 ? this.users[this.users.length - 1].id : 0 + this.users.push({ + id: lastId + 1, + username: response.data[username].username, + firstname: response.data[username].firstname, + lastname: response.data[username].lastname, + limit: response.data[username].limit, + locked: response.data[username].locked, + autoLock: response.data[username].autoLock, + creditList: list, + expand: false, + active: false + }) + } + } + }) } } diff --git a/src/views/Login.vue b/src/views/Login.vue index fe1ec02..8d68a0e 100644 --- a/src/views/Login.vue +++ b/src/views/Login.vue @@ -75,7 +75,6 @@ }, methods: { login() { - // eslint-disable-next-line no-console let o = {username: this.username, password: this.password} this.$store.dispatch("doLogin", o) },