Prevent doubling of tasks in week view

This commit is contained in:
raimund-schluessler 2014-11-09 19:20:18 +01:00
parent c804ebb660
commit 6b9d268582
5 changed files with 101 additions and 146 deletions

View file

@ -108,6 +108,24 @@ SettingsBusinessLayer) ->
return (task) ->
return _$tasksmodel.filterTasks(task, _$scope.route.listID)
@_$scope.dayHasEntry = () ->
return (date) ->
tasks = _$tasksmodel.getAll()
for task in tasks
if task.completed
continue
if _$tasksmodel.taskAtDay(task, date)
return true
return false
@_$scope.getTasksAtDay = (tasks, day) ->
ret = []
for task in tasks
if _$tasksmodel.taskAtDay(task, day)
ret.push(task)
return ret
@_$scope.filterTasksByCalendar = (task, listID) ->
return (task) ->
return ''+task.calendarid == ''+listID
@ -166,10 +184,6 @@ SettingsBusinessLayer) ->
_$scope.taskName = ""
_$scope.status.focusTaskInput = false
@_$scope.dayHasEntry = () ->
return (date) ->
return _$tasksmodel.dayHasEntry(date)
@_$scope.getCompletedTasks = (listID) ->
_tasksbusinesslayer.getCompletedTasks(listID)

View file

@ -1,44 +0,0 @@
###
ownCloud - Tasks
@author Raimund Schlüßler
@copyright 2013
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
License as published by the Free Software Foundation; either
version 3 of the License, or any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU AFFERO GENERAL PUBLIC LICENSE for more details.
You should have received a copy of the GNU Affero General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
###
angular.module('Tasks').filter 'taskAtDay', () ->
return (tasks, date) ->
ret = []
for task in tasks
start = moment(task.start, "YYYYMMDDTHHmmss")
if start.isValid()
diff = start.diff(moment().startOf('day'), 'days', true)
if !date && diff < date+1
ret.push(task)
continue
else if diff < date+1 && diff >= date
ret.push(task)
continue
due = moment(task.due, "YYYYMMDDTHHmmss")
if due.isValid()
diff = due.diff(moment().startOf('day'), 'days', true)
if !date && diff < date+1
ret.push(task)
continue
else if diff < date+1 && diff >= date
ret.push(task)
continue
return ret

View file

@ -87,31 +87,31 @@ angular.module('Tasks').factory 'TasksModel',
for id in taskIDs
@removeById(id)
dayHasEntry: (date) ->
tasks = @getAll()
ret = false
for task in tasks
if task.completed
continue
start = moment(task.start, "YYYYMMDDTHHmmss")
if start.isValid()
diff = start.diff(moment().startOf('day'), 'days', true)
if !date && diff < date+1
ret = true
break
else if diff < date+1 && diff >= date
ret = true
break
due = moment(task.due, "YYYYMMDDTHHmmss")
if due.isValid()
diff = due.diff(moment().startOf('day'), 'days', true)
if !date && diff < date+1
ret = true
break
else if diff < date+1 && diff >= date
ret = true
break
return ret
taskAtDay: (task, date) ->
start = moment(task.start, "YYYYMMDDTHHmmss")
due = moment(task.due, "YYYYMMDDTHHmmss")
if start.isValid() && !due.isValid()
diff = start.diff(moment().startOf('day'), 'days', true)
if !date && diff < date+1
return true
else if diff < date+1 && diff >= date
return true
if due.isValid() && !start.isValid()
diff = due.diff(moment().startOf('day'), 'days', true)
if !date && diff < date+1
return true
else if diff < date+1 && diff >= date
return true
if start.isValid() && due.isValid()
startdiff = start.diff(moment().startOf('day'), 'days', true)
duediff = due.diff(moment().startOf('day'), 'days', true)
if !date && (startdiff < date+1 || duediff < date+1)
return true
else if startdiff < date+1 && startdiff >= date && duediff >= date
return true
else if duediff < date+1 && duediff >= date && startdiff >= date
return true
return false
filterTasks: (task, collectionID) ->
switch collectionID

View file

