зеркало из https://github.com/nextcloud/activity.git
Move the type icons of the files stuff to an extension
This commit is contained in:
Родитель
1a8d27d476
Коммит
082539b978
|
@ -36,6 +36,10 @@ $navigationEntry = array(
|
|||
);
|
||||
$c->getServer()->getNavigationManager()->add($navigationEntry);
|
||||
|
||||
$c->getServer()->getActivityManager()->registerExtension(function() use ($c) {
|
||||
return $c->query('FilesExtension');
|
||||
});
|
||||
|
||||
// register the hooks for filesystem operations. All other events from other apps has to be send via the public api
|
||||
\OCA\Activity\HooksStatic::register();
|
||||
\OCA\Activity\Consumer::register($c->getServer()->getActivityManager(), $c);
|
||||
|
|
|
@ -28,6 +28,7 @@ use OCA\Activity\Controller\Activities;
|
|||
use OCA\Activity\Controller\Settings;
|
||||
use OCA\Activity\Data;
|
||||
use OCA\Activity\DataHelper;
|
||||
use OCA\Activity\Extension\Files;
|
||||
use OCA\Activity\GroupHelper;
|
||||
use OCA\Activity\Hooks;
|
||||
use OCA\Activity\Navigation;
|
||||
|
@ -75,6 +76,10 @@ class Application extends App {
|
|||
);
|
||||
});
|
||||
|
||||
$container->registerService('FilesExtension', function(IContainer $c) {
|
||||
return new Files();
|
||||
});
|
||||
|
||||
$container->registerService('GroupHelper', function(IContainer $c) {
|
||||
return new GroupHelper(
|
||||
$c->query('ServerContainer')->getActivityManager(),
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - Activity App
|
||||
*
|
||||
* @author Joas Schilling
|
||||
* @copyright 2015 Joas Schilling nickvergessen@owncloud.com
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Activity\Extension;
|
||||
|
||||
use OCA\Activity\Data;
|
||||
use OCP\Activity\IExtension;
|
||||
|
||||
class Files implements IExtension{
|
||||
/**
|
||||
* The extension can return an array of additional notification types.
|
||||
* If no additional types are to be added false is to be returned
|
||||
*
|
||||
* @param string $languageCode
|
||||
* @return array|false
|
||||
*/
|
||||
public function getNotificationTypes($languageCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The extension can filter the types based on the filter if required.
|
||||
* In case no filter is to be applied false is to be returned unchanged.
|
||||
*
|
||||
* @param array $types
|
||||
* @param string $filter
|
||||
* @return array|false
|
||||
*/
|
||||
public function filterNotificationTypes($types, $filter) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given method additional types to be displayed in the settings can be returned.
|
||||
* In case no additional types are to be added false is to be returned.
|
||||
*
|
||||
* @param string $method
|
||||
* @return array|false
|
||||
*/
|
||||
public function getDefaultTypes($method) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The extension can translate a given message to the requested languages.
|
||||
* If no translation is available false is to be returned.
|
||||
*
|
||||
* @param string $app
|
||||
* @param string $text
|
||||
* @param array $params
|
||||
* @param boolean $stripPath
|
||||
* @param boolean $highlightParams
|
||||
* @param string $languageCode
|
||||
* @return string|false
|
||||
*/
|
||||
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The extension can define the type of parameters for translation
|
||||
*
|
||||
* Currently known types are:
|
||||
* * file => will strip away the path of the file and add a tooltip with it
|
||||
* * username => will add the avatar of the user
|
||||
*
|
||||
* @param string $app
|
||||
* @param string $text
|
||||
* @return array|false
|
||||
*/
|
||||
function getSpecialParameterList($app, $text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A string naming the css class for the icon to be used can be returned.
|
||||
* If no icon is known for the given type false is to be returned.
|
||||
*
|
||||
* @param string $type
|
||||
* @return string|false
|
||||
*/
|
||||
public function getTypeIcon($type) {
|
||||
switch ($type)
|
||||
{
|
||||
case Data::TYPE_SHARE_CHANGED:
|
||||
return 'icon-change';
|
||||
case Data::TYPE_SHARE_CREATED:
|
||||
return 'icon-add-color';
|
||||
case Data::TYPE_SHARE_DELETED:
|
||||
return 'icon-delete-color';
|
||||
case Data::TYPE_SHARED:
|
||||
return 'icon-share';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The extension can define the parameter grouping by returning the index as integer.
|
||||
* In case no grouping is required false is to be returned.
|
||||
*
|
||||
* @param array $activity
|
||||
* @return integer|false
|
||||
*/
|
||||
public function getGroupParameter($activity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The extension can define additional navigation entries. The array returned has to contain two keys 'top'
|
||||
* and 'apps' which hold arrays with the relevant entries.
|
||||
* If no further entries are to be added false is no be returned.
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
public function getNavigation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The extension can check if a customer filter (given by a query string like filter=abc) is valid or not.
|
||||
*
|
||||
* @param string $filterValue
|
||||
* @return boolean
|
||||
*/
|
||||
public function isFilterValid($filterValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given filter the extension can specify the sql query conditions including parameters for that query.
|
||||
* In case the extension does not know the filter false is to be returned.
|
||||
* The query condition and the parameters are to be returned as array with two elements.
|
||||
* E.g. return array('`app` = ? and `message` like ?', array('mail', 'ownCloud%'));
|
||||
*
|
||||
* @param string $filter
|
||||
* @return array|false
|
||||
*/
|
||||
public function getQueryForFilter($filter) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -128,28 +128,4 @@ class DataHelper {
|
|||
|
||||
return $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon for a given activity type
|
||||
*
|
||||
* @param string $type
|
||||
* @return string CSS class which adds the icon
|
||||
*/
|
||||
public function getTypeIcon($type)
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case Data::TYPE_SHARE_CHANGED:
|
||||
return 'icon-change';
|
||||
case Data::TYPE_SHARE_CREATED:
|
||||
return 'icon-add-color';
|
||||
case Data::TYPE_SHARE_DELETED:
|
||||
return 'icon-delete-color';
|
||||
case Data::TYPE_SHARED:
|
||||
return 'icon-share';
|
||||
}
|
||||
|
||||
// Allow other apps to add a icon for their notifications
|
||||
return $this->activityManager->getTypeIcon($type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ class GroupHelper
|
|||
$activity = $this->dataHelper->formatStrings($activity, 'subject');
|
||||
$activity = $this->dataHelper->formatStrings($activity, 'message');
|
||||
|
||||
$activity['typeicon'] = $this->dataHelper->getTypeIcon($activity['type']);
|
||||
$activity['typeicon'] = $this->activityManager->getTypeIcon($activity['type']);
|
||||
$return[] = $activity;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,8 @@ class ApplicationTest extends TestCase {
|
|||
array('URLGenerator', 'OCP\IURLGenerator'),
|
||||
array('SettingsController', 'OCP\AppFramework\Controller'),
|
||||
array('ActivitiesController', 'OCP\AppFramework\Controller'),
|
||||
array('FilesExtension', 'OCP\Activity\IExtension'),
|
||||
array('FilesExtension', 'OCA\Activity\Extension\Files'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -203,33 +203,4 @@ class DataHelperTest extends TestCase {
|
|||
(string) $dataHelper->translation('activity', $text, $params, $stripPath, $highlightParams)
|
||||
);
|
||||
}
|
||||
|
||||
public function getTypeIconData() {
|
||||
return [
|
||||
['file_changed', 'icon-change'],
|
||||
['otherApp', ''],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider getTypeIconData
|
||||
*/
|
||||
public function testGetTypeIcon($type, $expected) {
|
||||
$manager = $this->getMock('\OCP\Activity\IManager');
|
||||
$manager->expects($this->any())
|
||||
->method('getTypeIcon')
|
||||
->willReturn('');
|
||||
$dataHelper = new DataHelper(
|
||||
$manager,
|
||||
new ParameterHelper(
|
||||
$manager,
|
||||
new View(''),
|
||||
Util::getL10N('activity')
|
||||
),
|
||||
Util::getL10N('activity')
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, $dataHelper->getTypeIcon($type));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud
|
||||
*
|
||||
* @author Joas Schilling
|
||||
* @copyright 2015 Joas Schilling nickvergessen@owncloud.com
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Activity\Tests;
|
||||
|
||||
use OCA\Activity\Data;
|
||||
use OCA\Activity\Extension\Files;
|
||||
|
||||
class ExtensionFilesTest extends TestCase {
|
||||
/** @var \OCA\Activity\Extension\Files */
|
||||
protected $filesExtension;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->filesExtension = new Files();
|
||||
}
|
||||
|
||||
public function testGetNotificationTypes() {
|
||||
$this->assertFalse($this->filesExtension->getNotificationTypes('en'));
|
||||
}
|
||||
|
||||
public function testFilterNotificationTypes() {
|
||||
$this->assertFalse($this->filesExtension->filterNotificationTypes('', ''));
|
||||
}
|
||||
|
||||
public function testGetDefaultTypes() {
|
||||
$this->assertFalse($this->filesExtension->getDefaultTypes(''));
|
||||
}
|
||||
|
||||
public function testTranslate() {
|
||||
$this->assertFalse($this->filesExtension->translate('', '', [], false, false, 'en'));
|
||||
}
|
||||
|
||||
public function testGetSpecialParameterList() {
|
||||
$this->assertFalse($this->filesExtension->getSpecialParameterList('', ''));
|
||||
}
|
||||
|
||||
public function dataGetTypeIcon() {
|
||||
return [
|
||||
[Data::TYPE_SHARED, true],
|
||||
[Data::TYPE_SHARE_CREATED, true],
|
||||
[Data::TYPE_SHARE_CHANGED, true],
|
||||
[Data::TYPE_SHARE_DELETED, true],
|
||||
[Data::TYPE_SHARE_RESTORED, false],
|
||||
['AnotherApp', false],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGetTypeIcon
|
||||
*
|
||||
* @param string $type
|
||||
* @param bool $expected
|
||||
*/
|
||||
public function testGetTypeIcon($type, $expected) {
|
||||
if ($expected) {
|
||||
$this->assertNotFalse($this->filesExtension->getTypeIcon($type));
|
||||
} else {
|
||||
$this->assertFalse($this->filesExtension->getTypeIcon($type));
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetGroupParameter() {
|
||||
$this->assertFalse($this->filesExtension->getGroupParameter(''));
|
||||
}
|
||||
|
||||
public function testGetNavigation() {
|
||||
$this->assertFalse($this->filesExtension->getNavigation(''));
|
||||
}
|
||||
|
||||
public function testIsFilterValid() {
|
||||
$this->assertFalse($this->filesExtension->isFilterValid(''));
|
||||
}
|
||||
|
||||
public function testGetQueryForFilter() {
|
||||
$this->assertFalse($this->filesExtension->getQueryForFilter(''));
|
||||
}
|
||||
}
|
|
@ -22,7 +22,9 @@
|
|||
|
||||
namespace OCA\Activity\Tests;
|
||||
|
||||
use OC\ActivityManager;
|
||||
use OCA\Activity\DataHelper;
|
||||
use OCA\Activity\Extension\Files;
|
||||
use OCA\Activity\GroupHelper;
|
||||
use OCA\Activity\ParameterHelper;
|
||||
|
||||
|
@ -474,11 +476,10 @@ class GroupHelperTest extends TestCase {
|
|||
* @dataProvider groupHelperData
|
||||
*/
|
||||
public function testGroupHelper($allowGrouping, $activities, $expected) {
|
||||
$activityManager = $this->getMock('\OCP\Activity\IManager');
|
||||
$activityManager->expects($this->any())
|
||||
->method('getGroupParameter')
|
||||
->with($this->anything())
|
||||
->will($this->returnValue(false));
|
||||
$activityManager = new ActivityManager();
|
||||
$activityManager->registerExtension(function() {
|
||||
return new Files();
|
||||
});
|
||||
$activityLanguage = \OCP\Util::getL10N('activity');
|
||||
|
||||
$helper = new GroupHelper(
|
||||
|
|
Загрузка…
Ссылка в новой задаче