diff --git a/src/admin/components/advanced-search/advanced-search.vue b/src/admin/components/advanced-search/advanced-search.vue index ecd72a979..69f319562 100644 --- a/src/admin/components/advanced-search/advanced-search.vue +++ b/src/admin/components/advanced-search/advanced-search.vue @@ -232,22 +232,36 @@ } }, mounted(){ - this.$root.$on('metadatumUpdated', (isRepositoryLevel) => { - if(isRepositoryLevel) { - this.metadataIsLoading = true; + this.$root.$on('metadatumUpdated', (isRepositoryLevel) => { - this.fetchMetadata({ - collectionId: this.isRepositoryLevel ? false : this.collectionId, - isRepositoryLevel: this.isRepositoryLevel, - isContextEdit: false, - includeDisabled: false, - isAdvancedSearch: true - }).then((metadata) => { - this.metadata = metadata; - this.metadataIsLoading = false; - }); - } - }); + if (isRepositoryLevel) { + this.metadataIsLoading = true; + + // Cancels previous Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); + + this.fetchMetadata({ + collectionId: this.isRepositoryLevel ? false : this.collectionId, + isRepositoryLevel: this.isRepositoryLevel, + isContextEdit: false, + includeDisabled: false, + isAdvancedSearch: true + }).then((resp) => { + resp.request + .then((metadata) => { + this.metadata = metadata; + this.metadataIsLoading = false; + }).catch(() => { + this.metadataIsLoading = false; + }); + + // Search Request Token for cancelling + this.metadataSearchCancel = resp.source; + }) + .catch(() => this.metadataIsLoading = false); + } + }); }, created(){ @@ -259,10 +273,19 @@ isContextEdit: false, includeDisabled: false, isAdvancedSearch: true - }).then((metadata) => { - this.metadata = metadata; - this.metadataIsLoading = false; - }); + }).then((resp) => { + resp.request + .then((metadata) => { + this.metadata = metadata; + this.metadataIsLoading = false; + }).catch(() => { + this.metadataIsLoading = false; + }); + + // Search Request Token for cancelling + this.metadataSearchCancel = resp.source; + }) + .catch(() => this.metadataIsLoading = false); if ((this.$route.query.metaquery && Object.keys(this.$route.query.metaquery).length > 0) || (this.$route.query.taxquery && Object.keys(this.$route.query.taxquery).length > 0) ){ @@ -343,6 +366,7 @@ }, metadataIsLoading: false, metadata: [], + metadataSearchCancel: undefined } }, methods: { @@ -557,6 +581,11 @@ }, beforeDestroy() { this.$root.$off('metadatumUpdated'); + + // Cancels previous Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); + } } diff --git a/src/admin/components/bulk-edition/bulk-edition-modal.vue b/src/admin/components/bulk-edition/bulk-edition-modal.vue index 99415d1bf..fa3cdd9f9 100644 --- a/src/admin/components/bulk-edition/bulk-edition-modal.vue +++ b/src/admin/components/bulk-edition/bulk-edition-modal.vue @@ -320,20 +320,30 @@ collectionID: Number, }, created(){ - if(!this.collectionID){ - // is repository level - - } else { + if (this.collectionID){ this.metadataIsLoading = true; + // Cancels previous Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); + this.fetchMetadata({ collectionId: this.collectionID, isRepositoryLevel: false, isContextEdit: true, - includeDisabled: false, - }).then(() => { - this.metadataIsLoading = false; - }); + includeDisabled: false + }).then((resp) => { + resp.request + .then(() => { + this.metadataIsLoading = false; + }).catch(() => { + this.metadataIsLoading = false; + }); + + // Search Request Token for cancelling + this.metadataSearchCancel = resp.source; + }) + .catch(() => this.metadataIsLoading = false); } this.createEditGroup({ @@ -378,6 +388,7 @@ groupID: null, dones: [false], metadataIsLoading: false, + metadataSearchCancel: undefined } }, methods: { @@ -552,6 +563,12 @@ } } }, + beforeDestroy() { + // Cancels previous Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); + + } } diff --git a/src/admin/components/edition/collection-edition-form.vue b/src/admin/components/edition/collection-edition-form.vue index b1eb25caf..3b1794b95 100644 --- a/src/admin/components/edition/collection-edition-form.vue +++ b/src/admin/components/edition/collection-edition-form.vue @@ -598,9 +598,6 @@ export default { 'fetchUsers', 'fetchCollectionsForParent' ]), - ...mapActions('metadata', [ - 'fetchMetadata' - ]), updateSlug: _.debounce(function() { if(!this.form.name || this.form.name.length <= 0){ return; @@ -957,7 +954,7 @@ export default { @import "../../scss/_variables.scss"; - @media screen and (max-width: 1024px) { + @media screen and (min-width: 1024px) { .column:last-of-type { padding-left: $page-side-padding !important; } diff --git a/src/admin/components/edition/importer-mapping-form.vue b/src/admin/components/edition/importer-mapping-form.vue index faf73b904..e913dcabc 100644 --- a/src/admin/components/edition/importer-mapping-form.vue +++ b/src/admin/components/edition/importer-mapping-form.vue @@ -207,7 +207,8 @@ export default { isEditingMetadatum: false, metadatum: {}, editedMetadatum: {}, - backgroundProcess: undefined + backgroundProcess: undefined, + metadataSearchCancel: undefined } }, components: { @@ -275,22 +276,37 @@ export default { loadMetadata() { // Generates options for metadata listing this.isFetchingCollectionMetadata = true; - this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: false, isContextEdit: false }) - .then((metadata) => { - this.collectionMetadata = JSON.parse(JSON.stringify(metadata)); - this.isFetchingCollectionMetadata = false; - this.fetchMappingImporter({ collection: this.collectionId, sessionId: this.sessionId }) - .then(res => { - if( res ) { - this.mappedCollection['mapping'] = res; - } - }) - }) - .catch((error) => { - this.$console.error(error); - this.isFetchingCollectionMetadata = false; - }); + // Cancels previous Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); + + this.fetchMetadata({ + collectionId: this.collectionId, + isRepositoryLevel: false, + isContextEdit: false + }).then((resp) => { + resp.request + .then((metadata) => { + this.collectionMetadata = JSON.parse(JSON.stringify(metadata)); + this.isFetchingCollectionMetadata = false; + + this.fetchMappingImporter({ collection: this.collectionId, sessionId: this.sessionId }) + .then(res => { + if( res ) { + this.mappedCollection['mapping'] = res; + } + }) + }) + .catch((error) => { + this.$console.error(error); + this.isFetchingCollectionMetadata = false; + }); + + // Search Request Token for cancelling + this.metadataSearchCancel = resp.source; + }) + .catch(() => this.isFetchingCollectionMetadata = false); }, cancelBack(){ this.$router.go(-2); @@ -433,6 +449,11 @@ export default { this.loadImporter(); this.loadMetadata(); + }, + beforeDestroy() { + // Cancels previous Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); } } diff --git a/src/admin/components/lists/filters-list.vue b/src/admin/components/lists/filters-list.vue index f89ff02ea..03c537829 100644 --- a/src/admin/components/lists/filters-list.vue +++ b/src/admin/components/lists/filters-list.vue @@ -334,7 +334,9 @@ export default { availableMetadata: [], filterTypes: [], currentFilterTypePreview: undefined, - columnsTopY: 0 + columnsTopY: 0, + filtersSearchCancel: undefined, + metadataSearchCancel: undefined } }, computed: { @@ -609,7 +611,7 @@ export default { return 190; } }, - mounted() { + mounted() { if (!this.isRepositoryLevel) this.$root.$emit('onCollectionBreadCrumbUpdate', [{ path: '', label: this.$i18n.get('filter') }]); @@ -624,7 +626,6 @@ export default { else this.collectionId = this.$route.params.collectionId; - this.isLoadingMetadatumTypes = true; this.isLoadingFilters = true; this.isLoadingFilterTypes = true; @@ -637,24 +638,57 @@ export default { this.isLoadingFilterTypes = false; }); - this.fetchFilters({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: true }) - .then(() => { - this.isLoadingFilters = false; - // Needs to be done after activeFilterList exists to compare and remove chosen metadata. - this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true }) - .then(() => { - this.isLoadingMetadatumTypes = false; - this.updateListOfMetadata(); - }) - .catch(() => { - this.isLoadingMetadatumTypes = false; - }); - }) - .catch(() => { - this.isLoadingFilters = false; - }); + // Cancels previous Request + if (this.filtersSearchCancel != undefined) + this.filtersSearchCancel.cancel('Filters search Canceled.'); + + this.fetchFilters({ + collectionId: this.collectionId, + isRepositoryLevel: this.isRepositoryLevel, + isContextEdit: !this.isOnTheme, + includeDisabled: true, + }).then((resp) => { + resp.request + .then(() => { + + this.isLoadingMetadatumTypes = true; + + // Cancels previous Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); + + // Needs to be done after activeFilterList exists to compare and remove chosen metadata. + this.fetchMetadata({ + collectionId: this.collectionId, + isRepositoryLevel: this.isRepositoryLevel, + isContextEdit: true + }).then((resp) => { + resp.request + .then(() => { + this.isLoadingMetadatumTypes = false; + this.updateListOfMetadata(); + }) + .catch(() => { + this.isLoadingMetadatumTypes = false; + }); + // Search Request Token for cancelling + this.metadataSearchCancel = resp.source; + }) + .catch(() => this.isLoadingMetadatumTypes = false); + }) + .catch(() => this.isLoadingFilters = false); + + // Search Request Token for cancelling + this.filtersSearchCancel = resp.source; + }) + .catch(() => this.isLoadingFilters = false); + + // On repository level we also fetch collection filters + if (this.isRepositoryLevel) { + this.fetchRepositoryCollectionFilters() + .catch(() => this.isLoadingFilters = false); + } - // Obtains collection name if (!this.isRepositoryLevel) { this.fetchCollectionName(this.collectionId).then((collectionName) => { @@ -666,6 +700,15 @@ export default { this.onCancelFilterTypeSelection(); } + }, + beforeDestroy() { + // Cancels previous filters Request + if (this.filtersSearchCancel != undefined) + this.filtersSearchCancel.cancel('Metadata search Canceled.'); + + // Cancels previous metadata Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); } } diff --git a/src/admin/components/lists/metadata-list.vue b/src/admin/components/lists/metadata-list.vue index 39dc0a6a4..14a579afb 100644 --- a/src/admin/components/lists/metadata-list.vue +++ b/src/admin/components/lists/metadata-list.vue @@ -461,7 +461,8 @@ export default { new_metadata_label: '', new_metadata_uri: '', new_metadata_slug: '', - columnsTopY: 0 + columnsTopY: 0, + metadataSearchCancel: undefined } }, components: { @@ -618,8 +619,11 @@ export default { .then(() => { if (!this.isRepositoryLevel) this.updateMetadataOrder(); + else + this.$root.$emit('metadatumUpdated', this.isRepositoryLevel); }) .catch(() => { + this.$console.log("Error deleting metadatum.") }); }, } @@ -846,26 +850,43 @@ export default { return true; }, refreshMetadata() { + + // Cancels previous Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); + this.isRepositoryLevel = this.$route.name == 'MetadataPage' ? true : false; + if (this.isRepositoryLevel) this.collectionId = 'default'; else this.collectionId = this.$route.params.collectionId; - - this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: true}) - .then(() => { - this.isLoadingMetadata = false; - - // Checks URL as router watcher would not wait for list to load - if (this.$route.query.edit != undefined) { - let existingMetadataIndex = this.activeMetadatumList.findIndex((metadatum) => metadatum.id == this.$route.query.edit); - if (existingMetadataIndex >= 0) - this.editMetadatum(this.activeMetadatumList[existingMetadataIndex]); - } + + this.fetchMetadata({ + collectionId: this.collectionId, + isRepositoryLevel: this.isRepositoryLevel, + isContextEdit: true, + includeDisabled: true + }).then((resp) => { + resp.request + .then(() => { + this.isLoadingMetadata = false; + + // Checks URL as router watcher would not wait for list to load + if (this.$route.query.edit != undefined) { + let existingMetadataIndex = this.activeMetadatumList.findIndex((metadatum) => metadatum.id == this.$route.query.edit); + if (existingMetadataIndex >= 0) + this.editMetadatum(this.activeMetadatumList[existingMetadataIndex]); + } + }) + .catch(() => { + this.isLoadingMetadata = false; + }); + + // Search Request Token for cancelling + this.metadataSearchCancel = resp.source; }) - .catch(() => { - this.isLoadingMetadata = false; - }); + .catch(() => this.isLoadingMetadata = false); }, getPreviewTemplateContent(metadatum) { return `
@@ -919,6 +940,13 @@ export default { this.collectionName = collectionName; }); } + }, + beforeDestroy() { + + // Cancels previous Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); + } } diff --git a/src/admin/pages/lists/items-page.vue b/src/admin/pages/lists/items-page.vue index 213fcbc0b..ed0a51719 100644 --- a/src/admin/pages/lists/items-page.vue +++ b/src/admin/pages/lists/items-page.vue @@ -915,7 +915,9 @@ isFilterModalActive: false, collection: undefined, hasAnOpenModal: false, - hasAnOpenAlert: true + hasAnOpenAlert: true, + filtersSearchCancel: undefined, + metadataSearchCancel: undefined } }, props: { @@ -1189,6 +1191,10 @@ }, prepareFilters() { + // Cancels previous Request + if (this.filtersSearchCancel != undefined) + this.filtersSearchCancel.cancel('Filters search Canceled.'); + this.isLoadingFilters = true; this.fetchFilters({ @@ -1197,7 +1203,14 @@ isContextEdit: !this.isOnTheme, includeDisabled: 'no', }) - .then(() => this.isLoadingFilters = false) + .then((resp) => { + resp.request + .then(() => this.isLoadingFilters = false) + .catch(() => this.isLoadingFilters = false); + + // Search Request Token for cancelling + this.filtersSearchCancel = resp.source; + }) .catch(() => this.isLoadingFilters = false); // On repository level we also fetch collection filters @@ -1209,6 +1222,10 @@ }, prepareMetadata() { + // Cancels previous Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); + this.$eventBusSearch.cleanFetchOnly(); this.isLoadingMetadata = true; @@ -1219,212 +1236,219 @@ isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }) - .then(() => { - this.sortingMetadata = []; + .then((resp) => { + resp.request + .then(() => { + this.sortingMetadata = []; - // Decides if custom meta will be loaded with item. - let shouldLoadMeta = true; - - if (this.isOnTheme) - shouldLoadMeta = this.registeredViewModes[this.viewMode].dynamic_metadata; - else - shouldLoadMeta = this.adminViewMode == 'table' || this.adminViewMode == 'records' || this.adminViewMode == undefined; - - if (shouldLoadMeta) { - - // Loads user prefs object as we'll need to check if there's something configured by user - let prefsFetchOnly = !this.isRepositoryLevel ? `fetch_only_${this.collectionId}` : 'fetch_only'; - let prefsFetchOnlyMeta = !this.isRepositoryLevel ? `fetch_only_meta_${this.collectionId}` : 'fetch_only_meta'; + // Decides if custom meta will be loaded with item. + let shouldLoadMeta = true; + + if (this.isOnTheme) + shouldLoadMeta = this.registeredViewModes[this.viewMode].dynamic_metadata; + else + shouldLoadMeta = this.adminViewMode == 'table' || this.adminViewMode == 'records' || this.adminViewMode == undefined; + + if (shouldLoadMeta) { + + // Loads user prefs object as we'll need to check if there's something configured by user + let prefsFetchOnly = !this.isRepositoryLevel ? `fetch_only_${this.collectionId}` : 'fetch_only'; + let prefsFetchOnlyMeta = !this.isRepositoryLevel ? `fetch_only_meta_${this.collectionId}` : 'fetch_only_meta'; - let prefsFetchOnlyObject = this.$userPrefs.get(prefsFetchOnly) ? typeof this.$userPrefs.get(prefsFetchOnly) != 'string' ? this.$userPrefs.get(prefsFetchOnly) : this.$userPrefs.get(prefsFetchOnly).replace(/,null/g, '').split(',') : []; - let prefsFetchOnlyMetaObject = this.$userPrefs.get(prefsFetchOnlyMeta) ? this.$userPrefs.get(prefsFetchOnlyMeta).split(',') : []; - - let thumbnailMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[0] != null) : true; - - metadata.push({ - name: this.$i18n.get('label_thumbnail'), - metadatum: 'row_thumbnail', - metadata_type: undefined, - slug: 'thumbnail', - id: undefined, - display: thumbnailMetadatumDisplay - }); - - // Repository Level always shows core metadata - if (this.isRepositoryLevel) { - metadata.push({ - name: this.$i18n.get('label_title'), - metadatum: 'row_title', - metadata_type_object: {core: true, related_mapped_prop: 'title'}, - metadata_type: undefined, - slug: 'title', - id: undefined, - display: true - }); - metadata.push({ - name: this.$i18n.get('label_description'), - metadatum: 'row_description', - metadata_type_object: {core: true, related_mapped_prop: 'description'}, - metadata_type: undefined, - slug: 'description', - id: undefined, - display: true - }); - } - - let fetchOnlyMetadatumIds = []; - - for (let metadatum of this.metadata) { - if (metadatum.display !== 'never') { - - let display; - - // Deciding display based on collection settings - if (metadatum.display == 'no') - display = false; - else if (metadatum.display == 'yes') - display = true; - - // Deciding display based on user prefs - if (prefsFetchOnlyMetaObject.length) { - let index = prefsFetchOnlyMetaObject.findIndex(metadatumId => metadatumId == metadatum.id); - - display = index >= 0; - } + let prefsFetchOnlyObject = this.$userPrefs.get(prefsFetchOnly) ? typeof this.$userPrefs.get(prefsFetchOnly) != 'string' ? this.$userPrefs.get(prefsFetchOnly) : this.$userPrefs.get(prefsFetchOnly).replace(/,null/g, '').split(',') : []; + let prefsFetchOnlyMetaObject = this.$userPrefs.get(prefsFetchOnlyMeta) ? this.$userPrefs.get(prefsFetchOnlyMeta).split(',') : []; + let thumbnailMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[0] != null) : true; + metadata.push({ - name: metadatum.name, - metadatum: metadatum.description, - slug: metadatum.slug, - metadata_type: metadatum.metadata_type, - metadata_type_object: metadatum.metadata_type_object, - metadata_type_options: metadatum.metadata_type_options, - id: metadatum.id, - display: display, - collection_id: metadatum.collection_id, - multiple: metadatum.multiple, + name: this.$i18n.get('label_thumbnail'), + metadatum: 'row_thumbnail', + metadata_type: undefined, + slug: 'thumbnail', + id: undefined, + display: thumbnailMetadatumDisplay }); - if (display) { - fetchOnlyMetadatumIds.push(metadatum.id); + + // Repository Level always shows core metadata + if (this.isRepositoryLevel) { + metadata.push({ + name: this.$i18n.get('label_title'), + metadatum: 'row_title', + metadata_type_object: {core: true, related_mapped_prop: 'title'}, + metadata_type: undefined, + slug: 'title', + id: undefined, + display: true + }); + metadata.push({ + name: this.$i18n.get('label_description'), + metadatum: 'row_description', + metadata_type_object: {core: true, related_mapped_prop: 'description'}, + metadata_type: undefined, + slug: 'description', + id: undefined, + display: true + }); + } + + let fetchOnlyMetadatumIds = []; + + for (let metadatum of this.metadata) { + if (metadatum.display !== 'never') { + + let display; + + // Deciding display based on collection settings + if (metadatum.display == 'no') + display = false; + else if (metadatum.display == 'yes') + display = true; + + // Deciding display based on user prefs + if (prefsFetchOnlyMetaObject.length) { + let index = prefsFetchOnlyMetaObject.findIndex(metadatumId => metadatumId == metadatum.id); + + display = index >= 0; + } + + metadata.push({ + name: metadatum.name, + metadatum: metadatum.description, + slug: metadatum.slug, + metadata_type: metadatum.metadata_type, + metadata_type_object: metadatum.metadata_type_object, + metadata_type_options: metadatum.metadata_type_options, + id: metadatum.id, + display: display, + collection_id: metadatum.collection_id, + multiple: metadatum.multiple, + }); + if (display) { + fetchOnlyMetadatumIds.push(metadatum.id); + } + + if ( + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' && + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' && + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship' + ) { + this.sortingMetadata.push(metadatum); + } + + } + } + + let creationDateMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[1] != null) : true; + let authorNameMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[2] != null) : true; + + // Creation date and author name should appear only on admin. + if (!this.isOnTheme) { + + metadata.push({ + name: this.$i18n.get('label_creation_date'), + metadatum: 'row_creation', + metadata_type: undefined, + slug: 'creation_date', + id: undefined, + display: creationDateMetadatumDisplay + }); + metadata.push({ + name: this.$i18n.get('label_created_by'), + metadatum: 'row_author', + metadata_type: undefined, + slug: 'author_name', + id: undefined, + display: authorNameMetadatumDisplay + }); } - if ( - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' && - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' && - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship' - ) { - this.sortingMetadata.push(metadatum); + this.$eventBusSearch.addFetchOnly( + (thumbnailMetadatumDisplay ? 'thumbnail' : null) +','+ + (creationDateMetadatumDisplay ? 'creation_date' : null) +','+ + (authorNameMetadatumDisplay ? 'author_name' : null) +','+ + (this.isRepositoryLevel ? 'title' : null) +','+ + (this.isRepositoryLevel ? 'description' : null) + , false, fetchOnlyMetadatumIds.toString()); + + // Sorting metadata + if (this.isRepositoryLevel) { + this.sortingMetadata.push({ + name: this.$i18n.get('label_title'), + metadatum: 'row_title', + metadata_type_object: {core: true, related_mapped_prop: 'title'}, + metadata_type: undefined, + slug: 'title', + id: undefined, + display: true + }); + } + this.sortingMetadata.push({ + name: this.$i18n.get('label_creation_date'), + metadatum: 'row_creation', + metadata_type: undefined, + slug: 'creation_date', + id: undefined, + display: creationDateMetadatumDisplay + }); + if (authorNameMetadatumDisplay) { + this.sortingMetadata.push({ + name: this.$i18n.get('label_created_by'), + metadatum: 'row_author', + metadata_type: undefined, + slug: 'author_name', + id: undefined, + display: authorNameMetadatumDisplay + }); } - - } - } - let creationDateMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[1] != null) : true; - let authorNameMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[2] != null) : true; - - // Creation date and author name should appear only on admin. - if (!this.isOnTheme) { - - metadata.push({ - name: this.$i18n.get('label_creation_date'), - metadatum: 'row_creation', - metadata_type: undefined, - slug: 'creation_date', - id: undefined, - display: creationDateMetadatumDisplay - }); - metadata.push({ - name: this.$i18n.get('label_created_by'), - metadatum: 'row_author', - metadata_type: undefined, - slug: 'author_name', - id: undefined, - display: authorNameMetadatumDisplay - }); - } + // Loads only basic attributes necessary to view modes that do not allow custom meta + } else { - this.$eventBusSearch.addFetchOnly( - (thumbnailMetadatumDisplay ? 'thumbnail' : null) +','+ - (creationDateMetadatumDisplay ? 'creation_date' : null) +','+ - (authorNameMetadatumDisplay ? 'author_name' : null) +','+ - (this.isRepositoryLevel ? 'title' : null) +','+ - (this.isRepositoryLevel ? 'description' : null) - , false, fetchOnlyMetadatumIds.toString()); + this.$eventBusSearch.addFetchOnly('thumbnail,creation_date,author_name,title,description', true, ''); - // Sorting metadata - if (this.isRepositoryLevel) { - this.sortingMetadata.push({ - name: this.$i18n.get('label_title'), - metadatum: 'row_title', - metadata_type_object: {core: true, related_mapped_prop: 'title'}, - metadata_type: undefined, - slug: 'title', - id: undefined, - display: true - }); - } - this.sortingMetadata.push({ - name: this.$i18n.get('label_creation_date'), - metadatum: 'row_creation', - metadata_type: undefined, - slug: 'creation_date', - id: undefined, - display: creationDateMetadatumDisplay - }); - if (authorNameMetadatumDisplay) { - this.sortingMetadata.push({ - name: this.$i18n.get('label_created_by'), - metadatum: 'row_author', - metadata_type: undefined, - slug: 'author_name', - id: undefined, - display: authorNameMetadatumDisplay - }); - } + if (this.isRepositoryLevel) { + this.sortingMetadata.push({ + name: this.$i18n.get('label_title'), + metadatum: 'row_title', + metadata_type_object: {core: true, related_mapped_prop: 'title'}, + metadata_type: undefined, + slug: 'title', + id: undefined, + display: true + }); + } - // Loads only basic attributes necessary to view modes that do not allow custom meta - } else { - - this.$eventBusSearch.addFetchOnly('thumbnail,creation_date,author_name,title,description', true, ''); + for (let metadatum of this.metadata) { + if (metadatum.display !== 'never' && + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' && + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' && + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship') { + this.sortingMetadata.push(metadatum); + } + } - if (this.isRepositoryLevel) { - this.sortingMetadata.push({ - name: this.$i18n.get('label_title'), - metadatum: 'row_title', - metadata_type_object: {core: true, related_mapped_prop: 'title'}, - metadata_type: undefined, - slug: 'title', - id: undefined, - display: true - }); - } + this.sortingMetadata.push({ + name: this.$i18n.get('label_creation_date'), + metadatum: 'row_creation', + metadata_type: undefined, + slug: 'creation_date', + id: undefined, + display: true + }) - for (let metadatum of this.metadata) { - if (metadatum.display !== 'never' && - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' && - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' && - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship') { - this.sortingMetadata.push(metadatum); } - } - this.sortingMetadata.push({ - name: this.$i18n.get('label_creation_date'), - metadatum: 'row_creation', - metadata_type: undefined, - slug: 'creation_date', - id: undefined, - display: true + this.isLoadingMetadata = false; + this.displayedMetadata = metadata; + }) + .catch(() => { + this.isLoadingMetadata = false; }) - } - - this.isLoadingMetadata = false; - this.displayedMetadata = metadata; + // Search Request Token for cancelling + this.metadataSearchCancel = resp.source; }) - .catch(() => { - this.isLoadingMetadata = false; - }); + .catch(() => this.isLoadingMetadata = false); }, updateCollectionInfo () { if (this.collectionId) { @@ -1579,8 +1603,16 @@ }, beforeDestroy() { this.removeEventListeners(); - - // Cancels previous Request + + // Cancels previous Metadata Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); + + // Cancels previous Filters Request + if (this.filtersSearchCancel != undefined) + this.filtersSearchCancel.cancel('Filters search Canceled.'); + + // Cancels previous Items Request if (this.$eventBusSearch.searchCancel != undefined) this.$eventBusSearch.searchCancel.cancel('Item search Canceled.'); diff --git a/src/admin/pages/lists/term-items-page.vue b/src/admin/pages/lists/term-items-page.vue index 826250c57..f0e2f8503 100644 --- a/src/admin/pages/lists/term-items-page.vue +++ b/src/admin/pages/lists/term-items-page.vue @@ -890,7 +890,9 @@ isFilterModalActive: false, customFilters: [], hasAnOpenModal: false, - hasAnOpenAlert: true + hasAnOpenAlert: true, + filtersSearchCancel: undefined, + metadataSearchCancel: undefined } }, props: { @@ -1133,6 +1135,10 @@ }, prepareFilters() { + // Cancels previous Request + if (this.filtersSearchCancel != undefined) + this.filtersSearchCancel.cancel('Filters search Canceled.'); + this.isLoadingFilters = true; // Normal filter loading, only collection ones @@ -1143,7 +1149,14 @@ isContextEdit: !this.isOnTheme, includeDisabled: 'no', }) - .then(() => this.isLoadingFilters = false) + .then((resp) => { + resp.request + .then(() => this.isLoadingFilters = false) + .catch(() => this.isLoadingFilters = false); + + // Search Request Token for cancelling + this.filtersSearchCancel = resp.source; + }) .catch(() => this.isLoadingFilters = false); // Custom filter loading, get's from collections that have items with that taxonomy @@ -1155,6 +1168,10 @@ } }, prepareMetadata() { + + // Cancels previous Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); this.$eventBusSearch.cleanFetchOnly(); this.isLoadingMetadata = true; @@ -1165,213 +1182,218 @@ collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false - }) - .then(() => { - this.sortingMetadata = []; + }).then((resp) => { + resp.request + .then(() => { + this.sortingMetadata = []; - // Decides if custom meta will be loaded with item. - let shouldLoadMeta = true; - - if (this.isOnTheme) - shouldLoadMeta = this.registeredViewModes[this.viewMode].dynamic_metadata; - else - shouldLoadMeta = this.adminViewMode == 'table' || this.adminViewMode == 'records' || this.adminViewMode == undefined; - - if (shouldLoadMeta) { - // Loads user prefs object as we'll need to check if there's something configured by user - let prefsFetchOnly = !this.isRepositoryLevel ? `fetch_only_${this.collectionId}` : 'fetch_only'; - let prefsFetchOnlyMeta = !this.isRepositoryLevel ? `fetch_only_meta_${this.collectionId}` : 'fetch_only_meta'; + // Decides if custom meta will be loaded with item. + let shouldLoadMeta = true; + + if (this.isOnTheme) + shouldLoadMeta = this.registeredViewModes[this.viewMode].dynamic_metadata; + else + shouldLoadMeta = this.adminViewMode == 'table' || this.adminViewMode == 'records' || this.adminViewMode == undefined; + + if (shouldLoadMeta) { + // Loads user prefs object as we'll need to check if there's something configured by user + let prefsFetchOnly = !this.isRepositoryLevel ? `fetch_only_${this.collectionId}` : 'fetch_only'; + let prefsFetchOnlyMeta = !this.isRepositoryLevel ? `fetch_only_meta_${this.collectionId}` : 'fetch_only_meta'; - let prefsFetchOnlyObject = this.$userPrefs.get(prefsFetchOnly) ? typeof this.$userPrefs.get(prefsFetchOnly) != 'string' ? this.$userPrefs.get(prefsFetchOnly) : this.$userPrefs.get(prefsFetchOnly).replace(/,null/g, '').split(',') : []; - let prefsFetchOnlyMetaObject = this.$userPrefs.get(prefsFetchOnlyMeta) ? this.$userPrefs.get(prefsFetchOnlyMeta).split(',') : []; + let prefsFetchOnlyObject = this.$userPrefs.get(prefsFetchOnly) ? typeof this.$userPrefs.get(prefsFetchOnly) != 'string' ? this.$userPrefs.get(prefsFetchOnly) : this.$userPrefs.get(prefsFetchOnly).replace(/,null/g, '').split(',') : []; + let prefsFetchOnlyMetaObject = this.$userPrefs.get(prefsFetchOnlyMeta) ? this.$userPrefs.get(prefsFetchOnlyMeta).split(',') : []; - let thumbnailMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[0] != null) : true; - - metadata.push({ - name: this.$i18n.get('label_thumbnail'), - metadatum: 'row_thumbnail', - metadata_type: undefined, - slug: 'thumbnail', - id: undefined, - display: thumbnailMetadatumDisplay - }); - - // Repository Level always shows core metadata - if (this.isRepositoryLevel) { - metadata.push({ - name: this.$i18n.get('label_title'), - metadatum: 'row_title', - metadata_type_object: {core: true, related_mapped_prop: 'title'}, - metadata_type: undefined, - slug: 'title', - id: undefined, - display: true - }); - metadata.push({ - name: this.$i18n.get('label_description'), - metadatum: 'row_description', - metadata_type_object: {core: true, related_mapped_prop: 'description'}, - metadata_type: undefined, - slug: 'description', - id: undefined, - display: true - }); - } - - let fetchOnlyMetadatumIds = []; - - for (let metadatum of this.metadata) { - if (metadatum.display !== 'never') { - - let display; - - // Deciding display based on collection settings - if (metadatum.display == 'no') - display = false; - else if (metadatum.display == 'yes') - display = true; - - // Deciding display based on user prefs - if (prefsFetchOnlyMetaObject.length) { - let index = prefsFetchOnlyMetaObject.findIndex(metadatumId => metadatumId == metadatum.id); - - display = index >= 0; - } + let thumbnailMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[0] != null) : true; metadata.push({ - name: metadatum.name, - metadatum: metadatum.description, - slug: metadatum.slug, - metadata_type: metadatum.metadata_type, - metadata_type_object: metadatum.metadata_type_object, - metadata_type_options: metadatum.metadata_type_options, - id: metadatum.id, - display: display, - collection_id: metadatum.collection_id, - multiple: metadatum.multiple, + name: this.$i18n.get('label_thumbnail'), + metadatum: 'row_thumbnail', + metadata_type: undefined, + slug: 'thumbnail', + id: undefined, + display: thumbnailMetadatumDisplay }); - if (display) { - fetchOnlyMetadatumIds.push(metadatum.id); + // Repository Level always shows core metadata + if (this.isRepositoryLevel) { + metadata.push({ + name: this.$i18n.get('label_title'), + metadatum: 'row_title', + metadata_type_object: {core: true, related_mapped_prop: 'title'}, + metadata_type: undefined, + slug: 'title', + id: undefined, + display: true + }); + metadata.push({ + name: this.$i18n.get('label_description'), + metadatum: 'row_description', + metadata_type_object: {core: true, related_mapped_prop: 'description'}, + metadata_type: undefined, + slug: 'description', + id: undefined, + display: true + }); } - if ( - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' && - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' && - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship' - ) { - this.sortingMetadata.push(metadatum); + let fetchOnlyMetadatumIds = []; + + for (let metadatum of this.metadata) { + if (metadatum.display !== 'never') { + + let display; + + // Deciding display based on collection settings + if (metadatum.display == 'no') + display = false; + else if (metadatum.display == 'yes') + display = true; + + // Deciding display based on user prefs + if (prefsFetchOnlyMetaObject.length) { + let index = prefsFetchOnlyMetaObject.findIndex(metadatumId => metadatumId == metadatum.id); + + display = index >= 0; + } + + metadata.push({ + name: metadatum.name, + metadatum: metadatum.description, + slug: metadatum.slug, + metadata_type: metadatum.metadata_type, + metadata_type_object: metadatum.metadata_type_object, + metadata_type_options: metadatum.metadata_type_options, + id: metadatum.id, + display: display, + collection_id: metadatum.collection_id, + multiple: metadatum.multiple, + }); + + if (display) { + fetchOnlyMetadatumIds.push(metadatum.id); + } + + if ( + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' && + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' && + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship' + ) { + this.sortingMetadata.push(metadatum); + } + + } + } - } + let creationDateMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[1] != null) : true; + let authorNameMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[2] != null) : true; + + // Creation date and author name should appear only on admin. + if (!this.isOnTheme) { + + metadata.push({ + name: this.$i18n.get('label_creation_date'), + metadatum: 'row_creation', + metadata_type: undefined, + slug: 'creation_date', + id: undefined, + display: creationDateMetadatumDisplay + }); + metadata.push({ + name: this.$i18n.get('label_created_by'), + metadatum: 'row_author', + metadata_type: undefined, + slug: 'author_name', + id: undefined, + display: authorNameMetadatumDisplay + }); + } - } + this.$eventBusSearch.addFetchOnly( + (thumbnailMetadatumDisplay ? 'thumbnail' : null) +','+ + (creationDateMetadatumDisplay ? 'creation_date' : null) +','+ + (authorNameMetadatumDisplay ? 'author_name' : null) +','+ + (this.isRepositoryLevel ? 'title' : null) +','+ + (this.isRepositoryLevel ? 'description' : null) + , false, fetchOnlyMetadatumIds.toString()); - let creationDateMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[1] != null) : true; - let authorNameMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[2] != null) : true; - - // Creation date and author name should appear only on admin. - if (!this.isOnTheme) { - - metadata.push({ - name: this.$i18n.get('label_creation_date'), - metadatum: 'row_creation', - metadata_type: undefined, - slug: 'creation_date', - id: undefined, - display: creationDateMetadatumDisplay - }); - metadata.push({ - name: this.$i18n.get('label_created_by'), - metadatum: 'row_author', - metadata_type: undefined, - slug: 'author_name', - id: undefined, - display: authorNameMetadatumDisplay - }); - } - - this.$eventBusSearch.addFetchOnly( - (thumbnailMetadatumDisplay ? 'thumbnail' : null) +','+ - (creationDateMetadatumDisplay ? 'creation_date' : null) +','+ - (authorNameMetadatumDisplay ? 'author_name' : null) +','+ - (this.isRepositoryLevel ? 'title' : null) +','+ - (this.isRepositoryLevel ? 'description' : null) - , false, fetchOnlyMetadatumIds.toString()); - - // Sorting metadata - if (this.isRepositoryLevel) { - this.sortingMetadata.push({ - name: this.$i18n.get('label_title'), - metadatum: 'row_title', - metadata_type_object: {core: true, related_mapped_prop: 'title'}, - metadata_type: undefined, - slug: 'title', - id: undefined, - display: true - }); - } - this.sortingMetadata.push({ - name: this.$i18n.get('label_creation_date'), - metadatum: 'row_creation', - metadata_type: undefined, - slug: 'creation_date', - id: undefined, - display: creationDateMetadatumDisplay - }); - if (authorNameMetadatumDisplay) { - this.sortingMetadata.push({ - name: this.$i18n.get('label_created_by'), - metadatum: 'row_author', - metadata_type: undefined, - slug: 'author_name', - id: undefined, - display: authorNameMetadatumDisplay - }); - } - // Loads only basic attributes necessary to view modes that do not allow custom meta - } else { - - this.$eventBusSearch.addFetchOnly('thumbnail,creation_date,author_name,title,description', true, ''); + // Sorting metadata + if (this.isRepositoryLevel) { + this.sortingMetadata.push({ + name: this.$i18n.get('label_title'), + metadatum: 'row_title', + metadata_type_object: {core: true, related_mapped_prop: 'title'}, + metadata_type: undefined, + slug: 'title', + id: undefined, + display: true + }); + } + this.sortingMetadata.push({ + name: this.$i18n.get('label_creation_date'), + metadatum: 'row_creation', + metadata_type: undefined, + slug: 'creation_date', + id: undefined, + display: creationDateMetadatumDisplay + }); + if (authorNameMetadatumDisplay) { + this.sortingMetadata.push({ + name: this.$i18n.get('label_created_by'), + metadatum: 'row_author', + metadata_type: undefined, + slug: 'author_name', + id: undefined, + display: authorNameMetadatumDisplay + }); + } + // Loads only basic attributes necessary to view modes that do not allow custom meta + } else { - if (this.isRepositoryLevel) { - this.sortingMetadata.push({ - name: this.$i18n.get('label_title'), - metadatum: 'row_title', - metadata_type_object: {core: true, related_mapped_prop: 'title'}, - metadata_type: undefined, - slug: 'title', - id: undefined, - display: true - }); - } - - for (let metadatum of this.metadata) { - if (metadatum.display !== 'never' && - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' && - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' && - metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship') { - this.sortingMetadata.push(metadatum); + this.$eventBusSearch.addFetchOnly('thumbnail,creation_date,author_name,title,description', true, ''); + + if (this.isRepositoryLevel) { + this.sortingMetadata.push({ + name: this.$i18n.get('label_title'), + metadatum: 'row_title', + metadata_type_object: {core: true, related_mapped_prop: 'title'}, + metadata_type: undefined, + slug: 'title', + id: undefined, + display: true + }); + } + + for (let metadatum of this.metadata) { + if (metadatum.display !== 'never' && + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' && + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' && + metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship') { + this.sortingMetadata.push(metadatum); + } + } + + this.sortingMetadata.push({ + name: this.$i18n.get('label_creation_date'), + metadatum: 'row_creation', + metadata_type: undefined, + slug: 'creation_date', + id: undefined, + display: true + }) + } - } - this.sortingMetadata.push({ - name: this.$i18n.get('label_creation_date'), - metadatum: 'row_creation', - metadata_type: undefined, - slug: 'creation_date', - id: undefined, - display: true + this.isLoadingMetadata = false; + this.displayedMetadata = metadata; }) - - } - - this.isLoadingMetadata = false; - this.displayedMetadata = metadata; + .catch(() => { + this.isLoadingMetadata = false; + }) + // Search Request Token for cancelling + this.metadataSearchCancel = resp.source; }) - .catch(() => { - this.isLoadingMetadata = false; - }); + .catch(() => this.isLoadingMetadata = false); }, showItemsHiddingDueSortingDialog() { @@ -1521,8 +1543,16 @@ }, beforeDestroy() { this.removeEventListeners(); - - // Cancels previous Request + + // Cancels previous Metadata Request + if (this.metadataSearchCancel != undefined) + this.metadataSearchCancel.cancel('Metadata search Canceled.'); + + // Cancels previous Filters Request + if (this.filtersSearchCancel != undefined) + this.filtersSearchCancel.cancel('Filters search Canceled.'); + + // Cancels previous Items Request if (this.$eventBusSearch.searchCancel != undefined) this.$eventBusSearch.searchCancel.cancel('Item search Canceled.'); diff --git a/src/classes/filter-types/autocomplete/Autocomplete.vue b/src/classes/filter-types/autocomplete/Autocomplete.vue index c2807a997..2f17a2df4 100644 --- a/src/classes/filter-types/autocomplete/Autocomplete.vue +++ b/src/classes/filter-types/autocomplete/Autocomplete.vue @@ -121,7 +121,7 @@ promise.request.catch( error => { if (isCancel(error)) - this.$console.log('Request canceled: ', error.message); + this.$console.log('Request canceled: ' + error.message); else this.$console.error( error ); }); diff --git a/src/classes/filter-types/checkbox/Checkbox.vue b/src/classes/filter-types/checkbox/Checkbox.vue index be3a7828c..be40b103c 100644 --- a/src/classes/filter-types/checkbox/Checkbox.vue +++ b/src/classes/filter-types/checkbox/Checkbox.vue @@ -137,10 +137,10 @@ .then(() => { this.selectedValues(); }) - .catch( error => { - if (isCancel(error)) - this.$console.log('Request canceled: ', error.message); - else + .catch( (error) => { + if (isCancel(error)) { + this.$console.log('Request canceled: ' + error.message); + }else this.$console.error( error ); }); } diff --git a/src/classes/filter-types/selectbox/Selectbox.vue b/src/classes/filter-types/selectbox/Selectbox.vue index ef379421e..e8cd648ef 100644 --- a/src/classes/filter-types/selectbox/Selectbox.vue +++ b/src/classes/filter-types/selectbox/Selectbox.vue @@ -112,7 +112,7 @@ }) .catch( error => { if (isCancel(error)) - this.$console.log('Request canceled: ', error.message); + this.$console.log('Request canceled: ' + error.message); else this.$console.error( error ); }); diff --git a/src/classes/filter-types/taginput/Taginput.vue b/src/classes/filter-types/taginput/Taginput.vue index 59915a076..c48f6d3c7 100644 --- a/src/classes/filter-types/taginput/Taginput.vue +++ b/src/classes/filter-types/taginput/Taginput.vue @@ -137,7 +137,7 @@ promise.request .catch( error => { if (isCancel(error)) - this.$console.log('Request canceled: ', error.message); + this.$console.log('Request canceled: ' + error.message); else this.$console.error( error ); }); diff --git a/src/classes/filter-types/taxonomy/Checkbox.vue b/src/classes/filter-types/taxonomy/Checkbox.vue index 37ca44c8a..490b4239a 100644 --- a/src/classes/filter-types/taxonomy/Checkbox.vue +++ b/src/classes/filter-types/taxonomy/Checkbox.vue @@ -157,7 +157,7 @@ }) .catch( error => { if (isCancel(error)) { - this.$console.log('Request canceled: ', error.message); + this.$console.log('Request canceled: ' + error.message); } else { this.$console.log('Error on facets request: ', error); this.isLoading = false; diff --git a/src/classes/metadata-types/relationship/FormRelationship.vue b/src/classes/metadata-types/relationship/FormRelationship.vue index aa83f552c..5f3be581c 100644 --- a/src/classes/metadata-types/relationship/FormRelationship.vue +++ b/src/classes/metadata-types/relationship/FormRelationship.vue @@ -167,7 +167,7 @@ this.$console.log(error); }); }, - fetchMetadataFromCollection( value ){ + fetchMetadataFromCollection(value) { this.loadingMetadata = true; this.hasMetadata = false; diff --git a/src/js/store/modules/collection/actions.js b/src/js/store/modules/collection/actions.js index 801503439..8d9c76a22 100644 --- a/src/js/store/modules/collection/actions.js +++ b/src/js/store/modules/collection/actions.js @@ -107,9 +107,9 @@ export const fetchItems = ({ rootGetters, dispatch, commit }, { collectionId, is .catch((thrown) => { if (axios.isCancel(thrown)) { console.log('Request canceled: ', thrown.message); - } else { + } else { reject(thrown); - } + } }); }), source: source diff --git a/src/js/store/modules/filter/actions.js b/src/js/store/modules/filter/actions.js index 0efcf17f0..43cb61836 100644 --- a/src/js/store/modules/filter/actions.js +++ b/src/js/store/modules/filter/actions.js @@ -3,39 +3,48 @@ import qs from 'qs'; // FILTERS -------------------------------------------------------- export const fetchFilters = ({ commit }, { collectionId, isRepositoryLevel, isContextEdit, includeDisabled, customFilters }) => { - return new Promise((resolve, reject) => { + + const source = axios.CancelToken.source(); - let endpoint = ''; - if (!isRepositoryLevel) - endpoint = '/collection/' + collectionId + '/filters/'; - else - endpoint = '/filters/'; + return new Object({ + request: new Promise((resolve, reject) => { + + let endpoint = ''; + if (!isRepositoryLevel) + endpoint = '/collection/' + collectionId + '/filters/'; + else + endpoint = '/filters/'; - endpoint += '?nopaging=1'; + endpoint += '?nopaging=1'; - if (isContextEdit) { - endpoint += '&context=edit'; - } + if (isContextEdit) { + endpoint += '&context=edit'; + } - if (includeDisabled){ - endpoint += '&include_disabled=' + includeDisabled; - } + if (includeDisabled){ + endpoint += '&include_disabled=' + includeDisabled; + } - if (customFilters != undefined && customFilters.length > 0) { - let postin = { 'postin': customFilters }; - endpoint += '&' + qs.stringify(postin); - } + if (customFilters != undefined && customFilters.length > 0) { + let postin = { 'postin': customFilters }; + endpoint += '&' + qs.stringify(postin); + } - axios.tainacan.get(endpoint) - .then((res) => { - let filters= res.data; - commit('setFilters', filters); - resolve (filters); - }) - .catch((error) => { - console.log(error); - reject(error); - }); + axios.tainacan.get(endpoint, { cancelToken: source.token }) + .then((res) => { + let filters= res.data; + commit('setFilters', filters); + resolve (filters); + }) + .catch((error) => { + if (axios.isCancel(error)) { + console.log('Request canceled: ', error.message); + } else { + reject(error); + } + }); + }), + source: source }); }; diff --git a/src/js/store/modules/metadata/actions.js b/src/js/store/modules/metadata/actions.js index ae0e1f2c0..94def16a3 100644 --- a/src/js/store/modules/metadata/actions.js +++ b/src/js/store/modules/metadata/actions.js @@ -2,31 +2,40 @@ import axios from '../../../axios/axios'; export const fetchMetadata = ({commit}, {collectionId, isRepositoryLevel, isContextEdit, includeDisabled, isAdvancedSearch}) => { - return new Promise((resolve, reject) => { - let endpoint = ''; - if (!isRepositoryLevel) - endpoint = '/collection/' + collectionId + '/metadata/'; - else - endpoint = '/metadata/'; + const source = axios.CancelToken.source(); - endpoint += '?nopaging=1'; - - if (isContextEdit) - endpoint += '&context=edit'; + return new Object({ + request: new Promise((resolve, reject) => { + let endpoint = ''; + if (!isRepositoryLevel) + endpoint = '/collection/' + collectionId + '/metadata/'; + else + endpoint = '/metadata/'; - if (includeDisabled) - endpoint += '&include_disabled=' + includeDisabled; + endpoint += '?nopaging=1'; + + if (isContextEdit) + endpoint += '&context=edit'; - axios.tainacan.get(endpoint) - .then((res) => { - let metadata = res.data; - if (!isAdvancedSearch) - commit('setMetadata', metadata); - resolve(metadata); - }) - .catch((error) => { - reject(error); - }); + if (includeDisabled) + endpoint += '&include_disabled=' + includeDisabled; + + axios.tainacan.get(endpoint, { cancelToken: source.token }) + .then((res) => { + let metadata = res.data; + if (!isAdvancedSearch) + commit('setMetadata', metadata); + resolve(metadata); + }) + .catch((error) => { + if (axios.isCancel(error)) { + console.log('Request canceled: ', error.message); + } else { + reject(error); + } + }); + }), + source: source }); };