Update picklist for new folders
This commit is contained in:
@@ -335,6 +335,8 @@ const fileNamesOutput = ref([]);
|
|||||||
const ksVideoGroupStore = KsVideoGroupStore();
|
const ksVideoGroupStore = KsVideoGroupStore();
|
||||||
const userPrefStore = UserPrefStore();
|
const userPrefStore = UserPrefStore();
|
||||||
const videoGroups = ref([]);
|
const videoGroups = ref([]);
|
||||||
|
const ksFolders = ref([]);
|
||||||
|
const folderToItemsMap = ref({});
|
||||||
// URL di upload
|
// URL di upload
|
||||||
const uploadUrlBase = import.meta.env.VITE_BACKEND_URL;
|
const uploadUrlBase = import.meta.env.VITE_BACKEND_URL;
|
||||||
const uploadUrl = ref('');
|
const uploadUrl = ref('');
|
||||||
@@ -424,6 +426,78 @@ const loadVideoGroups = async () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Estrae tutte le folder/subfolder uniche dai documenti e video
|
||||||
|
const extractFoldersFromItems = (items) => {
|
||||||
|
const folderMap = {};
|
||||||
|
const folderSet = new Set();
|
||||||
|
|
||||||
|
items.forEach((item) => {
|
||||||
|
const path = item.ingestionInfo?.metadata?.ksKnowledgePath;
|
||||||
|
if (!path) return;
|
||||||
|
|
||||||
|
// Rimuovi il leading slash se presente
|
||||||
|
const cleanPath = path.startsWith('/') ? path.substring(1) : path;
|
||||||
|
if (!cleanPath) return;
|
||||||
|
|
||||||
|
// Dividi il path in parti
|
||||||
|
const parts = cleanPath.split('/');
|
||||||
|
|
||||||
|
// Crea tutte le combinazioni di folder/subfolder
|
||||||
|
let currentPath = '';
|
||||||
|
parts.forEach((part, index) => {
|
||||||
|
currentPath = index === 0 ? part : `${currentPath}/${part}`;
|
||||||
|
const fullPath = `/${currentPath}`;
|
||||||
|
|
||||||
|
folderSet.add(fullPath);
|
||||||
|
|
||||||
|
// Inizializza l'array per questa folder se non esiste
|
||||||
|
if (!folderMap[fullPath]) {
|
||||||
|
folderMap[fullPath] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggiungi l'item solo se il path corrisponde esattamente
|
||||||
|
if (fullPath === path) {
|
||||||
|
folderMap[fullPath].push({
|
||||||
|
id: item.id,
|
||||||
|
type: item.fileName ? 'document' : 'video',
|
||||||
|
name: item.fileName || item.name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return { folders: Array.from(folderSet).sort(), folderMap };
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadKsFolders = async () => {
|
||||||
|
try {
|
||||||
|
// Carica documenti e video
|
||||||
|
const docsResponse = await KSDocumentService.getKSDocuments();
|
||||||
|
const documents = docsResponse.data || [];
|
||||||
|
|
||||||
|
// Combina documenti e video
|
||||||
|
const allItems = [...documents, ...videoGroups.value];
|
||||||
|
|
||||||
|
// Estrai folder e crea la mappa
|
||||||
|
const { folders, folderMap } = extractFoldersFromItems(allItems);
|
||||||
|
|
||||||
|
// Crea la struttura per la picklist
|
||||||
|
ksFolders.value = folders.map((path) => ({
|
||||||
|
id: path,
|
||||||
|
name: path,
|
||||||
|
path: path,
|
||||||
|
itemCount: folderMap[path]?.length || 0
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Salva la mappa folder->items per uso successivo
|
||||||
|
folderToItemsMap.value = folderMap;
|
||||||
|
|
||||||
|
console.log(`Loaded ${ksFolders.value.length} folders with items:`, folderToItemsMap.value);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading KS folders:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Ricarica i dati quando cambia il parametro `id`
|
// Ricarica i dati quando cambia il parametro `id`
|
||||||
watch(() => route.params.id, fetchScenario);
|
watch(() => route.params.id, fetchScenario);
|
||||||
|
|
||||||
@@ -517,9 +591,32 @@ const execScenario = async () => {
|
|||||||
const selectedItems = processedData[input.name];
|
const selectedItems = processedData[input.name];
|
||||||
|
|
||||||
if (Array.isArray(selectedItems) && selectedItems.length > 0) {
|
if (Array.isArray(selectedItems) && selectedItems.length > 0) {
|
||||||
// Elaborazione per VideoGroups (backward compatibility)
|
// Elaborazione speciale per ksFolders
|
||||||
|
if (input.dataSource === 'ksFolders') {
|
||||||
|
// Ottieni tutti gli ID dei documenti/video nelle folder selezionate
|
||||||
|
const allItemIds = [];
|
||||||
|
const allItemNames = [];
|
||||||
|
|
||||||
|
selectedItems.forEach((folder) => {
|
||||||
|
const folderPath = folder.path || folder.id || folder;
|
||||||
|
const items = folderToItemsMap.value[folderPath] || [];
|
||||||
|
|
||||||
|
items.forEach((item) => {
|
||||||
|
allItemIds.push(item.id);
|
||||||
|
allItemNames.push(item.name);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
processedData[`${input.name}_id`] = JSON.stringify(allItemIds);
|
||||||
|
processedData[`${input.name}_name`] = JSON.stringify(allItemNames);
|
||||||
|
processedData[`${input.name}_folders`] = JSON.stringify(selectedItems.map((item) => item.path || item.id || item));
|
||||||
|
|
||||||
|
console.log(`Folder selection - Total items: ${allItemIds.length}`, allItemIds);
|
||||||
|
} else {
|
||||||
|
// Elaborazione per VideoGroups e ksDocuments (backward compatibility)
|
||||||
processedData[`${input.name}_id`] = JSON.stringify(selectedItems.map((item) => item.id || item));
|
processedData[`${input.name}_id`] = JSON.stringify(selectedItems.map((item) => item.id || item));
|
||||||
processedData[`${input.name}_name`] = JSON.stringify(selectedItems.map((item) => item.name || item.fileName || item));
|
processedData[`${input.name}_name`] = JSON.stringify(selectedItems.map((item) => item.name || item.fileName || item));
|
||||||
|
}
|
||||||
|
|
||||||
// Rimuovi l'array originale
|
// Rimuovi l'array originale
|
||||||
delete processedData[input.name];
|
delete processedData[input.name];
|
||||||
@@ -892,6 +989,8 @@ const getOptionsForInput = (input) => {
|
|||||||
return videoGroups.value;
|
return videoGroups.value;
|
||||||
case 'ksDocuments':
|
case 'ksDocuments':
|
||||||
return ksDocuments.value;
|
return ksDocuments.value;
|
||||||
|
case 'ksFolders':
|
||||||
|
return ksFolders.value;
|
||||||
default:
|
default:
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -934,6 +1033,14 @@ const loadOptionsForScenario = async () => {
|
|||||||
console.log(`Loaded ${ksDocuments.value.length} KS documents`);
|
console.log(`Loaded ${ksDocuments.value.length} KS documents`);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'ksFolders':
|
||||||
|
// Prima carica i video groups se non sono già caricati
|
||||||
|
if (videoGroups.value.length === 0) {
|
||||||
|
await loadVideoGroups();
|
||||||
|
}
|
||||||
|
await loadKsFolders();
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.warn(`Unknown dataSource: ${dataSource}`);
|
console.warn(`Unknown dataSource: ${dataSource}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user