Compare commits
20 Commits
v1.0.0-alp
...
main
Author | SHA1 | Date |
---|---|---|
|
1350e34fd3 | |
|
9584774d18 | |
|
59a430bea8 | |
|
ebffecd364 | |
|
56b09abeaa | |
|
86a06e8094 | |
|
9120bc9dba | |
|
b6275f7478 | |
|
4abcedce3a | |
|
345227f5d4 | |
|
a876f99e13 | |
|
3c938a8f99 | |
|
e664c8a64b | |
|
a52ab890e0 | |
|
db4f3c45c4 | |
|
7a61dbef28 | |
|
96ec31d7c1 | |
|
8fe73b2cab | |
|
ef5c8eec5b | |
|
74b55b7839 |
18
.eslintrc.js
18
.eslintrc.js
|
@ -17,11 +17,11 @@ module.exports = {
|
|||
project: resolve(__dirname, './tsconfig.json'),
|
||||
tsconfigRootDir: __dirname,
|
||||
ecmaVersion: 2019, // Allows for the parsing of modern ECMAScript features
|
||||
sourceType: 'module' // Allows for the use of imports
|
||||
sourceType: 'module', // Allows for the use of imports
|
||||
},
|
||||
|
||||
env: {
|
||||
browser: true
|
||||
browser: true,
|
||||
},
|
||||
|
||||
// Rules order is important, please avoid shuffling them
|
||||
|
@ -44,7 +44,7 @@ module.exports = {
|
|||
|
||||
// https://github.com/prettier/eslint-config-prettier#installation
|
||||
// usage with Prettier, provided by 'eslint-config-prettier'.
|
||||
'prettier', //'plugin:prettier/recommended'
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
|
||||
plugins: [
|
||||
|
@ -54,10 +54,6 @@ module.exports = {
|
|||
// https://eslint.vuejs.org/user-guide/#why-doesn-t-it-work-on-vue-file
|
||||
// required to lint *.vue files
|
||||
'vue',
|
||||
|
||||
// https://github.com/typescript-eslint/typescript-eslint/issues/389#issuecomment-509292674
|
||||
// Prettier has not been included as plugin to avoid performance impact
|
||||
// add it as an extension for your IDE
|
||||
],
|
||||
|
||||
// add your custom rules here
|
||||
|
@ -65,11 +61,11 @@ module.exports = {
|
|||
'prefer-promise-reject-errors': 'off',
|
||||
|
||||
// TypeScript
|
||||
quotes: ['warn', 'single', { avoidEscape: true }],
|
||||
quotes: ['error', 'single', { avoidEscape: true }],
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
|
||||
// allow debugger during development only
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
|
||||
}
|
||||
}
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
node_modules
|
||||
yarn-error.log
|
||||
# No need for pinned dependencies, there are only peer dependencies
|
||||
yarn.lock
|
||||
|
||||
.idea
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
yarn-error.log
|
||||
|
||||
.woodpecker/
|
|
@ -0,0 +1,14 @@
|
|||
pipeline:
|
||||
deploy:
|
||||
when:
|
||||
event: tag
|
||||
tag: v*
|
||||
image: node:lts-alpine
|
||||
commands:
|
||||
- echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" > .npmrc
|
||||
- yarn publish --non-interactive
|
||||
secrets: [ node_auth_token ]
|
||||
|
||||
depends_on:
|
||||
- lint
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
pipeline:
|
||||
lint:
|
||||
when:
|
||||
branch: [main, develop]
|
||||
image: node:lts-alpine
|
||||
commands:
|
||||
- yarn install
|
||||
- yarn lint
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
# Flaschengeist `balance` fontend-plugin
|
||||

|
||||
|
||||
This package provides the [Flaschengeist](https://flaschengeist.dev/Flaschengeist/flaschengeist) frontend for the `balance` plugin.
|
||||
|
||||
|
|
90
package.json
90
package.json
|
@ -1,45 +1,49 @@
|
|||
{
|
||||
"license": "MIT",
|
||||
"version": "1.0.0-alpha.2",
|
||||
"name": "@flaschengeist/balance",
|
||||
"author": "Ferdinand Thiessen <rpm@fthiessen.de>",
|
||||
"homepage": "https://flaschengeist.dev/Flaschengeist",
|
||||
"description": "Flaschengeist balance plugin",
|
||||
"bugs": {
|
||||
"url": "https://flaschengeist.dev/Flaschengeist/flaschengeist/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://flaschengeist.dev/Flaschengeist/flaschengeist-balance"
|
||||
},
|
||||
"main": "src/index.ts",
|
||||
"types": "src/api.d.ts",
|
||||
"scripts": {
|
||||
"pretty": "prettier --config ./package.json --write '{,!(node_modules)/**/}*.ts'",
|
||||
"lint": "eslint --ext .js,.ts,.vue ./src"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@flaschengeist/types": "^1.0.0-alpha.10",
|
||||
"@quasar/app": "^3.2.4",
|
||||
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
||||
"@typescript-eslint/parser": "^5.5.0",
|
||||
"axios": "^0.24.0",
|
||||
"eslint": "^8.4.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-vue": "^8.1.1",
|
||||
"pinia": "^2.0.6",
|
||||
"prettier": "^2.5.1",
|
||||
"quasar": "^2.3.3",
|
||||
"typescript": "^4.5.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@flaschengeist/api": "1.0.0-alpha.7",
|
||||
"@flaschengeist/users": "1.0.0-alpha.3"
|
||||
},
|
||||
"prettier": {
|
||||
"singleQuote": true,
|
||||
"semi": true,
|
||||
"printWidth": 120,
|
||||
"arrowParens": "always"
|
||||
}
|
||||
"license": "MIT",
|
||||
"version": "1.0.0",
|
||||
"name": "@flaschengeist/balance",
|
||||
"author": "Ferdinand Thiessen <rpm@fthiessen.de>",
|
||||
"homepage": "https://flaschengeist.dev/Flaschengeist",
|
||||
"description": "Flaschengeist balance plugin",
|
||||
"bugs": {
|
||||
"url": "https://flaschengeist.dev/Flaschengeist/flaschengeist/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://flaschengeist.dev/Flaschengeist/flaschengeist-balance"
|
||||
},
|
||||
"main": "src/index.ts",
|
||||
"types": "src/api.d.ts",
|
||||
"scripts": {
|
||||
"format": "prettier --config ./package.json --write '{,!(node_modules)/**/}*.{js,ts,vue}'",
|
||||
"lint": "eslint --ext .js,.ts,.vue ./src"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@flaschengeist/api": "^1.0.0",
|
||||
"@flaschengeist/types": "^1.0.0",
|
||||
"@quasar/app-webpack": "^3.7.2",
|
||||
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
||||
"@typescript-eslint/parser": "^5.8.0",
|
||||
"axios": "^0.24.0",
|
||||
"eslint": "^8.5.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"eslint-plugin-vue": "^8.2.0",
|
||||
"eslint-webpack-plugin": "^3.1.1",
|
||||
"modify-source-webpack-plugin": "^3.0.0",
|
||||
"pinia": "^2.0.8",
|
||||
"prettier": "^2.5.1",
|
||||
"quasar": "^2.11.10",
|
||||
"typescript": "^4.5.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@flaschengeist/api": "1.0.0",
|
||||
"@flaschengeist/users": "1.0.0"
|
||||
},
|
||||
"prettier": {
|
||||
"singleQuote": true,
|
||||
"semi": true,
|
||||
"printWidth": 120,
|
||||
"arrowParens": "always"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -2,25 +2,19 @@
|
|||
<div class="col-sm-4 col-xs-12">
|
||||
<q-input
|
||||
v-model.number="amount"
|
||||
ref="refAmount"
|
||||
type="number"
|
||||
filled
|
||||
label="Eigener Betrag"
|
||||
step="0.1"
|
||||
min="0"
|
||||
suffix="€"
|
||||
:rules="[check_cent_step]"
|
||||
/>
|
||||
</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-tooltip v-if="canAddShortcut">
|
||||
Rechtsklick um Betrag als Verknüpfung hinzuzufügen
|
||||
</q-tooltip>
|
||||
<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>
|
||||
</q-menu>
|
||||
|
@ -29,7 +23,6 @@
|
|||
<div class="col-sm-4 col-xs-6">
|
||||
<q-btn
|
||||
v-if="canAddCredit"
|
||||
v-close-popup
|
||||
style="width: 100%"
|
||||
color="secondary"
|
||||
label="Gutschreiben"
|
||||
|
@ -38,10 +31,12 @@
|
|||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { defineComponent, ref, PropType, computed } from 'vue';
|
||||
import { defineComponent, ref, PropType, computed, watch } from 'vue';
|
||||
import { QInput } from 'quasar';
|
||||
import { useBalanceStore } from '../store';
|
||||
import { hasPermission, useUserStore } from '@flaschengeist/api';
|
||||
import PERMISSIONS from '../permissions';
|
||||
import { check_cent_step } from '../utils';
|
||||
export default defineComponent({
|
||||
name: 'BalanceAddBody',
|
||||
props: {
|
||||
|
@ -55,18 +50,21 @@ export default defineComponent({
|
|||
},
|
||||
},
|
||||
emits: {
|
||||
changeBalance: (user: FG.User) => user,
|
||||
'change-balance': (user: FG.User) => user,
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
const store = useBalanceStore();
|
||||
const userStore = useUserStore();
|
||||
const amount = ref<number>(0);
|
||||
const refAmount = ref<QInput>();
|
||||
async function changeBalance(amount: number) {
|
||||
await store.changeBalance(amount, user.value);
|
||||
emit('changeBalance', user.value);
|
||||
await refAmount.value?.validate();
|
||||
if (amount != 0 && !refAmount.value?.hasError) await store.changeBalance(amount, user.value);
|
||||
emit('change-balance', user.value);
|
||||
}
|
||||
function addShortcut() {
|
||||
if (amount.value != 0) void store.createShortcut(amount.value * -1);
|
||||
async function addShortcut() {
|
||||
await refAmount.value?.validate();
|
||||
if (amount.value != 0 && !refAmount.value?.hasError) void store.createShortcut(amount.value * -1);
|
||||
}
|
||||
const canAddCredit = hasPermission(PERMISSIONS.CREDIT);
|
||||
const user = computed(() =>
|
||||
|
@ -74,7 +72,10 @@ export default defineComponent({
|
|||
? <FG.User>props.user
|
||||
: <FG.User>userStore.users.find((a) => a.userid === <string>props.user)
|
||||
);
|
||||
return { changeBalance, addShortcut, canAddCredit, amount };
|
||||
watch(amount, (a) => {
|
||||
amount.value = Math.abs(a);
|
||||
});
|
||||
return { changeBalance, addShortcut, canAddCredit, amount, check_cent_step, refAmount };
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<q-card-section class="fit row justify-left content-center items-center q-col-gutter-sm">
|
||||
<div class="col-5">
|
||||
<div v-if="balance" class="text-h6">
|
||||
Aktueller Stand: {{ balance.balance ? balance.balance.toFixed(2) : "" }} €
|
||||
Aktueller Stand: {{ balance.balance ? balance.balance.toFixed(2) : parseInt('0').toFixed(2) }} €
|
||||
<q-badge v-if="isLocked" color="negative" align="top"> gesperrt </q-badge>
|
||||
</div>
|
||||
<q-spinner v-else color="primary" size="3em" />
|
||||
|
@ -10,8 +10,10 @@
|
|||
<div v-if="showSelector" class="col-6">
|
||||
<UserSelector v-model="user" />
|
||||
</div>
|
||||
<div class="col-1 justify-end">
|
||||
<q-btn round flat icon="mdi-format-list-checks" @click="openHistory" />
|
||||
<div class="col">
|
||||
<div class="row fit justify-end content-end items-end">
|
||||
<q-btn round flat icon="mdi-format-list-checks" @click="openHistory" />
|
||||
</div>
|
||||
</div>
|
||||
</q-card-section>
|
||||
</template>
|
||||
|
@ -22,7 +24,6 @@ import UserSelector from '@flaschengeist/users/src/components/UserSelector.vue';
|
|||
import { useMainStore } from '@flaschengeist/api';
|
||||
import { useBalanceStore } from '../store';
|
||||
|
||||
|
||||
export default defineComponent({
|
||||
name: 'BalanceHeader',
|
||||
components: { UserSelector },
|
||||
|
@ -40,9 +41,7 @@ export default defineComponent({
|
|||
|
||||
onBeforeMount(() => void store.getBalance(mainStore.currentUser));
|
||||
|
||||
const balance = computed(() =>
|
||||
store.balances.find((x) => x.userid === props.modelValue.userid)
|
||||
);
|
||||
const balance = computed(() => store.balances.find((x) => x.userid === props.modelValue.userid));
|
||||
|
||||
const isLocked = computed(
|
||||
() =>
|
||||
|
|
|
@ -35,7 +35,7 @@ import { ref, computed, defineComponent, onUnmounted, onMounted, PropType } from
|
|||
import { useBalanceStore } from '../store';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Transaction',
|
||||
name: 'BalanceTransaction',
|
||||
props: {
|
||||
transaction: {
|
||||
required: true,
|
|
@ -1,10 +1,10 @@
|
|||
<template>
|
||||
<q-card>
|
||||
<BalanceHeader v-model="sender" :show-selector="showSelector" @open-history="openHistory" />
|
||||
<q-separator />
|
||||
<q-card-section class="row q-col-gutter-md items-center">
|
||||
<balance-transfer-body :user="sender" />
|
||||
</q-card-section>
|
||||
<BalanceHeader v-model="sender" :show-selector="showSelector" @open-history="openHistory" />
|
||||
<q-separator />
|
||||
<q-card-section class="row q-col-gutter-md items-center">
|
||||
<balance-transfer-body :user="sender" />
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -2,32 +2,29 @@
|
|||
<div class="col-sm-4 col-xs-12">
|
||||
<q-input
|
||||
v-model.number="amount"
|
||||
ref="refAmount"
|
||||
type="number"
|
||||
filled
|
||||
label="Betrag"
|
||||
step="0.1"
|
||||
min="0"
|
||||
suffix="€"
|
||||
:rules="[check_cent_step]"
|
||||
/>
|
||||
</div>
|
||||
<div class="col-sm-4 col-xs-6">
|
||||
<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">
|
||||
import { computed, defineComponent, PropType, ref } from 'vue';
|
||||
import { QInput } from 'quasar';
|
||||
import UserSelector from '@flaschengeist/users/src/components/UserSelector.vue';
|
||||
import { useBalanceStore } from '../store';
|
||||
import { check_cent_step } from '../utils';
|
||||
import { useUserStore } from '@flaschengeist/api';
|
||||
export default defineComponent({
|
||||
name: 'BalanceTransferBody',
|
||||
|
@ -39,13 +36,14 @@ 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();
|
||||
const userStore = useUserStore();
|
||||
const receiver = ref<FG.User | undefined>(undefined);
|
||||
const amount = ref<number>(0);
|
||||
const refAmount = ref<QInput>();
|
||||
const sender = computed(() =>
|
||||
(<FG.User>props.user).userid
|
||||
? <FG.User>props.user
|
||||
|
@ -57,14 +55,16 @@ export default defineComponent({
|
|||
receiver.value &&
|
||||
sender.value &&
|
||||
sender.value.userid != receiver.value.userid &&
|
||||
amount.value > 0
|
||||
amount.value > 0 &&
|
||||
!refAmount.value?.hasError
|
||||
);
|
||||
});
|
||||
|
||||
async function sendAmount() {
|
||||
if (receiver.value) {
|
||||
await refAmount.value?.validate();
|
||||
if (receiver.value && !refAmount.value?.hasError) {
|
||||
await store.changeBalance(amount.value, receiver.value, sender.value);
|
||||
emit('changeBalance', sender.value, receiver.value);
|
||||
emit('changeBalance', { sender: sender.value, receiver: receiver.value });
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
@ -73,6 +73,8 @@ export default defineComponent({
|
|||
amount,
|
||||
sendAmount,
|
||||
sendDisabled,
|
||||
refAmount,
|
||||
check_cent_step,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
@ -21,7 +21,7 @@ export default defineComponent({
|
|||
void store.getBalance(mainStore.currentUser);
|
||||
});
|
||||
|
||||
const balance = computed(() => store.balance?.balance || NaN);
|
||||
const balance = computed(() => store.balance?.balance || 0);
|
||||
|
||||
return { balance };
|
||||
},
|
||||
|
|
21
src/index.ts
21
src/index.ts
|
@ -1,15 +1,17 @@
|
|||
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) {
|
||||
function transpile (msg: FG_Plugin.Notification) {
|
||||
console.log('notification:', msg);
|
||||
const message = msg as BalanceNotification;
|
||||
message.icon = 'mdi-cash';
|
||||
|
@ -18,23 +20,26 @@ function transpile(msg: FG_Plugin.Notification) {
|
|||
if (message.data.type === BalanceTypes.send_from) {
|
||||
const receiver = <FG.User>store.findUser((<SendFromNotification>message.data).receiver_id);
|
||||
const author = <FG.User>store.findUser((<SendFromNotification>message.data).author_id);
|
||||
message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ von dir zu ${
|
||||
receiver.display_name
|
||||
} überwiesen.`;
|
||||
} else {
|
||||
message.text = `${author.display_name} hat ${message.data.amount.toFixed(2)}€ von dir zu ${receiver.display_name
|
||||
} überwiesen.`;
|
||||
} 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']],
|
||||
version: '0.0.2',
|
||||
version: '1.0.0',
|
||||
notification: transpile,
|
||||
widgets: [
|
||||
{
|
||||
|
|
|
@ -1,257 +0,0 @@
|
|||
<template>
|
||||
<div>
|
||||
<q-page padding>
|
||||
<q-table :rows="rows" row-key="userid" :columns="columns" v-model:pagination="pagination" @request="onRequest">
|
||||
<template #top-right>
|
||||
<div class="full-width row q-gutter-sm">
|
||||
<q-input
|
||||
v-model.number="limit"
|
||||
label="Limit"
|
||||
type="number"
|
||||
step="0.01"
|
||||
suffix="€"
|
||||
filled
|
||||
dense
|
||||
/>
|
||||
<q-btn label="Limits Setzen" color="primary" dense @click="setLimits(limit)" />
|
||||
</div>
|
||||
</template>
|
||||
<template #body="props">
|
||||
<q-tr :props="props">
|
||||
<q-td key="firstname" :props="props">
|
||||
{{ getFirstname(props.row.userid) }}
|
||||
</q-td>
|
||||
<q-td key="lastname" :props="props">
|
||||
{{ getLastname(props.row.userid)}}
|
||||
</q-td>
|
||||
<q-td key="limit" :props="props">
|
||||
{{ getLimit(props.row.userid) || 'Kein Limit' }}
|
||||
<q-popup-edit
|
||||
v-slot="scope"
|
||||
v-model="limit"
|
||||
buttons
|
||||
label-cancel="Abbrechen"
|
||||
label-set="Speichern"
|
||||
@save="setLimit(props.row.userid)"
|
||||
@cancel="limit = undefined"
|
||||
>
|
||||
<q-input
|
||||
v-model.number="scope.value"
|
||||
label="Limit"
|
||||
type="number"
|
||||
step="0.01"
|
||||
suffix="€"
|
||||
filled
|
||||
dense
|
||||
/>
|
||||
</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-card>
|
||||
<q-card-section>
|
||||
<q-tab-panels v-model="tab" animated>
|
||||
<q-tab-panel name="add" class="fit column q-gutter-sm">
|
||||
<balance-add-body
|
||||
:user="props.row.userid"
|
||||
:can-add-shortcut="false"
|
||||
@changeBalance="updateBalance"
|
||||
/>
|
||||
</q-tab-panel>
|
||||
<q-tab-panel name="transfer" class="fit column q-gutter-sm">
|
||||
<balance-transfer-body
|
||||
:user="props.row.userid"
|
||||
@changeBalance="updateBalances"
|
||||
/>
|
||||
</q-tab-panel>
|
||||
</q-tab-panels>
|
||||
</q-card-section>
|
||||
<div v-if="$q.platform.is.mobile" class="full-width row justify-center">
|
||||
<q-btn v-close-popup label="Abbrechen" flat color="primary" />
|
||||
</div>
|
||||
<q-tabs
|
||||
v-model="tab"
|
||||
dense
|
||||
class="text-grey"
|
||||
active-color="primary"
|
||||
indicator-color="primary"
|
||||
align="justify"
|
||||
narrow-indicator
|
||||
>
|
||||
<q-tab name="add" label="Anschreiben" />
|
||||
<q-tab name="transfer" label="Übertragen" />
|
||||
</q-tabs>
|
||||
</q-card>
|
||||
</q-menu>
|
||||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
</q-table>
|
||||
</q-page>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
// TODO: Fill usefull data
|
||||
|
||||
import { ref, defineComponent, computed, onBeforeMount } from 'vue';
|
||||
import { useBalanceStore } from '../store';
|
||||
import {useUserStore} from '@flaschengeist/api';
|
||||
import BalanceAddBody from '../components/BalanceAddBody.vue';
|
||||
import BalanceTransferBody from '../components/BalanceTransferBody.vue';
|
||||
|
||||
export default defineComponent({
|
||||
components: { BalanceTransferBody, BalanceAddBody },
|
||||
// name: 'PageName'
|
||||
setup() {
|
||||
const store = useBalanceStore();
|
||||
const userStore = useUserStore();
|
||||
|
||||
onBeforeMount( () => {
|
||||
void userStore.getUsers();
|
||||
void store.getLimits();
|
||||
void onRequest({pagination: pagination.value, filter: undefined})
|
||||
});
|
||||
|
||||
const rows = computed(() => store.balances);
|
||||
const limit = ref<number>();
|
||||
|
||||
const columns = [
|
||||
{
|
||||
name: 'firstname',
|
||||
label: 'Vorname',
|
||||
field: 'userid',
|
||||
align: 'left',
|
||||
sortable: true
|
||||
},
|
||||
{
|
||||
name: 'lastname',
|
||||
label: 'Vorname',
|
||||
field: 'userid',
|
||||
align: 'left',
|
||||
sortable: true
|
||||
},
|
||||
{
|
||||
name: 'limit',
|
||||
label: 'Limit',
|
||||
align: 'right',
|
||||
field: 'userid',
|
||||
format: (_: undefined, row: { userid: string }) => getLimit(row.userid),
|
||||
sortable: true
|
||||
},
|
||||
{
|
||||
name: 'balance',
|
||||
label: 'Kontostand',
|
||||
align: 'right',
|
||||
field: 'userid',
|
||||
format: (_: undefined, row: { debit: number; credit: number }) =>
|
||||
getBalance(row.debit, row.credit),
|
||||
sortable: true,
|
||||
},
|
||||
];
|
||||
|
||||
interface PaginationInterface {
|
||||
sortBy: string;
|
||||
descending: boolean;
|
||||
page: number;
|
||||
rowsPerPage: number;
|
||||
rowsNumber: number;
|
||||
}
|
||||
|
||||
const pagination = ref<PaginationInterface>({
|
||||
sortBy: 'lastname',
|
||||
rowsPerPage: 5,
|
||||
rowsNumber: 10,
|
||||
descending: false,
|
||||
page: 1,
|
||||
})
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
async function onRequest(props: {pagination: PaginationInterface; filter?: string}) {
|
||||
const {page, rowsPerPage, sortBy, descending} = props.pagination;
|
||||
loading.value = true;
|
||||
const fetchCount = rowsPerPage === 0 ? pagination.value.rowsNumber : rowsPerPage;
|
||||
const startRow = (page - 1) * rowsPerPage;
|
||||
|
||||
try {
|
||||
const result = await store.getBalances({
|
||||
limit: fetchCount,
|
||||
offset: startRow,
|
||||
descending: descending ? true : undefined,
|
||||
sortBy,
|
||||
})
|
||||
pagination.value.page = page;
|
||||
pagination.value.rowsPerPage = rowsPerPage;
|
||||
pagination.value.sortBy = sortBy;
|
||||
pagination.value.descending = descending;
|
||||
if (result.count) pagination.value.rowsNumber = result.count;
|
||||
} catch (error) {
|
||||
console.warn(error)
|
||||
}
|
||||
console.log(pagination.value)
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
function getName(val: string) {
|
||||
return userStore.users.find((a) => a.userid === val)?.display_name;
|
||||
}
|
||||
|
||||
function getLimit(val: string) {
|
||||
const limit = store.user_limits.find((a) => a.userid === val)?.limit?.toFixed(2);
|
||||
return limit ? `${limit} €` : undefined
|
||||
}
|
||||
|
||||
function getBalance(debit: number, credit: number) {
|
||||
return (credit - debit).toFixed(2);
|
||||
}
|
||||
|
||||
function updateBalance(user: FG.User) {
|
||||
void store.getBalance(user);
|
||||
}
|
||||
|
||||
function updateBalances(sender: FG.User, receiver: FG.User) {
|
||||
updateBalance(sender);
|
||||
updateBalance(receiver);
|
||||
}
|
||||
|
||||
function setLimit(userid: string) {
|
||||
setTimeout(() => {
|
||||
void store.setLimit(<number>limit.value, userid);
|
||||
}, 50);
|
||||
setTimeout(() => {
|
||||
limit.value = undefined;
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function getFirstname(userid: string) {
|
||||
return userStore.users.find((a) => a.userid === userid)?.firstname
|
||||
}
|
||||
|
||||
function getLastname(userid: string) {
|
||||
return userStore.users.find((a) => a.userid === userid)?.lastname
|
||||
}
|
||||
|
||||
const tab = ref('add');
|
||||
|
||||
return {
|
||||
rows,
|
||||
columns,
|
||||
limit,
|
||||
setLimits: store.setLimits,
|
||||
getName,
|
||||
getLimit,
|
||||
setLimit,
|
||||
getBalance,
|
||||
updateBalance,
|
||||
updateBalances,
|
||||
tab,
|
||||
pagination,
|
||||
onRequest,
|
||||
getFirstname,
|
||||
getLastname,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,314 @@
|
|||
<template>
|
||||
<q-page padding>
|
||||
<q-table
|
||||
v-model:pagination="pagination"
|
||||
:rows="rows"
|
||||
row-key="userid"
|
||||
:columns="columns"
|
||||
: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 #append>
|
||||
<q-icon name="mdi-magnify" />
|
||||
</template>
|
||||
</q-input>
|
||||
<q-input
|
||||
ref="refLimit"
|
||||
v-model.number="limit"
|
||||
label="Limit"
|
||||
type="number"
|
||||
step="0.01"
|
||||
suffix="€"
|
||||
filled
|
||||
dense
|
||||
:rules="[check_cent_step]"
|
||||
>
|
||||
<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>
|
||||
<template #body="props">
|
||||
<q-tr :props="props">
|
||||
<q-td key="firstname" :props="props">
|
||||
{{ getFirstname(props.row.userid) }}
|
||||
</q-td>
|
||||
<q-td key="lastname" :props="props">
|
||||
{{ getLastname(props.row.userid) }}
|
||||
</q-td>
|
||||
<q-td key="limit" :props="props">
|
||||
{{ getLimit(props.row.userid) || 'Kein Limit' }}
|
||||
<q-popup-edit
|
||||
v-slot="scope"
|
||||
v-model="limit"
|
||||
buttons
|
||||
label-cancel="Abbrechen"
|
||||
label-set="Speichern"
|
||||
@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>
|
||||
<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
|
||||
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>
|
||||
<q-tab-panel name="add" class="fit column q-gutter-sm">
|
||||
<balance-add-body
|
||||
:user="props.row.userid"
|
||||
:can-add-shortcut="false"
|
||||
@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($event, $event, props.row.userid)"
|
||||
/>
|
||||
</q-tab-panel>
|
||||
</q-tab-panels>
|
||||
</q-card-section>
|
||||
<div v-if="$q.platform.is.mobile" class="full-width row justify-center">
|
||||
<q-btn v-close-popup label="Abbrechen" flat color="primary" />
|
||||
</div>
|
||||
<q-tabs
|
||||
v-model="tab"
|
||||
dense
|
||||
class="text-grey"
|
||||
active-color="primary"
|
||||
indicator-color="primary"
|
||||
align="justify"
|
||||
narrow-indicator
|
||||
>
|
||||
<q-tab name="add" label="Anschreiben" />
|
||||
<q-tab name="transfer" label="Übertragen" />
|
||||
</q-tabs>
|
||||
</q-card>
|
||||
</q-menu>
|
||||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
</q-table>
|
||||
</q-page>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ref, defineComponent, computed, onBeforeMount } from 'vue';
|
||||
import { QInput } from 'quasar';
|
||||
import { check_cent_step } from '../utils';
|
||||
import { useBalanceStore } from '../store';
|
||||
import { useUserStore } from '@flaschengeist/api';
|
||||
import BalanceAddBody from '../components/BalanceAddBody.vue';
|
||||
import BalanceTransferBody from '../components/BalanceTransferBody.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'BalanceAdminPage',
|
||||
components: { BalanceTransferBody, BalanceAddBody },
|
||||
setup() {
|
||||
const store = useBalanceStore();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const showMenu = ref<{ [userid: string]: boolean }>({});
|
||||
const refLimit = ref<QInput>();
|
||||
|
||||
onBeforeMount(() => {
|
||||
void userStore.getUsers();
|
||||
void store.getLimits();
|
||||
void onRequest({ pagination: pagination.value, filter: filter.value });
|
||||
});
|
||||
|
||||
const rows = computed(() => store.balances);
|
||||
const limit = ref<number>();
|
||||
const sign = ref<'+' | '-'>('-');
|
||||
const filter = ref<string>();
|
||||
|
||||
const columns = [
|
||||
{
|
||||
name: 'firstname',
|
||||
label: 'Vorname',
|
||||
field: 'userid',
|
||||
align: 'left',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'lastname',
|
||||
label: 'Vorname',
|
||||
field: 'userid',
|
||||
align: 'left',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'limit',
|
||||
label: 'Limit',
|
||||
align: 'right',
|
||||
field: 'userid',
|
||||
format: (_: undefined, row: { userid: string }) => getLimit(row.userid),
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'balance',
|
||||
label: 'Kontostand',
|
||||
align: 'right',
|
||||
field: 'userid',
|
||||
format: (_: undefined, row: { debit: number; credit: number }) => getBalance(row.debit, row.credit),
|
||||
sortable: true,
|
||||
},
|
||||
];
|
||||
|
||||
interface PaginationInterface {
|
||||
sortBy: string;
|
||||
descending: boolean;
|
||||
page: number;
|
||||
rowsPerPage: number;
|
||||
rowsNumber: number;
|
||||
}
|
||||
|
||||
const pagination = ref<PaginationInterface>({
|
||||
sortBy: 'lastname',
|
||||
rowsPerPage: 5,
|
||||
rowsNumber: 10,
|
||||
descending: false,
|
||||
page: 1,
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
async function onRequest(props: { pagination: PaginationInterface; filter?: string }) {
|
||||
const { page, rowsPerPage, sortBy, descending } = props.pagination;
|
||||
const filter = props.filter;
|
||||
loading.value = true;
|
||||
const fetchCount = rowsPerPage === 0 ? pagination.value.rowsNumber : rowsPerPage;
|
||||
const startRow = (page - 1) * rowsPerPage;
|
||||
|
||||
try {
|
||||
const result = await store.getBalances({
|
||||
limit: fetchCount,
|
||||
offset: startRow,
|
||||
descending: descending ? true : undefined,
|
||||
sortBy,
|
||||
filter,
|
||||
});
|
||||
pagination.value.page = page;
|
||||
pagination.value.rowsPerPage = rowsPerPage;
|
||||
pagination.value.sortBy = sortBy;
|
||||
pagination.value.descending = descending;
|
||||
if (result.count) pagination.value.rowsNumber = result.count;
|
||||
} catch (error) {
|
||||
console.warn(error);
|
||||
}
|
||||
//console.log(pagination.value);
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
function getName(val: string) {
|
||||
return userStore.users.find((a) => a.userid === val)?.display_name;
|
||||
}
|
||||
|
||||
function getLimit(val: string) {
|
||||
const limit = store.user_limits.find((a) => a.userid === val)?.limit?.toFixed(2);
|
||||
return limit ? `${limit} €` : undefined;
|
||||
}
|
||||
|
||||
function getBalance(debit: number, credit: number) {
|
||||
return (credit - debit).toFixed(2);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
async function setLimit(l: number, userid: string) {
|
||||
if (sign.value === '-') {
|
||||
l = -l;
|
||||
}
|
||||
await refLimit.value?.validate();
|
||||
if (refLimit.value?.hasError) {
|
||||
return;
|
||||
}
|
||||
await store.setLimit(l, userid);
|
||||
limit.value = undefined;
|
||||
}
|
||||
|
||||
function getFirstname(userid: string) {
|
||||
return userStore.users.find((a) => a.userid === userid)?.firstname;
|
||||
}
|
||||
|
||||
function getLastname(userid: string) {
|
||||
return userStore.users.find((a) => a.userid === userid)?.lastname;
|
||||
}
|
||||
|
||||
function changeSign() {
|
||||
sign.value = sign.value === '+' ? '-' : '+';
|
||||
}
|
||||
|
||||
async function setLimits(l: number) {
|
||||
if (sign.value === '-') {
|
||||
l = -l;
|
||||
}
|
||||
await refLimit.value?.validate();
|
||||
if (refLimit.value?.hasError) {
|
||||
return;
|
||||
}
|
||||
void store.setLimits(l);
|
||||
}
|
||||
|
||||
const tab = ref('add');
|
||||
return {
|
||||
rows,
|
||||
columns,
|
||||
limit,
|
||||
setLimits,
|
||||
getName,
|
||||
getLimit,
|
||||
setLimit,
|
||||
getBalance,
|
||||
updateBalance,
|
||||
updateBalances,
|
||||
tab,
|
||||
pagination,
|
||||
onRequest,
|
||||
getFirstname,
|
||||
getLastname,
|
||||
filter,
|
||||
showMenu,
|
||||
sign,
|
||||
changeSign,
|
||||
check_cent_step,
|
||||
refLimit,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
|
@ -38,17 +38,22 @@
|
|||
|
||||
<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({
|
||||
// name: 'PageName'
|
||||
name: 'BalanceOverviewPage',
|
||||
setup() {
|
||||
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({
|
||||
|
@ -107,7 +112,7 @@ export default defineComponent({
|
|||
loading.value = false;
|
||||
}
|
||||
|
||||
const balance = computed(() => store.balance?.balance || NaN);
|
||||
const balance = computed(() => store.balance?.balance || 0);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
|
@ -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 };
|
||||
},
|
||||
});
|
|
@ -1,12 +1,7 @@
|
|||
<template>
|
||||
<q-page padding class="fit row justify-center content-start items-start q-gutter-sm">
|
||||
<q-tabs v-if="$q.screen.gt.sm" v-model="tab">
|
||||
<q-tab
|
||||
v-for="(tabindex, index) in tabs"
|
||||
:key="'tab' + index"
|
||||
:name="tabindex.name"
|
||||
:label="tabindex.label"
|
||||
/>
|
||||
<q-tab v-for="(tabindex, index) in tabs" :key="'tab' + index" :name="tabindex.name" :label="tabindex.label" />
|
||||
</q-tabs>
|
||||
<div v-else class="fit row justify-end">
|
||||
<q-btn
|
||||
|
@ -33,18 +28,13 @@
|
|||
</q-list>
|
||||
<q-list v-if="show">
|
||||
<div v-for="(transaction, index) in transactions" :key="index" class="col-sm-12">
|
||||
<Transaction v-model:transaction="transactions[index]" />
|
||||
<balance-transaction v-model:transaction="transactions[index]" @update:transaction="updateBalance" />
|
||||
</div>
|
||||
</q-list>
|
||||
</q-drawer>
|
||||
<q-tab-panels
|
||||
v-model="tab"
|
||||
style="background-color: transparent"
|
||||
class="q-pa-none col-12"
|
||||
animated
|
||||
>
|
||||
<q-tab-panels v-model="tab" style="background-color: transparent" class="q-pa-none col-12" animated>
|
||||
<q-tab-panel name="add" class="q-px-xs">
|
||||
<BalanceAdd
|
||||
<balance-add
|
||||
@open-history="
|
||||
showDrawer = !showDrawer;
|
||||
show = true;
|
||||
|
@ -52,7 +42,7 @@
|
|||
/>
|
||||
</q-tab-panel>
|
||||
<q-tab-panel name="transfer" class="q-px-xs">
|
||||
<BalanceTransfer
|
||||
<balance-transfer
|
||||
@open-history="
|
||||
showDrawer = !showDrawer;
|
||||
show = true;
|
||||
|
@ -64,23 +54,31 @@
|
|||
</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 BalanceTransfer from '../components/BalanceTransfer.vue';
|
||||
import Transaction from '../components/Transaction.vue';
|
||||
import BalanceAdd from '../components/BalanceAdd.vue';
|
||||
import { useBalanceStore } from '../store';
|
||||
import PERMISSIONS from '../permissions';
|
||||
|
||||
import BalanceTransaction from '../components/BalanceTransaction.vue';
|
||||
import BalanceTransfer from '../components/BalanceTransfer.vue';
|
||||
import BalanceAdd from '../components/BalanceAdd.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'BalanceManage',
|
||||
components: { BalanceAdd, BalanceTransfer, Transaction },
|
||||
components: { BalanceAdd, BalanceTransfer, BalanceTransaction },
|
||||
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()),
|
||||
});
|
||||
|
@ -93,8 +91,7 @@ export default defineComponent({
|
|||
.sort((a, b) => (a.time >= b.time ? -1 : 1));
|
||||
});
|
||||
|
||||
const canAdd = () =>
|
||||
hasSomePermissions([PERMISSIONS.DEBIT, PERMISSIONS.CREDIT, PERMISSIONS.DEBIT_OWN]);
|
||||
const canAdd = () => hasSomePermissions([PERMISSIONS.DEBIT, PERMISSIONS.CREDIT, PERMISSIONS.DEBIT_OWN]);
|
||||
|
||||
interface Tab {
|
||||
name: string;
|
||||
|
@ -121,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,
|
||||
|
@ -128,6 +128,7 @@ export default defineComponent({
|
|||
tabs,
|
||||
transactions,
|
||||
show,
|
||||
updateBalance: () => balanceStore.getBalance(mainStore.currentUser),
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
@ -19,7 +19,7 @@ const mainRoutes: FG_Plugin.MenuRoute[] = [
|
|||
route: {
|
||||
path: 'overview',
|
||||
name: 'balance-view',
|
||||
component: () => import('../pages/Overview.vue'),
|
||||
component: () => import('../pages/BalanceOverviewPage.vue'),
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ const mainRoutes: FG_Plugin.MenuRoute[] = [
|
|||
route: {
|
||||
path: 'admin',
|
||||
name: 'balance-admin',
|
||||
component: () => import('../pages/Admin.vue'),
|
||||
component: () => import('../pages/BalanceAdminPage.vue'),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
32
src/store.ts
32
src/store.ts
|
@ -77,7 +77,13 @@ export const useBalanceStore = defineStore({
|
|||
return data;
|
||||
},
|
||||
|
||||
async getBalances(filter?: { limit?: number; offset?: number; sortBy?: string; descending?: boolean }) {
|
||||
async getBalances(filter?: {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
sortBy?: string;
|
||||
descending?: boolean;
|
||||
filter?: string;
|
||||
}) {
|
||||
const { data } = await api.get<{ balances: BalancesResponse[]; count: number }>('/balance', {
|
||||
params: filter,
|
||||
});
|
||||
|
@ -125,14 +131,14 @@ export const useBalanceStore = defineStore({
|
|||
user: FG.User,
|
||||
filter:
|
||||
| {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
from?: Date;
|
||||
to?: Date;
|
||||
showReversals?: boolean;
|
||||
showCancelled?: boolean;
|
||||
descending?: boolean;
|
||||
}
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
from?: Date;
|
||||
to?: Date;
|
||||
showReversals?: boolean;
|
||||
showCancelled?: boolean;
|
||||
descending?: boolean;
|
||||
}
|
||||
| undefined = undefined
|
||||
) {
|
||||
if (!filter) filter = { limit: 10 };
|
||||
|
@ -140,7 +146,13 @@ export const useBalanceStore = defineStore({
|
|||
params: filter,
|
||||
});
|
||||
data.transactions.forEach((t) => fixTransaction(t));
|
||||
if (data.transactions) this.transactions.push(...data.transactions);
|
||||
if (data.transactions) {
|
||||
data.transactions.forEach((t) => {
|
||||
const idx = this.transactions.findIndex((x) => x.id === t.id);
|
||||
if (idx == -1) this.transactions.push(t);
|
||||
else this.transactions[idx] = t;
|
||||
});
|
||||
}
|
||||
return data;
|
||||
},
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
export function check_cent_step(value: number): boolean | string {
|
||||
return (value * 100) % 1 === 0 || 'Betrag muss in 1-Cent-Schritten angegeben werden';
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"extends": "@quasar/app/tsconfig-preset",
|
||||
"extends": "@quasar/app-webpack/tsconfig-preset",
|
||||
"target": "esnext",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src/",
|
||||
|
|
Loading…
Reference in New Issue