Files
hermione-fe/src/stores/dashboard/DashboardScenarioStore.js
mariapia.lorusso e396f6d6fc filters updates
2025-06-10 16:14:24 +02:00

166 lines
5.6 KiB
JavaScript

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,
}
})