filters exec list

This commit is contained in:
Florinda
2025-03-10 12:12:11 +01:00
parent 934872a753
commit 4846331eaf
3 changed files with 199 additions and 170 deletions

View File

@@ -3,34 +3,76 @@ import { computed, ref } from 'vue';
import { ScenarioService } from '../service/ScenarioService';
import { LoadingStore } from './LoadingStore';
export const ScenarioExecutionStore = defineStore('scenario_execution_store', () => {
const lstScenarioExecution = ref([]);
const selectedExecScenario = ref(null);
const loadingStore = LoadingStore();
const lstScenarioExecution = ref([])
const selectedExecScenario = ref(null)
const loadingStore = LoadingStore()
const totalRecords = ref(0); // Numero totale di record
const currentPage = ref(0); // Pagina corrente
const pageSize = ref(10); // Numero di record per pagina
const filters = ref({}); // Oggetto per memorizzare i filtri
async function fetchScenariosExecution() {
// Funzione per recuperare le esecuzioni con filtri e paginazione
async function fetchScenariosExecution(page = 0, size = 10, filters, sortField, sortOrder) {
loadingStore.scenario_loading = true;
await ScenarioService.getExecScenariosByUser().then(resp => {
lstScenarioExecution.value = resp.data;
try {
console.log("Recupero delle esecuzioni con filtri:", page, size, filters, sortField, sortOrder);
const resp = await ScenarioService.getExecScenariosByUser(page, size, filters, sortField, sortOrder); // Passiamo anche i filtri
lstScenarioExecution.value = resp.data.content;
totalRecords.value = resp.data.totalElements;
currentPage.value = page;
pageSize.value = size;
} catch (error) {
console.error("Errore nel recupero delle esecuzioni:", error);
} finally {
loadingStore.scenario_loading = false;
});
}
}
const scenariosExecution = computed(() => {
return lstScenarioExecution.value
})
return lstScenarioExecution.value;
});
const getSelectedExecScenario = computed(() => {
return selectedExecScenario.value
})
return selectedExecScenario.value;
});
async function setSelectedExecScenario(execScenario){
selectedExecScenario.value = execScenario
console.log("selectedExecScenario", selectedExecScenario.value);
}
return { fetchScenariosExecution, selectedExecScenario, lstScenarioExecution, scenariosExecution, getSelectedExecScenario, setSelectedExecScenario}
})
const getCurrentPage = computed(() => {
return currentPage.value;
});
const getPageSize = computed(() => {
return pageSize.value;
});
const getTotalRecords = computed(() => {
return totalRecords.value;
});
const setSelectedExecScenario = (execScenario) => {
selectedExecScenario.value = execScenario;
};
// Funzione per aggiornare i filtri
const updateFilters = (newFilters) => {
console.log("Nuovi filtri:", newFilters);
filters.value = newFilters;
filters.value = encodeURIComponent(JSON.stringify(newFilters));
fetchScenariosExecution(currentPage.value, pageSize.value, filters.value); // Ricarica con i nuovi filtri
};
return {
getCurrentPage,
getPageSize,
getTotalRecords,
fetchScenariosExecution,
selectedExecScenario,
lstScenarioExecution,
scenariosExecution,
getSelectedExecScenario,
setSelectedExecScenario,
updateFilters, // Aggiunto per aggiornare i filtri
filters // Rende disponibile i filtri come parte dello store
};
});