Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #28 from takeit/master
Browse files Browse the repository at this point in the history
canLoadMore flag handling improvement
  • Loading branch information
takeit committed Aug 18, 2015
2 parents 8c9400d + 3ddbd87 commit d9c8a96
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions app/scripts/services/editorial-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ angular.module('authoringEnvironmentApp').service('editorialComments', [
* A flag indicating whether there are more comments to be loaded.
* @property canLoadMore
* @type Boolean
* @default true
* @default false
*/
self.canLoadMore = true;
self.canLoadMore = false;

/**
* A list of all comments loaded so far.
Expand Down Expand Up @@ -71,7 +71,7 @@ angular.module('authoringEnvironmentApp').service('editorialComments', [
self.tracker = pageTracker.getTracker();
self.loaded = [];
self.fetched = [];
self.canLoadMore = true;
self.canLoadMore = false;
sorting = 'nested';

self.getAllByPage(self.tracker.next()).then(function (data) {
Expand Down Expand Up @@ -140,9 +140,11 @@ angular.module('authoringEnvironmentApp').service('editorialComments', [
var next = self.tracker.next();
latestPage = next;
self.getAllByPage(next - 1).then(function (response) {
if (response.items.length < 1) {
self.canLoadMore = false;
self.canLoadMore = false;
if (response.items.length > 0) {
self.canLoadMore = true;
}

self.loaded = self.loaded.concat(response.items);
});
} else {
Expand Down Expand Up @@ -193,7 +195,12 @@ angular.module('authoringEnvironmentApp').service('editorialComments', [
.then(function (response) {
var responseData = response.data;
deferredGet.resolve(responseData);
if (responseData.items.length < 1 ||
if (responseData.items.length > 0 ||
responseData.pagination !== undefined) {
self.canLoadMore = true;
}

if (responseData.items.length > 0 &&
responseData.pagination === undefined) {
self.canLoadMore = false;
}
Expand Down
4 changes: 2 additions & 2 deletions test/spec/services/editorial-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ describe('Service: editorialComments', function () {
}));

it('init() resets everything to default values', function () {
comments.canLoadMore = false;
comments.canLoadMore = true;
comments.loaded.push(items[0], items[1]);
comments.displayed.push(items[0]);
comments.fetched.push(items[0]);

comments.init();

expect(comments.canLoadMore).toBe(true);
expect(comments.canLoadMore).toBe(false);
expect(comments.loaded.length).toBe(0);
expect(comments.displayed.length).toBe(1);
expect(comments.fetched.length).toBe(0);
Expand Down

0 comments on commit d9c8a96

Please sign in to comment.