release v2.0.0 #4

Merged
crimsen merged 481 commits from develop into master 2024-01-18 15:15:08 +00:00
7 changed files with 236 additions and 56 deletions
Showing only changes of commit 3247a5bb01 - Show all commits

View File

@ -1,6 +1,6 @@
import { boot } from 'quasar/wrappers';
import { RouteConfig } from 'vue-router';
import { Module, Store } from 'vuex';
import { Store } from 'vuex';
import { StateInterface } from 'src/store';
import { FG_Plugin } from 'src/plugins';
import routes from 'src/router/routes';

View File

@ -1,22 +1,28 @@
<template>
<q-item clickable tag="a" target="self" :to="{ name: link }" v-if="hasPermissions">
<q-item
clickable
tag="a"
target="self"
:to="{ name: link }"
v-if="hasPermissions"
>
<q-item-section v-if="icon" avatar>
<q-icon :name="icon"/>
<q-icon :name="icon" />
</q-item-section>
<q-item-section>
<q-item-label>{{ realTitle }}</q-item-label>
<q-item-label caption>
{{ permissions }}
</q-item-label>
<!--<q-item-label caption>
{{ caption }}
</q-item-label>-->
</q-item-section>
</q-item>
</template>
<script lang="ts">
import {computed, defineComponent} from '@vue/composition-api';
import {Store} from 'vuex'
import {StateInterface} from "src/store";
import { computed, defineComponent } from '@vue/composition-api';
import { Store } from 'vuex';
import { StateInterface } from 'src/store';
export default defineComponent({
name: 'EssentialLink',
@ -45,7 +51,7 @@ export default defineComponent({
}
},
setup(props, {root}) {
setup(props, { root }) {
let title = computed<string>(() => {
if (props.title.includes('loadFromStore')) {
const startIndex = props.title.indexOf('(') + 1;
@ -60,16 +66,18 @@ export default defineComponent({
});
const hasPermissions = computed(() => {
let permissions = props.permissions
let permissions = props.permissions;
if (permissions) {
return (<string[]>permissions).every(permission => {
return (<{'user/permissions': string[]}>(<Store<StateInterface>>root.$store).getters)['user/permissions'].includes(permission)
})
return (<{ 'user/permissions': string[] }>(
(<Store<StateInterface>>root.$store).getters
))['user/permissions'].includes(permission);
});
}
return true
})
return true;
});
return {realTitle: title, hasPermissions};
return { realTitle: title, hasPermissions };
}
});
</script>

View File

@ -1,11 +1,12 @@
<template>
<q-btn flat dense :icon="icon" :to="{ name: link }" v-if="hasPermissions"/>
<q-btn flat dense :icon="icon" :to="{ name: link }" v-if="hasPermissions" />
</template>
<script lang="ts">
import {computed, defineComponent} from '@vue/composition-api';
import {Store} from "vuex";
import {StateInterface} from "src/store";
import { computed, defineComponent } from '@vue/composition-api';
import { Store } from 'vuex';
import { StateInterface } from 'src/store';
export default defineComponent({
name: 'ShortCutLink',
props: {
@ -21,18 +22,19 @@ export default defineComponent({
default: undefined
}
},
setup(props, {root}) {
setup(props, { root }) {
const hasPermissions = computed(() => {
let permissions = props.permissions
let permissions = props.permissions;
if (permissions) {
return (<string[]>permissions).every(permission => {
return (<{'user/permissions': string[]}>(<Store<StateInterface>>root.$store).getters)['user/permissions'].includes(permission)
})
return (<{ 'user/permissions': string[] }>(
(<Store<StateInterface>>root.$store).getters
))['user/permissions'].includes(permission);
});
}
return true
})
return {hasPermissions}
return true;
});
return { hasPermissions };
}
});
</script>

View File

@ -1,12 +1,95 @@
<template>
<q-page padding>
<h1>Add works</h1>
<q-card>
<q-card-section class="row">
<div class="col-4 row q-pa-sm">
<q-btn
class="col"
color="green"
label="2€"
@click="changeBalance(-2)"
/>
</div>
<div class="col-4 row q-pa-sm">
<q-btn
class="col"
color="green"
label="1€"
@click="changeBalance(-1)"
/>
</div>
<div class="col-4 row q-pa-sm">
<q-btn
class="col"
color="green"
label="0,50€"
@click="changeBalance(-0.5)"
/>
</div>
<div class="col-4 row q-pa-sm">
<q-btn
class="col"
color="green"
label="0,40€"
@click="changeBalance(-0.4)"
/>
</div>
<div class="col-4 row q-pa-sm">
<q-btn
class="col"
color="green"
label="0,20€"
@click="changeBalance(-0.2)"
/>
</div>
<div class="col-4 row q-pa-sm">
<q-btn
class="col"
color="green"
label="0,10€"
@click="changeBalance(-0.1)"
/>
</div>
</q-card-section>
<q-card-section>
<div class="text-h6">{{ balance.toFixed(2) }} </div>
</q-card-section>
<q-card-actions>
<q-btn label="test" @click="$store.dispatch('balance/getBalance')" />
</q-card-actions>
</q-card>
</q-page>
</template>
<script lang="ts">
import { defineComponent } from '@vue/composition-api'
import { computed, defineComponent, onBeforeMount } from '@vue/composition-api';
import { BalanceInterface } from 'src/plugins/balance/store/balance';
import { Store } from 'vuex';
export default defineComponent({
// name: 'PageName'
})
setup(_, { root }) {
onBeforeMount(() => {
store.dispatch('balance/getBalance').catch(err => {
console.warn(err);
});
});
const store: Store<{ balance: BalanceInterface }> = <
Store<{ balance: BalanceInterface }>
>root.$store;
const balance = computed<number>(() => {
return store.state.balance.balance;
});
function changeBalance(amount: number) {
store
.dispatch('balance/changeBalance', amount)
.catch(err => console.log(err));
}
return { balance, changeBalance };
}
});
</script>

