Merge pull request #45 from owncloud/issue/13

Issue/13 display avatar next to user names
This commit is contained in:
Joas Schilling 2014-06-02 17:51:02 +02:00
Родитель 03868adec4 eb282e9a33
Коммит 2b2a127e22
5 изменённых файлов: 86 добавлений и 42 удалений

Просмотреть файл

@ -81,11 +81,6 @@
opacity: 0;
}
.box .avatar{
float: left;
margin-right: 20px;
}
.box .header{
height: 32px;
margin-bottom: 10px;
@ -159,6 +154,12 @@
font-weight: bold;
}
.activity-section .avatar {
vertical-align: middle;
display: inline-block;
margin-right: 5px;
}
/* colored icons, in addition to core ones */
.activity-icon {
min-width: 16px;
@ -177,7 +178,7 @@
}
/* grey the changed and shared icons so they are less intense */
.icon-change,
.icon-shared,
.icon-share,
.icon-public {
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=50);

Просмотреть файл

@ -3,7 +3,7 @@ $(function(){
function processElements($elem){
$elem.find('.avatar').each(function(){
var $this = $(this);
$this.avatar($this.data('user'), 32);
$this.avatar($this.data('user'), 28);
});
$elem.find('.tooltip').tipsy({gravity:'s', fade:true});
}

Просмотреть файл

@ -335,7 +335,7 @@ class Data
case self::TYPE_SHARE_DELETED:
return 'icon-delete-color';
case self::TYPE_SHARED:
return 'icon-shared';
return 'icon-share';
}
return '';
}

Просмотреть файл

