Merge branch 'feature/200' into develop
This commit is contained in:
commit
e4ef756f90
|
@ -279,9 +279,6 @@ class Admin {
|
|||
|
||||
$settings['wp_post_types'] = $wp_post_types;
|
||||
|
||||
// add an alternative to enable select all items in all pages while we temporarly disable bulk edit for all (see #199)
|
||||
$settings['enable_select_all_items_pages'] = defined('TAINACAN_ENABLE_SELECT_ALL_ITEMS_PAGES') ? TAINACAN_ENABLE_SELECT_ALL_ITEMS_PAGES : false;
|
||||
|
||||
return $settings;
|
||||
|
||||
}
|
||||
|
|
|
@ -80,20 +80,17 @@
|
|||
type="text"
|
||||
disabled />
|
||||
|
||||
<!-- Replace or Redefine in case of multiple -->
|
||||
<!-- Replace -->
|
||||
<template
|
||||
v-if="bulkEditionProcedures[criterion] &&
|
||||
bulkEditionProcedures[criterion].metadatumID &&
|
||||
(bulkEditionProcedures[criterion].action == editionActionsForMultiple.replace ||
|
||||
(bulkEditionProcedures[criterion].action == editionActionsForMultiple.redefine &&
|
||||
getMetadataByID(bulkEditionProcedures[criterion].metadatumID).multiple == 'yes'))">
|
||||
bulkEditionProcedures[criterion].action == editionActionsForMultiple.replace">
|
||||
|
||||
<component
|
||||
:forced-component-type="getMetadataByID(bulkEditionProcedures[criterion].metadatumID)
|
||||
.metadata_type_object.component.includes('taxonomy') ? 'tainacan-taxonomy-tag-input' : ''"
|
||||
:allow-new="false"
|
||||
:allow-select-to-create="getMetadataByID(bulkEditionProcedures[criterion].metadatumID)
|
||||
.metadata_type_options.allow_new_terms === 'yes'"
|
||||
:allow-select-to-create="false"
|
||||
:maxtags="1"
|
||||
:class="{'is-field-history': bulkEditionProcedures[criterion].isDone}"
|
||||
:disabled="bulkEditionProcedures[criterion].isDone"
|
||||
|
@ -109,11 +106,18 @@
|
|||
</small>
|
||||
</div>
|
||||
|
||||
<b-input
|
||||
<component
|
||||
:forced-component-type="getMetadataByID(bulkEditionProcedures[criterion].metadatumID)
|
||||
.metadata_type_object.component.includes('taxonomy') ? 'tainacan-taxonomy-tag-input' : ''"
|
||||
:allow-new="false"
|
||||
:allow-select-to-create="getMetadataByID(bulkEditionProcedures[criterion].metadatumID)
|
||||
.metadata_type_options.allow_new_terms === 'yes'"
|
||||
:maxtags="1"
|
||||
:class="{'is-field-history': bulkEditionProcedures[criterion].isDone}"
|
||||
:disabled="bulkEditionProcedures[criterion].isDone"
|
||||
:is="getMetadataByID(bulkEditionProcedures[criterion].metadatumID).metadata_type_object.component"
|
||||
:metadatum="{metadatum: getMetadataByID(bulkEditionProcedures[criterion].metadatumID)}"
|
||||
class="tainacan-bulk-edition-field tainacan-bulk-edition-field-not-last"
|
||||
type="text"
|
||||
@input="addToBulkEditionProcedures($event, 'newValue', criterion)"
|
||||
/>
|
||||
</template>
|
||||
|
@ -157,15 +161,6 @@
|
|||
/>
|
||||
</template>
|
||||
|
||||
<!-- DISABLED FIELD -->
|
||||
<!--<template v-else>-->
|
||||
<!--<input-->
|
||||
<!--style="border: none !important; background-color: white !important;"-->
|
||||
<!--class="tainacan-bulk-edition-field tainacan-bulk-edition-field-last"-->
|
||||
<!--type="text"-->
|
||||
<!--disabled >-->
|
||||
<!--</template>-->
|
||||
|
||||
<div
|
||||
:style="{
|
||||
marginRight: !bulkEditionProcedures[criterion].isDone && !bulkEditionProcedures[criterion].isExecuting ? '-7.4px': 0
|
||||
|
@ -188,7 +183,7 @@
|
|||
</button>
|
||||
|
||||
<div
|
||||
v-if="bulkEditionProcedures[criterion].isDone && bulkEditionProcedures[criterion].actionResult >= totalItems"
|
||||
v-if="bulkEditionProcedures[criterion].isDone"
|
||||
@mouseover="$set(bulkEditionProcedures[criterion], 'tooltipShow', !bulkEditionProcedures[criterion].tooltipShow)"
|
||||
class="is-pulled-right">
|
||||
<b-tooltip
|
||||
|
@ -198,60 +193,16 @@
|
|||
size="is-small"
|
||||
position="is-left"
|
||||
animated
|
||||
multilined
|
||||
:label="bulkEditionProcedures[criterion].actionResult.constructor.name !== 'Object' && bulkEditionProcedures[criterion].actionResult === 1 ? `${bulkEditionProcedures[criterion].actionResult} ${$i18n.get('info_item_affected')}` : `${bulkEditionProcedures[criterion].actionResult} ${$i18n.get('info_items_affected')}`">
|
||||
:label="$i18n.get('info_bulk_edition_process_added')">
|
||||
<span class="icon">
|
||||
<i class="has-text-success tainacan-icon tainacan-icon-20px tainacan-icon-approvedcircle"/>
|
||||
</span>
|
||||
</b-tooltip>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="bulkEditionProcedures[criterion].isDone && bulkEditionProcedures[criterion].actionResult < totalItems"
|
||||
@mouseover="$set(bulkEditionProcedures[criterion], 'tooltipShow', !bulkEditionProcedures[criterion].tooltipShow)"
|
||||
class="is-pulled-right">
|
||||
<b-tooltip
|
||||
:active="bulkEditionProcedures[criterion].tooltipShow"
|
||||
always
|
||||
class="is-yellow2"
|
||||
size="is-small"
|
||||
position="is-left"
|
||||
animated
|
||||
multilined
|
||||
:label="bulkEditionProcedures[criterion].actionResult.constructor.name !== 'Object' && bulkEditionProcedures[criterion].actionResult === 1 ? `${bulkEditionProcedures[criterion].actionResult} ${$i18n.get('info_item_affected')}` : `${bulkEditionProcedures[criterion].actionResult} ${$i18n.get('info_items_affected')}`">
|
||||
<span class="icon">
|
||||
<i class="has-text-yello2 tainacan-icon tainacan-icon-20px tainacan-icon-alertcircle"/>
|
||||
</span>
|
||||
</b-tooltip>
|
||||
</div>
|
||||
|
||||
<button
|
||||
:disabled="!groupID"
|
||||
v-if="bulkEditionProcedures[criterion].isDoneWithError &&
|
||||
!bulkEditionProcedures[criterion].isExecuting"
|
||||
@click="executeBulkEditionProcedure(criterion)"
|
||||
@mousedown="$set(bulkEditionProcedures[criterion], 'tooltipShow', !bulkEditionProcedures[criterion].tooltipShow)"
|
||||
@mouseup="$set(bulkEditionProcedures[criterion], 'tooltipShow', !bulkEditionProcedures[criterion].tooltipShow)"
|
||||
class="button is-white is-pulled-right">
|
||||
<b-tooltip
|
||||
:active="bulkEditionProcedures[criterion].tooltipShow"
|
||||
always
|
||||
class="is-red2"
|
||||
size="is-small"
|
||||
position="is-bottom"
|
||||
animated
|
||||
multilined
|
||||
:label="bulkEditionProcedures[criterion].actionResult.constructor.name === 'Object' ? (bulkEditionProcedures[criterion].actionResult.error_message ? bulkEditionProcedures[criterion].actionResult.error_message : bulkEditionProcedures[criterion].actionResult.message) : ''">
|
||||
<span class="icon">
|
||||
<i class="has-text-danger tainacan-icon tainacan-icon-20px tainacan-icon-processerror"/>
|
||||
</span>
|
||||
</b-tooltip>
|
||||
</button>
|
||||
|
||||
<button
|
||||
:disabled="!groupID"
|
||||
v-if="!bulkEditionProcedures[criterion].isDoneWithError &&
|
||||
!bulkEditionProcedures[criterion].isDone &&
|
||||
v-if="!bulkEditionProcedures[criterion].isDone &&
|
||||
!bulkEditionProcedures[criterion].isExecuting &&
|
||||
bulkEditionProcedures[criterion].metadatumID &&
|
||||
bulkEditionProcedures[criterion].action"
|
||||
|
@ -276,6 +227,15 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<a
|
||||
:disabled="dones.every((item) => item === true) === false"
|
||||
@click="addEditionCriterion()"
|
||||
class="has-text-right is-block add-link">
|
||||
<span class="icon is-small">
|
||||
<i class="tainacan-icon has-text-secondary tainacan-icon-add"/>
|
||||
</span>
|
||||
{{ $i18n.get('new_action') }}
|
||||
</a>
|
||||
</div>
|
||||
<!--<pre>{{ bulkEditionProcedures }}</pre>-->
|
||||
|
||||
|
@ -291,17 +251,11 @@
|
|||
</button>
|
||||
</p>
|
||||
<p class="control">
|
||||
<button
|
||||
class="button is-turquoise5"
|
||||
:disabled="dones.every((item) => item === true) === false"
|
||||
@click="addEditionCriterion()">
|
||||
{{ $i18n.get('new_action') }}
|
||||
</button>
|
||||
<button
|
||||
:disabled="dones.every((item) => item === true) === false"
|
||||
class="button is-success"
|
||||
type="button"
|
||||
@click="$eventBusSearch.loadItems(); $parent.close();">
|
||||
@click="$root.$emit('openProcessesPopup'); $eventBusSearch.loadItems(); $parent.close();">
|
||||
{{ $i18n.get('finish') }}
|
||||
</button>
|
||||
</p>
|
||||
|
@ -320,7 +274,7 @@
|
|||
totalItems: Array,
|
||||
objectType: String,
|
||||
selectedForBulk: Object,
|
||||
collectionID: Number,
|
||||
collectionID: Number
|
||||
},
|
||||
created(){
|
||||
if (this.collectionID){
|
||||
|
@ -385,9 +339,7 @@
|
|||
bulkEditionProcedures: {
|
||||
1: {
|
||||
isDone: false,
|
||||
isDoneWithError: false,
|
||||
isExecuting: false,
|
||||
actionResult: '',
|
||||
totalItemsEditedWithSuccess: 0,
|
||||
tooltipShow: true,
|
||||
}
|
||||
|
@ -400,8 +352,7 @@
|
|||
},
|
||||
methods: {
|
||||
...mapGetters('bulkedition', [
|
||||
'getGroupID',
|
||||
'getActionResult'
|
||||
'getGroupID'
|
||||
]),
|
||||
...mapActions('bulkedition', [
|
||||
'createEditGroup',
|
||||
|
@ -419,22 +370,10 @@
|
|||
'getMetadata'
|
||||
]),
|
||||
finalizeProcedure(criterion){
|
||||
this.$set(this.bulkEditionProcedures[criterion], 'actionResult', this.getActionResult());
|
||||
|
||||
let withError = false;
|
||||
|
||||
if(this.bulkEditionProcedures[criterion].actionResult.constructor.name === 'Object' &&
|
||||
(this.bulkEditionProcedures[criterion].actionResult.data &&
|
||||
this.bulkEditionProcedures[criterion].actionResult.data.status.toString().split('')[0] != 2) ||
|
||||
this.bulkEditionProcedures[criterion].actionResult.error_message) {
|
||||
|
||||
withError = true;
|
||||
} else {
|
||||
this.$set(this.bulkEditionProcedures[criterion], 'totalItemsEditedWithSuccess', this.actionResult);
|
||||
}
|
||||
|
||||
this.$set(this.bulkEditionProcedures[criterion], 'isDone', !withError);
|
||||
this.$set(this.bulkEditionProcedures[criterion], 'isDoneWithError', withError);
|
||||
this.$set(this.bulkEditionProcedures[criterion], 'isDone', true);
|
||||
|
||||
let index = this.editionCriteria.indexOf(criterion);
|
||||
|
||||
|
@ -523,9 +462,7 @@
|
|||
this.bulkEditionProcedures = Object.assign({}, this.bulkEditionProcedures, {
|
||||
[`${aleatoryKey}`]: {
|
||||
isDone: false,
|
||||
isDoneWithError: false,
|
||||
isExecuting: false,
|
||||
actionResult: '',
|
||||
totalItemsEditedWithSuccess: 0,
|
||||
tooltipShow: true,
|
||||
}
|
||||
|
@ -603,7 +540,7 @@
|
|||
}
|
||||
|
||||
.this-tainacan-modal-content .form-submit {
|
||||
padding: 160px 0 0.4em 0 !important;
|
||||
padding: 42px 0 0.4em 0 !important;
|
||||
}
|
||||
|
||||
.no-overflow-modal-card-body {
|
||||
|
@ -698,6 +635,7 @@
|
|||
border: none !important;
|
||||
background-color: white !important;
|
||||
min-height: auto !important;
|
||||
line-height: 1.5rem;
|
||||
}
|
||||
|
||||
.select {
|
||||
|
|
|
@ -153,7 +153,7 @@
|
|||
style="margin-left: auto;"
|
||||
class="control">
|
||||
<button
|
||||
:disabled="!(uploadedItems.length > 0 && uploadedItems.length == amountFinished) || isCreatingBulkEditGroup"
|
||||
:disabled="!(uploadedItems.length > 0 && uploadedItems.length == amountFinished)"
|
||||
class="button is-secondary"
|
||||
:class="{'is-loading': isCreatingSequenceEditGroup }"
|
||||
@click.prevent="sequenceEditGroup()"
|
||||
|
@ -161,10 +161,9 @@
|
|||
</div>
|
||||
<div class="control">
|
||||
<button
|
||||
:disabled="!(uploadedItems.length > 0 && uploadedItems.length == amountFinished) || isCreatingSequenceEditGroup"
|
||||
:disabled="!(uploadedItems.length > 0 && uploadedItems.length == amountFinished)"
|
||||
class="button is-secondary"
|
||||
:class="{'is-loading': isCreatingBulkEditGroup }"
|
||||
@click.prevent="createBulkEditGroup()"
|
||||
@click.prevent="openBulkEditionModal()"
|
||||
type="submit">{{ $i18n.get('label_bulk_edit_items') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -188,6 +187,7 @@
|
|||
<script>
|
||||
import { mapActions, mapGetters } from 'vuex';
|
||||
import CustomDialog from '../other/custom-dialog.vue';
|
||||
import BulkEditionModal from '../bulk-edition/bulk-edition-modal.vue';
|
||||
|
||||
export default {
|
||||
name: 'ItemBulkEditionForm',
|
||||
|
@ -195,7 +195,6 @@ export default {
|
|||
return {
|
||||
collectionId: '',
|
||||
isLoading: false,
|
||||
isCreatingBulkEditGroup: false,
|
||||
isCreatingSequenceEditGroup: false,
|
||||
submitedFileList: [],
|
||||
thumbPlaceholderPath: tainacan_plugin.base_url + '/admin/images/placeholder_square.png',
|
||||
|
@ -227,8 +226,8 @@ export default {
|
|||
]),
|
||||
...mapActions('bulkedition', [
|
||||
'createEditGroup',
|
||||
'setStatusInBulk',
|
||||
'setBulkAddItems'
|
||||
'createSequenceEditGroup',
|
||||
'setStatusInBulk'
|
||||
]),
|
||||
uploadFiles() {
|
||||
|
||||
|
@ -237,7 +236,7 @@ export default {
|
|||
// Creates draft Item
|
||||
let data = {
|
||||
collection_id: this.collectionId,
|
||||
status: 'auto-draft',
|
||||
status: 'draft',
|
||||
title: file.name
|
||||
};
|
||||
this.sendItem(data)
|
||||
|
@ -273,12 +272,11 @@ export default {
|
|||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
let index = this.uploadedItems.findIndex(existingItem => existingItem.id === item.id);
|
||||
if ( index >= 0)
|
||||
this.uploadedItems.splice(index, 1);
|
||||
|
||||
item.errorMessage = error.data.message;
|
||||
item.errorMessage = error.data && error.data.message ? error.data.message : this.$i18n.get('info_error_upload');
|
||||
this.$buefy.toast.open({
|
||||
message: item.errorMessage + ": " + file.name,
|
||||
type: 'is-danger',
|
||||
|
@ -299,41 +297,31 @@ export default {
|
|||
sequenceEditGroup() {
|
||||
let onlyItemIds = this.uploadedItems.map(item => item.id);
|
||||
this.isCreatingSequenceEditGroup = true;
|
||||
this.createEditGroup({
|
||||
this.createSequenceEditGroup({
|
||||
object: onlyItemIds,
|
||||
collectionID: this.collectionId
|
||||
}).then((group) => {
|
||||
let sequenceId = group.id;
|
||||
this.setStatusInBulk({
|
||||
groupID: sequenceId,
|
||||
collectionID: this.collectionId,
|
||||
bodyParams: { value: 'draft' }
|
||||
}).then(() => {
|
||||
this.isCreatingSequenceEditGroup = true;
|
||||
this.isCreatingSequenceEditGroup = false;
|
||||
this.$router.push(this.$routerHelper.getCollectionSequenceEditPath(this.collectionId, sequenceId, 1));
|
||||
});
|
||||
});
|
||||
},
|
||||
createBulkEditGroup() {
|
||||
// Sends to store, so we can retrieve in next page.
|
||||
this.setBulkAddItems(this.uploadedItems);
|
||||
openBulkEditionModal() {
|
||||
|
||||
let onlyItemIds = this.uploadedItems.map(item => item.id);
|
||||
|
||||
this.isCreatingBulkEditGroup = true;
|
||||
this.createEditGroup({
|
||||
object: onlyItemIds,
|
||||
this.$buefy.modal.open({
|
||||
parent: this,
|
||||
component: BulkEditionModal,
|
||||
props: {
|
||||
modalTitle: this.$i18n.get('info_editing_items_in_bulk'),
|
||||
totalItems: onlyItemIds.length,
|
||||
selectedForBulk: onlyItemIds,
|
||||
objectType: this.$i18n.get('items'),
|
||||
collectionID: this.collectionId
|
||||
}).then((group) => {
|
||||
let groupId = group.id;
|
||||
this.setStatusInBulk({
|
||||
groupID: groupId,
|
||||
collectionID: this.collectionId,
|
||||
bodyParams: { value: 'draft' }
|
||||
}).then(() => {
|
||||
this.isCreatingBulkEditGroup = false;
|
||||
this.$router.push(this.$routerHelper.getItemMetadataBulkAddPath(this.collectionId, groupId));
|
||||
});
|
||||
},
|
||||
width: 'calc(100% - 8.333333333%)',
|
||||
trapFocus: true
|
||||
});
|
||||
},
|
||||
deleteOneItem(itemId, index) {
|
||||
|
@ -363,7 +351,6 @@ export default {
|
|||
this.collectionId = this.$route.params.collectionId;
|
||||
|
||||
this.cleanFiles();
|
||||
this.setBulkAddItems([]);
|
||||
|
||||
// Updates Collection BreadCrumb
|
||||
this.$root.$emit('onCollectionBreadCrumbUpdate', [
|
||||
|
|
|
@ -863,7 +863,7 @@ export default {
|
|||
});
|
||||
|
||||
// Obtains current Sequence Group Info
|
||||
this.fetchGroup({ collectionId: this.collectionId, groupId: this.sequenceId });
|
||||
this.fetchSequenceGroup({ collectionId: this.collectionId, groupId: this.sequenceId });
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -896,7 +896,8 @@ export default {
|
|||
]),
|
||||
...mapActions('bulkedition', [
|
||||
'fetchItemIdInSequence',
|
||||
'fetchGroup'
|
||||
'fetchGroup',
|
||||
'fetchSequenceGroup'
|
||||
]),
|
||||
...mapGetters('bulkedition', [
|
||||
'getItemIdInSequence',
|
||||
|
@ -1372,7 +1373,7 @@ export default {
|
|||
});
|
||||
|
||||
// Obtains current Sequence Group Info
|
||||
this.fetchGroup({ collectionId: this.collectionId, groupId: this.sequenceId });
|
||||
this.fetchSequenceGroup({ collectionId: this.collectionId, groupId: this.sequenceId });
|
||||
}
|
||||
|
||||
// Sets feedback variables
|
||||
|
|
|
@ -1,690 +0,0 @@
|
|||
<template>
|
||||
<div>
|
||||
<b-loading
|
||||
:is-full-page="false"
|
||||
:active.sync="showLoading"
|
||||
:can-cancel="false"/>
|
||||
<div class="tainacan-page-title">
|
||||
<h1><span class="status-tag">{{ $i18n.get('status_' + status) }}</span>{{ $i18n.get('label_bulk_edit_items') }}</h1>
|
||||
<a
|
||||
@click="$router.go(-1)"
|
||||
class="back-link has-text-secondary">
|
||||
{{ $i18n.get('back') }}
|
||||
</a>
|
||||
<hr>
|
||||
</div>
|
||||
<form
|
||||
v-if="collection && collection.current_user_can_bulk_edit"
|
||||
class="tainacan-form"
|
||||
label-width="120px">
|
||||
|
||||
<div class="columns">
|
||||
<div class="column is-half document-list">
|
||||
<div class="section-label">
|
||||
<label>{{ $i18n.get('label_added_items') }}
|
||||
<span
|
||||
v-if="!isLoadingGroupInfo && bulkEditGroup.items_count != undefined"
|
||||
class="has-text-gray has-text-weight-normal">{{ ' (' + bulkEditGroup.items_count + ')' }}</span>
|
||||
</label>
|
||||
</div>
|
||||
<br>
|
||||
<p v-if="items.length <= 0 && !isLoadingGroupInfo && bulkEditGroup.items_count == 1">
|
||||
{{ $i18n.get('info_there_is_one_item_being_edited') }}
|
||||
</p>
|
||||
<p v-if="items.length <= 0 && !isLoadingGroupInfo && bulkEditGroup.items_count > 1">
|
||||
{{ $i18n.getWithVariables('info_there_are_%s_items_being_edited', [bulkEditGroup.items_count]) }}
|
||||
</p>
|
||||
<p v-if="items.length <= 0 && !isLoadingGroupInfo">
|
||||
{{ $i18n.get('info_no_preview_found') }}
|
||||
</p>
|
||||
<transition-group name="item-appear">
|
||||
<div
|
||||
class="document-item"
|
||||
v-for="(item) of items"
|
||||
:key="item.id">
|
||||
<img
|
||||
v-if="item.document!= undefined && item.document != '' && item.document_type != 'empty'"
|
||||
class="document-thumb"
|
||||
:alt="$i18n.get('label_thumbnail') + ': ' + item.title"
|
||||
:src="item.thumbnail['tainacan-small'] ? item.thumbnail['tainacan-small'][0] : (item.thumbnail.thumbnail ? item.thumbnail.thumbnail[0] : thumbPlaceholderPath)" >
|
||||
<span
|
||||
class="document-name"
|
||||
v-html="item.title" />
|
||||
<span
|
||||
v-if="item.errorMessage != undefined"
|
||||
class="help is-danger">
|
||||
{{ item.errorMessage }}
|
||||
</span>
|
||||
</div>
|
||||
</transition-group>
|
||||
</div>
|
||||
<div class="column is-half">
|
||||
|
||||
<!-- Visibility (status public or private) -------------------------------- -->
|
||||
<div class="section-label">
|
||||
<label>{{ $i18n.get('label_status') }}</label>
|
||||
<span class="required-metadatum-asterisk">*</span>
|
||||
<help-button
|
||||
:title="$i18n.get('label_status')"
|
||||
:message="$i18n.get('info_visibility_helper')"/>
|
||||
</div>
|
||||
<div class="section-status">
|
||||
<div class="field has-addons">
|
||||
<b-radio
|
||||
v-for="(statusOption, index) of $statusHelper.getStatuses().filter(option => { return option.value != 'trash' })"
|
||||
:key="index"
|
||||
v-model="status"
|
||||
@input="changeStatus($event)"
|
||||
:value="statusOption.slug"
|
||||
:native-value="statusOption.slug">
|
||||
<span class="icon">
|
||||
<i
|
||||
class="tainacan-icon"
|
||||
:class="$statusHelper.getIcon(statusOption.slug)"/>
|
||||
</span> {{ statusOption.name }}
|
||||
</b-radio>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Metadata from Collection-------------------------------- -->
|
||||
<span class="section-label">
|
||||
<label>{{ $i18n.get('metadata') }}</label>
|
||||
</span>
|
||||
<br>
|
||||
<a
|
||||
class="collapse-all"
|
||||
@click="toggleCollapseAll()">
|
||||
{{ collapseAll ? $i18n.get('label_collapse_all') : $i18n.get('label_expand_all') }}
|
||||
<b-icon :icon=" collapseAll ? 'menu-down' : 'menu-right'" />
|
||||
</a>
|
||||
|
||||
<template
|
||||
v-if="!showLoading"
|
||||
v-for="(metadatum, index) of metadata">
|
||||
<b-field
|
||||
:key="index"
|
||||
:addons="false"
|
||||
:message="getErrorMessage(formErrors[metadatum.id])"
|
||||
:type="getErrorMessage(formErrors[metadatum.id]) != '' ? 'is-danger' : ''">
|
||||
<span
|
||||
class="collapse-handle"
|
||||
@click="changeCollapse(!metadatumCollapses[index], index)">
|
||||
<b-icon
|
||||
type="is-secondary"
|
||||
:icon="metadatumCollapses[index] ? 'menu-down' : 'menu-right'" />
|
||||
<label class="label">{{ metadatum.name }}</label>
|
||||
<span
|
||||
v-if="metadatum.required == 'yes'"
|
||||
class="required-metadatum-asterisk">*</span>
|
||||
<span class="metadata-type">({{ metadatum.metadata_type_object.metadata }})</span>
|
||||
<help-button
|
||||
:title="metadatum.name"
|
||||
:message="metadatum.description"/>
|
||||
</span>
|
||||
<transition name="filter-item">
|
||||
<div v-show="metadatumCollapses[index]">
|
||||
<component
|
||||
:forced-component-type="false"
|
||||
:allow-new="false"
|
||||
:allow-select-to-create="metadatum.metadata_type_options.allow_new_terms === 'yes'"
|
||||
:maxtags="1"
|
||||
:id="metadatum.metadata_type_object.component + '-' + metadatum.slug"
|
||||
:is="metadatum.metadata_type_object.component"
|
||||
:metadatum="{ metadatum: metadatum }"
|
||||
:value="itemMetadata[index].value"
|
||||
@input="clearErrorMessage(metadatum.id); bulkEdit($event, metadatum)"/>
|
||||
</div>
|
||||
</transition>
|
||||
</b-field>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="footer">
|
||||
<!-- Last Updated Info -->
|
||||
<div class="update-info-section">
|
||||
<p v-if="!isExecutingBulkEdit && lastUpdated != ''">
|
||||
{{ ($i18n.get('info_updated_at') + ' ' + lastUpdated) }}
|
||||
<span class="help is-danger">{{ formErrorMessage }}</span>
|
||||
</p>
|
||||
<p v-if="!isExecutingBulkEdit && lastUpdated == ''">
|
||||
<span class="help is-danger">{{ formErrorMessage }}</span>
|
||||
</p>
|
||||
<p
|
||||
class="update-warning"
|
||||
v-if="isExecutingBulkEdit">
|
||||
<b-icon icon="autorenew" />{{ $i18n.get('info_updating_metadata_values') }}
|
||||
<span class="help is-danger">{{ formErrorMessage }}</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="form-submission-footer">
|
||||
<button
|
||||
v-if="status != 'trash'"
|
||||
@click="onSubmit('trash')"
|
||||
type="button"
|
||||
:class="{ 'is-loading': isTrashingItems }"
|
||||
class="button is-outlined">{{ $i18n.get('label_send_to_trash') }}</button>
|
||||
<button
|
||||
v-if="status == 'trash'"
|
||||
class="button is-secondary"
|
||||
:class="{'is-loading': isCreatingSequenceEditGroup || isTrashingItems }"
|
||||
@click.prevent="status = previousStatus; changeStatus(previousStatus)"
|
||||
type="submit">{{ $i18n.get('label_recover_from_trash') }}</button>
|
||||
<button
|
||||
:disabled="status == 'trash'"
|
||||
class="button is-secondary"
|
||||
:class="{'is-loading': isCreatingSequenceEditGroup }"
|
||||
@click.prevent="sequenceEditGroup()"
|
||||
type="submit">{{ $i18n.get('label_sequence_edit_items') }}</button>
|
||||
<button
|
||||
:disabled="formErrorMessage != undefined && formErrorMessage != ''"
|
||||
@click="onSubmit(status)"
|
||||
type="button"
|
||||
:class="{ 'is-loading': isPublishingItems }"
|
||||
class="button is-success">{{ $i18n.get('finish') }}</button>
|
||||
</div>
|
||||
</footer>
|
||||
</form>
|
||||
<template v-if="collection && !collection.current_user_can_bulk_edit">
|
||||
<section class="section">
|
||||
<div class="content has-text-grey has-text-centered">
|
||||
<p>
|
||||
<span class="icon">
|
||||
<i class="tainacan-icon tainacan-icon-30px tainacan-icon-collection"/>
|
||||
</span>
|
||||
</p>
|
||||
<p>{{ $i18n.get('info_can_not_bulk_edit_items_collection') }}</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapActions, mapGetters } from 'vuex';
|
||||
import CustomDialog from '../other/custom-dialog.vue';
|
||||
|
||||
export default {
|
||||
name: 'ItemMetadataBulkEditionForm',
|
||||
data(){
|
||||
return {
|
||||
collectionId: '',
|
||||
isLoadingItems: false,
|
||||
isLoadingMetadata: false,
|
||||
isLoadingItemMetadata: false,
|
||||
isLoadingGroupInfo: false,
|
||||
isExecutingBulkEdit: false,
|
||||
isCreatingSequenceEditGroup: false,
|
||||
isUpdatingItems: false,
|
||||
isTrashingItems: false,
|
||||
isPublishingItems: false,
|
||||
collapseAll: true,
|
||||
thumbPlaceholderPath: tainacan_plugin.base_url + '/admin/images/placeholder_square.png',
|
||||
metadatumCollapses: [],
|
||||
itemMetadata: [],
|
||||
formErrors: {},
|
||||
status: 'draft',
|
||||
previousStatus: 'draft',
|
||||
groupID: null,
|
||||
formErrorMessage: '',
|
||||
copyItemId: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
metadata() {
|
||||
return this.getMetadata();
|
||||
},
|
||||
lastUpdated() {
|
||||
return this.getLastUpdated();
|
||||
},
|
||||
items() {
|
||||
return this.getBulkAddItems();
|
||||
},
|
||||
bulkEditGroup() {
|
||||
return this.getGroup();
|
||||
},
|
||||
showLoading() {
|
||||
return this.isLoadingMetadata || this.isLoadingItemMetadata;
|
||||
},
|
||||
collection() {
|
||||
return this.getCollection()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions('item', {
|
||||
'updateItem': 'updateItem',
|
||||
'fetchItemMetadata':'fetchMetadata'
|
||||
}),
|
||||
...mapActions('metadata', [
|
||||
'fetchMetadata',
|
||||
]),
|
||||
...mapGetters('metadata', [
|
||||
'getMetadata',
|
||||
]),
|
||||
...mapGetters('collection', [
|
||||
'getCollection',
|
||||
]),
|
||||
...mapActions('bulkedition', [
|
||||
'setValueInBulk',
|
||||
'addValueInBulk',
|
||||
'replaceValueInBulk',
|
||||
'redefineValueInBulk',
|
||||
'setStatusInBulk',
|
||||
'removeValueInBulk',
|
||||
'createEditGroup',
|
||||
'deleteItemsInBulk',
|
||||
'trashItemsInBulk',
|
||||
'fetchItemIdInSequence',
|
||||
'fetchGroup'
|
||||
]),
|
||||
...mapGetters('bulkedition', [
|
||||
'getItemIdInSequence',
|
||||
'getGroup',
|
||||
'getLastUpdated',
|
||||
'getBulkAddItems'
|
||||
]),
|
||||
toggleCollapseAll() {
|
||||
this.collapseAll = !this.collapseAll;
|
||||
|
||||
for (let i = 0; i < this.metadatumCollapses.length; i++)
|
||||
this.metadatumCollapses[i] = this.collapseAll;
|
||||
},
|
||||
changeCollapse(event, index) {
|
||||
this.metadatumCollapses.splice(index, 1, event);
|
||||
},
|
||||
bulkEdit: _.debounce(function(newValue, metadatum) {
|
||||
|
||||
this.isExecutingBulkEdit = true;
|
||||
this.setValueInBulk({
|
||||
collectionID: this.collectionId,
|
||||
groupID: this.groupID,
|
||||
bodyParams: {
|
||||
metadatum_id: metadatum.id,
|
||||
value: newValue,
|
||||
}
|
||||
}).then(() => {
|
||||
this.isExecutingBulkEdit = false;
|
||||
|
||||
}).catch(() => this.isExecutingBulkEdit = false);
|
||||
}, 1000),
|
||||
onSubmit(status) {
|
||||
this.isExecutingBulkEdit = true;
|
||||
this.previousStatus = status;
|
||||
|
||||
if (status != 'trash') {
|
||||
this.status = status;
|
||||
this.isPublishingItems = false;
|
||||
this.isExecutingBulkEdit = false;
|
||||
|
||||
this.$buefy.modal.open({
|
||||
parent: this,
|
||||
component: CustomDialog,
|
||||
props: {
|
||||
icon: 'alert',
|
||||
title: this.$i18n.get('label_warning'),
|
||||
message: this.$i18n.get('info_leaving_bulk_edition' ),
|
||||
onConfirm: () => {
|
||||
this.$router.push(this.$routerHelper.getCollectionItemsPath(this.collectionId));
|
||||
}
|
||||
},
|
||||
trapFocus: true
|
||||
});
|
||||
|
||||
} else if (status == 'trash') {
|
||||
|
||||
this.$buefy.modal.open({
|
||||
parent: this,
|
||||
component: CustomDialog,
|
||||
props: {
|
||||
icon: 'alert',
|
||||
title: this.$i18n.get('label_warning'),
|
||||
message: this.$i18n.get('info_warning_selected_items_trash'),
|
||||
onConfirm: () => {
|
||||
|
||||
this.isTrashingItems = true;
|
||||
this.trashItemsInBulk({
|
||||
groupID: this.groupID,
|
||||
collectionID: this.collectionId
|
||||
}).then(() => {
|
||||
this.status = status;
|
||||
this.isTrashingItems = false;
|
||||
this.isExecutingBulkEdit = false;
|
||||
this.$router.push(this.$routerHelper.getCollectionItemsPath(this.collectionId));
|
||||
}).catch(() => {
|
||||
this.isExecutingBulkEdit = false;
|
||||
this.isTrashingItems = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
trapFocus: true
|
||||
});
|
||||
}
|
||||
},
|
||||
sequenceEditGroup() {
|
||||
this.isCreatingSequenceEditGroup = true;
|
||||
this.$router.push(this.$routerHelper.getCollectionSequenceEditPath(this.collectionId, this.groupID, 1));
|
||||
},
|
||||
changeStatus(status) {
|
||||
this.isPublishingItems = true;
|
||||
|
||||
if (!this.copyItemId){
|
||||
// Gets an item from the bulk group
|
||||
this.fetchItemIdInSequence({ collectionId: this.collectionId, sequenceId: this.groupID, itemPosition: 1 })
|
||||
.then((itemId) => {
|
||||
this.copyItemId = itemId;
|
||||
this.updateItemStatus(status);
|
||||
})
|
||||
.catch(() => {
|
||||
this.isPublishingItems = false;
|
||||
this.isExecutingBulkEdit = false;
|
||||
});
|
||||
} else {
|
||||
this.updateItemStatus(status);
|
||||
}
|
||||
},
|
||||
updateItemStatus(status) {
|
||||
|
||||
// Test if this item can be set to this status
|
||||
this.updateItem({ id: this.copyItemId, status: status })
|
||||
.then(() => {
|
||||
|
||||
// The status can be applied to everyone.
|
||||
this.setStatusInBulk({
|
||||
groupID: this.groupID,
|
||||
collectionID: this.collectionId,
|
||||
bodyParams: { value: status }
|
||||
}).then(() => {
|
||||
|
||||
this.status = status;
|
||||
this.isPublishingItems = false;
|
||||
this.isExecutingBulkEdit = false;
|
||||
|
||||
}).catch(() => {
|
||||
this.isPublishingItems = false;
|
||||
this.isExecutingBulkEdit = false;
|
||||
});
|
||||
})
|
||||
.catch((errors) => {
|
||||
// The status can not be applied.
|
||||
this.isPublishingItems = false;
|
||||
this.isExecutingBulkEdit = false;
|
||||
|
||||
for (let error of errors.errors) {
|
||||
for (let metadatum of Object.keys(error)){
|
||||
this.formErrors[metadatum] = error[metadatum];
|
||||
}
|
||||
}
|
||||
this.formErrorMessage = errors.error_message;
|
||||
});
|
||||
},
|
||||
clearErrorMessage(metadatumId) {
|
||||
this.formErrors[metadatumId] = false;
|
||||
let amountClean = 0;
|
||||
|
||||
for (let formError in this.formErrors) {
|
||||
if (formError == false || formError == undefined)
|
||||
amountClean++;
|
||||
}
|
||||
|
||||
if (amountClean == 0)
|
||||
this.formErrorMessage = '';
|
||||
},
|
||||
getErrorMessage(errors) {
|
||||
|
||||
let msg = '';
|
||||
if ( errors != undefined && errors != false) {
|
||||
for (let error of errors) {
|
||||
for (let index of Object.keys(error)) {
|
||||
msg += error[index] + '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
},
|
||||
loadItemMetadata() {
|
||||
this.isLoadingItemMetadata = true;
|
||||
// Gets an item from the bulk group
|
||||
this.fetchItemIdInSequence({ collectionId: this.collectionId, sequenceId: this.groupID, itemPosition: 1 })
|
||||
.then((itemId) => {
|
||||
this.copyItemId = itemId;
|
||||
this.fetchItemMetadata(this.copyItemId)
|
||||
.then((metadata) => {
|
||||
this.itemMetadata = metadata;
|
||||
this.isLoadingItemMetadata = false;
|
||||
});
|
||||
})
|
||||
.catch(() => this.isLoadingItemMetadata = false);
|
||||
}
|
||||
},
|
||||
created() {
|
||||
// Obtains collection ID
|
||||
this.collectionId = this.$route.params.collectionId;
|
||||
this.groupID = this.$route.params.groupId;
|
||||
|
||||
// Updates Collection BreadCrumb
|
||||
this.$root.$emit('onCollectionBreadCrumbUpdate', [
|
||||
{ path: this.$routerHelper.getCollectionPath(this.collectionId), label: this.$i18n.get('items') },
|
||||
{ path: '', label: this.$i18n.get('add_items_bulk') }
|
||||
]);
|
||||
|
||||
this.isLoadingMetadata = true;
|
||||
this.fetchMetadata({
|
||||
collectionId: this.collectionId,
|
||||
isRepositoryLevel: false,
|
||||
isContextEdit: true,
|
||||
includeDisabled: false,
|
||||
}).then(() => {
|
||||
this.isLoadingMetadata = false;
|
||||
for (let i = 0; i < this.metadata.length; i++) {
|
||||
this.metadatumCollapses.push(false);
|
||||
this.metadatumCollapses[i] = true;
|
||||
}
|
||||
this.loadItemMetadata();
|
||||
})
|
||||
.catch(() => this.isLoadingMetadata = false);
|
||||
|
||||
this.isLoadingGroupInfo = true;
|
||||
this.fetchGroup({ collectionId: this.collectionId, groupId: this.groupID })
|
||||
.then(() => this.isLoadingGroupInfo = false)
|
||||
.then(() => this.isLoadingGroupInfo = false)
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@import "../../scss/_variables.scss";
|
||||
|
||||
|
||||
.page-container {
|
||||
|
||||
&>.tainacan-form {
|
||||
padding: 0 $page-side-padding;
|
||||
margin-bottom: 110px;
|
||||
}
|
||||
|
||||
.tainacan-page-title {
|
||||
margin-bottom: 35px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
|
||||
h1, h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
color: $gray5;
|
||||
display: inline-block;
|
||||
flex-shrink: 1;
|
||||
flex-grow: 1;
|
||||
}
|
||||
.status-tag {
|
||||
color: white;
|
||||
background: $turquoise5;
|
||||
padding: 0.15rem 0.5rem;
|
||||
font-size: 0.75rem;
|
||||
margin: 0 1rem 0 0;
|
||||
font-weight: 600;
|
||||
position: relative;
|
||||
top: -2px;
|
||||
}
|
||||
a.back-link{
|
||||
font-weight: 500;
|
||||
float: right;
|
||||
margin-top: 5px;
|
||||
}
|
||||
hr{
|
||||
margin: 0px 0px 4px 0px;
|
||||
height: 1px;
|
||||
background-color: $secondary;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.document-list {
|
||||
display: inline-block;
|
||||
|
||||
.document-item {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
width: 100%;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
padding: 0.5rem 0.75rem;
|
||||
position: relative;
|
||||
cursor: default;
|
||||
|
||||
.document-thumb {
|
||||
max-height: 42px;
|
||||
max-width: 42px;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
.document-name {
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.column {
|
||||
|
||||
.section-status{
|
||||
padding: 16px 0;
|
||||
.field {
|
||||
border-bottom: none;
|
||||
.b-radio {
|
||||
margin-right: 24px;
|
||||
.icon {
|
||||
font-size: 18px !important;
|
||||
color: $gray3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.section-label {
|
||||
cursor: default;
|
||||
position: relative;
|
||||
label {
|
||||
font-size: 16px !important;
|
||||
font-weight: 500 !important;
|
||||
color: $gray5 !important;
|
||||
line-height: 1.2em;
|
||||
}
|
||||
}
|
||||
|
||||
.collapse-all {
|
||||
font-size: 12px;
|
||||
.icon {
|
||||
vertical-align: bottom;
|
||||
}
|
||||
}
|
||||
|
||||
.multiple-inputs {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.field {
|
||||
border-bottom: 1px solid $gray2;
|
||||
padding: 10px 0px 10px 60px;
|
||||
|
||||
.label {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
margin-left: 15px;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
.metadata-type {
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 400;
|
||||
color: $gray3;
|
||||
top: -0.2em;
|
||||
position: relative;
|
||||
}
|
||||
.help-wrapper {
|
||||
top: -0.2em;
|
||||
}
|
||||
.collapse-handle {
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
margin-left: -42px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding: 18px $page-side-padding;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
z-index: 999999;
|
||||
background-color: $gray1;
|
||||
width: 100%;
|
||||
height: 65px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
left: 0;
|
||||
|
||||
.form-submission-footer {
|
||||
.button {
|
||||
margin-left: 16px;
|
||||
margin-right: 6px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@keyframes blink {
|
||||
from { color: $blue5; }
|
||||
to { color: $gray4; }
|
||||
}
|
||||
|
||||
.update-warning {
|
||||
color: $blue5;
|
||||
animation-name: blink;
|
||||
animation-duration: 0.5s;
|
||||
animation-delay: 0.5s;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.update-info-section {
|
||||
color: $gray4;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.help {
|
||||
display: inline-block;
|
||||
font-size: 1.0em;
|
||||
margin-top: 0;
|
||||
margin-left: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</style>
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
<span
|
||||
style="margin-left: 10px"
|
||||
v-if="enableSelectAllItemsPages == true && allItemsOnPageSelected && items.length > 1">
|
||||
v-if="allItemsOnPageSelected && items.length > 1">
|
||||
<b-checkbox
|
||||
v-model="isAllItemsSelected">
|
||||
{{ $i18n.getWithVariables('label_select_all_%s_items', [totalItems]) }}
|
||||
|
@ -930,8 +930,7 @@ export default {
|
|||
thumbPlaceholderPath: tainacan_plugin.base_url + '/admin/images/placeholder_square.png',
|
||||
cursorPosX: -1,
|
||||
cursorPosY: -1,
|
||||
contextMenuItem: null,
|
||||
enableSelectAllItemsPages: tainacan_plugin.enable_select_all_items_pages
|
||||
contextMenuItem: null
|
||||
}
|
||||
},
|
||||
mixins: [ dateInter ],
|
||||
|
@ -1003,6 +1002,7 @@ export default {
|
|||
]),
|
||||
...mapActions('bulkedition', [
|
||||
'createEditGroup',
|
||||
'createSequenceEditGroup',
|
||||
'trashItemsInBulk',
|
||||
'deleteItemsInBulk',
|
||||
'untrashItemsInBulk'
|
||||
|
@ -1050,11 +1050,9 @@ export default {
|
|||
});
|
||||
},
|
||||
sequenceEditSelectedItems() {
|
||||
this.createEditGroup({
|
||||
this.createSequenceEditGroup({
|
||||
object: Object.keys(this.queryAllItemsSelected).length ? this.queryAllItemsSelected : this.selectedItems,
|
||||
collectionID: this.collectionId,
|
||||
order: this.getOrder(),
|
||||
orderBy: this.getOrderBy()
|
||||
collectionID: this.collectionId
|
||||
}).then(() => {
|
||||
let sequenceId = this.getGroupID();
|
||||
this.$router.push(this.$routerHelper.getCollectionSequenceEditPath(this.collectionId, sequenceId, 1));
|
||||
|
|
|
@ -174,6 +174,9 @@
|
|||
this.$root.$on('closeAdvancedSearchShortcut', () => {
|
||||
this.$refs.advancedSearchShortcut.toggle();
|
||||
});
|
||||
this.$root.$on('openProcessesPopup', () => {
|
||||
this.showProcesses = true;
|
||||
});
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.$root.$off('closeAdvancedSearchShortcut');
|
||||
|
|
|
@ -82,8 +82,7 @@
|
|||
<button
|
||||
v-if="copyCount > 1 && hasCopied && newItems.length > 1"
|
||||
class="button is-secondary"
|
||||
:class="{'is-loading': isCreatingBulkEditGroup }"
|
||||
@click.prevent="createBulkEditGroup()"
|
||||
@click.prevent="openBulkEditionModal()"
|
||||
type="submit">
|
||||
{{ $i18n.get('label_bulk_edit_items') }}
|
||||
</button>
|
||||
|
@ -94,6 +93,8 @@
|
|||
|
||||
<script>
|
||||
import { mapActions } from 'vuex';
|
||||
import BulkEditionModal from '../bulk-edition/bulk-edition-modal.vue';
|
||||
|
||||
export default {
|
||||
name: 'ItemCopyDialog',
|
||||
props: {
|
||||
|
@ -112,7 +113,6 @@
|
|||
newItems: Array,
|
||||
copyCount: Number,
|
||||
hasCopied: Boolean,
|
||||
isCreatingBulkEditGroup: Boolean,
|
||||
isCreatingSequenceEditGroup: Boolean,
|
||||
}
|
||||
},
|
||||
|
@ -123,8 +123,8 @@
|
|||
]),
|
||||
...mapActions('bulkedition', [
|
||||
'createEditGroup',
|
||||
'setStatusInBulk',
|
||||
'setBulkAddItems'
|
||||
'createSequenceEditGroup',
|
||||
'setStatusInBulk'
|
||||
]),
|
||||
generateCopies() {
|
||||
this.isLoading = true;
|
||||
|
@ -151,7 +151,7 @@
|
|||
let onlyItemIds = this.newItems.map(item => item.id);
|
||||
|
||||
this.isCreatingSequenceEditGroup = true;
|
||||
this.createEditGroup({
|
||||
this.createSequenceEditGroup({
|
||||
object: onlyItemIds,
|
||||
collectionID: this.collectionId
|
||||
}).then((group) => {
|
||||
|
@ -161,29 +161,31 @@
|
|||
this.$parent.close();
|
||||
});
|
||||
},
|
||||
createBulkEditGroup() {
|
||||
// Sends to store, so we can retrieve in next page.
|
||||
this.setBulkAddItems(this.newItems);
|
||||
openBulkEditionModal() {
|
||||
|
||||
let onlyItemIds = this.newItems.map(item => item.id);
|
||||
|
||||
this.isCreatingBulkEditGroup = true;
|
||||
this.createEditGroup({
|
||||
object: onlyItemIds,
|
||||
this.$buefy.modal.open({
|
||||
parent: this,
|
||||
component: BulkEditionModal,
|
||||
props: {
|
||||
modalTitle: this.$i18n.get('info_editing_items_in_bulk'),
|
||||
totalItems: onlyItemIds.length,
|
||||
selectedForBulk: onlyItemIds,
|
||||
objectType: this.$i18n.get('items'),
|
||||
collectionID: this.collectionId
|
||||
}).then((group) => {
|
||||
let groupId = group.id;
|
||||
this.isCreatingBulkEditGroup = false;
|
||||
this.$router.push({ path: this.$routerHelper.getItemMetadataBulkAddPath(this.collectionId, groupId), query: { loadCopy: true }});
|
||||
this.$parent.close();
|
||||
},
|
||||
width: 'calc(100% - 8.333333333%)',
|
||||
trapFocus: true
|
||||
});
|
||||
|
||||
this.$parent.close();
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.message = this.$i18n.get('instruction_select_the_amount_of_copies');
|
||||
this.isLoading = false;
|
||||
this.hasCopied = false;
|
||||
this.isCreatingBulkEditGroup = false;
|
||||
this.isCreatingSequenceEditGroup = false;
|
||||
this.copyCount = 1;
|
||||
},
|
||||
|
|
|
@ -22,7 +22,6 @@ import ImporterEditionForm from '../components/edition/importer-edition-form.vue
|
|||
import ImporterMappingForm from '../components/edition/importer-mapping-form.vue'
|
||||
import ItemEditionForm from '../components/edition/item-edition-form.vue'
|
||||
import ItemBulkEditionForm from '../components/edition/item-bulk-edition-form.vue'
|
||||
import ItemMetadataBulkEditionForm from '../components/edition/item-metadata-bulk-edition-form.vue'
|
||||
import TaxonomyEditionForm from '../components/edition/taxonomy-edition-form.vue'
|
||||
import ExporterEditionForm from '../components/edition/exporter-edition-form.vue'
|
||||
|
||||
|
@ -53,7 +52,6 @@ const routes = [
|
|||
{ path: 'items/new', name: 'CollectionItemCreatePage', component: ItemEditionForm, meta: {title: i18nGet('title_create_item_collection') } },
|
||||
{ path: 'items/:itemId', name: 'ItemPage', component: ItemPage, meta: {title: i18nGet('title_item_page') } },
|
||||
{ path: 'bulk-add', name: 'CollectionItemBulkAddPage', component: ItemBulkEditionForm, meta: {title: i18nGet('title_item_bulk_add') } },
|
||||
{ path: 'bulk-add/:groupId', name: 'CollectionItemBulkAddMetadataPage', component: ItemMetadataBulkEditionForm, meta: {title: i18nGet('title_item_bulk_add') } },
|
||||
{ path: 'settings', component: CollectionEditionForm, name: 'CollectionEditionForm', meta: {title: i18nGet('title_collection_settings') } },
|
||||
{ path: 'metadata', component: MetadataList, name: 'MetadataList', meta: {title: i18nGet('title_collection_metadata_edition') } },
|
||||
{ path: 'filters', component: FiltersList, name: 'FiltersList', meta: {title: i18nGet('title_collection_filters_edition') } },
|
||||
|
|
|
@ -139,6 +139,7 @@
|
|||
}
|
||||
.tags {
|
||||
margin: 0.17rem 0.25rem 0.08rem 0.25rem !important;
|
||||
display: inline-flex;
|
||||
}
|
||||
.tag {
|
||||
background: white;
|
||||
|
|
|
@ -557,6 +557,7 @@ return apply_filters( 'tainacan-admin-i18n', [
|
|||
'info_error_deleting_taxonomy' => __( 'Error on deleting taxonomy', 'tainacan' ),
|
||||
'info_error_first_value_greater' => __( 'First value should be lower than second value', 'tainacan' ),
|
||||
'info_error_value_must_be_number' => __( 'Value should be a number', 'tainacan' ),
|
||||
'info_error_upload' => __( 'Error while uploading files.', 'tainacan' ),
|
||||
'info_collection_deleted' => __( 'Collection deleted.', 'tainacan' ),
|
||||
'info_item_deleted' => __( 'Item deleted.', 'tainacan' ),
|
||||
'info_taxonomy_deleted' => __( 'Taxonomy deleted', 'tainacan' ),
|
||||
|
@ -648,9 +649,7 @@ return apply_filters( 'tainacan-admin-i18n', [
|
|||
'info_bulk_add_items' => __( 'Bulk add documents from your computer as items.', 'tainacan' ),
|
||||
'info_editing_items_in_bulk' => __( 'Bulk edit items', 'tainacan' ),
|
||||
'info_by_inner' => __( 'by', 'tainacan' ),
|
||||
'info_items_selected' => __( 'items selected', 'tainacan' ),
|
||||
'info_items_affected' => __( 'items affected', 'tainacan' ),
|
||||
'info_item_affected' => __( 'item affected', 'tainacan' ),
|
||||
'info_bulk_edition_process_added' => __( 'Bulk edition added to process queue.', 'tainacan' ),
|
||||
'info_no_parent_term_found' => __( 'No valid parent term was found with this name.', 'tainacan' ),
|
||||
'info_warning_changing_parent_term' => __( 'Warning! Changing parent term will reload the terms list, thus uncheking any selection.', 'tainacan' ),
|
||||
'info_warning_selected_items_remove_from_trash' => __( 'Do you really want to remove from trash the selected items?', 'tainacan' ),
|
||||
|
|
|
@ -20,7 +20,6 @@ class REST_Bulkedit_Controller extends REST_Controller {
|
|||
$this->collections_repository = Repositories\Collections::get_instance();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -177,10 +176,8 @@ class REST_Bulkedit_Controller extends REST_Controller {
|
|||
),
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function bulk_edit_permissions_check($request) {
|
||||
$collection = $this->collections_repository->fetch($request['collection_id']);
|
||||
$bulk_cap = 'tnc_col_' . $request['collection_id'] . '_bulk_edit';
|
||||
|
@ -192,13 +189,16 @@ class REST_Bulkedit_Controller extends REST_Controller {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function create_item($request) {
|
||||
$body = json_decode($request->get_body(), true);
|
||||
$args = [];
|
||||
|
||||
if (isset($body['items_ids']) && is_array($body['items_ids']) && !empty($body['items_ids'])) {
|
||||
$args['items_ids'] = $body['items_ids'];
|
||||
$collection_id = $request['collection_id'];
|
||||
$args = [
|
||||
'items_ids' => $body['items_ids'],
|
||||
'collection_id' => $collection_id
|
||||
];
|
||||
if (isset($body['options'])) {
|
||||
$args['options'] = $body['options'];
|
||||
}
|
||||
|
@ -220,17 +220,32 @@ class REST_Bulkedit_Controller extends REST_Controller {
|
|||
], 400);
|
||||
}
|
||||
|
||||
$bulk = new \Tainacan\Bulk_Edit($args);
|
||||
|
||||
global $Tainacan_Generic_Process_Handler;
|
||||
$process = $Tainacan_Generic_Process_Handler->initialize_generic_process('bulk_edit', $bulk->get_id());
|
||||
$Tainacan_Generic_Process_Handler->save_process_instance($process);
|
||||
$bulk = $Tainacan_Generic_Process_Handler->initialize_generic_process('bulk_edit');
|
||||
$bulk->create_bulk_edit($args);
|
||||
$Tainacan_Generic_Process_Handler->save_process_instance($bulk);
|
||||
|
||||
$response = $this->prepare_item_for_response($bulk, $request);
|
||||
$rest_response = new \WP_REST_Response($response, 200);
|
||||
return $rest_response;
|
||||
}
|
||||
|
||||
public function set_status($request) {
|
||||
return $this->generic_action('set_status', $request);
|
||||
}
|
||||
|
||||
public function trash_items($request) {
|
||||
return $this->generic_action('trash_items', $request);
|
||||
}
|
||||
|
||||
public function untrash_items($request) {
|
||||
return $this->generic_action('untrash_items', $request);
|
||||
}
|
||||
|
||||
public function delete_items($request) {
|
||||
return $this->generic_action('delete_items', $request);
|
||||
}
|
||||
|
||||
public function add_value($request) {
|
||||
return $this->generic_action('add_value', $request);
|
||||
}
|
||||
|
@ -247,111 +262,40 @@ class REST_Bulkedit_Controller extends REST_Controller {
|
|||
return $this->generic_action('replace_value', $request, ['old_value', 'new_value']);
|
||||
}
|
||||
|
||||
public function set_status($request) {
|
||||
$body = json_decode($request->get_body(), true);
|
||||
|
||||
if( !isset($body['value']) ) {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Value must be provided', 'tainacan'),
|
||||
], 400);
|
||||
}
|
||||
|
||||
$group_id = $request['group_id'];
|
||||
$args = ['id' => $group_id];
|
||||
$bulk = new \Tainacan\Bulk_Edit($args);
|
||||
|
||||
$action = $bulk->set_status($body['value']);
|
||||
|
||||
if ( is_wp_error($action) ) {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => $action->get_error_message(),
|
||||
], 400);
|
||||
} else {
|
||||
return new \WP_REST_Response($action, 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_item($request) {
|
||||
$group_id = $request['group_id'];
|
||||
|
||||
$args = ['id' => $group_id];
|
||||
$bulk = new \Tainacan\Bulk_Edit($args);
|
||||
$return = $this->prepare_item_for_response($bulk, $request);
|
||||
|
||||
if (0 === $return['items_count']) {
|
||||
global $Tainacan_Generic_Process_Handler;
|
||||
$bulk = $Tainacan_Generic_Process_Handler->get_process_instance_by_session_id($group_id);
|
||||
if ($bulk == false) {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Group not found', 'tainacan'),
|
||||
], 404);
|
||||
}
|
||||
$return = $this->prepare_item_for_response($bulk, $request);
|
||||
return new \WP_REST_Response($return, 200);
|
||||
}
|
||||
|
||||
function prepare_item_for_response($bulk_object, $request) {
|
||||
$count = $bulk_object->count_posts();
|
||||
$options = $bulk_object->get_options();
|
||||
$return = [
|
||||
'id' => $bulk_object->get_id(),
|
||||
'items_count' => $count,
|
||||
'options' => $options
|
||||
];
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function trash_items($request) {
|
||||
$group_id = $request['group_id'];
|
||||
$args = ['id' => $group_id];
|
||||
$bulk = new \Tainacan\Bulk_Edit($args);
|
||||
$action = $bulk->trash_items();
|
||||
|
||||
if ( is_wp_error($action) ) {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => $action->get_error_message(),
|
||||
], 400);
|
||||
} else {
|
||||
return new \WP_REST_Response($action, 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function untrash_items($request) {
|
||||
$group_id = $request['group_id'];
|
||||
$args = ['id' => $group_id];
|
||||
$bulk = new \Tainacan\Bulk_Edit($args);
|
||||
$action = $bulk->untrash_items();
|
||||
|
||||
if ( is_wp_error($action) ) {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => $action->get_error_message(),
|
||||
], 400);
|
||||
} else {
|
||||
return new \WP_REST_Response($action, 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete_items($request) {
|
||||
$group_id = $request['group_id'];
|
||||
$args = ['id' => $group_id];
|
||||
$bulk = new \Tainacan\Bulk_Edit($args);
|
||||
$action = $bulk->delete_items();
|
||||
|
||||
if ( is_wp_error($action) ) {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => $action->get_error_message(),
|
||||
], 400);
|
||||
} else {
|
||||
return new \WP_REST_Response($action, 200);
|
||||
}
|
||||
}
|
||||
|
||||
private function generic_action($method, $request, $keys = ['value']) {
|
||||
$body = json_decode($request->get_body(), true);
|
||||
|
||||
if ( !in_array($method, ['trash_items', 'untrash_items', 'delete_items']) ) {
|
||||
if (empty($body)) {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Body can not be empty.', 'tainacan'),
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (!isset($body['metadatum_id'])) {
|
||||
if ($method != 'set_status' && !isset($body['metadatum_id'])) {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('You must specify a Metadatum ID.', 'tainacan'),
|
||||
], 400);
|
||||
|
@ -364,29 +308,25 @@ class REST_Bulkedit_Controller extends REST_Controller {
|
|||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
$group_id = $request['group_id'];
|
||||
$args = ['id' => $group_id];
|
||||
$bulk = new \Tainacan\Bulk_Edit($args);
|
||||
|
||||
$metadatum = $this->metadatum_repository->fetch($body['metadatum_id']);
|
||||
|
||||
if ( $metadatum instanceof Entities\Metadatum ) {
|
||||
$value = isset($body['new_value']) ? $body['new_value'] : $body['value'];
|
||||
$old_value = isset($body['old_value']) ? $body['old_value'] : null;
|
||||
$action = $bulk->$method($metadatum, $value, $old_value);
|
||||
if ( is_wp_error($action) ) {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => $action->get_error_message(),
|
||||
], 400);
|
||||
} else {
|
||||
return new \WP_REST_Response($action, 200);
|
||||
}
|
||||
} else {
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Metadatum not found.', 'tainacan'),
|
||||
], 400);
|
||||
|
||||
$bulk_id = $request['group_id'];
|
||||
|
||||
global $Tainacan_Generic_Process_Handler;
|
||||
$process = $Tainacan_Generic_Process_Handler->get_process_instance_by_session_id($bulk_id);
|
||||
if ($process !== false) {
|
||||
$bulk_edit_data = [
|
||||
"value" => isset($body['new_value']) ? $body['new_value'] : $body['value'],
|
||||
"method" => $method,
|
||||
"old_value" => isset($body['old_value']) ? $body['old_value'] : null,
|
||||
"metadatum_id" => isset($body['metadatum_id']) ? $body['metadatum_id'] : null,
|
||||
];
|
||||
$process->set_bulk_edit_data($bulk_edit_data);
|
||||
$bg_bulk = $Tainacan_Generic_Process_Handler->add_to_queue($process);
|
||||
//$Tainacan_Generic_Process_Handler->delete_process_instance($process);
|
||||
}
|
||||
|
||||
return new \WP_REST_Response(["bg_process_id"=>$bulk_id, "method" => $method], 200);
|
||||
}
|
||||
|
||||
public function get_item_in_sequence($request) {
|
||||
|
|
|
@ -0,0 +1,203 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\API\EndPoints;
|
||||
|
||||
use \Tainacan\API\REST_Controller;
|
||||
use Tainacan\Entities;
|
||||
use Tainacan\Repositories;
|
||||
use Tainacan\Entities\Entity;
|
||||
|
||||
class REST_Sequence_Edit_Controller extends REST_Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->rest_base = 'sequence-edit';
|
||||
parent::__construct();
|
||||
add_action('init', array(&$this, 'init_objects'), 11);
|
||||
}
|
||||
|
||||
public function init_objects() {
|
||||
$this->items_repository = Repositories\Items::get_instance();
|
||||
$this->collections_repository = Repositories\Collections::get_instance();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base,
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => array($this, 'create_item'),
|
||||
'permission_callback' => array($this, 'sequence_edit_permissions_check'),
|
||||
'args' => $this->get_create_params()
|
||||
),
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<group_id>[0-9a-f]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item'),
|
||||
'permission_callback' => array($this, 'sequence_edit_permissions_check'),
|
||||
),
|
||||
)
|
||||
);
|
||||
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<group_id>[0-9a-f]+)/(?P<sequence_index>[\d]+)',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array($this, 'get_item_in_sequence'),
|
||||
'permission_callback' => array($this, 'sequence_edit_permissions_check'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function prepare_item_for_response($item, $request) {
|
||||
|
||||
}
|
||||
|
||||
public function sequence_edit_permissions_check($request) {
|
||||
$collection = $this->collections_repository->fetch($request['collection_id']);
|
||||
|
||||
if ($collection instanceof Entities\Collection) {
|
||||
return current_user_can($collection->get_items_capabilities()->edit_others_posts);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function create_item($request) {
|
||||
$body = json_decode($request->get_body(), true);
|
||||
$args = [];
|
||||
|
||||
if (isset($body['items_ids']) && is_array($body['items_ids']) && !empty($body['items_ids'])) {
|
||||
|
||||
$args['items_ids'] = $body['items_ids'];
|
||||
$count = sizeof($args['items_ids']);
|
||||
$args['items_count'] = $count;
|
||||
|
||||
} elseif ( isset($body['use_query']) && $body['use_query'] ) {
|
||||
|
||||
unset($body['use_query']['paged']);
|
||||
unset($body['use_query']['offset']);
|
||||
unset($body['use_query']['perpage']);
|
||||
|
||||
$query_args = $this->prepare_filters($body['use_query']);
|
||||
$collection_id = $request['collection_id'];
|
||||
$args = [
|
||||
'query' => $query_args,
|
||||
'collection_id' => $collection_id
|
||||
];
|
||||
|
||||
// calculate size
|
||||
$query_args['posts_per_page'] = 1;
|
||||
$items_q = $this->items_repository->fetch( $query_args, $collection_id );
|
||||
$count = $items_q->found_posts;
|
||||
|
||||
$args['items_count'] = $count;
|
||||
|
||||
} else {
|
||||
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('You mus specify items_ids OR use_query', 'tainacan'),
|
||||
], 400);
|
||||
|
||||
}
|
||||
|
||||
$new_group_id = uniqid();
|
||||
|
||||
update_option('tnc_transient_' . $new_group_id, $args);
|
||||
|
||||
$response = [
|
||||
'id' => $new_group_id,
|
||||
'items_count' => $count
|
||||
];
|
||||
$rest_response = new \WP_REST_Response($response, 200);
|
||||
return $rest_response;
|
||||
}
|
||||
|
||||
public function get_item($request) {
|
||||
$group_id = $request['group_id'];
|
||||
|
||||
$group = get_option('tnc_transient_' . $group_id);
|
||||
if ( is_array($group) ) {
|
||||
|
||||
return new \WP_REST_Response( $group, 200 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Item not found.', 'tainacan'),
|
||||
], 404);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function get_item_in_sequence($request) {
|
||||
$group_id = $request['group_id'];
|
||||
$index = (int) $request['sequence_index'];
|
||||
|
||||
$group = get_option('tnc_transient_' . $group_id);
|
||||
if ( is_array($group) ) {
|
||||
|
||||
if ( isset($group['items_ids']) && is_array($group['items_ids']) ) {
|
||||
$index = $index - 1;
|
||||
if ( isset( $group['items_ids'][$index] ) ) {
|
||||
return new \WP_REST_Response( $group['items_ids'][$index], 200 );
|
||||
}
|
||||
} elseif (
|
||||
is_array($group) &&
|
||||
isset($group['collection_id']) &&
|
||||
isset($group['query']) &&
|
||||
is_array($group['query'])
|
||||
) {
|
||||
|
||||
$group['query']['paged'] = $index;
|
||||
|
||||
$group['query']['posts_per_page'] = 1;
|
||||
|
||||
$items = $this->items_repository->fetch_ids( $group['query'], $group['collection_id'] );
|
||||
|
||||
if ( is_array($items) && !empty($items) ) {
|
||||
return new \WP_REST_Response( $items[0], 200 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new \WP_REST_Response([
|
||||
'error_message' => __('Item not found.', 'tainacan'),
|
||||
], 404);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $object_name
|
||||
*
|
||||
* @return array|void
|
||||
*/
|
||||
public function get_create_params($object_name = null) {
|
||||
|
||||
$query_params['items_ids'] = [
|
||||
'type' => 'array',
|
||||
'items' => ['type' => 'integer'],
|
||||
'description' => __( 'Array of items IDs', 'tainacan' ),
|
||||
];
|
||||
|
||||
$query_params['use_query'] = [
|
||||
'description' => __( 'The query used to define the items in the group', 'tainacan' ),
|
||||
];
|
||||
|
||||
return $query_params;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -22,6 +22,7 @@ $rest_roles_controller = new \Tainacan\API\EndPoints\REST_Roles_Controller();
|
|||
new \Tainacan\API\EndPoints\REST_Metadatum_Mappers_Controller();
|
||||
$rest_facets_controller = new \Tainacan\API\EndPoints\REST_Facets_Controller();
|
||||
$rest_oaipmh_expose_controller = new \Tainacan\API\EndPoints\REST_Oaipmh_Expose_Controller();
|
||||
$rest_sequence_edit_controller = new \Tainacan\API\EndPoints\REST_Sequence_Edit_Controller();
|
||||
// Add here other endpoints imports
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
<?php
|
||||
/**
|
||||
* This is the old Bulk Edit approach that performs SQL queries directly into the database
|
||||
* It was disabled in favor of Bulk edit BG process approach
|
||||
*
|
||||
* Its is still here because there is an idea to use it via WP CLI command
|
||||
* If we do this someday, there are also tests written in __test-bulk-edit.php file
|
||||
*/
|
||||
|
||||
namespace Tainacan;
|
||||
use Tainacan\Repositories;
|
||||
|
@ -9,7 +16,7 @@ defined( 'ABSPATH' ) || exit;
|
|||
/**
|
||||
* Bulk_Edit class handles bulk item edition
|
||||
*/
|
||||
class Bulk_Edit {
|
||||
class __Bulk_Edit {
|
||||
|
||||
private $meta_key = '_tnc_bulk';
|
||||
|
||||
|
@ -50,6 +57,8 @@ class Bulk_Edit {
|
|||
*/
|
||||
public function __construct($params) {
|
||||
|
||||
throw new \Exception('This Class is currently disabled');
|
||||
|
||||
if (isset($params['id']) && !empty($params['id'])) {
|
||||
$this->id = $params['id'];
|
||||
return;
|
||||
|
|
|
@ -5,13 +5,404 @@ use Tainacan\Entities;
|
|||
|
||||
class Bulk_Edit_Process extends Generic_Process {
|
||||
|
||||
public function __construct($id) {
|
||||
parent::__construct();
|
||||
$this->id = $id;
|
||||
private $meta_key = '_tnc_bulk';
|
||||
private $group_id = false;
|
||||
|
||||
public function __construct($attributes = array()) {
|
||||
$this->array_attributes = array_merge($this->array_attributes, [
|
||||
'group_id',
|
||||
'bulk_edit_data'
|
||||
]);
|
||||
parent::__construct($attributes);
|
||||
$this->init_objects();
|
||||
}
|
||||
|
||||
public function init_objects() {
|
||||
$this->items_repository = \Tainacan\Repositories\Items::get_instance();
|
||||
$this->metadatum_repository = \Tainacan\Repositories\Metadata::get_instance();
|
||||
$this->item_metadata_repository = \Tainacan\Repositories\Item_Metadata::get_instance();
|
||||
$this->steps = [
|
||||
[
|
||||
'name' => __('Bulk edit control metadada', 'tainacan'),
|
||||
'progress_label' => __('Creating bulk edit control metadada', 'tainacan'),
|
||||
'callback' => 'add_control_metadata'
|
||||
],[
|
||||
'name' => __('Bulk edit', 'tainacan'),
|
||||
'progress_label' => __('Running bulk edit', 'tainacan'),
|
||||
'callback' => 'main_process',
|
||||
'total' => $this->get_total_items()
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function create_bulk_edit($params) {
|
||||
if ( isset($params['group_id']) && !empty($params['group_id']) ) {
|
||||
$this->set_group_id($params['group_id']);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($params['collection_id']) || !is_numeric($params['collection_id'])) {
|
||||
throw new \Exception('Collection ID must be informed when creating a group.');
|
||||
}
|
||||
|
||||
$this->set_group_id(uniqid());
|
||||
if (isset($params['query']) && is_array($params['query'])) {
|
||||
$bulk_params = [
|
||||
'collection_id' => $params['collection_id'],
|
||||
'query' => $params['query'],
|
||||
'order' => isset($params['query']['order']) ? $params['query']['order'] : 'DESC',
|
||||
'orderby' => isset($params['query']['orderby']) ? $params['query']['orderby'] : 'post_date'
|
||||
];
|
||||
} elseif (isset($params['items_ids']) && is_array($params['items_ids'])) {
|
||||
$items_ids = array_filter($params['items_ids'], 'is_integer');
|
||||
$bulk_params = [
|
||||
'collection_id' => $params['collection_id'],
|
||||
'items_ids' => $items_ids,
|
||||
'order' => isset($params['options']['order']) ? $params['options']['order'] : 'DESC',
|
||||
'orderby' => isset($params['options']['orderby']) ? $params['options']['orderby'] : 'post_date'
|
||||
];
|
||||
}
|
||||
$this->save_options($bulk_params);
|
||||
return;
|
||||
}
|
||||
|
||||
public function save_options($value) {
|
||||
update_option('tainacan_bulk_' . $this->get_group_id(), $value);
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
return get_option('tainacan_bulk_' . $this->get_group_id());
|
||||
}
|
||||
|
||||
public function set_group_id($group_id) {
|
||||
$this->group_id = $group_id;
|
||||
}
|
||||
|
||||
public function get_group_id( ) {
|
||||
return $this->group_id;
|
||||
}
|
||||
|
||||
public function get_output() {
|
||||
$message = __('Bulk edit finished', 'tainacan');
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function set_bulk_edit_data($bulk_edit_data = false) {
|
||||
$this->bulk_edit_data = $bulk_edit_data;
|
||||
}
|
||||
|
||||
public function get_bulk_edit_data() {
|
||||
return $this->bulk_edit_data;
|
||||
}
|
||||
|
||||
private function bulk_list_remove_item($item) {
|
||||
return delete_post_meta( $item->get_id(), $this->meta_key, $this->get_group_id());
|
||||
}
|
||||
|
||||
public function add_control_metadata() {
|
||||
$params = $this->get_options();
|
||||
|
||||
if( !isset($params['control_metadata']) ) {
|
||||
$params['control_metadata'] = $this->get_id();
|
||||
$this->save_options($params);
|
||||
} elseif ($params['control_metadata'] === true) {
|
||||
$this->add_log( __('bulk edit control metadata has already been created', 'tainacan') );
|
||||
return false;
|
||||
} elseif( is_numeric($params['control_metadata']) && $params['control_metadata'] != $this->get_id() ) {
|
||||
$this->add_log( sprintf( __( 'waiting creating bulk edit control metadata by process ID: "%d"', 'tainacan' ), $params['control_metadata'] ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isset($params['query']) && is_array($params['query'])) {
|
||||
$itemsRepo = \Tainacan\Repositories\Items::get_instance();
|
||||
$count = $this->get_in_step_count();
|
||||
|
||||
$post_per_page = 1;
|
||||
if ( isset($params['query']['posts_per_page']) && $params['query']['posts_per_page'] != -1 ) {
|
||||
$post_per_page = $params['query']['posts_per_page'] - $count;
|
||||
$params['query']['posts_per_page'] = $post_per_page;
|
||||
}
|
||||
if($post_per_page <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $params['query'];
|
||||
$query['fields'] = 'ids';
|
||||
$query['posts_per_page'] = $post_per_page;
|
||||
$query['offset'] = $count++;
|
||||
$query['nopaging'] = false;
|
||||
|
||||
$item_query = $itemsRepo->fetch($query, $params['collection_id']);
|
||||
if(!$item_query->have_posts() ) {
|
||||
$params['control_metadata'] = true;
|
||||
$this->save_options($params);
|
||||
$this->add_log( __('bulk edit control metadata created', 'tainacan') );
|
||||
return false;
|
||||
}
|
||||
$item_id = $item_query->get_posts()[0];
|
||||
$this->add_log( sprintf( __( 'creating bulk edit control metadata for item: "%d"', 'tainacan' ), $item_id ) );
|
||||
add_post_meta($item_id, $this->meta_key, $this->get_group_id());
|
||||
return $count;
|
||||
} elseif (isset($params['items_ids']) && is_array($params['items_ids'])) {
|
||||
$items_ids = array_filter($params['items_ids'], 'is_integer');
|
||||
|
||||
$count = $this->get_in_step_count();
|
||||
if( isset($items_ids[$count]) ) {
|
||||
$this->add_log( sprintf( __( 'creating bulk edit control metadata for item: "%d"', 'tainacan' ), $items_ids[$count] ) );
|
||||
add_post_meta($items_ids[$count++], $this->meta_key, $this->get_group_id());
|
||||
return $count;
|
||||
} else {
|
||||
$params['control_metadata'] = true;
|
||||
$this->save_options($params);
|
||||
$this->add_log( __('bulk edit control metadata created', 'tainacan') );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->add_error_log(__('wrong parameter on add bulk edit control metadata', 'tainacan'));
|
||||
$this->abort();
|
||||
return false;
|
||||
}
|
||||
|
||||
private function get_total_items() {
|
||||
if (!$this->get_group_id()) return 0;
|
||||
$args = [
|
||||
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash'),
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => $this->meta_key,
|
||||
'value' => $this->get_group_id(),
|
||||
'compare' => '=',
|
||||
)
|
||||
)
|
||||
];
|
||||
$item = $this->items_repository->fetch($args, [], 'WP_Query');
|
||||
return intval($item->found_posts);
|
||||
}
|
||||
|
||||
private function bulk_list_get_item($count) {
|
||||
$args = [
|
||||
'perpage' => 1,
|
||||
'offset' => $count,
|
||||
'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash'),
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => $this->meta_key,
|
||||
'value' => $this->get_group_id(),
|
||||
'compare' => '=',
|
||||
)
|
||||
)
|
||||
];
|
||||
$item = $this->items_repository->fetch($args, [], 'WP_Query');
|
||||
$this->set_current_step_total($item->found_posts);
|
||||
if ($item->have_posts()) {
|
||||
$item->the_post();
|
||||
$item = new \Tainacan\Entities\Item($item->post);
|
||||
return $item;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function main_process() {
|
||||
$this->add_log("log");
|
||||
$method = $this->bulk_edit_data['method'];
|
||||
if ( !method_exists($this, $method) ) {
|
||||
$this->add_error_log(__('method not exists', 'tainacan'));
|
||||
$this->abort();
|
||||
return false;
|
||||
}
|
||||
$count = $this->get_in_step_count();
|
||||
$item = $this->bulk_list_get_item($count++);
|
||||
if($item == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->add_log( sprintf( __('bulk edit has process the item ID: "%d"', 'tainacan'), $item->get_id() ) );
|
||||
$add_steps = $this->$method($item);
|
||||
if ( is_int($add_steps) ) {
|
||||
$count = $count + $add_steps;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
private function save_item_metadata(\Tainacan\Entities\Item_Metadata_Entity $item_metadata, \Tainacan\Entities\Item $item) {
|
||||
if ( $item_metadata->validate() ) {
|
||||
if( $item->can_edit() ) {
|
||||
$updated_item_metadata = $this->item_metadata_repository->update( $item_metadata );
|
||||
} else {
|
||||
$this->add_error_log( sprintf( __('do not have permission to edit item ID: "%d"', 'tainacan'), $item->get_id() ) );
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->add_error_log( sprintf( __( 'Please verify, invalid value(s) to edit item ID: "%d"', 'tainacan' ), $item->get_id() ) );
|
||||
|
||||
$serealize_erro = (object) array('err' => array());
|
||||
$erro = $item_metadata->get_errors();
|
||||
array_walk_recursive($erro, function($v, $k, &$t) {$t->err[] = $v;}, $serealize_erro);
|
||||
$this->add_error_log( __('errors: ', 'tainacan') . implode(", ", $serealize_erro->err) );
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function set_value(\Tainacan\Entities\Item $item) {
|
||||
$metadatum = $this->metadatum_repository->fetch($this->bulk_edit_data['metadatum_id']);
|
||||
$value = $this->bulk_edit_data['value'];
|
||||
|
||||
$item_metadata = new Entities\Item_Metadata_Entity( $item, $metadatum );
|
||||
|
||||
if($item_metadata->is_multiple()) {
|
||||
$value = is_array( $value ) ? $value : [$value];
|
||||
$item_metadata->set_value( $value );
|
||||
} else {
|
||||
$item_metadata->set_value($value);
|
||||
}
|
||||
|
||||
return $this->save_item_metadata($item_metadata, $item);
|
||||
|
||||
}
|
||||
|
||||
private function add_value(\Tainacan\Entities\Item $item) {
|
||||
$metadatum_id = $this->bulk_edit_data['metadatum_id'];
|
||||
$metadatum = $this->metadatum_repository->fetch($metadatum_id);
|
||||
$value = $this->bulk_edit_data['value'];
|
||||
|
||||
if (!$metadatum->is_multiple()) {
|
||||
$this->add_error_log( __( 'Unable to add a value to a metadata if it does not accept multiple values', 'tainacan' ) );
|
||||
return false;
|
||||
}
|
||||
if ($metadatum->is_collection_key()) {
|
||||
$this->add_error_log( __( 'Unable to add a value to a metadata set to be a collection key', 'tainacan' ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
$items_metadata = $item->get_metadata();
|
||||
|
||||
foreach ($items_metadata as $item_metadata) {
|
||||
$metadatum = $item_metadata->get_metadatum();
|
||||
if($metadatum->get_id() == $metadatum_id) {
|
||||
$values = is_array($item_metadata->get_value()) ? $item_metadata->get_value() : [$item_metadata->get_value()];
|
||||
$values = array_merge($values, [$value]);
|
||||
$item_metadata->set_value( $values );
|
||||
return $this->save_item_metadata($item_metadata, $item);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function remove_value(\Tainacan\Entities\Item $item) {
|
||||
$metadatum_id = $this->bulk_edit_data['metadatum_id'];
|
||||
$metadatum = $this->metadatum_repository->fetch($metadatum_id);
|
||||
$value = $this->bulk_edit_data['value'];
|
||||
|
||||
if ($metadatum->is_required()) {
|
||||
$this->add_error_log( __( 'Unable to remove a value from a required metadatum', 'tainacan' ) );
|
||||
return false;
|
||||
}
|
||||
if (!$metadatum->is_multiple()) {
|
||||
$this->add_error_log( __( 'Unable to remove a value from a metadata if it does not accept multiple values', 'tainacan' ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
$items_metadata = $item->get_metadata();
|
||||
|
||||
foreach ($items_metadata as $item_metadata) {
|
||||
$metadatum = $item_metadata->get_metadatum();
|
||||
if($metadatum->get_id() == $metadatum_id) {
|
||||
$values = is_array($item_metadata->get_value()) ? $item_metadata->get_value() : [$item_metadata->get_value()];
|
||||
$pos = array_search($value, $values);
|
||||
unset($values[$pos]);
|
||||
$item_metadata->set_value( $values );
|
||||
return $this->save_item_metadata($item_metadata, $item);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function replace_value(\Tainacan\Entities\Item $item) {
|
||||
$metadatum_id = $this->bulk_edit_data['metadatum_id'];
|
||||
$metadatum = $this->metadatum_repository->fetch($metadatum_id);
|
||||
$old_value = $this->bulk_edit_data['old_value'];
|
||||
$new_value = $this->bulk_edit_data['value'];
|
||||
|
||||
if ($metadatum->is_collection_key()) {
|
||||
$this->add_error_log( __( 'Unable to set a value to a metadata set to be a collection key', 'tainacan' ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($new_value == $old_value) {
|
||||
$this->add_error_log( __( 'Old value and new value can not be the same', 'tainacan' ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
$items_metadata = $item->get_metadata();
|
||||
|
||||
foreach ($items_metadata as $item_metadata) {
|
||||
$metadatum = $item_metadata->get_metadatum();
|
||||
if($metadatum->get_id() == $metadatum_id) {
|
||||
$values = is_array($item_metadata->get_value()) ? $item_metadata->get_value() : [$item_metadata->get_value()];
|
||||
$pos = array_search($old_value, $values);
|
||||
if ($pos !== false) {
|
||||
$values[$pos] = $new_value;
|
||||
$item_metadata->set_value( $metadatum->is_multiple() ? $values : $values[$pos] );
|
||||
return $this->save_item_metadata($item_metadata, $item);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function trash_items(\Tainacan\Entities\Item $item) {
|
||||
if ( !$this->items_repository->trash($item) ) {
|
||||
$this->add_error_log( sprintf( __('error on send to trash, item ID: "%d"', 'tainacan'), $item->get_id() ) );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function untrash_items(\Tainacan\Entities\Item $item) {
|
||||
if ( !wp_untrash_post( $item->get_id() ) ) {
|
||||
$this->add_error_log( sprintf( __('error on untrash, item ID: "%d"', 'tainacan'), $item->get_id() ) );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function delete_items(\Tainacan\Entities\Item $item) {
|
||||
if ('trash' != $item->get_status() ) {
|
||||
$this->add_error_log( sprintf( __('Items must be on trash to be deleted, item ID: "%d"', 'tainacan'), $item->get_id() ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !$this->items_repository->delete($item) ) {
|
||||
$this->add_error_log( sprintf( __('error on send to trash, item ID: "%d"', 'tainacan'), $item->get_id() ) );
|
||||
return false;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private function set_status(\Tainacan\Entities\Item $item) {
|
||||
$value = $this->bulk_edit_data['value'];
|
||||
$possible_values = ['trash', 'draft', 'publish', 'private'];
|
||||
|
||||
if (!in_array($value, $possible_values)) {
|
||||
$this->add_error_log( __( 'Invalid status', 'tainacan' ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
$item->set("status", $value);
|
||||
if($item->validate()) {
|
||||
$this->items_repository->update($item);
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->add_error_log( sprintf( __( 'Please verify, invalid value(s) to edit item ID: "%d"', 'tainacan' ), $item->get_id() ) );
|
||||
$serealize_erro = (object) array('err' => array());
|
||||
array_walk_recursive($item->get_errors(), create_function('&$v, $k, &$t', '$t->err[] = $v;'), $serealize_erro);
|
||||
$this->add_error_log( __('errors: ', 'tainacan') . implode(", ", $serealize_erro->err) );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ class Generic_Process_Handler {
|
|||
return true;
|
||||
}
|
||||
|
||||
function add_to_queue(\Tainacan\process\process $process_object) {
|
||||
function add_to_queue(\Tainacan\GenericBackgroundProcess\Generic_Process $process_object) {
|
||||
$data = $process_object->_to_Array(true);
|
||||
$process = $this->get_process_by_object($process_object);
|
||||
$process = $this->get_generic_process_by_object($process_object);
|
||||
|
||||
$process_name = sprintf( __('%s process', 'tainacan'), $process['name'] );
|
||||
|
||||
|
@ -63,13 +63,22 @@ class Generic_Process_Handler {
|
|||
return null;
|
||||
}
|
||||
|
||||
public function initialize_generic_process($slug, $id = null) {
|
||||
public function get_generic_process_by_object(\Tainacan\GenericBackgroundProcess\Generic_Process $process_object) {
|
||||
$class_name = get_class($process_object);
|
||||
$class_name = '\\' . $class_name;
|
||||
$generic_process = $this->get_registered_generic_process();
|
||||
foreach ($generic_process as $process) {
|
||||
if ($process['class_name'] == $class_name)
|
||||
return $process;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function initialize_generic_process($slug) {
|
||||
$process = $this->get_generic_process($slug);
|
||||
if ( is_array($process) && isset($process['class_name']) && class_exists($process['class_name']) ) {
|
||||
if ($id == null)
|
||||
return new $process['class_name']();
|
||||
else
|
||||
return new $process['class_name']($id);
|
||||
$prc = new $process['class_name']();
|
||||
return $prc;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -5,12 +5,20 @@ use Tainacan\Entities;
|
|||
|
||||
abstract class Generic_Process {
|
||||
|
||||
public function __construct( ) {
|
||||
public function __construct( $attributess = array() ) {
|
||||
$this->id = uniqid();
|
||||
$author = get_current_user_id();
|
||||
if($author) {
|
||||
$this->add_transient('author', $author);
|
||||
}
|
||||
if (!empty($attributess)) {
|
||||
foreach ($attributess as $attr => $value) {
|
||||
$method = 'set_' . $attr;
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,7 +74,7 @@ abstract class Generic_Process {
|
|||
|
||||
/**
|
||||
* List of attributes that are saved in DB and that are used to
|
||||
* reconstruct the object, this property need be overwrite in custom import/export.
|
||||
* reconstruct the object, this property need be overwrite.
|
||||
* @var array
|
||||
*/
|
||||
protected $array_attributes = [
|
||||
|
@ -271,8 +279,8 @@ abstract class Generic_Process {
|
|||
$current_step = $this->get_current_step();
|
||||
$steps = $this->get_steps();
|
||||
$current_step ++;
|
||||
$this->set_current_step($current_step);
|
||||
if (isset($steps[$current_step])) {
|
||||
$this->set_current_step($current_step);
|
||||
return $current_step;
|
||||
}
|
||||
return false;
|
||||
|
@ -295,6 +303,10 @@ abstract class Generic_Process {
|
|||
return $return;
|
||||
}
|
||||
|
||||
public function finished() {
|
||||
$this->add_log('finished');
|
||||
}
|
||||
|
||||
/**
|
||||
* runs one iteration
|
||||
*/
|
||||
|
@ -319,7 +331,7 @@ abstract class Generic_Process {
|
|||
//Move on to the next step
|
||||
$this->set_in_step_count(0);
|
||||
$return = $this->next_step();
|
||||
} else if(is_numeric($result) && $result > 0) {
|
||||
} else if(is_numeric($result) && $result >= 0) {
|
||||
$this->set_in_step_count($result);
|
||||
$return = $result;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,21 @@ export const fetchGroup = ({commit}, { collectionId, groupId }) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const fetchSequenceGroup = ({commit}, { collectionId, groupId }) => {
|
||||
|
||||
return new Promise ((resolve, reject) => {
|
||||
axios.tainacan.get(`/collection/${collectionId}/sequence-edit/${groupId}`)
|
||||
.then(response => {
|
||||
commit('setGroup', response.data);
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const setValueInBulk = ({commit}, parameters) => {
|
||||
let groupID = parameters.groupID;
|
||||
let collectionID = parameters.collectionID;
|
||||
|
@ -61,13 +76,11 @@ export const setValueInBulk = ({commit}, parameters) => {
|
|||
|
||||
return axios.tainacan.post(`/collection/${collectionID}/bulk-edit/${groupID}/set`, bodyParams)
|
||||
.then(response => {
|
||||
commit('setActionResult', response.data);
|
||||
commit('setLastUpdated');
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
commit('setActionResult', error.response.data);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -82,12 +95,10 @@ export const addValueInBulk = ({commit}, parameters) => {
|
|||
|
||||
return axios.tainacan.post(`/collection/${collectionID}/bulk-edit/${groupID}/add`, bodyParams)
|
||||
.then(response => {
|
||||
commit('setActionResult', response.data);
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
commit('setActionResult', error.response.data);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -101,12 +112,8 @@ export const removeValueInBulk = ({commit}, parameters) => {
|
|||
let bodyParams = parameters.bodyParams;
|
||||
|
||||
return axios.tainacan.post(`/collection/${collectionID}/bulk-edit/${groupID}/remove`, bodyParams)
|
||||
.then(response => {
|
||||
commit('setActionResult', response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
commit('setActionResult', error.response.data);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -121,12 +128,10 @@ export const replaceValueInBulk = ({commit}, parameters) => {
|
|||
|
||||
return axios.tainacan.post(`/collection/${collectionID}/bulk-edit/${groupID}/replace`, bodyParams)
|
||||
.then(response => {
|
||||
commit('setActionResult', response.data);
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
commit('setActionResult', error.response.data);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -142,13 +147,11 @@ export const setStatusInBulk = ({commit}, parameters) => {
|
|||
|
||||
return axios.tainacan.post(`/collection/${collectionID}/bulk-edit/${groupID}/set_status`, bodyParams)
|
||||
.then(response => {
|
||||
commit('setActionResult', response.data);
|
||||
commit('setLastUpdated');
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
commit('setActionResult', error.response.data);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -158,13 +161,11 @@ export const trashItemsInBulk = ({commit}, parameters) => {
|
|||
|
||||
return axios.tainacan.post(`/collection/${collectionID}/bulk-edit/${groupID}/trash`)
|
||||
.then(response => {
|
||||
commit('setActionResult', response.data);
|
||||
commit('setLastUpdated');
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
commit('setActionResult', error.response.data);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -174,12 +175,10 @@ export const untrashItemsInBulk = ({commit}, parameters) => {
|
|||
|
||||
return axios.tainacan.post(`/collection/${collectionID}/bulk-edit/${groupID}/untrash`)
|
||||
.then(response => {
|
||||
commit('setActionResult', response.data);
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
commit('setActionResult', error.response.data)
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -189,13 +188,11 @@ export const deleteItemsInBulk = ({commit}, parameters) => {
|
|||
|
||||
return axios.tainacan.post(`/collection/${collectionID}/bulk-edit/${groupID}/delete_items`)
|
||||
.then(response => {
|
||||
commit('setActionResult', response.data);
|
||||
commit('setLastUpdated');
|
||||
return response;
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
commit('setActionResult', error.response.data);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -203,7 +200,7 @@ export const deleteItemsInBulk = ({commit}, parameters) => {
|
|||
export const fetchItemIdInSequence = ({commit}, { collectionId, sequenceId, itemPosition }) => {
|
||||
|
||||
return new Promise ((resolve, reject) => {
|
||||
axios.tainacan.get(`/collection/${collectionId}/bulk-edit/${sequenceId}/sequence/${itemPosition}`)
|
||||
axios.tainacan.get(`/collection/${collectionId}/sequence-edit/${sequenceId}/${itemPosition}`)
|
||||
.then(response => {
|
||||
commit('setItemIdInSequence', response.data);
|
||||
resolve(response.data);
|
||||
|
@ -215,7 +212,32 @@ export const fetchItemIdInSequence = ({commit}, { collectionId, sequenceId, item
|
|||
});
|
||||
};
|
||||
|
||||
// BULK ADD SPECIFIC
|
||||
export const setBulkAddItems = ({commit}, items) => {
|
||||
commit('setBulkAddItems', items);
|
||||
export const createSequenceEditGroup = ({commit}, parameters) => {
|
||||
let object = parameters.object;
|
||||
let collectionID = parameters.collectionID;
|
||||
|
||||
let sequenceEditParams = null;
|
||||
|
||||
if(object.constructor.name === 'Array'){
|
||||
sequenceEditParams = {
|
||||
items_ids: object,
|
||||
};
|
||||
|
||||
} else if(object.constructor.name === 'Object'){
|
||||
sequenceEditParams = {
|
||||
use_query: object,
|
||||
};
|
||||
}
|
||||
|
||||
return new Promise ((resolve, reject) => {
|
||||
axios.tainacan.post(`/collection/${collectionID}/sequence-edit`, sequenceEditParams)
|
||||
.then(response => {
|
||||
commit('setGroup', response.data);
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
|
@ -6,10 +6,6 @@ export const getGroup = state => {
|
|||
return state.group;
|
||||
};
|
||||
|
||||
export const getActionResult = state => {
|
||||
return state.actionResult;
|
||||
};
|
||||
|
||||
export const getItemIdInSequence = state => {
|
||||
return state.itemIdInSequence;
|
||||
};
|
||||
|
@ -17,7 +13,3 @@ export const getItemIdInSequence = state => {
|
|||
export const getLastUpdated = state => {
|
||||
return state.lastUpdated;
|
||||
}
|
||||
|
||||
export const getBulkAddItems = state => {
|
||||
return state.bulkAddItems;
|
||||
}
|
|
@ -4,10 +4,8 @@ import * as getters from './getters.js'
|
|||
|
||||
const state = {
|
||||
group: null,
|
||||
actionResult: null,
|
||||
itemIdInSequence: null,
|
||||
lastUpdated: '',
|
||||
bulkAddItems: []
|
||||
lastUpdated: ''
|
||||
};
|
||||
|
||||
export default {
|
||||
|
|
|
@ -2,10 +2,6 @@ export const setGroup = (state, group) => {
|
|||
state.group = group;
|
||||
};
|
||||
|
||||
export const setActionResult = (state, actionResult) => {
|
||||
state.actionResult = actionResult;
|
||||
};
|
||||
|
||||
export const setItemIdInSequence = (state, itemIdInSequence) => {
|
||||
state.itemIdInSequence = itemIdInSequence;
|
||||
};
|
||||
|
@ -18,7 +14,3 @@ export const setLastUpdated = (state, value) => {
|
|||
state.lastUpdated = now.toLocaleString();
|
||||
}
|
||||
}
|
||||
|
||||
export const setBulkAddItems = (state, items) => {
|
||||
return state.bulkAddItems = items;
|
||||
}
|
|
@ -3,7 +3,10 @@
|
|||
namespace Tainacan\Tests;
|
||||
|
||||
/**
|
||||
* Class TestCollections
|
||||
* Class BulkEdit
|
||||
*
|
||||
* These are the tests for the old Bulk edit class that has been disabled
|
||||
* More info in src/classes/class-tainacan-bulk-edit.php
|
||||
*
|
||||
* @package Test_Tainacan
|
||||
*/
|
||||
|
@ -892,158 +895,6 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals(7, $count);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group api
|
||||
*/
|
||||
function test_api_create_by_items_ids() {
|
||||
|
||||
$ids = array_slice($this->items_ids, 2, 17);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'POST', $this->api_baseroute
|
||||
);
|
||||
|
||||
$request->set_body( json_encode(['items_ids' => $ids]) );
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertTrue(is_string($data['id']));
|
||||
|
||||
$this->assertEquals(17, $data['items_count']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group api
|
||||
*/
|
||||
function test_api_create_by_query() {
|
||||
|
||||
$query = [
|
||||
|
||||
'metaquery' => [
|
||||
[
|
||||
'key' => $this->metadatum->get_id(),
|
||||
'value' => 'odd'
|
||||
]
|
||||
],
|
||||
'taxquery' => [
|
||||
[
|
||||
'taxonomy' => $this->taxonomy->get_db_identifier(),
|
||||
'field' => 'name',
|
||||
'terms' => 'good'
|
||||
]
|
||||
],
|
||||
'perpage' => 4,
|
||||
'paged' => 2
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'POST', $this->api_baseroute
|
||||
);
|
||||
|
||||
//$request->set_query_params($query);
|
||||
|
||||
$request->set_body( json_encode(['use_query' => $query]) );
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertTrue(is_string($data['id']));
|
||||
|
||||
$this->assertEquals(20, $data['items_count']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group api
|
||||
*/
|
||||
public function test_api_add_action() {
|
||||
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
|
||||
$ids = array_slice($this->items_ids, 2, 14);
|
||||
|
||||
$bulk = new \Tainacan\Bulk_Edit([
|
||||
'items_ids' => $ids,
|
||||
]);
|
||||
|
||||
$body = json_encode([
|
||||
'metadatum_id' => $this->multiple_meta->get_id(),
|
||||
'value' => 'superduper'
|
||||
]);
|
||||
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'POST', $this->api_baseroute . '/' . $bulk->get_id() . '/add'
|
||||
);
|
||||
|
||||
$request->set_body( $body );
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$items = $Tainacan_Items->fetch([
|
||||
'meta_query' => [
|
||||
[
|
||||
'key' => $this->multiple_meta->get_id(),
|
||||
'value' => 'superduper'
|
||||
]
|
||||
],
|
||||
'posts_per_page' => -1
|
||||
]);
|
||||
|
||||
$this->assertEquals(14, $items->found_posts);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group api
|
||||
*/
|
||||
public function test_api_set_status() {
|
||||
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
|
||||
$ids = array_slice($this->items_ids, 2, 14);
|
||||
|
||||
$bulk = new \Tainacan\Bulk_Edit([
|
||||
'items_ids' => $ids,
|
||||
]);
|
||||
|
||||
$body = json_encode([
|
||||
'value' => 'private'
|
||||
]);
|
||||
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'POST', $this->api_baseroute . '/' . $bulk->get_id() . '/set_status'
|
||||
);
|
||||
|
||||
$request->set_body( $body );
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$items = $Tainacan_Items->fetch([
|
||||
'status' => 'private',
|
||||
'posts_per_page' => -1
|
||||
]);
|
||||
|
||||
$this->assertEquals(14, $items->found_posts);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1359,78 +1210,6 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group sequence
|
||||
*/
|
||||
function test_api_get_item_in_sequence() {
|
||||
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
|
||||
$query = [
|
||||
'posts_per_page' => 22,
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC'
|
||||
];
|
||||
|
||||
$bulk = new \Tainacan\Bulk_Edit([
|
||||
'query' => $query,
|
||||
'collection_id' => $this->collection->get_id()
|
||||
]);
|
||||
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/' . $bulk->get_id() . '/sequence/7'
|
||||
);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$id = $response->get_data();
|
||||
|
||||
$item = $Tainacan_Items->fetch($id);
|
||||
|
||||
$this->assertEquals('testeItem 07', $item->get_title());
|
||||
|
||||
|
||||
}
|
||||
|
||||
function test_api_get_group() {
|
||||
|
||||
$query = [
|
||||
'posts_per_page' => 22,
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC'
|
||||
];
|
||||
|
||||
$bulk = new \Tainacan\Bulk_Edit([
|
||||
'query' => $query,
|
||||
'collection_id' => $this->collection->get_id()
|
||||
]);
|
||||
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/' . $bulk->get_id()
|
||||
);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals($bulk->get_id(), $data['id']);
|
||||
$this->assertEquals($bulk->get_options()['order'], $data['options']['order']);
|
||||
$this->assertEquals($bulk->get_options()['orderby'], $data['options']['orderby']);
|
||||
$this->assertEquals($bulk->count_posts(), $data['items_count']);
|
||||
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/fefefe23232'
|
||||
);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(404, $response->get_status());
|
||||
|
||||
}
|
||||
|
||||
function test_set_multiple_tax_meta() {
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
|
|
@ -0,0 +1,206 @@
|
|||
<?php
|
||||
|
||||
namespace Tainacan\Tests;
|
||||
|
||||
use Tainacan\Entities;
|
||||
|
||||
/**
|
||||
* Sample test case.
|
||||
*/
|
||||
class SequenceEdit extends TAINACAN_UnitApiTestCase {
|
||||
|
||||
public $items_ids = [];
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$collection = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
'name' => 'test_col',
|
||||
'status' => 'publish'
|
||||
),
|
||||
true
|
||||
);
|
||||
$this->collection = $collection;
|
||||
|
||||
$metadatum = $this->tainacan_entity_factory->create_entity(
|
||||
'metadatum',
|
||||
array(
|
||||
'name' => 'metadado',
|
||||
'status' => 'publish',
|
||||
'collection' => $collection,
|
||||
'metadata_type' => 'Tainacan\Metadata_Types\Text',
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$this->metadatum = $metadatum;
|
||||
|
||||
|
||||
for ($i = 1; $i<=40; $i++) {
|
||||
|
||||
$title = 'testeItem ' . str_pad($i, 2, "0", STR_PAD_LEFT);
|
||||
|
||||
$item = $this->tainacan_entity_factory->create_entity(
|
||||
'item',
|
||||
array(
|
||||
'title' => $title,
|
||||
'collection' => $collection,
|
||||
'status' => 'publish'
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$this->items_ids[] = $item->get_id();
|
||||
|
||||
$this->tainacan_item_metadata_factory->create_item_metadata($item, $metadatum, $i % 2 == 0 ? 'even' : 'odd');
|
||||
$this->tainacan_item_metadata_factory->create_item_metadata($item, $collection->get_core_title_metadatum(), $title);
|
||||
|
||||
}
|
||||
|
||||
$this->api_baseroute = $this->namespace . '/collection/' . $collection->get_id() . '/sequence-edit';
|
||||
|
||||
}
|
||||
|
||||
function test_setup() {
|
||||
$this->assertEquals(40, sizeof($this->items_ids));
|
||||
}
|
||||
|
||||
function test_init_by_query() {
|
||||
|
||||
|
||||
$query = [
|
||||
'metaquery' => [
|
||||
[
|
||||
'key' => $this->metadatum->get_id(),
|
||||
'value' => 'even'
|
||||
]
|
||||
],
|
||||
'orderby' => 'title'
|
||||
];
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'POST', $this->api_baseroute
|
||||
);
|
||||
|
||||
$request->set_body( json_encode(['use_query' => $query]) );
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals(20, $data['items_count']);
|
||||
|
||||
$group_id = $data['id'];
|
||||
|
||||
$items = \Tainacan\Repositories\Items::get_instance()->fetch( [
|
||||
'meta_query' => [
|
||||
[
|
||||
'key' => $this->metadatum->get_id(),
|
||||
'value' => 'even'
|
||||
]
|
||||
],
|
||||
'nopaging' => 1,
|
||||
'orderby' => 'post_title'
|
||||
], $this->collection->get_id(), 'OBJECT');
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/' . $group_id . '/1'
|
||||
);
|
||||
$response = $this->server->dispatch($request);
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$this->assertEquals($items[0]->get_id(), $data);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/' . $group_id . '/7'
|
||||
);
|
||||
$response = $this->server->dispatch($request);
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$this->assertEquals($items[6]->get_id(), $data);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/' . $group_id . '/20'
|
||||
);
|
||||
$response = $this->server->dispatch($request);
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$this->assertEquals($items[19]->get_id(), $data);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/' . $group_id . '/30'
|
||||
);
|
||||
$response = $this->server->dispatch($request);
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals(404, $response->get_status());
|
||||
|
||||
|
||||
}
|
||||
|
||||
function test_init_by_ids() {
|
||||
|
||||
$ids = array_slice($this->items_ids, 2, 7);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'POST', $this->api_baseroute
|
||||
);
|
||||
|
||||
$request->set_body( json_encode(['items_ids' => $ids]) );
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals(7, $data['items_count']);
|
||||
$group_id = $data['id'];
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/' . $group_id . '/1'
|
||||
);
|
||||
$response = $this->server->dispatch($request);
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$this->assertEquals($ids[0], $data);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/' . $group_id . '/3'
|
||||
);
|
||||
$response = $this->server->dispatch($request);
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$this->assertEquals($ids[2], $data);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/' . $group_id . '/6'
|
||||
);
|
||||
$response = $this->server->dispatch($request);
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$this->assertEquals($ids[5], $data);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/' . $group_id . '/7'
|
||||
);
|
||||
$response = $this->server->dispatch($request);
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals(200, $response->get_status());
|
||||
$this->assertEquals($ids[6], $data);
|
||||
|
||||
$request = new \WP_REST_Request(
|
||||
'GET', $this->api_baseroute . '/' . $group_id . '/8'
|
||||
);
|
||||
$response = $this->server->dispatch($request);
|
||||
$data = $response->get_data();
|
||||
$this->assertEquals(404, $response->get_status());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue