Uses mitt for emitting events in event buses and begins implementation of deep watchers for arrays.

This commit is contained in:
mateuswetah 2023-07-18 09:10:58 -03:00
parent d6b74c9964
commit 7362b4fad0
24 changed files with 343 additions and 278 deletions

5
package-lock.json generated
View File

@ -4926,6 +4926,11 @@
"yallist": "^4.0.0" "yallist": "^4.0.0"
} }
}, },
"mitt": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz",
"integrity": "sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw=="
},
"mkdirp": { "mkdirp": {
"version": "1.0.4", "version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",

View File

@ -8,6 +8,7 @@
"build-prod": "cross-env NODE_ENV=production webpack --config webpack.prod.js --progress --mode production" "build-prod": "cross-env NODE_ENV=production webpack --config webpack.prod.js --progress --mode production"
}, },
"dependencies": { "dependencies": {
"@vue/compat": "^3.3.4",
"apexcharts": "^3.40.0", "apexcharts": "^3.40.0",
"axios": "^1.4.0", "axios": "^1.4.0",
"blurhash": "^2.0.5", "blurhash": "^2.0.5",
@ -20,6 +21,7 @@
"leaflet": "^1.9.4", "leaflet": "^1.9.4",
"leaflet-active-area": "^1.2.1", "leaflet-active-area": "^1.2.1",
"masonry-layout": "^4.2.2", "masonry-layout": "^4.2.2",
"mitt": "^3.0.1",
"moment": "^2.29.4", "moment": "^2.29.4",
"node-sass": "^7.0.3", "node-sass": "^7.0.3",
"photoswipe": "^5.3.7", "photoswipe": "^5.3.7",
@ -28,7 +30,6 @@
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"swiper": "^8.4.5", "swiper": "^8.4.5",
"vue": "^3.3.4", "vue": "^3.3.4",
"@vue/compat": "^3.3.4",
"vue-apexcharts": "^1.6.2", "vue-apexcharts": "^1.6.2",
"vue-blurhash": "^0.1.4", "vue-blurhash": "^0.1.4",
"vue-countup-v2": "^4.0.0", "vue-countup-v2": "^4.0.0",

View File

@ -950,7 +950,7 @@ export default {
// Obtains current Sequence Group Info // Obtains current Sequence Group Info
this.fetchSequenceGroup({ collectionId: this.collectionId, groupId: this.sequenceId }); this.fetchSequenceGroup({ collectionId: this.collectionId, groupId: this.sequenceId });
}, },
tabs:{ tabs: {
handler() { handler() {
if (this.tabs.length >= 2) { if (this.tabs.length >= 2) {
if (typeof this.swiper.update == 'function') if (typeof this.swiper.update == 'function')
@ -976,7 +976,8 @@ export default {
} }
} }
}, },
immediate: true immediate: true,
deep: true
} }
}, },
created() { created() {
@ -1065,10 +1066,10 @@ export default {
}); });
// Sets feedback variables // Sets feedback variables
eventBusItemMetadata.$on('isUpdatingValue', (status) => { eventBusItemMetadata.$emitter.$on('isUpdatingValue', (status) => {
this.isUpdatingValues = status; this.isUpdatingValues = status;
}); });
eventBusItemMetadata.$on('hasErrorsOnForm', (hasErrors) => { eventBusItemMetadata.$emitter.$on('hasErrorsOnForm', (hasErrors) => {
if (hasErrors) if (hasErrors)
this.formErrorMessage = this.formErrorMessage ? this.formErrorMessage : this.$i18n.get('info_errors_in_form'); this.formErrorMessage = this.formErrorMessage ? this.formErrorMessage : this.$i18n.get('info_errors_in_form');
else else
@ -1077,10 +1078,10 @@ export default {
this.cleanLastUpdated(); this.cleanLastUpdated();
// Updates variables for metadata navigation from compound childs // Updates variables for metadata navigation from compound childs
eventBusItemMetadata.$on('isOnFirstMetadatumOfCompoundNavigation', (isOnFirstMetadatumOfCompoundNavigation) => { eventBusItemMetadata.$emitter.$on('isOnFirstMetadatumOfCompoundNavigation', (isOnFirstMetadatumOfCompoundNavigation) => {
this.isOnFirstMetadatumOfCompoundNavigation = isOnFirstMetadatumOfCompoundNavigation this.isOnFirstMetadatumOfCompoundNavigation = isOnFirstMetadatumOfCompoundNavigation
}); });
eventBusItemMetadata.$on('isOnLastMetadatumOfCompoundNavigation', (isOnLastMetadatumOfCompoundNavigation) => { eventBusItemMetadata.$emitter.$on('isOnLastMetadatumOfCompoundNavigation', (isOnLastMetadatumOfCompoundNavigation) => {
this.isOnLastMetadatumOfCompoundNavigation = isOnLastMetadatumOfCompoundNavigation this.isOnLastMetadatumOfCompoundNavigation = isOnLastMetadatumOfCompoundNavigation
}); });
@ -1093,10 +1094,10 @@ export default {
this.isMobileSubheaderOpen = true; this.isMobileSubheaderOpen = true;
}, },
beforeUnmount () { beforeUnmount () {
eventBusItemMetadata.$off('isUpdatingValue'); eventBusItemMetadata.$emitter.$off('isUpdatingValue');
eventBusItemMetadata.$off('hasErrorsOnForm'); eventBusItemMetadata.$emitter.$off('hasErrorsOnForm');
eventBusItemMetadata.$off('isOnFirstMetadatumOfCompoundNavigation'); eventBusItemMetadata.$emitter.$off('isOnFirstMetadatumOfCompoundNavigation');
eventBusItemMetadata.$off('isOnLastMetadatumOfCompoundNavigation'); eventBusItemMetadata.$emitter.$off('isOnLastMetadatumOfCompoundNavigation');
window.removeEventListener('resize', this.handleWindowResize); window.removeEventListener('resize', this.handleWindowResize);
if (typeof this.swiper.destroy == 'function') if (typeof this.swiper.destroy == 'function')
this.swiper.destroy(); this.swiper.destroy();

View File

@ -206,13 +206,13 @@ export default {
'onDiscard', 'onDiscard',
], ],
mounted() { mounted() {
this.$parent.$on('toggleItemEditionFooterDropdown', () => { this.$parent.$emitter.$on('toggleItemEditionFooterDropdown', () => {
if (this.$refs && this.$refs['item-edition-footer-dropdown']) if (this.$refs && this.$refs['item-edition-footer-dropdown'])
this.$refs['item-edition-footer-dropdown'].toggle(); this.$refs['item-edition-footer-dropdown'].toggle();
}); });
}, },
beforeUnmount() { beforeUnmount() {
this.$parent.$off('toggleItemEditionFooterDropdown'); this.$parent.$emitter.$off('toggleItemEditionFooterDropdown');
}, },
methods: { methods: {
openItemCreationStatusDialog() { openItemCreationStatusDialog() {

View File

@ -83,19 +83,23 @@
} }
}, },
watch: { watch: {
selected(newVal, oldVal) { selected: {
handler(newVal, oldVal) {
const isEqual = (Array.isArray(newVal) && Array.isArray(oldVal) && (newVal.length == oldVal.length)) && newVal.every((element, index) => { const isEqual = (Array.isArray(newVal) && Array.isArray(oldVal) && (newVal.length == oldVal.length)) && newVal.every((element, index) => {
return element === oldVal[index]; return element === oldVal[index];
}); });
if (!isEqual) if (!isEqual)
this.onSelect(); this.onSelect();
}, },
deep: true
},
facetsFromItemSearch: { facetsFromItemSearch: {
handler() { handler() {
if (this.isUsingElasticSearch) if (this.isUsingElasticSearch)
this.loadOptions(); this.loadOptions();
}, },
immediate: true immediate: true,
deep: true
}, },
}, },
mounted() { mounted() {
@ -103,10 +107,10 @@
this.loadOptions(); this.loadOptions();
}, },
created() { created() {
this.$eventBusSearch.$on('hasToReloadFacets', this.reloadOptions); this.$eventBusSearch.$emitter.$on('hasToReloadFacets', this.reloadOptions);
}, },
beforeUnmount() { beforeUnmount() {
this.$eventBusSearch.$off('hasToReloadFacets', this.reloadOptions); this.$eventBusSearch.$emitter.$off('hasToReloadFacets', this.reloadOptions);
}, },
methods: { methods: {
reloadOptions(shouldReload) { reloadOptions(shouldReload) {

View File

@ -46,7 +46,8 @@
if (this.isUsingElasticSearch) if (this.isUsingElasticSearch)
this.loadOptions(); this.loadOptions();
}, },
immediate: true immediate: true,
deep: true
} }
}, },
mounted() { mounted() {
@ -54,10 +55,10 @@
this.loadOptions(); this.loadOptions();
}, },
created() { created() {
this.$eventBusSearch.$on('hasToReloadFacets', this.reloadOptions); this.$eventBusSearch.$emitter.$on('hasToReloadFacets', this.reloadOptions);
}, },
beforeUnmount() { beforeUnmount() {
this.$eventBusSearch.$off('hasToReloadFacets', this.reloadOptions); this.$eventBusSearch.$emitter.$off('hasToReloadFacets', this.reloadOptions);
}, },
methods: { methods: {
reloadOptions(shouldReload) { reloadOptions(shouldReload) {

View File

@ -98,19 +98,23 @@
} }
}, },
watch: { watch: {
selected(newVal, oldVal) { selected: {
handler(newVal, oldVal) {
const isEqual = (Array.isArray(newVal) && Array.isArray(oldVal) && (newVal.length == oldVal.length)) && newVal.every((element, index) => { const isEqual = (Array.isArray(newVal) && Array.isArray(oldVal) && (newVal.length == oldVal.length)) && newVal.every((element, index) => {
return element === oldVal[index]; return element === oldVal[index];
}); });
if (!isEqual) if (!isEqual)
this.onSelect(); this.onSelect();
}, },
deep: true
},
facetsFromItemSearch: { facetsFromItemSearch: {
handler() { handler() {
if (this.isUsingElasticSearch) if (this.isUsingElasticSearch)
this.loadOptions(); this.loadOptions();
}, },
immediate: true immediate: true,
deep:true
}, },
isLoadingItems: { isLoadingItems: {
handler() { handler() {
@ -129,7 +133,7 @@
this.taxonomyId = this.filter.metadatum.metadata_type_object.options.taxonomy_id; this.taxonomyId = this.filter.metadatum.metadata_type_object.options.taxonomy_id;
this.taxonomy = this.filter.metadatum.metadata_type_object.options.taxonomy; this.taxonomy = this.filter.metadatum.metadata_type_object.options.taxonomy;
} }
this.$eventBusSearch.$on('hasToReloadFacets', this.reloadOptions); this.$eventBusSearch.$emitter.$on('hasToReloadFacets', this.reloadOptions);
}, },
mounted(){ mounted(){
if (!this.isUsingElasticSearch) if (!this.isUsingElasticSearch)
@ -141,7 +145,7 @@
if (this.getOptionsValuesCancel != undefined) if (this.getOptionsValuesCancel != undefined)
this.getOptionsValuesCancel.cancel('Facet search Canceled.'); this.getOptionsValuesCancel.cancel('Facet search Canceled.');
this.$eventBusSearch.$off('hasToReloadFacets', this.reloadOptions); this.$eventBusSearch.$emitter.$off('hasToReloadFacets', this.reloadOptions);
}, },
methods: { methods: {
...mapGetters('search', [ ...mapGetters('search', [

View File

@ -2107,7 +2107,8 @@ export default {
}, },
immediate: true immediate: true
}, },
itemsLocations() { itemsLocations: {
handler() {
setTimeout(() => { setTimeout(() => {
if ( this.itemsLocations.length && this.$refs['tainacan-admin-view-mode-map'] && this.$refs['tainacan-admin-view-mode-map'].mapObject ) { if ( this.itemsLocations.length && this.$refs['tainacan-admin-view-mode-map'] && this.$refs['tainacan-admin-view-mode-map'].mapObject ) {
if (this.itemsLocations.length == 1) if (this.itemsLocations.length == 1)
@ -2115,7 +2116,9 @@ export default {
else else
this.$refs['tainacan-admin-view-mode-map'].mapObject.flyToBounds(this.itemsLocations.map((anItemLocation) => anItemLocation.location), { animate: true, maxZoom: 16, paddingTopLeft: [48, 48], paddingTopRight: [48, 48] }); this.$refs['tainacan-admin-view-mode-map'].mapObject.flyToBounds(this.itemsLocations.map((anItemLocation) => anItemLocation.location), { animate: true, maxZoom: 16, paddingTopLeft: [48, 48], paddingTopRight: [48, 48] });
} }
}, 500) }, 500);
},
deep: true
}, },
selectedGeocoordinateMetadatum() { selectedGeocoordinateMetadatum() {
this.clearSelectedMarkers(); this.clearSelectedMarkers();
@ -2134,7 +2137,8 @@ export default {
else else
this.selectedGeocoordinateMetadatumId = this.$userPrefs.get(prefsGeocoordinateMetadatum); this.selectedGeocoordinateMetadatumId = this.$userPrefs.get(prefsGeocoordinateMetadatum);
}, },
immediate: true immediate: true,
deep: true
} }
}, },
mounted() { mounted() {

View File

@ -168,27 +168,27 @@
handler() { handler() {
this.createChildMetadataGroups(); this.createChildMetadataGroups();
}, },
immediate: true immediate: true,
deep: true
}, },
isMetadataNavigation() { isMetadataNavigation() {
this.focusedGroupMetadatum = 0; this.focusedGroupMetadatum = 0;
this.focusedChildMetadatum = 0; this.focusedChildMetadatum = 0;
}, },
isFocused() { isFocused() {
if (this.isFocused) { if ( this.isFocused )
this.setMetadatumChildFocus({ groupIndex: this.focusedGroupMetadatum, childIndex: this.focusedChildMetadatum, scrollIntoView: true }); this.setMetadatumChildFocus({ groupIndex: this.focusedGroupMetadatum, childIndex: this.focusedChildMetadatum, scrollIntoView: true });
} }
}
}, },
created() { created() {
eventBusItemMetadata.$on('hasRemovedItemMetadataGroup', this.laterUpdateIsRemovingGroup); eventBusItemMetadata.$emitter.$on('hasRemovedItemMetadataGroup', this.laterUpdateIsRemovingGroup);
eventBusItemMetadata.$on('focusPreviousChildMetadatum', this.focusPreviousChildMetadatum); eventBusItemMetadata.$emitter.$on('focusPreviousChildMetadatum', this.focusPreviousChildMetadatum);
eventBusItemMetadata.$on('focusNextChildMetadatum', this.focusNextChildMetadatum); eventBusItemMetadata.$emitter.$on('focusNextChildMetadatum', this.focusNextChildMetadatum);
}, },
beforeUnmount() { beforeUnmount() {
eventBusItemMetadata.$off('hasRemovedItemMetadataGroup', this.laterUpdateIsRemovingGroup); eventBusItemMetadata.$emitter.$off('hasRemovedItemMetadataGroup', this.laterUpdateIsRemovingGroup);
eventBusItemMetadata.$off('focusPreviousChildMetadatum', this.focusPreviousChildMetadatum); eventBusItemMetadata.$emitter.$off('focusPreviousChildMetadatum', this.focusPreviousChildMetadatum);
eventBusItemMetadata.$off('focusNextChildMetadatum', this.focusNextChildMetadatum); eventBusItemMetadata.$emitter.$off('focusNextChildMetadatum', this.focusNextChildMetadatum);
}, },
methods: { methods: {
createChildMetadataGroups() { createChildMetadataGroups() {

View File

@ -179,7 +179,8 @@
} }
}, },
watch: { watch: {
selectedLatLng() { selectedLatLng: {
handler() {
const mapComponentRef = 'map--' + this.itemMetadatumIdentifier; const mapComponentRef = 'map--' + this.itemMetadatumIdentifier;
nextTick(() => { nextTick(() => {
if ( this.$refs[mapComponentRef] && this.$refs[mapComponentRef].mapObject && this.selectedLatLng.length != undefined) { if ( this.$refs[mapComponentRef] && this.$refs[mapComponentRef].mapObject && this.selectedLatLng.length != undefined) {
@ -189,6 +190,8 @@
this.$refs[mapComponentRef].mapObject.flyToBounds(this.selectedLatLng, { animate: true, maxZoom: this.maxZoom }); this.$refs[mapComponentRef].mapObject.flyToBounds(this.selectedLatLng, { animate: true, maxZoom: this.maxZoom });
} }
}); });
},
deep: true
} }
}, },
created() { created() {
@ -199,7 +202,7 @@
// We need to pass mapComponentRef here instead of creating it inside the function // We need to pass mapComponentRef here instead of creating it inside the function
// otherwise the listener would conflict when multiple geo metadata are inserted. // otherwise the listener would conflict when multiple geo metadata are inserted.
const mapComponentRef = 'map--' + this.itemMetadatumIdentifier; const mapComponentRef = 'map--' + this.itemMetadatumIdentifier;
eventBusItemMetadata.$on('itemEditionFormResize', () => this.handleWindowResize(mapComponentRef)); eventBusItemMetadata.$emitter.$on('itemEditionFormResize', () => this.handleWindowResize(mapComponentRef));
}, },
mounted() { mounted() {
nextTick(() => { nextTick(() => {
@ -209,7 +212,7 @@
}, },
beforeUnmount() { beforeUnmount() {
const mapComponentRef = 'map--' + this.itemMetadatumIdentifier; const mapComponentRef = 'map--' + this.itemMetadatumIdentifier;
eventBusItemMetadata.$off('itemEditionFormResize', () => this.handleWindowResize(mapComponentRef)); eventBusItemMetadata.$emitter.$off('itemEditionFormResize', () => this.handleWindowResize(mapComponentRef));
}, },
methods: { methods: {
onUpdateFromLatitudeInput: _.debounce( function($event) { onUpdateFromLatitudeInput: _.debounce( function($event) {

View File

@ -218,7 +218,7 @@
}, },
created() { created() {
this.setInitialValues(); this.setInitialValues();
eventBusItemMetadata.$on('updateErrorMessageOf#' + (this.itemMetadatum.parent_meta_id ? this.itemMetadatum.metadatum.id + '-' + this.itemMetadatum.parent_meta_id : this.itemMetadatum.metadatum.id), (errors) => { eventBusItemMetadata.$emitter.$on('updateErrorMessageOf#' + (this.itemMetadatum.parent_meta_id ? this.itemMetadatum.metadatum.id + '-' + this.itemMetadatum.parent_meta_id : this.itemMetadatum.metadatum.id), (errors) => {
let updatedErrorMessage = ''; let updatedErrorMessage = '';
if (errors && errors.errors && this.itemMetadatum && this.itemMetadatum.metadatum && (this.itemMetadatum.parent_meta_id ? (this.itemMetadatum.parent_meta_id == errors.parent_meta_id && this.itemMetadatum.metadatum.id == errors.metadatum_id) : this.itemMetadatum.metadatum.id == errors.metadatum_id)) { if (errors && errors.errors && this.itemMetadatum && this.itemMetadatum.metadatum && (this.itemMetadatum.parent_meta_id ? (this.itemMetadatum.parent_meta_id == errors.parent_meta_id && this.itemMetadatum.metadatum.id == errors.metadatum_id) : this.itemMetadatum.metadatum.id == errors.metadatum_id)) {
for (let error of errors.errors) { for (let error of errors.errors) {
@ -231,7 +231,7 @@
}, },
beforeUnmount() { beforeUnmount() {
if (this.itemMetadatum && this.itemMetadatum.metadatum) { if (this.itemMetadatum && this.itemMetadatum.metadatum) {
eventBusItemMetadata.$off('updateErrorMessageOf#' + (this.itemMetadatum.parent_meta_id ? this.itemMetadatum.metadatum.id + '-' + this.itemMetadatum.parent_meta_id : this.itemMetadatum.metadatum.id)); eventBusItemMetadata.$emitter.$off('updateErrorMessageOf#' + (this.itemMetadatum.parent_meta_id ? this.itemMetadatum.metadatum.id + '-' + this.itemMetadatum.parent_meta_id : this.itemMetadatum.metadatum.id));
} }
}, },
mounted () { mounted () {

View File

@ -130,12 +130,12 @@
} }
}, },
created(){ created(){
this.$root.$on('openProcessesPopup', () => { this.$root.$emitter.$on('openProcessesPopup', () => {
this.showProcesses = true; this.showProcesses = true;
}); });
}, },
beforeUnmount() { beforeUnmount() {
this.$root.$off('openProcessesPopup'); this.$root.$emitter.$off('openProcessesPopup');
}, },
methods: { methods: {
updateSearch() { updateSearch() {

View File

@ -81,13 +81,16 @@ export default {
} }
}, },
watch: { watch: {
'$route' (to, from) { '$route': {
handler(to, from) {
if (to.path != from.path) { if (to.path != from.path) {
this.isRepositoryLevel = (to.params.collectionId == undefined); this.isRepositoryLevel = (to.params.collectionId == undefined);
this.activeRoute = to.name; this.activeRoute = to.name;
this.pageTitle = this.$route.meta.title; this.pageTitle = this.$route.meta.title;
} }
},
deep: true
} }
}, },
created() { created() {
@ -96,10 +99,10 @@ export default {
document.title = this.$route.meta.title; document.title = this.$route.meta.title;
this.pageTitle = document.title; this.pageTitle = document.title;
this.$root.$on('onCollectionBreadCrumbUpdate', this.collectionBreadCrumbUpdate); this.$root.$emitter.$on('onCollectionBreadCrumbUpdate', this.collectionBreadCrumbUpdate);
}, },
beforeUnmount() { beforeUnmount() {
this.$root.$on('onCollectionBreadCrumbUpdate', this.collectionBreadCrumbUpdate); this.$root.$emitter.$on('onCollectionBreadCrumbUpdate', this.collectionBreadCrumbUpdate);
}, },
methods: { methods: {
...mapGetters('collection', [ ...mapGetters('collection', [

View File

@ -402,7 +402,7 @@
else else
this.isCheckboxListLoading = true; this.isCheckboxListLoading = true;
this.$parent.$on('updateTaxonomyInputs', ($event) => { this.$parent.$emitter.$on('updateTaxonomyInputs', ($event) => {
if ($event.taxonomyId == this.taxonomy_id && $event.metadatumId == this.metadatumId) { if ($event.taxonomyId == this.taxonomy_id && $event.metadatumId == this.metadatumId) {
this.finderColumns = []; this.finderColumns = [];
this.optionName = ''; this.optionName = '';

View File

@ -385,9 +385,12 @@
} }
}, },
watch: { watch: {
selected() { selected: {
handler() {
this.$emit('input', this.selected); this.$emit('input', this.selected);
}, },
deep: true
},
optionName(newValue, oldValue) { optionName(newValue, oldValue) {
if (newValue != oldValue) { if (newValue != oldValue) {
this.noMoreSearchPage = false; this.noMoreSearchPage = false;
@ -405,7 +408,7 @@
this.expandResultsSection = this.shouldBeginWithListExpanded; this.expandResultsSection = this.shouldBeginWithListExpanded;
this.$parent.$on('updateTaxonomyInputs', ($event) => { this.$parent.$emitter.$on('updateTaxonomyInputs', ($event) => {
if ($event.taxonomyId == this.taxonomy_id && $event.metadatumId == this.metadatumId) { if ($event.taxonomyId == this.taxonomy_id && $event.metadatumId == this.metadatumId) {
this.finderColumns = []; this.finderColumns = [];
this.optionName = ''; this.optionName = '';

View File

@ -356,7 +356,8 @@
} }
}, },
watch: { watch: {
taxonomyFilters() { taxonomyFilters: {
handler() {
if ( this.taxonomyFilters != undefined && Object.keys(this.taxonomyFilters).length ) { if ( this.taxonomyFilters != undefined && Object.keys(this.taxonomyFilters).length ) {
Object.assign( this.taxonomyFiltersCollectionNames, { 'repository-filters': this.$i18n.get('repository') }); Object.assign( this.taxonomyFiltersCollectionNames, { 'repository-filters': this.$i18n.get('repository') });
@ -378,7 +379,10 @@
}); });
} }
}, },
repositoryCollectionFilters() { deep: true
},
repositoryCollectionFilters: {
handler() {
if ( this.repositoryCollectionFilters != undefined && Object.keys(this.repositoryCollectionFilters).length ) { if ( this.repositoryCollectionFilters != undefined && Object.keys(this.repositoryCollectionFilters).length ) {
Object.assign( this.repositoryCollectionNames, { 'repository-filters': this.$i18n.get('repository') }); Object.assign( this.repositoryCollectionNames, { 'repository-filters': this.$i18n.get('repository') });
@ -386,13 +390,15 @@
for ( let collection of this.getCollections() ) for ( let collection of this.getCollections() )
Object.assign( this.repositoryCollectionNames, { [collection.id]: collection.name }); Object.assign( this.repositoryCollectionNames, { [collection.id]: collection.name });
} }
},
deep: true
} }
}, },
mounted() { mounted() {
this.prepareFilters(); this.prepareFilters();
if (this.isUsingElasticSearch) if (this.isUsingElasticSearch)
this.$eventBusSearch.$on('isLoadingItems', this.updateIsLoadingItems); this.$eventBusSearch.$emitter.$on('isLoadingItems', this.updateIsLoadingItems);
}, },
beforeUnmount() { beforeUnmount() {
// Cancels previous collection name Request // Cancels previous collection name Request
@ -408,7 +414,7 @@
this.filtersSearchCancel.cancel('Filters search Canceled.'); this.filtersSearchCancel.cancel('Filters search Canceled.');
if (this.isUsingElasticSearch) if (this.isUsingElasticSearch)
this.$eventBusSearch.$off('isLoadingItems', this.updateIsLoadingItems); this.$eventBusSearch.$emitter.$off('isLoadingItems', this.updateIsLoadingItems);
}, },
methods: { methods: {

View File

@ -87,6 +87,7 @@ import {
ThumbnailHelperPlugin, ThumbnailHelperPlugin,
OrderByHelperPlugin OrderByHelperPlugin
} from './utilities'; } from './utilities';
import mitt from 'mitt';
export default (element) => { export default (element) => {
@ -108,6 +109,9 @@ export default (element) => {
app.use(router); app.use(router);
app.use(store); app.use(store);
const emitter = mitt();
app.config.globalProperties.$emitter = emitter;
/* Registers Extra Vue Plugins passed to the window.tainacan_extra_plugins */ /* Registers Extra Vue Plugins passed to the window.tainacan_extra_plugins */
if (typeof window.tainacan_extra_plugins != "undefined") { if (typeof window.tainacan_extra_plugins != "undefined") {
for (let [extraVuePluginName, extraVuePluginObject] of Object.entries(window.tainacan_extra_plugins)) for (let [extraVuePluginName, extraVuePluginObject] of Object.entries(window.tainacan_extra_plugins))

View File

@ -1,5 +1,8 @@
import { createApp } from 'vue'; import { createApp } from 'vue';
import store from './store/store' import store from './store/store'
import mitt from 'mitt';
const emitter = mitt();
export const eventBusItemMetadata = createApp({ export const eventBusItemMetadata = createApp({
store, store,
@ -8,13 +11,16 @@ export const eventBusItemMetadata = createApp({
conditionalSections: {} conditionalSections: {}
}, },
watch: { watch: {
errors() { errors: {
handler() {
this.$emit('hasErrorsOnForm', this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length); this.$emit('hasErrorsOnForm', this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length);
if (this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length) { if (this.errors.length > 0 && this.errors[0].errors && this.errors[0].errors.length) {
for (let error of this.errors) for (let error of this.errors)
this.$emit('updateErrorMessageOf#' + (error.metadatum_id + (error.parent_meta_id ? '-' + error.parent_meta_id : '')), error); this.$emit('updateErrorMessageOf#' + (error.metadatum_id + (error.parent_meta_id ? '-' + error.parent_meta_id : '')), error);
} }
},
deep: true
} }
}, },
emits: [ emits: [
@ -31,12 +37,12 @@ export const eventBusItemMetadata = createApp({
'isUpdatingValue' 'isUpdatingValue'
], ],
created() { created() {
this.$on('input', this.updateValue); this.$emitter.$on('input', this.updateValue);
this.$on('removeCompoundGroup', this.removeItemMetadataGroup); this.$emitter.$on('removeCompoundGroup', this.removeItemMetadataGroup);
}, },
beforeUpdate() { beforeUpdate() {
this.$off('input', this.updateValue); this.$emitter.$off('input', this.updateValue);
this.$on('removeCompoundGroup', this.removeItemMetadataGroup); this.$emitter.$on('removeCompoundGroup', this.removeItemMetadataGroup);
}, },
methods : { methods : {
updateValue({ itemId, metadatumId, values, parentMetaId, parentId }){ updateValue({ itemId, metadatumId, values, parentMetaId, parentId }){
@ -153,3 +159,4 @@ export const eventBusItemMetadata = createApp({
} }
} }
}); });
eventBusItemMetadata.config.globalProperties.$emitter = emitter;

View File

@ -1,9 +1,12 @@
import { createApp } from 'vue'; import { createApp } from 'vue';
import mitt from 'mitt';
const emitter = mitt();
export default { export default {
install(app, options = {}) { install(app, options = {}) {
app.config.globalProperties.$emitter = emitter;
app.config.globalProperties.$eventBusMetadataList = createApp({ app.config.globalProperties.$eventBusMetadataList = createApp({
emits: [ emits: [
'addMetadatumViaButton', 'addMetadatumViaButton',

View File

@ -1,9 +1,12 @@
import { createApp } from 'vue'; import { createApp } from 'vue';
import mitt from 'mitt';
const emitter = mitt();
export default { export default {
install(app, options = {}) { install(app, options = {}) {
app.config.globalProperties.$emitter = emitter;
app.config.globalProperties.$eventBusSearch = createApp({ app.config.globalProperties.$eventBusSearch = createApp({
router: options.router, router: options.router,
store: options.store, store: options.store,
@ -26,20 +29,20 @@ export default {
'closeAdvancedSearch' 'closeAdvancedSearch'
], ],
created() { created() {
this.$on('input', data => { this.$emitter.$on('input', data => {
if (data.taxonomy) if (data.taxonomy)
this.addTaxquery(data); this.addTaxquery(data);
else else
this.addMetaquery(data); this.addMetaquery(data);
}); });
this.$root.$on('closeAdvancedSearch', () => { this.$root.$emitter.$on('closeAdvancedSearch', () => {
this.$store.dispatch('search/setPage', 1); this.$store.dispatch('search/setPage', 1);
this.performAdvancedSearch({}); this.performAdvancedSearch({});
}); });
this.$root.$on('performAdvancedSearch', advancedSearchQuery => { this.$root.$emitter.$on('performAdvancedSearch', advancedSearchQuery => {
this.$store.dispatch('search/setPage', 1); this.$store.dispatch('search/setPage', 1);
this.performAdvancedSearch(advancedSearchQuery); this.performAdvancedSearch(advancedSearchQuery);
@ -47,7 +50,8 @@ export default {
}); });
}, },
watch: { watch: {
'$route' (to, from) { '$route': {
handler(to, from) {
// Should set Collection ID from URL only when in admin. // Should set Collection ID from URL only when in admin.
if (this.$route.name == 'CollectionItemsPage' || this.$route.name == 'ItemsPage') if (this.$route.name == 'CollectionItemsPage' || this.$route.name == 'ItemsPage')
@ -189,6 +193,8 @@ export default {
if (to.fullPath != from.fullPath) if (to.fullPath != from.fullPath)
this.loadItems(); this.loadItems();
} }
},
deep: true
} }
}, },
methods: { methods: {

View File

@ -816,9 +816,12 @@
} }
}, },
watch: { watch: {
displayedMetadata() { displayedMetadata: {
handler() {
this.localDisplayedMetadata = JSON.parse(JSON.stringify(this.displayedMetadata)); this.localDisplayedMetadata = JSON.parse(JSON.stringify(this.displayedMetadata));
}, },
deep: true
},
openAdvancedSearch(newValue) { openAdvancedSearch(newValue) {
if (newValue == false){ if (newValue == false){
this.$eventBusSearch.$emit('closeAdvancedSearch'); this.$eventBusSearch.$emit('closeAdvancedSearch');
@ -848,7 +851,7 @@
this.$eventBusSearch.setCollectionId(this.collectionId); this.$eventBusSearch.setCollectionId(this.collectionId);
this.$eventBusSearch.updateStoreFromURL(); this.$eventBusSearch.updateStoreFromURL();
this.$eventBusSearch.$on('isLoadingItems', isLoadingItems => { this.$eventBusSearch.$emitter.$on('isLoadingItems', isLoadingItems => {
if (isLoadingItems != this.isLoadingItems && this.$refs['items-page-container'] && this.$refs['search-control']) { if (isLoadingItems != this.isLoadingItems && this.$refs['items-page-container'] && this.$refs['search-control']) {
@ -861,7 +864,7 @@
this.isLoadingItems = isLoadingItems; this.isLoadingItems = isLoadingItems;
}); });
this.$eventBusSearch.$on('hasFiltered', hasFiltered => { this.$eventBusSearch.$emitter.$on('hasFiltered', hasFiltered => {
this.hasFiltered = hasFiltered; this.hasFiltered = hasFiltered;
}); });
@ -869,7 +872,7 @@
this.openAdvancedSearch = this.$route.query.advancedSearch; this.openAdvancedSearch = this.$route.query.advancedSearch;
} }
this.$root.$on('openAdvancedSearch', (openAdvancedSearch) => { this.$root.$emitter.$on('openAdvancedSearch', (openAdvancedSearch) => {
this.openAdvancedSearch = openAdvancedSearch; this.openAdvancedSearch = openAdvancedSearch;
}); });
@ -1393,14 +1396,14 @@
}, 750), }, 750),
removeEventListeners() { removeEventListeners() {
// Component // Component
this.$off(); this.$emitter.$off();
// Window // Window
window.removeEventListener('resize', this.hideFiltersOnMobile); window.removeEventListener('resize', this.hideFiltersOnMobile);
// $root // $root
this.$root.$off('openAdvancedSearch'); this.$root.$emitter.$off('openAdvancedSearch');
// $eventBusSearch // $eventBusSearch
this.$eventBusSearch.$off('isLoadingItems'); this.$eventBusSearch.$emitter.$off('isLoadingItems');
this.$eventBusSearch.$off('hasFiltered'); this.$eventBusSearch.$emitter.$off('hasFiltered');
} }
} }
} }

View File

@ -830,9 +830,12 @@
} }
}, },
watch: { watch: {
displayedMetadata() { displayedMetadata: {
handler() {
this.localDisplayedMetadata = JSON.parse(JSON.stringify(this.displayedMetadata)); this.localDisplayedMetadata = JSON.parse(JSON.stringify(this.displayedMetadata));
}, },
deep: true
},
openAdvancedSearch(newValue){ openAdvancedSearch(newValue){
if (newValue == false){ if (newValue == false){
this.$eventBusSearch.$emit('closeAdvancedSearch'); this.$eventBusSearch.$emit('closeAdvancedSearch');
@ -898,7 +901,7 @@
} }
} }
this.$eventBusSearch.$on('isLoadingItems', isLoadingItems => { this.$eventBusSearch.$emitter.$on('isLoadingItems', isLoadingItems => {
this.isLoadingItems = isLoadingItems; this.isLoadingItems = isLoadingItems;
@ -912,7 +915,7 @@
})); }));
}); });
this.$eventBusSearch.$on('hasFiltered', hasFiltered => { this.$eventBusSearch.$emitter.$on('hasFiltered', hasFiltered => {
this.hasFiltered = hasFiltered; this.hasFiltered = hasFiltered;
}); });
@ -922,12 +925,12 @@
this.openAdvancedSearch = this.$route.query.advancedSearch; this.openAdvancedSearch = this.$route.query.advancedSearch;
} }
this.$root.$on('openAdvancedSearch', (openAdvancedSearch) => { this.$root.$emitter.$on('openAdvancedSearch', (openAdvancedSearch) => {
this.openAdvancedSearch = openAdvancedSearch; this.openAdvancedSearch = openAdvancedSearch;
}); });
} }
this.$eventBusSearch.$on('startSlideshowFromItem', (index) => { this.$eventBusSearch.$emitter.$on('startSlideshowFromItem', (index) => {
let currentQuery = this.$route.query; let currentQuery = this.$route.query;
delete currentQuery['slideshow-from']; delete currentQuery['slideshow-from'];
this.$router.replace({ query: currentQuery }).catch((error) => this.$console.log(error)); this.$router.replace({ query: currentQuery }).catch((error) => this.$console.log(error));
@ -1453,16 +1456,16 @@
}, 500), }, 500),
removeEventListeners() { removeEventListeners() {
// Component // Component
this.$off(); this.$emitter.$off();
// Window // Window
if (!this.hideFilters) if (!this.hideFilters)
window.removeEventListener('resize', this.hideFiltersOnMobile); window.removeEventListener('resize', this.hideFiltersOnMobile);
// $root // $root
if (!this.hideAdvancedSearch) if (!this.hideAdvancedSearch)
this.$root.$off('openAdvancedSearch'); this.$root.$emitter.$off('openAdvancedSearch');
// $eventBusSearch // $eventBusSearch
this.$eventBusSearch.$off('isLoadingItems'); this.$eventBusSearch.$emitter.$off('isLoadingItems');
this.$eventBusSearch.$off('hasFiltered'); this.$eventBusSearch.$emitter.$off('hasFiltered');
}, },
} }

View File

@ -44,6 +44,7 @@ import {
ThumbnailHelperPlugin, ThumbnailHelperPlugin,
OrderByHelperPlugin OrderByHelperPlugin
} from '../../../admin/js/utilities'; } from '../../../admin/js/utilities';
import mitt from 'mitt';
export default (element) => { export default (element) => {
@ -279,6 +280,9 @@ export default (element) => {
.catch(error => console.log(error)); .catch(error => console.log(error));
}); });
const emitter = mitt();
VueItemsList.config.globalProperties.$emitter = emitter;
VueItemsList.use(eventBusSearch, { store: store, router: routerTheme }); VueItemsList.use(eventBusSearch, { store: store, router: routerTheme });
VueItemsList.mount(); VueItemsList.mount();

View File

@ -908,7 +908,7 @@ export default {
// CREATING NEW ITEM SUBMISSION // CREATING NEW ITEM SUBMISSION
this.createNewItem(); this.createNewItem();
eventBusItemMetadata.$on('hasErrorsOnForm', (hasErrors) => { eventBusItemMetadata.$emitter.$on('hasErrorsOnForm', (hasErrors) => {
if (hasErrors) { if (hasErrors) {
if (Array.isArray(this.formErrors)) { if (Array.isArray(this.formErrors)) {
for (let i = 0; i < this.metadataSectionCollapses.length; i++) for (let i = 0; i < this.metadataSectionCollapses.length; i++)
@ -968,7 +968,7 @@ export default {
this.form.document_type = 'url'; this.form.document_type = 'url';
}, },
beforeUnmount () { beforeUnmount () {
eventBusItemMetadata.$off('hasErrorsOnForm'); eventBusItemMetadata.$emitter.$off('hasErrorsOnForm');
}, },
methods: { methods: {
...mapActions('item', [ ...mapActions('item', [