upate rating

This commit is contained in:
Florinda
2024-12-17 11:20:04 +01:00
parent 559b595f33
commit 064abb6d04
3 changed files with 109 additions and 37 deletions

View File

@@ -33,8 +33,29 @@
<template #header>
<div class="flex items-center gap-2">
<span class="font-bold">Execution Input for ID {{execution_id}}</span>
<div v-if="rating!=null" class="flex justify-end">
<Rating
:modelValue="rating"
:stars="5"
:readonly="true"
/>
</div>
<div v-else class="flex justify-end">
<Rating
:modelValue="rating"
:stars="5"
@change="updateRating($event)"
/>
</div>
</div>
</template>
<div class="box p-4 border rounded-md shadow-sm" style="background-color: white;">
<div v-for="(input, index) in inputs" :key="index" class="input-container">
<div class="input-wrapper">
@@ -91,8 +112,10 @@ import JsonEditorVue from 'json-editor-vue';
import { MdPreview } from 'md-editor-v3';
import 'md-editor-v3/lib/style.css';
import ProgressSpinner from 'primevue/progressspinner';
import { useToast } from 'primevue/usetoast';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { ScenarioService } from '../../service/ScenarioService.js';
import { ScenarioExecutionStore } from '../../stores/ScenarioExecutionStore.js';
const router = useRouter();
@@ -107,10 +130,12 @@ const formData = ref({});
const exec_id = ref(null);
const exec_scenario = ref({});
const debug_modal = ref(false);
const rating = ref(null);
const scenario_execution_store = ScenarioExecutionStore();
const execution = scenario_execution_store.getSelectedExecScenario;
const execution_id = ref(null)
const inputs = ref(null);
const toast = useToast();
onMounted(() => {
@@ -136,12 +161,46 @@ const retrieveScenarioExec = (id) => {
scenario.value = response.data.scenario
exec_scenario.value = response.data
data_loaded.value = true;
rating.value = response.data.rating
scenario_output.value = response.data.execSharedMap.scenario_output;
exec_id.value = response.data.scenarioExecution_id
inputs.value = response.data.scenarioExecutionInput.inputs
});
};
async function updateRating(newRating) {
loading_data.value = true;
ScenarioService.updateScenarioExecRating(execution_id.value,newRating.value).then((response) => {
console.log('response:', response);
if (response.data === "OK") {
rating.value = newRating.value;
console.log('Rating aggiornato con successo:', response.data);
toast.add({
severity: 'success', // Tipo di notifica (successo)
summary: 'Successo', // Titolo della notifica
detail: 'Rating updated with success.', // Messaggio dettagliato
life: 3000 // Durata della notifica in millisecondi
});
} else {
console.error('Errore nell\'aggiornamento del rating', response.data);
toast.add({
severity: 'error', // Tipo di notifica (errore)
summary: 'Errore', // Titolo della notifica
detail: 'Error updating rating. Try later.', // Messaggio dettagliato
life: 3000 // Durata della notifica in millisecondi
});
}
}).catch((error) => {
console.error('Errore durante la chiamata al backend:', error);
}).finally(() => {
loading_data.value = false;
});
}