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 { boot } from 'quasar/wrappers';
import { RouteConfig } from 'vue-router'; import { RouteConfig } from 'vue-router';
import { Module, Store } from 'vuex'; import { Store } from 'vuex';
import { StateInterface } from 'src/store'; import { StateInterface } from 'src/store';
import { FG_Plugin } from 'src/plugins'; import { FG_Plugin } from 'src/plugins';
import routes from 'src/router/routes'; import routes from 'src/router/routes';

View File

@ -1,22 +1,28 @@
<template> <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-item-section v-if="icon" avatar>
<q-icon :name="icon" /> <q-icon :name="icon" />
</q-item-section> </q-item-section>
<q-item-section> <q-item-section>
<q-item-label>{{ realTitle }}</q-item-label> <q-item-label>{{ realTitle }}</q-item-label>
<q-item-label caption> <!--<q-item-label caption>
{{ permissions }} {{ caption }}
</q-item-label> </q-item-label>-->
</q-item-section> </q-item-section>
</q-item> </q-item>
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from '@vue/composition-api'; import { computed, defineComponent } from '@vue/composition-api';
import {Store} from 'vuex' import { Store } from 'vuex';
import {StateInterface} from "src/store"; import { StateInterface } from 'src/store';
export default defineComponent({ export default defineComponent({
name: 'EssentialLink', name: 'EssentialLink',
@ -60,14 +66,16 @@ export default defineComponent({
}); });
const hasPermissions = computed(() => { const hasPermissions = computed(() => {
let permissions = props.permissions let permissions = props.permissions;
if (permissions) { if (permissions) {
return (<string[]>permissions).every(permission => { 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 };
} }

View File

@ -4,8 +4,9 @@
<script lang="ts"> <script lang="ts">
import { computed, defineComponent } from '@vue/composition-api'; import { computed, defineComponent } from '@vue/composition-api';
import {Store} from "vuex"; import { Store } from 'vuex';
import {StateInterface} from "src/store"; import { StateInterface } from 'src/store';
export default defineComponent({ export default defineComponent({
name: 'ShortCutLink', name: 'ShortCutLink',
props: { props: {
@ -22,17 +23,18 @@ export default defineComponent({
} }
}, },
setup(props, { root }) { setup(props, { root }) {
const hasPermissions = computed(() => { const hasPermissions = computed(() => {
let permissions = props.permissions let permissions = props.permissions;
if (permissions) { if (permissions) {
return (<string[]>permissions).every(permission => { 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 {hasPermissions} return { hasPermissions };
} }
}); });
</script> </script>

View File

@ -1,12 +1,95 @@
<template> <template>
<q-page padding> <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> </q-page>
</template> </template>
<script lang="ts"> <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({ export default defineComponent({
// name: 'PageName' // 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> </script>

View File

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

View File

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