| 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 |  * Module to handle condition AJAX requests
 | 
        
           |  |  | 18 |  *
 | 
        
           |  |  | 19 |  * @module      core_reportbuilder/local/repository/conditions
 | 
        
           |  |  | 20 |  * @copyright   2021 Paul Holden <paulh@moodle.com>
 | 
        
           |  |  | 21 |  * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 22 |  */
 | 
        
           |  |  | 23 |   | 
        
           |  |  | 24 | import Ajax from 'core/ajax';
 | 
        
           |  |  | 25 |   | 
        
           |  |  | 26 | /**
 | 
        
           |  |  | 27 |  * Reset all conditions for given report
 | 
        
           |  |  | 28 |  *
 | 
        
           |  |  | 29 |  * @param {Number} reportId
 | 
        
           |  |  | 30 |  * @return {Promise}
 | 
        
           |  |  | 31 |  */
 | 
        
           |  |  | 32 | export const resetConditions = reportId => {
 | 
        
           |  |  | 33 |     const request = {
 | 
        
           |  |  | 34 |         methodname: 'core_reportbuilder_conditions_reset',
 | 
        
           |  |  | 35 |         args: {reportid: reportId}
 | 
        
           |  |  | 36 |     };
 | 
        
           |  |  | 37 |   | 
        
           |  |  | 38 |     return Ajax.call([request])[0];
 | 
        
           |  |  | 39 | };
 | 
        
           |  |  | 40 |   | 
        
           |  |  | 41 | /**
 | 
        
           |  |  | 42 |  * Add condition to given report
 | 
        
           |  |  | 43 |  *
 | 
        
           |  |  | 44 |  * @param {Number} reportId
 | 
        
           |  |  | 45 |  * @param {String} uniqueIdentifier
 | 
        
           |  |  | 46 |  * @return {Promise}
 | 
        
           |  |  | 47 |  */
 | 
        
           |  |  | 48 | export const addCondition = (reportId, uniqueIdentifier) => {
 | 
        
           |  |  | 49 |     const request = {
 | 
        
           |  |  | 50 |         methodname: 'core_reportbuilder_conditions_add',
 | 
        
           |  |  | 51 |         args: {reportid: reportId, uniqueidentifier: uniqueIdentifier}
 | 
        
           |  |  | 52 |     };
 | 
        
           |  |  | 53 |   | 
        
           |  |  | 54 |     return Ajax.call([request])[0];
 | 
        
           |  |  | 55 | };
 | 
        
           |  |  | 56 |   | 
        
           |  |  | 57 | /**
 | 
        
           |  |  | 58 |  * Remove condition from given report
 | 
        
           |  |  | 59 |  *
 | 
        
           |  |  | 60 |  * @param {Number} reportId
 | 
        
           |  |  | 61 |  * @param {Number} conditionId
 | 
        
           |  |  | 62 |  * @return {Promise}
 | 
        
           |  |  | 63 |  */
 | 
        
           |  |  | 64 | export const deleteCondition = (reportId, conditionId) => {
 | 
        
           |  |  | 65 |     const request = {
 | 
        
           |  |  | 66 |         methodname: 'core_reportbuilder_conditions_delete',
 | 
        
           |  |  | 67 |         args: {reportid: reportId, conditionid: conditionId}
 | 
        
           |  |  | 68 |     };
 | 
        
           |  |  | 69 |   | 
        
           |  |  | 70 |     return Ajax.call([request])[0];
 | 
        
           |  |  | 71 | };
 | 
        
           |  |  | 72 |   | 
        
           |  |  | 73 | /**
 | 
        
           |  |  | 74 |  * Reorder a condition in a given report
 | 
        
           |  |  | 75 |  *
 | 
        
           |  |  | 76 |  * @param {Number} reportId
 | 
        
           |  |  | 77 |  * @param {Number} conditionId
 | 
        
           |  |  | 78 |  * @param {Number} position
 | 
        
           |  |  | 79 |  * @return {Promise}
 | 
        
           |  |  | 80 |  */
 | 
        
           |  |  | 81 | export const reorderCondition = (reportId, conditionId, position) => {
 | 
        
           |  |  | 82 |     const request = {
 | 
        
           |  |  | 83 |         methodname: 'core_reportbuilder_conditions_reorder',
 | 
        
           |  |  | 84 |         args: {reportid: reportId, conditionid: conditionId, position: position}
 | 
        
           |  |  | 85 |     };
 | 
        
           |  |  | 86 |   | 
        
           |  |  | 87 |     return Ajax.call([request])[0];
 | 
        
           |  |  | 88 | };
 |