Skip to content

Commit

Permalink
MDL-65033 mod_forum: Move locked functionality into action menu
Browse files Browse the repository at this point in the history
Moved the lock functionality into the menu which exposes it to the
discussion list
  • Loading branch information
peterRd committed Apr 29, 2019
1 parent d3cac88 commit cda9da9
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 57 deletions.
2 changes: 1 addition & 1 deletion mod/forum/amd/build/discussion_list.min.js

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

34 changes: 34 additions & 0 deletions mod/forum/amd/src/discussion_list.js
Expand Up @@ -23,11 +23,17 @@
*/
define([
'jquery',
'core/templates',
'core/str',
'core/notification',
'mod_forum/subscription_toggle',
'mod_forum/selectors',
'mod_forum/repository',
], function(
$,
Templates,
String,
Notification,
SubscriptionToggle,
Selectors,
Repository
Expand Down Expand Up @@ -57,6 +63,34 @@ define([
})
.catch(Notification.exception);
});

root.on('click', Selectors.lock.toggle, function(e) {
var toggleElement = $(this);
var forumId = toggleElement.data('forumid');
var discussionId = toggleElement.data('discussionid');
var state = toggleElement.data('state');

Repository.setDiscussionLockState(forumId, discussionId, state)
.then(function(context) {
context.forumid = forumId;
return Templates.render('mod_forum/discussion_lock_toggle', context);
})
.then(function(html, js) {
return Templates.replaceNode(toggleElement, html, js);
})
.then(function() {
return String.get_string('lockupdated', 'forum')
.done(function(s) {
return Notification.addNotification({
message: s,
type: "info"
});
});
})
.catch(Notification.exception);

e.preventDefault();
});
};

