From 72388ecd143e156b6331c3edbf32109782c14449 Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Thu, 18 Jul 2019 14:50:30 -0300 Subject: [PATCH] Adds duplication dialog and routine. --- src/admin/components/lists/items-list.vue | 72 ++++++++--- src/admin/components/lists/processes-list.vue | 2 +- .../components/other/duplication-dialog.vue | 113 ++++++++++++++++++ src/admin/tainacan-admin-i18n.php | 8 +- src/js/event-bus-search.js | 3 + src/js/store/modules/item/actions.js | 8 +- src/js/store/modules/search/actions.js | 4 + src/js/store/modules/search/getters.js | 4 + src/js/store/modules/search/index.js | 3 +- src/js/store/modules/search/mutations.js | 6 +- 10 files changed, 195 insertions(+), 28 deletions(-) create mode 100644 src/admin/components/other/duplication-dialog.vue diff --git a/src/admin/components/lists/items-list.vue b/src/admin/components/lists/items-list.vue index af759d6e5..ac9800971 100644 --- a/src/admin/components/lists/items-list.vue +++ b/src/admin/components/lists/items-list.vue @@ -107,11 +107,11 @@ v-if="contextMenuItem != null && contextMenuItem.current_user_can_edit && !$route.query.iframemode"> {{ $i18n.getFrom('items','edit_item') }} - + @@ -673,7 +673,7 @@ - + @@ -900,6 +903,7 @@ + + + diff --git a/src/admin/tainacan-admin-i18n.php b/src/admin/tainacan-admin-i18n.php index 726eb8be8..e79b7fd36 100644 --- a/src/admin/tainacan-admin-i18n.php +++ b/src/admin/tainacan-admin-i18n.php @@ -415,6 +415,9 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_duplicate_item' => __( 'Duplicate item', 'tainacan' ), 'label_create_another_item' => __( 'Create another item', 'tainacan' ), 'label_recent_collections' => __( 'Recent Collections', 'tainacan' ), + 'label_duplicating_item' => __( 'Duplicating item', 'tainacan' ), + 'label_item_duplication_success' => __( 'The item was duplicated with success!', 'tainacan' ), + 'label_item_duplication_failure' => __( 'Something wrong happened... Item duplication failed!', 'tainacan' ), // Instructions. More complex sentences to guide user and placeholders 'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ), @@ -625,8 +628,9 @@ return apply_filters( 'tainacan-admin-i18n', [ 'info_send_email' => __('The exporter may take a while. Check this option to receive an e-mail when the process is done. You can also check the process status visiting the', 'tainacan'), 'info_tainacan_api' => __('Tainacan API on JSON format.', 'tainacan'), 'info_items_hidden_due_sorting' => __('When ordering by metadata value, items that have no value for the chosen metadata will not be listed. This list may have less elements than the total existing for current search criteria.', 'tainacan'), - 'info_sorting_by_metadata_value_%s' => __('Showing only items that have value for metadata %s.'), - 'info_sorting_by_metadata_value_%s_empty_list' => __('No item found, but only items with values for metadata %s are shown. Try sorting by other metatada.'), + 'info_sorting_by_metadata_value_%s' => __('Showing only items that have value for metadata %s.', 'tainacan'), + 'info_sorting_by_metadata_value_%s_empty_list' => __('No item found, but only items with values for metadata %s are shown. Try sorting by other metatada.', 'tainacan'), + 'info_await_while_item_duplication' => __('Please wait while item is being duplicated...', 'tainacan'), // Tainacan Metadatum Types 'tainacan-text' => __( 'Text', 'tainacan' ), diff --git a/src/js/event-bus-search.js b/src/js/event-bus-search.js index ceda66645..dd3d5af5a 100644 --- a/src/js/event-bus-search.js +++ b/src/js/event-bus-search.js @@ -303,6 +303,9 @@ export default { this.$store.dispatch('search/setAdminViewMode', adminViewMode); this.updateURLQueries(); }, + highlightsItem(itemId) { + this.$store.dispatch('search/highlightsItem', itemId); + }, updateURLQueries() { this.$router.replace({ query: {} }); this.$router.replace({ query: this.$store.getters['search/getPostQuery'] }); diff --git a/src/js/store/modules/item/actions.js b/src/js/store/modules/item/actions.js index 7c543e11b..5e9d3bc7e 100644 --- a/src/js/store/modules/item/actions.js +++ b/src/js/store/modules/item/actions.js @@ -134,14 +134,10 @@ export const updateItem = ({ commit }, item) => { }); }; -export const duplicateItem = ({ commit }, { item, attachment }) => { - delete item['id']; - - if (item['terms'] == null) - item['terms'] = []; +export const duplicateItem = ({ commit }, { collectionId, itemId }) => { return new Promise((resolve, reject) => { - axios.tainacan.post('/collection/' + item.collection_id + '/items/', item) + axios.tainacan.post('/collection/' + collectionId + '/items/' + itemId + '/duplicate') .then( res => { resolve( res.data ); }).catch( error => { diff --git a/src/js/store/modules/search/actions.js b/src/js/store/modules/search/actions.js index b9632b25a..4293a250c 100644 --- a/src/js/store/modules/search/actions.js +++ b/src/js/store/modules/search/actions.js @@ -165,4 +165,8 @@ export const cleanTaxQueries = ({ commit }) => { export const cleanFetchOnly = ({ commit }) => { commit('cleanFetchOnly'); +}; + +export const highlightsItem = ({ commit }, itemId ) => { + commit('setHighlightedItem', itemId); }; \ 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 769b702d6..f62490cec 100644 --- a/src/js/store/modules/search/getters.js +++ b/src/js/store/modules/search/getters.js @@ -83,3 +83,7 @@ export const getFilterTags = state => { export const getFacets = state => { return state.facets; }; + +export const getHighlightedItem = state => { + return state.highlightedItem; +}; diff --git a/src/js/store/modules/search/index.js b/src/js/store/modules/search/index.js index bd68c4e2a..8165020a0 100644 --- a/src/js/store/modules/search/index.js +++ b/src/js/store/modules/search/index.js @@ -23,7 +23,8 @@ const state = { totalPages: 0, itemsPerPage: 12, // Not the same as postquery.perpage as API may have limited it's value facets: {}, - orderByName: '' + orderByName: '', + highlightedItem: null }; export default { diff --git a/src/js/store/modules/search/mutations.js b/src/js/store/modules/search/mutations.js index 35ce6d03e..64465b4e1 100644 --- a/src/js/store/modules/search/mutations.js +++ b/src/js/store/modules/search/mutations.js @@ -187,4 +187,8 @@ export const cleanFetchOnly = (state) => { export const setFacets = (state, facets) => { state.facets = facets; -} \ No newline at end of file +} + +export const setHighlightedItem = (state, itemId) => { + state.highlightedItem = itemId; +}