diff --git a/blocks/social_activities/block_social_activities.php b/blocks/social_activities/block_social_activities.php index c60eee7ac3a2d..728464aeb27a4 100644 --- a/blocks/social_activities/block_social_activities.php +++ b/blocks/social_activities/block_social_activities.php @@ -21,8 +21,7 @@ * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -class block_social_activities extends block_list { +class block_social_activities extends block_base { function init(){ $this->title = get_string('pluginname', 'block_social_activities'); } @@ -32,15 +31,12 @@ function applicable_formats() { } function get_content() { - global $USER, $CFG, $DB, $OUTPUT; - if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); - $this->content->items = array(); - $this->content->icons = array(); + $this->content->text = ''; $this->content->footer = ''; if (empty($this->instance)) { @@ -48,198 +44,24 @@ function get_content() { } $course = $this->page->course; - $format = course_get_format($course); - $courserenderer = $format->get_renderer($this->page); - - require_once($CFG->dirroot.'/course/lib.php'); - - $context = context_course::instance($course->id); - $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context); - $modinfo = get_fast_modinfo($course); - - // Output classes. - $cmnameclass = $format->get_output_classname('content\\cm\\cmname'); - $controlmenuclass = $format->get_output_classname('content\\cm\\controlmenu'); - - $badgeattributes = [ - 'class' => 'badge rounded-pill bg-warning text-dark mt-2', - 'data-region' => 'visibility' - ]; - // Extra fast view mode. - if (!$isediting) { - if (!empty($modinfo->sections[0])) { - foreach($modinfo->sections[0] as $cmid) { - $cm = $modinfo->cms[$cmid]; - if (!$cm->uservisible || !$cm->is_visible_on_course_page()) { - continue; - } - - $badges = ''; - if (!$cm->visible) { - $badges = html_writer::tag( - 'span', - get_string('hiddenfromstudents'), - $badgeattributes - ); - } - - if ($cm->is_stealth()) { - $badges = html_writer::tag( - 'span', - get_string('hiddenoncoursepage'), - $badgeattributes - ); - } - - if (!$cm->url) { - $activitybasis = html_writer::div( - $cm->get_formatted_content(['overflowdiv' => true, 'noclean' => true]), - 'activity-basis d-flex align-items-center' - ); - $content = html_writer::div( - $activitybasis . $badges, - 'contentwithoutlink activity-item activity', - ['data-activityname' => $cm->name] - ); - $this->content->items[] = $content; - $this->content->icons[] = ''; - } else { - $cmname = new $cmnameclass($format, $cm->get_section_info(), $cm); - $activitybasis = html_writer::div( - $courserenderer->render($cmname), - 'activity-basis d-flex align-items-center'); - $content = html_writer::div( - $activitybasis . $badges, - 'activity-item activity', - ['data-activityname' => $cm->name] - ); - $this->content->items[] = $content; - } - } - } - return $this->content; - } - - // Slow & hacky editing mode. - $ismoving = ismoving($course->id); + course_create_sections_if_missing($course, 0); + $format = course_get_format($course); + $modinfo = $format->get_modinfo(); $section = $modinfo->get_section_info(0); - if ($ismoving) { - $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'")); - $strcancel= get_string('cancel'); - } else { - $strmove = get_string('move'); - } - - if ($ismoving) { - $this->content->icons[] = ' ' . $OUTPUT->pix_icon('t/move', get_string('move')); - $cancelurl = new moodle_url('/course/mod.php', array('cancelcopy' => 'true', 'sesskey' => sesskey())); - $this->content->items[] = $USER->activitycopyname . ' (' . $strcancel . ')'; - } - - if (!empty($modinfo->sections[0])) { - foreach ($modinfo->sections[0] as $modnumber) { - $mod = $modinfo->cms[$modnumber]; - if (!$mod->uservisible || !$mod->is_visible_on_course_page()) { - continue; - } - if (!$ismoving) { - - $controlmenu = new $controlmenuclass( - $format, - $mod->get_section_info(), - $mod, - ['disableindentation' => true] - ); - - $menu = $controlmenu->get_action_menu($OUTPUT); - - // Add a move primary action. - $moveaction = html_writer::link( - new moodle_url('/course/mod.php', ['sesskey' => sesskey(), 'copy' => $mod->id]), - $OUTPUT->pix_icon('i/dragdrop', $strmove), - ['class' => 'editing_move_activity'] - ); - - $editbuttons = html_writer::tag('div', - $courserenderer->render($controlmenu), - ['class' => 'buttons activity-actions ms-auto'] - ); - } else { - $editbuttons = ''; - $moveaction = ''; - } - if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $mod->context)) { - if ($ismoving) { - if ($mod->id == $USER->activitycopy) { - continue; - } - $movingurl = new moodle_url('/course/mod.php', array('moveto' => $mod->id, 'sesskey' => sesskey())); - $this->content->items[] = html_writer::link($movingurl, '', array('title' => $strmovefull, - 'class' => 'movehere')); - $this->content->icons[] = ''; - } - - $badges = ''; - if (!$mod->visible) { - $badges = html_writer::tag( - 'span', - get_string('hiddenfromstudents'), - $badgeattributes - ); - } - - if ($mod->is_stealth()) { - $badges = html_writer::tag( - 'span', - get_string('hiddenoncoursepage'), - $badgeattributes - ); - } - - if (!$mod->url) { - $activitybasis = html_writer::div( - $mod->get_formatted_content(['overflowdiv' => true, 'noclean' => true]) . - $editbuttons, - 'activity-basis d-flex align-items-center'); - $content = html_writer::div( - $moveaction . - $activitybasis . - $badges, - 'contentwithoutlink activity-item activity', - ['data-activityname' => $mod->name] - ); - $this->content->items[] = $content; - $this->content->icons[] = ''; - } else { - $cmname = new $cmnameclass($format, $mod->get_section_info(), $mod); - $activitybasis = html_writer::div( - $courserenderer->render($cmname) . - $editbuttons, - 'activity-basis d-flex align-items-center'); - $content = html_writer::div( - $moveaction . - $activitybasis . - $badges, - 'activity-item activity', - ['data-activityname' => $mod->name] - ); - $this->content->items[] = $content; - } - } - } - } + $courserenderer = $format->get_renderer($this->page); - if ($ismoving) { - $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey())); - $this->content->items[] = html_writer::link($movingurl, '', array('title' => $strmovefull, 'class' => 'movehere')); - $this->content->icons[] = ''; - } + $output = new block_social_activities\output\blocksection($format, $section); - $this->content->footer = $courserenderer->course_section_add_cm_control($course, - 0, null, array('inblock' => true)); + $this->content->text = $courserenderer->render($output); + $this->content->footer = $courserenderer->course_section_add_cm_control( + course: $course, + section: 0, + sectionreturn: null, + displayoptions: ['inblock' => true], + ); return $this->content; } } diff --git a/blocks/social_activities/classes/output/blocksection.php b/blocks/social_activities/classes/output/blocksection.php new file mode 100644 index 0000000000000..6b12e8262cb5a --- /dev/null +++ b/blocks/social_activities/classes/output/blocksection.php @@ -0,0 +1,72 @@ +. + +namespace block_social_activities\output; + +use core_courseformat\base as courseformat; +use renderable; +use section_info; +use templatable; + +/** + * Class blocksection + * + * @package block_social_activities + * @copyright 2024 Ferran Recio + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class blocksection implements renderable, templatable { + + /** + * The class constructor. + * + * @param courseformat $format the course format instance + * @param section_info $section the section to render + */ + public function __construct( + /** @var courseformat $format the course format instance. */ + protected courseformat $format, + /** @var section_info $section the section to render. */ + protected section_info $section, + ) { + } + + /** + * Export for template. + * + * @param \renderer_base $output + * @return array + */ + public function export_for_template(\renderer_base $output) { + $format = $this->format; + $course = $format->get_course(); + $section = $this->section; + + $sectionoutputclass = $format->get_output_classname('content\\section\\cmlist'); + $sectionoutput = new $sectionoutputclass($format, $section); + + $cmlist = $output->render($sectionoutput); + + return [ + 'siteid' => $course->id, + 'cmlist' => $cmlist, + 'sectionid' => $section->id, + 'sectionname' => $format->get_section_name($section), + 'sectionnum' => $section->sectionnum, + 'editing' => $format->show_editor(), + ]; + } +} diff --git a/blocks/social_activities/styles.css b/blocks/social_activities/styles.css index 1de78703fd16d..2e6b8b90f3a30 100644 --- a/blocks/social_activities/styles.css +++ b/blocks/social_activities/styles.css @@ -1,15 +1,34 @@ -.block_social_activities li { - clear: both; +/* Imitate mobile grid for activity card. */ +.block_social_activities .activity-item .activity-grid { + grid-template-columns: min-content 1fr min-content min-content min-content; + grid-template-rows: 1fr repeat(4, min-content); + grid-template-areas: + "icon name actions" + "visibility visibility visibility" + "dates dates dates" + "completion completion completion" + "altcontent altcontent altcontent" + "afterlink afterlink afterlink" + "availability availability availability"; } -.block_social_activities li .column { - width: 100%; +.block_social_activities .activity-item .activity-grid.noname-grid { + grid-template-columns: 1fr min-content; + grid-template-areas: + "actions" + "visibility" + "altcontent" + "groupmode" + "afterlink" + "completion" + "availability"; } -.block_social_activities li .buttons a img { - vertical-align: text-bottom; +.block_social_activities .activity-item .activity-grid.noname-grid .activity-actions { + justify-self: end; } -.block_social_activities .instancename { - word-break: break-all; +/* Hide extra edit elements in block space. */ +.block_social_activities .activity-groupmode-info { + display: none; } diff --git a/blocks/social_activities/templates/blocksection.mustache b/blocks/social_activities/templates/blocksection.mustache new file mode 100644 index 0000000000000..56b995818b7b1 --- /dev/null +++ b/blocks/social_activities/templates/blocksection.mustache @@ -0,0 +1,72 @@ +{{! + 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 . +}} +{{! + @template block_social_activities/blocksection + + This mustache emulates a course single section structure inside a block. + + It requires to include several divs to emulate the structure of a course format. + + Example context (json): + { + "cmlist": "Sample", + "siteid": 1, + "sectionid": 1, + "sectionname": "Sample", + "sectionnum": 1, + "editing": true + } +}} +
+ {{! The section list is used by the content module to init the sections.}} +
+ {{! The section need some bottom padding and margin for the dropzone. + Otherwise the activities will cover the area. }} +
+ {{#editing}} + {{! The section header is used as a dropzone when the section is empty.}} +
 
+ {{/editing}} + {{{cmlist}}} +
+
+
+{{#js}} +{{! The block should be fast to load, we only load the editor when needed.}} +{{#editing}} +require(['core_courseformat/local/content'], function(component) { + component.init('block_social_activities_section', {}); +}); +{{/editing}} +{{/js}} diff --git a/blocks/social_activities/tests/behat/behat_block_social_activities.php b/blocks/social_activities/tests/behat/behat_block_social_activities.php index ae026737b266d..1e64e6e491f83 100644 --- a/blocks/social_activities/tests/behat/behat_block_social_activities.php +++ b/blocks/social_activities/tests/behat/behat_block_social_activities.php @@ -40,129 +40,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class behat_block_social_activities extends behat_base { - - /** - * Returns the DOM node of the activity in the social activities block - * - * @throws ElementNotFoundException Thrown by behat_base::find - * @param string $activityname The activity name - * @return NodeElement - */ - protected function get_social_block_activity_node($activityname) { - $activityname = behat_context_helper::escape($activityname); - $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_social_activities ')]//li[contains(., $activityname)]"; - - return $this->find('xpath', $xpath); - } - - /** - * Checks that the specified activity in the social activities block should have the specified editing icon. - * - * This includes items in the action menu for the item (does not require it to be open) - * - * You should be in the course page with editing mode turned on. - * - * @Then /^"(?P(?:[^"]|\\")*)" activity in social activities block should have "(?P(?:[^"]|\\")*)" editing icon$/ - * @param string $activityname - * @param string $iconname - */ - public function activity_in_social_activities_block_should_have_editing_icon($activityname, $iconname) { - $activitynode = $this->get_social_block_activity_node($activityname); - - $notfoundexception = new ExpectationException('"' . $activityname . '" doesn\'t have a "' . - $iconname . '" editing icon', $this->getSession()); - $this->find('named_partial', array('link', $iconname), $notfoundexception, $activitynode); - } - - /** - * Checks that the specified activity in the social activities block should not have the specified editing icon. - * - * This includes items in the action menu for the item (does not require it to be open) - * - * You should be in the course page with editing mode turned on. - * - * @Then /^"(?P(?:[^"]|\\")*)" activity in social activities block should not have "(?P(?:[^"]|\\")*)" editing icon$/ - * @param string $activityname - * @param string $iconname - */ - public function activity_in_social_activities_block_should_not_have_editing_icon($activityname, $iconname) { - $activitynode = $this->get_social_block_activity_node($activityname); - - try { - $this->find('named_partial', array('link', $iconname), false, $activitynode); - throw new ExpectationException('"' . $activityname . '" has a "' . $iconname . - '" editing icon when it should not', $this->getSession()); - } catch (ElementNotFoundException $e) { - // This is good, the menu item should not be there. - } - } - - /** - * Clicks on the specified element of the activity. You should be in the course page with editing mode turned on. - * - * @Given /^I click on "(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)" in the "(?P(?:[^"]|\\")*)" activity in social activities block$/ - * @param string $element - * @param string $selectortype - * @param string $activityname - */ - public function i_click_on_in_the_activity_in_social_activities_block($element, $selectortype, $activityname) { - $element = $this->get_social_block_activity_element($element, $selectortype, $activityname); - $element->click(); - } - - /** - * Finds the element containing a specific activity in the social activity block. - * - * @throws ElementNotFoundException - * @param string $element - * @param string $selectortype - * @param string $activityname - * @return NodeElement - */ - protected function get_social_block_activity_element($element, $selectortype, $activityname) { - $activitynode = $this->get_social_block_activity_node($activityname); - - $exception = new ElementNotFoundException($this->getSession(), "'{$element}' '{$selectortype}' in '{$activityname}'"); - return $this->find($selectortype, $element, $exception, $activitynode); - } - - /** - * Checks that the specified activity is hidden in the social activities block. - * - * @Then /^"(?P(?:[^"]|\\")*)" activity in social activities block should be hidden$/ - * @param string $activityname - */ - public function activity_in_social_activities_block_should_be_hidden($activityname) { - $activitynode = $this->get_social_block_activity_node($activityname); - $exception = new ExpectationException('"' . $activityname . '" is not hidden', $this->getSession()); - $this->find('named_partial', array('badge', get_string('hiddenfromstudents')), $exception, $activitynode); - } - - /** - * Checks that the specified activity is hidden in the social activities block. - * - * @Then /^"(?P(?:[^"]|\\")*)" activity in social activities block should be available but hidden from course page$/ - * @param string $activityname - */ - public function activity_in_social_activities_block_should_be_available_but_hidden_from_course_page($activityname) { - $activitynode = $this->get_social_block_activity_node($activityname); - $exception = new ExpectationException('"' . $activityname . '" is not hidden but available', $this->getSession()); - $this->find('named_partial', array('badge', get_string('hiddenoncoursepage')), $exception, $activitynode); - } - - /** - * Opens an activity actions menu in the social activities block if it is not already opened. - * - * @Given /^I open "(?P(?:[^"]|\\")*)" actions menu in social activities block$/ - * @throws DriverException The step is not available when Javascript is disabled - * @param string $activityname - */ - public function i_open_actions_menu_in_social_activities_block($activityname) { - $activityname = behat_context_helper::escape($activityname); - $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_social_activities ')]//li[contains(., $activityname)]"; - $this->execute('behat_action_menu::i_open_the_action_menu_in', [$xpath, 'xpath_element']); - } - /** * Return the list of partial named selectors. * diff --git a/blocks/social_activities/tests/behat/behat_block_social_activities_deprecated.php b/blocks/social_activities/tests/behat/behat_block_social_activities_deprecated.php new file mode 100644 index 0000000000000..f98a38c76bf5b --- /dev/null +++ b/blocks/social_activities/tests/behat/behat_block_social_activities_deprecated.php @@ -0,0 +1,205 @@ +. + +// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. + +require_once(__DIR__ . '/../../../../lib/behat/behat_deprecated_base.php'); + +use Behat\Mink\Element\NodeElement; +use Behat\Mink\Exception\ExpectationException as ExpectationException; +use Behat\Mink\Exception\DriverException as DriverException; +use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; + +/** + * Behat steps in plugin block_social_activities + * + * @package block_social_activities + * @category test + * @copyright 2024 Ferran Recio + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_block_social_activities_deprecated extends behat_deprecated_base { + /** + * Returns the DOM node of the activity in the social activities block + * + * @throws ElementNotFoundException Thrown by behat_base::find + * @param string $activityname The activity name + * @return NodeElement + */ + protected function get_social_block_activity_node($activityname) { + $activityname = behat_context_helper::escape($activityname); + $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_social_activities ')]//li[contains(., $activityname)]"; + + return $this->find('xpath', $xpath); + } + + /** + * Finds the element containing a specific activity in the social activity block. + * + * @throws ElementNotFoundException + * @param string $element + * @param string $selectortype + * @param string $activityname + * @return NodeElement + */ + protected function get_social_block_activity_element($element, $selectortype, $activityname) { + $activitynode = $this->get_social_block_activity_node($activityname); + + $exception = new ElementNotFoundException($this->getSession(), "'{$element}' '{$selectortype}' in '{$activityname}'"); + return $this->find($selectortype, $element, $exception, $activitynode); + } + + /** + * Checks that the specified activity in the social activities block should have the specified editing icon. + * + * This includes items in the action menu for the item (does not require it to be open) + * + * You should be in the course page with editing mode turned on. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Then /^"(?P(?:[^"]|\\")*)" activity in social activities block should have "(?P(?:[^"]|\\")*)" editing icon$/ + * @param string $activityname + * @param string $iconname + */ + public function activity_in_social_activities_block_should_have_editing_icon($activityname, $iconname) { + $this->deprecated_message([ + 'behat_block_social_activities::activity_in_social_activities_block_should_have_editing_icon is deprecated', + 'Use: I should see WHATEVER in the ACTIVITYNAME "activity"', + ]); + + $activitynode = $this->get_social_block_activity_node($activityname); + + $notfoundexception = new ExpectationException('"' . $activityname . '" doesn\'t have a "' . + $iconname . '" editing icon', $this->getSession()); + $this->find('named_partial', ['link', $iconname], $notfoundexception, $activitynode); + } + + /** + * Checks that the specified activity in the social activities block should not have the specified editing icon. + * + * This includes items in the action menu for the item (does not require it to be open) + * + * You should be in the course page with editing mode turned on. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Then /^"(?P(?:[^"]|\\")*)" activity in social activities block should not have "(?P(?:[^"]|\\")*)" editing icon$/ + * @param string $activityname + * @param string $iconname + */ + public function activity_in_social_activities_block_should_not_have_editing_icon($activityname, $iconname) { + $this->deprecated_message([ + 'behat_block_social_activities::activity_in_social_activities_block_should_not_have_editing_icon is deprecated', + 'Use: I should not see WHATEVER in the ACTIVITYNAME "activity"', + ]); + + $activitynode = $this->get_social_block_activity_node($activityname); + + try { + $this->find('named_partial', ['link', $iconname], false, $activitynode); + throw new ExpectationException('"' . $activityname . '" has a "' . $iconname . + '" editing icon when it should not', $this->getSession()); + } catch (ElementNotFoundException $e) { + // This is good, the menu item should not be there. + return; + } + } + + /** + * Clicks on the specified element of the activity. You should be in the course page with editing mode turned on. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Given /^I click on "(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)" in the "(?P(?:[^"]|\\")*)" activity in social activities block$/ + * @param string $element + * @param string $selectortype + * @param string $activityname + */ + public function i_click_on_in_the_activity_in_social_activities_block($element, $selectortype, $activityname) { + $this->deprecated_message([ + 'behat_block_social_activities::i_click_on_in_the_activity_in_social_activities_block is deprecated', + 'Use: I open ACTIVITYNAME actions menu & I choose OPTIONTEXT in the open action menu', + ]); + + $element = $this->get_social_block_activity_element($element, $selectortype, $activityname); + $element->click(); + } + + /** + * Checks that the specified activity is hidden in the social activities block. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Then /^"(?P(?:[^"]|\\")*)" activity in social activities block should be hidden$/ + * @param string $activityname + */ + public function activity_in_social_activities_block_should_be_hidden($activityname) { + $this->deprecated_message([ + 'behat_block_social_activities::activity_in_social_activities_block_should_be_hidden is deprecated', + 'Use: I should see "Hidden from students" in the "ACTIVITYNAME" "core_courseformat > Activity visibility"', + ]); + + $activitynode = $this->get_social_block_activity_node($activityname); + $exception = new ExpectationException('"' . $activityname . '" is not hidden', $this->getSession()); + $this->find('named_partial', ['badge', get_string('hiddenfromstudents')], $exception, $activitynode); + } + + /** + * Checks that the specified activity is hidden in the social activities block. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Then /^"(?P(?:[^"]|\\")*)" activity in social activities block should be available but hidden from course page$/ + * @param string $activityname + */ + public function activity_in_social_activities_block_should_be_available_but_hidden_from_course_page($activityname) { + $this->deprecated_message([ + 'behat_block_social_activities::activity_in_social_activities_block_should_be_available_but_hidden_from_course_page is deprecated', + 'Use: I should see "Available but not shown on course page" in the "ACTIVITYNAME" "core_courseformat > Activity visibility"', + ]); + + $activitynode = $this->get_social_block_activity_node($activityname); + $exception = new ExpectationException('"' . $activityname . '" is not hidden but available', $this->getSession()); + $this->find('named_partial', ['badge', get_string('hiddenoncoursepage')], $exception, $activitynode); + } + + /** + * Opens an activity actions menu in the social activities block if it is not already opened. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Given /^I open "(?P(?:[^"]|\\")*)" actions menu in social activities block$/ + * @throws DriverException The step is not available when Javascript is disabled + * @param string $activityname + */ + public function i_open_actions_menu_in_social_activities_block($activityname) { + $this->deprecated_message([ + 'behat_block_social_activities::i_open_actions_menu_in_social_activities_block is deprecated', + 'Use: I open "ACTIVITYNAME" actions menu', + ]); + + $activityname = behat_context_helper::escape($activityname); + $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_social_activities ')]//li[contains(., $activityname)]"; + $this->execute('behat_action_menu::i_open_the_action_menu_in', [$xpath, 'xpath_element']); + } +} diff --git a/blocks/social_activities/tests/behat/edit_activities.feature b/blocks/social_activities/tests/behat/edit_activities.feature index 9094e19c24ea9..9e223a17595c7 100644 --- a/blocks/social_activities/tests/behat/edit_activities.feature +++ b/blocks/social_activities/tests/behat/edit_activities.feature @@ -5,16 +5,18 @@ Feature: Edit activities in social activities block I need to add and edit activities there Background: - Given the following "courses" exist: - | fullname | shortname | format | - | Course 1 | C1 | social | + Given the following "course" exists: + | fullname | Course 1 | + | shortname | C1 | + | format | social | + | numsections | 0 | And the following "users" exist: | username | firstname | lastname | - | user1 | User | One | + | teacher1 | Teacher | One | | student1 | Student | One | And the following "course enrolments" exist: | user | course | role | - | user1 | C1 | editingteacher | + | teacher1 | C1 | editingteacher | | student1 | C1 | student | @javascript @@ -22,10 +24,10 @@ Feature: Edit activities in social activities block Given the following "activities" exist: | activity | course | name | | forum | C1 | My forum name | - And I log in as "user1" + And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - When I set the field "Edit title" in the "My forum name" "block_social_activities > Activity" to "New forum name" - Then I should not see "My forum name" in the "Social activities" "block" + When I set the field "Edit title" in the "My forum name" "activity" to "New forum name" + Then I should not see "My forum name" And I should see "New forum name" And I follow "New forum name" And I should not see "My forum name" @@ -38,29 +40,102 @@ Feature: Edit activities in social activities block And the following "blocks" exist: | blockname | contextlevel | reference | pagetypepattern | defaultregion | | recent_activity | Course | C1 | course-view-* | side-pre | - And I log in as "user1" + And the following "activity" exists: + | activity | forum | + | course | C1 | + | name | My forum name | + | section | 0 | + And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I press "Add an activity or resource" - And I click on "Add a new Forum" "link" in the "Add an activity or resource" "dialogue" - And I set the field "Forum name" to "My forum name" - And I press "Save and return to course" - When I open "My forum name" actions menu in social activities block + When I open "My forum name" actions menu And I choose "Availability > Make available but don't show on course page" in the open action menu Then I should see "Available but not shown on course page" in the "My forum name" "core_courseformat > Activity visibility" # Make sure that "Availability" dropdown in the edit menu has three options. - And I open "My forum name" actions menu in social activities block - And I click on "Edit settings" "link" in the "My forum name" activity in social activities block + And I open "My forum name" actions menu + And I choose "Edit settings" in the open action menu And I expand all fieldsets And the "Availability" select box should contain "Show on course page" And the "Availability" select box should contain "Hide on course page" And the field "Availability" matches value "Make available but don't show on course page" And I press "Save and return to course" - And "My forum name" activity in social activities block should be available but hidden from course page + Then I should see "Available but not shown on course page" in the "My forum name" "core_courseformat > Activity visibility" And I turn editing mode off - And "My forum name" activity in social activities block should be available but hidden from course page + And I should see "Available but not shown on course page" in the "My forum name" "core_courseformat > Activity visibility" And I log out # Student will not see the module on the course page but can access it from other reports and blocks: When I am on the "Course 1" course page logged in as student1 Then I should not see "My forum name" in the "Social activities" "block" And I click on "My forum name" "link" in the "Recent activity" "block" And I should see "My forum name" in the ".breadcrumb" "css_element" + + @javascript + Scenario: The move activity modal allow to move activities in the social activities block + And the following "activities" exist: + | activity | course | section | name | + | forum | C1 | 0 | My forum name | + | forum | C1 | 0 | Other forum name | + | forum | C1 | 0 | Yet another forum name | + And I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + And I should see "My forum name" in the "Social activities" "block" + And I should see "Other forum name" in the "Social activities" "block" + And I should see "Yet another forum name" in the "Social activities" "block" + And "Other forum name" "activity" should appear after "My forum name" "activity" + And "Yet another forum name" "activity" should appear after "Other forum name" "activity" + When I open "My forum name" actions menu + And I click on "Move" "link" in the "My forum name" activity + And I should see "My forum name" in the "Move activity" "dialogue" + And I should see "Other forum name" in the "Move activity" "dialogue" + And I should see "Yet another forum name" in the "Move activity" "dialogue" + And I should see "Social activities" in the "Move activity" "dialogue" + And I click on "Yet another forum name" "link" in the "Move activity" "dialogue" + Then I should see "My forum name" in the "Social activities" "block" + And I should see "Other forum name" in the "Social activities" "block" + And I should see "Yet another forum name" in the "Social activities" "block" + And "Yet another forum name" "activity" should appear after "Other forum name" "activity" + And "My forum name" "activity" should appear after "Yet another forum name" "activity" + + @javascript + Scenario: Teacher can delete an activity in the social activities block + Given the following "activity" exists: + | activity | forum | + | course | C1 | + | name | My forum name | + | section | 0 | + And I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + When I open "My forum name" actions menu + And I choose "Delete" in the open action menu + And I click on "Delete" "button" in the "Delete activity?" "dialogue" + Then I should not see "My forum name" in the "Social activities" "block" + + @javascript + Scenario: Teacher can duplicate an activity in the social activities block + Given the following "activity" exists: + | activity | forum | + | course | C1 | + | name | My forum name | + | section | 0 | + And I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + When I open "My forum name" actions menu + And I choose "Duplicate" in the open action menu + Then I should see "My forum name" in the "Social activities" "block" + And I should see "My forum name (copy)" in the "Social activities" "block" + And "My forum name (copy)" "activity" should appear after "My forum name" "activity" + + @javascript + Scenario: Teacher can move right and left an activity in the social activities block + Given I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + When I open "Social forum" actions menu + And "Move right" "link" should be visible + And "Move left" "link" should not be visible + And I choose "Move right" in the open action menu + Then I open "Social forum" actions menu + And "Move right" "link" should not be visible + And "Move left" "link" should be visible + And I choose "Move left" in the open action menu + And I open "Social forum" actions menu + And "Move right" "link" should be visible + And "Move left" "link" should not be visible diff --git a/theme/boost/scss/moodle/blocks.scss b/theme/boost/scss/moodle/blocks.scss index 5b5657bb6a176..d17e639b285c5 100644 --- a/theme/boost/scss/moodle/blocks.scss +++ b/theme/boost/scss/moodle/blocks.scss @@ -333,15 +333,6 @@ $blocks-plus-gutter: $blocks-column-width + ( $grid-gutter-width * 0.5 ); color: $text-muted; } -.block_social_activities li a.movehere, -.block_site_main_menu li a.movehere { - display: block; - width: 100%; - height: 2rem; - border: 2px dashed $gray-800; - margin: 4px 0; -} - // // Fake blocks // diff --git a/theme/boost/style/moodle.css b/theme/boost/style/moodle.css index a78947448ab18..1439cc2b25e6f 100644 --- a/theme/boost/style/moodle.css +++ b/theme/boost/style/moodle.css @@ -27353,15 +27353,6 @@ aside[id^=block-region-side-] .block_recentlyaccesseditems .card:nth-of-type(n+4 color: #6a737b; } -.block_social_activities li a.movehere, -.block_site_main_menu li a.movehere { - display: block; - width: 100%; - height: 2rem; - border: 2px dashed #343a40; - margin: 4px 0; -} - .pagelayout-embedded .has-fake-blocks { padding: 1rem; display: flex; diff --git a/theme/classic/style/moodle.css b/theme/classic/style/moodle.css index 73d9e67395d0c..d8c203a45f70f 100644 --- a/theme/classic/style/moodle.css +++ b/theme/classic/style/moodle.css @@ -27353,15 +27353,6 @@ aside[id^=block-region-side-] .block_recentlyaccesseditems .card:nth-of-type(n+4 color: #6a737b; } -.block_social_activities li a.movehere, -.block_site_main_menu li a.movehere { - display: block; - width: 100%; - height: 2rem; - border: 2px dashed #343a40; - margin: 4px 0; -} - .pagelayout-embedded .has-fake-blocks { padding: 1rem; display: flex;