diff --git a/src/service/ScenarioExecutionService.js b/src/service/ScenarioExecutionService.js new file mode 100644 index 0000000..e5306a6 --- /dev/null +++ b/src/service/ScenarioExecutionService.js @@ -0,0 +1,18 @@ +import axios from 'axios'; + +export const ScenarioExecutionService = { + getExecScenariosByUser(page = 0, size = 10, filters = {}, sortField, sortOrder) { + const requestBody = { page, size, ...filters, sortField, sortOrder }; + return axios.post('/executions', requestBody); + }, + + downloadFile(filePath, executionId) { + return axios.get('/downloadFile', { + params: { + filePath: filePath, + executionId: executionId + }, + responseType: 'blob' // Importante per gestire il download di file + }); + } +}; diff --git a/src/stores/ScenarioExecutionStore.js b/src/stores/ScenarioExecutionStore.js index 4cb08f4..9dd79f5 100644 --- a/src/stores/ScenarioExecutionStore.js +++ b/src/stores/ScenarioExecutionStore.js @@ -1,6 +1,6 @@ import { defineStore } from 'pinia'; import { computed, ref } from 'vue'; -import { ScenarioService } from '../service/ScenarioService'; +import { ScenarioExecutionService } from '../service/ScenarioExecutionService'; import { LoadingStore } from './LoadingStore'; export const ScenarioExecutionStore = defineStore('scenario_execution_store', () => { @@ -8,23 +8,53 @@ export const ScenarioExecutionStore = defineStore('scenario_execution_store', () 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 + 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 // Funzione per recuperare le esecuzioni con filtri e paginazione async function fetchScenariosExecution(page = 0, size = 10, filters, sortField, sortOrder) { loadingStore.scenario_loading = true; try { - console.log("Fetching executions with filters:", page, size, filters, sortField, sortOrder); - const resp = await ScenarioService.getExecScenariosByUser(page, size, filters, sortField, sortOrder); // Passiamo anche i filtri + console.log('Fetching executions with filters:', page, size, filters, sortField, sortOrder); + const resp = await ScenarioExecutionService.getExecScenariosByUser(page, size, filters, sortField, sortOrder); lstScenarioExecution.value = resp.data.content; totalRecords.value = resp.data.totalElements; currentPage.value = page; pageSize.value = size; } catch (error) { - console.error("Error fetching executions:", error); + console.error('Error fetching executions:', error); + } finally { + loadingStore.scenario_loading = false; + } + } + + async function downloadFile(filePath, executionId) { + loadingStore.scenario_loading = true; + try { + const response = await ScenarioExecutionService.downloadFile(filePath, executionId); + + // Crea un URL per il blob e avvia il download + const url = window.URL.createObjectURL(new Blob([response.data])); + const link = document.createElement('a'); + link.href = url; + + // Estrae il nome del file dal filePath o usa un nome di default + const fileName = filePath.split('/').pop() || `file_${executionId}`; + link.setAttribute('download', fileName); + + document.body.appendChild(link); + link.click(); + + // Cleanup + link.remove(); + window.URL.revokeObjectURL(url); + + return response; + } catch (error) { + console.error('Error downloading file:', error); + throw error; } finally { loadingStore.scenario_loading = false; } @@ -56,10 +86,20 @@ export const ScenarioExecutionStore = defineStore('scenario_execution_store', () // Funzione per aggiornare i filtri const updateFilters = (newFilters) => { - console.log("New filters:", newFilters); + console.log('New filters:', newFilters); filters.value = newFilters; filters.value = encodeURIComponent(JSON.stringify(newFilters)); - fetchScenariosExecution(currentPage.value, pageSize.value, filters.value); // Ricarica con i nuovi filtri + fetchScenariosExecution(currentPage.value, pageSize.value, filters.value); // Ricarica con i nuovi filtri + }; + + // Funzione per resettare lo store + const resetStore = () => { + lstScenarioExecution.value = []; + selectedExecScenario.value = null; + totalRecords.value = 0; + currentPage.value = 0; + pageSize.value = 10; + filters.value = {}; }; return { @@ -67,12 +107,14 @@ export const ScenarioExecutionStore = defineStore('scenario_execution_store', () getPageSize, getTotalRecords, fetchScenariosExecution, + downloadFile, selectedExecScenario, lstScenarioExecution, scenariosExecution, getSelectedExecScenario, setSelectedExecScenario, - updateFilters, // Aggiunto per aggiornare i filtri - filters // Rende disponibile i filtri come parte dello store + updateFilters, // Aggiunto per aggiornare i filtri + filters, + resetStore // Rende disponibile i filtri come parte dello store }; }); diff --git a/src/views/pages/OldScenarioExec.vue b/src/views/pages/OldScenarioExec.vue index ce2015c..15ec64f 100644 --- a/src/views/pages/OldScenarioExec.vue +++ b/src/views/pages/OldScenarioExec.vue @@ -4,13 +4,6 @@
-
@@ -39,24 +32,15 @@ Files Uploaded Parameter - {{ (scenario.inputs && Array.isArray(scenario.inputs) ? scenario.inputs.find((i) => i.name === 'input_multiselect')?.label : null)}} + {{ scenario.inputs && Array.isArray(scenario.inputs) ? scenario.inputs.find((i) => i.name === 'input_multiselect')?.label : null }} {{ index.replace(/_/g, ' ').replace(/\b\w/g, (char) => char.toUpperCase()) }}
-
- -
-
-

No files found in the zip.

-
+ {{ filteredInputs.SingleFileUpload.replace(/\\/g, '/').split('/').pop() }} +
{{ input }}
@@ -110,7 +94,7 @@ @@ -198,6 +182,7 @@ const updateLoading = ref(false); const fileContent = ref(''); const fileType = ref(''); const chat_enabled = ref(false); +const baseUploadDir = 'mnt/hermione_storage/documents/file_input_scenarios/'; onMounted(() => { if (execution) { @@ -210,7 +195,6 @@ onMounted(() => { }); const retrieveScenarioExec = (id) => { - //const id = execution_id.value.id; loading.value = true; axios.get('/execution?id=' + id).then((response) => { @@ -224,8 +208,8 @@ const retrieveScenarioExec = (id) => { inputs.value = response.data.scenarioExecutionInput.inputs; steps.value = response.data.scenario.steps; if (inputs.value['MultiFileUpload']) { - extractFiles(inputs.value['MultiFileUpload'], 'input', zipInput); if (steps.value[0].attributes['codegenie_output_type']) { + extractFiles(inputs.value['MultiFileUpload'], 'input', zipInput); if (steps.value[0].attributes['codegenie_output_type'] == 'FILE') { fileType.value = 'FILE'; } else if (steps.value[0].attributes['codegenie_output_type'] == 'MARKDOWN') { @@ -380,34 +364,29 @@ const downloadFileOutput = async (fileName) => { } }; -const downloadFile = (base64String) => { - // Decodifica la stringa Base64 - const binaryString = atob(base64String); - const binaryLength = binaryString.length; - const bytes = new Uint8Array(binaryLength); +const downloadFile = async (filePath) => { + try { + let relativePath = filePath; + if (filePath.startsWith(baseUploadDir)) { + relativePath = filePath.substring(baseUploadDir.length); + } - for (let i = 0; i < binaryLength; i++) { - bytes[i] = binaryString.charCodeAt(i); + console.log('Original path:', filePath); + console.log('Relative path:', relativePath); + + // Chiamata all'API backend per ottenere il file + await scenario_execution_store.downloadFile(relativePath, execution_id.value); + } catch (error) { + console.error('Error downloading file:', error); + + // Notifica di errore + toast.add({ + severity: 'error', + summary: 'Error', + detail: 'Error downloading file. Please try again.', + life: 3000 + }); } - - // Creazione di un Blob dal file binario - const blob = new Blob([bytes], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }); - - // Creazione di un URL per il Blob - const url = URL.createObjectURL(blob); - - // Creazione di un elemento anchor per il download - const link = document.createElement('a'); - link.href = url; - link.download = 'sf_document-' + execution_id.value + '.docx'; - - // Simulazione di un click per scaricare il file - document.body.appendChild(link); - link.click(); - - // Pulizia del DOM - document.body.removeChild(link); - URL.revokeObjectURL(url); }; const downloadFolderFromBase64 = async (base64String) => { diff --git a/src/views/pages/ProjectList.vue b/src/views/pages/ProjectList.vue index 1f15601..34b087d 100644 --- a/src/views/pages/ProjectList.vue +++ b/src/views/pages/ProjectList.vue @@ -80,6 +80,7 @@ import { useRouter } from 'vue-router'; import { LoadingStore } from '../../stores/LoadingStore.js'; import { UserPrefStore } from '../../stores/UserPrefStore.js'; import { ScenarioStore } from '../../stores/ScenarioStore.js'; +import { ScenarioExecutionStore } from '../../stores/ScenarioExecutionStore.js'; const loadingStore = LoadingStore() @@ -87,6 +88,7 @@ const userPrefStore = UserPrefStore(); const auth = useAuth(); const user = computed(() => auth.user()); const scenario_store = ScenarioStore(); +const scenario_execution_store = ScenarioExecutionStore(); const router = useRouter() @@ -125,6 +127,7 @@ const scenario_store = ScenarioStore(); try { // Esegui l'update del progetto scenario_store.resetStore(); + scenario_execution_store.resetStore(); await userPrefStore.updateSelectedProject(project); console.log('Progetto aggiornato e dati utente ricaricati');