add new user and role table in app (in progress)
All checks were successful
Build Quasar SPA and Go Backend for memberApp / build-spa (push) Successful in 2m12s
Build Quasar SPA and Go Backend for memberApp / build-backend (amd64, , linux) (push) Successful in 5m8s
Build Quasar SPA and Go Backend for memberApp / build-backend (amd64, .exe, windows) (push) Successful in 5m8s
Build Quasar SPA and Go Backend for memberApp / build-backend (arm, 6, , linux) (push) Successful in 4m57s
Build Quasar SPA and Go Backend for memberApp / build-backend (arm64, , linux) (push) Successful in 5m7s

This commit is contained in:
Adrian Zürcher
2025-10-14 16:41:20 +02:00
parent fdf56a4c0b
commit 690b7f4034
45 changed files with 1427 additions and 629 deletions

View File

@@ -0,0 +1,79 @@
import { appApi } from 'src/boot/axios';
import { ref, computed } from 'vue';
import { useNotify } from 'src/vueLib/general/useNotify';
import { i18n } from 'boot/lang';
import type { Roles } from 'src/vueLib/models/roles';
export const roles = ref<Roles>([]);
export function useRoleTable() {
const pagination = ref({
sortBy: 'role',
descending: false,
page: 1,
rowsPerPage: 10,
});
const columns = computed(() => [
{
name: 'id',
align: 'left' as const,
label: 'Id',
field: 'id',
sortable: true,
style: 'width: 50px; max-width: 50px;',
},
{
name: 'role',
align: 'left' as const,
label: i18n.global.t('role'),
field: 'role',
sortable: true,
},
{
name: 'rights',
align: 'left' as const,
label: i18n.global.t('rights'),
field: 'rights',
sortable: true,
style: 'width: 120px; max-width: 120px;',
},
{ name: 'option', align: 'center' as const, label: '', field: 'option', icon: 'option' },
]);
const { NotifyResponse } = useNotify();
const loading = ref(false);
//updates user list from database
function updateRoles() {
loading.value = true;
appApi
.get('secure/roles')
.then((resp) => {
if (resp.data === null) {
roles.value = [];
return;
}
roles.value = resp.data as Roles;
if (roles.value === null) {
roles.value = [];
return;
}
})
.catch((err) => {
NotifyResponse(err, 'error');
})
.finally(() => {
loading.value = false;
});
}
return {
roles,
pagination,
columns,
loading,
updateRoles,
};
}

View File

