decisions and voting

This commit is contained in:
Julian Krauser 2024-10-18 14:20:58 +02:00
parent c0bfc00862
commit d62436722a
6 changed files with 246 additions and 34 deletions

View file

@ -52,7 +52,7 @@ export const useProtocolAgendaStore = defineStore("protocolAgenda", {
id: res.data,
topic: "",
context: "",
protocolId,
protocolId: Number(protocolId),
});
})
.catch((err) => {});
@ -60,7 +60,6 @@ export const useProtocolAgendaStore = defineStore("protocolAgenda", {
async synchronizeActiveProtocolAgenda() {
this.syncingProtocolAgenda = "syncing";
const protocolId = useProtocolStore().activeProtocol;
console.log(this.agenda, this.origin, differenceWith(this.agenda, this.origin, isEqual));
await http
.patch(`/admin/protocol/${protocolId}/synchronize/agenda`, {

View file

@ -8,38 +8,75 @@ import type {
import { useProtocolStore } from "./protocol";
import cloneDeep from "lodash.clonedeep";
import isEqual from "lodash.isEqual";
import difference from "lodash.difference";
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() {
const protocolId = useProtocolStore().activeProtocol;
this.loading = "loading";
http
.get(`/admin/protocol/${protocolId}/decisions`)
this.fetchProtocolDecisionPromise()
.then((result) => {
this.decision = result.data;
this.origin = result.data;
this.decision = cloneDeep(this.origin);
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
async synchronizeActiveProtocolDecision(
decision: Array<SyncProtocolDecisionViewModel>
): Promise<AxiosResponse<any, any>> {
fetchProtocolDecisionPromise() {
const protocolId = useProtocolStore().activeProtocol;
const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/decisions`, {
decision: decision,
});
this.fetchProtocolDecision();
return result;
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: 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;
})
.catch((err) => {});
},
},
});

View file

@ -8,38 +8,78 @@ import type {
import { useProtocolStore } from "./protocol";
import cloneDeep from "lodash.clonedeep";
import isEqual from "lodash.isEqual";
import difference from "lodash.difference";
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() {
const protocolId = useProtocolStore().activeProtocol;
this.loading = "loading";
http
.get(`/admin/protocol/${protocolId}/votings`)
this.fetchProtocolVotingPromise()
.then((result) => {
this.voting = result.data;
this.origin = result.data;
this.voting = cloneDeep(this.origin);
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
async synchronizeActiveProtocolVoting(
voting: Array<SyncProtocolVotingViewModel>
): Promise<AxiosResponse<any, any>> {
fetchProtocolVotingPromise() {
const protocolId = useProtocolStore().activeProtocol;
const result = await http.patch(`/admin/protocol/${protocolId}/synchronize/votings`, {
voting: voting,
});
this.fetchProtocolVoting();
return result;
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: 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;
})
.catch((err) => {});
},
},
});