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

feature(discussions): More compact listing of lastest discussions #71

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ download
credentials.php
/google2*
/google8*
npm-debug.log
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Features
========
# https://elgg.org

This is the source code for the elgg.org homepage and community site.

## Features

* Turns a message board widget into a send a private message widget. Spammers
were leaving messages on their message boards and we would rather have
Expand All @@ -8,3 +11,12 @@ Features
* Delete private messages sent from deleted users
* Add APC cache flush button to admin control panel widget
* Filter out friending and new bookmarks from the river


## Contributing

Automatically fix various style/coding issues in changed files:

```
composer fix
```
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"scripts": {
"post-install-cmd": "\\Elgg\\Composer\\PostUpdate::execute",
"post-update-cmd": "\\Elgg\\Composer\\PostUpdate::execute",
"fix": [
"npm install",
"./fix.sh"
],
"test": "phpunit tests",
"translations:update": "tx pull -a --mode=reviewed --minimum-perc=100"
},
Expand Down
6 changes: 6 additions & 0 deletions fix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

for line in $(git diff --name-only | grep '.*.css'); do
echo "node_modules/.bin/postcss --use autoprefixer -o $line $line"
node_modules/.bin/postcss --use autoprefixer -o $line $line
done
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"devDependencies": {
"autoprefixer": "^5.2.0",
"postcss-cli": "^1.5.0"
}
}
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;
}
});
});
103 changes: 103 additions & 0 deletions views/default/resources/discussion/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
.actions {
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
white-space: nowrap;
}

.header {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
padding: 0 12px;
}

.listItem {
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
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 {
-webkit-box-flex: 100%;
-webkit-flex: 100%;
-ms-flex: 100%;
flex: 100%;

}

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

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

.pagination {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
padding: 8px 12px;
}

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

.title {
-webkit-box-flex: 100%;
-webkit-flex: 100%;
-ms-flex: 100%;
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);