reportbuilder/amd/src/local/repository/conditions.js

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