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 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 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
            instance: this.instance,
44
            users: this.getMatchedResults().slice(0, 5),
45
            hasresults: this.getMatchedResults().length > 0,
46
            searchterm: this.getSearchTerm(),
47
        });
48
        replaceNodeContents(this.getHTMLElements().searchDropdown, html, js);
49
        // Remove aria-activedescendant when the available options change.
50
        this.searchInput.removeAttribute('aria-activedescendant');
51
    }
52
 
53
    /**
54
     * Stub out default required function unused here.
55
     * @returns {null}
56
     */
57
    selectAllResultsLink() {
58
        return null;
59
    }
60
 
61
    /**
62
     * Build up the view all link that is dedicated to a particular result.
63
     *
64
     * @param {Number} userID The ID of the user selected.
65
     * @returns {string|*}
66
     */
67
    selectOneLink(userID) {
68
        return Url.relativeUrl('/grade/report/singleview/index.php', {
69
            id: this.courseID,
70
            searchvalue: this.getSearchTerm(),
71
            item: 'user',
72
            userid: userID,
73
        }, false);
74
    }
75
 
76
    /**
77
     * Get the data we will be searching against in this component.
78
     *
79
     * @returns {Promise<*>}
80
     */
81
    fetchDataset() {
82
        // Small typing checks as sometimes groups don't exist therefore the element returns a empty string.
83
        const gts = typeof (this.groupID) === "string" && this.groupID === '' ? 0 : this.groupID;
84
        return Repository.userFetch(this.courseID, gts).then((r) => r.users);
85
    }
86
}