question/bank/columnsortorder/amd/src/repository.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. * External function calls for qbank_columnsortorder
  17. *
  18. * @module qbank_columnsortorder/repository
  19. * @copyright 2023 Catalyst IT Europe Ltd.
  20. * @author Mark Johnson <mark.johnson@catalyst-eu.net>
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. import {call as fetchMany} from 'core/ajax';
  24. /**
  25. * Save the list of hidden columns
  26. *
  27. * @param {String[]} columns List of hidden column names
  28. * @param {Boolean} global Set global config setting, rather than user preference
  29. * @return {Promise}
  30. */
  31. export const setHiddenColumns = (columns, global = false) => fetchMany([{
  32. methodname: 'qbank_columnsortorder_set_hidden_columns',
  33. args: {
  34. columns,
  35. global,
  36. },
  37. }])[0];
  38. /**
  39. * Save the order of columns
  40. *
  41. * @param {String[]} columns List of column names in the desired order
  42. * @param {Boolean} global Set global config setting, rather than user preference
  43. * @return {Promise}
  44. */
  45. export const setColumnbankOrder = (columns, global = false) => fetchMany([{
  46. methodname: 'qbank_columnsortorder_set_columnbank_order',
  47. args: {
  48. columns,
  49. global,
  50. },
  51. }])[0];
  52. /**
  53. * Save the column widths
  54. *
  55. * @param {String} sizes JSON string encoding an array of objects with "column" and "width" properties.
  56. * @param {Boolean} global Set global config setting, rather than user preference
  57. * @return {Promise}
  58. */
  59. export const setColumnSize = (sizes, global = false) => fetchMany([{
  60. methodname: 'qbank_columnsortorder_set_column_size',
  61. args: {
  62. sizes,
  63. global,
  64. },
  65. }])[0];
  66. /**
  67. * Reset all settings.
  68. *
  69. * @param {Boolean} global Reset global config settings, rather than user preference
  70. * @return {Promise}
  71. */
  72. export const resetColumns = (global = false) => Promise.all(
  73. fetchMany([
  74. {
  75. methodname: 'qbank_columnsortorder_set_column_size',
  76. args: {
  77. global,
  78. },
  79. },
  80. {
  81. methodname: 'qbank_columnsortorder_set_columnbank_order',
  82. args: {
  83. global,
  84. },
  85. },
  86. {
  87. methodname: 'qbank_columnsortorder_set_hidden_columns',
  88. args: {
  89. global,
  90. },
  91. },
  92. ])
  93. );