diff --git a/src/admin/js/router.js b/src/admin/js/router.js index b96703e78..f886a0ee5 100644 --- a/src/admin/js/router.js +++ b/src/admin/js/router.js @@ -4,7 +4,7 @@ import VueRouter from 'vue-router' import AdminPage from '../admin.vue' import CollectionPage from '../pages/collection-page.vue' import ItemPage from '../pages/item-page.vue' -import ItemCreationPage from '../pages/item-creation-page.vue' +import ItemEditionPage from '../pages/item-edition-page.vue' import CollectionsList from '../components/collections-list.vue' import ItemsList from '../components/items-list.vue' @@ -19,8 +19,8 @@ const routes = [ ], meta: { title: 'Collection Page' } }, - { path: '/collections/:id/items/new', component: ItemCreationPage, meta: {title: 'Create Item'} }, - { path: '/collections/:collection_id/items/:id/edit', component: ItemCreationPage, meta: {title: 'Edit Item'} }, + { path: '/collections/:id/items/new', component: ItemEditionPage, meta: {title: 'Create Item'} }, + { path: '/collections/:collection_id/items/:id/edit', component: ItemEditionPage, meta: {title: 'Edit Item'} }, { path: '/collections/:collection_id/items/:id', component: ItemPage, meta: {title: 'Item Page'} }, { path: '*', redirect: '/'} ] diff --git a/src/admin/pages/item-creation-page.vue b/src/admin/pages/item-edition-page.vue similarity index 95% rename from src/admin/pages/item-creation-page.vue rename to src/admin/pages/item-edition-page.vue index fbcd24779..14e9a4c1b 100644 --- a/src/admin/pages/item-creation-page.vue +++ b/src/admin/pages/item-edition-page.vue @@ -44,7 +44,7 @@ import { mapActions, mapGetters } from 'vuex' export default { - name: 'ItemCreationPage', + name: 'ItemEditionPage', data(){ return { itemId: Number, @@ -141,13 +141,6 @@ export default { }) .catch(error => console.log(error)); }, - loadExistingItem() { - // Puts loading on Item Loading - let loadingInstance = this.$loading({ text: 'Atualizando item...' }); - - this.loadMetadata(loadingInstance); - - }, loadMetadata(loadingInstance) { loadingInstance = this.$loading({ text: 'Carregando metadados...'}); // Obtains Item Field @@ -159,7 +152,7 @@ export default { computed: { fieldList(){ return this.getFields(); - } + } }, created(){ // Obtains collection ID @@ -167,12 +160,12 @@ export default { this.form.collectionId = this.collectionId; if (this.$route.fullPath.split("/").pop() == "new") { - console.log("CRIANDO ITEM"); this.createNewItem(); } else if (this.$route.fullPath.split("/").pop() == "edit") { let loadingInstance = this.$loading({ text: 'Carregando item...'}); + // Obtains current Item ID from URL this.pathArray = this.$route.fullPath.split("/").reverse(); this.itemId = this.pathArray[1]; @@ -183,7 +176,7 @@ export default { this.form.title = this.item.title; this.form.description = this.item.description; this.form.status = this.item.status; - + loadingInstance.close(); }); } diff --git a/src/admin/pages/item-page.vue b/src/admin/pages/item-page.vue index 82adea339..fd836d90f 100644 --- a/src/admin/pages/item-page.vue +++ b/src/admin/pages/item-page.vue @@ -33,9 +33,6 @@ export default { ...mapGetters('item', [ 'getItem' ]), - createItem() { - - } }, computed: { item(){ @@ -45,11 +42,11 @@ export default { created(){ // Obtains item and collection ID this.collectionId = this.$route.params.collection_id; - this.itemId = this.$route.params.id; - + this.itemId = this.$route.fullPath.split("/").pop(); + // Puts loading on Item Loading let loadingInstance = this.$loading({ text: 'Carregando item...' }); - + // Obtains Item this.fetchItem(this.itemId).then(res => { loadingInstance.close(); diff --git a/src/js/store/modules/item/actions.js b/src/js/store/modules/item/actions.js index 8d3628a21..fe1df8df1 100644 --- a/src/js/store/modules/item/actions.js +++ b/src/js/store/modules/item/actions.js @@ -58,7 +58,7 @@ export const fetchItem = ({ commit }, item_id) => { axios.get('/items/'+item_id) .then(res => { let item = res.data; - commit('setSingleItem', item); + commit('setItem', item); resolve( res.data ); }) .catch(error => { @@ -98,10 +98,10 @@ export const sendItem = ( { commit }, { collection_id, title, description, statu description: description, status: status }).then( res => { - commit('setSingleItem', { id: item_id, title: title, description: description, status: status }); + commit('setItem', { id: item_id, title: title, description: description, status: status }); resolve( res.data ); }).catch( error => { - commit('setSingleItem', { id: item_id, title: title, description: description, status: status }); + commit('setItem', { id: item_id, title: title, description: description, status: status }); reject( error.response ); }); diff --git a/src/js/store/modules/item/getters.js b/src/js/store/modules/item/getters.js index 1f77733fc..4a1987a3d 100644 --- a/src/js/store/modules/item/getters.js +++ b/src/js/store/modules/item/getters.js @@ -3,7 +3,7 @@ export const getFields = state => { return state.fields; } -export const getItem = state => { +export const getItem = state => { return state.item; } diff --git a/src/js/store/modules/item/mutations.js b/src/js/store/modules/item/mutations.js index 50937c47f..5c50ffeda 100644 --- a/src/js/store/modules/item/mutations.js +++ b/src/js/store/modules/item/mutations.js @@ -18,16 +18,6 @@ export const setSingleField = ( state, field) => { } } -export const setSingleItem = ( state, item) => { - let index = state.item.findIndex(itemItem => itemItem.id === item.id); - if ( index >= 0){ - //state.field[index] = field; - Vue.set( state.item, index, item ); - }else{ - state.item.push( item ); - } -} - export const setError = ( state, field ) => { let index = state.error.findIndex(itemMetadata => itemMetadata.field_id === field.field_id); if ( index >= 0){