diff --git a/src/admin/js/utilities.js b/src/admin/js/utilities.js index 995bb6e72..dfdfaf068 100644 --- a/src/admin/js/utilities.js +++ b/src/admin/js/utilities.js @@ -111,7 +111,7 @@ UserPrefsPlugin.install = function (Vue, options = {}) { slug: 'creation_date', name: 'Creation Date' }, - 'view_mode': 'cards', + 'view_mode': 'table', 'admin_view_mode': 'table' }, init() { diff --git a/src/js/event-bus-search.js b/src/js/event-bus-search.js index ba0f789b9..39f7235d4 100644 --- a/src/js/event-bus-search.js +++ b/src/js/event-bus-search.js @@ -122,6 +122,22 @@ export default { } } + // Admin View Modes + if (this.$route.name != null && this.$route.name != undefined && + (this.$route.name == 'CollectionItemsPage' || this.$route.name == 'ItemsPage') && + (this.$route.query.admin_view_mode == undefined || to.params.collectionId != from.params.collectionId) + ) { + let adminViewModeKey = (this.collectionId != undefined ? 'admin_view_mode_' + this.collectionId : 'admin_view_mode'); + let adminViewModeValue = this.$userPrefs.get(adminViewModeKey); + + if (adminViewModeValue) + this.$route.query.admin_view_mode = adminViewModeValue; + else { + this.$route.query.admin_view_mode = 'table'; + this.$userPrefs.set(adminViewModeKey, 'table'); + } + } + // Advanced Search if (this.$route.query.metaquery && this.$route.query.metaquery.advancedSearch){ this.$store.dispatch('search/set_advanced_query', this.$route.query.metaquery); @@ -225,15 +241,15 @@ export default { this.$store.dispatch('search/setViewMode', viewMode); this.updateURLQueries(); }, - setAdminViewMode(viewMode) { + setAdminViewMode(adminViewMode) { let prefsAdminViewMode = this.collectionId != undefined ? 'admin_view_mode_' + this.collectionId : 'admin_view_mode'; - if(this.$userPrefs.get(prefsAdminViewMode) != viewMode) { - this.$userPrefs.set(prefsAdminViewMode, viewMode) + if(this.$userPrefs.get(prefsAdminViewMode) != adminViewMode) { + this.$userPrefs.set(prefsAdminViewMode, adminViewMode) .catch(() => { this.$console.log("Error settings user prefs for admin view mode.") }); } - // Admin view mode is not syncronizing with URL yet. - //this.$store.dispatch('search/setViewMode', viewMode); - //this.updateURLQueries(); + + this.$store.dispatch('search/setAdminViewMode', adminViewMode); + this.updateURLQueries(); }, setInitialViewMode(viewMode) { this.$store.dispatch('search/setViewMode', viewMode); diff --git a/src/js/store/modules/collection/actions.js b/src/js/store/modules/collection/actions.js index 9457166d7..c85ab1eff 100644 --- a/src/js/store/modules/collection/actions.js +++ b/src/js/store/modules/collection/actions.js @@ -50,7 +50,11 @@ export const fetchItems = ({ rootGetters, dispatch, commit }, { collectionId, is postQueries.view_mode = null; endpoint = endpoint + 'context=edit&' - } + } else { + if (postQueries.admin_view_mode != undefined) + postQueries.admin_view_mode = null; + } + axios.tainacan.get(endpoint+query) .then(res => { diff --git a/src/js/store/modules/search/actions.js b/src/js/store/modules/search/actions.js index e6f4a5f51..c43f99e23 100644 --- a/src/js/store/modules/search/actions.js +++ b/src/js/store/modules/search/actions.js @@ -106,4 +106,9 @@ export const setSearchQuery = ({ commit }, searchQuery ) => { // Set ViewMode (view_mode) export const setViewMode = ({ commit }, viewMode ) => { commit('setViewMode', viewMode ); +}; + +// Set AdminViewMode (admin_view_mode) +export const setAdminViewMode = ({ commit }, adminViewMode ) => { + commit('setAdminViewMode', adminViewMode ); }; \ No newline at end of file diff --git a/src/js/store/modules/search/getters.js b/src/js/store/modules/search/getters.js index 7585aed45..80019a015 100644 --- a/src/js/store/modules/search/getters.js +++ b/src/js/store/modules/search/getters.js @@ -52,6 +52,9 @@ export const getViewMode = state => { return state.postquery.view_mode; }; +export const getAdminViewMode = state => { + return state.postquery.admin_view_mode; +}; export const getFetchOnly = state => { return state.postquery.fetch_only; }; diff --git a/src/js/store/modules/search/index.js b/src/js/store/modules/search/index.js index 0b42bd391..5df6c490f 100644 --- a/src/js/store/modules/search/index.js +++ b/src/js/store/modules/search/index.js @@ -19,7 +19,8 @@ const state = { '1': 'creation_date', '2': 'author_name' }, - view_mode: 'table' + view_mode: 'table', + admin_view_mode: 'table' }, totalItems: 0 }; diff --git a/src/js/store/modules/search/mutations.js b/src/js/store/modules/search/mutations.js index b512aaa1f..d48415b39 100644 --- a/src/js/store/modules/search/mutations.js +++ b/src/js/store/modules/search/mutations.js @@ -127,4 +127,8 @@ export const setStatus = ( state, status ) => { export const setViewMode = ( state, viewMode ) => { state.postquery.view_mode = viewMode; +}; + +export const setAdminViewMode = ( state, adminViewMode ) => { + state.postquery.admin_view_mode = adminViewMode; }; \ No newline at end of file