Skip to content

Commit

Permalink
MDL-64821 mod_forum: add templates for modern display mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwyllie committed Sep 25, 2019
1 parent b7c27c2 commit 7255378
Show file tree
Hide file tree
Showing 13 changed files with 1,105 additions and 9 deletions.
2 changes: 2 additions & 0 deletions mod/forum/amd/build/discussion_modern.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mod/forum/amd/build/discussion_modern.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions mod/forum/amd/src/discussion_modern.js
@@ -0,0 +1,37 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Module for viewing a discussion.
*
* @module mod_forum/discussion_new
* @package mod_forum
* @copyright 2019 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import $ from 'jquery';
import Discussion from 'mod_forum/discussion';
import LockToggle from 'mod_forum/lock_toggle';
import FavouriteToggle from 'mod_forum/favourite_toggle';
import Pin from 'mod_forum/pin_toggle';

export const init = (root) => {
Discussion.init(root);

var discussionToolsContainer = $('[data-container="discussion-tools"]');
LockToggle.init(discussionToolsContainer);
FavouriteToggle.init(discussionToolsContainer);
Pin.init(discussionToolsContainer);
};
10 changes: 8 additions & 2 deletions mod/forum/classes/local/factories/renderer.php
Expand Up @@ -192,12 +192,17 @@ public function get_single_discussion_posts_renderer(int $displaymode = null, bo
// Post process the exported posts for our template. This function will add the "replies"
// and "hasreplies" properties to the exported posts. It will also sort them into the
// reply tree structure if the display mode requires it.
function($exportedposts, $forums) use ($displaymode, $readonly, $exportedpostssorter) {
function($exportedposts, $forums, $discussions) use ($displaymode, $readonly, $exportedpostssorter) {
$forum = array_shift($forums);
$seenfirstunread = false;
$postcount = count($exportedposts);
$discussionsbyid = array_reduce($discussions, function($carry, $discussion) {
$carry[$discussion->get_id()] = $discussion;
return $carry;
}, []);
$exportedposts = array_map(
function($exportedpost) use ($forum, $readonly, $seenfirstunread) {
function($exportedpost) use ($forum, $discussionsbyid, $readonly, $seenfirstunread) {
$discussion = $discussionsbyid[$exportedpost->discussionid] ?? null;
if ($forum->get_type() == 'single' && !$exportedpost->hasparent) {
// Remove the author from any posts that don't have a parent.
unset($exportedpost->author);
Expand All @@ -209,6 +214,7 @@ function($exportedpost) use ($forum, $readonly, $seenfirstunread) {
$exportedpost->hasreplycount = false;
$exportedpost->hasreplies = false;
$exportedpost->replies = [];
$exportedpost->discussionlocked = $discussion ? $discussion->is_locked() : null;

$exportedpost->isfirstunread = false;
if (!$seenfirstunread && $exportedpost->unread) {
Expand Down
5 changes: 5 additions & 0 deletions mod/forum/lang/en/forum.php
Expand Up @@ -24,6 +24,7 @@
*/

$string['activityoverview'] = 'There are new forum posts';
$string['actionsforpost'] = 'Actions for post';
$string['addanewdiscussion'] = 'Add a new discussion topic';
$string['addanewquestion'] = 'Add a new question';
$string['addanewtopic'] = 'Add a new topic';
Expand All @@ -41,10 +42,13 @@
$string['areapost'] = 'Messages';
$string['attachment'] = 'Attachment';
$string['attachmentname'] = 'Attachment {$a}';
$string['attachmentnameandfilesize'] = '{$a->name} ({$a->size})';
$string['attachment_help'] = 'You can optionally attach one or more files to a forum post. If you attach an image, it will be displayed after the message.';
$string['attachmentnopost'] = 'You cannot export attachments without a post id';
$string['attachments'] = 'Attachments';
$string['attachmentswordcount'] = 'Attachments and word count';
$string['authorreplyingprivatelytoauthor'] = '{$a->respondant} replying privately to {$a->author}';
$string['authorreplyingtoauthor'] = '{$a->respondant} replying to {$a->author}';
$string['availability'] = 'Availability';
$string['blockafter'] = 'Post threshold for blocking';
$string['blockafter_help'] = 'This setting specifies the maximum number of posts which a user can post in the given time period. Users with the capability mod/forum:postwithoutthrottling are exempt from post limits.';
Expand Down Expand Up @@ -645,6 +649,7 @@
If \'Allow forced read tracking\' is enabled in the site administration, then a further option is available - forced. This means that tracking is always on, regardless of users\' forum preferences.';
$string['unlockdiscussion'] = 'Unlock this discussion';
$string['unread'] = 'Unread';
$string['unreadpost'] = 'Unread post';
$string['unreadposts'] = 'Unread posts';
$string['unreadpostsnumber'] = '{$a} unread posts';
$string['unreadpostsone'] = '1 unread post';
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/templates/forum_action_menu.mustache
Expand Up @@ -25,7 +25,7 @@
}
}}
<div class="ml-auto dropdown">
<button class="{{^settings.excludetext}}dropdown-toggle{{/settings.excludetext}} m-t-0 p-t-0 btn btn-link btn-icon"
<button class="{{^settings.excludetext}}dropdown-toggle{{/settings.excludetext}} m-t-0 p-t-0 btn btn-link"
type="button"
role="button"
data-toggle="dropdown"
Expand Down
62 changes: 62 additions & 0 deletions mod/forum/templates/forum_discussion_modern.mustache
@@ -0,0 +1,62 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template mod_forum/forum_discussion_modern
Template for displaying a single forum discussion.
Classes required for JS:
* none
Data attributes required for JS:
* none
Example context (json):
{
}
}}

<div id="discussion-container-{{uniqid}}" data-content="forum-discussion">
{{#html}}
<div class="mb-5">
<div class="d-flex flex-wrap">
<div>{{{modeselectorform}}}</div>
<div class="ml-auto d-flex align-items-middle" data-container="discussion-tools">
<div>{{{subscribe}}}</div>
<div class="pl-1">{{> mod_forum/forum_action_menu}}</div>
</div>
</div>

<div class="d-flex mt-2">
<div>{{{movediscussion}}}</div>
<div {{#movediscussion}}class="ml-2"{{/movediscussion}}>{{{exportdiscussion}}}</div>
</div>
</div>
{{/html}}

{{#notifications}}
{{> core/notification}}
{{/notifications}}

{{{html.posts}}}
</div>
{{#js}}
require(['jquery', 'mod_forum/discussion_modern'], function($, Discussion) {
var root = $('#discussion-container-{{uniqid}}');
Discussion.init(root);
});
{{/js}}

0 comments on commit 7255378

Please sign in to comment.