Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to search files by comments #9222

Merged
merged 5 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,15 @@ pipeline:
when:
matrix:
TESTS: integration-comments
integration-comments-search:
image: nextcloudci/integration-php7.0:integration-php7.0-8
commands:
- ./occ maintenance:install --admin-pass=admin --data-dir=/dev/shm/nc_int
- cd build/integration
- ./run.sh features/comments-search.feature
when:
matrix:
TESTS: integration-comments-search
integration-favorites:
image: nextcloudci/integration-php7.0:integration-php7.0-8
commands:
Expand Down Expand Up @@ -783,6 +792,7 @@ matrix:
- TESTS: integration-tags
- TESTS: integration-caldav
- TESTS: integration-comments
- TESTS: integration-comments-search
- TESTS: integration-favorites
- TESTS: integration-provisioning-v2
- TESTS: integration-webdav-related
Expand Down
59 changes: 11 additions & 48 deletions apps/comments/appinfo/app.php
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();
2 changes: 2 additions & 0 deletions apps/comments/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
'OCA\\Comments\\JSSettingsHelper' => $baseDir . '/../lib/JSSettingsHelper.php',
'OCA\\Comments\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php',
'OCA\\Comments\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
'OCA\\Comments\\Search\\Provider' => $baseDir . '/../lib/Search/Provider.php',
'OCA\\Comments\\Search\\Result' => $baseDir . '/../lib/Search/Result.php',
);
2 changes: 2 additions & 0 deletions apps/comments/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class ComposerStaticInitComments
'OCA\\Comments\\JSSettingsHelper' => __DIR__ . '/..' . '/../lib/JSSettingsHelper.php',
'OCA\\Comments\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php',
'OCA\\Comments\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
'OCA\\Comments\\Search\\Provider' => __DIR__ . '/..' . '/../lib/Search/Provider.php',
'OCA\\Comments\\Search\\Result' => __DIR__ . '/..' . '/../lib/Search/Result.php',
);

public static function getInitializer(ClassLoader $loader)
Expand Down
1 change: 1 addition & 0 deletions apps/comments/js/merged.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
132 changes: 132 additions & 0 deletions apps/comments/js/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* 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') + ')');
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, $);
56 changes: 56 additions & 0 deletions apps/comments/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
namespace OCA\Comments\AppInfo;

use OCA\Comments\Controller\Notifications;
use OCA\Comments\EventHandler;
use OCA\Comments\JSSettingsHelper;
use OCA\Comments\Notification\Notifier;
use OCA\Comments\Search\Provider;
use OCP\AppFramework\App;
use OCP\Comments\CommentsEntityEvent;
use OCP\Util;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class Application extends App {

Expand All @@ -39,4 +44,55 @@ public function __construct (array $urlParams = array()) {
$jsSettingsHelper = new JSSettingsHelper($container->getServer());
Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend');
}

public function register() {
$server = $this->getContainer()->getServer();

$dispatcher = $server->getEventDispatcher();
$this->registerSidebarScripts($dispatcher);
$this->registerDavEntity($dispatcher);
$this->registerNotifier();
$this->registerCommentsEventHandler();

$server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]);
}

protected function registerSidebarScripts(EventDispatcherInterface $dispatcher) {
$dispatcher->addListener(
'OCA\Files::loadAdditionalScripts',
function() {
Util::addScript('oc-backbone-webdav');
Util::addScript('comments', 'merged');
Util::addStyle('comments', 'autocomplete');
Util::addStyle('comments', 'comments');
}
);
}

protected function registerDavEntity(EventDispatcherInterface $dispatcher) {
$dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) {
$event->addEntityCollection('files', function($name) {
$nodes = \OC::$server->getUserFolder()->getById((int)$name);
return !empty($nodes);
});
});
}

protected function registerNotifier() {
$this->getContainer()->getServer()->getNotificationManager()->registerNotifier(
function() {
return $this->getContainer()->query(Notifier::class);
},
function () {
$l = $this->getContainer()->getServer()->getL10NFactory()->get('comments');
return ['id' => 'comments', 'name' => $l->t('Comments')];
}
);
}

protected function registerCommentsEventHandler() {
$this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () {
return $this->getContainer()->query(EventHandler::class);
});
}
}
Loading