@ -1174,6 +1174,33 @@
return _$tasksmodel.filterTasks(task, _$scope.route.listID);
};
};
this._$scope.dayHasEntry = function() {
return function(date) {
var task, tasks, _i, _len;
tasks = _$tasksmodel.getAll();
for (_i = 0, _len = tasks.length; _i < _len; _i++) {
task = tasks[_i];
if (task.completed) {
continue;
}
if (_$tasksmodel.taskAtDay(task, date)) {
return true;
}
}
return false;
};
};
this._$scope.getTasksAtDay = function(tasks, day) {
var ret, task, _i, _len;
ret = [];
for (_i = 0, _len = tasks.length; _i < _len; _i++) {
task = tasks[_i];
if (_$tasksmodel.taskAtDay(task, day)) {
ret.push(task);
}
}
return ret;
};
this._$scope.filterTasksByCalendar = function(task, listID) {
return function(task) {
return '' + task.calendarid === '' + listID;
@ -1233,11 +1260,6 @@
return _$scope.status.focusTaskInput = false;
}
};
this._$scope.dayHasEntry = function() {
return function(date) {
return _$tasksmodel.dayHasEntry(date);
};
};
this._$scope.getCompletedTasks = function(listID) {
return _tasksbusinesslayer.getCompletedTasks(listID);
};
@ -2194,39 +2216,38 @@
return _results;
};
TasksModel.prototype.dayHasEntry = function(date) {
var diff, due, ret, start, task, tasks, _i, _len;
tasks = this.getAll();
ret = false;
for (_i = 0, _len = tasks.length; _i < _len; _i++) {
task = tasks[_i];
if (task.completed) {
continue;
}
start = moment(task.start, "YYYYMMDDTHHmmss");
if (start.isValid()) {
diff = start.diff(moment().startOf('day'), 'days', true);
if (!date && diff < date + 1) {
ret = true;
break;
} else if (diff < date + 1 && diff >= date) {
ret = true;
break;
}
}
due = moment(task.due, "YYYYMMDDTHHmmss");
if (due.isValid()) {
diff = due.diff(moment().startOf('day'), 'days', true);
if (!date && diff < date + 1) {
ret = true;
break;
} else if (diff < date + 1 && diff >= date) {
ret = true;
break;
}
TasksModel.prototype.taskAtDay = function(task, date) {
var diff, due, duediff, start, startdiff;
start = moment(task.start, "YYYYMMDDTHHmmss");
due = moment(task.due, "YYYYMMDDTHHmmss");
if (start.isValid() && !due.isValid()) {
diff = start.diff(moment().startOf('day'), 'days', true);
if (!date && diff < date + 1) {
return true;
} else if (diff < date + 1 && diff >= date) {
return true;
}
}
return ret;
if (due.isValid() && !start.isValid()) {
diff = due.diff(moment().startOf('day'), 'days', true);
if (!date && diff < date + 1) {
return true;
} else if (diff < date + 1 && diff >= date) {
return true;
}
}
if (start.isValid() && due.isValid()) {
startdiff = start.diff(moment().startOf('day'), 'days', true);
duediff = due.diff(moment().startOf('day'), 'days', true);
if (!date && (startdiff < date + 1 || duediff < date + 1)) {
return true;
} else if (startdiff < date + 1 && startdiff >= date && duediff >= date) {
return true;
} else if (duediff < date + 1 && duediff >= date && startdiff >= date) {
return true;
}
}
return false;
};
TasksModel.prototype.filterTasks = function(task, collectionID) {
@ -3060,42 +3081,6 @@
}).call(this);
(function() {
angular.module('Tasks').filter('taskAtDay', function() {
return function(tasks, date) {
var diff, due, ret, start, task, _i, _len;
ret = [];
for (_i = 0, _len = tasks.length; _i < _len; _i++) {
task = tasks[_i];
start = moment(task.start, "YYYYMMDDTHHmmss");
if (start.isValid()) {
diff = start.diff(moment().startOf('day'), 'days', true);
if (!date && diff < date + 1) {
ret.push(task);
continue;
} else if (diff < date + 1 && diff >= date) {
ret.push(task);
continue;
}
}
due = moment(task.due, "YYYYMMDDTHHmmss");
if (due.isValid()) {
diff = due.diff(moment().startOf('day'), 'days', true);
if (!date && diff < date + 1) {
ret.push(task);
continue;
} else if (diff < date + 1 && diff >= date) {
ret.push(task);
continue;
}
}
}
return ret;
};
});
}).call(this);
(function() {
angular.module('Tasks').filter('timeTaskList', function() {
return function(due) {

View file

@ -4,7 +4,7 @@
<text>{{ day | day }}</text>
</h2>
<ol class="tasks">
<li ng-animate="'animate'" ng-repeat="task in tasks | taskAtDay:day | filter:{'completed':'false'} | orderBy:sortDue | orderBy:'starred':true"
<li ng-animate="'animate'" ng-repeat="task in getTasksAtDay(tasks, day) | filter:{'completed':'false'} | orderBy:sortDue | orderBy:'starred':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:{{ getTaskColor(task.calendarid) }};"></div>