View File

@ -1,13 +1,17 @@
import {Module} from 'vuex';
import {StateInterface} from "src/store";
import mainRoutes from "./routes"
import { Module } from 'vuex';
import { StateInterface } from 'src/store';
import mainRoutes from './routes';
import { FG_Plugin } from 'src/plugins';
import balance, { BalanceInterface } from './store/balance';
const plugin: FG_Plugin.Plugin = {
name: 'Balance',
mainRoutes,
requiredModules: ['User'],
version: '0.0.1',
}
store: new Map<string, Module<BalanceInterface, StateInterface>>([
['balance', balance]
])
};
export default plugin;

View File

@ -1,22 +1,22 @@
import {FG_Plugin} from 'src/plugins';
import { FG_Plugin } from 'src/plugins';
const permissions = {
// Show own and others balance
SHOW: "balance_show",
SHOW_OTHER: "balance_show_others",
// Credit balance
ADD: "balance_add",
// Debit balance
SUB: "balance_sub",
// Send from to other
SEND: "balance_send",
// Send from other to another
SEND_OTHER: "balance_send_others",
// Can set limit for users
SET_LIMIT: "balance_set_limit",
//Allow sending / sub while exceeding the set limit
EXCEED_LIMIT: "balance_exceed_limit"
}
// Show own and others balance
SHOW: 'balance_show',
SHOW_OTHER: 'balance_show_others',
// Credit balance
ADD: 'balance_add',
// Debit balance
SUB: 'balance_sub',
// Send from to other
SEND: 'balance_send',
// Send from other to another
SEND_OTHER: 'balance_send_others',
// Can set limit for users
SET_LIMIT: 'balance_set_limit',
//Allow sending / sub while exceeding the set limit
EXCEED_LIMIT: 'balance_exceed_limit'
};
const mainRoutes: FG_Plugin.PluginRouteConfig[] = [
{
@ -25,7 +25,7 @@ const mainRoutes: FG_Plugin.PluginRouteConfig[] = [
path: 'balance',
name: 'balance',
component: () => import('../pages/MainPage.vue'),
meta: {permissions: ['user']},
meta: { permissions: ['user'] },
children: [
{
title: 'Anschreiben',
@ -33,11 +33,11 @@ const mainRoutes: FG_Plugin.PluginRouteConfig[] = [
path: 'balance-add',
name: 'balance-add',
shortcut: true,
meta: {permissions: [permissions.ADD, permissions.SHOW]},
meta: { permissions: [permissions.SUB, permissions.SHOW] },
component: () => import('../pages/Add.vue')
}
]
}
]
];
export default mainRoutes
export default mainRoutes;

View File

@ -0,0 +1,83 @@
import { Module, MutationTree, ActionTree, GetterTree } from 'vuex';
import { StateInterface } from 'src/store';
import { axios } from 'src/boot/axios';
import { AxiosResponse } from 'axios';
interface BalanceResponse {
balance: number;
credit: number;
debit: number;
}
export interface BalanceInterface extends BalanceResponse {
limit: number;
}
const state: BalanceInterface = {
balance: 0,
credit: 0,
debit: 0,
limit: 0
};
const mutations: MutationTree<BalanceInterface> = {
setBalance(state, data: number) {
state.balance = data;
},
setCredit(state, data: number) {
state.credit = data;
},
setDebit(state, data: number) {
state.debit = data;
},
setLimit(state, data: number) {
state.limit = data;
}
};
const actions: ActionTree<BalanceInterface, StateInterface> = {
getBalance({ commit, rootState }) {
axios
.get(`/users/${rootState.user.user.userid}/balance`)
.then(({ data }: AxiosResponse<BalanceResponse>) => {
commit('setBalance', data.balance);
commit('setCredit', data.credit);
commit('setDebit', data.debit);
})
.catch(err => {
console.warn(err);
});
},
getLimit({ rootState }) {
axios
.get(`/users/${rootState.user.user.userid}/balance/limit`)
.then(({ data }) => {
console.log(data);
})
.catch(err => {
console.warn(err);
});
},
changeBalance({ rootState, dispatch }, amount: number) {
axios
.put(`/users/${rootState.user.user.userid}/balance`, <{ amount: number }>{
amount: amount
})
.then(() => {
dispatch('getBalance').catch(err => console.warn(err));
})
.catch(err => console.warn(err));
}
};
const getters: GetterTree<BalanceInterface, StateInterface> = {};
const balance: Module<BalanceInterface, StateInterface> = {
namespaced: true,
state,
mutations,
actions,
getters
};
export default balance;