marinaglancy / moodle-format_flexsections

25 stars 25 forks source link

Subsections are skipped in course index highlighting #47

Closed HSOtago closed 1 year ago

HSOtago commented 1 year ago

Hi there,

As the title suggests, take a look at the video below - this can be quite disorienting for our users.

https://user-images.githubusercontent.com/127059146/222991306-cc99b518-e279-4a62-b4db-83f1e6717a95.mp4

Thanks, Harry

luttje commented 1 year ago

In lieu of making a PR I can provide this fix:

  1. Add this method to {flexsections plugin dir}/amd/src/local/courseeditor/exporter.js:

    /**
     * Return a sorted list of all sections and cms items in the state.
     *
     * @param {Object} state the current state.
     * @returns {Array} all sections and cms items in the state.
     */
    allItemsArray(state) {
        const items = [];
        const sectionlist = state.course.sectionlist ?? [];
    
        const addCms = (sectioninfo) => {
            const cmlist = sectioninfo.cmlist ?? [];
            cmlist.forEach(cmid => {
                const cminfo = state.cm.get(cmid);
                items.push({type: 'cm', id: cminfo.id, url: cminfo.url});
            });
        };
        const addChildItems = (children) => {
            if (children && children.length) {
                for (let i = 0; i < children.length; i++) {
                    const child = children[i];
                    items.push({type: 'section', id: child.id, url: child.sectionurl});
                    addCms(child);
                    addChildItems(child.children);
                }
            }
        };
        sectionlist.forEach(sectionid => {
            const sectioninfo = state.section.get(sectionid);
            items.push({type: 'section', id: sectioninfo.id, url: sectioninfo.sectionurl});
            addCms(sectioninfo);
            addChildItems(sectioninfo.children);
        });
        return items;
    }
  2. Run grunt amd inside the plugin {flexsections plugin dir}/amd directory (make sure you ran npm install in moodle's root)

firefox_rRuvCeJIOV

HSOtago commented 1 year ago

Thanks very much @luttje that is incredibly useful.

marinaglancy commented 1 year ago

Thank you very much for the patch, @luttje , It has been added to version 4.0.5 (2023-08-08) . I'm going to close this issue as resolved. Thanks