Implement pagination to tags and categories query

[MAILPOET-1613]
This commit is contained in:
Pavel Dohnal
2018-11-13 10:12:48 +01:00
parent 19d13c5165
commit 141cb09a54
4 changed files with 25 additions and 9 deletions

View File

@@ -210,7 +210,8 @@ define([
ajax: { ajax: {
data: function (params) { data: function (params) {
return { return {
term: params.term term: params.term,
page: params.page || 1
}; };
}, },
transport: function (options, success, failure) { transport: function (options, success, failure) {
@@ -223,6 +224,7 @@ define([
// Fetch available terms based on the list of taxonomies already fetched // Fetch available terms based on the list of taxonomies already fetched
termsPromise = CommunicationComponent.getTerms({ termsPromise = CommunicationComponent.getTerms({
search: options.data.term, search: options.data.term,
page: options.data.page,
taxonomies: _.keys(taxonomies) taxonomies: _.keys(taxonomies)
}).then(function (terms) { }).then(function (terms) {
return { return {
@@ -248,7 +250,10 @@ define([
id: item.term_id id: item.term_id
}, item); }, item);
} }
) ),
pagination: {
more: data.terms.length === 100
}
}; };
} }
} }

View File

@@ -205,7 +205,8 @@ define([
ajax: { ajax: {
data: function (params) { data: function (params) {
return { return {
term: params.term term: params.term,
page: params.page || 1
}; };
}, },
transport: function (options, success, failure) { transport: function (options, success, failure) {
@@ -218,6 +219,7 @@ define([
// Fetch available terms based on the list of taxonomies already fetched // Fetch available terms based on the list of taxonomies already fetched
termsPromise = CommunicationComponent.getTerms({ termsPromise = CommunicationComponent.getTerms({
search: options.data.term, search: options.data.term,
page: options.data.page,
taxonomies: _.keys(taxonomies) taxonomies: _.keys(taxonomies)
}).then(function (terms) { }).then(function (terms) {
return { return {
@@ -243,7 +245,10 @@ define([
id: item.term_id id: item.term_id
}, item); }, item);
} }
) ),
pagination: {
more: data.terms.length === 100
}
}; };
} }
} }

View File

@@ -372,7 +372,8 @@ define([
ajax: { ajax: {
data: function (params) { data: function (params) {
return { return {
term: params.term term: params.term,
page: params.page || 1
}; };
}, },
transport: function (options, success, failure) { transport: function (options, success, failure) {
@@ -385,6 +386,7 @@ define([
// Fetch available terms based on the list of taxonomies already fetched // Fetch available terms based on the list of taxonomies already fetched
termsPromise = CommunicationComponent.getTerms({ termsPromise = CommunicationComponent.getTerms({
search: options.data.term, search: options.data.term,
page: options.data.page,
taxonomies: _.keys(taxonomies) taxonomies: _.keys(taxonomies)
}).then(function (terms) { }).then(function (terms) {
return { return {
@@ -410,7 +412,10 @@ define([
id: item.term_id id: item.term_id
}, item); }, item);
} }
) ),
pagination: {
more: data.terms.length === 100
}
}; };
} }
} }

View File

@@ -43,7 +43,7 @@ class AutomatedLatestContent extends APIEndpoint {
function getTerms($data = array()) { function getTerms($data = array()) {
$taxonomies = (isset($data['taxonomies'])) ? $data['taxonomies'] : array(); $taxonomies = (isset($data['taxonomies'])) ? $data['taxonomies'] : array();
$search = (isset($data['search'])) ? $data['search'] : ''; $search = (isset($data['search'])) ? $data['search'] : '';
$limit = (isset($data['limit'])) ? (int)$data['limit'] : 50; $limit = (isset($data['limit'])) ? (int)$data['limit'] : 100;
$page = (isset($data['page'])) ? (int)$data['page'] : 1; $page = (isset($data['page'])) ? (int)$data['page'] : 1;
$args = array( $args = array(
'taxonomy' => $taxonomies, 'taxonomy' => $taxonomies,
@@ -56,8 +56,9 @@ class AutomatedLatestContent extends APIEndpoint {
); );
$args = Hooks::applyFilters('mailpoet_search_terms_args', $args); $args = Hooks::applyFilters('mailpoet_search_terms_args', $args);
$terms = WPPosts::getTerms($args);
return $this->successResponse(WPPosts::getTerms($args)); return $this->successResponse(array_values($terms));
} }
function getPosts($data = array()) { function getPosts($data = array()) {
@@ -90,4 +91,4 @@ class AutomatedLatestContent extends APIEndpoint {
return $this->successResponse($rendered_posts); return $this->successResponse($rendered_posts);
} }
} }