return {
Expand Down
63 changes: 31 additions & 32 deletions mod/forum/externallib.php
Expand Up @@ -1642,6 +1642,36 @@ public static function set_lock_state($forumid, $discussionid, $targetstate) {
return $exporter->export($PAGE->get_renderer('mod_forum'));
}

/**
* Returns description of method parameters.
*
* @return external_function_parameters
*/
public static function set_lock_state_parameters() {
return new external_function_parameters(
[
'forumid' => new external_value(PARAM_INT, 'Forum that the discussion is in'),
'discussionid' => new external_value(PARAM_INT, 'The discussion to lock / unlock'),
'targetstate' => new external_value(PARAM_INT, 'The timestamp for the lock state')
]
);
}

/**
* Returns description of method result value.
*
* @return external_description
*/
public static function set_lock_state_returns() {
return new external_single_structure([
'id' => new external_value(PARAM_INT, 'The discussion we are locking.'),
'locked' => new external_value(PARAM_BOOL, 'The locked state of the discussion.'),
'times' => new external_single_structure([
'locked' => new external_value(PARAM_INT, 'The locked time of the discussion.'),
])
]);
}

/**
* Set the pin state.
*
Expand Down Expand Up @@ -1672,29 +1702,13 @@ public static function set_pin_state($discussionid, $targetstate) {
}

$discussion->set_pinned($targetstate);
$discussionrecord = $legacydatamapperfactory->get_discussion_data_mapper()->to_legacy_object($discussion);
$discussionvault->update_discussion($discussionrecord);
$discussionvault->update_discussion($discussion);

$exporterfactory = mod_forum\local\container::get_exporter_factory();
$exporter = $exporterfactory->get_discussion_exporter($USER, $forum, $discussion);
return $exporter->export($PAGE->get_renderer('mod_forum'));
}

/**
* Returns description of method parameters.
*
* @return external_function_parameters
*/
public static function set_lock_state_parameters() {
return new external_function_parameters(
[
'forumid' => new external_value(PARAM_INT, 'Forum that the discussion is in'),
'discussionid' => new external_value(PARAM_INT, 'The discussion to lock / unlock'),
'targetstate' => new external_value(PARAM_INT, 'The timestamp for the lock state')
]
);
}

/**
* Returns description of method parameters.
*
Expand All @@ -1711,21 +1725,6 @@ public static function set_pin_state_parameters() {
);
}

/**
* Returns description of method result value.
*
* @return external_description
*/
public static function set_lock_state_returns() {
return new external_single_structure([
'id' => new external_value(PARAM_INT, 'The discussion we are locking.'),
'locked' => new external_value(PARAM_BOOL, 'The locked state of the discussion.'),
'times' => new external_single_structure([
'locked' => new external_value(PARAM_INT, 'The locked time of the discussion.'),
])
]);
}

/**
* Returns description of method result value.
*
Expand Down
1 change: 1 addition & 0 deletions mod/forum/lang/en/forum.php
Expand Up @@ -325,6 +325,7 @@
Users with the capability to reply to locked discussions can unlock a discussion by replying to it.';
$string['longpost'] = 'Long post';
$string['locked'] = 'Locked';
$string['lockupdated'] = 'The lock option has been updated.';
$string['mailnow'] = 'Send forum post notifications with no editing-time delay';
$string['manydiscussions'] = 'Discussions per page';
$string['managesubscriptionsoff'] = 'Finish managing subscriptions';
Expand Down
1 change: 0 additions & 1 deletion mod/forum/styles.css
Expand Up @@ -302,7 +302,6 @@ span.unread {
}

.path-mod-forum .discussionsubscription,
.path-mod-forum .discussionlock,
.path-mod-forum .discussion-settings-menu,
.path-mod-forum .discussionsubscription {
margin-top: -10px;
Expand Down
8 changes: 4 additions & 4 deletions mod/forum/templates/discussion_lock_toggle.mustache
Expand Up @@ -35,12 +35,12 @@
}
}}
<a
class="iconsmall"
class="btn btn-link"
data-type="lock-toggle"
data-action="toggle"
data-discussionid="{{id}}"
data-forumid="{{forumid}}"
data-state="{{locked}}"
data-state="{{times.locked}}"
href="#"
{{#locked}}
title="{{#str}}clicktounlockdiscussion, forum{{/str}}"
Expand All @@ -50,9 +50,9 @@
{{/locked}}
>
{{#locked}}
{{#pix}}t/unlock, core, {{#str}}clicktounlockdiscussion, forum{{/str}}{{/pix}}{{#str}}locked, forum{{/str}}
{{#str}}locked, forum{{/str}}
{{/locked}}
{{^locked}}
{{#pix}}t/lock, core, {{#str}}clicktolockdiscussion, forum{{/str}}{{/pix}}{{#str}}notlocked, forum{{/str}}
{{#str}}notlocked, forum{{/str}}
{{/locked}}
</a>
7 changes: 7 additions & 0 deletions mod/forum/templates/forum_action_menu.mustache
Expand Up @@ -59,5 +59,12 @@
{{> mod_forum/discussion_pin_toggle}}
</div>
{{/capabilities.pin}}
{{#capabilities.manage}}
{{^istimelocked}}
<div class="dropdown-item" role="menuitem">
{{> forum/discussion_lock_toggle }}
</div>
{{/istimelocked}}
{{/capabilities.manage}}
</div>
</div>
8 changes: 1 addition & 7 deletions mod/forum/templates/forum_discussion.mustache
Expand Up @@ -33,13 +33,7 @@
<div id="discussion-container-{{uniqid}}" data-content="forum-discussion">
{{#html}}
<div class="d-flex flex-wrap flex-row-reverse m-b-1 text-right" data-container="discussion-tools">
{{#capabilities.manage}}
{{^istimelocked}}
<div class="pl-1 discussionlock">
{{> forum/discussion_lock_toggle }}
</div>
{{/istimelocked}}
{{/capabilities.manage}}

<div class="pl-1">
<div class="discussion-settings-menu">
{{> mod_forum/forum_action_menu}}
Expand Down
5 changes: 4 additions & 1 deletion mod/forum/tests/behat/discussion_lock.feature
Expand Up @@ -34,11 +34,14 @@ Feature: As a teacher, you can manually lock individual discussions when viewing
Given I log in as "admin"
And I am on "Course 1" course homepage
And I navigate to post "Discussion 1" in "Test forum name" forum
And I press "Settings"
Then "Lock" "link" should be visible
And I follow "Lock"
Then I should see "This discussion has been locked so you can no longer reply to it."
And I press "Settings"
Then "a[@title='Lock']" "css_element" should not be visible
Then "Locked" "link" should be visible
Then I should see "This discussion has been locked so you can no longer reply to it."
And I press "Settings"
And I follow "Discussion 2"
Then I should not see "This discussion has been locked so you can no longer reply to it."
And I log out
Expand Down
3 changes: 0 additions & 3 deletions theme/boost/scss/moodle/modules.scss
Expand Up @@ -69,7 +69,6 @@ select {

thead .header th,
tbody .discussion td {
&.discussionlock,
&.discussionsubscription {
width: 16px;
padding-left: 0.5em;
Expand All @@ -84,14 +83,12 @@ select {
}

.discussionsubscription,
.discussionlock,
.replies {
text-align: center;
}

.topic,
.discussionsubscription,
.discussionlock,
.topic.starter,
.replies,
.lastpost {
Expand Down
5 changes: 1 addition & 4 deletions theme/boost/style/moodle.css
Expand Up @@ -15028,8 +15028,7 @@ select {
.path-mod-forum .forumheaderlist thead .header.lastpost {
text-align: right; }

.path-mod-forum .forumheaderlist thead .header th.discussionlock, .path-mod-forum .forumheaderlist thead .header th.discussionsubscription,
.path-mod-forum .forumheaderlist tbody .discussion td.discussionlock,
.path-mod-forum .forumheaderlist thead .header th.discussionsubscription,
.path-mod-forum .forumheaderlist tbody .discussion td.discussionsubscription {
width: 16px;
padding-left: 0.5em;
Expand All @@ -15040,13 +15039,11 @@ select {
white-space: normal; }

.path-mod-forum .forumheaderlist .discussion .discussionsubscription,
.path-mod-forum .forumheaderlist .discussion .discussionlock,
.path-mod-forum .forumheaderlist .discussion .replies {
text-align: center; }

.path-mod-forum .forumheaderlist .discussion .topic,
.path-mod-forum .forumheaderlist .discussion .discussionsubscription,
.path-mod-forum .forumheaderlist .discussion .discussionlock,
.path-mod-forum .forumheaderlist .discussion .topic.starter,
.path-mod-forum .forumheaderlist .discussion .replies,
.path-mod-forum .forumheaderlist .discussion .lastpost {
Expand Down
5 changes: 1 addition & 4 deletions theme/classic/style/moodle.css
Expand Up @@ -15285,8 +15285,7 @@ select {
.path-mod-forum .forumheaderlist thead .header.lastpost {
text-align: right; }

.path-mod-forum .forumheaderlist thead .header th.discussionlock, .path-mod-forum .forumheaderlist thead .header th.discussionsubscription,
.path-mod-forum .forumheaderlist tbody .discussion td.discussionlock,
.path-mod-forum .forumheaderlist thead .header th.discussionsubscription,
.path-mod-forum .forumheaderlist tbody .discussion td.discussionsubscription {
width: 16px;
padding-left: 0.5em;
Expand All @@ -15297,13 +15296,11 @@ select {
white-space: normal; }

.path-mod-forum .forumheaderlist .discussion .discussionsubscription,
.path-mod-forum .forumheaderlist .discussion .discussionlock,
.path-mod-forum .forumheaderlist .discussion .replies {
text-align: center; }

.path-mod-forum .forumheaderlist .discussion .topic,
.path-mod-forum .forumheaderlist .discussion .discussionsubscription,
.path-mod-forum .forumheaderlist .discussion .discussionlock,
.path-mod-forum .forumheaderlist .discussion .topic.starter,
.path-mod-forum .forumheaderlist .discussion .replies,
.path-mod-forum .forumheaderlist .discussion .lastpost {
Expand Down

0 comments on commit cda9da9

Please sign in to comment.