@ -31,19 +31,19 @@ class DataHelper
* @param string $app
* @param string $text
* @param array $params
* @param mixed $filePosition Position of a file in $params
* @param array $paramTypes Type of parameters, if they need special handling
* @param bool $stripPath Shall we remove the path from the filename
* @param bool $highlightParams
* @return array
*/
public static function prepareParameters(\OC_L10N $l, $app, $text, $params, $filePosition = false, $stripPath = false, $highlightParams = false) {
public static function prepareParameters(\OC_L10N $l, $app, $text, $params, $paramTypes = array(), $stripPath = false, $highlightParams = false) {
if ($app === 'files' && $text) {
$preparedParams = array();
foreach ($params as $i => $param) {
if (is_array($param)) {
$parameterList = $plainParameterList = array();
foreach ($param as $parameter) {
if ($filePosition === $i) {
if (isset($paramTypes[$i]) && $paramTypes[$i] === 'file') {
$parameterList[] = self::prepareFileParam($parameter, $stripPath, $highlightParams);
$plainParameterList[] = self::prepareFileParam($parameter, false, false);
} else {
@ -53,8 +53,10 @@ class DataHelper
}
$preparedParams[] = self::joinParameterList($l, $parameterList, $plainParameterList, $highlightParams);
} else {
if ($filePosition === $i) {
if (isset($paramTypes[$i]) && $paramTypes[$i] === 'file') {
$preparedParams[] = self::prepareFileParam($param, $stripPath, $highlightParams);
} else if (isset($paramTypes[$i]) && $paramTypes[$i] === 'username') {
$preparedParams[] = self::prepareUserParam($param, $highlightParams);
} else {
$preparedParams[] = self::prepareParam($param, $highlightParams);
}
@ -80,6 +82,25 @@ class DataHelper
}
}
/**
* Prepares a user name parameter for usage
*
* Add an avatar to usernames
*
* @param string $param
* @param bool $highlightParams
* @return string
*/
protected static function prepareUserParam($param, $highlightParams) {
if ($highlightParams) {
$param = \OC_Util::sanitizeHTML($param);
return '<div class="avatar" data-user="' . $param . '"></div>'
. '<strong>' . $param . '</strong>';
} else {
return $param;
}
}
/**
* Prepares a file parameter for usage
*
@ -190,39 +211,49 @@ class DataHelper
}
if ($app === 'files') {
$params = self::prepareParameters($l, $app, $text, $params, 0, $stripPath, $highlightParams);
$preparedParams = self::prepareParameters(
$l, $app, $text,
$params, array(0 => 'file', 1 => 'username'),
$stripPath, $highlightParams
);
if ($text === 'created_self') {
return $l->t('You created %1$s', $params);
return $l->t('You created %1$s', $preparedParams);
}
else if ($text === 'created_by') {
return $l->t('%2$s created %1$s', $params);
return $l->t('%2$s created %1$s', $preparedParams);
}
else if ($text === 'changed_self') {
return $l->t('You changed %1$s', $params);
return $l->t('You changed %1$s', $preparedParams);
}
else if ($text === 'changed_by') {
return $l->t('%2$s changed %1$s', $params);
return $l->t('%2$s changed %1$s', $preparedParams);
}
else if ($text === 'deleted_self') {
return $l->t('You deleted %1$s', $params);
return $l->t('You deleted %1$s', $preparedParams);
}
else if ($text === 'deleted_by') {
return $l->t('%2$s deleted %1$s', $params);
return $l->t('%2$s deleted %1$s', $preparedParams);
}
else if ($text === 'shared_user_self') {
return $l->t('You shared %1$s with %2$s', $params);
return $l->t('You shared %1$s with %2$s', $preparedParams);
}
else if ($text === 'shared_group_self') {
return $l->t('You shared %1$s with group %2$s', $params);
// Second parameter is not a username here
$preparedParams = self::prepareParameters(
$l, $app, $text,
$params, array(0 => 'file'),
$stripPath, $highlightParams
);
return $l->t('You shared %1$s with group %2$s', $preparedParams);
}
else if ($text === 'shared_with_by') {
return $l->t('%2$s shared %1$s with you', $params);
return $l->t('%2$s shared %1$s with you', $preparedParams);
}
else if ($text === 'shared_link_self') {
return $l->t('You shared %1$s', $params);
return $l->t('You shared %1$s', $preparedParams);
}
return $l->t($text, $params);
return $l->t($text, $preparedParams);
} else {
$l = \OCP\Util::getL10N($app);
return $l->t($text, $params);

Просмотреть файл

@ -36,42 +36,51 @@ class DataHelper extends \PHPUnit_Framework_TestCase {
parent::tearDown();
}
public function prepareFilesParamsData() {
public function prepareParametersData() {
return array(
array(array(), false, false, false, array()),
// No file position: no path strip
array(array('/foo/bar.file'), false, false, false, array('/foo/bar.file')),
array(array('/foo/bar.file'), false, true, false, array('/foo/bar.file')),
array(array('/foo/bar.file'), false, false, true, array('<strong>/foo/bar.file</strong>')),
array(array('/foo/bar.file'), false, true, true, array('<strong>/foo/bar.file</strong>')),
array(array('/foo/bar.file'), array(), false, false, array('/foo/bar.file')),
array(array('/foo/bar.file'), array(), true, false, array('/foo/bar.file')),
array(array('/foo/bar.file'), array(), false, true, array('<strong>/foo/bar.file</strong>')),
array(array('/foo/bar.file'), array(), true, true, array('<strong>/foo/bar.file</strong>')),
// Valid file position
array(array('/foo/bar.file'), 0, true, false, array('bar.file')),
array(array('/foo/bar.file'), 0, true, true, array(
array(array('/foo/bar.file'), array(0 => 'file'), true, false, array('bar.file')),
array(array('/foo/bar.file'), array(0 => 'file'), true, true, array(
'<a class="filename tooltip" href="/index.php/apps/files?dir=%2Ffoo" title="foo/bar.file">bar.file</a>',
)),
array(array('/foo/bar.file'), 1, true, false, array('/foo/bar.file')),
array(array('/foo/bar.file'), 1, true, true, array('<strong>/foo/bar.file</strong>')),
array(array('/foo/bar.file'), array(1 => 'file'), true, false, array('/foo/bar.file')),
array(array('/foo/bar.file'), array(1 => 'file'), true, true, array('<strong>/foo/bar.file</strong>')),
// Valid file position
array(array('UserA', '/foo/bar.file'), 1, true, false, array('UserA', 'bar.file')),
array(array('UserA', '/foo/bar.file'), 1, true, true, array(
array(array('UserA', '/foo/bar.file'), array(1 => 'file'), true, false, array('UserA', 'bar.file')),
array(array('UserA', '/foo/bar.file'), array(1 => 'file'), true, true, array(
'<strong>UserA</strong>',
'<a class="filename tooltip" href="/index.php/apps/files?dir=%2Ffoo" title="foo/bar.file">bar.file</a>',
)),
array(array('UserA', '/foo/bar.file'), 2, true, false, array('UserA', '/foo/bar.file')),
array(array('UserA', '/foo/bar.file'), 2, true, true, array(
array(array('UserA', '/foo/bar.file'), array(2 => 'file'), true, false, array('UserA', '/foo/bar.file')),
array(array('UserA', '/foo/bar.file'), array(2 => 'file'), true, true, array(
'<strong>UserA</strong>',
'<strong>/foo/bar.file</strong>',
)),
array(array('UserA', '/foo/bar.file'), array(0 => 'username'), true, true, array(
'<div class="avatar" data-user="UserA"></div><strong>UserA</strong>',
'<strong>/foo/bar.file</strong>',
)),
array(array('UserA', '/foo/bar.file'), array(0 => 'username', 1 => 'file'), true, true, array(
'<div class="avatar" data-user="UserA"></div><strong>UserA</strong>',
'<a class="filename tooltip" href="/index.php/apps/files?dir=%2Ffoo" title="foo/bar.file">bar.file</a>',
)),
);
}
/**
* @dataProvider prepareFilesParamsData
* @dataProvider prepareParametersData
*/
public function testPrepareFilesParams($params, $filePosition, $stripPath, $highlightParams, $expected) {
public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected) {
$l = \OC_L10N::get('activity');
$this->assertEquals(
$expected,
@ -102,15 +111,18 @@ class DataHelper extends \PHPUnit_Framework_TestCase {
array('created_by', array('/SubFolder/A.txt', 'UserB'), true, false, 'UserB created A.txt'),
array(
'created_by', array('/SubFolder/A.txt', 'UserB'), false, true,
'<strong>UserB</strong> created <a class="filename" href="/index.php/apps/files?dir=%2FSubFolder">SubFolder/A.txt</a>',
'<div class="avatar" data-user="UserB"></div><strong>UserB</strong> created '
. '<a class="filename" href="/index.php/apps/files?dir=%2FSubFolder">SubFolder/A.txt</a>',
),
array(
'created_by', array('/SubFolder/A.txt', 'UserB'), true, true,
'<strong>UserB</strong> created <a class="filename tooltip" href="/index.php/apps/files?dir=%2FSubFolder" title="SubFolder/A.txt">A.txt</a>',
'<div class="avatar" data-user="UserB"></div><strong>UserB</strong> created '
. '<a class="filename tooltip" href="/index.php/apps/files?dir=%2FSubFolder" title="SubFolder/A.txt">A.txt</a>',
),
array(
'created_by', array('/A.txt', 'UserB'), true, true,
'<strong>UserB</strong> created <a class="filename tooltip" href="/index.php/apps/files?dir=%2F" title="A.txt">A.txt</a>',
'<div class="avatar" data-user="UserB"></div><strong>UserB</strong> created '
. '<a class="filename tooltip" href="/index.php/apps/files?dir=%2F" title="A.txt">A.txt</a>',
),
array(