Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// This file is part of Moodle - http://moodle.org/
2
//
3
// Moodle is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// Moodle is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
/**
17
 * Allow the user to search for learners within the singleview report.
18
 *
19
 * @module    gradereport_singleview/user
20
 * @copyright 2023 Mathew May <mathew.solutions>
21
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
import UserSearch from 'core_user/comboboxsearch/user';
24
import {renderForPromise, replaceNodeContents} from 'core/templates';
25
import * as Repository from 'core_grades/searchwidget/repository';
26
 
27
export default class User extends UserSearch {
28
 
1441 ariadna 29
    /**
30
     * Construct the class.
31
     *
32
     * @param {string} baseUrl The base URL for the page.
33
     */
34
    constructor(baseUrl) {
1 efrain 35
        super();
1441 ariadna 36
        this.baseUrl = baseUrl;
1 efrain 37
    }
38
 
1441 ariadna 39
    static init(baseUrl) {
40
        return new User(baseUrl);
1 efrain 41
    }
42
 
43
    /**
44
     * Build the content then replace the node.
45
     */
46
    async renderDropdown() {
47
        const {html, js} = await renderForPromise('core_user/comboboxsearch/resultset', {
48
            instance: this.instance,
49
            users: this.getMatchedResults().slice(0, 5),
50
            hasresults: this.getMatchedResults().length > 0,
51
            searchterm: this.getSearchTerm(),
52
        });
53
        replaceNodeContents(this.getHTMLElements().searchDropdown, html, js);
54
        // Remove aria-activedescendant when the available options change.
55
        this.searchInput.removeAttribute('aria-activedescendant');
56
    }
57
 
58
    /**
59
     * Stub out default required function unused here.
60
     * @returns {null}
61
     */
62
    selectAllResultsLink() {
63
        return null;
64
    }
65
 
66
    /**
67
     * Build up the view all link that is dedicated to a particular result.
68
     *
69
     * @param {Number} userID The ID of the user selected.
70
     * @returns {string|*}
71
     */
72
    selectOneLink(userID) {
1441 ariadna 73
        const url = new URL(this.baseUrl);
74
        url.searchParams.set('searchvalue', this.getSearchTerm());
75
        url.searchParams.set('item', 'user');
76
        url.searchParams.set('userid', userID);
77
        return url.toString();
1 efrain 78
    }
79
 
80
    /**
81
     * Get the data we will be searching against in this component.
82
     *
83
     * @returns {Promise<*>}
84
     */
85
    fetchDataset() {
86
        // Small typing checks as sometimes groups don't exist therefore the element returns a empty string.
87
        const gts = typeof (this.groupID) === "string" && this.groupID === '' ? 0 : this.groupID;
88
        return Repository.userFetch(this.courseID, gts).then((r) => r.users);
89
    }
90
}