Adds GetPagedDescendants to EntityController

Implements GetPagedDescendants in the mediapicker Search
Removes duplicate ExamineSearch and Search endpoint code from MediaController
This commit is contained in:
Emil Wangaa
2017-02-16 14:41:50 +01:00
parent cab1536a30
commit bd38dde1fc
5 changed files with 124 additions and 169 deletions

View File

@@ -395,6 +395,76 @@ function entityResource($q, $http, umbRequestHelper) {
)),
'Failed to retrieve child data for id ' + parentId);
},
/**
* @ngdoc method
* @name umbraco.resources.entityResource#getPagedDescendants
* @methodOf umbraco.resources.entityResource
*
* @description
* Gets paged descendants of a content item with a given id
*
* ##usage
* <pre>
* entityResource.getPagedDescendants(1234, "Content", {pageSize: 10, pageNumber: 2})
* .then(function(contentArray) {
* var children = contentArray;
* alert('they are here!');
* });
* </pre>
*
* @param {Int} parentid id of content item to return descendants of
* @param {string} type Object type name
* @param {Object} options optional options object
* @param {Int} options.pageSize if paging data, number of nodes per page, default = 0
* @param {Int} options.pageNumber if paging data, current page index, default = 0
* @param {String} options.filter if provided, query will only return those with names matching the filter
* @param {String} options.orderDirection can be `Ascending` or `Descending` - Default: `Ascending`
* @param {String} options.orderBy property to order items by, default: `SortOrder`
* @returns {Promise} resourcePromise object containing an array of content items.
*
*/
getPagedDescendants: function (parentId, type, options) {
var defaults = {
pageSize: 0,
pageNumber: 0,
filter: '',
orderDirection: "Ascending",
orderBy: "SortOrder"
};
if (options === undefined) {
options = {};
}
//overwrite the defaults if there are any specified
angular.extend(defaults, options);
//now copy back to the options we will use
options = defaults;
//change asc/desct
if (options.orderDirection === "asc") {
options.orderDirection = "Ascending";
}
else if (options.orderDirection === "desc") {
options.orderDirection = "Descending";
}
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"entityApiBaseUrl",
"GetPagedDescendants",
{
id: parentId,
type: type,
pageNumber: options.pageNumber,
pageSize: options.pageSize,
orderBy: options.orderBy,
orderDirection: options.orderDirection,
filter: options.filter
}
)),
'Failed to retrieve child data for id ' + parentId);
},
/**
* @ngdoc method

View File

@@ -37,7 +37,8 @@ angular.module("umbraco")
pageNumber: 1,
pageSize: 100,
totalItems: 0,
totalPages: 0
totalPages: 0,
filter: '',
};
//preload selected item
@@ -233,7 +234,7 @@ angular.module("umbraco")
var debounceSearchMedia = _.debounce(function () {
$scope.$apply(function () {
if ($scope.searchTerm) {
if ($scope.searchOptions.filter) {
searchMedia();
} else {
// reset pagination
@@ -241,7 +242,8 @@ angular.module("umbraco")
pageNumber: 1,
pageSize: 100,
totalItems: 0,
totalPages: 0
totalPages: 0,
filter: ''
};
getChildren($scope.currentFolder.id);
}
@@ -250,7 +252,7 @@ angular.module("umbraco")
function searchMedia() {
$scope.loading = true;
mediaResource.search($scope.searchTerm, $scope.searchOptions.pageNumber, $scope.searchOptions.pageSize, $scope.startNodeId)
entityResource.getPagedDescendants($scope.startNodeId, "Media", $scope.searchOptions)
.then(function (data) {
// update images
$scope.images = data.items ? data.items : [];

View File

@@ -18,7 +18,7 @@
<i class="icon-search"></i>
<input
class="umb-search-field search-query"
ng-model="searchTerm"
ng-model="searchOptions.filter"
localize="placeholder"
placeholder="@placeholders_search"
ng-change="changeSearch()"