@@ -0,0 +1,201 @@
<template>
<div class="q-pa-md">
<q-table
flat
bordered
ref="tableRef"
title="Roles"
title-class="text-bold text-blue-9"
:no-data-label="$t('noDataAvailable')"
:loading-label="$t('loading')"
:rows-per-page-label="$t('recordsPerPage')"
:selected-rows-label="(val) => val + $t('recordSelected')"
:rows="roles"
:columns="columns"
row-key="id"
v-model:pagination="pagination"
:loading="loading"
:filter="filter"
:selection="selectOption ? 'multiple' : 'none'"
v-model:selected="selected"
binary-state-sort
class="bigger-table-text"
>
<template v-slot:top-left>
<q-btn-group push flat style="color: grey">
<q-btn dense flat icon="add" @click="openAllValueDialog(null)">
<q-tooltip>{{ $t('addNewRole') }}</q-tooltip>
</q-btn>
<q-btn
dense
flat
style="color: grey"
:icon="selectOption ? 'check_box' : 'check_box_outline_blank'"
@click="selectOption = !selectOption"
>
<q-tooltip>{{ $t('selectRoleOptions') }}</q-tooltip>
</q-btn>
</q-btn-group>
<div v-if="selectOption && selected.length > 0">
<q-btn flat dense icon="more_vert" @click="openSubmenu = true" />
<q-menu v-if="openSubmenu" anchor="bottom middle" self="top middle">
<q-item
clickable
v-close-popup
@click="openRemoveDialog(...selected)"
class="text-negative"
>{{ $t('delete') }}</q-item
>
</q-menu>
</div>
<div v-if="selectOption && selected.length > 0" class="q-ml-md text-weight-bold">
{{ $t('selected') }}: {{ selected.length }}
</div>
</template>
<template v-slot:top-right>
<q-input filled dense debounce="300" v-model="filter" :placeholder="$t('search')">
<template v-slot:append>
<q-icon name="search" />
</template>
</q-input>
</template>
<template v-slot:body-cell="props">
<q-td
:props="props"
@click="openSingleValueDialog(props.col.label, props.col.name, props.row)"
>
{{ props.value }}
</q-td>
</template>
<template v-slot:body-cell-option="props">
<q-td :props="props">
<q-btn flat dense icon="delete" color="negative" @click="openRemoveDialog(props.row)">
<q-tooltip> {{ $t('delete') }} </q-tooltip>
</q-btn>
</q-td>
</template>
</q-table>
</div>
<EditOneDialog ref="editOneDialog" v-on:update="updateRoles"></EditOneDialog>
<EditAllDialog ref="editAllDialog" v-on:update="updateRoles"></EditAllDialog>
<OkDialog
ref="okDialog"
:dialog-label="$t('delete')"
:text="$t('doYouWantToDelete') + ' ' + deleteText"
label-color="red"
:button-cancel-label="$t('cancel')"
:button-ok-label="$t('confirm')"
:button-ok-flat="false"
button-ok-color="red"
v-on:update-confirm="(val) => removeRole(...val)"
></OkDialog>
</template>
<script setup lang="ts">
import { appApi } from 'src/boot/axios';
import { ref, onMounted } from 'vue';
import type { Roles, Role } from 'src/vueLib/models/roles';
import EditOneDialog from 'src/components/EditOneDialog.vue';
import EditAllDialog from 'src/components/RoleEditAllDialog.vue';
import OkDialog from 'src/components/dialog/OkDialog.vue';
import { useNotify } from 'src/vueLib/general/useNotify';
import { useRoleTable } from './RoleTable';
import { useLogin } from 'src/vueLib/login/useLogin';
const { NotifyResponse } = useNotify();
const editOneDialog = ref();
const editAllDialog = ref();
const okDialog = ref();
const deleteText = ref('');
const selectOption = ref(false);
const selected = ref<Roles>([]);
const openSubmenu = ref(false);
const filter = ref('');
const { roles, pagination, loading, columns, updateRoles } = useRoleTable();
//load on mounting page
onMounted(() => {
loading.value = true;
updateRoles();
});
// opens dialog for all role values
function openSingleValueDialog(label: string, field: string, role: Role) {
editOneDialog.value?.open(label, field, role);
}
//opens dialog for one value
function openAllValueDialog(role: Role | null) {
editAllDialog.value?.open(role);
}
//opens remove dialog
function openRemoveDialog(...roles: Roles) {
if (roles.length === 1) {
deleteText.value = "'" + roles[0]?.role + "'";
} else {
deleteText.value = String(roles.length) + ' roles';
}
okDialog.value?.open(roles);
}
//remove role from database
function removeRole(...removeRoles: Roles) {
const roles: string[] = [];
removeRoles.forEach((role: Role) => {
if (role.role) {
roles.push(role.role);
}
});
const login = useLogin();
const user = login.getUser();
appApi
.post('secure/roles/delete?role=' + user?.role, { roles: roles })
.then(() => {
updateRoles();
selected.value = [];
})
.catch((err) => NotifyResponse(err, 'error'))
.finally(() => {
loading.value = false;
});
}
function getSelected(): Roles {
if (selected.value.length === 0) return [];
return selected.value;
}
defineExpose({
getSelected,
});
</script>
<style>
@keyframes blink-yellow {
0%,
100% {
background-color: yellow;
}
50% {
background-color: transparent;
}
}
.blink-yellow {
animation: blink-yellow 1.5s step-start 6 !important;
}
.bigger-table-text .q-table__middle td {
font-size: 14px;
}
.bigger-table-text .q-table__top,
.bigger-table-text .q-table__bottom,
.bigger-table-text th {
font-size: 14px;
}
</style>