front_foundation #9

Closed
mohamed_maoulainine wants to merge 181 commits from front_foundation into main
9 changed files with 104 additions and 80 deletions
Showing only changes of commit 820c979c94 - Show all commits

View File

@ -95,7 +95,7 @@ const props = defineProps<{
title: number;
titleText: string;
description: string;
isAdmin: number;
isAdmin: boolean;
}>();
const IS_MOCK_MODE = false;
@ -107,18 +107,23 @@ const editedDescriptions = ref<SectionCell[]>([]);
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 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");
return `${year}-${month}-${day} ${hours}:${minutes}`;
return `${year}-${month}-${day} ${hours}:${minutes}`;
}
adnane marked this conversation as resolved Outdated
Outdated
Review

Same, don't use axios

Same, don't use axios
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) {
adnane marked this conversation as resolved Outdated
Outdated
Review

be careful with axiosInstance, but i may be fine

be careful with axiosInstance, but i may be fine
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({
idSectionCell: cell.idSectionCell,
sectionId: cell.sectionId,
contentSectionCell: cell.contentSectionCell,
modificationDate: cell.modificationDate, })
(cell) =>
new SectionCell({
idSectionCell: cell.idSectionCell,
sectionId: cell.sectionId,
contentSectionCell: cell.contentSectionCell,
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);
adnane marked this conversation as resolved Outdated
Outdated
Review

Ce saveEdit utile étant donnée celle définie en dessous ?

Ce saveEdit utile étant donnée celle définie en dessous ?
handleFetchSuccess(responseData);
} else {
await new Promise<void>((resolve, reject) => {
adnane marked this conversation as resolved Outdated
Outdated
Review

axios again

axios again
Outdated
Review

And the path is not right

And the path is not right
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({
idSectionCell: cellData.idSectionCell,
sectionId: cellData.sectionId,
contentSectionCell: cellData.contentSectionCell,
modificationDate:
cellData.modificationDate, })
const sectionCells = data.map(
(cellData) =>
new SectionCell({
idSectionCell: cellData.idSectionCell,
sectionId: cellData.sectionId,
contentSectionCell:
cellData.contentSectionCell,
modificationDate:
cellData.modificationDate,
})
);
adnane marked this conversation as resolved Outdated
Outdated
Review

same

same
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) => {

View File

@ -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([

View File

@ -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,32 +28,6 @@ keycloakService.CallInit(() => {
}
});
type TokenPayload = {
realm_access?: {
roles?: string[];
};
};
function isAdmin(): boolean {
if (store.authenticated && store.user.token) {
try {
const decoded = jwtDecode<TokenPayload>(store.user.token);
const roles = decoded.realm_access?.roles || [];
if (roles.includes("MyINPulse-admin")) {
return true;
} else {
return false;
}
} catch (err) {
console.error("Failed to decode token", err);
}
}
}
// this shit made by me so i can run the canva vue app
adnane marked this conversation as resolved Outdated
Outdated
Review

We can't let this kind of comments

We can't let this kind of comments
//createApp(App).use(router).mount('#app');
@ -97,4 +70,4 @@ app.use(VueKeyCloak,{
} );
*/
export { store, isAdmin };
export { store };

View File

@ -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(

View File

@ -1,6 +1,10 @@
import Project from "@/ApiClasses/Project";
import SectionCell from "@/ApiClasses/SectionCell";
import { axiosInstance, defaultApiErrorHandler, defaultApiSuccessHandler } from "@/services/api"
import {
axiosInstance,
defaultApiErrorHandler,
defaultApiSuccessHandler,
} from "@/services/api";
axiosInstance.interceptors.response.use(
(response) => response, // Directly return successful responses.
@ -62,7 +66,7 @@ function addSectionCell(
onErrorHandler?: (error: AxiosError) => void
): void {
axiosInstance
.post("/entrepreneur/sectionCells", sectionCellDetails.toPlainObject()) // <-- Ici
.post("/entrepreneur/sectionCells", sectionCellDetails.toPlainObject()) // <-- Ici
.then((response) => {
if (onSuccessHandler) {
onSuccessHandler(response);

View File

@ -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(

View File

@ -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]

View File

@ -1,7 +1,7 @@
import axios, { type AxiosError, type AxiosResponse } from "axios";
import { store } from "@/main.ts";
import { addNewMessage, color } from "@/services/popupDisplayer.ts";
import router from "@/router/router";
import router from "@/router/router";
const axiosInstance = axios.create({
baseURL: import.meta.env.VITE_BACKEND_URL,
@ -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,
};

View File

@ -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;
adnane marked this conversation as resolved Outdated
Outdated
Review

This should not be true

This should not be true

Le fetching n'est pas encore prêt pour passer à la base de données

Le fetching n'est pas encore prêt pour passer à la base de données
/*
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({