merge: enstrpenrue issuees
This commit is contained in:
commit
8024b8070b
@ -95,7 +95,7 @@ const props = defineProps<{
|
||||
title: number;
|
||||
titleText: string;
|
||||
description: string;
|
||||
isAdmin: number;
|
||||
isAdmin: boolean;
|
||||
}>();
|
||||
|
||||
const IS_MOCK_MODE = false;
|
||||
@ -109,16 +109,21 @@ const isEditing = ref<boolean[]>([]);
|
||||
function getCurrentFormattedDate(): string {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0'); // +1 car janvier = 0
|
||||
const day = String(now.getDate()).padStart(2, '0');
|
||||
const hours = String(now.getHours()).padStart(2, '0');
|
||||
const minutes = String(now.getMinutes()).padStart(2, '0');
|
||||
const month = String(now.getMonth() + 1).padStart(2, "0"); // +1 car janvier = 0
|
||||
const day = String(now.getDate()).padStart(2, "0");
|
||||
const hours = String(now.getHours()).padStart(2, "0");
|
||||
const minutes = String(now.getMinutes()).padStart(2, "0");
|
||||
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchData(props.projectId, props.title, getCurrentFormattedDate(), IS_MOCK_MODE);
|
||||
fetchData(
|
||||
props.projectId,
|
||||
props.title,
|
||||
getCurrentFormattedDate(),
|
||||
IS_MOCK_MODE
|
||||
);
|
||||
});
|
||||
|
||||
// Fonctions
|
||||
@ -137,10 +142,14 @@ const saveEdit = (index: number) => {
|
||||
editedDescriptions.value[index].contentSectionCell;
|
||||
isEditing.value[index] = false;
|
||||
|
||||
if (!IS_MOCK_MODE){
|
||||
addSectionCell(currentDescriptions.value[index],
|
||||
if (!IS_MOCK_MODE) {
|
||||
addSectionCell(
|
||||
currentDescriptions.value[index],
|
||||
(response) => {
|
||||
console.log("Modification enregistrée avec succès :", response.data);
|
||||
console.log(
|
||||
"Modification enregistrée avec succès :",
|
||||
response.data
|
||||
);
|
||||
},
|
||||
(error) => {
|
||||
console.error("Erreur lors de l'enregistrement :", error);
|
||||
@ -149,7 +158,6 @@ const saveEdit = (index: number) => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const handleClick = () => {
|
||||
if (expanded.value) {
|
||||
const editingInProgress = isEditing.value.some((edit) => edit);
|
||||
@ -165,11 +173,13 @@ const handleClick = () => {
|
||||
const handleFetchSuccess = (sectionCells: SectionCell[]) => {
|
||||
currentDescriptions.value = sectionCells;
|
||||
editedDescriptions.value = sectionCells.map(
|
||||
(cell) => new SectionCell({
|
||||
(cell) =>
|
||||
new SectionCell({
|
||||
idSectionCell: cell.idSectionCell,
|
||||
sectionId: cell.sectionId,
|
||||
contentSectionCell: cell.contentSectionCell,
|
||||
modificationDate: cell.modificationDate, })
|
||||
modificationDate: cell.modificationDate,
|
||||
})
|
||||
);
|
||||
isEditing.value = Array(sectionCells.length).fill(false);
|
||||
};
|
||||
@ -178,28 +188,43 @@ const handleFetchError = (error: unknown) => {
|
||||
console.error("Erreur lors de la récupération des données :", error);
|
||||
};
|
||||
|
||||
const fetchData = async ( projectId: number, title: number, date: string, useMock = false ) => {
|
||||
const fetchData = async (
|
||||
projectId: number,
|
||||
title: number,
|
||||
date: string,
|
||||
useMock = false
|
||||
) => {
|
||||
try {
|
||||
if (useMock) {
|
||||
const responseData = await mockFetch(projectId, title, date);
|
||||
handleFetchSuccess(responseData);
|
||||
} else {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
getSectionCellsByDate( projectId, title, date,
|
||||
getSectionCellsByDate(
|
||||
projectId,
|
||||
title,
|
||||
date,
|
||||
(response: AxiosResponse) => {
|
||||
const data = response.data;
|
||||
|
||||
if (Array.isArray(data) && data.length > 0) {
|
||||
const sectionCells = data.map((cellData) => new SectionCell({
|
||||
const sectionCells = data.map(
|
||||
(cellData) =>
|
||||
new SectionCell({
|
||||
idSectionCell: cellData.idSectionCell,
|
||||
sectionId: cellData.sectionId,
|
||||
contentSectionCell: cellData.contentSectionCell,
|
||||
contentSectionCell:
|
||||
cellData.contentSectionCell,
|
||||
modificationDate:
|
||||
cellData.modificationDate, })
|
||||
cellData.modificationDate,
|
||||
})
|
||||
);
|
||||
handleFetchSuccess(sectionCells);
|
||||
} else {
|
||||
console.warn( "Aucune donnée reçue ou format inattendu :", data);
|
||||
console.warn(
|
||||
"Aucune donnée reçue ou format inattendu :",
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
resolve();
|
||||
@ -216,7 +241,11 @@ const fetchData = async ( projectId: number, title: number, date: string, useMoc
|
||||
}
|
||||
};
|
||||
|
||||
const mockFetch = async ( projectId: number, title: number, date: string ): Promise<SectionCell[]> => {
|
||||
const mockFetch = async (
|
||||
projectId: number,
|
||||
title: number,
|
||||
date: string
|
||||
): Promise<SectionCell[]> => {
|
||||
console.log(
|
||||
`Mock fetch pour projectId: ${projectId}, title: ${title}, date: ${date}`
|
||||
);
|
||||
@ -272,8 +301,13 @@ const mockFetch = async ( projectId: number, title: number, date: string ): Prom
|
||||
|
||||
// On crée des instances de SectionCell
|
||||
const result = section.map(
|
||||
(txt, index) => new SectionCell({ idSectionCell: index + 1, sectionId: title,
|
||||
contentSectionCell: txt, modificationDate: date, })
|
||||
(txt, index) =>
|
||||
new SectionCell({
|
||||
idSectionCell: index + 1,
|
||||
sectionId: title,
|
||||
contentSectionCell: txt,
|
||||
modificationDate: date,
|
||||
})
|
||||
);
|
||||
|
||||
return new Promise<SectionCell[]>((resolve) => {
|
||||
|
@ -18,7 +18,7 @@ import { ref } from "vue";
|
||||
import CanvasItem from "@/components/canvas/CanvasItem.vue";
|
||||
|
||||
const props = defineProps<{
|
||||
isAdmin: number;
|
||||
isAdmin: boolean;
|
||||
}>();
|
||||
|
||||
const items = ref([
|
||||
|
@ -5,7 +5,6 @@ import { createPinia } from "pinia";
|
||||
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
|
||||
import keycloakService from "./services/keycloak";
|
||||
import { type AuthStore, useAuthStore } from "@/stores/authStore.ts";
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
|
||||
let store: AuthStore;
|
||||
|
||||
@ -29,30 +28,6 @@ keycloakService.CallInit(() => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
type TokenPayload = {
|
||||
realm_access?: {
|
||||
roles?: string[];
|
||||
};
|
||||
};
|
||||
|
||||
function isAdmin(): boolean{
|
||||
if (store.authenticated && store.user.token) {
|
||||
const decoded = jwtDecode<TokenPayload>(store.user.token);
|
||||
const roles = decoded.realm_access?.roles || [];
|
||||
if (roles.includes("MyINPulse-admin")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// this shit made by me so i can run the canva vue app
|
||||
//createApp(App).use(router).mount('#app');
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
import { type AxiosError, type AxiosResponse } from "axios";
|
||||
import Project from "@/ApiClasses/Project";
|
||||
import Report from "@/ApiClasses/Repport";
|
||||
import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api"
|
||||
import {
|
||||
axiosInstance,
|
||||
defaultApiErrorHandler,
|
||||
defaultApiSuccessHandler,
|
||||
} from "@/services/api";
|
||||
|
||||
// Admin API
|
||||
function getPendingAccounts(
|
||||
|
@ -35,7 +35,7 @@ function addSectionCell(
|
||||
onErrorHandler?: (error: AxiosError) => void
|
||||
): void {
|
||||
axiosInstance
|
||||
.post("/entrepreneur/sectionCells", sectionCellDetails)
|
||||
.post("/entrepreneur/sectionCells", sectionCellDetails.toPlainObject())
|
||||
.then((response) => {
|
||||
if (onSuccessHandler) {
|
||||
onSuccessHandler(response);
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { type AxiosError, type AxiosResponse } from "axios";
|
||||
import Appointment from "@/ApiClasses/Appointment";
|
||||
import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api"
|
||||
|
||||
import {
|
||||
axiosInstance,
|
||||
defaultApiErrorHandler,
|
||||
defaultApiSuccessHandler,
|
||||
} from "@/services/api";
|
||||
|
||||
// Shared API
|
||||
function getSectionCellsByDate(
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { type AxiosError, type AxiosResponse } from "axios";
|
||||
|
||||
import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api"
|
||||
|
||||
import {
|
||||
axiosInstance,
|
||||
defaultApiErrorHandler,
|
||||
defaultApiSuccessHandler,
|
||||
} from "@/services/api";
|
||||
|
||||
// Unauth API
|
||||
function finalizeAccount(
|
||||
@ -49,7 +52,6 @@ function finalizeAccount(
|
||||
// });
|
||||
// }
|
||||
|
||||
|
||||
export {
|
||||
finalizeAccount,
|
||||
// requestJoinProject, // Not yet implemented [cite: 4]
|
||||
|
@ -43,8 +43,7 @@ axiosInstance.interceptors.response.use(
|
||||
// TODO: spawn a error modal
|
||||
function defaultApiErrorHandler(err: AxiosError) {
|
||||
const errorMessage =
|
||||
(err.response?.data as { message?: string })?.message ??
|
||||
err.message;
|
||||
(err.response?.data as { message?: string })?.message ?? err.message;
|
||||
addNewMessage(errorMessage, color.Red);
|
||||
}
|
||||
|
||||
@ -94,4 +93,11 @@ function deleteApi(
|
||||
|
||||
//export { axiosInstance, callApi, postApi, deleteApi };
|
||||
|
||||
export{ axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler, callApi, postApi, deleteApi }
|
||||
export {
|
||||
axiosInstance,
|
||||
defaultApiErrorHandler,
|
||||
defaultApiSuccessHandler,
|
||||
callApi,
|
||||
postApi,
|
||||
deleteApi,
|
||||
};
|
||||
|
@ -10,7 +10,7 @@
|
||||
Cliquez sur un champ du tableau pour afficher son contenu en détail
|
||||
ci-dessous.
|
||||
</p>
|
||||
<LeanCanvas :is-admin="isAdmin" />
|
||||
<LeanCanvas :is-admin="isAdmin_" />
|
||||
<div class="info-box">
|
||||
<p>
|
||||
Responsable :
|
||||
@ -35,20 +35,18 @@ import HeaderCanvas from "../components/canvas/HeaderCanvas.vue";
|
||||
import LeanCanvas from "../components/canvas/LeanCanvas.vue";
|
||||
import { ref, onMounted /*, defineProps*/ } from "vue";
|
||||
import { axiosInstance } from "@/services/api.ts";
|
||||
|
||||
import { isAdmin } from "@/services/tools.ts";
|
||||
const IS_MOCK_MODE = true;
|
||||
|
||||
/*
|
||||
const props = defineProps<{
|
||||
projectId: number;
|
||||
token: TokenPayload;
|
||||
}>();
|
||||
|
||||
const projectId = props.projectId;
|
||||
*/
|
||||
|
||||
is_admin = token.includes("MyINPulse-admin")
|
||||
*/
|
||||
|
||||
const isAdmin = 0;
|
||||
const isAdmin_: boolean = isAdmin();
|
||||
|
||||
// Variables pour les informations de l'administrateur
|
||||
const admin = ref({
|
||||
|
Loading…
x
Reference in New Issue
Block a user