refactor sequence edit front-end #200

Now independent from bulk edit
This commit is contained in:
leogermani 2019-12-11 08:50:38 -03:00
parent 04ed966369
commit 61ed5b4e5d
4 changed files with 346 additions and 280 deletions

View File

@ -817,7 +817,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: {
@ -849,7 +849,8 @@ export default {
]),
...mapActions('bulkedition', [
'fetchItemIdInSequence',
'fetchGroup'
'fetchGroup',
'fetchSequenceGroup'
]),
...mapGetters('bulkedition', [
'getItemIdInSequence',
@ -1323,7 +1324,7 @@ export default {
});
// Obtains current Sequence Group Info
this.fetchGroup({ collectionId: this.collectionId, groupId: this.sequenceId });
this.fetchSequenceGroup({ collectionId: this.collectionId, groupId: this.sequenceId });
}
// Obtains collection name

View File

@ -989,6 +989,7 @@ export default {
]),
...mapActions('bulkedition', [
'createEditGroup',
'createSequenceEditGroup',
'trashItemsInBulk',
'deleteItemsInBulk',
'untrashItemsInBulk'
@ -1036,11 +1037,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));

View File

@ -36,15 +36,15 @@ class REST_Sequence_Edit_Controller extends REST_Controller {
),
)
);
//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]+)',
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(
@ -79,6 +79,7 @@ class REST_Sequence_Edit_Controller extends REST_Controller {
$args['items_ids'] = $body['items_ids'];
$count = sizeof($args['items_ids']);
$args['items_count'] = $count;
} elseif ( isset($body['use_query']) && $body['use_query'] ) {
@ -98,6 +99,8 @@ class REST_Sequence_Edit_Controller extends REST_Controller {
$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([
@ -118,12 +121,29 @@ class REST_Sequence_Edit_Controller extends REST_Controller {
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);
//ar_dump($group);
if ( is_array($group) ) {
if ( isset($group['items_ids']) && is_array($group['items_ids']) ) {

View File

@ -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;
@ -203,7 +218,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 +230,38 @@ export const fetchItemIdInSequence = ({commit}, { collectionId, sequenceId, item
});
};
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);
});
});
};
// BULK ADD SPECIFIC
export const setBulkAddItems = ({commit}, items) => {
commit('setBulkAddItems', items);
};