Similar events are now aggregated/group into a box

Events that have the same user, app and event type are now grouped together
in a single box.
This commit is contained in:
Vincent Petry 2013-10-04 16:57:45 +02:00
Родитель 107fe51154
Коммит 6df2881bc4
3 изменённых файлов: 111 добавлений и 16 удалений

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

@ -129,6 +129,22 @@
font-size: 0.8em;
}
.box .appname {
float: right;
color: #333;
font-size: 0.8em;
}
.box .grouped{
list-style: none;
}
.box .grouped .more{
cursor: default;
color: #666;
text-align: right;
}
/* Infinite Scroll loader */
#infscr-loading {
text-align: center;

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

@ -145,6 +145,7 @@ class Data
*/
public static function show($event)
{
$l=\OC_L10N::get('lib');
$user = $event['affecteduser'];
$formattedDate = \OCP\Util::formatDate($event['timestamp']);
$formattedTimestamp = \OCP\relative_modified_date($event['timestamp']);
@ -157,24 +158,45 @@ class Data
echo('<span>');
echo('<span class="user">' . \OC_Util::sanitizeHTML($user) . '</span>');
echo('<span class="activitytime tooltip" title="' . \OC_Util::sanitizeHTML($formattedDate) . '">' . \OC_Util::sanitizeHTML($formattedTimestamp) . '</span>');
echo('<span class="appname">' . \OC_Util::sanitizeHTML($event['app']) . '</span>');
echo('</span>');
echo('</div>');
echo('<div class="messagecontainer">');
if ($event['link'] <> '') echo('<a href="' . $event['link'] . '">');
echo('<div class="activitysubject">' . \OC_Util::sanitizeHTML($event['subject']) . '</div>');
echo('<div class="activitymessage">' . \OC_Util::sanitizeHTML($event['message']) . '</div>');
$rootView = new \OC\Files\View('');
$exist = $rootView->file_exists('/' . $user . '/files' . $event['file']);
unset($rootView);
// show a preview image if the file still exists
if ($exist) {
echo('<img class="preview" src="' . \OCP\Util::linkToRoute('core_ajax_preview', array('file' => $event['file'], 'x' => 150, 'y' => 150)) . '" />');
if ($event['isGrouped']){
$count = 0;
echo('<ul class="activitysubject grouped">');
foreach($event['events'] as $subEvent){
echo('<li>');
if ($subEvent['link'] <> '') echo('<a href="' . $subEvent['link'] . '">');
echo($subEvent['subject']);
if ($subEvent['link'] <> '') echo('</a>');
echo('</li>');
$count++;
if ($count > 5){
echo('<li class="more">' . $l->n('%n more...', '%n more...', count($event['events']) - $count) . '</li>');
break;
}
}
echo('</ul>');
}
else{
if ($event['link'] <> '') echo('<a href="' . $event['link'] . '">');
echo('<div class="activitysubject">' . \OC_Util::sanitizeHTML($event['subject']) . '</div>');
echo('<div class="activitymessage">' . \OC_Util::sanitizeHTML($event['message']) . '</div>');
}
if ($event['link'] <> '') echo('</a>');
$rootView = new \OC\Files\View('');
if ($event['file'] !== null){
$exist = $rootView->file_exists('/' . $user . '/files' . $event['file']);
unset($rootView);
// show a preview image if the file still exists
if ($exist) {
echo('<img class="preview" src="' . \OCP\Util::linkToRoute('core_ajax_preview', array('file' => $event['file'], 'x' => 150, 'y' => 150)) . '" />');
}
}
if (!$event['isGrouped'] && $event['link'] <> '') echo('</a>');
echo('</div>'); // end messagecontainer
echo('</div>'); // end box

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

@ -24,24 +24,81 @@
/** @var $l OC_L10N */
/** @var $theme OC_Defaults */
/**
* @brief Makes a single event that aggregates the info
* from the given events into a group
* @param array $events array of events to aggregate
* @return array single event containing the aggregated info from
* the given events
*/
function makeEventGroup($events){
if (count($events) === 1){
return $events[0];
}
$event = array_shift($events);
// populate with first event
$groupedEvent = array(
'isGrouped' => true,
'user' => $event['user'],
'affecteduser' => $event['affecteduser'],
'app' => $event['app'],
'type' => $event['type'],
'timestamp' => $event['timestamp'],
'file' => $event['file'],
'link' => $event['link'],
'events' => $events
);
return $groupedEvent;
}
function makeGroupKey($event){
return $event['user'] . '|' .
$event['affecteduser'] . '|' .
$event['app'] . '|' .
$event['type'];
}
$lastDate = null;
$eventsInGroup = array();
$lastGroup = null;
foreach ($_['activity'] as $event) {
// group by date
// TODO: use more efficient way to group by date (don't group by localized string...)
$currentDate = (string)(\OCP\relative_modified_date($event['timestamp'], true));
// new date group
if ($currentDate !== $lastDate){
// not first group ?
// not first date group ?
if ($lastDate !== null){
// close previous group
// output box group
if (count($eventsInGroup) > 0){
\OCA\Activity\Data::show(makeEventGroup($eventsInGroup));
}
$eventsInGroup = array();
$lastGroup = null;
// close previous date group
echo('</div>'); // boxcontainer
echo('</div>'); // group
echo('</div>'); // date group
}
$lastDate = $currentDate;
echo('<div class="group" data-date="' . $currentDate . '">');
echo('<div class="groupheader"><span class="tooltip" title="' . \OCP\Util::formatDate(strip_time($event['timestamp']), true) .'">' . ucfirst($currentDate) . '</span></div>');
echo('<div class="boxcontainer">');
}
\OCA\Activity\Data::show($event);
$currentGroup = makeGroupKey($event);
// new box group
if ($lastGroup !== $currentGroup){
if ($lastGroup !== null){
// create meta event and add it to the list
\OCA\Activity\Data::show(makeEventGroup($eventsInGroup));
$eventsInGroup = array();
}
$lastGroup = $currentGroup;
}
$eventsInGroup[] = $event;
}
// show last group
if (count($eventsInGroup) > 0){
\OCA\Activity\Data::show(makeEventGroup($eventsInGroup));
}
echo('</div>'); // boxcontainer
echo('</div>'); // group