-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9222 from nextcloud/feature/noid/search-for-files…
…-by-comments Allow to search files by comments
- Loading branch information
Showing
15 changed files
with
854 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,25 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) 2016, ownCloud, Inc. | ||
* @copyright Copyright (c) 2018, Joas Schilling <coding@schilljs.com> | ||
* | ||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de> | ||
* @author Joas Schilling <coding@schilljs.com> | ||
* @author Lukas Reschke <lukas@statuscode.ch> | ||
* @author Vincent Petry <pvince81@owncloud.com> | ||
* | ||
* @license AGPL-3.0 | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program 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 | ||
* 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, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
$eventDispatcher = \OC::$server->getEventDispatcher(); | ||
$eventDispatcher->addListener( | ||
'OCA\Files::loadAdditionalScripts', | ||
function() { | ||
\OCP\Util::addScript('oc-backbone-webdav'); | ||
\OCP\Util::addScript('comments', 'merged'); | ||
\OCP\Util::addStyle('comments', 'autocomplete'); | ||
\OCP\Util::addStyle('comments', 'comments'); | ||
} | ||
); | ||
|
||
$eventDispatcher->addListener(\OCP\Comments\CommentsEntityEvent::EVENT_ENTITY, function(\OCP\Comments\CommentsEntityEvent $event) { | ||
$event->addEntityCollection('files', function($name) { | ||
$nodes = \OC::$server->getUserFolder()->getById((int)$name); | ||
return !empty($nodes); | ||
}); | ||
}); | ||
|
||
$notificationManager = \OC::$server->getNotificationManager(); | ||
$notificationManager->registerNotifier( | ||
function() { | ||
$application = new \OCP\AppFramework\App('comments'); | ||
return $application->getContainer()->query(\OCA\Comments\Notification\Notifier::class); | ||
}, | ||
function () { | ||
$l = \OC::$server->getL10N('comments'); | ||
return ['id' => 'comments', 'name' => $l->t('Comments')]; | ||
} | ||
); | ||
|
||
$commentsManager = \OC::$server->getCommentsManager(); | ||
$commentsManager->registerEventHandler(function () { | ||
$application = new \OCP\AppFramework\App('comments'); | ||
/** @var \OCA\Comments\EventHandler $handler */ | ||
$handler = $application->getContainer()->query(\OCA\Comments\EventHandler::class); | ||
return $handler; | ||
}); | ||
$application = new \OCA\Comments\AppInfo\Application(); | ||
$application->register(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, $); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.