Merge pull request #216 from nextcloud/search

Fix the client-side search, closes #22
This commit is contained in:
Raimund Schlüßler 2018-11-21 16:21:44 +01:00 committed by GitHub
commit 6ae1de6e96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 135 deletions

View file

@ -1226,21 +1226,6 @@ ol[dnd-list] {
}
}
/**
* rules for searchresults
*/
#searchresults {
padding-top: 0 !important;
margin-top: 20px !important;
background-color: transparent !important;
min-height: 150px;
span.icon.task-checkbox {
opacity: .6;
}
}
#status {
padding: 10px 0 18px !important;
height: 22px !important;

View file

@ -40,6 +40,7 @@
this._$location = _$location;
this.getFilter = __bind(this.getFilter, this);
this.setFilter = __bind(this.setFilter, this);
this.cleanSearch = __bind(this.cleanSearch, this);
this.attach = __bind(this.attach, this);
this.initialize();
this._$searchString = '';
@ -48,16 +49,22 @@
SearchBusinessLayer.prototype.attach = function(search) {
var _this = this;
search.setFilter('tasks', function(query) {
return _this._$rootScope.$apply(function() {
return _this.setFilter(query);
});
return _this.setFilter(query);
});
search.setRenderer('task', this.renderTaskResult.bind(this));
return search.setHandler('task', this.handleTaskClick.bind(this));
};
SearchBusinessLayer.prototype.setFilter = function(query) {
this._$searchString = query;
var _this = this;
return _this._$rootScope.$apply(function() {
_this._$searchString = query;
});
};
SearchBusinessLayer.prototype.cleanSearch = function() {
var _this = this;
return _this._$rootScope.$apply(function() {
_this._$searchString = '';
});
};
SearchBusinessLayer.prototype.getFilter = function() {
@ -65,40 +72,14 @@
};
SearchBusinessLayer.prototype.initialize = function() {
var _this = this;
this.handleTaskClick = function($row, result, event) {
return _this._$location.path('/lists/' + result.calendarid + '/tasks/' + result.id);
};
this.renderTaskResult = function($row, result) {
var $template;
if (!_this._$tasksmodel.filterTasks(result, _this._$routeparams.listID) || !_this._$tasksmodel.isLoaded(result)) {
$template = $('div.task-item.template');
$template = $template.clone();
$row = $('<tr class="result"></tr>').append($template.removeClass('template'));
$row.data('result', result);
$row.find('span.title').text(result.name);
if (result.starred) {
$row.find('span.task-star').addClass('task-starred');
}
if (result.completed) {
$row.find('div.task-item').addClass('done');
$row.find('span.task-checkbox').addClass('svg-checkmark');
}
if (result.complete) {
$row.find('div.percentdone').css({
'width': result.complete + '%',
'background-color': '' + _this._$listsmodel.getColor(result.calendarid)
});
}
if (result.note) {
$row.find('div.title-wrapper').addClass('attachment');
}
return $row;
} else {
return null;
}
};
return OC.Plugins.register('OCA.Search', this);
var version = OC.config.version.split('.');
if (version[0] >= 14) {
OC.Search = new OCA.Search(this.setFilter, this.cleanSearch);
} else {
OC.Plugins.register('OCA.Search', this);
}
};
return SearchBusinessLayer;

View file

