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 grader report.
18
 *
19
 * @module    gradereport_grader/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 * as Repository from 'gradereport_grader/local/user/repository';
25
 
26
// Define our standard lookups.
27
const selectors = {
28
    component: '.user-search',
29
    courseid: '[data-region="courseid"]',
30
};
31
const component = document.querySelector(selectors.component);
32
const courseID = component.querySelector(selectors.courseid).dataset.courseid;
33
 
34
export default class User extends UserSearch {
35
 
1441 ariadna 36
    /**
37
     * Construct the class.
38
     * @param {string} baseUrl The base URL for the page.
39
     */
40
    constructor(baseUrl) {
1 efrain 41
        super();
1441 ariadna 42
        this.baseUrl = baseUrl;
1 efrain 43
    }
44
 
1441 ariadna 45
    static init(baseUrl) {
46
        return new User(baseUrl);
1 efrain 47
    }
48
 
49
    /**
50
     * Get the data we will be searching against in this component.
51
     *
52
     * @returns {Promise<*>}
53
     */
54
    fetchDataset() {
55
        return Repository.userFetch(courseID).then((r) => r.users);
56
    }
57
 
58
    /**
59
     * Build up the view all link.
60
     *
61
     * @returns {string|*}
62
     */
63
    selectAllResultsLink() {
1441 ariadna 64
        const url = new URL(this.baseUrl);
65
        url.searchParams.set('gpr_search', this.getSearchTerm());
66
        return url.toString();
1 efrain 67
    }
68
 
69
    /**
70
     * Build up the link that is dedicated to a particular result.
71
     *
72
     * @param {Number} userID The ID of the user selected.
73
     * @returns {string|*}
74
     */
75
    selectOneLink(userID) {
1441 ariadna 76
        const url = new URL(this.baseUrl);
77
        url.searchParams.set('gpr_search', this.getSearchTerm());
78
        url.searchParams.set('gpr_userid', userID);
79
        return url.toString();
1 efrain 80
    }
81
}