diff --git a/js/app/controllers/listcontroller.coffee b/js/app/controllers/listcontroller.coffee index 1e7ab5d5..d17b67aa 100644 --- a/js/app/controllers/listcontroller.coffee +++ b/js/app/controllers/listcontroller.coffee @@ -143,7 +143,10 @@ CollectionsModel, ListsBusinessLayer, $location) -> return (@getCollectionCount(collectionID) < 1) @_$scope.getCollectionString = (collectionID) -> - return _$collectionsmodel.getCountString(collectionID) + if collectionID != 'completed' + return _$collectionsmodel.getCount(collectionID) + else + return '' @_$scope.getListCount = (listID,type) -> return _$listsmodel.getCount(listID,type) diff --git a/js/app/controllers/taskscontroller.coffee b/js/app/controllers/taskscontroller.coffee index ff25cbae..9f902751 100644 --- a/js/app/controllers/taskscontroller.coffee +++ b/js/app/controllers/taskscontroller.coffee @@ -125,7 +125,6 @@ SettingsBusinessLayer) -> ret.push(task) return ret - @_$scope.filterTasksByCalendar = (task, listID) -> return (task) -> return ''+task.calendarid == ''+listID diff --git a/js/app/services/models/collectionsmodel.coffee b/js/app/services/models/collectionsmodel.coffee index 9121d10c..47a69eeb 100644 --- a/js/app/services/models/collectionsmodel.coffee +++ b/js/app/services/models/collectionsmodel.coffee @@ -42,11 +42,5 @@ angular.module('Tasks').factory 'CollectionsModel', count += @_$tasksmodel.filterTasks(task, collectionID) return count - getCountString: (collectionID) -> - if collectionID != 'completed' - return @getCount(collectionID) - else - return '' - return new CollectionsModel(TasksModel) ] \ No newline at end of file diff --git a/js/app/services/models/listsmodel.coffee b/js/app/services/models/listsmodel.coffee index 1b4d1195..b7e391c2 100644 --- a/js/app/services/models/listsmodel.coffee +++ b/js/app/services/models/listsmodel.coffee @@ -93,32 +93,14 @@ angular.module('Tasks').factory 'ListsModel', ret = false return ret - getCount: (listID,type) -> + getCount: (listID,collectionID) -> count = 0 tasks = @_$tasksmodel.getAll() - switch type - when 'all' - for task in tasks - count += (task.calendarid==listID && !task.completed) - return count - when 'current' - for task in tasks - count += (task.calendarid==listID && !task.completed && - @_$tasksmodel.current(task.start)) - return count - when 'completed' - for task in tasks - count += (task.calendarid==listID && task.completed) - return count + @notLoaded(listID) - when 'starred' - for task in tasks - count += (task.calendarid==listID && !task.completed && task.starred) - return count - when 'today' - for task in tasks - count += (task.calendarid==listID && !task.completed && - @_$tasksmodel.today(task.due)) - return count + + for task in tasks + count += (@_$tasksmodel.filterTasks(task, collectionID) && + task.calendarid == listID) + return count notLoaded: (listID) -> if angular.isUndefined(@getById(listID)) diff --git a/js/public/app.js b/js/public/app.js index e33edc57..e3c9239a 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -937,7 +937,11 @@ } }; this._$scope.getCollectionString = function(collectionID) { - return _$collectionsmodel.getCountString(collectionID); + if (collectionID !== 'completed') { + return _$collectionsmodel.getCount(collectionID); + } else { + return ''; + } }; this._$scope.getListCount = function(listID, type) { return _$listsmodel.getCount(listID, type); @@ -1869,14 +1873,6 @@ return count; }; - CollectionsModel.prototype.getCountString = function(collectionID) { - if (collectionID !== 'completed') { - return this.getCount(collectionID); - } else { - return ''; - } - }; - return CollectionsModel; })(_Model); @@ -1997,42 +1993,15 @@ return ret; }; - ListsModel.prototype.getCount = function(listID, type) { - var count, task, tasks, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m; + ListsModel.prototype.getCount = function(listID, collectionID) { + var count, task, tasks, _i, _len; count = 0; tasks = this._$tasksmodel.getAll(); - switch (type) { - case 'all': - for (_i = 0, _len = tasks.length; _i < _len; _i++) { - task = tasks[_i]; - count += task.calendarid === listID && !task.completed; - } - return count; - case 'current': - for (_j = 0, _len1 = tasks.length; _j < _len1; _j++) { - task = tasks[_j]; - count += task.calendarid === listID && !task.completed && this._$tasksmodel.current(task.start); - } - return count; - case 'completed': - for (_k = 0, _len2 = tasks.length; _k < _len2; _k++) { - task = tasks[_k]; - count += task.calendarid === listID && task.completed; - } - return count + this.notLoaded(listID); - case 'starred': - for (_l = 0, _len3 = tasks.length; _l < _len3; _l++) { - task = tasks[_l]; - count += task.calendarid === listID && !task.completed && task.starred; - } - return count; - case 'today': - for (_m = 0, _len4 = tasks.length; _m < _len4; _m++) { - task = tasks[_m]; - count += task.calendarid === listID && !task.completed && this._$tasksmodel.today(task.due); - } - return count; + for (_i = 0, _len = tasks.length; _i < _len; _i++) { + task = tasks[_i]; + count += this._$tasksmodel.filterTasks(task, collectionID) && task.calendarid === listID; } + return count; }; ListsModel.prototype.notLoaded = function(listID) {