Load only the last five completed tasks per list

This commit is contained in:
raimund-schluessler 2014-11-06 22:17:51 +01:00
parent 697344cd11
commit 930abaae99
11 changed files with 113 additions and 30 deletions

View file

@ -42,7 +42,7 @@ $application->registerRoutes($this, array('routes' => array(
array('name' => 'lists#setListName','url' => '/lists/{listID}/name', 'verb' => 'POST'),
// tasks
array('name' => 'tasks#getTasks', 'url' => '/tasks', 'verb' => 'GET'),
array('name' => 'tasks#getTasks', 'url' => '/tasks/{type}/{listID}', 'verb' => 'GET'),
array('name' => 'tasks#starTask', 'url' => '/tasks/{taskID}/star', 'verb' => 'POST'),
array('name' => 'tasks#unstarTask', 'url' => '/tasks/{taskID}/unstar', 'verb' => 'POST'),
array('name' => 'tasks#completeTask', 'url' => '/tasks/{taskID}/complete', 'verb' => 'POST'),

View file

@ -39,13 +39,20 @@ class TasksController extends Controller {
/**
* @NoAdminRequired
*/
public function getTasks(){
public function getTasks($listID = 'all', $type = 'all'){
$calendars = \OC_Calendar_Calendar::allCalendars($this->userId, true);
$user_timezone = \OC_Calendar_App::getTimezone();
$tasks = array();
$lists = array();
foreach( $calendars as $calendar ) {
if ($listID != 'all' && $calendar['id'] != $listID){
continue;
}
$calendar_tasks = \OC_Calendar_Object::all($calendar['id']);
$nrCompleted = 0;
$notLoaded = 0;
foreach( $calendar_tasks as $task ) {
if($task['objecttype']!='VTODO') {
continue;
@ -58,16 +65,37 @@ class TasksController extends Controller {
$task_data = Helper::arrayForJSON($task['id'], $vtodo, $user_timezone);
$task_data['calendarid'] = $calendar['id'];
$task_data['calendarcolor'] = $calendar['calendarcolor'];
switch($type){
case 'all':
if ($task_data['completed']){
$nrCompleted++;
if ($nrCompleted > 5){
$notLoaded++;
continue 2;
}
}
break;
case 'completed':
if (!$task_data['completed']){
continue 2;
}
break;
}
$tasks[] = $task_data;
} catch(\Exception $e) {
\OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR);
}
}
$lists[] = array(
'id' => $calendar['id'],
'notLoaded' => $notLoaded
);
}
$result = array(
'data' => array(
'tasks' => $tasks
'tasks' => $tasks,
'lists' => $lists
)
);
$response = new JSONResponse();

View file

@ -594,9 +594,15 @@
margin-top: 10px;
text-align: center;
}
#app-content div.task-list .loadmore span:hover {
#app-content div.task-list .loadmore span {
color: #A0A0A0;
background-color: #e9e9e9;
border-radius: 10px;
padding: 3px 6px;
}
#app-content div.task-list .loadmore span:hover {
cursor: pointer;
color: #555;
}
#app-content div.task-list.completed-hidden ol.completed-tasks {
display: none;

View file

@ -627,9 +627,15 @@
}
.loadmore{
span:hover{
span{
color: #A0A0A0;
cursor: pointer;
background-color: #e9e9e9;
border-radius: 10px;
padding: 3px 6px;
&:hover{
cursor: pointer;
color: #555;
}
}
font-size: 11px;
margin-top: 10px;

View file

@ -181,8 +181,11 @@ SettingsBusinessLayer) ->
return (date) ->
return _$tasksmodel.dayHasEntry(date)
@_$scope.loadMore = () ->
console.log('TODO')
@_$scope.getCompletedTasks = (listID) ->
_tasksbusinesslayer.getCompletedTasks(listID)
@_$scope.loadedAll = (listID) ->
return _$listsmodel.loadedAll(listID)
@_$scope.sortDue = (task) ->
if task.due == null

View file

@ -325,14 +325,11 @@ angular.module('Tasks').factory 'TasksBusinessLayer',
@_$tasksmodel.voidAll()
success = () =>
@_$tasksmodel.removeVoid()
@_persistence.getTasks(success, true)
@_persistence.getTasks('all', 'all', success, true)
setShowHidden: (showHidden) ->
@_persistence.setShowHidden(showHidden)
# addComment: (taskID, comment) ->
# @_persistence.addComment(taskID, comment)
addComment: (comment, onSuccess=null, onFailure=null) ->
onSuccess or= ->
onFailure or= ->
@ -350,6 +347,8 @@ angular.module('Tasks').factory 'TasksBusinessLayer',
@_$tasksmodel.deleteComment(taskID, commentID)
@_persistence.deleteComment(taskID, commentID)
getCompletedTasks: (listID) ->
@_persistence.getTasks(listID, 'completed')
return new TasksBusinessLayer(TasksModel, Persistence)

View file

@ -109,7 +109,7 @@ angular.module('Tasks').factory 'ListsModel',
when 'completed'
for task in tasks
count += (task.calendarid==listID && task.completed)
return count
return count + @notLoaded(listID)
when 'starred'
for task in tasks
count += (task.calendarid==listID && !task.completed && task.starred)
@ -120,5 +120,14 @@ angular.module('Tasks').factory 'ListsModel',
@_$tasksmodel.today(task.due))
return count
notLoaded: (listID) ->
if angular.isUndefined(@getById(listID))
return 0
else
return @getById(listID).notLoaded
loadedAll: (listID) ->
return !@notLoaded(listID)
return new ListsModel(TasksModel, Utils)
]

View file

@ -37,7 +37,7 @@ angular.module('Tasks').factory 'Persistence',
@getCollections()
@getSettings()
@getLists()
@getTasks(successCallback)
@getTasks('all', 'all', successCallback)
@deferred.promise
@ -155,7 +155,7 @@ angular.module('Tasks').factory 'Persistence',
@_request.post '/apps/tasks/lists/{listID}/delete', params
getTasks: (onSuccess, showLoading=true) ->
getTasks: (listID='all', type='all', onSuccess, showLoading=true) ->
onSuccess or= ->
if showLoading
@ -173,8 +173,11 @@ angular.module('Tasks').factory 'Persistence',
params =
onSuccess: successCallbackWrapper
onFailure: failureCallbackWrapper
routeParams:
listID: listID
type: type
@_request.get '/apps/tasks/tasks', params
@_request.get '/apps/tasks/tasks/{type}/{listID}', params
starTask: (taskID) ->
params =
@ -203,9 +206,6 @@ angular.module('Tasks').factory 'Persistence',
onSuccess or= ->
onFailure or= ->
params =
# routeParams:
# name: task.name
# calendarID: task.calendarID
data:
name: task.name
calendarID: task.calendarID

View file

@ -1249,8 +1249,11 @@
return _$tasksmodel.dayHasEntry(date);
};
};
this._$scope.loadMore = function() {
return console.log('TODO');
this._$scope.getCompletedTasks = function(listID) {
return _tasksbusinesslayer.getCompletedTasks(listID);
};
this._$scope.loadedAll = function(listID) {
return _$listsmodel.loadedAll(listID);
};
this._$scope.sortDue = function(task) {
if (task.due === null) {
@ -1765,7 +1768,7 @@
success = function() {
return _this._$tasksmodel.removeVoid();
};
return this._persistence.getTasks(success, true);
return this._persistence.getTasks('all', 'all', success, true);
};
TasksBusinessLayer.prototype.setShowHidden = function(showHidden) {
@ -1799,6 +1802,10 @@
return this._persistence.deleteComment(taskID, commentID);
};
TasksBusinessLayer.prototype.getCompletedTasks = function(listID) {
return this._persistence.getTasks(listID, 'completed');
};
return TasksBusinessLayer;
})();
@ -2028,7 +2035,7 @@
task = tasks[_k];
count += task.calendarid === listID && task.completed;
}
return count;
return count + this.notLoaded(listID);
case 'starred':
for (_l = 0, _len3 = tasks.length; _l < _len3; _l++) {
task = tasks[_l];
@ -2044,6 +2051,18 @@
}
};
ListsModel.prototype.notLoaded = function(listID) {
if (angular.isUndefined(this.getById(listID))) {
return 0;
} else {
return this.getById(listID).notLoaded;
}
};
ListsModel.prototype.loadedAll = function(listID) {
return !this.notLoaded(listID);
};
return ListsModel;
})(_Model);
@ -2395,7 +2414,7 @@
this.getCollections();
this.getSettings();
this.getLists();
this.getTasks(successCallback);
this.getTasks('all', 'all', successCallback);
return this.deferred.promise;
};
@ -2561,9 +2580,15 @@
return this._request.post('/apps/tasks/lists/{listID}/delete', params);
};
Persistence.prototype.getTasks = function(onSuccess, showLoading) {
Persistence.prototype.getTasks = function(listID, type, onSuccess, showLoading) {
var failureCallbackWrapper, params, successCallbackWrapper,
_this = this;
if (listID == null) {
listID = 'all';
}
if (type == null) {
type = 'all';
}
if (showLoading == null) {
showLoading = true;
}
@ -2585,9 +2610,13 @@
}
params = {
onSuccess: successCallbackWrapper,
onFailure: failureCallbackWrapper
onFailure: failureCallbackWrapper,
routeParams: {
listID: listID,
type: type
}
};
return this._request.get('/apps/tasks/tasks', params);
return this._request.get('/apps/tasks/tasks/{type}/{listID}', params);
};
Persistence.prototype.starTask = function(taskID) {

View file

@ -23,5 +23,8 @@
</div>
</li>
</ol>
<div class="loadmore" ng-hide="loadedAll(list.id) || route.listID != 'completed'">
<span ng-click="getCompletedTasks(list.id)" stop-event="click"> <?php p($l->t('Load remaining completed tasks.')); ?> </span>
</div>
</div>
</div>

View file

@ -45,8 +45,8 @@
</div>
</li>
</ol>
<div class="loadmore">
<!-- <span ng-click="loadMore()" stop-event="click"> <?php p($l->t('Load more completed tasks')); ?> </span> -->
<div class="loadmore" ng-hide="loadedAll(route.listID)">
<span ng-click="getCompletedTasks(route.listID)" stop-event="click"> <?php p($l->t('Load remaining completed tasks.')); ?> </span>
</div>
</div>
</div>