Skip to content

Commit

Permalink
feature(discussions): More compact listing of lastest discussions
Browse files Browse the repository at this point in the history
Removes several features to make the listing cleaner/more compact:

 * All the actions/controls (like, mark-as-spam, remove-ad, etc.)
 * The preview text (people need to write better titles anyways)
 * Which group it was posted in (usually don't care)

Refs #18
  • Loading branch information
ewinslow committed Aug 19, 2015
1 parent 40e7342 commit 710c5e9
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 0 deletions.
7 changes: 7 additions & 0 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,11 @@ function community_theme_pagesetup() {

$actions = __DIR__ . "/actions";
elgg_register_action('admin/flush_apc', "$actions/admin/flush_apc.php", 'admin');

elgg_register_plugin_hook_handler('route', 'discussion', function($hook, $type, $result, $params) {
if (!isset($params['segments'][0])) {
echo elgg_view_resource('discussion/index');
return false;
}
});
});
64 changes: 64 additions & 0 deletions views/default/resources/discussion/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.actions {
align-items: center;
display: flex;
flex-direction: row;
white-space: nowrap;
}

.header {
display: flex;
flex-direction: row;
padding: 0 12px;
}

.listItem {
align-items: center;
display: flex;
flex-direction: row;
padding-left: 12px;
}

.listItem:not(:last-child) {
border-bottom: 1px solid #ccc;
}

.listItem--unread {
font-weight: bold;
}

.listItem-author {
display: block;

/* If we don't set this explicit, the div grows to be 46px???? */
height: 40px;
}

.listItem-body {
flex: 100%;

}

.listItem-metadata {
padding: 0 12px 8px;
}

.listItem-title {
display: block;
font-size: larger;
padding: 8px 12px;
}

.pagination {
display: flex;
padding: 8px 12px;
}

.pagination > * {
flex: 1;
text-align: center;
}

.title {
flex: 100%;
padding: .5em 0;
}
134 changes: 134 additions & 0 deletions views/default/resources/discussion/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

$offset = get_input('offset', 0);
$limit = max(50, elgg_get_config('default_limit'));

$recentlyActive = elgg_get_entities([
'type' => 'object',
'subtype' => 'discussion',
'order_by' => 'e.last_action desc',
'limit' => $limit,
'offset' => $offset,
'preload_owners' => true,
'preload_containers' => true,
]);

$discussions = (object)[
'length' => elgg_get_entities([
'type' => 'object',
'subtype' => 'discussion',
'count' => true,
]),
'fields' => (object)[
'title' => (object)['label' => 'Title'],
'replies_length' => (object)['label' => 'Replies'],
'last_action' => (object)['label' => 'Last activity'],
],
'recently_active' => (object)[
'label' => 'Latest discussion',
'next' => (object)['label' => 'Older &raquo;'],
'prev' => (object)['label' => '&laquo; Newer'],
'actions' => [
(object)[
'label' => 'Start new discussion',
'href' => elgg_get_site_url() . 'discussion/new',
],
],
'items' => array_map(function($discussion) {
$owner = $discussion->getOwnerEntity();

return (object)[
'author' => (object)[
'name' => $owner->name,
'url' => $owner->getUrl(),
'avatar' => (object)[
'preview' => (new ElggUser())->getIconUrl('small'),
'40x40' => $owner->getIconUrl('small'),
'100x100' => $owner->getIconUrl('medium'),
],
],
'is_unread' => false,
'last_action' => $discussion->last_action,
'title' => $discussion->title,
'url' => $discussion->getUrl(),
'replies_length' => elgg_get_entities(array(
'type' => 'object',
'subtype' => 'discussion_reply',
'container_guid' => $discussion->getGUID(),
'count' => true,
'distinct' => false,
)),
];
}, $recentlyActive),
],
];


elgg_register_css('resources/discussion/index', elgg_get_simplecache_url('resources/discussion/index.css'));
elgg_load_css('resources/discussion/index');
?>

<?php ob_start(); ?>
<main>
<header class="header">
<h1 class="title">
<?=$discussions->recently_active->label; ?>
</h1>
<ul class="actions">
<?php foreach ($discussions->recently_active->actions as $action): ?>
<li>
<a href="<?=$action->href?>" class="elgg-button elgg-button-special">
<?=$action->label;?>
</a>
</li>
<?php endforeach; ?>
</ul>
</header>
<ol class="list">
<?php foreach ($discussions->recently_active->items as $discussion): ?>
<li class="listItem <?=$discussion->is_unread ? 'listItem--unread' : ''?>">
<div class="listItem-author">
<?php $avatar = $discussion->author->avatar; ?>
<img src="<?=$avatar->preview?>" width="40" height="40"
srcset="<?=$avatar->{'40x40'}?> 1x, <?=$avatar->{'100x100'}?> 2.5x"
alt="<?=$discussion->author->name?>">
</div>
<div class="listItem-body">
<a class="listItem-title"
href="<?=$discussion->url;?>">
<?=$discussion->title;?>
</a>
<div class="listItem-metadata">
<a href="<?=$discussion->author->url?>">
<?=$discussion->author->name?>
</a>
&middot;
<?=elgg_view('output/friendlytime', ['time' => $discussion->last_action]);?>
&middot;
<?=$discussion->replies_length . ' ' . elgg_echo('discussion:replies')?>
</div>
</div>
</li>
<?php endforeach; ?>
</ol>
<nav class="pagination">
<?php if ($offset > 0): ?>
<a href="?offset=<?=max(0, $offset - $limit)?>" rel="prev"
class="elgg-button elgg-button-action">
<?=$discussions->recently_active->prev->label?>
</a>
<?php endif; ?>

<?php if ($offset + $limit < $discussions->length): ?>
<a href="?offset=<?=$limit+$offset?>" rel="next"
class="elgg-button elgg-button-action">
<?=$discussions->recently_active->next->label?>
</a>
<?php endif; ?>
</nav>
</main>
<?php $body = ob_get_clean(); ?>

<?php

echo elgg_view_page($title, $body);

0 comments on commit 710c5e9

Please sign in to comment.