filter search results in case task is already shown
This commit is contained in:
parent
6eb7b19f23
commit
96882cd8ab
9 changed files with 151 additions and 101 deletions
|
@ -33,6 +33,7 @@ class SearchController extends \OCP\Search\Provider {
|
|||
*/
|
||||
function search($query) {
|
||||
$calendars = \OC_Calendar_Calendar::allCalendars(\OCP\USER::getUser(), true);
|
||||
$user_timezone = \OC_Calendar_App::getTimezone();
|
||||
// check if the calenar is enabled
|
||||
if (count($calendars) == 0 || !\OCP\App::isEnabled('tasks')) {
|
||||
return array();
|
||||
|
@ -58,7 +59,7 @@ class SearchController extends \OCP\Search\Provider {
|
|||
foreach ($properties as $property) {
|
||||
$string = $vtodo->getAsString($property);
|
||||
if (stripos($string, $query) !== false) {
|
||||
$results[] = new \OCA\Tasks\Controller\Task($id,$calendarId,$vtodo,$property,$query);
|
||||
$results[] = new \OCA\Tasks\Controller\Task($id,$calendarId,$vtodo,$property,$query,$user_timezone);
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +67,7 @@ class SearchController extends \OCP\Search\Provider {
|
|||
if($comments) {
|
||||
foreach($comments as $com) {
|
||||
if (stripos($com->value, $query) !== false) {
|
||||
$results[] = new \OCA\Tasks\Controller\Task($id,$calendarId,$vtodo,'COMMENTS',$query);
|
||||
$results[] = new \OCA\Tasks\Controller\Task($id,$calendarId,$vtodo,'COMMENTS',$query,$user_timezone);
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,18 +54,25 @@ class Task extends \OCP\Search\Result {
|
|||
public $text = '';
|
||||
|
||||
/**
|
||||
* Start time for the event
|
||||
* Start time for the task
|
||||
*
|
||||
* @var string human-readable string in RFC2822 format
|
||||
*/
|
||||
public $start_time;
|
||||
public $start;
|
||||
|
||||
/**
|
||||
* End time for the event
|
||||
* Due time for the task
|
||||
*
|
||||
* @var string human-readable string in RFC2822 format
|
||||
*/
|
||||
public $end_time;
|
||||
public $due;
|
||||
|
||||
/**
|
||||
* Is Task starred
|
||||
*
|
||||
* @var boolean human-readable string in RFC2822 format
|
||||
*/
|
||||
public $starred;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -73,12 +80,39 @@ class Task extends \OCP\Search\Result {
|
|||
* @param array $data
|
||||
* @return \OCA\Tasks\Controller\Task
|
||||
*/
|
||||
public function __construct($taskId, $calendarId, $vtodo, $reason, $query) {
|
||||
public function __construct($taskId, $calendarId, $vtodo, $reason, $query, $user_timezone) {
|
||||
// set default properties
|
||||
$this->id = $taskId;
|
||||
$this->calendarID = $calendarId;
|
||||
$this->calendarid = $calendarId;
|
||||
$this->name = $vtodo->getAsString('SUMMARY');
|
||||
$this->completed = $vtodo->COMPLETED ? true : false;
|
||||
$start = $vtodo->DTSTART;
|
||||
if ($start) {
|
||||
try {
|
||||
$start = $start->getDateTime();
|
||||
$start->setTimezone(new \DateTimeZone($user_timezone));
|
||||
$this->start = $start->format('Ymd\THis');
|
||||
} catch(\Exception $e) {
|
||||
$this->start = null;
|
||||
\OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR);
|
||||
}
|
||||
} else {
|
||||
$this->start = null;
|
||||
}
|
||||
$due = $vtodo->DUE;
|
||||
if ($due) {
|
||||
try {
|
||||
$due = $due->getDateTime();
|
||||
$due->setTimezone(new \DateTimeZone($user_timezone));
|
||||
$this->due = $due->format('Ymd\THis');
|
||||
} catch(\Exception $e) {
|
||||
$this->due = null;
|
||||
\OCP\Util::writeLog('tasks', $e->getMessage(), \OCP\Util::ERROR);
|
||||
}
|
||||
} else {
|
||||
$this->due = null;
|
||||
}
|
||||
$this->starred = $vtodo->getAsString('PRIORITY') ? true : false;
|
||||
$this->link = \OCP\Util::linkToRoute('tasks.page.index') . '#/lists/' . $calendarId . '/tasks/' . $taskId;
|
||||
$l = new \OC_l10n('tasks');
|
||||
switch($reason){
|
||||
|
|
|
@ -77,25 +77,6 @@ SettingsBusinessLayer, SearchBusinessLayer) ->
|
|||
else
|
||||
return true
|
||||
|
||||
@_$scope.filterByString = () =>
|
||||
return (task) ->
|
||||
keys = ['name', 'note', 'location',
|
||||
'categories', 'comments']
|
||||
filter = _searchbusinesslayer.getFilter().toLowerCase()
|
||||
for key,value of task
|
||||
if key in keys
|
||||
if key == 'comments'
|
||||
for comment in task.comments
|
||||
if comment.comment.toLowerCase().indexOf(filter) !=-1
|
||||
return true
|
||||
else if key == 'categories'
|
||||
for category in task.categories
|
||||
if category.toLowerCase().indexOf(filter) !=-1
|
||||
return true
|
||||
else if value.toLowerCase().indexOf(filter) !=-1
|
||||
return true
|
||||
return false
|
||||
|
||||
@_$scope.focusInput = () ->
|
||||
_$scope.status.focusTaskInput = true
|
||||
|
||||
|
@ -119,9 +100,14 @@ SettingsBusinessLayer, SearchBusinessLayer) ->
|
|||
@_$scope.toggleHidden = () ->
|
||||
_settingsbusinesslayer.toggle('various','showHidden')
|
||||
|
||||
@_$scope.filterTasks = () ->
|
||||
@_$scope.filterTasks = (task, filter) ->
|
||||
return (task) ->
|
||||
return _$tasksmodel.filterTasks(task, _$scope.route.listID)
|
||||
return _$tasksmodel.filterTasks(task, filter)
|
||||
|
||||
@_$scope.filterTasksByString = (task) =>
|
||||
return (task) ->
|
||||
filter = _searchbusinesslayer.getFilter().toLowerCase()
|
||||
return _$tasksmodel.filterTasksByString(task, filter)
|
||||
|
||||
@_$scope.dayHasEntry = () ->
|
||||
return (date) ->
|
||||
|
@ -140,10 +126,6 @@ SettingsBusinessLayer, SearchBusinessLayer) ->
|
|||
ret.push(task)
|
||||
return ret
|
||||
|
||||
@_$scope.filterTasksByCalendar = (task, listID) ->
|
||||
return (task) ->
|
||||
return ''+task.calendarid == ''+listID
|
||||
|
||||
@_$scope.filterLists = () ->
|
||||
return (list) ->
|
||||
return _$scope.getCount(list.id,_$scope.route.listID)
|
||||
|
|
|
@ -23,12 +23,14 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
angular.module('Tasks').factory 'SearchBusinessLayer',
|
||||
['ListsModel', 'Persistence', 'TasksModel', '$rootScope',
|
||||
(ListsModel, Persistence, TasksModel, $rootScope) ->
|
||||
'$routeParams',
|
||||
(ListsModel, Persistence, TasksModel, $rootScope,
|
||||
$routeParams) ->
|
||||
|
||||
class SearchBusinessLayer
|
||||
|
||||
constructor: (@_$listsmodel, @_persistence,
|
||||
@_$tasksmodel, @_$rootScope) ->
|
||||
@_$tasksmodel, @_$rootScope, @_$routeparams) ->
|
||||
@initialize()
|
||||
@_$searchString = ''
|
||||
|
||||
|
@ -37,13 +39,6 @@ angular.module('Tasks').factory 'SearchBusinessLayer',
|
|||
@_$rootScope.$apply(
|
||||
@setFilter(query)
|
||||
)
|
||||
# if (self.fileAppLoaded())
|
||||
# self.fileList.setFilter(query)
|
||||
# if (query.length > 2)
|
||||
# # //search is not started until 500msec have passed
|
||||
# window.setTimeout(() =>
|
||||
# $('.nofilterresults').addClass('hidden')
|
||||
# , 500)
|
||||
)
|
||||
search.setRenderer('task', @renderTaskResult.bind(@))
|
||||
search.setHandler('task', @handleTaskClick.bind(@))
|
||||
|
@ -59,14 +54,16 @@ angular.module('Tasks').factory 'SearchBusinessLayer',
|
|||
console.log('Search result clicked')
|
||||
|
||||
@renderTaskResult = ($row, result) =>
|
||||
# console.log('Render result')
|
||||
# console.log($row)
|
||||
# console.log(result)
|
||||
return $row
|
||||
if !@_$tasksmodel.filterTasks(result,@_$routeparams.listID) ||
|
||||
!@_$tasksmodel.isLoaded(result)
|
||||
return $row
|
||||
else
|
||||
return null
|
||||
|
||||
OC.Plugins.register('OCA.Search', @)
|
||||
|
||||
|
||||
return new SearchBusinessLayer(ListsModel, Persistence,
|
||||
TasksModel, $rootScope)
|
||||
TasksModel, $rootScope, $routeParams)
|
||||
|
||||
]
|
|
@ -113,8 +113,11 @@ angular.module('Tasks').factory 'TasksModel',
|
|||
return true
|
||||
return false
|
||||
|
||||
filterTasks: (task, collectionID) ->
|
||||
switch collectionID
|
||||
isLoaded: (task) ->
|
||||
return if @getById(task.id) then true else false
|
||||
|
||||
filterTasks: (task, filter) ->
|
||||
switch filter
|
||||
when 'completed'
|
||||
return task.completed == true
|
||||
when 'all'
|
||||
|
@ -129,6 +132,25 @@ angular.module('Tasks').factory 'TasksModel',
|
|||
when 'week'
|
||||
return (task.completed == false && (@week(task.start) ||
|
||||
@week(task.due)))
|
||||
else
|
||||
return ''+task.calendarid == ''+filter
|
||||
|
||||
filterTasksByString: (task, filter) ->
|
||||
keys = ['name', 'note', 'location',
|
||||
'categories', 'comments']
|
||||
for key,value of task
|
||||
if key in keys
|
||||
if key == 'comments'
|
||||
for comment in task.comments
|
||||
if comment.comment.toLowerCase().indexOf(filter) !=-1
|
||||
return true
|
||||
else if key == 'categories'
|
||||
for category in task.categories
|
||||
if category.toLowerCase().indexOf(filter) !=-1
|
||||
return true
|
||||
else if value.toLowerCase().indexOf(filter) !=-1
|
||||
return true
|
||||
return false
|
||||
|
||||
starred: (taskID) ->
|
||||
return @getById(taskID).starred
|
||||
|
|
110
js/public/app.js
110
js/public/app.js
|
@ -1037,8 +1037,6 @@
|
|||
}).call(this);
|
||||
|
||||
(function() {
|
||||
var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
angular.module('Tasks').controller('TasksController', [
|
||||
'$scope', '$window', '$routeParams', 'TasksModel', 'ListsModel', 'CollectionsModel', 'TasksBusinessLayer', '$location', 'SettingsBusinessLayer', 'SearchBusinessLayer', function($scope, $window, $routeParams, TasksModel, ListsModel, CollectionsModel, TasksBusinessLayer, $location, SettingsBusinessLayer, SearchBusinessLayer) {
|
||||
var TasksController;
|
||||
|
@ -1092,38 +1090,6 @@
|
|||
return true;
|
||||
}
|
||||
};
|
||||
this._$scope.filterByString = function() {
|
||||
return function(task) {
|
||||
var category, comment, filter, key, keys, value, _i, _j, _len, _len1, _ref, _ref1;
|
||||
keys = ['name', 'note', 'location', 'categories', 'comments'];
|
||||
filter = _searchbusinesslayer.getFilter().toLowerCase();
|
||||
for (key in task) {
|
||||
value = task[key];
|
||||
if (__indexOf.call(keys, key) >= 0) {
|
||||
if (key === 'comments') {
|
||||
_ref = task.comments;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
comment = _ref[_i];
|
||||
if (comment.comment.toLowerCase().indexOf(filter) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (key === 'categories') {
|
||||
_ref1 = task.categories;
|
||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||
category = _ref1[_j];
|
||||
if (category.toLowerCase().indexOf(filter) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (value.toLowerCase().indexOf(filter) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
};
|
||||
this._$scope.focusInput = function() {
|
||||
return _$scope.status.focusTaskInput = true;
|
||||
};
|
||||
|
@ -1150,9 +1116,16 @@
|
|||
this._$scope.toggleHidden = function() {
|
||||
return _settingsbusinesslayer.toggle('various', 'showHidden');
|
||||
};
|
||||
this._$scope.filterTasks = function() {
|
||||
this._$scope.filterTasks = function(task, filter) {
|
||||
return function(task) {
|
||||
return _$tasksmodel.filterTasks(task, _$scope.route.listID);
|
||||
return _$tasksmodel.filterTasks(task, filter);
|
||||
};
|
||||
};
|
||||
this._$scope.filterTasksByString = function(task) {
|
||||
return function(task) {
|
||||
var filter;
|
||||
filter = _searchbusinesslayer.getFilter().toLowerCase();
|
||||
return _$tasksmodel.filterTasksByString(task, filter);
|
||||
};
|
||||
};
|
||||
this._$scope.dayHasEntry = function() {
|
||||
|
@ -1182,11 +1155,6 @@
|
|||
}
|
||||
return ret;
|
||||
};
|
||||
this._$scope.filterTasksByCalendar = function(task, listID) {
|
||||
return function(task) {
|
||||
return '' + task.calendarid === '' + listID;
|
||||
};
|
||||
};
|
||||
this._$scope.filterLists = function() {
|
||||
return function(list) {
|
||||
return _$scope.getCount(list.id, _$scope.route.listID);
|
||||
|
@ -1337,14 +1305,15 @@
|
|||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||||
|
||||
angular.module('Tasks').factory('SearchBusinessLayer', [
|
||||
'ListsModel', 'Persistence', 'TasksModel', '$rootScope', function(ListsModel, Persistence, TasksModel, $rootScope) {
|
||||
'ListsModel', 'Persistence', 'TasksModel', '$rootScope', '$routeParams', function(ListsModel, Persistence, TasksModel, $rootScope, $routeParams) {
|
||||
var SearchBusinessLayer;
|
||||
SearchBusinessLayer = (function() {
|
||||
function SearchBusinessLayer(_$listsmodel, _persistence, _$tasksmodel, _$rootScope) {
|
||||
function SearchBusinessLayer(_$listsmodel, _persistence, _$tasksmodel, _$rootScope, _$routeparams) {
|
||||
this._$listsmodel = _$listsmodel;
|
||||
this._persistence = _persistence;
|
||||
this._$tasksmodel = _$tasksmodel;
|
||||
this._$rootScope = _$rootScope;
|
||||
this._$routeparams = _$routeparams;
|
||||
this.getFilter = __bind(this.getFilter, this);
|
||||
this.setFilter = __bind(this.setFilter, this);
|
||||
this.attach = __bind(this.attach, this);
|
||||
|
@ -1375,7 +1344,11 @@
|
|||
return console.log('Search result clicked');
|
||||
};
|
||||
this.renderTaskResult = function($row, result) {
|
||||
return $row;
|
||||
if (!_this._$tasksmodel.filterTasks(result, _this._$routeparams.listID) || !_this._$tasksmodel.isLoaded(result)) {
|
||||
return $row;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return OC.Plugins.register('OCA.Search', this);
|
||||
};
|
||||
|
@ -1383,7 +1356,7 @@
|
|||
return SearchBusinessLayer;
|
||||
|
||||
})();
|
||||
return new SearchBusinessLayer(ListsModel, Persistence, TasksModel, $rootScope);
|
||||
return new SearchBusinessLayer(ListsModel, Persistence, TasksModel, $rootScope, $routeParams);
|
||||
}
|
||||
]);
|
||||
|
||||
|
@ -2130,7 +2103,8 @@
|
|||
|
||||
(function() {
|
||||
var __hasProp = {}.hasOwnProperty,
|
||||
__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; };
|
||||
__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; },
|
||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
angular.module('Tasks').factory('TasksModel', [
|
||||
'_Model', '_EqualQuery', 'Utils', function(_Model, _EqualQuery, Utils) {
|
||||
|
@ -2266,8 +2240,16 @@
|
|||
return false;
|
||||
};
|
||||
|
||||
TasksModel.prototype.filterTasks = function(task, collectionID) {
|
||||
switch (collectionID) {
|
||||
TasksModel.prototype.isLoaded = function(task) {
|
||||
if (this.getById(task.id)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
TasksModel.prototype.filterTasks = function(task, filter) {
|
||||
switch (filter) {
|
||||
case 'completed':
|
||||
return task.completed === true;
|
||||
case 'all':
|
||||
|
@ -2280,9 +2262,41 @@
|
|||
return task.completed === false && (this.today(task.start) || this.today(task.due));
|
||||
case 'week':
|
||||
return task.completed === false && (this.week(task.start) || this.week(task.due));
|
||||
default:
|
||||
return '' + task.calendarid === '' + filter;
|
||||
}
|
||||
};
|
||||
|
||||
TasksModel.prototype.filterTasksByString = function(task, filter) {
|
||||
var category, comment, key, keys, value, _i, _j, _len, _len1, _ref, _ref1;
|
||||
keys = ['name', 'note', 'location', 'categories', 'comments'];
|
||||
for (key in task) {
|
||||
value = task[key];
|
||||
if (__indexOf.call(keys, key) >= 0) {
|
||||
if (key === 'comments') {
|
||||
_ref = task.comments;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
comment = _ref[_i];
|
||||
if (comment.comment.toLowerCase().indexOf(filter) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (key === 'categories') {
|
||||
_ref1 = task.categories;
|
||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||
category = _ref1[_j];
|
||||
if (category.toLowerCase().indexOf(filter) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (value.toLowerCase().indexOf(filter) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
TasksModel.prototype.starred = function(taskID) {
|
||||
return this.getById(taskID).starred;
|
||||
};
|
||||
|
|
|
@ -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) | filter:filterByString(task) | orderBy:sortDue | orderBy:'starred':true | orderBy:'completed_date':true"
|
||||
<li ng-animate="'animate'" ng-repeat="task in tasks | filter:filterTasks(task,list.id) | filter:filterTasks(task,route.listID) | filter:filterTasksByString(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>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<text>{{ day | day }}</text>
|
||||
</h2>
|
||||
<ol class="tasks">
|
||||
<li ng-animate="'animate'" ng-repeat="task in getTasksAtDay(tasks, day) | filter:filterByString(task) | filter:{'completed':'false'} | orderBy:sortDue | orderBy:'starred':true"
|
||||
<li ng-animate="'animate'" ng-repeat="task in getTasksAtDay(tasks, day) | filter:filterTasksByString(task) | 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>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div ng-switch-default>
|
||||
<div class="grouped-tasks">
|
||||
<ol class="tasks" rel="uncompleted" oc-drop-task>
|
||||
<li ng-repeat="(id, task) in tasks | filter:filterTasksByCalendar(task,route.listID) | filter:{'completed':'false'} | filter:filterByString(task) | orderBy:sortDue | orderBy:'starred':true"
|
||||
<li ng-repeat="(id, task) in tasks | filter:filterTasks(task,route.listID) | filter:{'completed':'false'} | filter:filterTasksByString(task) | 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>
|
||||
|
@ -25,7 +25,7 @@
|
|||
<text ng-click="toggleHidden()">{{ getCountString(route.listID,'completed') }}</text>
|
||||
</h2>
|
||||
<ol class="completed-tasks" rel="completed" oc-drop-task>
|
||||
<li ng-repeat="task in tasks | filter:filterTasksByCalendar(task,route.listID) | filter:{'completed':'true'} | filter:filterByString(task) | orderBy:'completed_date':true"
|
||||
<li ng-repeat="task in tasks | filter:filterTasks(task,route.listID) | filter:{'completed':'true'} | filter:filterTasksByString(task) | orderBy:'completed_date':true"
|
||||
class="task-item" rel="{{ task.id }}" ng-click="openDetails(task.id)"
|
||||
ng-class="{done: task.completed}" oc-drag-task stop-event="click">
|
||||
<div class="task-body">
|
||||
|
|
Loading…
Reference in a new issue