diff --git a/src/components/SingleClassViewer.vue b/src/components/SingleClassViewer.vue index f754667..97c54c7 100644 --- a/src/components/SingleClassViewer.vue +++ b/src/components/SingleClassViewer.vue @@ -96,7 +96,6 @@
-
Select a Scenario
0) { + const groupedScenarios = {}; + + //Raggruppa gli scenari per categoria (solo se type non è null) selectedApp.available_scenarios.forEach(app => { - let scenarioItem = { - label: app.label, - icon: 'pi pi-fw pi-wrench', - items: [], // Sub-items per ogni scenario - command: () => { - route.push({ path: `/scenario/exec/${app.scenario_id}` }); + if (app.type) { + const type = app.type; + if (!groupedScenarios[type]) { + groupedScenarios[type] = []; } - }; + groupedScenarios[type].push(app); + } else { + //Se non ha categoria, lo trattiamo singolarmente + model.value[1].items.push(createScenarioItem(app)); + } + }); + + //Creazione del menu in base ai gruppi + Object.keys(groupedScenarios).forEach(type => { + const scenarios = groupedScenarios[type]; - // Aggiungi la sottovoce "Execution List" - scenarioItem.items.push({ - label: 'Execution List', - icon: 'pi pi-fw pi-list', - to: '/executions/filter', - command: () => { - // Salva il nome dello scenario nello store - userPrefStore.setSelectedScenario(app.label); - } - }); + if (scenarios.length >= 2) { + //Se ci sono almeno 2 scenari nella stessa categoria, creiamo un gruppo + const typeItem = { + label: type, + icon: 'pi pi-fw pi-folder', + items: [] + }; - // Aggiungi lo scenario alla lista principale - model.value[1].items.push(scenarioItem); + scenarios.forEach(app => { + typeItem.items.push(createScenarioItem(app)); + }); + + model.value[1].items.push(typeItem); + }else { + //Se c'è solo un elemento, lo aggiungiamo direttamente + model.value[1].items.push(createScenarioItem(scenarios[0])); + } + }); + + //Aggiungi "Rev Eng Code" alla fine della lista + model.value[1].items.push({ + label: 'Rev Eng Code', + icon: 'pi pi-fw pi-cog', + command: () => { + route.push({ path: '/app-browser' }); + } }); } - - // Aggiungi "Rev Eng Code" alla fine della lista - model.value[1].items.push({ - label: 'Rev Eng Code', - icon: 'pi pi-fw pi-wrench', - command: () => { - route.push({ path: '/app-browser' }); - } - }); - } else { - // Se selectedApp è nullo, svuota gli item + //Se selectedApp è nullo, svuota il menu model.value[1].label = ''; model.value[1].items = []; } } +//Funzione per creare un item scenario con Execution List +function createScenarioItem(app) { + return { + label: app.label, + icon: 'pi pi-fw pi-wrench', + items: [ + { + label: 'Execution List', + icon: 'pi pi-fw pi-list', + to: '/executions/filter', + command: () => { + userPrefStore.setSelectedScenario(app.label); + } + } + ], + command: () => { + route.push({ path: `/scenario/exec/${app.scenario_id}` }); + } + }; +} + +