Compare commits
4 Commits
3c938a8f99
...
b6275f7478
Author | SHA1 | Date |
---|---|---|
Tim Gröger | b6275f7478 | |
Tim Gröger | 4abcedce3a | |
Tim Gröger | 345227f5d4 | |
Tim Gröger | a876f99e13 |
|
@ -2,16 +2,19 @@ import { FG_Plugin } from '@flaschengeist/types';
|
|||
|
||||
export interface SendFromNotification {
|
||||
receiver_id: string;
|
||||
author_id: string;
|
||||
}
|
||||
|
||||
export interface SendToNotification {
|
||||
sender_id: string;
|
||||
}
|
||||
|
||||
export interface TransactionNotification {
|
||||
author_id: string;
|
||||
}
|
||||
|
||||
export interface BalanceNotification extends FG_Plugin.Notification {
|
||||
data: {
|
||||
type: number;
|
||||
amount: number;
|
||||
} & (SendFromNotification | SendToNotification);
|
||||
} & (SendFromNotification | SendToNotification | TransactionNotification);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<q-input v-model.number="amount" type="number" filled label="Eigener Betrag" step="0.1" min="0" suffix="€" />
|
||||
</div>
|
||||
<div class="col-sm-4 col-xs-6">
|
||||
<q-btn v-close-popup style="width: 100%" color="primary" label="Anschreiben" @click="changeBalance(amount * -1)">
|
||||
<q-btn style="width: 100%" color="primary" label="Anschreiben" @click="changeBalance(amount * -1)">
|
||||
<q-tooltip v-if="canAddShortcut"> Rechtsklick um Betrag als Verknüpfung hinzuzufügen </q-tooltip>
|
||||
<q-menu v-if="canAddShortcut" anchor="bottom middle" self="top middle" context-menu>
|
||||
<q-btn label="neue Verknüpfung" @click="addShortcut"></q-btn>
|
||||
|
@ -13,7 +13,6 @@
|
|||
<div class="col-sm-4 col-xs-6">
|
||||
<q-btn
|
||||
v-if="canAddCredit"
|
||||
v-close-popup
|
||||
style="width: 100%"
|
||||
color="secondary"
|
||||
label="Gutschreiben"
|
||||
|
@ -39,7 +38,7 @@ export default defineComponent({
|
|||
},
|
||||
},
|
||||
emits: {
|
||||
changeBalance: (user: FG.User) => user,
|
||||
'change-balance': (user: FG.User) => user,
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
const store = useBalanceStore();
|
||||
|
@ -47,7 +46,7 @@ export default defineComponent({
|
|||
const amount = ref<number>(0);
|
||||
async function changeBalance(amount: number) {
|
||||
await store.changeBalance(amount, user.value);
|
||||
emit('changeBalance', user.value);
|
||||
emit('change-balance', user.value);
|
||||
}
|
||||
function addShortcut() {
|
||||
if (amount.value != 0) void store.createShortcut(amount.value * -1);
|
||||
|
|
|
@ -6,14 +6,7 @@
|
|||
<UserSelector v-model="receiver" label="Empfänger" />
|
||||
</div>
|
||||
<div class="col-sm-4 col-xs-6">
|
||||
<q-btn
|
||||
v-close-popup
|
||||
style="width: 100%"
|
||||
color="primary"
|
||||
:disable="sendDisabled"
|
||||
label="Senden"
|
||||
@click="sendAmount"
|
||||
/>
|
||||
<q-btn style="width: 100%" color="primary" :disable="sendDisabled" label="Senden" @click="sendAmount" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
|
@ -31,7 +24,7 @@ export default defineComponent({
|
|||
},
|
||||
},
|
||||
emits: {
|
||||
changeBalance: (sender: FG.User, receiver: FG.User) => sender && receiver,
|
||||
changeBalance: ({ sender, receiver }: { sender: FG.User; receiver: FG.User }) => sender && receiver,
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
const store = useBalanceStore();
|
||||
|
@ -51,7 +44,7 @@ export default defineComponent({
|
|||
async function sendAmount() {
|
||||
if (receiver.value) {
|
||||
await store.changeBalance(amount.value, receiver.value, sender.value);
|
||||
emit('changeBalance', sender.value, receiver.value);
|
||||
emit('changeBalance', { sender: sender.value, receiver: receiver.value });
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
|
12
src/index.ts
12
src/index.ts
|
@ -1,12 +1,14 @@
|
|||
import { FG_Plugin } from '@flaschengeist/types';
|
||||
import { defineAsyncComponent } from 'vue';
|
||||
import routes from './routes';
|
||||
import { BalanceNotification, SendFromNotification, SendToNotification } from 'app/balance';
|
||||
import { BalanceNotification, SendFromNotification, SendToNotification, TransactionNotification } from 'app/balance';
|
||||
import { useUserStore } from '@flaschengeist/api';
|
||||
|
||||
const BalanceTypes = {
|
||||
send_to: 0x01,
|
||||
send_from: 0x02,
|
||||
add_from: 0x03,
|
||||
sub_from: 0x04,
|
||||
};
|
||||
|
||||
function transpile(msg: FG_Plugin.Notification) {
|
||||
|
@ -21,16 +23,20 @@ function transpile(msg: FG_Plugin.Notification) {
|
|||
message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ von dir zu ${
|
||||
receiver.display_name
|
||||
} überwiesen.`;
|
||||
} else {
|
||||
} else if (message.data.type === BalanceTypes.send_to) {
|
||||
const sender = <FG.User>store.findUser((<SendToNotification>message.data).sender_id);
|
||||
console.log(sender);
|
||||
message.text = `${sender.display_name} hat dir ${message.data.amount.toFixed(2)}€ überwiesen.`;
|
||||
} else {
|
||||
const author = <FG.User>store.findUser((<TransactionNotification>message.data).author_id);
|
||||
const abgebucht = message.data.type === BalanceTypes.add_from ? 'aufgeladen' : 'abgebucht';
|
||||
message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ dir ${abgebucht}.`;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
const plugin: FG_Plugin.Plugin = {
|
||||
id: 'dev.flaschengeist.balance',
|
||||
id: 'balance',
|
||||
name: 'Balance',
|
||||
innerRoutes: routes,
|
||||
requiredModules: [['balance']],
|
||||
|
|
|
@ -5,17 +5,27 @@
|
|||
:rows="rows"
|
||||
row-key="userid"
|
||||
:columns="columns"
|
||||
@request="onRequest"
|
||||
:filter="filter"
|
||||
@request="onRequest"
|
||||
>
|
||||
<template #top-right>
|
||||
<div class="full-width row q-gutter-sm">
|
||||
<q-input v-model="filter" label="Filter" filled dense debounce="300">
|
||||
<template v-slot:append>
|
||||
<template #append>
|
||||
<q-icon name="mdi-magnify" />
|
||||
</template>
|
||||
</q-input>
|
||||
<q-input v-model.number="limit" label="Limit" type="number" step="0.01" suffix="€" filled dense />
|
||||
<q-input v-model.number="limit" label="Limit" type="number" step="0.01" suffix="€" filled dense>
|
||||
<template #prepend>
|
||||
<q-btn
|
||||
:icon="sign === '+' ? 'mdi-plus' : 'mdi-minus'"
|
||||
round
|
||||
flat
|
||||
:text-color="sign === '+' ? 'secondary' : 'negative'"
|
||||
@click="changeSign"
|
||||
/>
|
||||
</template>
|
||||
</q-input>
|
||||
<q-btn label="Limits Setzen" color="primary" dense @click="setLimits(limit)" />
|
||||
</div>
|
||||
</template>
|
||||
|
@ -35,15 +45,24 @@
|
|||
buttons
|
||||
label-cancel="Abbrechen"
|
||||
label-set="Speichern"
|
||||
@save="setLimit(props.row.userid)"
|
||||
@save="setLimit($event, props.row.userid)"
|
||||
@cancel="limit = undefined"
|
||||
>
|
||||
<q-input v-model.number="scope.value" label="Limit" type="number" step="0.01" suffix="€" filled dense />
|
||||
<q-input v-model.number="scope.value" label="Limit" type="number" step="0.01" suffix="€" filled dense>
|
||||
<template #prepend>
|
||||
<q-btn :icon="sign === '+' ? 'mdi-plus' : 'mdi-minus'" round flat @click="changeSign" />
|
||||
</template>
|
||||
</q-input>
|
||||
</q-popup-edit>
|
||||
</q-td>
|
||||
<q-td key="balance" :props="props">
|
||||
{{ getBalance(props.row.debit, props.row.credit) }}€
|
||||
<q-menu anchor="bottom middle" self="top middle" :persistent="$q.platform.is.mobile">
|
||||
<q-menu
|
||||
v-model="showMenu[props.row.userid]"
|
||||
anchor="bottom middle"
|
||||
self="top middle"
|
||||
:persistent="$q.platform.is.mobile"
|
||||
>
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
<q-tab-panels v-model="tab" animated>
|
||||
|
@ -51,11 +70,14 @@
|
|||
<balance-add-body
|
||||
:user="props.row.userid"
|
||||
:can-add-shortcut="false"
|
||||
@change-balance="updateBalance"
|
||||
@change-balance="updateBalance($event, props.row.userid)"
|
||||
/>
|
||||
</q-tab-panel>
|
||||
<q-tab-panel name="transfer" class="fit column q-gutter-sm">
|
||||
<balance-transfer-body :user="props.row.userid" @change-balance="updateBalances" />
|
||||
<balance-transfer-body
|
||||
:user="props.row.userid"
|
||||
@change-balance="updateBalances($event, $event, props.row.userid)"
|
||||
/>
|
||||
</q-tab-panel>
|
||||
</q-tab-panels>
|
||||
</q-card-section>
|
||||
|
@ -84,8 +106,6 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
// TODO: Fill usefull data
|
||||
|
||||
import { ref, defineComponent, computed, onBeforeMount } from 'vue';
|
||||
import { useBalanceStore } from '../store';
|
||||
import { useUserStore } from '@flaschengeist/api';
|
||||
|
@ -99,6 +119,8 @@ export default defineComponent({
|
|||
const store = useBalanceStore();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const showMenu = ref<{ [userid: string]: boolean }>({});
|
||||
|
||||
onBeforeMount(() => {
|
||||
void userStore.getUsers();
|
||||
void store.getLimits();
|
||||
|
@ -107,6 +129,7 @@ export default defineComponent({
|
|||
|
||||
const rows = computed(() => store.balances);
|
||||
const limit = ref<number>();
|
||||
const sign = ref<'+' | '-'>('-');
|
||||
const filter = ref<string>();
|
||||
|
||||
const columns = [
|
||||
|
@ -183,7 +206,7 @@ export default defineComponent({
|
|||
} catch (error) {
|
||||
console.warn(error);
|
||||
}
|
||||
console.log(pagination.value);
|
||||
//console.log(pagination.value);
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
|
@ -200,22 +223,26 @@ export default defineComponent({
|
|||
return (credit - debit).toFixed(2);
|
||||
}
|
||||
|
||||
function updateBalance(user: FG.User) {
|
||||
void store.getBalance(user);
|
||||
async function updateBalance(user: FG.User, ref_showMenu?: string) {
|
||||
await store.getBalance(user);
|
||||
if (ref_showMenu) {
|
||||
showMenu.value[ref_showMenu] = false;
|
||||
}
|
||||
}
|
||||
async function updateBalances({ sender, receiver }: { sender: FG.User; receiver: FG.User }, ref_showMenu?: string) {
|
||||
await updateBalance(sender);
|
||||
await updateBalance(receiver);
|
||||
if (ref_showMenu) {
|
||||
showMenu.value[ref_showMenu] = false;
|
||||
}
|
||||
}
|
||||
|
||||
function updateBalances(sender: FG.User, receiver: FG.User) {
|
||||
updateBalance(sender);
|
||||
updateBalance(receiver);
|
||||
async function setLimit(l: number, userid: string) {
|
||||
if (sign.value === '-') {
|
||||
l = -l;
|
||||
}
|
||||
|
||||
function setLimit(userid: string) {
|
||||
setTimeout(() => {
|
||||
void store.setLimit(<number>limit.value, userid);
|
||||
}, 50);
|
||||
setTimeout(() => {
|
||||
await store.setLimit(l, userid);
|
||||
limit.value = undefined;
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function getFirstname(userid: string) {
|
||||
|
@ -226,13 +253,23 @@ export default defineComponent({
|
|||
return userStore.users.find((a) => a.userid === userid)?.lastname;
|
||||
}
|
||||
|
||||
const tab = ref('add');
|
||||
function changeSign() {
|
||||
sign.value = sign.value === '+' ? '-' : '+';
|
||||
}
|
||||
|
||||
function setLimits(l: number) {
|
||||
if (sign.value === '-') {
|
||||
l = -l;
|
||||
}
|
||||
void store.setLimits(l);
|
||||
}
|
||||
|
||||
const tab = ref('add');
|
||||
return {
|
||||
rows,
|
||||
columns,
|
||||
limit,
|
||||
setLimits: (l: number) => store.setLimits(l),
|
||||
setLimits,
|
||||
getName,
|
||||
getLimit,
|
||||
setLimit,
|
||||
|
@ -245,6 +282,9 @@ export default defineComponent({
|
|||
getFirstname,
|
||||
getLastname,
|
||||
filter,
|
||||
showMenu,
|
||||
sign,
|
||||
changeSign,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
@ -38,7 +38,8 @@
|
|||
|
||||
<script lang="ts">
|
||||
import { formatDateTime, useMainStore, useUserStore } from '@flaschengeist/api';
|
||||
import { computed, defineComponent, onMounted, ref } from 'vue';
|
||||
import { computed, defineComponent, onMounted, ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useBalanceStore } from '../store';
|
||||
|
||||
export default defineComponent({
|
||||
|
@ -47,8 +48,12 @@ export default defineComponent({
|
|||
const store = useBalanceStore();
|
||||
const mainStore = useMainStore();
|
||||
const userStore = useUserStore();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
if (route.query?.showCancelled == 'true') showCancelled.value = true;
|
||||
await router.replace({ query: { showCancelled: showCancelled.value } });
|
||||
void store.getBalance(mainStore.currentUser);
|
||||
void userStore.getUsers().then(() =>
|
||||
onRequest({
|
||||
|
@ -155,6 +160,14 @@ export default defineComponent({
|
|||
return userStore.users.find((a) => a.userid === userid)?.display_name;
|
||||
}
|
||||
|
||||
watch(showCancelled, async () => {
|
||||
await router.replace({ query: { showCancelled: showCancelled.value } });
|
||||
await onRequest({
|
||||
pagination: pagination.value,
|
||||
filter: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
return { data, pagination, onRequest, loading, balance, columns, showCancelled };
|
||||
},
|
||||
});
|
||||
|
|
|
@ -54,7 +54,8 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, ref, onMounted } from 'vue';
|
||||
import { computed, defineComponent, ref, onMounted, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { hasSomePermissions, useMainStore } from '@flaschengeist/api';
|
||||
import { useBalanceStore } from '../store';
|
||||
import PERMISSIONS from '../permissions';
|
||||
|
@ -69,9 +70,15 @@ export default defineComponent({
|
|||
setup() {
|
||||
const balanceStore = useBalanceStore();
|
||||
const mainStore = useMainStore();
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
const now = new Date();
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
if (tabs.some((value) => value.name == route.query.q_tab)) {
|
||||
tab.value = route.query.q_tab as string;
|
||||
}
|
||||
await router.replace({ query: { q_tab: tab.value } });
|
||||
void balanceStore.getTransactions(mainStore.currentUser, {
|
||||
from: new Date(now.getFullYear(), now.getMonth(), now.getDate()),
|
||||
});
|
||||
|
@ -111,6 +118,9 @@ export default defineComponent({
|
|||
*/
|
||||
const showDrawer = ref<boolean>(false);
|
||||
const tab = ref<string>(canAdd() ? 'add' : 'transfer');
|
||||
watch(tab, (val) => {
|
||||
void router.replace({ query: { q_tab: val } });
|
||||
});
|
||||
const show = ref<boolean>(false);
|
||||
return {
|
||||
showDrawer,
|
||||
|
|
Loading…
Reference in New Issue