diff --git a/components/Element/ChatbotLinkItem.vue b/components/Element/ChatbotLinkItem.vue index fee4516..0cc6306 100644 --- a/components/Element/ChatbotLinkItem.vue +++ b/components/Element/ChatbotLinkItem.vue @@ -1,22 +1,37 @@ diff --git a/components/Element/ChatbotLinks.vue b/components/Element/ChatbotLinks.vue index ebbe1ac..1948d12 100644 --- a/components/Element/ChatbotLinks.vue +++ b/components/Element/ChatbotLinks.vue @@ -1,29 +1,50 @@ @@ -32,12 +53,16 @@ const addMode = ref(false); const isLoading = ref(true); const statesStore = useStatesStore(); const collection = statesStore.collection; +const FILTERS = ref(['ALL_LINKS', 'INDEXED_LINKS', 'NON_INDEXED_LINKS', 'ERROR_LINKS']) + const isDemo = statesStore.userHasRole('demo'); const isLinkAddAllowed = ref(false); -const links = ref([]); -let indexedItems = []; +const links = ref([]); +let indexedItems = []; const integration = useIntegration(); +const filterType = ref('ALL_LINKS'); +const openSelect = ref(false); const loadLinks = async () => { isLoading.value = true; @@ -72,6 +97,29 @@ const checkindexed = (id: string | undefined) => { return true; } +const checkHttpError = (id: string | undefined) => { + const it = indexedItems?.find((element :any) => element.custom_id == id ); + if (!it) { + return null; + } + return it.cmetadata.http_error; +} + +const filteredLinks = () => { + const referenceIds = indexedItems.map((item:any) => item.custom_id); + switch(filterType.value) { + case 'INDEXED_LINKS': + return links.value.filter((el:any) => referenceIds.includes(el.custom_id)) + case 'NON_INDEXED_LINKS': + return links.value.filter((el:any) => !referenceIds.includes(el.custom_id)) + case 'ERROR_LINKS': + const errorLinks = new Map(indexedItems.map((item: any) => [item.custom_id, item.cmetadata.http_error])); + return links.value.filter((el:any) => errorLinks.get(el.custom_id)) + default: + return links.value; + } +} + watch(links, (newLinks) => { isLinkAddAllowed.value = checkAddAllowed(newLinks); }); diff --git a/components/Form/ChatbotLink.vue b/components/Form/ChatbotLink.vue index 72329e7..569d9ea 100644 --- a/components/Form/ChatbotLink.vue +++ b/components/Form/ChatbotLink.vue @@ -18,6 +18,10 @@ @click.prevent="deleteLink" v-if="item.custom_id"> + @@ -26,6 +30,23 @@ :disabled="!url">{{ $t('ADD') }} + +
+

+ + {{ $t('INDEXING_SUCCESS') }} +

+

+ + {{ $t('INDEXING_FAILURE') }} +

+
+
@@ -37,11 +58,12 @@ const props = defineProps({ }, }); -const emit = defineEmits(['close']); +const emit = defineEmits(['close', 'index_link']); const error = ref(false); const isSaving = ref(false); const isDeleting = ref(false); +const isIndexing = ref(false); const url = ref(''); if (props.item.cmetadata) { @@ -53,6 +75,7 @@ const collectionUuid = statesStore.collection?.uuid || ''; const metadataDefaults = statesStore.collection?.cmetadata?.metadata_defaults?.links || {}; const linkLoadOptions = statesStore.collection?.cmetadata?.link_load_options || []; const integration = useIntegration(); +const indexingResult = ref<"Indexed" | "Not Indexed" | "None">("None"); // methods const cancel = () => { @@ -143,4 +166,50 @@ const deleteLink = async () => { isDeleting.value = false; emit('close', true); } + +const reindexLink = async(item: Record, collection: string | undefined) => { + let url = item.cmetadata.url; + let metadata = item.cmetadata; + let document_id = item.custom_id; + isIndexing.value = true; + try { + await $fetch(`/api/brevia/index/link`, { + method: 'POST', + body: { + link: url, + collection_id : collection, + metadata: metadata, + options: linkOptions(url), + document_id: document_id + }, + }); + //indexing + let data = await $fetch(`/api/brevia/index/${collection}/${document_id}`); + isIndexing.value = false; + if(!data.length || data[0].cmetadata.http_error){ + indexingResult.value = "Not Indexed"; + } + else { + indexingResult.value = "Indexed"; + emit('index_link'); + } + setTimeout(() => {indexingResult.value = "None"}, 1200); + } catch (err) { + console.log(err); + isIndexing.value = false; + } +} + + + diff --git a/locales/en/messages.json b/locales/en/messages.json index 8767883..8bd58d3 100644 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -77,6 +77,8 @@ "GIVE_THE_NEW_CHATBOT_A_TITLE_AND_INCLUDE_A_BRIEF_DESCRIPTION": "Give the new chatbot a title and include a brief description", "GO_TO_LOGIN_PAGE": "Go to login page", "HELLO": "Hello {name}", + "INDEXING_SUCCESS": "Content indexed successfully!", + "INDEXING_FAILURE": "An error occurred during indexing. Please try again later", "ITALIAN": "Italian", "JOBS_LEFT": "Analysis left", "LAST_LOGIN_ERROR": "Last login error: ", @@ -84,6 +86,12 @@ "LAST_NAME_PLACEHOLDER": "Enter your last name", "LAST_NAME_ERROR": "The user surname cannot be empty!", "LAST_PASSWORD_CHANGE": "Last password change: ", + "LINK_FILTERS": { + "ALL_LINKS": "All Links", + "INDEXED_LINKS": "Indexed Links", + "NON_INDEXED_LINKS": "Unindexed links", + "ERROR_LINKS": "Links with error status" + }, "LINK_PLACEHOLDER": "Write here a valid link to a webpage", "LOGIN_PLACEHOLDER": "Enter your email or username", "LOGOUT": "Logout", @@ -102,6 +110,7 @@ "NO_METADATA": "No metadata found for editing", "NO_MORE_ANALYSIS_JOBS": "You have exhausted the number of analysis for today", "NO_MORE_CHAT_MESSAGES": "You have exhausted the number of messages for today", + "NO_RESULTS_WITH_FILTER": "There are no results available with this filter", "NOT_A_MEMBER": "Not a member?", "NOT_VALID_EMAIL": "The provided email address is not valid", "OVERVIEW": "Overview", @@ -128,6 +137,7 @@ "SEND": "Send", "SET_NEW_PASSWORD": "Set the new password", "SETTINGS": "Settings", + "SHOW_FILTERED": "Show", "SHOW_DOCUMENTS_FOUND": "Show documents found", "SHOW_PASSWORD": "Show Password", "SIGN_IN": "Sign in", diff --git a/locales/it/messages.json b/locales/it/messages.json index eea9762..2f88e17 100644 --- a/locales/it/messages.json +++ b/locales/it/messages.json @@ -81,7 +81,15 @@ "LAST_NAME_PLACEHOLDER": "Il tuo cognome", "LAST_NAME_ERROR": "Il cognome utente non può essere vuoto!", "LAST_PASSWORD_CHANGE": "Ultimo cambio password: ", + "LINK_FILTERS": { + "ALL_LINKS": "Tutti i link", + "INDEXED_LINKS": "Link indicizzati", + "NON_INDEXED_LINKS": "Link non indicizzati", + "ERROR_LINKS": "Link in stato di errore" + }, "HELLO": "Ciao {name}", + "INDEXING_SUCCESS": "Contenuto indicizzato correttamente!", + "INDEXING_FAILURE": "Si è verificato un errore durante l'indicizzazione. Riprova più tardi.", "ITALIAN": "Italiano", "JOBS_LEFT": "Analisi rimanenti", "LINK_PLACEHOLDER": "Scrivi qui un link valido a una pagina web", @@ -102,6 +110,7 @@ "NO_METADATA": "Non ci sono metadati da modificare", "NO_MORE_ANALYSIS_JOBS": "Hai esaurito il numero di analisi per oggi", "NO_MORE_CHAT_MESSAGES": "Hai esaurito il numero di messaggi per oggi", + "NO_RESULTS_WITH_FILTER": "Non ci sono risultati per questo filtro", "NOT_A_MEMBER": "Non sei ancora registrato?", "NOT_VALID_EMAIL": "L'indirizzo di e-mail inserito non è valido", "OVERVIEW": "Generale", @@ -128,6 +137,7 @@ "SEND": "Invia", "SETTINGS": "Impostazioni", "SET_NEW_PASSWORD": "Applica la nuova password", + "SHOW_FILTERED": "Mostra", "SHOW_DOCUMENTS_FOUND": "Mostra i documenti trovati", "SHOW_PASSWORD": "Mostra password", "SIGN_IN": "Accedi",