Merge pull request #1618 from mailpoet/more-tags

Implement pagination to tags and categories query [MAILPOET-1613]
This commit is contained in:
M. Shull
2018-11-15 10:57:45 -05:00
committed by GitHub
4 changed files with 24 additions and 8 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

@ -44,7 +44,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,
@ -57,8 +57,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()) {