Account for not loaded completed tasks too

This commit is contained in:
Raimund Schlüßler 2015-06-17 22:44:06 +02:00
parent 90e4fbc4bc
commit 03308d884e
3 changed files with 31 additions and 7 deletions

View file

@ -21,11 +21,11 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
###
angular.module('Tasks').factory 'CollectionsModel',
['TasksModel', '_Model',
(TasksModel, _Model) ->
['TasksModel', 'ListsModel', '_Model',
(TasksModel, ListsModel, _Model) ->
class CollectionsModel extends _Model
constructor: (@_$tasksmodel) ->
constructor: (@_$tasksmodel, @_$listsmodel) ->
@_nameCache = {}
super()
@ -41,7 +41,9 @@ angular.module('Tasks').factory 'CollectionsModel',
for task in tasks
count += (@_$tasksmodel.filterTasks(task, collectionID) &&
@_$tasksmodel.filterTasksByString(task, filter))
if (collectionID == 'completed' && filter == '')
count += @_$listsmodel.notLoadedAll()
return count
return new CollectionsModel(TasksModel)
return new CollectionsModel(TasksModel, ListsModel)
]

View file

@ -110,6 +110,13 @@ angular.module('Tasks').factory 'ListsModel',
else
return @getById(listID).notLoaded
notLoadedAll: () ->
lists = @getAll()
count = 0
for list in lists
count += @notLoaded(list.id)
return count
loadedAll: (listID) ->
return !@notLoaded(listID)

View file

@ -1922,13 +1922,14 @@
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
angular.module('Tasks').factory('CollectionsModel', [
'TasksModel', '_Model', function(TasksModel, _Model) {
'TasksModel', 'ListsModel', '_Model', function(TasksModel, ListsModel, _Model) {
var CollectionsModel;
CollectionsModel = (function(_super) {
__extends(CollectionsModel, _super);
function CollectionsModel(_$tasksmodel) {
function CollectionsModel(_$tasksmodel, _$listsmodel) {
this._$tasksmodel = _$tasksmodel;
this._$listsmodel = _$listsmodel;
this._nameCache = {};
CollectionsModel.__super__.constructor.call(this);
}
@ -1954,13 +1955,16 @@
task = tasks[_i];
count += this._$tasksmodel.filterTasks(task, collectionID) && this._$tasksmodel.filterTasksByString(task, filter);
}
if (collectionID === 'completed' && filter === '') {
count += this._$listsmodel.notLoadedAll();
}
return count;
};
return CollectionsModel;
})(_Model);
return new CollectionsModel(TasksModel);
return new CollectionsModel(TasksModel, ListsModel);
}
]);
@ -2102,6 +2106,17 @@
}
};
ListsModel.prototype.notLoadedAll = function() {
var count, list, lists, _i, _len;
lists = this.getAll();
count = 0;
for (_i = 0, _len = lists.length; _i < _len; _i++) {
list = lists[_i];
count += this.notLoaded(list.id);
}
return count;
};
ListsModel.prototype.loadedAll = function(listID) {
return !this.notLoaded(listID);
};