summaryrefslogtreecommitdiffstats
path: root/apps/comments/js
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-07-25 20:30:00 +0200
committerGitHub <noreply@github.com>2018-07-25 20:30:00 +0200
commit61397ee091287e983d0ff345b0e43fb4a3329f19 (patch)
tree2a04e9f5076d351dc7884c6ba946c80bf002d147 /apps/comments/js
parent8255faada4101b91b342bcf929d9a0e4c759cf34 (diff)
parent2dd55b0550c42355a6188554c3e217870ce37eb5 (diff)
downloadnextcloud-server-61397ee091287e983d0ff345b0e43fb4a3329f19.tar.gz
nextcloud-server-61397ee091287e983d0ff345b0e43fb4a3329f19.zip
Merge pull request #9222 from nextcloud/feature/noid/search-for-files-by-comments
Allow to search files by comments
Diffstat (limited to 'apps/comments/js')
-rw-r--r--apps/comments/js/merged.json1
-rw-r--r--apps/comments/js/search.js134
2 files changed, 135 insertions, 0 deletions
diff --git a/apps/comments/js/merged.json b/apps/comments/js/merged.json
index 6e77d9cf80a..d5b2b882334 100644
--- a/apps/comments/js/merged.json
+++ b/apps/comments/js/merged.json
@@ -7,6 +7,7 @@
"commentsmodifymenu.js",
"filesplugin.js",
"activitytabviewplugin.js",
+ "search.js",
"vendor/Caret.js/dist/jquery.caret.min.js",
"vendor/At.js/dist/js/jquery.atwho.min.js"
]
diff --git a/apps/comments/js/search.js b/apps/comments/js/search.js
new file mode 100644
index 00000000000..11a96594580
--- /dev/null
+++ b/apps/comments/js/search.js
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2014
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+(function(OC, OCA, $) {
+ "use strict";
+
+ /**
+ * Construct a new FileActions instance
+ * @constructs Files
+ */
+ var Comment = function() {
+ this.initialize();
+ };
+
+ Comment.prototype = {
+
+ fileList: null,
+
+ /**
+ * Initialize the file search
+ */
+ initialize: function() {
+
+ var self = this;
+
+ this.fileAppLoaded = function() {
+ return !!OCA.Files && !!OCA.Files.App;
+ };
+ function inFileList($row, result) {
+ return false;
+
+ if (! self.fileAppLoaded()) {
+ return false;
+ }
+ var dir = self.fileList.getCurrentDirectory().replace(/\/+$/,'');
+ var resultDir = OC.dirname(result.path);
+ return dir === resultDir && self.fileList.inList(result.name);
+ }
+ function hideNoFilterResults() {
+ var $nofilterresults = $('.nofilterresults');
+ if ( ! $nofilterresults.hasClass('hidden') ) {
+ $nofilterresults.addClass('hidden');
+ }
+ }
+
+ /**
+ *
+ * @param {jQuery} $row
+ * @param {Object} result
+ * @param {int} result.id
+ * @param {string} result.comment
+ * @param {string} result.authorId
+ * @param {string} result.authorName
+ * @param {string} result.link
+ * @param {string} result.fileName
+ * @param {string} result.path
+ * @returns {*}
+ */
+ this.renderCommentResult = function($row, result) {
+ if (inFileList($row, result)) {
+ return null;
+ }
+ hideNoFilterResults();
+ /*render preview icon, show path beneath filename,
+ show size and last modified date on the right */
+ this.updateLegacyMimetype(result);
+
+ var $pathDiv = $('<div>').addClass('path').text(result.path);
+
+ var $avatar = $('<div>');
+ $avatar.addClass('avatar')
+ .css('display', 'inline-block')
+ .css('vertical-align', 'middle')
+ .css('margin', '0 5px 2px 3px');
+
+ if (result.authorName) {
+ $avatar.avatar(result.authorId, 21, undefined, false, undefined, result.authorName);
+ } else {
+ $avatar.avatar(result.authorId, 21);
+ }
+
+ $row.find('td.info div.name').after($pathDiv).text(result.comment).prepend($('<span>').addClass('path').css('margin-right', '5px').text(result.authorName)).prepend($avatar);
+ $row.find('td.result a').attr('href', result.link);
+
+ $row.find('td.icon')
+ .css('background-image', 'url(' + OC.imagePath('core', 'actions/comment') + ')')
+ .css('opacity', '.4');
+ var dir = OC.dirname(result.path);
+ if (dir === '') {
+ dir = '/';
+ }
+ $row.find('td.info a').attr('href',
+ OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: dir, scrollto: result.fileName})
+ );
+
+ return $row;
+ };
+
+ this.handleCommentClick = function($row, result, event) {
+ if (self.fileAppLoaded() && self.fileList.id === 'files') {
+ self.fileList.changeDirectory(OC.dirname(result.path));
+ self.fileList.scrollTo(result.name);
+ return false;
+ } else {
+ return true;
+ }
+ };
+
+ this.updateLegacyMimetype = function (result) {
+ // backward compatibility:
+ if (!result.mime && result.mime_type) {
+ result.mime = result.mime_type;
+ }
+ };
+ this.setFileList = function (fileList) {
+ this.fileList = fileList;
+ };
+
+ OC.Plugins.register('OCA.Search.Core', this);
+ },
+ attach: function(search) {
+ search.setRenderer('comment', this.renderCommentResult.bind(this));
+ search.setHandler('comment', this.handleCommentClick.bind(this));
+ }
+ };
+
+ OCA.Search.comment = new Comment();
+})(OC, OCA, $);