Adds related objects to activities modal #261.

This commit is contained in:
Mateus Machado Luna 2019-09-30 12:52:11 -03:00
parent 63cd0fdce7
commit c0ead5b941
5 changed files with 163 additions and 84 deletions

View File

@ -117,7 +117,7 @@
@input="onChangeEnable($event, index)"/>
<a
:style="{ visibility: filter.collection_id != collectionId && !isRepositoryLevel? 'hidden' : 'visible' }"
@click.prevent="editFilter(filter)">
@click.prevent="toggleFilterEdition(filter.id)">
<span
v-tooltip="{
content: $i18n.get('edit'),
@ -353,6 +353,18 @@ export default {
components: {
FilterEditionForm
},
watch: {
'$route.query': {
handler(newQuery) {
if (newQuery.edit != undefined) {
let existingFilterIndex = this.activeFilterList.findIndex((filter) => filter.id == newQuery.edit);
if (existingFilterIndex >= 0)
this.editFilter(this.activeFilterList[existingFilterIndex])
}
},
immediate: true
}
},
beforeRouteLeave ( to, from, next ) {
let hasUnsavedForms = false;
for (let editForm in this.editForms) {
@ -524,7 +536,7 @@ export default {
this.selectedFilterType = {}
this.allowedFilterTypes = [];
this.editFilter(filter);
this.toggleFilterEdition(filter.id);
})
.catch((error) => {
this.$console.error(error);
@ -559,22 +571,18 @@ export default {
// this.deleteTemporaryFilter(this.newFilterIndex);
this.newFilterIndex = 0;
},
editFilter(filter) {
toggleFilterEdition(filterId) {
// Closing collapse
if (this.openedFilterId == filter.id) {
if (this.openedFilterId == filterId) {
this.openedFilterId = '';
this.$router.push({ query: {}});
// Opening collapse
} else {
if (this.openedFilterId == '' && this.choosenMetadatum.id != undefined) {
this.availableMetadata.push(this.choosenMetadatum);
this.choosenMetadatum = {};
this.allowedFilterTypes = [];
this.selectedFilterType = {};
// this.deleteTemporaryFilter(this.newFilterIndex);
this.newFilterIndex = 0;
this.$router.push({ query: { edit: filterId}})
}
},
editFilter(filter) {
this.openedFilterId = filter.id;
// First time opening
@ -588,17 +596,18 @@ export default {
this.editForms[this.openedFilterId].saved = false;
}
}
}
},
onEditionFinished() {
this.formWithErrors = '';
delete this.editForms[this.openedFilterId];
this.openedFilterId = '';
this.$router.push({ query: {}});
},
onEditionCanceled() {
this.formWithErrors = '';
delete this.editForms[this.openedFilterId];
this.openedFilterId = '';
this.$router.push({ query: {}});
},
getProperPreviewMinHeight() {
for (let filterType of this.allowedFilterTypes) {
@ -610,6 +619,55 @@ export default {
}
}
return 190;
},
refreshFilters() {
this.fetchFilters({
collectionId: this.collectionId,
isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: !this.isOnTheme,
includeDisabled: true,
}).then((resp) => {
resp.request
.then(() => {
this.isLoadingMetadatumTypes = true;
// Checks URL as router watcher would not wait for list to load
if (this.$route.query.edit != undefined) {
let existingFilterIndex = this.activeFilterList.findIndex((filter) => filter.id == this.$route.query.edit);
if (existingFilterIndex >= 0)
this.editFilter(this.activeFilterList[existingFilterIndex]);
}
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
// Needs to be done after activeFilterList exists to compare and remove chosen metadata.
this.fetchMetadata({
collectionId: this.collectionId,
isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: true
}).then((resp) => {
resp.request
.then(() => {
this.isLoadingMetadatumTypes = false;
this.updateListOfMetadata();
})
.catch(() => {
this.isLoadingMetadatumTypes = false;
});
// Search Request Token for cancelling
this.metadataSearchCancel = resp.source;
})
.catch(() => this.isLoadingMetadatumTypes = false);
})
.catch(() => this.isLoadingFilters = false);
// Search Request Token for cancelling
this.filtersSearchCancel = resp.source;
})
.catch(() => this.isLoadingFilters = false);
}
},
mounted() {
@ -643,46 +701,8 @@ export default {
if (this.filtersSearchCancel != undefined)
this.filtersSearchCancel.cancel('Filters search Canceled.');
this.fetchFilters({
collectionId: this.collectionId,
isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: !this.isOnTheme,
includeDisabled: true,
}).then((resp) => {
resp.request
.then(() => {
this.isLoadingMetadatumTypes = true;
// Cancels previous Request
if (this.metadataSearchCancel != undefined)
this.metadataSearchCancel.cancel('Metadata search Canceled.');
// Needs to be done after activeFilterList exists to compare and remove chosen metadata.
this.fetchMetadata({
collectionId: this.collectionId,
isRepositoryLevel: this.isRepositoryLevel,
isContextEdit: true
}).then((resp) => {
resp.request
.then(() => {
this.isLoadingMetadatumTypes = false;
this.updateListOfMetadata();
})
.catch(() => {
this.isLoadingMetadatumTypes = false;
});
// Search Request Token for cancelling
this.metadataSearchCancel = resp.source;
})
.catch(() => this.isLoadingMetadatumTypes = false);
})
.catch(() => this.isLoadingFilters = false);
// Search Request Token for cancelling
this.filtersSearchCancel = resp.source;
})
.catch(() => this.isLoadingFilters = false);
// Loads Filters
this.refreshFilters();
// On repository level we also fetch collection filters
if (this.isRepositoryLevel) {

View File

@ -594,7 +594,14 @@ export default {
},
addNewMetadatum(newMetadatum, newIndex) {
this.sendMetadatum({collectionId: this.collectionId, name: newMetadatum.name, metadatumType: newMetadatum.className, status: 'auto-draft', isRepositoryLevel: this.isRepositoryLevel, newIndex: newIndex})
this.sendMetadatum({
collectionId: this.collectionId,
name: newMetadatum.name,
metadatumType: newMetadatum.className,
status: 'auto-draft',
isRepositoryLevel: this.isRepositoryLevel,
newIndex: newIndex
})
.then((metadatum) => {
if (!this.isRepositoryLevel)

View File

@ -1,8 +1,11 @@
<template>
<div class="tainacan-modal-content">
<header class="tainacan-modal-title">
<header
v-if="!isLoadingActivity"
class="tainacan-modal-title">
<h2>{{ activity.title ? activity.title : $i18n.get('activity') }}</h2>
<hr>
<p>{{ activityCreationDate + ', ' + $i18n.get('info_by_inner') }} <strong> {{ activity.user_name }}</strong></p>
</header>
<b-loading
:is-full-page="false"
@ -13,8 +16,10 @@
class="modal-card-body">
<div class="content">
<p v-if="activity.description"><strong>{{ $i18n.get('label_activity_description') }}:</strong> {{ activity.description }}</p>
<p><strong>{{ $i18n.get('label_activity_creation_date') }}:</strong> {{ activityCreationDate }}</p>
<p><strong>{{ $i18n.get('label_activity_author') }}:</strong> {{ activity.user_name }}</p>
<p v-if="activity.object">
<strong>{{ $i18n.get('label_related_to') }}: </strong>
<span v-html="relatedToLink" />
</p>
</div>
<!-- LEGACY LOG API RETURN -->
@ -609,15 +614,54 @@
dateFormat: '',
activityCreationDate: '',
placeholderSquareImage: `${tainacan_plugin.base_url}/admin/images/placeholder_square.png`,
isLoadingActivity: false
isLoadingActivity: false,
adminFullURL: tainacan_plugin.admin_url + 'admin.php?page=tainacan_admin#',
}
},
components: {
FileItem
},
watch: {
'$route' (to, from) {
if (to !== from)
this.$parent.close();
}
},
computed: {
activity() {
return this.getActivity();
},
relatedToLink() {
switch(this.activity.object_type) {
case 'Tainacan\\Entities\\Collection':
return `${ this.$i18n.get('collection') }
<a href="${ this.adminFullURL + this.$routerHelper.getCollectionPath(this.activity.object_id) }">${ this.activity.object.name }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-collections"/></span>`;
case 'Tainacan\\Entities\\Taxonomy':
return `${ this.$i18n.get('taxonomy') }
<a href="${ this.adminFullURL + this.$routerHelper.getTaxonomyPath(this.activity.object_id) }">${ this.activity.object.name }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-taxonomies"/></span>`;
case 'Tainacan\\Entities\\Metadatum':
return `${ this.$i18n.get('metadatum') }
<a href="${ this.adminFullURL + (this.activity.object.collection_id == 'default' ? this.$routerHelper.getMetadataEditPath(this.activity.object_id) : this.$routerHelper.getCollectionMetadataEditPath(this.activity.object.collection_id, this.activity.object_id)) }">${ this.activity.object.name }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-metadata"/></span>`;
case 'Tainacan\\Entities\\Filter':
return `${ this.$i18n.get('filter') }
<a href="${ this.adminFullURL + (this.activity.object.collection_id == 'default' || this.activity.object.collection_id == 'filter_in_repository' ? this.$routerHelper.getFilterEditPath(this.activity.object_id) : this.$routerHelper.getCollectionFilterEditPath(this.activity.object.collection_id, this.activity.object_id)) }">${ this.activity.object.name }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-filters"/></span>`;
case 'Tainacan\\Entities\\Term':
return `${ this.$i18n.get('term') }
<a href="${ this.adminFullURL + this.$routerHelper.getTermEditPath(this.activity.object.taxonomy.split('tnc_tax_')[1], this.activity.object_id) }">${ this.activity.object.name }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-terms"/></span>`;
case 'Tainacan\\Entities\\Item':
return `${ this.$i18n.get('item') }
<a href="${ this.adminFullURL + this.$routerHelper.getItemEditPath(this.activity.object.collection_id, this.activity.object_id) }">${ this.activity.object.title }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-items"/></span>`;
case 'Tainacan\\Entities\\Item_Metadata_Entity':
return `${ this.$i18n.get('item') }
<a href="${ this.adminFullURL + this.$routerHelper.getItemEditPath(this.activity.object.collection_id, this.activity.item.id) }">${ this.activity.item.title }</a>
<span class="icon has-text-gray3">&nbsp;<i class="tainacan-icon tainacan-icon-20px tainacan-icon-items"/></span>`;
}
}
},
created() {
@ -635,9 +679,6 @@
},
notApproveActivity(){
this.$emit('notApproveActivity', this.activity.id);
},
undo(){
},
loadActivity() {
this.isLoadingActivity = true;
@ -677,11 +718,15 @@
display: flex;
flex-direction: column;
width: 100%;
p {
margin-right: auto;
}
}
.tainacan-modal-content {
width: auto;
min-height: 600px;
min-height: 500px;
p {
font-size: 0.875rem;
@ -689,10 +734,10 @@
}
.modal-card-body {
min-height: 400px;
min-height: 300px;
padding: 0;
.columns {
margin: 12px $page-side-padding;
margin: 6px $page-side-padding 0 $page-side-padding;
}
}

View File

@ -227,9 +227,6 @@ RouterHelperPlugin.install = function (Vue, options = {}) {
getFiltersPath(query) {
return '/filters/?' + qs.stringify(query);
},
getMetadataPath(query) {
return '/metadata/?' + qs.stringify(query);
},
getActivitiesPath(query) {
return '/activities/?' + qs.stringify(query);
},
@ -302,14 +299,23 @@ RouterHelperPlugin.install = function (Vue, options = {}) {
getItemEditPath(collectionId, itemId) {
return '/collections/' + collectionId + '/items/' + itemId + '/edit';
},
getFilterEditPath(id) {
return '/filters/' + id + '/edit';
getMetadataEditPath(metadatumId) {
return '/metadata/?edit=' + metadatumId;
},
getFilterEditPath(filterId) {
return '/filters/?edit=' + filterId;
},
getCollectionMetadataEditPath(collectionId, metadatumId) {
return '/collections/' + collectionId + '/metadata/?edit=' + metadatumId;
},
getCollectionFilterEditPath(collectionId, filterId) {
return '/collections/' + collectionId + '/filters/?edit=' + filterId;
},
getTaxonomyEditPath(id, isRecent) {
return isRecent != undefined ? '/taxonomies/' + id + '/edit?recent=true' : '/taxonomies/' + id + '/edit';
},
getTermEditPath(taxonomyId, termId) {
return '/taxonomies/' + taxonomyId + '/terms/' + termId + '/edit';
return '/taxonomies/' + taxonomyId + '/edit?tab=terms';
},
getImporterEditionPath(importerType) {
return '/importers/' + importerType;

View File

@ -434,6 +434,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'label_day' => __( 'Day', 'tainacan' ),
'label_month' => __( 'Month', 'tainacan' ),
'label_year' => __( 'Year', 'tainacan' ),
'label_related_to' => __( 'Related to', 'tainacan' ),
// Instructions. More complex sentences to guide user and placeholders
'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ),