Proyectos de Subversion Moodle

Rev

| 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 user report.
18
 *
19
 * @module    gradereport_user/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 Url from 'core/url';
25
import {renderForPromise, replaceNodeContents} from 'core/templates';
26
import * as Repository from 'core_grades/searchwidget/repository';
27
 
28
export default class User extends UserSearch {
29
 
30
    constructor() {
31
        super();
32
    }
33
 
34
    static init() {
35
        return new User();
36
    }
37
 
38
    /**
39
     * Build the content then replace the node.
40
     */
41
    async renderDropdown() {
42
        const {html, js} = await renderForPromise('core_user/comboboxsearch/resultset', {
43
            users: this.getMatchedResults().slice(0, 5),
44
            hasresults: this.getMatchedResults().length > 0,
45
            instance: this.instance,
46
            matches: this.getDatasetSize(),
47
            searchterm: this.getSearchTerm(),
48
            selectall: this.selectAllResultsLink(),
49
        });
50
        replaceNodeContents(this.getHTMLElements().searchDropdown, html, js);
51
        // Remove aria-activedescendant when the available options change.
52
        this.searchInput.removeAttribute('aria-activedescendant');
53
    }
54
 
55
    /**
56
     * Build up the view all link.
57
     *
58
     * @returns {string|*}
59
     */
60
    selectAllResultsLink() {
61
        return Url.relativeUrl('/grade/report/user/index.php', {
62
            id: this.courseID,
63
            userid: 0,
64
            searchvalue: this.getSearchTerm()
65
        }, false);
66
    }
67
 
68
    /**
69
     * Build up the link that is dedicated to a particular result.
70
     *
71
     * @param {Number} userID The ID of the user selected.
72
     * @returns {string|*}
73
     */
74
    selectOneLink(userID) {
75
        return Url.relativeUrl('/grade/report/user/index.php', {
76
            id: this.courseID,
77
            searchvalue: this.getSearchTerm(),
78
            userid: userID,
79
        }, false);
80
    }
81
 
82
    /**
83
     * Get the data we will be searching against in this component.
84
     *
85
     * @returns {Promise<*>}
86
     */
87
    fetchDataset() {
88
        // Small typing checks as sometimes groups don't exist therefore the element returns a empty string.
89
        const gts = typeof (this.groupID) === "string" && this.groupID === '' ? 0 : this.groupID;
90
        return Repository.userFetch(this.courseID, gts).then((r) => r.users);
91
    }
92
}