Adds option to load collectionId from props in ItemsList

This commit is contained in:
Mateus Machado Luna 2018-04-13 13:00:06 -03:00
parent db1796ea03
commit 6a927ea27d
1 changed files with 16 additions and 12 deletions

View File

@ -11,14 +11,14 @@
id="button-create-item"
tag="button"
class="button is-secondary"
:to="{ path: $routerHelper.getNewItemPath(collectionId) }">
:to="{ path: $routerHelper.getNewItemPath(finalCollectionId) }">
{{ $i18n.getFrom('items', 'new_item') }}
</router-link>
</div>
<search-control
v-if="fields.length > 0 && (items.length != 0 || isLoadingItems)"
:is-repository-level="isRepositoryLevel"
:collection-id="collectionId"
:collection-id="finalCollectionId"
:table-fields="tableFields"
:pref-table-fields="prefTableFields"/>
</div>
@ -43,7 +43,7 @@
<p>{{ $i18n.get('info_there_is_no_filter' ) }}</p>
<router-link
id="button-create-filter"
:to="isRepositoryLevel ? $routerHelper.getNewFilterPath() : $routerHelper.getNewCollectionFilterPath(collectionId)"
:to="isRepositoryLevel ? $routerHelper.getNewFilterPath() : $routerHelper.getNewCollectionFilterPath(finalCollectionId)"
tag="button"
class="button is-secondary is-centered">
{{ $i18n.getFrom('filters', 'new_item') }}</router-link>
@ -57,7 +57,7 @@
:active.sync="isLoadingItems"/>
<items-list
v-if="!isLoadingItems && items.length > 0"
:collection-id="collectionId"
:collection-id="finalCollectionId"
:table-fields="tableFields"
:items="items"
:is-loading="isLoading"/>
@ -76,7 +76,7 @@
id="button-create-item"
tag="button"
class="button is-primary"
:to="{ path: $routerHelper.getNewItemPath(collectionId) }">
:to="{ path: $routerHelper.getNewItemPath(finalCollectionId) }">
{{ $i18n.getFrom('items', 'new_item') }}
</router-link>
</div>
@ -101,7 +101,7 @@ export default {
name: 'ItemsPage',
data(){
return {
collectionId: Number,
finalCollectionId: Number,
isRepositoryLevel: false,
tableFields: [],
prefTableFields: [],
@ -111,6 +111,9 @@ export default {
hasFiltered: false
}
},
props: {
collectionId: Number
},
components: {
SearchControl,
ItemsList,
@ -146,8 +149,9 @@ export default {
}
},
created() {
this.collectionId = this.$route.params.collectionId;
this.isRepositoryLevel = (this.collectionId == undefined);
this.$console.log(this.collectionId);
this.finalCollectionId = (this.collectionId != undefined && this.collectionId != null && this.collectionId != '' ) ? this.collectionId : this.$route.params.collectionId;
this.isRepositoryLevel = (this.finalCollectionId == undefined);
eventBusSearch.$on('isLoadingItems', isLoadingItems => {
this.isLoadingItems = isLoadingItems;
@ -158,12 +162,12 @@ export default {
});
this.isLoadingFilters = true;
this.fetchFilters( { collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true })
this.fetchFilters( { collectionId: this.finalCollectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true })
.then(() => this.isLoadingFilters = false)
.catch(() => this.isLoadingFilters = false);
this.isLoadingFields = true;
this.fetchFields({ collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }).then(() => {
this.fetchFields({ collectionId: this.finalCollectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: false }).then(() => {
this.tableFields.push({ name: this.$i18n.get('label_thumbnail'), field: 'row_thumbnail', field_type: undefined, slug: 'featured_image', id: undefined, visible: true });
for (let field of this.fields) {
@ -176,12 +180,12 @@ export default {
this.tableFields.push({ name: this.$i18n.get('label_actions'), field: 'row_actions', field_type: undefined, slug: 'actions', id: undefined, visible: true });
//this.prefTableFields = this.tableFields;
// this.$userPrefs.get('table_columns_' + this.collectionId)
// this.$userPrefs.get('table_columns_' + this.finalCollectionId)
// .then((value) => {
// this.prefTableFields = value;
// })
// .catch((error) => {
// this.$userPrefs.set('table_columns_' + this.collectionId, this.prefTableFields, null);
// this.$userPrefs.set('table_columns_' + this.finalCollectionId, this.prefTableFields, null);
// });
this.isLoadingFields = false;