[User] Rollen können umbenannt werden

This commit is contained in:
Tim Gröger 2020-11-15 01:22:23 +01:00
parent e4378af76e
commit 63b25bb3d6
1 changed files with 31 additions and 33 deletions

View File

@ -1,17 +1,16 @@
<template> <template>
<div> <div>
<q-card class="col-12"> <q-card class="col-12">
<q-form <q-form @submit="save" @reset="reset">
@submit="save"
@reset="reset"
>
<q-linear-progress <q-linear-progress
indeterminate indeterminate
rounded rounded
color="primary" color="primary"
v-if="loading" v-if="loading"
/> />
<q-card-section class="fit row justify-start content-center items-center"> <q-card-section
class="fit row justify-start content-center items-center"
>
<span class="col-xs-12 col-sm-6 text-center text-h6"> <span class="col-xs-12 col-sm-6 text-center text-h6">
Rollen und Berechtigungen Rollen und Berechtigungen
</span> </span>
@ -38,6 +37,12 @@
class="fit row justify-start content-center items-center" class="fit row justify-start content-center items-center"
> >
<q-scroll-area style="height: 20em; width: 100%;"> <q-scroll-area style="height: 20em; width: 100%;">
<q-input
filled
v-model="newRoleName"
label="neuer Name"
v-if="role.id != -1"
/>
<q-option-group <q-option-group
:value="role.permissions" :value="role.permissions"
@input="updatePermissions" @input="updatePermissions"
@ -47,24 +52,10 @@
/> />
</q-scroll-area> </q-scroll-area>
</q-card-section> </q-card-section>
<q-card-actions <q-card-actions v-if="role" align="right">
v-if="role" <q-btn label="Löschen" color="negative" @click="remove" />
align="right" <q-btn label="Reset" type="reset" />
> <q-btn color="primary" type="submit" label="Speichern" />
<q-btn
label="Löschen"
color="negative"
@click="remove"
/>
<q-btn
label="Reset"
type="reset"
/>
<q-btn
color="primary"
type="submit"
label="Speichern"
/>
</q-card-actions> </q-card-actions>
</q-form> </q-form>
</q-card> </q-card>
@ -76,7 +67,7 @@ import {
computed, computed,
defineComponent, defineComponent,
ref, ref,
onBeforeMount, onBeforeMount
} from '@vue/composition-api'; } from '@vue/composition-api';
import { Store } from 'vuex'; import { Store } from 'vuex';
import { StateInterface } from 'src/store'; import { StateInterface } from 'src/store';
@ -87,10 +78,10 @@ export default defineComponent({
const store = <Store<StateInterface>>root.$store; const store = <Store<StateInterface>>root.$store;
onBeforeMount(() => { onBeforeMount(() => {
store.dispatch('user/getRoles').catch((error) => { store.dispatch('user/getRoles').catch(error => {
console.warn(error); console.warn(error);
}); });
store.dispatch('user/getPermissions').catch((error) => { store.dispatch('user/getPermissions').catch(error => {
console.warn(error); console.warn(error);
}); });
}); });
@ -99,14 +90,16 @@ export default defineComponent({
const role = ref<FG.Role | null>(null); const role = ref<FG.Role | null>(null);
const roles = computed(() => store.state.user.roles); const roles = computed(() => store.state.user.roles);
const permissions = computed(() => const permissions = computed(() =>
store.state.user.permissions.map((perm) => { store.state.user.permissions.map(perm => {
return { return {
value: perm, value: perm,
label: perm, label: perm
}; };
}) })
); );
const newRoleName = ref<string>('');
function createRole( function createRole(
name: string, name: string,
done: (arg0: string, arg1: string) => void done: (arg0: string, arg1: string) => void
@ -130,7 +123,7 @@ export default defineComponent({
role.value = { role.value = {
id: rl.id, id: rl.id,
name: rl.name, name: rl.name,
permissions: Array.from(rl.permissions), permissions: Array.from(rl.permissions)
}; };
} }
@ -138,14 +131,18 @@ export default defineComponent({
if (role.value) { if (role.value) {
if (role.value.id === -1) if (role.value.id === -1)
void store.dispatch('user/newRole', role.value); void store.dispatch('user/newRole', role.value);
else void store.dispatch('user/updateRole', role.value); else {
if (newRoleName.value !== '') role.value.name = newRoleName.value;
console.log(role.value);
void store.dispatch('user/updateRole', role.value);
}
} }
} }
function reset() { function reset() {
if (role.value && role.value.id !== -1) { if (role.value && role.value.id !== -1) {
const original = roles.value.find( const original = roles.value.find(
(value) => value.name === role.value?.name value => value.name === role.value?.name
); );
if (original) updateRole(original); if (original) updateRole(original);
} else { } else {
@ -161,7 +158,7 @@ export default defineComponent({
store store
.dispatch('user/deleteRole', role.value) .dispatch('user/deleteRole', role.value)
.then(() => (role.value = null)) .then(() => (role.value = null))
.catch((error) => console.warn(error)); .catch(error => console.warn(error));
} }
} }
} }
@ -178,7 +175,8 @@ export default defineComponent({
removeRole, removeRole,
remove, remove,
loading, loading,
newRoleName
}; };
}, }
}); });
</script> </script>