From 647fc23595acb1e27bf2814b465016c1ebd256c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimund=20Schl=C3=BC=C3=9Fler?= Date: Tue, 20 Nov 2018 12:39:51 +0100 Subject: [PATCH 1/2] Remove server-side search --- css/src/style.scss | 15 -------- .../businesslayer/searchbusinesslayer.js | 35 ------------------- templates/main.php | 18 ---------- 3 files changed, 68 deletions(-) diff --git a/css/src/style.scss b/css/src/style.scss index c662664f..2ec4c6d1 100644 --- a/css/src/style.scss +++ b/css/src/style.scss @@ -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; diff --git a/js/app/services/businesslayer/searchbusinesslayer.js b/js/app/services/businesslayer/searchbusinesslayer.js index ce9f6603..3592c4d8 100644 --- a/js/app/services/businesslayer/searchbusinesslayer.js +++ b/js/app/services/businesslayer/searchbusinesslayer.js @@ -52,8 +52,6 @@ return _this.setFilter(query); }); }); - search.setRenderer('task', this.renderTaskResult.bind(this)); - return search.setHandler('task', this.handleTaskClick.bind(this)); }; SearchBusinessLayer.prototype.setFilter = function(query) { @@ -65,39 +63,6 @@ }; 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 = $('').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); }; diff --git a/templates/main.php b/templates/main.php index c1d0a257..66a0ebce 100644 --- a/templates/main.php +++ b/templates/main.php @@ -245,24 +245,6 @@ inc('part.tasklist')); ?> inc('part.collectionall')); ?> inc('part.collectionweek')); ?> -
-
- -
From aee56dcf604d00a3d4ce13471a9d00dd0b17cfe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimund=20Schl=C3=BC=C3=9Fler?= Date: Wed, 21 Nov 2018 15:41:47 +0100 Subject: [PATCH 2/2] Fix client-side search --- .../businesslayer/searchbusinesslayer.js | 26 ++++-- js/app/services/models/tasksmodel.js | 87 ++++++------------- 2 files changed, 46 insertions(+), 67 deletions(-) diff --git a/js/app/services/businesslayer/searchbusinesslayer.js b/js/app/services/businesslayer/searchbusinesslayer.js index 3592c4d8..cd01f2cd 100644 --- a/js/app/services/businesslayer/searchbusinesslayer.js +++ b/js/app/services/businesslayer/searchbusinesslayer.js @@ -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,14 +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); }); }; 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() { @@ -63,7 +72,14 @@ }; SearchBusinessLayer.prototype.initialize = function() { - 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; diff --git a/js/app/services/models/tasksmodel.js b/js/app/services/models/tasksmodel.js index 0bc53b8a..3896f25b 100644 --- a/js/app/services/models/tasksmodel.js +++ b/js/app/services/models/tasksmodel.js @@ -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);