From c5578db866367b2ec43ef84d514cba87d90f0d2b Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Wed, 11 Aug 2021 10:51:36 +0200 Subject: [PATCH] MDL-72310 core_course: Expand course index sections by default --- .../build/local/courseeditor/exporter.min.js | 2 +- .../local/courseeditor/exporter.min.js.map | 2 +- .../amd/src/local/courseeditor/exporter.js | 2 +- .../tests/behat/course_courseindex.feature | 37 ++++++++++++++----- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/course/format/amd/build/local/courseeditor/exporter.min.js b/course/format/amd/build/local/courseeditor/exporter.min.js index 7f492602506..e0be958ab49 100644 --- a/course/format/amd/build/local/courseeditor/exporter.min.js +++ b/course/format/amd/build/local/courseeditor/exporter.min.js @@ -1,2 +1,2 @@ -define ("core_courseformat/local/courseeditor/exporter",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;function b(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);if(b)d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable});c.push.apply(c,d)}return c}function c(a){for(var c=1,e;c.\n\n/**\n * Module to export parts of the state and transform them to be used in templates\n * and as draggable data.\n *\n * @module core_courseformat/local/courseeditor/exporter\n * @class core_courseformat/local/courseeditor/exporter\n * @copyright 2021 Ferran Recio \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default class {\n\n /**\n * Class constructor.\n *\n * @param {CourseEditor} reactive the course editor object\n */\n constructor(reactive) {\n this.reactive = reactive;\n }\n\n /**\n * Generate the course export data from the state.\n *\n * @param {Object} state the current state.\n * @returns {Object}\n */\n course(state) {\n // Collect section information from the state.\n const data = {\n sections: [],\n editmode: this.reactive.isEditing,\n };\n const sectionlist = state.course.sectionlist ?? [];\n sectionlist.forEach(sectionid => {\n const sectioninfo = state.section.get(sectionid) ?? {};\n const section = this.section(state, sectioninfo);\n data.sections.push(section);\n });\n data.hassections = (data.sections.length != 0);\n\n return data;\n }\n\n /**\n * Generate a section export data from the state.\n *\n * @param {Object} state the current state.\n * @param {Object} sectioninfo the section state data.\n * @returns {Object}\n */\n section(state, sectioninfo) {\n const section = {\n ...sectioninfo,\n cms: [],\n isactive: false,\n };\n const cmlist = sectioninfo.cmlist ?? [];\n cmlist.forEach(cmid => {\n const cminfo = state.cm.get(cmid);\n const cm = this.cm(state, cminfo);\n section.cms.push(cm);\n });\n section.hascms = (section.cms.length != 0);\n\n return section;\n }\n\n /**\n * Generate a cm export data from the state.\n *\n * @param {Object} state the current state.\n * @param {Object} cminfo the course module state data.\n * @returns {Object}\n */\n cm(state, cminfo) {\n const cm = {\n ...cminfo,\n isactive: false,\n };\n return cm;\n }\n}\n"],"file":"exporter.min.js"} \ No newline at end of file +{"version":3,"sources":["../../../src/local/courseeditor/exporter.js"],"names":["reactive","state","data","sections","editmode","isEditing","sectionlist","course","forEach","sectionid","sectioninfo","section","get","push","hassections","length","cms","isactive","cmlist","cmid","cminfo","cm","hascms"],"mappings":"4rCA+BI,WAAYA,CAAZ,CAAsB,WAClB,KAAKA,QAAL,CAAgBA,CACnB,C,yCAQMC,C,CAAO,cAEJC,CAAI,CAAG,CACTC,QAAQ,CAAE,EADD,CAETC,QAAQ,CAAE,KAAKJ,QAAL,CAAcK,SAFf,CAFH,CAMJC,CAAW,WAAGL,CAAK,CAACM,MAAN,CAAaD,WAAhB,gBAA+B,EANtC,CAOVA,CAAW,CAACE,OAAZ,CAAoB,SAAAC,CAAS,CAAI,OACvBC,CAAW,WAAGT,CAAK,CAACU,OAAN,CAAcC,GAAd,CAAkBH,CAAlB,CAAH,gBAAmC,EADvB,CAEvBE,CAAO,CAAG,CAAI,CAACA,OAAL,CAAaV,CAAb,CAAoBS,CAApB,CAFa,CAG7BR,CAAI,CAACC,QAAL,CAAcU,IAAd,CAAmBF,CAAnB,CACH,CAJD,EAKAT,CAAI,CAACY,WAAL,CAA4C,CAAxB,EAAAZ,CAAI,CAACC,QAAL,CAAcY,MAAlC,CAEA,MAAOb,CAAAA,CACV,C,gCASOD,C,CAAOS,C,CAAa,cAClBC,CAAO,MACND,CADM,EAETM,GAAG,CAAE,EAFI,CAGTC,QAAQ,GAHC,EADW,CAMlBC,CAAM,WAAGR,CAAW,CAACQ,MAAf,gBAAyB,EANb,CAOxBA,CAAM,CAACV,OAAP,CAAe,SAAAW,CAAI,CAAI,IACbC,CAAAA,CAAM,CAAGnB,CAAK,CAACoB,EAAN,CAAST,GAAT,CAAaO,CAAb,CADI,CAEbE,CAAE,CAAG,CAAI,CAACA,EAAL,CAAQpB,CAAR,CAAemB,CAAf,CAFQ,CAGnBT,CAAO,CAACK,GAAR,CAAYH,IAAZ,CAAiBQ,CAAjB,CACH,CAJD,EAKAV,CAAO,CAACW,MAAR,CAAwC,CAAtB,EAAAX,CAAO,CAACK,GAAR,CAAYD,MAA9B,CAEA,MAAOJ,CAAAA,CACV,C,2BASEV,C,CAAOmB,C,CAAQ,CACd,GAAMC,CAAAA,CAAE,MACDD,CADC,EAEJH,QAAQ,GAFJ,EAAR,CAIA,MAAOI,CAAAA,CACV,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Module to export parts of the state and transform them to be used in templates\n * and as draggable data.\n *\n * @module core_courseformat/local/courseeditor/exporter\n * @class core_courseformat/local/courseeditor/exporter\n * @copyright 2021 Ferran Recio \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default class {\n\n /**\n * Class constructor.\n *\n * @param {CourseEditor} reactive the course editor object\n */\n constructor(reactive) {\n this.reactive = reactive;\n }\n\n /**\n * Generate the course export data from the state.\n *\n * @param {Object} state the current state.\n * @returns {Object}\n */\n course(state) {\n // Collect section information from the state.\n const data = {\n sections: [],\n editmode: this.reactive.isEditing,\n };\n const sectionlist = state.course.sectionlist ?? [];\n sectionlist.forEach(sectionid => {\n const sectioninfo = state.section.get(sectionid) ?? {};\n const section = this.section(state, sectioninfo);\n data.sections.push(section);\n });\n data.hassections = (data.sections.length != 0);\n\n return data;\n }\n\n /**\n * Generate a section export data from the state.\n *\n * @param {Object} state the current state.\n * @param {Object} sectioninfo the section state data.\n * @returns {Object}\n */\n section(state, sectioninfo) {\n const section = {\n ...sectioninfo,\n cms: [],\n isactive: true,\n };\n const cmlist = sectioninfo.cmlist ?? [];\n cmlist.forEach(cmid => {\n const cminfo = state.cm.get(cmid);\n const cm = this.cm(state, cminfo);\n section.cms.push(cm);\n });\n section.hascms = (section.cms.length != 0);\n\n return section;\n }\n\n /**\n * Generate a cm export data from the state.\n *\n * @param {Object} state the current state.\n * @param {Object} cminfo the course module state data.\n * @returns {Object}\n */\n cm(state, cminfo) {\n const cm = {\n ...cminfo,\n isactive: false,\n };\n return cm;\n }\n}\n"],"file":"exporter.min.js"} \ No newline at end of file diff --git a/course/format/amd/src/local/courseeditor/exporter.js b/course/format/amd/src/local/courseeditor/exporter.js index 80b9ebf18b4..c76d076d958 100644 --- a/course/format/amd/src/local/courseeditor/exporter.js +++ b/course/format/amd/src/local/courseeditor/exporter.js @@ -67,7 +67,7 @@ export default class { const section = { ...sectioninfo, cms: [], - isactive: false, + isactive: true, }; const cmlist = sectioninfo.cmlist ?? []; cmlist.forEach(cmid => { diff --git a/course/format/tests/behat/course_courseindex.feature b/course/format/tests/behat/course_courseindex.feature index 4d1399eb757..1a6162f3231 100644 --- a/course/format/tests/behat/course_courseindex.feature +++ b/course/format/tests/behat/course_courseindex.feature @@ -36,9 +36,6 @@ Feature: Course index depending on role And I am on "Course 1" course homepage And I click on "Side panel" "button" When I click on "Open course index drawer" "button" - And I click on "Topic 1" "link" in the "courseindex-content" "region" - And I click on "Topic 2" "link" in the "courseindex-content" "region" - And I click on "Topic 3" "link" in the "courseindex-content" "region" Then I should see "Topic 1" in the "courseindex-content" "region" And I should see "Topic 2" in the "courseindex-content" "region" And I should see "Topic 3" in the "courseindex-content" "region" @@ -58,9 +55,6 @@ Feature: Course index depending on role And I am on "Course 1" course homepage And I click on "Side panel" "button" When I click on "Open course index drawer" "button" - And I click on "Topic 1" "link" in the "courseindex-content" "region" - And I click on "Topic 2" "link" in the "courseindex-content" "region" - And I click on "Topic 3" "link" in the "courseindex-content" "region" Then I should see "Topic 1" in the "courseindex-content" "region" And I should see "Topic 2" in the "courseindex-content" "region" And I should see "Topic 3" in the "courseindex-content" "region" @@ -80,8 +74,6 @@ Feature: Course index depending on role And I am on "Course 1" course homepage And I click on "Side panel" "button" When I click on "Open course index drawer" "button" - And I click on "Topic 1" "link" in the "courseindex-content" "region" - And I click on "Topic 3" "link" in the "courseindex-content" "region" Then I should see "Topic 1" in the "courseindex-content" "region" And I should not see "Topic 2" in the "courseindex-content" "region" And I should see "Topic 3" in the "courseindex-content" "region" @@ -96,8 +88,6 @@ Feature: Course index depending on role And I click on "Side panel" "button" When I delete "Activity sample 2" activity And I click on "Open course index drawer" "button" - And I click on "Topic 1" "link" in the "courseindex-content" "region" - And I click on "Topic 2" "link" in the "courseindex-content" "region" Then I should not see "Activity sample 2" in the "courseindex-content" "region" @javascript @@ -112,3 +102,30 @@ Feature: Course index depending on role And I click on "Open course index drawer" "button" # Current section is only marked visually in the course index. Then the "class" attribute of "#courseindex-content [data-for='section'][data-number='1']" "css_element" should contain "current" + + @javascript + Scenario: Course index toggling + Given the following "activities" exist: + | activity | name | intro | course | idnumber | section | + | book | Second activity in section 1 | Test book description | C1 | sample4 | 1 | + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I click on "Side panel" "button" + When I click on "Open course index drawer" "button" + Then I should see "Topic 1" in the "courseindex-content" "region" + And I should see "Activity sample 1" in the "courseindex-content" "region" + And I should see "Second activity in section 1" in the "courseindex-content" "region" + And I click on "Topic 1" "link" in the "courseindex-content" "region" + And I should not see "Activity sample 1" in the "courseindex-content" "region" + And I should not see "Second activity in section 1" in the "courseindex-content" "region" + And I should see "Topic 2" in the "courseindex-content" "region" + And I should see "Activity sample 2" in the "courseindex-content" "region" + And I click on "Topic 2" "link" in the "courseindex-content" "region" + And I should not see "Activity sample 2" in the "courseindex-content" "region" + And I should see "Topic 3" in the "courseindex-content" "region" + And I should see "Activity sample 3" in the "courseindex-content" "region" + And I click on "Topic 3" "link" in the "courseindex-content" "region" + And I should not see "Activity sample 3" in the "courseindex-content" "region" + And I should not see "Activity sample 1" in the "courseindex-content" "region" + And I should not see "Second activity in section 1" in the "courseindex-content" "region" + And I should not see "Activity sample 2" in the "courseindex-content" "region"