diff --git a/src/admin/components/tainacan-header.vue b/src/admin/components/tainacan-header.vue index f7fc0804f..f9b5486cf 100644 --- a/src/admin/components/tainacan-header.vue +++ b/src/admin/components/tainacan-header.vue @@ -3,15 +3,15 @@

{{pageTitle}}

-
@@ -34,49 +34,73 @@ export default { wordpressAdmin: window.location.origin + window.location.pathname.replace('admin.php', ''), onSecondaryPage: false, pageTitle: '', - arrayPath: [], + arrayRealPath: [], + arrayViewPath: [] } }, methods: { ...mapActions('collection', [ - 'fetchCollection' + 'fetchCollectionName' ]), ...mapGetters('collection', [ - 'getCollection' + 'getCollectionName' ]), ...mapActions('item', [ - 'fetchItem' + 'fetchItemTitle' ]), ...mapGetters('item', [ - 'getItem' + 'getItemTitle' ]), - getEntityName(type, id) { - switch(type) { - case 'collections': - //return this.getCollectionName(id); - break; - case 'items': - //return this.getItemName(id); - break; - default: - return id; + generateViewPath() { + + for (let i = 0; i < this.arrayRealPath.length; i++) { + + this.arrayViewPath.push(''); + + if (!isNaN(this.arrayRealPath[i]) && i > 0) { + + switch(this.arrayRealPath[i-1]) { + case 'collections': + this.fetchCollectionName(this.arrayRealPath[i]) + .then(collectionName => this.arrayViewPath.splice(i, 1, collectionName)) + .catch((error) => console.log(error)); + break; + case 'items': + this.fetchItemTitle(this.arrayRealPath[i]) + .then(itemTitle => this.arrayViewPath.splice(i, 1,itemTitle)) + .catch((error) => console.log(error)); + break; + } + + } else { + this.arrayViewPath.splice(i, 1, this.$i18n.get(this.arrayRealPath[i])); + } + } - return id; - } + }, }, watch: { '$route' (to, from) { this.onSecondaryPage = (to.params.collectionId != undefined); - this.arrayPath = to.path.split("/"); - this.arrayPath = this.arrayPath.filter((item) => item.length != 0); this.pageTitle = this.$route.meta.title; + + this.arrayRealPath = to.path.split("/"); + this.arrayRealPath = this.arrayRealPath.filter((item) => item.length != 0); + + this.generateViewPath(); } }, + mounted() { + console.log(this.arrayViewPath); + }, created() { this.onSecondaryPage = (this.$route.params.collectionId != undefined); - this.arrayPath = this.$route.path.split("/"); - this.arrayPath = this.arrayPath.filter((item) => item.length != 0); this.pageTitle = this.$route.meta.title; + + this.arrayRealPath = this.$route.path.split("/"); + this.arrayRealPath = this.arrayRealPath.filter((item) => item.length != 0); + + this.generateViewPath(); } } diff --git a/src/js/store/modules/collection/actions.js b/src/js/store/modules/collection/actions.js index 22f97e475..4a1280a70 100644 --- a/src/js/store/modules/collection/actions.js +++ b/src/js/store/modules/collection/actions.js @@ -54,6 +54,20 @@ export const fetchCollection = ({ commit }, id) => { }); } +export const fetchCollectionName = ({ commit }, id) => { + return new Promise((resolve, reject) =>{ + axios.get('/collections/' + id + '?fetch_only=name') + .then(res => { + let collectionName = res.data; + commit('setCollectionName', collectionName.name); + resolve( collectionName.name ); + }) + .catch(error => { + reject(error); + }) + }); +} + export const deleteCollection = ({ commit }, id) => { return new Promise((resolve, reject) =>{ axios.delete('/collections/' + id) diff --git a/src/js/store/modules/collection/getters.js b/src/js/store/modules/collection/getters.js index a1ce71347..201d78f7e 100644 --- a/src/js/store/modules/collection/getters.js +++ b/src/js/store/modules/collection/getters.js @@ -9,3 +9,7 @@ export const getCollections = state => { export const getCollection = state => { return state.collection; } + +export const getCollectionName = state => { + return state.collectionName; +} \ No newline at end of file diff --git a/src/js/store/modules/collection/index.js b/src/js/store/modules/collection/index.js index 4669ba467..9cbe37563 100644 --- a/src/js/store/modules/collection/index.js +++ b/src/js/store/modules/collection/index.js @@ -5,7 +5,8 @@ import * as mutations from './mutations'; const state = { items: [], collections: [], - collection: null + collection: null, + collectionName: '' }; export default { diff --git a/src/js/store/modules/collection/mutations.js b/src/js/store/modules/collection/mutations.js index 7a6295d5f..06c497a11 100644 --- a/src/js/store/modules/collection/mutations.js +++ b/src/js/store/modules/collection/mutations.js @@ -27,3 +27,7 @@ export const setFields = (state, fields) => { export const setCollection = (state, collection) => { state.collection = collection; } + +export const setCollectionName = (state, collectionName) => { + state.collectionName = collectionName; +} diff --git a/src/js/store/modules/item/actions.js b/src/js/store/modules/item/actions.js index 7d5805fa4..b0db5c6f1 100644 --- a/src/js/store/modules/item/actions.js +++ b/src/js/store/modules/item/actions.js @@ -62,6 +62,20 @@ export const fetchItem = ({ commit }, item_id) => { }); }; +export const fetchItemTitle = ({ commit }, id) => { + return new Promise((resolve, reject) =>{ + axios.get('/items/' + id + '?fetch_only=title') + .then(res => { + let itemTitle = res.data; + commit('setItemTitle', itemTitle.title); + resolve( itemTitle.title ); + }) + .catch(error => { + reject(error); + }) + }); +} + export const sendItem = ( { commit }, { collection_id, status }) => { return new Promise(( resolve, reject ) => { axios.post('/collection/'+ collection_id + '/items/', { diff --git a/src/js/store/modules/item/getters.js b/src/js/store/modules/item/getters.js index d33ad3132..a99901616 100644 --- a/src/js/store/modules/item/getters.js +++ b/src/js/store/modules/item/getters.js @@ -6,3 +6,7 @@ export const getFields = state => { export const getItem = state => { return state.item; } + +export const getItemTitle = state => { + return state.itemTitle; +} diff --git a/src/js/store/modules/item/index.js b/src/js/store/modules/item/index.js index 54e74bc34..d43b465bf 100644 --- a/src/js/store/modules/item/index.js +++ b/src/js/store/modules/item/index.js @@ -5,7 +5,8 @@ import * as mutations from './mutations'; const state = { item: [], fields: [], - error: [] + error: [], + itemTitle: '' }; diff --git a/src/js/store/modules/item/mutations.js b/src/js/store/modules/item/mutations.js index b9a8e3fbd..b5d8ee75d 100644 --- a/src/js/store/modules/item/mutations.js +++ b/src/js/store/modules/item/mutations.js @@ -4,6 +4,10 @@ export const setItem = ( state, item ) => { state.item = item; } +export const setItemTitle = ( state, itemTitle ) => { + state.itemTitle = itemTitle; +} + export const setFields = ( state, field) => { state.fields = field; }