add new workspace settings for users
This commit is contained in:
BIN
backend/gagag.dbaa
Normal file
BIN
backend/gagag.dbaa
Normal file
Binary file not shown.
@@ -3,7 +3,7 @@ module backend
|
||||
go 1.25.4
|
||||
|
||||
require (
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.48
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.51
|
||||
gitea.tecamino.com/paadi/memberDB v1.1.30
|
||||
gitea.tecamino.com/paadi/tecamino-dbm v1.0.0
|
||||
gitea.tecamino.com/paadi/tecamino-logger v0.2.1
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.48 h1:PYZvOwR9HCORAFpm7Nd5ZXvWwT5w04OvbcHhVHmPJlw=
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.48/go.mod h1:0kUGU4Jw2jSvopCCwecuX/2QnVKS09Ec1KQNrBXvsFs=
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.51 h1:kTPwN+0Zw/Uyfo6el1jl5ORzIrjQdC8PUlczoN9mBS4=
|
||||
gitea.tecamino.com/paadi/access-handler v1.0.51/go.mod h1:0kUGU4Jw2jSvopCCwecuX/2QnVKS09Ec1KQNrBXvsFs=
|
||||
gitea.tecamino.com/paadi/dbHandler v1.1.12 h1:F1ARSTUm0MZmF84FfD/g5RQNMYyDYXHYrB3cXPSi4qw=
|
||||
gitea.tecamino.com/paadi/dbHandler v1.1.12/go.mod h1:y/xn/POJg1DO++67uKvnO23lJQgh+XFQq7HZCS9Getw=
|
||||
gitea.tecamino.com/paadi/memberDB v1.1.30 h1:N+3V9A/+OAGIoJeUNVHj1qUuBcy6ADLYFIgCnp2Ggk4=
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
:label="$t('workspaces')"
|
||||
:options="localUser?.workspaces"
|
||||
option-label="name"
|
||||
v-model="settings.workspace"
|
||||
v-model="localWorkspace"
|
||||
@update:model-value="changeWorkspace"
|
||||
></q-select>
|
||||
<q-select
|
||||
@@ -187,7 +187,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { logo, appName, databaseName, workspace } from 'src/vueLib/models/settings';
|
||||
import { logo, appName } from 'src/vueLib/models/settings';
|
||||
import { onMounted, reactive, ref, watch } from 'vue';
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
@@ -195,9 +195,11 @@ import type { Settings } from 'src/vueLib/models/settings';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
import { setLocalSettings } from 'src/localstorage/localStorage';
|
||||
import SiteTitle from 'src/vueLib/general/SiteTitle.vue';
|
||||
import type { User } from 'src/vueLib/models/user';
|
||||
import { type User } from 'src/vueLib/models/user';
|
||||
import { i18n } from 'src/boot/lang';
|
||||
import DialogFrame from 'src/vueLib/dialog/DialogFrame.vue';
|
||||
import type { Workspace } from 'src/vueLib/models/workspaces';
|
||||
import { openDatabase } from '../vueLib/components/DatabaseCall';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const colorGroup = ref(false);
|
||||
@@ -207,11 +209,11 @@ const newDatabase = ref<string>('');
|
||||
const foundDatabases = ref<number>(0);
|
||||
const localUser = ref<User>();
|
||||
const databases = ref<string[]>([]);
|
||||
const localWorkspace = ref<Workspace>();
|
||||
|
||||
const settings = reactive<Settings>({
|
||||
appName: appName.value,
|
||||
icon: logo.value,
|
||||
databaseName: databaseName.value,
|
||||
workspace: { name: '', description: '', uuid: workspace.value },
|
||||
primaryColor: document.documentElement.style.getPropertyValue('--q-primary'),
|
||||
primaryColorText: document.documentElement.style.getPropertyValue('--q-primary-text'),
|
||||
secondaryColor: document.documentElement.style.getPropertyValue('--q-secondary'),
|
||||
@@ -224,11 +226,15 @@ onMounted(async () => {
|
||||
.then((resp) => {
|
||||
if (!resp.data) return;
|
||||
localUser.value = resp.data[0];
|
||||
settings.workspace = localUser.value?.settings?.workspace || null;
|
||||
localWorkspace.value = localUser.value?.workspaces?.find(
|
||||
(w) => w.id === localUser.value?.workspaceId,
|
||||
);
|
||||
|
||||
if (localUser.value) {
|
||||
settings.databaseName = localUser.value.settings?.databaseName || '';
|
||||
|
||||
if (settings.workspace) {
|
||||
appApi
|
||||
.post('workspaces/data', settings.workspace)
|
||||
.post('workspaces/data', localWorkspace.value)
|
||||
.then((resp) => {
|
||||
if (!resp.data) {
|
||||
settings.databaseName = '';
|
||||
@@ -239,8 +245,6 @@ onMounted(async () => {
|
||||
foundDatabases.value = resp.data.data.length;
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
} else {
|
||||
settings.databaseName = '';
|
||||
}
|
||||
})
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
@@ -249,7 +253,6 @@ onMounted(async () => {
|
||||
watch(settings, (newSettings) => {
|
||||
logo.value = newSettings.icon;
|
||||
appName.value = newSettings.appName;
|
||||
databaseName.value = newSettings.databaseName;
|
||||
});
|
||||
|
||||
function resetColors() {
|
||||
@@ -265,7 +268,7 @@ function resetColors() {
|
||||
|
||||
function changeWorkspace() {
|
||||
appApi
|
||||
.post('workspaces/data', settings.workspace)
|
||||
.post('workspaces/data', localWorkspace.value)
|
||||
.then((resp) => {
|
||||
if (resp.data) {
|
||||
databases.value = [i18n.global.t('addNewDatabase')];
|
||||
@@ -277,9 +280,11 @@ function changeWorkspace() {
|
||||
}
|
||||
|
||||
function changeDatabase() {
|
||||
if (settings.databaseName) {
|
||||
if (databases.value.indexOf(settings.databaseName) === 0) {
|
||||
addDatabaseRef.value?.open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeItem(index: number) {
|
||||
@@ -297,7 +302,7 @@ function addNewDatabase() {
|
||||
addDatabaseRef.value.close();
|
||||
}
|
||||
|
||||
function save() {
|
||||
async function save() {
|
||||
document.documentElement.style.setProperty('--q-primary', settings.primaryColor);
|
||||
document.documentElement.style.setProperty('--q-primary-text', settings.primaryColorText);
|
||||
document.documentElement.style.setProperty('--q-secondary', settings.secondaryColor);
|
||||
@@ -309,8 +314,12 @@ function save() {
|
||||
}
|
||||
|
||||
setLocalSettings(settings);
|
||||
if (localUser.value) {
|
||||
await user.setUser(localUser.value);
|
||||
localUser.value.workspaceId = localWorkspace.value?.id;
|
||||
}
|
||||
|
||||
appApi
|
||||
await appApi
|
||||
.post('users/update', localUser.value)
|
||||
.then(() =>
|
||||
NotifyResponse(
|
||||
@@ -324,5 +333,7 @@ function save() {
|
||||
),
|
||||
)
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
|
||||
await openDatabase().catch((err) => console.error(err));
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -50,6 +50,9 @@ export const useUserStore = defineStore('user', {
|
||||
}
|
||||
};
|
||||
},
|
||||
getWorkspaceUuid: (state: UserState) => {
|
||||
return state.user?.workspaces?.find((w) => w.id === state.user?.workspaceId)?.uuid;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setFirstLogin(b: boolean) {
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import { ref } from 'vue';
|
||||
import type { Workspace } from './workspaces';
|
||||
|
||||
export const logo = ref<string>('');
|
||||
export const appName = ref<string>('Attendance Records');
|
||||
export const databaseName = ref<string>('members.dba');
|
||||
export const workspace = ref<string>('');
|
||||
|
||||
export type Settings = {
|
||||
appName: string;
|
||||
icon: string;
|
||||
databaseName: string;
|
||||
workspace: Workspace | null;
|
||||
databaseName?: string;
|
||||
primaryColor: string;
|
||||
primaryColorText: string;
|
||||
secondaryColor: string;
|
||||
@@ -21,8 +17,6 @@ export function DefaultSettings(): Settings {
|
||||
return {
|
||||
appName: 'Attendance Records',
|
||||
icon: '',
|
||||
databaseName: 'members.dba',
|
||||
workspace: { name: '', description: '', uuid: workspace.value },
|
||||
primaryColor: document.documentElement.style.getPropertyValue('--q-primary-text'),
|
||||
primaryColorText: document.documentElement.style.getPropertyValue('--q-primary'),
|
||||
secondaryColor: document.documentElement.style.getPropertyValue('--q-secondary'),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Permissions } from '../checkboxes/permissions';
|
||||
import type { Role } from './roles';
|
||||
import type { Settings } from './settings';
|
||||
import type { Workspaces } from './workspaces';
|
||||
|
||||
export interface User {
|
||||
id: number;
|
||||
@@ -9,7 +10,8 @@ export interface User {
|
||||
permissions?: Permissions;
|
||||
settings?: Settings;
|
||||
newDatabase?: boolean;
|
||||
workspaces?: string[];
|
||||
workspaceId?: number | undefined;
|
||||
workspaces?: Workspaces;
|
||||
}
|
||||
|
||||
export interface UserState {
|
||||
|
||||
@@ -12,6 +12,7 @@ export interface User {
|
||||
password?: string;
|
||||
newPassword?: string;
|
||||
settings?: Settings;
|
||||
workspaceId?: number;
|
||||
workspaces?: Workspace[];
|
||||
}
|
||||
|
||||
|
||||
@@ -129,8 +129,7 @@ import { i18n } from 'src/boot/lang';
|
||||
import { QTable } from 'quasar';
|
||||
import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
import SearchableInput from '../components/SearchableInput.vue';
|
||||
import type { User } from 'src/vueLib/models/user';
|
||||
import { workspace } from 'src/vueLib/models/settings';
|
||||
import { type User } from 'src/vueLib/models/user';
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
const editOneDialog = ref();
|
||||
@@ -179,8 +178,11 @@ function openRemoveDialog(...workspaces: Workspaces) {
|
||||
function removeWorkspace(...removeWorkspaces: Workspaces) {
|
||||
const workspaces: Workspace[] = [];
|
||||
|
||||
const user = useUserStore().user;
|
||||
const usedWorkspaceId = user?.workspaces?.find((w) => w.uuid === user.workspaceId)?.id;
|
||||
|
||||
removeWorkspaces.forEach((workspace: Workspace) => {
|
||||
if (workspace.id === currentUser.value?.settings?.workspace) {
|
||||
if (workspace.id === usedWorkspaceId) {
|
||||
NotifyResponse(i18n.global.t('notPossibleToDeleteUsedWorkspace'), 'error');
|
||||
} else if (workspace.id) {
|
||||
workspaces.push(workspace);
|
||||
@@ -192,11 +194,6 @@ function removeWorkspace(...removeWorkspaces: Workspaces) {
|
||||
workspaces: workspaces,
|
||||
})
|
||||
.then(() => {
|
||||
const storageWorkspace = localStorage.getItem('workspace');
|
||||
if (workspaces.some((w) => w.uuid === storageWorkspace)) {
|
||||
workspace.value = '';
|
||||
localStorage.removeItem('workspace');
|
||||
}
|
||||
updateWorkspaces().catch((err) => NotifyResponse(err, 'error'));
|
||||
if (workspaces.length === 1) {
|
||||
NotifyResponse("'" + workspaces[0]?.name + "' " + i18n.global.t('deleted'), 'warning');
|
||||
|
||||
Reference in New Issue
Block a user