Got the GetChildren wired up to the back end, updated the sort and list view controls to use the new resource with promises, updated unit tests to support.

This commit is contained in:
Shannon
2013-08-06 18:42:36 +10:00
parent ec0e5107ea
commit 66fc7e91dd
24 changed files with 512 additions and 255 deletions

View File

@@ -2,6 +2,49 @@ angular.module('umbraco.mocks').
factory('contentMocks', ['$httpBackend', 'mocksUtils', function ($httpBackend, mocksUtils) {
'use strict';
function returnChildren(status, data, headers) {
if (!mocksUtils.checkAuth()) {
return [401, null, null];
}
var pageNumber = mocksUtils.getParameterByName(data, "pageNumber");
var filter = mocksUtils.getParameterByName(data, "filter");
var pageSize = mocksUtils.getParameterByName(data, "pageSize");
var parentId = mocksUtils.getParameterByName(data, "id");
var collection = { pageSize: 10, totalItems: 68, totalPages: 7, pageNumber: pageNumber, filter: filter };
collection.totalItems = 56 - (filter.length);
if (pageSize > 0) {
collection.totalPages = Math.round(collection.totalItems / collection.pageSize);
}
else {
collection.totalPages = 1;
}
collection.items = [];
if (collection.totalItems < pageSize || pageSize < 1) {
collection.pageSize = collection.totalItems;
} else {
collection.pageSize = pageSize;
}
var id = 0;
for (var i = 0; i < collection.pageSize; i++) {
id = (parentId + i) * pageNumber;
var cnt = mocksUtils.getMockContent(id);
//here we fake filtering
if (filter !== '') {
cnt.name = filter + cnt.name;
}
collection.items.push(cnt);
}
return [200, collection, null];
}
function returnDeletedNode(status, data, headers) {
if (!mocksUtils.checkAuth()) {
return [401, null, null];
@@ -50,7 +93,11 @@ angular.module('umbraco.mocks').
return {
register: function() {
register: function () {
$httpBackend
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Content/GetChildren'))
.respond(returnChildren);
$httpBackend
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/Content/GetById'))
.respond(returnNodebyId);

View File

@@ -76,42 +76,42 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
getChildren: function (parentId, options) {
//TODO: Make this real
var defaults = {
pageSize: 0,
pageNumber: 0,
filter: '',
orderDirection: "Ascending",
orderBy: "SortOrder"
};
if (options === undefined) {
options = {
take: 10,
offset: 0,
filter: ''
};
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 {
options.orderDirection = "Descending";
}
var collection = { take: 10, total: 68, pages: 7, currentPage: options.offset, filter: options.filter };
collection.total = 56 - (options.filter.length);
collection.pages = Math.round(collection.total / collection.take);
collection.resultSet = [];
if (collection.total < options.take) {
collection.take = collection.total;
} else {
collection.take = options.take;
}
var _id = 0;
for (var i = 0; i < collection.take; i++) {
_id = (parentId + i) * options.offset;
var cnt = this.getById(_id);
//here we fake filtering
if (options.filter !== '') {
cnt.name = options.filter + cnt.name;
}
collection.resultSet.push(cnt);
}
return collection;
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"contentApiBaseUrl",
"GetChildren",
[
{ id: parentId },
{ pageNumber: options.pageNumber },
{ pageSize: options.pageSize },
{ orderBy: options.orderBy },
{ orderDirection: options.orderDirection },
{ filter: options.filter }
])),
'Failed to retreive children for content item ' + parentId);
},
/** saves or updates a content object */

View File

@@ -0,0 +1,37 @@
/**
* @ngdoc controller
* @name Umbraco.Editors.ContentDeleteController
* @function
*
* @description
* The controller for deleting content
*/
function ContentSortController($scope, contentResource, treeService, navigationService) {
contentResource.getChildren($scope.currentNode.id).then(function(data) {
$scope.itemsToSort = data.items;
});
$scope.performSort = function() {
//contentResource.sort($scope.currentNode.id).then(function () {
// $scope.currentNode.loading = false;
// //get the root node before we remove it
// var rootNode = treeService.getTreeRoot($scope.currentNode);
// //TODO: Need to sync tree, etc...
// treeService.removeNode($scope.currentNode);
// //ensure the recycle bin has child nodes now
// var recycleBin = treeService.getDescendantNode(rootNode, -20);
// recycleBin.hasChildren = true;
// navigationService.hideMenu();
//});
};
}
angular.module("umbraco").controller("Umbraco.Editors.Content.SortController", ContentSortController);

View File

@@ -1,28 +1,28 @@
<div class="umb-dialog" style="width: 500px">
<div class="umb-dialog-body" auto-scale="90">
<p class="umb-abstract">Sort children of {{nav.ui.currentNode.name}}</p>
<div class="umb-dialog" style="width: 500px" ng-controller="Umbraco.Editors.Content.SortController">
<ng-form name="sortForm" ng-submit="performSort()">
<div class="umb-dialog-body" auto-scale="90">
<p class="umb-abstract">Sort children of {{nav.ui.currentNode.name}}</p>
<table class="table umb-table">
<thead>
<tr><td>Name</td><td>Last Update</td> <td>Index</td>
</thead>
<tbody>
<tr><td>Some node</td><td>13:23 3 July 2024</td> <td>0</td></tr>
<tr><td>Some node</td><td>13:23 3 July 2024</td> <td>0</td></tr>
<tr><td>Some node</td><td>13:23 3 July 2024</td> <td>0</td></tr>
<tr><td>Some node</td><td>13:23 3 July 2024</td> <td>0</td></tr>
<tr><td>Some node</td><td>13:23 3 July 2024</td> <td>0</td></tr>
<tr><td>Some node</td><td>13:23 3 July 2024</td> <td>0</td></tr>
<tr><td>Some node</td><td>13:23 3 July 2024</td> <td>0</td></tr>
<tr><td>Some node</td><td>13:23 3 July 2024</td> <td>0</td></tr>
<tr><td>Some node</td><td>13:23 3 July 2024</td> <td>0</td></tr>
<tr><td>Some node</td><td>13:23 3 July 2024</td> <td>0</td></tr>
</tbody>
</table>
<table class="table umb-table">
<thead>
<tr>
<td>Name</td>
<td>Last Update</td>
<td>Index</td>
</thead>
<tbody>
<tr ng-repeat="model in itemsToSort">
<td>{{model.name}}</td>
<td>{{model.updateDate}}</td>
<td>{{model.sortOrder}}</td>
</tr>
</tbody>
</table>
</div>
<div class="btn-toolbar umb-btn-toolbar">
<button class="btn" ng-click="nav.hideDialog()">Cancel</button>
<button class="btn btn-primary" ng-click="nav.hideDialog()">Sort</button>
</div>
</div>
</div>
<div class="btn-toolbar umb-btn-toolbar">
<button class="btn" ng-click="nav.hideDialog()">Cancel</button>
<button class="btn btn-primary">Sort</button>
</div>
</ng-form>
</div>

View File

@@ -2,25 +2,25 @@ angular.module("umbraco")
.controller("Umbraco.Editors.ListViewController",
function ($rootScope, $scope, contentResource, contentTypeResource) {
$scope.options = {
take: 10,
offset: 0,
pageSize: 10,
pageNumber: 1,
filter: '',
sortby: 'id',
order: "desc"
orderBy: 'id',
orderDirection: "desc"
};
$scope.pagination = new Array(100);
$scope.pagination = [];
$scope.listViewAllowedTypes = contentTypeResource.getAllowedTypes($scope.content.id);
$scope.next = function(){
if($scope.options.offset < $scope.listViewResultSet.pages){
$scope.options.offset++;
if ($scope.options.pageNumber < $scope.listViewResultSet.totalPages) {
$scope.options.pageNumber++;
$scope.reloadView();
}
};
$scope.goToOffset = function(offset){
$scope.options.offset = offset;
$scope.goToPage = function (pageNumber) {
$scope.options.pageNumber = pageNumber + 1;
$scope.reloadView();
};
@@ -38,8 +38,8 @@ angular.module("umbraco")
};
$scope.prev = function(){
if($scope.options.offset > 0){
$scope.options.offset--;
if ($scope.options.pageNumber > 1) {
$scope.options.pageNumber--;
$scope.reloadView();
}
@@ -48,17 +48,23 @@ angular.module("umbraco")
/*Loads the search results, based on parameters set in prev,next,sort and so on*/
/*Pagination is done by an array of objects, due angularJS's funky way of monitoring state
with simple values */
$scope.reloadView = function(){
$scope.listViewResultSet = contentResource.getChildren($scope.content.id, $scope.options);
$scope.reloadView = function() {
contentResource.getChildren($scope.content.id, $scope.options).then(function(data) {
$scope.listViewResultSet = data;
$scope.pagination = [];
for (var i = $scope.listViewResultSet.pages - 1; i >= 0; i--) {
$scope.pagination[i] = {index: i, name: i+1};
for (var i = $scope.listViewResultSet.totalPages - 1; i >= 0; i--) {
$scope.pagination[i] = { index: i, name: i + 1 };
};
if($scope.options.offset > $scope.listViewResultSet.pages){
$scope.options.offset = $scope.listViewResultSet.pages;
}
if ($scope.options.pageNumber > $scope.listViewResultSet.totalPages) {
$scope.options.pageNumber = $scope.listViewResultSet.totalPages;
}
});
};
$scope.reloadView();

View File

@@ -31,7 +31,7 @@
</thead>
<tbody>
<tr ng-repeat="result in listViewResultSet.resultSet">
<tr ng-repeat="result in listViewResultSet.items">
<td><i class="{{result.icon}}"></i><input type="checkbox"></td>
<td><a href="#/content/edit/{{result.id}}">{{result.name}}</a></td>
<td>{{result.updateDate|date:'medium'}}
@@ -54,7 +54,7 @@
<li ng-repeat="pgn in pagination"
ng-class="{active:$index==options.offset}">
<a href="#" ng-click="goToOffset($index)" prevent-default>{{$index + 1}}</a>
<a href="#" ng-click="goToPage($index)" prevent-default>{{$index + 1}}</a>
</li>
<li><a href="#" ng-click="next()" prevent-default>Next</a></li>

View File

@@ -41,17 +41,26 @@ describe('content factory tests', function () {
});
it('should return a content children collection given an id', function () {
var collection = contentFactory.getChildren(1234, undefined);
$rootScope.$digest();
$httpBackend.flush();
expect(collection.resultSet.length).toBe(10);
it('should return a all children collection given an id', function () {
collection = contentFactory.getChildren(1234,{take: 5, offset: 1, filter: ""});
var collection;
contentFactory.getChildren(1234, undefined).then(function (data) {
collection = data;
});
$rootScope.$digest();
$httpBackend.flush();
expect(collection.items.length).toBe(56);
});
it('should return paged children collection given an id', function () {
var collection;
contentFactory.getChildren(1234, { pageSize: 5, pageNumber: 1, filter: "" }).then(function (data) {
collection = data;
});
$rootScope.$digest();
$httpBackend.flush();
expect(collection.resultSet.length).toBe(5);
});
expect(collection.items.length).toBe(5);
});
});
});