Merged PR 155: create dashboard

create dashboard
This commit is contained in:
Mariapia Lorusso
2025-06-09 14:58:03 +00:00
6 changed files with 1403 additions and 55 deletions

View File

@@ -6,8 +6,7 @@ import { UserPrefStore } from '../stores/UserPrefStore.js';
import AppMenuItem from './AppMenuItem.vue';
const userPrefStore = UserPrefStore();
const route = useRouter()
const route = useRouter();
const model = ref([
@@ -33,19 +32,22 @@ const model = ref([
]);
// onMounted(() => {
// if(userPrefStore.user.role == 'ADMIN'){
// model.value.push({
// label: 'Chat',
// items: [{ label: 'Chat', icon: 'pi pi-fw pi-comments', to: '/chat' }]
// });
// }
// });
onMounted(() => {
if(userPrefStore.user.role === 'ADMIN'){
model.value[0].items.push({
label: 'Dashboard',
icon: 'pi pi-fw pi-chart-bar',
command: () => {
route.push({ path: '/dashboard' });
}
});
}
});
// Funzione per aggiornare la sezione "Your Applications" in base a selectedApp
function updateApplicationsMenu() {
const selectedApp = userPrefStore.getSelApp;
console.log("selectedApp", selectedApp);
console.log('selectedApp', selectedApp);
if (selectedApp != null) {
//Aggiorna il label dell'app
@@ -58,7 +60,7 @@ function updateApplicationsMenu() {
const groupedScenarios = {};
//Raggruppa gli scenari per categoria (solo se type non è null)
selectedApp.available_scenarios.forEach(app => {
selectedApp.available_scenarios.forEach((app) => {
if (app.type) {
const type = app.type.trim();
if (!groupedScenarios[type]) {
@@ -72,7 +74,7 @@ function updateApplicationsMenu() {
});
//Creazione del menu in base ai gruppi
Object.keys(groupedScenarios).forEach(type => {
Object.keys(groupedScenarios).forEach((type) => {
const scenarios = groupedScenarios[type];
if (scenarios.length >= 2) {
@@ -83,7 +85,7 @@ function updateApplicationsMenu() {
items: []
};
scenarios.forEach(app => {
scenarios.forEach((app) => {
typeItem.items.push(createScenarioItem(app));
});
@@ -94,6 +96,7 @@ function updateApplicationsMenu() {
}
});
//Aggiungi "Rev Eng Code" alla fine della lista
model.value[1].items.push({
label: 'Application Code',
@@ -108,13 +111,9 @@ function updateApplicationsMenu() {
model.value[1].label = '';
model.value[1].items = [];
}
}
function createScenarioItem(app) {
if (app.associate_exec_list === 'Y') {
return {
label: app.label,
@@ -133,7 +132,6 @@ function createScenarioItem(app) {
route.push({ path: `/home/scenario/exec/${app.scenario_id}` });
}
};
} else {
return {
label: app.label,
@@ -143,14 +141,8 @@ function createScenarioItem(app) {
}
};
}
}
// Monitora i cambiamenti in selectedApp dallo store
watch(() => userPrefStore.getSelApp, updateApplicationsMenu, { immediate: true });
</script>

View File

@@ -18,14 +18,6 @@ export const ScenarioService = {
},
// getExecScenariosByUser(page = 0, size = 10) {
// return axios.get('/executions', {
// params: {
// page: page,
// size: size }
// });
// }
getExecScenariosByUser(page = 0, size = 10, filters = {}, sortField, sortOrder) {
// Filtri potrebbero essere vuoti, quindi rimuoviamoli se non necessari
const requestBody = { page, size, ...filters, sortField, sortOrder };
@@ -38,6 +30,10 @@ export const ScenarioService = {
},
updateScenarioExecRating(id, rating) {
return axios.get('/updateRating?id=' + id + '&rating=' + rating)
},
getExecScenarioByProject () {
return axios.get('/getExecScenarioByProject')
}
}

View File

@@ -0,0 +1,79 @@
import axios from 'axios';
export const DashboardScenarioService = {
getExecScenarioByProject (project) {
return axios.get('/getExecScenarioByProject', {
params: project
});
},
//funzione per recuperare la lista con TUTTI i progetti
getProjects() {
return axios.get('/projects');
},
getExecutions(filters) {
return axios.post('/executions-dash', {
dateFrom: filters.dateFrom,
dateTo: filters.dateTo,
projectNameList: filters.projectNames,
scenarioNameList: filters.scenarioNames
}
);
},
getExecutionsStats(filters) {
return axios.post('/executions-stats-dash', {
dateFrom: filters.dateFrom,
dateTo: filters.dateTo,
projectNameList: filters.projectNames,
scenarioNameList: filters.scenarioNames
}
);
},
getUsers(filters) {
return axios.get('/users-by-projects', {
params: {
projectIdsArr: filters
}
});
},
getScenarios(filters) {
return axios.get('/scenarios-filter', {
params: {
selectedAccount: filters
}
});
},
getChats(filters) {
return axios.get('/chats', {
params: {
dateFrom: filters.dateFrom,
dateTo: filters.dateTo,
projectId: filters.projectId,
user: filters.user
}
});
},
getChatStats(filters) {
return axios.post('/dashboard-chat-stats', {
dateFrom: filters.dateFrom,
dateTo: filters.dateTo,
projectNameList: filters.projectNames,
scenarioIdList: filters.scenarioId
}
);
},
};

View File

@@ -14,18 +14,23 @@ export const UserPrefStore = defineStore('userpref_store', () => {
const selectedScenario = ref(null)
async function fetchUserData() {
const auth = useAuth();
loadingStore.user_loading = true;
await auth.fetch().then((fetchedUser) => {
try {
const fetchedUser = await auth.fetch();
user.value = fetchedUser.data.data;
selectedApp.value = user.value.selectedApplication;
userLoaded.value = true;
} catch (error) {
console.error('Errore nel recupero dei dati utente:', error);
// Puoi anche lanciare un errore se vuoi gestirlo in modo diverso altrove
throw error; // Lancia l'errore per gestirlo fuori dalla funzione, se necessario
} finally {
loadingStore.user_loading = false;
}).catch((error) => {
reject(error);
});
};
}
}
async function updateSelectedProject(project) {
try {

View File

@@ -0,0 +1,166 @@
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
import { DashboardScenarioService } from '../../service/dashboard/DashboardScenarioService'
import { LoadingStore } from '../../stores/LoadingStore'
import { UserPrefStore } from '../../stores/UserPrefStore'
export const DashboardScenarioStore = defineStore('dashboard_scenario_store', () => {
const projectScenarios = ref([])
const globalScenarios = ref([])
const applicationScenarios = ref([])
const filterString = ref('')
const allScenarios = ref([])
const typeFilter = ref({ name: 'All', value: 'all' })
const scenariosForRE = ref([])
const projects = ref([])
const executions = ref([])
const chats = ref([])
const error = ref(null)
const users = ref([])
const dashboardResponse = ref(null)
const totalExecutions = ref(0);
const totalTokens = ref(0);
const userPrefStore = UserPrefStore()
const loadingStore = LoadingStore()
async function fetchExecutionForProject() { //funzione che recupera le esecuzioni dei progetti
loadingStore.scenario_loading = true;
await DashboardScenarioService.getExecScenarioByProject(userPrefStore.selectedProject).then(resp => {
projectScenarios.value = resp.data;
allScenarios.value = [...projectScenarios.value]
loadingStore.scenario_loading = false;
});
}
//funzioni per la dashboard
async function loadProjects() { //carica tutti i progetti
try {
loadingStore.scenario_loading = true;
const response = await DashboardScenarioService.getProjects(); // prende i progetti dal back
projects.value = response.data;
} catch (err) {
console.error('Errore caricamento progetti:', err);
error.value = err.message || 'Errore durante il caricamento dei progetti';
} finally {
loadingStore.scenario_loading = false;
}
}
async function loadExecutions(filters) { //carica i dati per le esecuzioni
try {
loadingStore.scenario_loading = true;
const response = await DashboardScenarioService.getExecutions(filters);
console.log("RISPOSTA RAW DA API:", response)
executions.value = response.data
} catch (err) {
console.error('Errore caricamento executions:', err);
error.value = err.message || 'Errore durante il caricamento delle esecuzioni';
} finally {
loadingStore.scenario_loading = false;
}
}
async function loadExecutionsStats (filters) {
try {
loadingStore.scenario_loading = true;
const response = await DashboardScenarioService.getExecutionsStats(filters);
console.log("RISPOSTA RAW DA API:", response)
dashboardResponse.value = response.data
} catch (err) {
console.error('Errore caricamento executions:', err);
error.value = err.message || 'Errore durante il caricamento delle esecuzioni';
} finally {
loadingStore.scenario_loading = false;
}
}
async function loadUsers(filters) {
try {
loadingStore.scenario_loading = true;
const response = await DashboardScenarioService.getUsers(filters);
users.value = response.data;
return response;
} catch (err) {
console.error('Errore caricamento users:', err);
error.value = err.message || 'Errore durante il caricamento delle esecuzioni';
} finally {
loadingStore.scenario_loading = false;
}
}
async function loadChats(filters) { //carica i dati per la tabella della chat
try {
loadingStore.scenario_loading = true;
const response = await DashboardScenarioService.getChats(filters);
chats.value = response.data;
} catch (err) {
console.error('Errore caricamento chats:', err);
error.value = err.message || 'Errore durante il caricamento delle chat';
} finally {
loadingStore.scenario_loading = false;
}
}
async function loadScenarios(filters) {
try {
loadingStore.scenario_loading = true;
const response = await DashboardScenarioService.getScenarios(filters);
allScenarios.value = response.data;
return response;
} catch (err) {
console.error('Errore caricamento scenari:', err);
error.value = err.message || 'Errore durante il caricamento degli scenari';
} finally {
loadingStore.scenario_loading = false;
}
}
async function loadChatStats(filters) {
try {
loadingStore.scenario_loading = true;
const response = await DashboardScenarioService.getChatStats(filters);
console.log("RISPOSTA :", response)
chatStats.value = response.data
} catch (err) {
console.error('Errore caricamento chat:', err);
error.value = err.message || 'Errore durante il caricamento delle chat';
} finally {
loadingStore.scenario_loading = false;
}
}
return {
fetchExecutionForProject,
projects,
executions,
chats,
error,
loadProjects,
loadExecutions,
loadChats,
loadUsers,
loadScenarios,
allScenarios,
dashboardResponse,
totalExecutions,
totalTokens,
loadExecutionsStats,
loadChatStats,
chatStats
}
})

File diff suppressed because it is too large Load Diff