Merge pull request #99 from owncloud/LazyLoading
Load only last five completed tasks per list, closes #3
This commit is contained in:
commit
9453e07835
11 changed files with 144 additions and 35 deletions
|
@ -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'),
|
||||
|
|
|
@ -39,14 +39,22 @@ class TasksController extends Controller {
|
|||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function getTasks(){
|
||||
$calendars = \OC_Calendar_Calendar::allCalendars($this->userId, true);
|
||||
public function getTasks($listID = 'all', $type = 'all'){
|
||||
|
||||
$user_timezone = \OC_Calendar_App::getTimezone();
|
||||
if ($listID == 'all'){
|
||||
$calendars = \OC_Calendar_Calendar::allCalendars($this->userId, true);
|
||||
} else {
|
||||
$calendar = \OC_Calendar_App::getCalendar($listID, true, false);
|
||||
$calendars = array($calendar);
|
||||
}
|
||||
|
||||
$tasks = array();
|
||||
$lists = array();
|
||||
foreach( $calendars as $calendar ) {
|
||||
$calendar_tasks = \OC_Calendar_Object::all($calendar['id']);
|
||||
foreach( $calendar_tasks as $task ) {
|
||||
$calendar_entries = \OC_Calendar_Object::all($calendar['id']);
|
||||
$tasks_selected = array();
|
||||
foreach( $calendar_entries as $task ) {
|
||||
if($task['objecttype']!='VTODO') {
|
||||
continue;
|
||||
}
|
||||
|
@ -58,16 +66,53 @@ class TasksController extends Controller {
|
|||
$task_data = Helper::arrayForJSON($task['id'], $vtodo, $user_timezone);
|
||||
$task_data['calendarid'] = $calendar['id'];
|
||||
$task_data['calendarcolor'] = $calendar['calendarcolor'];
|
||||
$tasks[] = $task_data;
|
||||
|
||||
switch($type){
|
||||
case 'all':
|
||||
$tasks[] = $task_data;
|
||||
break;
|
||||
case 'init':
|
||||
if (!$task_data['completed']){
|
||||
$tasks[] = $task_data;
|
||||
} else {
|
||||
$tasks_selected[] = $task_data;
|
||||
}
|
||||
break;
|
||||
case 'completed':
|
||||
if ($task_data['completed']){
|
||||
$tasks[] = $task_data;
|
||||
}
|
||||
break;
|
||||
case 'uncompleted':
|
||||
if (!$task_data['completed']){
|
||||
$tasks[] = $task_data;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
\OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR);
|
||||
}
|
||||
}
|
||||
$nrCompleted = 0;
|
||||
$notLoaded = 0;
|
||||
usort($tasks_selected, array($this, 'sort_completed'));
|
||||
foreach( $tasks_selected as $task_selected){
|
||||
$nrCompleted++;
|
||||
if ($nrCompleted > 5){
|
||||
$notLoaded++;
|
||||
continue;
|
||||
}
|
||||
$tasks[] = $task_selected;
|
||||
}
|
||||
$lists[] = array(
|
||||
'id' => $calendar['id'],
|
||||
'notLoaded' => $notLoaded
|
||||
);
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'data' => array(
|
||||
'tasks' => $tasks
|
||||
'tasks' => $tasks,
|
||||
'lists' => $lists
|
||||
)
|
||||
);
|
||||
$response = new JSONResponse();
|
||||
|
@ -75,6 +120,15 @@ class TasksController extends Controller {
|
|||
return $response;
|
||||
}
|
||||
|
||||
private static function sort_completed($a, $b){
|
||||
$t1 = \DateTime::createFromFormat('Ymd\THis', $a['completed_date']);
|
||||
$t2 = \DateTime::createFromFormat('Ymd\THis', $b['completed_date']);
|
||||
if ($t1 == $t2) {
|
||||
return 0;
|
||||
}
|
||||
return $t1 < $t2 ? 1 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $isStarred
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -325,14 +325,11 @@ angular.module('Tasks').factory 'TasksBusinessLayer',
|
|||
@_$tasksmodel.voidAll()
|
||||
success = () =>
|
||||
@_$tasksmodel.removeVoid()
|
||||
@_persistence.getTasks(success, true)
|
||||
@_persistence.getTasks('init', '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('completed', listID)
|
||||
|
||||
return new TasksBusinessLayer(TasksModel, Persistence)
|
||||
|
||||
|
|
|
@ -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)
|
||||
]
|
|
@ -37,7 +37,7 @@ angular.module('Tasks').factory 'Persistence',
|
|||
@getCollections()
|
||||
@getSettings()
|
||||
@getLists()
|
||||
@getTasks(successCallback)
|
||||
@getTasks('init', '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: (type='init', listID='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
|
||||
|
|
|
@ -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('init', '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('completed', listID);
|
||||
};
|
||||
|
||||
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('init', '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(type, listID, onSuccess, showLoading) {
|
||||
var failureCallbackWrapper, params, successCallbackWrapper,
|
||||
_this = this;
|
||||
if (type == null) {
|
||||
type = 'init';
|
||||
}
|
||||
if (listID == null) {
|
||||
listID = '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) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<text>{{ list.displayname }}</text>
|
||||
</h2>
|
||||
<ol class="tasks">
|
||||
<li ng-animate="'animate'" ng-repeat="task in tasks | filter:filterTasksByCalendar(task,list.id) | filter:filterTasks(task) | orderBy:sortDue | orderBy:'starred':true"
|
||||
<li ng-animate="'animate'" ng-repeat="task in tasks | filter:filterTasksByCalendar(task,list.id) | filter:filterTasks(task) | orderBy:sortDue | orderBy:'starred':true | orderBy:'completed_date':true"
|
||||
class="task-item ui-draggable" rel="{{ task.id }}" ng-click="openDetails(task.id)" ng-class="{done: task.completed}" oc-drag-task stop-event="click">
|
||||
<div class="task-body">
|
||||
<div class="percentdone" style="width:{{ task.complete }}%; background-color:{{list.calendarcolor}};"></div>
|
||||
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue