SEVERAL metadata request cancels on component destroy. #296

This commit is contained in:
Mateus Machado Luna 2019-09-03 14:51:52 -03:00
parent 77a48d126a
commit fa0fb4857b
17 changed files with 741 additions and 526 deletions

View File

@ -232,22 +232,36 @@
} }
}, },
mounted(){ mounted(){
this.$root.$on('metadatumUpdated', (isRepositoryLevel) => { this.$root.$on('metadatumUpdated', (isRepositoryLevel) => {
if(isRepositoryLevel) {
this.metadataIsLoading = true;
this.fetchMetadata({ if (isRepositoryLevel) {
collectionId: this.isRepositoryLevel ? false : this.collectionId, this.metadataIsLoading = true;
isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: false, // Cancels previous Request
includeDisabled: false, if (this.metadataSearchCancel != undefined)
isAdvancedSearch: true this.metadataSearchCancel.cancel('Metadata search Canceled.');
}).then((metadata) => {
this.metadata = metadata; this.fetchMetadata({
this.metadataIsLoading = false; 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(){ created(){
@ -259,10 +273,19 @@
isContextEdit: false, isContextEdit: false,
includeDisabled: false, includeDisabled: false,
isAdvancedSearch: true isAdvancedSearch: true
}).then((metadata) => { }).then((resp) => {
this.metadata = metadata; resp.request
this.metadataIsLoading = false; .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) || 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) ){ (this.$route.query.taxquery && Object.keys(this.$route.query.taxquery).length > 0) ){
@ -343,6 +366,7 @@
}, },
metadataIsLoading: false, metadataIsLoading: false,
metadata: [], metadata: [],
metadataSearchCancel: undefined
} }
}, },
methods: { methods: {
@ -557,6 +581,11 @@
}, },
beforeDestroy() { beforeDestroy() {
this.$root.$off('metadatumUpdated'); this.$root.$off('metadatumUpdated');
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
} }
} }
</script> </script>

View File

@ -320,20 +320,30 @@
collectionID: Number, collectionID: Number,
}, },
created(){ created(){
if(!this.collectionID){ if (this.collectionID){
// is repository level
} else {
this.metadataIsLoading = true; this.metadataIsLoading = true;
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
this.fetchMetadata({ this.fetchMetadata({
collectionId: this.collectionID, collectionId: this.collectionID,
isRepositoryLevel: false, isRepositoryLevel: false,
isContextEdit: true, isContextEdit: true,
includeDisabled: false, includeDisabled: false
}).then(() => { }).then((resp) => {
this.metadataIsLoading = false; 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({ this.createEditGroup({
@ -378,6 +388,7 @@
groupID: null, groupID: null,
dones: [false], dones: [false],
metadataIsLoading: false, metadataIsLoading: false,
metadataSearchCancel: undefined
} }
}, },
methods: { methods: {
@ -552,6 +563,12 @@
} }
} }
}, },
beforeDestroy() {
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
}
} }
</script> </script>

View File

@ -598,9 +598,6 @@ export default {
'fetchUsers', 'fetchUsers',
'fetchCollectionsForParent' 'fetchCollectionsForParent'
]), ]),
...mapActions('metadata', [
'fetchMetadata'
]),
updateSlug: _.debounce(function() { updateSlug: _.debounce(function() {
if(!this.form.name || this.form.name.length <= 0){ if(!this.form.name || this.form.name.length <= 0){
return; return;
@ -957,7 +954,7 @@ export default {
@import "../../scss/_variables.scss"; @import "../../scss/_variables.scss";
@media screen and (max-width: 1024px) { @media screen and (min-width: 1024px) {
.column:last-of-type { .column:last-of-type {
padding-left: $page-side-padding !important; padding-left: $page-side-padding !important;
} }

View File

@ -207,7 +207,8 @@ export default {
isEditingMetadatum: false, isEditingMetadatum: false,
metadatum: {}, metadatum: {},
editedMetadatum: {}, editedMetadatum: {},
backgroundProcess: undefined backgroundProcess: undefined,
metadataSearchCancel: undefined
} }
}, },
components: { components: {
@ -275,22 +276,37 @@ export default {
loadMetadata() { loadMetadata() {
// Generates options for metadata listing // Generates options for metadata listing
this.isFetchingCollectionMetadata = true; 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 }) // Cancels previous Request
.then(res => { if (this.metadataSearchCancel != undefined)
if( res ) { this.metadataSearchCancel.cancel('Metadata search Canceled.');
this.mappedCollection['mapping'] = res;
} this.fetchMetadata({
}) collectionId: this.collectionId,
}) isRepositoryLevel: false,
.catch((error) => { isContextEdit: false
this.$console.error(error); }).then((resp) => {
this.isFetchingCollectionMetadata = false; 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(){ cancelBack(){
this.$router.go(-2); this.$router.go(-2);
@ -433,6 +449,11 @@ export default {
this.loadImporter(); this.loadImporter();
this.loadMetadata(); this.loadMetadata();
},
beforeDestroy() {
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
} }
} }

View File

@ -334,7 +334,9 @@ export default {
availableMetadata: [], availableMetadata: [],
filterTypes: [], filterTypes: [],
currentFilterTypePreview: undefined, currentFilterTypePreview: undefined,
columnsTopY: 0 columnsTopY: 0,
filtersSearchCancel: undefined,
metadataSearchCancel: undefined
} }
}, },
computed: { computed: {
@ -609,7 +611,7 @@ export default {
return 190; return 190;
} }
}, },
mounted() { mounted() {
if (!this.isRepositoryLevel) if (!this.isRepositoryLevel)
this.$root.$emit('onCollectionBreadCrumbUpdate', [{ path: '', label: this.$i18n.get('filter') }]); this.$root.$emit('onCollectionBreadCrumbUpdate', [{ path: '', label: this.$i18n.get('filter') }]);
@ -624,7 +626,6 @@ export default {
else else
this.collectionId = this.$route.params.collectionId; this.collectionId = this.$route.params.collectionId;
this.isLoadingMetadatumTypes = true;
this.isLoadingFilters = true; this.isLoadingFilters = true;
this.isLoadingFilterTypes = true; this.isLoadingFilterTypes = true;
@ -637,24 +638,57 @@ export default {
this.isLoadingFilterTypes = false; this.isLoadingFilterTypes = false;
}); });
this.fetchFilters({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: true }) // Cancels previous Request
.then(() => { if (this.filtersSearchCancel != undefined)
this.isLoadingFilters = false; this.filtersSearchCancel.cancel('Filters 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 }) this.fetchFilters({
.then(() => { collectionId: this.collectionId,
this.isLoadingMetadatumTypes = false; isRepositoryLevel: this.isRepositoryLevel,
this.updateListOfMetadata(); isContextEdit: !this.isOnTheme,
}) includeDisabled: true,
.catch(() => { }).then((resp) => {
this.isLoadingMetadatumTypes = false; resp.request
}); .then(() => {
})
.catch(() => { this.isLoadingMetadatumTypes = true;
this.isLoadingFilters = false;
}); // 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 // Obtains collection name
if (!this.isRepositoryLevel) { if (!this.isRepositoryLevel) {
this.fetchCollectionName(this.collectionId).then((collectionName) => { this.fetchCollectionName(this.collectionId).then((collectionName) => {
@ -666,6 +700,15 @@ export default {
this.onCancelFilterTypeSelection(); 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.');
} }
} }
</script> </script>

View File

@ -461,7 +461,8 @@ export default {
new_metadata_label: '', new_metadata_label: '',
new_metadata_uri: '', new_metadata_uri: '',
new_metadata_slug: '', new_metadata_slug: '',
columnsTopY: 0 columnsTopY: 0,
metadataSearchCancel: undefined
} }
}, },
components: { components: {
@ -618,8 +619,11 @@ export default {
.then(() => { .then(() => {
if (!this.isRepositoryLevel) if (!this.isRepositoryLevel)
this.updateMetadataOrder(); this.updateMetadataOrder();
else
this.$root.$emit('metadatumUpdated', this.isRepositoryLevel);
}) })
.catch(() => { .catch(() => {
this.$console.log("Error deleting metadatum.")
}); });
}, },
} }
@ -846,26 +850,43 @@ export default {
return true; return true;
}, },
refreshMetadata() { refreshMetadata() {
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
this.isRepositoryLevel = this.$route.name == 'MetadataPage' ? true : false; this.isRepositoryLevel = this.$route.name == 'MetadataPage' ? true : false;
if (this.isRepositoryLevel) if (this.isRepositoryLevel)
this.collectionId = 'default'; this.collectionId = 'default';
else else
this.collectionId = this.$route.params.collectionId; this.collectionId = this.$route.params.collectionId;
this.fetchMetadata({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true, includeDisabled: true}) this.fetchMetadata({
.then(() => { collectionId: this.collectionId,
this.isLoadingMetadata = false; isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: true,
// Checks URL as router watcher would not wait for list to load includeDisabled: true
if (this.$route.query.edit != undefined) { }).then((resp) => {
let existingMetadataIndex = this.activeMetadatumList.findIndex((metadatum) => metadatum.id == this.$route.query.edit); resp.request
if (existingMetadataIndex >= 0) .then(() => {
this.editMetadatum(this.activeMetadatumList[existingMetadataIndex]); 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(() => { .catch(() => this.isLoadingMetadata = false);
this.isLoadingMetadata = false;
});
}, },
getPreviewTemplateContent(metadatum) { getPreviewTemplateContent(metadatum) {
return `<div class="metadata-type-preview tainacan-form"> return `<div class="metadata-type-preview tainacan-form">
@ -919,6 +940,13 @@ export default {
this.collectionName = collectionName; this.collectionName = collectionName;
}); });
} }
},
beforeDestroy() {
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
} }
} }
</script> </script>

View File

@ -915,7 +915,9 @@
isFilterModalActive: false, isFilterModalActive: false,
collection: undefined, collection: undefined,
hasAnOpenModal: false, hasAnOpenModal: false,
hasAnOpenAlert: true hasAnOpenAlert: true,
filtersSearchCancel: undefined,
metadataSearchCancel: undefined
} }
}, },
props: { props: {
@ -1189,6 +1191,10 @@
}, },
prepareFilters() { prepareFilters() {
// Cancels previous Request
if (this.filtersSearchCancel != undefined)
this.filtersSearchCancel.cancel('Filters search Canceled.');
this.isLoadingFilters = true; this.isLoadingFilters = true;
this.fetchFilters({ this.fetchFilters({
@ -1197,7 +1203,14 @@
isContextEdit: !this.isOnTheme, isContextEdit: !this.isOnTheme,
includeDisabled: 'no', 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); .catch(() => this.isLoadingFilters = false);
// On repository level we also fetch collection filters // On repository level we also fetch collection filters
@ -1209,6 +1222,10 @@
}, },
prepareMetadata() { prepareMetadata() {
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
this.$eventBusSearch.cleanFetchOnly(); this.$eventBusSearch.cleanFetchOnly();
this.isLoadingMetadata = true; this.isLoadingMetadata = true;
@ -1219,212 +1236,219 @@
isRepositoryLevel: this.isRepositoryLevel, isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: false isContextEdit: false
}) })
.then(() => { .then((resp) => {
this.sortingMetadata = []; resp.request
.then(() => {
this.sortingMetadata = [];
// Decides if custom meta will be loaded with item. // Decides if custom meta will be loaded with item.
let shouldLoadMeta = true; let shouldLoadMeta = true;
if (this.isOnTheme) if (this.isOnTheme)
shouldLoadMeta = this.registeredViewModes[this.viewMode].dynamic_metadata; shouldLoadMeta = this.registeredViewModes[this.viewMode].dynamic_metadata;
else else
shouldLoadMeta = this.adminViewMode == 'table' || this.adminViewMode == 'records' || this.adminViewMode == undefined; shouldLoadMeta = this.adminViewMode == 'table' || this.adminViewMode == 'records' || this.adminViewMode == undefined;
if (shouldLoadMeta) { if (shouldLoadMeta) {
// Loads user prefs object as we'll need to check if there's something configured by user // 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 prefsFetchOnly = !this.isRepositoryLevel ? `fetch_only_${this.collectionId}` : 'fetch_only';
let prefsFetchOnlyMeta = !this.isRepositoryLevel ? `fetch_only_meta_${this.collectionId}` : 'fetch_only_meta'; 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 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 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({ metadata.push({
name: metadatum.name, name: this.$i18n.get('label_thumbnail'),
metadatum: metadatum.description, metadatum: 'row_thumbnail',
slug: metadatum.slug, metadata_type: undefined,
metadata_type: metadatum.metadata_type, slug: 'thumbnail',
metadata_type_object: metadatum.metadata_type_object, id: undefined,
metadata_type_options: metadatum.metadata_type_options, display: thumbnailMetadatumDisplay
id: metadatum.id,
display: display,
collection_id: metadatum.collection_id,
multiple: metadatum.multiple,
}); });
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 ( this.$eventBusSearch.addFetchOnly(
metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' && (thumbnailMetadatumDisplay ? 'thumbnail' : null) +','+
metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' && (creationDateMetadatumDisplay ? 'creation_date' : null) +','+
metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship' (authorNameMetadatumDisplay ? 'author_name' : null) +','+
) { (this.isRepositoryLevel ? 'title' : null) +','+
this.sortingMetadata.push(metadatum); (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; // Loads only basic attributes necessary to view modes that do not allow custom meta
let authorNameMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[2] != null) : true; } else {
// 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( this.$eventBusSearch.addFetchOnly('thumbnail,creation_date,author_name,title,description', true, '');
(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) {
if (this.isRepositoryLevel) { this.sortingMetadata.push({
this.sortingMetadata.push({ name: this.$i18n.get('label_title'),
name: this.$i18n.get('label_title'), metadatum: 'row_title',
metadatum: 'row_title', metadata_type_object: {core: true, related_mapped_prop: 'title'},
metadata_type_object: {core: true, related_mapped_prop: 'title'}, metadata_type: undefined,
metadata_type: undefined, slug: 'title',
slug: 'title', id: undefined,
id: undefined, display: true
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 for (let metadatum of this.metadata) {
} else { if (metadatum.display !== 'never' &&
metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' &&
this.$eventBusSearch.addFetchOnly('thumbnail,creation_date,author_name,title,description', true, ''); metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' &&
metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship') {
this.sortingMetadata.push(metadatum);
}
}
if (this.isRepositoryLevel) { this.sortingMetadata.push({
this.sortingMetadata.push({ name: this.$i18n.get('label_creation_date'),
name: this.$i18n.get('label_title'), metadatum: 'row_creation',
metadatum: 'row_title', metadata_type: undefined,
metadata_type_object: {core: true, related_mapped_prop: 'title'}, slug: 'creation_date',
metadata_type: undefined, id: undefined,
slug: 'title', display: true
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({ this.isLoadingMetadata = false;
name: this.$i18n.get('label_creation_date'), this.displayedMetadata = metadata;
metadatum: 'row_creation', })
metadata_type: undefined, .catch(() => {
slug: 'creation_date', this.isLoadingMetadata = false;
id: undefined,
display: true
}) })
} // Search Request Token for cancelling
this.metadataSearchCancel = resp.source;
this.isLoadingMetadata = false;
this.displayedMetadata = metadata;
}) })
.catch(() => { .catch(() => this.isLoadingMetadata = false);
this.isLoadingMetadata = false;
});
}, },
updateCollectionInfo () { updateCollectionInfo () {
if (this.collectionId) { if (this.collectionId) {
@ -1579,8 +1603,16 @@
}, },
beforeDestroy() { beforeDestroy() {
this.removeEventListeners(); 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) if (this.$eventBusSearch.searchCancel != undefined)
this.$eventBusSearch.searchCancel.cancel('Item search Canceled.'); this.$eventBusSearch.searchCancel.cancel('Item search Canceled.');

View File

@ -890,7 +890,9 @@
isFilterModalActive: false, isFilterModalActive: false,
customFilters: [], customFilters: [],
hasAnOpenModal: false, hasAnOpenModal: false,
hasAnOpenAlert: true hasAnOpenAlert: true,
filtersSearchCancel: undefined,
metadataSearchCancel: undefined
} }
}, },
props: { props: {
@ -1133,6 +1135,10 @@
}, },
prepareFilters() { prepareFilters() {
// Cancels previous Request
if (this.filtersSearchCancel != undefined)
this.filtersSearchCancel.cancel('Filters search Canceled.');
this.isLoadingFilters = true; this.isLoadingFilters = true;
// Normal filter loading, only collection ones // Normal filter loading, only collection ones
@ -1143,7 +1149,14 @@
isContextEdit: !this.isOnTheme, isContextEdit: !this.isOnTheme,
includeDisabled: 'no', 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); .catch(() => this.isLoadingFilters = false);
// Custom filter loading, get's from collections that have items with that taxonomy // Custom filter loading, get's from collections that have items with that taxonomy
@ -1155,6 +1168,10 @@
} }
}, },
prepareMetadata() { prepareMetadata() {
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
this.$eventBusSearch.cleanFetchOnly(); this.$eventBusSearch.cleanFetchOnly();
this.isLoadingMetadata = true; this.isLoadingMetadata = true;
@ -1165,213 +1182,218 @@
collectionId: this.collectionId, collectionId: this.collectionId,
isRepositoryLevel: this.isRepositoryLevel, isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: false isContextEdit: false
}) }).then((resp) => {
.then(() => { resp.request
this.sortingMetadata = []; .then(() => {
this.sortingMetadata = [];
// Decides if custom meta will be loaded with item. // Decides if custom meta will be loaded with item.
let shouldLoadMeta = true; let shouldLoadMeta = true;
if (this.isOnTheme) if (this.isOnTheme)
shouldLoadMeta = this.registeredViewModes[this.viewMode].dynamic_metadata; shouldLoadMeta = this.registeredViewModes[this.viewMode].dynamic_metadata;
else else
shouldLoadMeta = this.adminViewMode == 'table' || this.adminViewMode == 'records' || this.adminViewMode == undefined; shouldLoadMeta = this.adminViewMode == 'table' || this.adminViewMode == 'records' || this.adminViewMode == undefined;
if (shouldLoadMeta) { if (shouldLoadMeta) {
// Loads user prefs object as we'll need to check if there's something configured by user // 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 prefsFetchOnly = !this.isRepositoryLevel ? `fetch_only_${this.collectionId}` : 'fetch_only';
let prefsFetchOnlyMeta = !this.isRepositoryLevel ? `fetch_only_meta_${this.collectionId}` : 'fetch_only_meta'; 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 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 prefsFetchOnlyMetaObject = this.$userPrefs.get(prefsFetchOnlyMeta) ? this.$userPrefs.get(prefsFetchOnlyMeta).split(',') : [];
let thumbnailMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[0] != null) : true; 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;
}
metadata.push({ metadata.push({
name: metadatum.name, name: this.$i18n.get('label_thumbnail'),
metadatum: metadatum.description, metadatum: 'row_thumbnail',
slug: metadatum.slug, metadata_type: undefined,
metadata_type: metadatum.metadata_type, slug: 'thumbnail',
metadata_type_object: metadatum.metadata_type_object, id: undefined,
metadata_type_options: metadatum.metadata_type_options, display: thumbnailMetadatumDisplay
id: metadatum.id,
display: display,
collection_id: metadatum.collection_id,
multiple: metadatum.multiple,
}); });
if (display) { // Repository Level always shows core metadata
fetchOnlyMetadatumIds.push(metadatum.id); 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 ( let fetchOnlyMetadatumIds = [];
metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' &&
metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' && for (let metadatum of this.metadata) {
metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship' if (metadatum.display !== 'never') {
) {
this.sortingMetadata.push(metadatum); 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; // Sorting metadata
let authorNameMetadatumDisplay = prefsFetchOnlyObject ? (prefsFetchOnlyObject[2] != null) : true; if (this.isRepositoryLevel) {
this.sortingMetadata.push({
// Creation date and author name should appear only on admin. name: this.$i18n.get('label_title'),
if (!this.isOnTheme) { metadatum: 'row_title',
metadata_type_object: {core: true, related_mapped_prop: 'title'},
metadata.push({ metadata_type: undefined,
name: this.$i18n.get('label_creation_date'), slug: 'title',
metadatum: 'row_creation', id: undefined,
metadata_type: undefined, display: true
slug: 'creation_date', });
id: undefined, }
display: creationDateMetadatumDisplay this.sortingMetadata.push({
}); name: this.$i18n.get('label_creation_date'),
metadata.push({ metadatum: 'row_creation',
name: this.$i18n.get('label_created_by'), metadata_type: undefined,
metadatum: 'row_author', slug: 'creation_date',
metadata_type: undefined, id: undefined,
slug: 'author_name', display: creationDateMetadatumDisplay
id: undefined, });
display: authorNameMetadatumDisplay if (authorNameMetadatumDisplay) {
}); this.sortingMetadata.push({
} name: this.$i18n.get('label_created_by'),
metadatum: 'row_author',
this.$eventBusSearch.addFetchOnly( metadata_type: undefined,
(thumbnailMetadatumDisplay ? 'thumbnail' : null) +','+ slug: 'author_name',
(creationDateMetadatumDisplay ? 'creation_date' : null) +','+ id: undefined,
(authorNameMetadatumDisplay ? 'author_name' : null) +','+ display: authorNameMetadatumDisplay
(this.isRepositoryLevel ? 'title' : null) +','+ });
(this.isRepositoryLevel ? 'description' : null) }
, false, fetchOnlyMetadatumIds.toString()); // Loads only basic attributes necessary to view modes that do not allow custom meta
} else {
// 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, '');
if (this.isRepositoryLevel) { this.$eventBusSearch.addFetchOnly('thumbnail,creation_date,author_name,title,description', true, '');
this.sortingMetadata.push({
name: this.$i18n.get('label_title'), if (this.isRepositoryLevel) {
metadatum: 'row_title', this.sortingMetadata.push({
metadata_type_object: {core: true, related_mapped_prop: 'title'}, name: this.$i18n.get('label_title'),
metadata_type: undefined, metadatum: 'row_title',
slug: 'title', metadata_type_object: {core: true, related_mapped_prop: 'title'},
id: undefined, metadata_type: undefined,
display: true slug: 'title',
}); id: undefined,
} display: true
});
for (let metadatum of this.metadata) { }
if (metadatum.display !== 'never' &&
metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' && for (let metadatum of this.metadata) {
metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Taxonomy' && if (metadatum.display !== 'never' &&
metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Relationship') { metadatum.metadata_type != 'Tainacan\\Metadata_Types\\Core_Description' &&
this.sortingMetadata.push(metadatum); 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({ this.isLoadingMetadata = false;
name: this.$i18n.get('label_creation_date'), this.displayedMetadata = metadata;
metadatum: 'row_creation',
metadata_type: undefined,
slug: 'creation_date',
id: undefined,
display: true
}) })
.catch(() => {
} this.isLoadingMetadata = false;
})
this.isLoadingMetadata = false; // Search Request Token for cancelling
this.displayedMetadata = metadata; this.metadataSearchCancel = resp.source;
}) })
.catch(() => { .catch(() => this.isLoadingMetadata = false);
this.isLoadingMetadata = false;
});
}, },
showItemsHiddingDueSortingDialog() { showItemsHiddingDueSortingDialog() {
@ -1521,8 +1543,16 @@
}, },
beforeDestroy() { beforeDestroy() {
this.removeEventListeners(); 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) if (this.$eventBusSearch.searchCancel != undefined)
this.$eventBusSearch.searchCancel.cancel('Item search Canceled.'); this.$eventBusSearch.searchCancel.cancel('Item search Canceled.');

View File

@ -121,7 +121,7 @@
promise.request.catch( error => { promise.request.catch( error => {
if (isCancel(error)) if (isCancel(error))
this.$console.log('Request canceled: ', error.message); this.$console.log('Request canceled: ' + error.message);
else else
this.$console.error( error ); this.$console.error( error );
}); });

View File

@ -137,10 +137,10 @@
.then(() => { .then(() => {
this.selectedValues(); this.selectedValues();
}) })
.catch( error => { .catch( (error) => {
if (isCancel(error)) if (isCancel(error)) {
this.$console.log('Request canceled: ', error.message); this.$console.log('Request canceled: ' + error.message);
else }else
this.$console.error( error ); this.$console.error( error );
}); });
} }

View File

@ -112,7 +112,7 @@
}) })
.catch( error => { .catch( error => {
if (isCancel(error)) if (isCancel(error))
this.$console.log('Request canceled: ', error.message); this.$console.log('Request canceled: ' + error.message);
else else
this.$console.error( error ); this.$console.error( error );
}); });

View File

@ -137,7 +137,7 @@
promise.request promise.request
.catch( error => { .catch( error => {
if (isCancel(error)) if (isCancel(error))
this.$console.log('Request canceled: ', error.message); this.$console.log('Request canceled: ' + error.message);
else else
this.$console.error( error ); this.$console.error( error );
}); });

View File

@ -157,7 +157,7 @@
}) })
.catch( error => { .catch( error => {
if (isCancel(error)) { if (isCancel(error)) {
this.$console.log('Request canceled: ', error.message); this.$console.log('Request canceled: ' + error.message);
} else { } else {
this.$console.log('Error on facets request: ', error); this.$console.log('Error on facets request: ', error);
this.isLoading = false; this.isLoading = false;

View File

@ -167,7 +167,7 @@
this.$console.log(error); this.$console.log(error);
}); });
}, },
fetchMetadataFromCollection( value ){ fetchMetadataFromCollection(value) {
this.loadingMetadata = true; this.loadingMetadata = true;
this.hasMetadata = false; this.hasMetadata = false;

View File

@ -107,9 +107,9 @@ export const fetchItems = ({ rootGetters, dispatch, commit }, { collectionId, is
.catch((thrown) => { .catch((thrown) => {
if (axios.isCancel(thrown)) { if (axios.isCancel(thrown)) {
console.log('Request canceled: ', thrown.message); console.log('Request canceled: ', thrown.message);
} else { } else {
reject(thrown); reject(thrown);
} }
}); });
}), }),
source: source source: source

View File

@ -3,39 +3,48 @@ import qs from 'qs';
// FILTERS -------------------------------------------------------- // FILTERS --------------------------------------------------------
export const fetchFilters = ({ commit }, { collectionId, isRepositoryLevel, isContextEdit, includeDisabled, customFilters }) => { export const fetchFilters = ({ commit }, { collectionId, isRepositoryLevel, isContextEdit, includeDisabled, customFilters }) => {
return new Promise((resolve, reject) => {
const source = axios.CancelToken.source();
let endpoint = ''; return new Object({
if (!isRepositoryLevel) request: new Promise((resolve, reject) => {
endpoint = '/collection/' + collectionId + '/filters/';
else let endpoint = '';
endpoint = '/filters/'; if (!isRepositoryLevel)
endpoint = '/collection/' + collectionId + '/filters/';
else
endpoint = '/filters/';
endpoint += '?nopaging=1'; endpoint += '?nopaging=1';
if (isContextEdit) { if (isContextEdit) {
endpoint += '&context=edit'; endpoint += '&context=edit';
} }
if (includeDisabled){ if (includeDisabled){
endpoint += '&include_disabled=' + includeDisabled; endpoint += '&include_disabled=' + includeDisabled;
} }
if (customFilters != undefined && customFilters.length > 0) { if (customFilters != undefined && customFilters.length > 0) {
let postin = { 'postin': customFilters }; let postin = { 'postin': customFilters };
endpoint += '&' + qs.stringify(postin); endpoint += '&' + qs.stringify(postin);
} }
axios.tainacan.get(endpoint) axios.tainacan.get(endpoint, { cancelToken: source.token })
.then((res) => { .then((res) => {
let filters= res.data; let filters= res.data;
commit('setFilters', filters); commit('setFilters', filters);
resolve (filters); resolve (filters);
}) })
.catch((error) => { .catch((error) => {
console.log(error); if (axios.isCancel(error)) {
reject(error); console.log('Request canceled: ', error.message);
}); } else {
reject(error);
}
});
}),
source: source
}); });
}; };

View File

@ -2,31 +2,40 @@ import axios from '../../../axios/axios';
export const fetchMetadata = ({commit}, {collectionId, isRepositoryLevel, isContextEdit, includeDisabled, isAdvancedSearch}) => { export const fetchMetadata = ({commit}, {collectionId, isRepositoryLevel, isContextEdit, includeDisabled, isAdvancedSearch}) => {
return new Promise((resolve, reject) => { const source = axios.CancelToken.source();
let endpoint = '';
if (!isRepositoryLevel)
endpoint = '/collection/' + collectionId + '/metadata/';
else
endpoint = '/metadata/';
endpoint += '?nopaging=1'; return new Object({
request: new Promise((resolve, reject) => {
if (isContextEdit) let endpoint = '';
endpoint += '&context=edit'; if (!isRepositoryLevel)
endpoint = '/collection/' + collectionId + '/metadata/';
else
endpoint = '/metadata/';
if (includeDisabled) endpoint += '?nopaging=1';
endpoint += '&include_disabled=' + includeDisabled;
if (isContextEdit)
endpoint += '&context=edit';
axios.tainacan.get(endpoint) if (includeDisabled)
.then((res) => { endpoint += '&include_disabled=' + includeDisabled;
let metadata = res.data;
if (!isAdvancedSearch) axios.tainacan.get(endpoint, { cancelToken: source.token })
commit('setMetadata', metadata); .then((res) => {
resolve(metadata); let metadata = res.data;
}) if (!isAdvancedSearch)
.catch((error) => { commit('setMetadata', metadata);
reject(error); resolve(metadata);
}); })
.catch((error) => {
if (axios.isCancel(error)) {
console.log('Request canceled: ', error.message);
} else {
reject(error);
}
});
}),
source: source
}); });
}; };