From e366a2583815543b5d70749b860b1b853fff6adc Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 27 Jan 2021 02:40:24 +0100 Subject: [PATCH 1/5] Save transactions in store and allow setting and getting a single user from store --- src/plugins/balance/store/balance.ts | 31 +++++++++++++++++++++------- src/plugins/user/store/user.ts | 22 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/plugins/balance/store/balance.ts b/src/plugins/balance/store/balance.ts index 880b641..e675b72 100644 --- a/src/plugins/balance/store/balance.ts +++ b/src/plugins/balance/store/balance.ts @@ -16,6 +16,7 @@ export interface UserBalance extends BalanceResponse { export interface BalanceInterface { balances: Map; shortcuts: Array; + transactions: Array; loading: number; } @@ -26,6 +27,7 @@ export interface StateInterfaceBalance extends StateInterface { const state: BalanceInterface = { balances: new Map(), shortcuts: [], + transactions: [], loading: 0 }; @@ -53,6 +55,15 @@ const mutations: MutationTree = { }, setShortcuts(state, data: Array) { state.shortcuts.splice(0, state.shortcuts.length, ...data); + }, + addTransaction(state, data: FG.Transaction) { + state.transactions.push(data); + }, + reverseTransaction(state, data: { transaction: FG.Transaction; reversal: FG.Transaction }) { + const idx = state.transactions.findIndex(value => value.id === data.transaction.id); + data.transaction.reversal = data.reversal; + if (idx > -1) state.transactions[idx] = data.transaction; + else state.transactions.push(data.transaction); } }; @@ -111,16 +122,22 @@ const actions: ActionTree = { }) .finally(() => commit('setLoading', false)); }, - revert({ dispatch }, transaction: FG.Transaction) { - return axios.delete(`/balance/${transaction.id}`).then(() => { - dispatch('getBalance').catch(err => console.warn(err)); - }); + revert({ dispatch, commit }, transaction: FG.Transaction) { + return axios + .delete(`/balance/${transaction.id}`) + .then((response: AxiosResponse) => { + commit('reverseTransaction', { transaction: transaction, reversal: response.data }); + dispatch('getBalance').catch(err => console.warn(err)); + }); }, changeBalance({ dispatch, commit }, data: { amount: number; user: string; sender?: string }) { commit('setLoading'); return axios .put(`/users/${data.user}/balance`, data) .then((response: AxiosResponse) => { + const transaction = response.data; + transaction.time = new Date(transaction.time); + commit('addTransaction', transaction); commit(state.balances.has(data.user) ? 'changeBalance' : 'setBalance', { userid: data.user, amount: data.amount @@ -130,12 +147,12 @@ const actions: ActionTree = { userid: data.sender, amount: -1 * data.amount }); - return response.data; + return transaction; }) .catch(err => { + console.debug(err); // Maybe Balance changed - dispatch('getBalance').catch(err => console.warn(err)); - console.warn(err); + return dispatch('getBalance', data.sender ? data.sender : data.user); }) .finally(() => commit('setLoading', false)); } diff --git a/src/plugins/user/store/user.ts b/src/plugins/user/store/user.ts index 8f1e785..1d520d2 100644 --- a/src/plugins/user/store/user.ts +++ b/src/plugins/user/store/user.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unsafe-call */ import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'; import { StateInterface } from 'src/store'; import { axios } from 'boot/axios'; @@ -48,6 +49,11 @@ const mutations: MutationTree = { setUsers(state, data: FG.User[]) { state.users = data; }, + setUser(state, data: FG.User) { + const index = state.users.findIndex(x => x.userid === data.userid); + if (index > -1) state.users[index] = data; + else state.users.push(data); + }, setRoles(state, data: FG.Role[]) { state.roles = data; }, @@ -221,10 +227,26 @@ const actions: ActionTree = { commit('setPermissions', response.data); }) .finally(() => commit('setLoading', false)); + }, + getUser({ commit, getters }, data: { userid: string; force?: boolean }) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + const user = getters['getUser'](data.userid); + if (user === undefined || data.force === true) { + return axios.get(`/users/${data.userid}`).then((response: AxiosResponse) => { + commit('setUser', response.data); + return response.data; + }); + } else { + return Promise.resolve(user); + } } }; const getters: GetterTree = { + getUser: state => (userid: string) => { + const user = state.users.filter(usr => usr.userid === userid); + return user.length > 0 ? user[0] : undefined; + }, currentUser({ currentUser }) { return currentUser; }, From a787abdbc0b949b048b541ca47e4abc1f907b500 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 27 Jan 2021 02:40:47 +0100 Subject: [PATCH 2/5] Improved Transaction design and function --- .vscode/settings.json | 3 +- .../balance/components/Transaction.vue | 101 ++++++++++++------ src/plugins/balance/pages/Add.vue | 20 +--- src/plugins/balance/pages/Transfer.vue | 16 +-- 4 files changed, 77 insertions(+), 63 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 89e30df..ae2ea04 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,5 +24,6 @@ "sortAttributes": false } }, - "vetur.format.defaultFormatter.ts": "prettier-tslint" + "vetur.format.defaultFormatter.ts": "prettier-tslint", + "typescript.format.enable": false } diff --git a/src/plugins/balance/components/Transaction.vue b/src/plugins/balance/components/Transaction.vue index 5e51920..e64cd31 100644 --- a/src/plugins/balance/components/Transaction.vue +++ b/src/plugins/balance/components/Transaction.vue @@ -1,24 +1,33 @@ diff --git a/src/plugins/balance/pages/Add.vue b/src/plugins/balance/pages/Add.vue index 1a179a1..19706e1 100644 --- a/src/plugins/balance/pages/Add.vue +++ b/src/plugins/balance/pages/Add.vue @@ -56,8 +56,9 @@ -
- +
+ +
@@ -80,7 +81,7 @@ export default defineComponent({ const amount = ref(0); const showAddShortcut = ref(false); - const transactions = ref([]); + const transactions = computed(() => store.state.balance.transactions.slice().reverse()); const user = ref(store.state.user.currentUser); const shortCuts = ref(store.state.balance.shortcuts); @@ -89,7 +90,7 @@ export default defineComponent({ ); function addShortcut() { - void store.dispatch('balance/addShortcut', amount.value * -1); + if (amount.value != 0) void store.dispatch('balance/addShortcut', amount.value * -1); } function removeShortcut(shortcut: number) { void store.dispatch('balance/removeShortcut', shortcut); @@ -100,19 +101,9 @@ export default defineComponent({ function changeBalance(amount: number) { store .dispatch('balance/changeBalance', { amount: amount, user: user.value?.userid }) - .then((transaction: FG.Transaction) => { - if (transactions.value.length > 5) transactions.value.pop(); - transaction.time = new Date(transaction.time); - transactions.value.unshift(transaction); - console.log(transactions.value); - }) .catch(err => console.log(err)); } - function reversed(id: number) { - transactions.value = transactions.value.filter(t => t.id != id); - } - return { user, addShortcut, @@ -123,7 +114,6 @@ export default defineComponent({ amount, showSelector, shortCuts, - reversed, userUpdated }; } diff --git a/src/plugins/balance/pages/Transfer.vue b/src/plugins/balance/pages/Transfer.vue index 83a7f0e..eaa021f 100644 --- a/src/plugins/balance/pages/Transfer.vue +++ b/src/plugins/balance/pages/Transfer.vue @@ -31,7 +31,7 @@
- +
@@ -56,7 +56,7 @@ export default defineComponent({ const sender = ref(store.state.user.currentUser); const receiver = ref(undefined); const amount = ref(0); - const transactions = ref([]); + const transactions = computed(() => store.state.balance.transactions.slice().reverse()); const sendDisabled = computed(() => { return !( @@ -75,10 +75,6 @@ export default defineComponent({ receiver.value = selectedUser; } - function reversed(id: number) { - transactions.value = transactions.value.filter(value => value.id != id); - } - function sendAmount() { store .dispatch('balance/changeBalance', { @@ -86,11 +82,6 @@ export default defineComponent({ sender: sender.value?.userid, user: receiver.value?.userid }) - .then((transaction: FG.Transaction) => { - if (transactions.value.length > 5) transactions.value.pop(); - transaction.time = new Date(transaction.time); - transactions.value.unshift(transaction); - }) .catch(err => console.log(err)); } @@ -103,8 +94,7 @@ export default defineComponent({ showSelector, senderUpdated, receiverUpdated, - sendDisabled, - reversed + sendDisabled }; } }); From 91200f277ceceee38c2998983eb2feed4be43c54 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 27 Jan 2021 02:47:19 +0100 Subject: [PATCH 3/5] Display Balance as fixed --- src/plugins/balance/pages/Admin.vue | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/balance/pages/Admin.vue b/src/plugins/balance/pages/Admin.vue index a0c0eb1..cde0f97 100644 --- a/src/plugins/balance/pages/Admin.vue +++ b/src/plugins/balance/pages/Admin.vue @@ -40,7 +40,12 @@ export default defineComponent({ align: 'left', sortable: true }, - { name: 'balance', label: 'Kontostand', field: 'balance' }, + { + name: 'balance', + label: 'Kontostand', + field: 'balance', + format: (val: number) => val.toFixed(2) + }, { name: 'limit', label: 'Limit', From 693b6a11d34801481624987127df033dedfdb12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Wed, 27 Jan 2021 08:16:44 +0100 Subject: [PATCH 4/5] prettier all files --- src/components/navigation/EmptyParent.vue | 2 +- src/components/navigation/EssentialLink.vue | 8 +-- src/components/navigation/ShortCutLink.vue | 4 +- src/components/utils/IsoDateInput.vue | 12 ++-- src/layouts/MainLayout.vue | 26 ++++----- src/layouts/OutLayout.vue | 2 +- src/pages/Dashboard.vue | 15 ++--- src/pages/Offline.vue | 21 ++++--- src/pages/PluginError.vue | 35 +++++++---- src/pages/about/About.vue | 26 ++++----- src/plugins/balance/pages/MainPage.vue | 5 +- src/plugins/user/components/UpdateUser.vue | 16 ++--- src/plugins/user/components/Widget.vue | 25 ++++---- .../user/components/settings/RoleSettings.vue | 58 ++++++------------- .../user/components/settings/Sessions.vue | 12 +--- src/plugins/user/pages/AdminSettings.vue | 41 ++++--------- src/plugins/user/pages/MainPage.vue | 5 +- src/plugins/user/pages/Settings.vue | 11 +--- 18 files changed, 126 insertions(+), 198 deletions(-) diff --git a/src/components/navigation/EmptyParent.vue b/src/components/navigation/EmptyParent.vue index 4dc75e8..f9817a4 100644 --- a/src/components/navigation/EmptyParent.vue +++ b/src/components/navigation/EmptyParent.vue @@ -9,6 +9,6 @@ export default defineComponent({ name: 'EmptyParent', setup() { return {}; - }, + } }); diff --git a/src/components/navigation/EssentialLink.vue b/src/components/navigation/EssentialLink.vue index ddc7434..bb03bf4 100644 --- a/src/components/navigation/EssentialLink.vue +++ b/src/components/navigation/EssentialLink.vue @@ -49,18 +49,14 @@ export default defineComponent({ if (props.title.includes('loadFromStore')) { const startIndex = props.title.indexOf('(') + 1; const endIndex = props.title.indexOf(')'); - const substring = props.title - .substring(startIndex, endIndex) - .replace(/"/g, ''); + const substring = props.title.substring(startIndex, endIndex).replace(/"/g, ''); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access return root.$store.getters[substring]; } return props.title; }); - const isGranted = computed(() => - hasPermissions(props.permissions || [], root.$store) - ); + const isGranted = computed(() => hasPermissions(props.permissions || [], root.$store)); return { realTitle: title, isGranted }; } diff --git a/src/components/navigation/ShortCutLink.vue b/src/components/navigation/ShortCutLink.vue index e06d77d..1a09398 100644 --- a/src/components/navigation/ShortCutLink.vue +++ b/src/components/navigation/ShortCutLink.vue @@ -22,9 +22,7 @@ export default defineComponent({ } }, setup(props, { root }) { - const isGranted = computed(() => - hasPermissions(props.permissions || [], root.$store) - ); + const isGranted = computed(() => hasPermissions(props.permissions || [], root.$store)); return { isGranted }; } }); diff --git a/src/components/utils/IsoDateInput.vue b/src/components/utils/IsoDateInput.vue index 02009d0..517efee 100644 --- a/src/components/utils/IsoDateInput.vue +++ b/src/components/utils/IsoDateInput.vue @@ -49,18 +49,18 @@ export default defineComponent({ name: 'IsoDateInput', props: { value: { - required: true, + required: true }, label: {}, readonly: { - default: false, + default: false }, type: { default: 'date', validator: function(value: string) { return ['date', 'time', 'datetime'].indexOf(value) !== -1; - }, - }, + } + } }, setup(props: Props, { emit }: { emit: any }) { function getDateTime() { @@ -183,8 +183,8 @@ export default defineComponent({ rules, timeChanged, placeholder, - dateTimeChanged, + dateTimeChanged }; - }, + } }); diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index 3a79cfa..e826db5 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -112,23 +112,23 @@ const links = [ name: 'about', title: 'Über Flaschengeist', link: 'about', - icon: 'mdi-information', - }, + icon: 'mdi-information' + } ]; const shortcuts = [ { link: 'about', - icon: 'mdi-information', + icon: 'mdi-information' }, { link: 'user', - icon: 'mdi-account', + icon: 'mdi-account' }, { link: 'user-plugin1', - icon: 'mdi-account-plus', - }, + icon: 'mdi-account-plus' + } ]; declare module 'vue/types/vue' { @@ -146,7 +146,7 @@ export default defineComponent({ const leftDrawerOpen = ref( computed({ get: () => (leftDrawer.value || Screen.gt.sm ? true : false), - set: (val: boolean) => (leftDrawer.value = val), + set: (val: boolean) => (leftDrawer.value = val) }) ); const leftDrawerMini = ref(false); @@ -177,11 +177,9 @@ export default defineComponent({ function logout() { Loading.show({ message: 'Session wird abgemeldet' }); - (>ctx.root.$store) - .dispatch('session/logout') - .finally(() => { - Loading.hide(); - }); + (>ctx.root.$store).dispatch('session/logout').finally(() => { + Loading.hide(); + }); } return { @@ -191,8 +189,8 @@ export default defineComponent({ links, pluginChildLinks, shortcuts, - logout, + logout }; - }, + } }); diff --git a/src/layouts/OutLayout.vue b/src/layouts/OutLayout.vue index 05f4fb5..cda1c88 100644 --- a/src/layouts/OutLayout.vue +++ b/src/layouts/OutLayout.vue @@ -49,6 +49,6 @@ import ShortCutLink from 'components/navigation/ShortCutLink.vue'; export default defineComponent({ name: 'OutLayout', - components: { ShortCutLink }, + components: { ShortCutLink } }); diff --git a/src/pages/Dashboard.vue b/src/pages/Dashboard.vue index 65ddc78..4040ac7 100644 --- a/src/pages/Dashboard.vue +++ b/src/pages/Dashboard.vue @@ -4,11 +4,7 @@ style="grid-auto-rows: 1fr;" class="fit row justify-around items-start q-col-gutter-sm" > -
+
@@ -25,15 +21,14 @@ export default defineComponent({ const widgets = ref>([]); onMounted(() => { - root.$flaschengeistPlugins.widgets.forEach((widget) => { - if (hasPermissions(widget.permissions, root.$store)) - widgets.value.push(widget.widget); + root.$flaschengeistPlugins.widgets.forEach(widget => { + if (hasPermissions(widget.permissions, root.$store)) widgets.value.push(widget.widget); }); }); return { - widgets, + widgets }; - }, + } }); diff --git a/src/pages/Offline.vue b/src/pages/Offline.vue index 4c83970..3906b4f 100644 --- a/src/pages/Offline.vue +++ b/src/pages/Offline.vue @@ -12,14 +12,16 @@ fill="white" > - + + + - - -
@@ -27,7 +29,8 @@ Der Admin is über's Kabel gestolpert!
- Aktuell kann der Backend Server nicht erreicht werden, wir versuchen es in {{reload}} Sekunden erneut. + Aktuell kann der Backend Server nicht erreicht werden, wir versuchen es in + {{ reload }} Sekunden erneut.
@@ -49,6 +52,6 @@ export default defineComponent({ }, 1000); onUnmounted(() => clearInterval(ival)); return { reload }; - }, + } }); diff --git a/src/pages/PluginError.vue b/src/pages/PluginError.vue index ca1c3e8..ca2165c 100644 --- a/src/pages/PluginError.vue +++ b/src/pages/PluginError.vue @@ -2,12 +2,26 @@
- + - - - - + + + +
@@ -15,20 +29,19 @@ Der Admin war betrunken!!
- Einige Plugins konnten nicht geladen werden.
Sollte diese Seite jemals auftauchen, kontaktiere einen nüchternen Admin. + Einige Plugins konnten nicht geladen werden.
Sollte diese Seite jemals auftauchen, + kontaktiere einen nüchternen Admin.
- + diff --git a/src/pages/about/About.vue b/src/pages/about/About.vue index 9072724..47184d8 100644 --- a/src/pages/about/About.vue +++ b/src/pages/about/About.vue @@ -6,7 +6,7 @@ >
@@ -17,16 +17,14 @@
- Flaschengeist ist ein dynamischen Managementsystem für Studentenclubs. - Es ermöglicht unter anderem die Mitgliederverwaltung, Dienstverwaltung, - Arbeitsgruppenverwaltung und vieles meher. Es kann fast alles ermöglich - werden, wenn ein Plugin dafür geschrieben wird. Jeder Club hat die - Möglichkeit sein eigenes Flaschengeist zu hosten. Ziel ist später + Flaschengeist ist ein dynamischen Managementsystem für Studentenclubs. Es ermöglicht unter + anderem die Mitgliederverwaltung, Dienstverwaltung, Arbeitsgruppenverwaltung und vieles + meher. Es kann fast alles ermöglich werden, wenn ein Plugin dafür geschrieben wird. Jeder + Club hat die Möglichkeit sein eigenes Flaschengeist zu hosten. Ziel ist später Clubübergreifend dezentralisiert miteinander zu arbeiten.
- - +
Geladene Plugins:
@@ -44,14 +42,12 @@ - +
Entwickler:
-
+
diff --git a/src/plugins/balance/pages/MainPage.vue b/src/plugins/balance/pages/MainPage.vue index a862214..77f44b1 100644 --- a/src/plugins/balance/pages/MainPage.vue +++ b/src/plugins/balance/pages/MainPage.vue @@ -3,10 +3,7 @@ - +
- +
- +
@@ -39,7 +33,7 @@ export default defineComponent({ }; function updateUser(value: FG.User) { - store.dispatch('user/updateUser', value).catch((error) => { + store.dispatch('user/updateUser', value).catch(error => { console.warn(error); }); } @@ -47,9 +41,9 @@ export default defineComponent({ return { user, userUpdated, - updateUser, + updateUser }; - }, + } }); diff --git a/src/plugins/user/components/Widget.vue b/src/plugins/user/components/Widget.vue index 4788526..d898e26 100644 --- a/src/plugins/user/components/Widget.vue +++ b/src/plugins/user/components/Widget.vue @@ -9,12 +9,16 @@
- Hallo {{ name }}
+ Hallo {{ name }}
Herzlichen Glückwunsch zum Geburtstag!
- Heute hat haben {{user.display_name}}, Geburtstag. + Heute hat haben {{ user.display_name }}, + Geburtstag. Heute stehen keine Geburtstage an
@@ -22,12 +26,7 @@ diff --git a/src/plugins/user/components/settings/RoleSettings.vue b/src/plugins/user/components/settings/RoleSettings.vue index 523ebd5..445f1e0 100644 --- a/src/plugins/user/components/settings/RoleSettings.vue +++ b/src/plugins/user/components/settings/RoleSettings.vue @@ -2,9 +2,7 @@
- + Rollen und Berechtigungen @@ -26,17 +24,9 @@ /> - + - + diff --git a/src/plugins/user/components/settings/Sessions.vue b/src/plugins/user/components/settings/Sessions.vue index 361bccf..1932931 100644 --- a/src/plugins/user/components/settings/Sessions.vue +++ b/src/plugins/user/components/settings/Sessions.vue @@ -21,19 +21,11 @@ Lebenszeit: {{ session.lifetime }}
-
- Läuft aus: {{ session.expires | dateTime(true) }} -
+
Läuft aus: {{ session.expires | dateTime(true) }}
- + diff --git a/src/plugins/user/pages/AdminSettings.vue b/src/plugins/user/pages/AdminSettings.vue index 9780df5..c4964ff 100644 --- a/src/plugins/user/pages/AdminSettings.vue +++ b/src/plugins/user/pages/AdminSettings.vue @@ -1,9 +1,6 @@