@ -126,7 +126,7 @@
for (var _i = 0, _len = tasks.length; _i < _len; _i++) {
task = tasks[_i];
if (task.calendarid === listID) {
taskIDs.push(task.id);
taskIDs.push(task.uid);
}
}
_results = [];
@ -172,7 +172,7 @@
};
TasksModel.prototype.isLoaded = function(task) {
if (this.getById(task.id)) {
if (this.getByUid(task.uid)) {
return true;
} else {
return false;
@ -216,12 +216,12 @@
}
};
TasksModel.prototype.getIdByUid = function(uid) {
TasksModel.prototype.getUriByUid = function(uid) {
var tasks = this.getAll();
for (var _i = 0, _len = tasks.length; _i < _len; _i++) {
var task = tasks[_i];
if (task.uid === uid) {
return task.id;
return task.uri;
}
}
return false;
@ -296,7 +296,7 @@
continue;
}
ret.push(task);
parentID = this.getIdByUid(task.related);
parentID = this.getUriByUid(task.related);
ancestors = this.getAncestor(parentID, ret);
if (ancestors) {
ret = ret.concat(ancestors);
@ -310,7 +310,7 @@
TasksModel.prototype.objectExists = function(task, ret) {
for (var _i = 0, _len = ret.length; _i < _len; _i++) {
var re = ret[_i];
if (re.id === task.id) {
if (re.uid === task.uid) {
return true;
}
}
@ -319,16 +319,12 @@
TasksModel.prototype.filterTasksByString = function(task, filter) {
var key, keys, value;
keys = ['name', 'note', 'location', 'categories', 'comments'];
keys = ['summary', 'note', 'location', 'categories'];
filter = filter.toLowerCase();
for (key in task) {
value = task[key];
if (__indexOf.call(keys, key) >= 0) {
if (key === 'comments') {
if (this.searchComments(task.comments, filter)) {
return true;
}
} else if (key === 'categories') {
if (key === 'categories') {
if (this.searchCategories(task.categories, filter)) {
return true;
}
@ -340,14 +336,25 @@
return false;
};
TasksModel.prototype.searchComments = function(comments, filter) {
for (var _i = 0, _len = comments.length; _i < _len; _i++) {
var comment = comments[_i];
if (comment.comment.toLowerCase().indexOf(filter) !== -1) {
return true;
TasksModel.prototype.getAncestor = function(taskUri, ret) {
var ancestors, parentUri, task, tasks;
tasks = [];
task = this.getByUri(taskUri);
if (task) {
if (this.objectExists(task, ret)) {
return tasks;
}
tasks.push(task);
if (this.hasNoParent(task)) {
return tasks;
}
parentUri = this.getUriByUid(task.related);
ancestors = this.getAncestor(parentUri, ret);
if (ancestors) {
tasks = tasks.concat(ancestors);
}
}
return false;
return tasks;
};
TasksModel.prototype.searchCategories = function(categories, filter) {
@ -387,50 +394,6 @@
return !moment(start, "YYYYMMDDTHHmmss").isValid() || moment(start, "YYYYMMDDTHHmmss").diff(moment(), 'days', true) < 0 || moment(due, "YYYYMMDDTHHmmss").diff(moment(), 'days', true) < 0;
};
TasksModel.prototype.addComment = function(comment) {
var task;
task = this.getById(comment.taskID);
if (task.comments) {
task.comments.push(comment);
} else {
task.comments = [comment];
}
};
TasksModel.prototype.updateComment = function(comment) {
var com, i, task, _i, _len, _ref, _results;
task = this.getById(comment.taskID);
i = 0;
_ref = task.comments;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
com = _ref[_i];
if (com.tmpID === comment.tmpID) {
task.comments[i] = comment;
break;
}
_results.push(i++);
}
return _results;
};
TasksModel.prototype.deleteComment = function(taskID, commentID) {
var comment, i, task, _i, _len, _ref, _results;
task = this.getById(taskID);
i = 0;
_ref = task.comments;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
comment = _ref[_i];
if (comment.id === commentID) {
task.comments.splice(i, 1);
break;
}
_results.push(i++);
}
return _results;
};
return TasksModel;
})(_Model);

View file

@ -245,24 +245,6 @@
<?php print_unescaped($this->inc('part.tasklist')); ?>
<?php print_unescaped($this->inc('part.collectionall')); ?>
<?php print_unescaped($this->inc('part.collectionweek')); ?>
<div id="searchresults"></div>
<div class="task-item template">
<div class="task-body">
<div class="percentdone"></div>
<a class="task-checkbox" name="toggleCompleted" ng-click="toggleCompleted()">
<span class="icon task-checkbox"></span>
</a>
<a class="icon task-separator"></a>
<a class="task-star" ng-click="toggleStarred(task.id)">
<span class="icon task-star faded"></span>
</a>
<a class="duedate" ng-class="{overdue: TasksModel.overdue(task.due)}">{{ task.due | dateTaskList }}</a>
<div class="title-wrapper">
<span class="title"></span>
<span class="icon task-attachment"></span>
</div>
</div>
</div>
</div>
</div>
</div>