Fixes Item Getter. Adds ItemPage with computed property..

This commit is contained in:
mateuswetah 2018-02-01 16:12:29 -02:00
parent b24c08c471
commit ffb1045754
6 changed files with 14 additions and 34 deletions

View File

@ -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: '/'}
]

View File

@ -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();
});
}

View File

@ -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();

View File

@ -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 );
});

View File

@ -3,7 +3,7 @@ export const getFields = state => {
return state.fields;
}
export const getItem = state => {
export const getItem = state => {
return state.item;
}

View File

@ -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){