Merge branch 'main' into #3-calendar

# Conflicts:
#	package-lock.json
#	src/main.css
#	src/router/authGuards.ts
#	src/types/permissionTypes.ts
This commit is contained in:
Julian Krauser 2024-11-07 11:06:52 +01:00
commit 8074dbf5c4
38 changed files with 2228 additions and 66 deletions

View file

@ -0,0 +1,105 @@
import { defineStore } from "pinia";
import type { CreateProtocolViewModel, SyncProtocolViewModel } from "@/viewmodels/admin/protocol.models";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import type { ProtocolViewModel } from "@/viewmodels/admin/protocol.models";
import cloneDeep from "lodash.clonedeep";
import isEqual from "lodash.isEqual";
import difference from "lodash.difference";
export const useProtocolStore = defineStore("protocol", {
state: () => {
return {
protocols: [] as Array<ProtocolViewModel & { tab_pos: number }>,
totalCount: 0 as number,
loading: "loading" as "loading" | "fetched" | "failed",
activeProtocol: null as number | null,
activeProtocolObj: null as ProtocolViewModel | null,
origin: null as ProtocolViewModel | null,
loadingActive: "loading" as "loading" | "fetched" | "failed",
syncingProtocol: "synced" as "synced" | "syncing" | "detectedChanges" | "failed",
};
},
getters: {
detectedChangeProtocol: (state) =>
!isEqual(state.origin, state.activeProtocolObj) && state.syncingProtocol != "syncing",
},
actions: {
setProtocolSyncingState(state: "synced" | "syncing" | "detectedChanges" | "failed") {
this.syncingProtocol = state;
},
fetchProtocols(offset = 0, count = 25, clear = false) {
if (clear) this.protocols = [];
this.loading = "loading";
http
.get(`/admin/protocol?offset=${offset}&count=${count}`)
.then((result) => {
this.totalCount = result.data.total;
result.data.protocols
.filter((elem: ProtocolViewModel) => this.protocols.findIndex((m) => m.id == elem.id) == -1)
.map((elem: ProtocolViewModel, index: number): ProtocolViewModel & { tab_pos: number } => {
return {
...elem,
tab_pos: index + offset,
};
})
.forEach((elem: ProtocolViewModel & { tab_pos: number }) => {
this.protocols.push(elem);
});
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
fetchProtocolByActiveId() {
this.loadingActive = "loading";
http
.get(`/admin/protocol/${this.activeProtocol}`)
.then((res) => {
this.origin = res.data;
this.activeProtocolObj = cloneDeep(this.origin);
this.loadingActive = "fetched";
})
.catch((err) => {
this.loadingActive = "failed";
});
},
fetchProtocolById(id: number) {
return http.get(`/admin/protocol/${id}`);
},
async createProtocol(protocol: CreateProtocolViewModel): Promise<AxiosResponse<any, any>> {
const result = await http.post(`/admin/protocol`, {
title: protocol.title,
date: protocol.date,
});
this.fetchProtocols();
return result;
},
async synchronizeActiveProtocol(): Promise<void> {
if (this.origin == null || this.activeProtocolObj == null) return;
this.syncingProtocol = "syncing";
await http
.patch(`/admin/protocol/${this.origin.id}/synchronize`, {
title: this.activeProtocolObj.title,
date: this.activeProtocolObj.date,
starttime: this.activeProtocolObj.starttime,
endtime: this.activeProtocolObj.endtime,
summary: this.activeProtocolObj.summary,
})
.then((res) => {
this.syncingProtocol = "synced";
})
.catch((err) => {
this.syncingProtocol = "failed";
});
this.fetchProtocolById(this.origin.id)
.then((res) => {
this.origin = res.data;
if (this.detectedChangeProtocol) this.syncingProtocol = "detectedChanges";
})
.catch((err) => {});
},
},
});

View file

@ -0,0 +1,82 @@
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import type {
ProtocolAgendaViewModel,
SyncProtocolAgendaViewModel,
} from "../../viewmodels/admin/protocolAgenda.models";
import { useProtocolStore } from "./protocol";
import cloneDeep from "lodash.clonedeep";
import isEqual from "lodash.isEqual";
import differenceWith from "lodash.differencewith";
export const useProtocolAgendaStore = defineStore("protocolAgenda", {
state: () => {
return {
agenda: [] as Array<ProtocolAgendaViewModel>,
origin: [] as Array<ProtocolAgendaViewModel>,
loading: "loading" as "loading" | "fetched" | "failed",
syncingProtocolAgenda: "synced" as "synced" | "syncing" | "detectedChanges" | "failed",
};
},
getters: {
detectedChangeProtocolAgenda: (state) =>
!isEqual(state.origin, state.agenda) && state.syncingProtocolAgenda != "syncing",
},
actions: {
setProtocolAgendaSyncingState(state: "synced" | "syncing" | "detectedChanges" | "failed") {
this.syncingProtocolAgenda = state;
},
fetchProtocolAgenda() {
this.loading = "loading";
this.fetchProtocolAgendaPromise()
.then((result) => {
this.origin = result.data;
this.agenda = cloneDeep(this.origin);
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
fetchProtocolAgendaPromise() {
const protocolId = useProtocolStore().activeProtocol;
return http.get(`/admin/protocol/${protocolId}/agenda`);
},
createProtocolAgenda() {
const protocolId = useProtocolStore().activeProtocol;
if (protocolId == null) return;
return http
.post(`/admin/protocol/${protocolId}/agenda`)
.then((res) => {
this.agenda.push({
id: Number(res.data),
topic: "",
context: "",
protocolId: Number(protocolId),
});
})
.catch((err) => {});
},
async synchronizeActiveProtocolAgenda() {
this.syncingProtocolAgenda = "syncing";
const protocolId = useProtocolStore().activeProtocol;
await http
.patch(`/admin/protocol/${protocolId}/synchronize/agenda`, {
agenda: differenceWith(this.agenda, this.origin, isEqual),
})
.then((res) => {
this.syncingProtocolAgenda = "synced";
})
.catch((err) => {
this.syncingProtocolAgenda = "failed";
});
this.fetchProtocolAgendaPromise()
.then((res) => {
this.origin = res.data;
if (this.detectedChangeProtocolAgenda) this.syncingProtocolAgenda = "detectedChanges";
})
.catch((err) => {});
},
},
});

View file

@ -0,0 +1,83 @@
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import type {
ProtocolDecisionViewModel,
SyncProtocolDecisionViewModel,
} from "../../viewmodels/admin/protocolDecision.models";
import { useProtocolStore } from "./protocol";
import cloneDeep from "lodash.clonedeep";
import isEqual from "lodash.isEqual";
import differenceWith from "lodash.differencewith";
export const useProtocolDecisionStore = defineStore("protocolDecision", {
state: () => {
return {
decision: [] as Array<ProtocolDecisionViewModel>,
origin: [] as Array<ProtocolDecisionViewModel>,
loading: "loading" as "loading" | "fetched" | "failed",
syncingProtocolDecision: "synced" as "synced" | "syncing" | "detectedChanges" | "failed",
};
},
getters: {
detectedChangeProtocolDecision: (state) =>
!isEqual(state.origin, state.decision) && state.syncingProtocolDecision != "syncing",
},
actions: {
setProtocolDecisionSyncingState(state: "synced" | "syncing" | "detectedChanges" | "failed") {
this.syncingProtocolDecision = state;
},
fetchProtocolDecision() {
this.loading = "loading";
this.fetchProtocolDecisionPromise()
.then((result) => {
this.origin = result.data;
this.decision = cloneDeep(this.origin);
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
fetchProtocolDecisionPromise() {
const protocolId = useProtocolStore().activeProtocol;
return http.get(`/admin/protocol/${protocolId}/decisions`);
},
createProtocolDecision() {
const protocolId = useProtocolStore().activeProtocol;
if (protocolId == null) return;
return http
.post(`/admin/protocol/${protocolId}/decision`)
.then((res) => {
this.decision.push({
id: Number(res.data),
topic: "",
context: "",
protocolId: Number(protocolId),
});
})
.catch((err) => {});
},
async synchronizeActiveProtocolDecision() {
this.syncingProtocolDecision = "syncing";
const protocolId = useProtocolStore().activeProtocol;
await http
.patch(`/admin/protocol/${protocolId}/synchronize/decisions`, {
decisions: differenceWith(this.decision, this.origin, isEqual),
})
.then((res) => {
this.syncingProtocolDecision = "synced";
})
.catch((err) => {
this.syncingProtocolDecision = "failed";
});
this.fetchProtocolDecisionPromise()
.then((res) => {
this.origin = res.data;
if (this.detectedChangeProtocolDecision) this.syncingProtocolDecision = "detectedChanges";
})
.catch((err) => {});
},
},
});

View file

@ -0,0 +1,66 @@
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import type {
ProtocolPresenceViewModel,
SyncProtocolPresenceViewModel,
} from "../../viewmodels/admin/protocolPresence.models";
import { useProtocolStore } from "./protocol";
import cloneDeep from "lodash.clonedeep";
import isEqual from "lodash.isEqual";
export const useProtocolPresenceStore = defineStore("protocolPresence", {
state: () => {
return {
presence: [] as Array<number>,
origin: [] as Array<number>,
loading: "loading" as "loading" | "fetched" | "failed",
syncingProtocolPresence: "synced" as "synced" | "syncing" | "detectedChanges" | "failed",
};
},
getters: {
detectedChangeProtocolPresence: (state) =>
!isEqual(state.origin, state.presence) && state.syncingProtocolPresence != "syncing",
},
actions: {
setProtocolPresenceSyncingState(state: "synced" | "syncing" | "detectedChanges" | "failed") {
this.syncingProtocolPresence = state;
},
fetchProtocolPresence() {
this.loading = "loading";
this.fetchProtocolPresencePromise()
.then((result) => {
this.origin = result.data.map((d: ProtocolPresenceViewModel) => d.memberId);
this.presence = cloneDeep(this.origin);
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
fetchProtocolPresencePromise() {
const protocolId = useProtocolStore().activeProtocol;
return http.get(`/admin/protocol/${protocolId}/presence`);
},
async synchronizeActiveProtocolPresence() {
this.syncingProtocolPresence = "syncing";
const protocolId = useProtocolStore().activeProtocol;
await http
.put(`/admin/protocol/${protocolId}/synchronize/presence`, {
presence: this.presence,
})
.then((res) => {
this.syncingProtocolPresence = "synced";
})
.catch((err) => {
this.syncingProtocolPresence = "failed";
});
this.fetchProtocolPresencePromise()
.then((result) => {
this.origin = result.data.map((d: ProtocolPresenceViewModel) => d.memberId);
if (this.detectedChangeProtocolPresence) this.syncingProtocolPresence = "detectedChanges";
})
.catch((err) => {});
},
},
});

View file

@ -0,0 +1,55 @@
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import type { ProtocolPrintoutViewModel } from "../../viewmodels/admin/protocolPrintout.models";
import { useProtocolStore } from "./protocol";
import type { AxiosResponse } from "axios";
export const useProtocolPrintoutStore = defineStore("protocolPrintout", {
state: () => {
return {
printout: [] as Array<ProtocolPrintoutViewModel>,
loading: "loading" as "loading" | "fetched" | "failed",
printing: undefined as undefined | "loading" | "success" | "failed",
};
},
actions: {
fetchProtocolPrintout() {
const protocolId = useProtocolStore().activeProtocol;
this.loading = "loading";
http
.get(`/admin/protocol/${protocolId}/printouts`)
.then((result) => {
this.printout = result.data;
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
fetchProtocolPrintoutById(printoutId: number): Promise<AxiosResponse<any, any>> {
const protocolId = useProtocolStore().activeProtocol;
return http.get(`/admin/protocol/${protocolId}/printout/${printoutId}`, {
responseType: "blob",
});
},
createProtocolPrintout() {
this.printing = "loading";
const protocolId = useProtocolStore().activeProtocol;
if (protocolId == null) return;
return http
.post(`/admin/protocol/${protocolId}/printout`)
.then((res) => {
this.fetchProtocolPrintout();
this.printing = "success";
})
.catch((err) => {
this.printing = "failed";
})
.finally(() => {
setTimeout(() => {
this.printing = undefined;
}, 1500);
});
},
},
});

View file

@ -0,0 +1,86 @@
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import type { AxiosResponse } from "axios";
import type {
ProtocolVotingViewModel,
SyncProtocolVotingViewModel,
} from "../../viewmodels/admin/protocolVoting.models";
import { useProtocolStore } from "./protocol";
import cloneDeep from "lodash.clonedeep";
import isEqual from "lodash.isEqual";
import differenceWith from "lodash.differencewith";
export const useProtocolVotingStore = defineStore("protocolVoting", {
state: () => {
return {
voting: [] as Array<ProtocolVotingViewModel>,
origin: [] as Array<ProtocolVotingViewModel>,
loading: "loading" as "loading" | "fetched" | "failed",
syncingProtocolVoting: "synced" as "synced" | "syncing" | "detectedChanges" | "failed",
};
},
getters: {
detectedChangeProtocolVoting: (state) =>
!isEqual(state.origin, state.voting) && state.syncingProtocolVoting != "syncing",
},
actions: {
setProtocolVotingSyncingState(state: "synced" | "syncing" | "detectedChanges" | "failed") {
this.syncingProtocolVoting = state;
},
fetchProtocolVoting() {
this.loading = "loading";
this.fetchProtocolVotingPromise()
.then((result) => {
this.origin = result.data;
this.voting = cloneDeep(this.origin);
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
fetchProtocolVotingPromise() {
const protocolId = useProtocolStore().activeProtocol;
return http.get(`/admin/protocol/${protocolId}/votings`);
},
createProtocolVoting() {
const protocolId = useProtocolStore().activeProtocol;
if (protocolId == null) return;
return http
.post(`/admin/protocol/${protocolId}/voting`)
.then((res) => {
this.voting.push({
id: Number(res.data),
topic: "",
context: "",
favour: 0,
abstain: 0,
against: 0,
protocolId: Number(protocolId),
});
})
.catch((err) => {});
},
async synchronizeActiveProtocolVoting() {
this.syncingProtocolVoting = "syncing";
const protocolId = useProtocolStore().activeProtocol;
await http
.patch(`/admin/protocol/${protocolId}/synchronize/votings`, {
votings: differenceWith(this.voting, this.origin, isEqual),
})
.then((res) => {
this.syncingProtocolVoting = "synced";
})
.catch((err) => {
this.syncingProtocolVoting = "failed";
});
this.fetchProtocolVotingPromise()
.then((res) => {
this.origin = res.data;
if (this.detectedChangeProtocolVoting) this.syncingProtocolVoting = "detectedChanges";
})
.catch((err) => {});
},
},
});