diff --git a/reportbuilder/amd/build/local/editor/conditions.min.js b/reportbuilder/amd/build/local/editor/conditions.min.js index fbe2f5f946f..f109170f5dc 100644 --- a/reportbuilder/amd/build/local/editor/conditions.min.js +++ b/reportbuilder/amd/build/local/editor/conditions.min.js @@ -1,2 +1,2 @@ -function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_reportbuilder/local/editor/conditions",["exports","jquery","core/event_dispatcher","core/inplace_editable","core/notification","core/pending","core/sortable_list","core/str","core/templates","core/toast","core_form/dynamicform","core_reportbuilder/local/events","core_reportbuilder/local/selectors","core_reportbuilder/local/repository/conditions"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=q(b);e=q(e);f=q(f);g=q(g);i=q(i);k=q(k);l=p(l);m=p(m);function o(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;o=function(){return a};return a}function p(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=o();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function q(a){return a&&a.__esModule?a:{default:a}}function r(a,b){return w(a)||v(a,b)||t(a,b)||s()}function s(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function t(a,b){if(!a)return;if("string"==typeof a)return u(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return u(a,b)}function u(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);ck){o--}(0,n.reorderCondition)(g.dataset.reportId,i,o).then(function(a){return x(g,a)}).then(function(){return(0,h.get_string)("conditionmoved","core_reportbuilder",b.element.data("conditionName"))}).then(j.add).then(function(){(0,c.dispatchEvent)(l.tableReload,{},g);return d.resolve()}).catch(e.default.exception)}})};a.init=z}); +function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core_reportbuilder/local/editor/conditions",["exports","jquery","core/event_dispatcher","core/inplace_editable","core/notification","core/pending","core/sortable_list","core/str","core/templates","core/toast","core_form/dynamicform","core_reportbuilder/local/events","core_reportbuilder/local/selectors","core_reportbuilder/local/repository/conditions"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=q(b);e=q(e);f=q(f);g=q(g);i=q(i);k=q(k);l=p(l);m=p(m);function o(){if("function"!=typeof WeakMap)return null;var a=new WeakMap;o=function(){return a};return a}function p(a){if(a&&a.__esModule){return a}if(null===a||"object"!==_typeof(a)&&"function"!=typeof a){return{default:a}}var b=o();if(b&&b.has(a)){return b.get(a)}var c={},d=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var e in a){if(Object.prototype.hasOwnProperty.call(a,e)){var f=d?Object.getOwnPropertyDescriptor(a,e):null;if(f&&(f.get||f.set)){Object.defineProperty(c,e,f)}else{c[e]=a[e]}}}c.default=a;if(b){b.set(a,c)}return c}function q(a){return a&&a.__esModule?a:{default:a}}function r(a,b){return w(a)||v(a,b)||t(a,b)||s()}function s(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function t(a,b){if(!a)return;if("string"==typeof a)return u(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return u(a,b)}function u(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);ck){o--}(0,n.reorderCondition)(g.dataset.reportId,i,o).then(function(a){return x(g,a)}).then(function(){return(0,h.get_string)("conditionmoved","core_reportbuilder",b.element.data("conditionName"))}).then(j.add).then(function(){(0,c.dispatchEvent)(l.tableReload,{},g);return d.resolve()}).catch(e.default.exception)}})};a.init=z}); //# sourceMappingURL=conditions.min.js.map diff --git a/reportbuilder/amd/build/local/editor/conditions.min.js.map b/reportbuilder/amd/build/local/editor/conditions.min.js.map index 7b7d34ac29d..3c520f42ab2 100644 --- a/reportbuilder/amd/build/local/editor/conditions.min.js.map +++ b/reportbuilder/amd/build/local/editor/conditions.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../../src/local/editor/conditions.js"],"names":["reloadSettingsConditionsRegion","reportElement","templateContext","pendingPromise","Pending","settingsConditionsRegion","querySelector","reportSelectors","regions","settingsConditions","Templates","renderForPromise","conditions","then","html","js","replaceNode","javascript","initConditionsForm","resolve","document","report","conditionFormContainer","conditionForm","DynamicForm","addEventListener","events","FORM_SUBMITTED","event","preventDefault","addToast","catch","Notification","exception","reportEvents","tableReload","NOSUBMIT_BUTTON_PRESSED","dataset","reportId","data","init","initialized","reportAddCondition","target","closest","actions","value","options","selectedIndex","text","reportRemoveCondition","conditionContainer","activeCondition","conditionName","key","component","param","confirmTitle","confirmText","confirmButton","confirm","conditionId","activeConditionsSortableList","SortableList","activeConditions","isHorizontal","getElementName","element","Promise","on","EVENTS","DROP","info","positionChanged","conditionPosition","targetConditionPosition","targetN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I,CAACC,eAAT,CAA0B,IAChBtE,CAAAA,CAAc,CAAG,GAAIC,UAAJ,CAAY,uCAAZ,CADD,CAEhBH,CAAa,CAAG2B,CAAK,CAACe,MAAN,CAAaC,OAAb,CAAqBrC,CAAe,CAACC,OAAhB,CAAwBa,MAA7C,CAFA,CAGhBwC,CAAW,CAAGW,CAAI,CAACL,OAAL,CAAa5B,IAAb,CAAkB,aAAlB,CAHE,CAIhBmC,CAAiB,CAAGF,CAAI,CAACL,OAAL,CAAa5B,IAAb,CAAkB,mBAAlB,CAJJ,CAOlBoC,CAAuB,CAAGH,CAAI,CAACI,iBAAL,CAAuBrC,IAAvB,CAA4B,mBAA5B,GAAoDiC,CAAI,CAACL,OAAL,CAAaU,QAAb,GAAwBC,MAAxB,CAAiC,CAP7F,CAQtB,GAAIH,CAAuB,CAAGD,CAA9B,CAAiD,CAC7CC,CAAuB,EAC1B,CAED,uBAAiB1E,CAAa,CAACoC,OAAd,CAAsBC,QAAvC,CAAiDuB,CAAjD,CAA8Dc,CAA9D,EACK9D,IADL,CACU,SAAA0B,CAAI,QAAIvC,CAAAA,CAA8B,CAACC,CAAD,CAAgBsC,CAAhB,CAAlC,CADd,EAEK1B,IAFL,CAEU,iBAAM,iBAAU,gBAAV,CAA4B,oBAA5B,CAAkD2D,CAAI,CAACL,OAAL,CAAa5B,IAAb,CAAkB,eAAlB,CAAlD,CAAN,CAFV,EAGK1B,IAHL,CAGUiB,KAHV,EAIKjB,IAJL,CAIU,UAAM,CACR,oBAAcqB,CAAY,CAACC,WAA3B,CAAwC,EAAxC,CAA4ClC,CAA5C,EACA,MAAOE,CAAAA,CAAc,CAACgB,OAAf,EACV,CAPL,EAQKY,KARL,CAQWC,UAAaC,SARxB,CASH,CACJ,CAvBD,CAwBH,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Report builder conditions editor\n *\n * @module core_reportbuilder/local/editor/conditions\n * @copyright 2021 Paul Holden \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\"use strict\";\n\nimport $ from 'jquery';\nimport {dispatchEvent} from 'core/event_dispatcher';\nimport 'core/inplace_editable';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport SortableList from 'core/sortable_list';\nimport {get_string as getString, get_strings as getStrings} from 'core/str';\nimport Templates from 'core/templates';\nimport {add as addToast} from 'core/toast';\nimport DynamicForm from 'core_form/dynamicform';\nimport * as reportEvents from 'core_reportbuilder/local/events';\nimport * as reportSelectors from 'core_reportbuilder/local/selectors';\nimport {addCondition, deleteCondition, reorderCondition, resetConditions} from 'core_reportbuilder/local/repository/conditions';\n\n/**\n * Reload conditions settings region\n *\n * @param {Element} reportElement\n * @param {Object} templateContext\n * @return {Promise}\n */\nconst reloadSettingsConditionsRegion = (reportElement, templateContext) => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reload');\n const settingsConditionsRegion = reportElement.querySelector(reportSelectors.regions.settingsConditions);\n\n return Templates.renderForPromise('core_reportbuilder/local/settings/conditions', {conditions: templateContext})\n .then(({html, js}) => {\n Templates.replaceNode(settingsConditionsRegion, html, js + templateContext.javascript);\n initConditionsForm(reportElement);\n return pendingPromise.resolve();\n });\n};\n\n/**\n * Initialise conditions form, must be called on each init because the form container is re-created when switching editor modes\n */\nconst initConditionsForm = () => {\n // Handle dynamic conditions form.\n const reportElement = document.querySelector(reportSelectors.regions.report);\n const conditionFormContainer = reportElement.querySelector(reportSelectors.regions.settingsConditions);\n const conditionForm = new DynamicForm(conditionFormContainer, '\\\\core_reportbuilder\\\\form\\\\condition');\n\n // Submit report conditions.\n conditionForm.addEventListener(conditionForm.events.FORM_SUBMITTED, event => {\n event.preventDefault();\n\n getString('conditionsapplied', 'core_reportbuilder')\n .then(addToast)\n .catch(Notification.exception);\n\n // After the form has been submitted, we should trigger report table reload.\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n });\n\n // Reset report conditions.\n conditionForm.addEventListener(conditionForm.events.NOSUBMIT_BUTTON_PRESSED, event => {\n event.preventDefault();\n\n const pendingPromise = new Pending('core_reportbuilder/conditions:reset');\n\n resetConditions(reportElement.dataset.reportId)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionsreset', 'core_reportbuilder'))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n });\n};\n\n/**\n * Initialise module\n *\n * @param {Boolean} initialized Ensure we only add our listeners once\n */\nexport const init = (initialized) => {\n initConditionsForm();\n if (initialized) {\n return;\n }\n\n document.addEventListener('click', event => {\n\n // Add condition to report.\n const reportAddCondition = event.target.closest(reportSelectors.actions.reportAddCondition);\n if (reportAddCondition) {\n event.preventDefault();\n\n const reportElement = reportAddCondition.closest(reportSelectors.regions.report);\n\n // Check if dropdown is closed with no condition selected.\n if (reportAddCondition.value === '0') {\n return;\n }\n\n const pendingPromise = new Pending('core_reportbuilder/conditions:add');\n\n addCondition(reportElement.dataset.reportId, reportAddCondition.value)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionadded', 'core_reportbuilder',\n reportAddCondition.options[reportAddCondition.selectedIndex].text))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }\n\n // Remove condition from report.\n const reportRemoveCondition = event.target.closest(reportSelectors.actions.reportRemoveCondition);\n if (reportRemoveCondition) {\n event.preventDefault();\n\n const reportElement = reportRemoveCondition.closest(reportSelectors.regions.report);\n const conditionContainer = reportRemoveCondition.closest(reportSelectors.regions.activeCondition);\n const conditionName = conditionContainer.dataset.conditionName;\n\n getStrings([\n {key: 'deletecondition', component: 'core_reportbuilder', param: conditionName},\n {key: 'deleteconditionconfirm', component: 'core_reportbuilder', param: conditionName},\n {key: 'delete', component: 'moodle'},\n ]).then(([confirmTitle, confirmText, confirmButton]) => {\n Notification.confirm(confirmTitle, confirmText, confirmButton, null, () => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:remove');\n\n deleteCondition(reportElement.dataset.reportId, conditionContainer.dataset.conditionId)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditiondeleted', 'core_reportbuilder', conditionName))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n });\n return;\n }).catch(Notification.exception);\n }\n });\n\n // Initialize sortable list to handle active conditions moving (note JQuery dependency, see MDL-72293 for resolution).\n var activeConditionsSortableList = new SortableList(`${reportSelectors.regions.activeConditions}`,\n {isHorizontal: false});\n activeConditionsSortableList.getElementName = element => Promise.resolve(element.data('conditionName'));\n\n $(document).on(SortableList.EVENTS.DROP, reportSelectors.regions.activeCondition, (event, info) => {\n if (info.positionChanged) {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reorder');\n const reportElement = event.target.closest(reportSelectors.regions.report);\n const conditionId = info.element.data('conditionId');\n const conditionPosition = info.element.data('conditionPosition');\n\n // Select target position, if moving to the end then count number of element siblings.\n let targetConditionPosition = info.targetNextElement.data('conditionPosition') || info.element.siblings().length + 2;\n if (targetConditionPosition > conditionPosition) {\n targetConditionPosition--;\n }\n\n reorderCondition(reportElement.dataset.reportId, conditionId, targetConditionPosition)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionmoved', 'core_reportbuilder', info.element.data('conditionName')))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }\n });\n};\n"],"file":"conditions.min.js"} \ No newline at end of file +{"version":3,"sources":["../../../src/local/editor/conditions.js"],"names":["reloadSettingsConditionsRegion","reportElement","templateContext","pendingPromise","Pending","settingsConditionsRegion","querySelector","reportSelectors","regions","settingsConditions","Templates","renderForPromise","conditions","then","html","js","replaceNode","javascript","initConditionsForm","resolve","document","report","conditionFormContainer","conditionForm","DynamicForm","addEventListener","events","FORM_SUBMITTED","event","preventDefault","addToast","catch","Notification","exception","reportEvents","tableReload","NOSUBMIT_BUTTON_PRESSED","dataset","reportId","data","init","initialized","reportAddCondition","target","closest","actions","value","options","selectedIndex","text","reportRemoveCondition","conditionContainer","activeCondition","conditionName","key","component","param","confirmTitle","confirmText","confirmButton","confirm","conditionId","activeConditionsSortableList","SortableList","activeConditions","isHorizontal","getElementName","element","Promise","on","EVENTS","DROP","info","positionChanged","conditionPosition","targetConditionPosition","targetNextElement","siblings","length"],"mappings":"orBAuBA,a,+DAEA,OAGA,OACA,OACA,OAEA,OAEA,OACA,OACA,O,wjDAUMA,CAAAA,CAA8B,CAAG,SAACC,CAAD,CAAgBC,CAAhB,CAAoC,IACjEC,CAAAA,CAAc,CAAG,GAAIC,UAAJ,CAAY,sCAAZ,CADgD,CAEjEC,CAAwB,CAAGJ,CAAa,CAACK,aAAd,CAA4BC,CAAe,CAACC,OAAhB,CAAwBC,kBAApD,CAFsC,CAIvE,MAAOC,WAAUC,gBAAV,CAA2B,8CAA3B,CAA2E,CAACC,UAAU,CAAEV,CAAb,CAA3E,EACFW,IADE,CACG,WAAgB,IAAdC,CAAAA,CAAc,GAAdA,IAAc,CAARC,CAAQ,GAARA,EAAQ,CAClBL,UAAUM,WAAV,CAAsBX,CAAtB,CAAgDS,CAAhD,CAAsDC,CAAE,CAAGb,CAAe,CAACe,UAA3E,EACAC,CAAkB,CAACjB,CAAD,CAAlB,CACA,MAAOE,CAAAA,CAAc,CAACgB,OAAf,EACV,CALE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,OAAd,CAAsBC,QAAvC,CAAiDuB,CAAjD,CAA8Dc,CAA9D,EACK9D,IADL,CACU,SAAA0B,CAAI,QAAIvC,CAAAA,CAA8B,CAACC,CAAD,CAAgBsC,CAAhB,CAAlC,CADd,EAEK1B,IAFL,CAEU,iBAAM,iBAAU,gBAAV,CAA4B,oBAA5B,CAAkD2D,CAAI,CAACL,OAAL,CAAa5B,IAAb,CAAkB,eAAlB,CAAlD,CAAN,CAFV,EAGK1B,IAHL,CAGUiB,KAHV,EAIKjB,IAJL,CAIU,UAAM,CACR,oBAAcqB,CAAY,CAACC,WAA3B,CAAwC,EAAxC,CAA4ClC,CAA5C,EACA,MAAOE,CAAAA,CAAc,CAACgB,OAAf,EACV,CAPL,EAQKY,KARL,CAQWC,UAAaC,SARxB,CASH,CACJ,CAvBD,CAwBH,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Report builder conditions editor\n *\n * @module core_reportbuilder/local/editor/conditions\n * @copyright 2021 Paul Holden \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\"use strict\";\n\nimport $ from 'jquery';\nimport {dispatchEvent} from 'core/event_dispatcher';\nimport 'core/inplace_editable';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport SortableList from 'core/sortable_list';\nimport {get_string as getString, get_strings as getStrings} from 'core/str';\nimport Templates from 'core/templates';\nimport {add as addToast} from 'core/toast';\nimport DynamicForm from 'core_form/dynamicform';\nimport * as reportEvents from 'core_reportbuilder/local/events';\nimport * as reportSelectors from 'core_reportbuilder/local/selectors';\nimport {addCondition, deleteCondition, reorderCondition, resetConditions} from 'core_reportbuilder/local/repository/conditions';\n\n/**\n * Reload conditions settings region\n *\n * @param {Element} reportElement\n * @param {Object} templateContext\n * @return {Promise}\n */\nconst reloadSettingsConditionsRegion = (reportElement, templateContext) => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reload');\n const settingsConditionsRegion = reportElement.querySelector(reportSelectors.regions.settingsConditions);\n\n return Templates.renderForPromise('core_reportbuilder/local/settings/conditions', {conditions: templateContext})\n .then(({html, js}) => {\n Templates.replaceNode(settingsConditionsRegion, html, js + templateContext.javascript);\n initConditionsForm(reportElement);\n return pendingPromise.resolve();\n });\n};\n\n/**\n * Initialise conditions form, must be called on each init because the form container is re-created when switching editor modes\n */\nconst initConditionsForm = () => {\n // Handle dynamic conditions form.\n const reportElement = document.querySelector(reportSelectors.regions.report);\n const conditionFormContainer = reportElement.querySelector(reportSelectors.regions.settingsConditions);\n if (!conditionFormContainer) {\n return;\n }\n const conditionForm = new DynamicForm(conditionFormContainer, '\\\\core_reportbuilder\\\\form\\\\condition');\n\n // Submit report conditions.\n conditionForm.addEventListener(conditionForm.events.FORM_SUBMITTED, event => {\n event.preventDefault();\n\n getString('conditionsapplied', 'core_reportbuilder')\n .then(addToast)\n .catch(Notification.exception);\n\n // After the form has been submitted, we should trigger report table reload.\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n });\n\n // Reset report conditions.\n conditionForm.addEventListener(conditionForm.events.NOSUBMIT_BUTTON_PRESSED, event => {\n event.preventDefault();\n\n const pendingPromise = new Pending('core_reportbuilder/conditions:reset');\n\n resetConditions(reportElement.dataset.reportId)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionsreset', 'core_reportbuilder'))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n });\n};\n\n/**\n * Initialise module\n *\n * @param {Boolean} initialized Ensure we only add our listeners once\n */\nexport const init = (initialized) => {\n initConditionsForm();\n if (initialized) {\n return;\n }\n\n document.addEventListener('click', event => {\n\n // Add condition to report.\n const reportAddCondition = event.target.closest(reportSelectors.actions.reportAddCondition);\n if (reportAddCondition) {\n event.preventDefault();\n\n const reportElement = reportAddCondition.closest(reportSelectors.regions.report);\n\n // Check if dropdown is closed with no condition selected.\n if (reportAddCondition.value === '0') {\n return;\n }\n\n const pendingPromise = new Pending('core_reportbuilder/conditions:add');\n\n addCondition(reportElement.dataset.reportId, reportAddCondition.value)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionadded', 'core_reportbuilder',\n reportAddCondition.options[reportAddCondition.selectedIndex].text))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }\n\n // Remove condition from report.\n const reportRemoveCondition = event.target.closest(reportSelectors.actions.reportRemoveCondition);\n if (reportRemoveCondition) {\n event.preventDefault();\n\n const reportElement = reportRemoveCondition.closest(reportSelectors.regions.report);\n const conditionContainer = reportRemoveCondition.closest(reportSelectors.regions.activeCondition);\n const conditionName = conditionContainer.dataset.conditionName;\n\n getStrings([\n {key: 'deletecondition', component: 'core_reportbuilder', param: conditionName},\n {key: 'deleteconditionconfirm', component: 'core_reportbuilder', param: conditionName},\n {key: 'delete', component: 'moodle'},\n ]).then(([confirmTitle, confirmText, confirmButton]) => {\n Notification.confirm(confirmTitle, confirmText, confirmButton, null, () => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:remove');\n\n deleteCondition(reportElement.dataset.reportId, conditionContainer.dataset.conditionId)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditiondeleted', 'core_reportbuilder', conditionName))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n });\n return;\n }).catch(Notification.exception);\n }\n });\n\n // Initialize sortable list to handle active conditions moving (note JQuery dependency, see MDL-72293 for resolution).\n var activeConditionsSortableList = new SortableList(`${reportSelectors.regions.activeConditions}`,\n {isHorizontal: false});\n activeConditionsSortableList.getElementName = element => Promise.resolve(element.data('conditionName'));\n\n $(document).on(SortableList.EVENTS.DROP, reportSelectors.regions.activeCondition, (event, info) => {\n if (info.positionChanged) {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reorder');\n const reportElement = event.target.closest(reportSelectors.regions.report);\n const conditionId = info.element.data('conditionId');\n const conditionPosition = info.element.data('conditionPosition');\n\n // Select target position, if moving to the end then count number of element siblings.\n let targetConditionPosition = info.targetNextElement.data('conditionPosition') || info.element.siblings().length + 2;\n if (targetConditionPosition > conditionPosition) {\n targetConditionPosition--;\n }\n\n reorderCondition(reportElement.dataset.reportId, conditionId, targetConditionPosition)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionmoved', 'core_reportbuilder', info.element.data('conditionName')))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }\n });\n};\n"],"file":"conditions.min.js"} \ No newline at end of file diff --git a/reportbuilder/amd/src/local/editor/conditions.js b/reportbuilder/amd/src/local/editor/conditions.js index 28e1174cacd..71410688241 100644 --- a/reportbuilder/amd/src/local/editor/conditions.js +++ b/reportbuilder/amd/src/local/editor/conditions.js @@ -63,6 +63,9 @@ const initConditionsForm = () => { // Handle dynamic conditions form. const reportElement = document.querySelector(reportSelectors.regions.report); const conditionFormContainer = reportElement.querySelector(reportSelectors.regions.settingsConditions); + if (!conditionFormContainer) { + return; + } const conditionForm = new DynamicForm(conditionFormContainer, '\\core_reportbuilder\\form\\condition'); // Submit report conditions. diff --git a/reportbuilder/classes/external/custom_report_columns_sorting_exporter.php b/reportbuilder/classes/external/custom_report_columns_sorting_exporter.php index 1a497be686f..2fe31585f4a 100644 --- a/reportbuilder/classes/external/custom_report_columns_sorting_exporter.php +++ b/reportbuilder/classes/external/custom_report_columns_sorting_exporter.php @@ -53,6 +53,7 @@ class custom_report_columns_sorting_exporter extends exporter { return [ 'hassortablecolumns' => [ 'type' => PARAM_BOOL, + 'optional' => true, ], 'sortablecolumns' => [ 'type' => [ @@ -77,6 +78,7 @@ class custom_report_columns_sorting_exporter extends exporter { ], 'helpicon' => [ 'type' => PARAM_RAW, + 'optional' => true, ], ]; } diff --git a/reportbuilder/classes/external/custom_report_conditions_exporter.php b/reportbuilder/classes/external/custom_report_conditions_exporter.php index 3a19532814f..59f04a5068c 100644 --- a/reportbuilder/classes/external/custom_report_conditions_exporter.php +++ b/reportbuilder/classes/external/custom_report_conditions_exporter.php @@ -53,6 +53,7 @@ class custom_report_conditions_exporter extends exporter { return [ 'hasavailableconditions' => [ 'type' => PARAM_BOOL, + 'optional' => true, ], 'availableconditions' => [ 'type' => [ @@ -74,6 +75,7 @@ class custom_report_conditions_exporter extends exporter { ], 'hasactiveconditions' => [ 'type' => PARAM_BOOL, + 'optional' => true, ], 'activeconditionsform' => [ 'type' => PARAM_RAW, diff --git a/reportbuilder/classes/external/custom_report_exporter.php b/reportbuilder/classes/external/custom_report_exporter.php index 2f446b84ea5..8eedcb07606 100644 --- a/reportbuilder/classes/external/custom_report_exporter.php +++ b/reportbuilder/classes/external/custom_report_exporter.php @@ -46,9 +46,6 @@ class custom_report_exporter extends persistent_exporter { /** @var bool */ protected $editmode; - /** @var bool $showeditbutton When showing the report on view.php the Edit button has to be hidden */ - protected $showeditbutton; - /** @var string */ protected $download; @@ -58,15 +55,11 @@ class custom_report_exporter extends persistent_exporter { * @param persistent $persistent * @param array $related * @param bool $editmode - * @param bool $showeditbutton * @param string $download */ - public function __construct(persistent $persistent, array $related = [], bool $editmode = true, - bool $showeditbutton = true, string $download = '') { - + public function __construct(persistent $persistent, array $related = [], bool $editmode = true, string $download = '') { parent::__construct($persistent, $related); $this->editmode = $editmode; - $this->showeditbutton = $showeditbutton; $this->download = $download; } /** @@ -101,12 +94,12 @@ class custom_report_exporter extends persistent_exporter { 'filters' => ['type' => custom_report_filters_exporter::read_properties_definition()], 'sorting' => ['type' => custom_report_columns_sorting_exporter::read_properties_definition()], 'filtersapplied' => ['type' => PARAM_INT], + 'filterspresent' => ['type' => PARAM_BOOL], 'filtersform' => [ 'type' => PARAM_RAW, 'optional' => true, ], 'editmode' => ['type' => PARAM_INT], - 'showeditbutton' => ['type' => PARAM_BOOL], 'javascript' => ['type' => PARAM_RAW], ]; } @@ -118,8 +111,8 @@ class custom_report_exporter extends persistent_exporter { * @return array */ protected function get_other_values(renderer_base $output): array { + $filterspresent = false; $filtersform = ''; - $menucards = []; if ($this->editmode) { $table = custom_report_table::create($this->persistent->get('id')); @@ -133,33 +126,39 @@ class custom_report_exporter extends persistent_exporter { /** @var datasource $datasource */ $datasource = new $source($this->persistent); - if (!empty($datasource->get_active_filters())) { + $filterspresent = !empty($datasource->get_active_filters()); + if ($filterspresent) { $filtersform = $this->generate_filters_form()->render(); } } $report = manager::get_report_from_persistent($this->persistent); - $conditionsexporter = new custom_report_conditions_exporter(null, ['report' => $report]); - $filtersexporter = new custom_report_filters_exporter(null, ['report' => $report]); - $sortingexporter = new custom_report_columns_sorting_exporter(null, ['report' => $report]); + // If we are editing we need all this information for the template. if ($this->editmode) { $menucardexporter = new custom_report_menu_cards_exporter(null, [ 'menucards' => report_helper::get_available_columns($report->get_report_persistent()) ]); + $menucards = (array) $menucardexporter->export($output); + $conditionsexporter = new custom_report_conditions_exporter(null, ['report' => $report]); + $conditions = (array) $conditionsexporter->export($output); + $filtersexporter = new custom_report_filters_exporter(null, ['report' => $report]); + $filters = (array) $filtersexporter->export($output); + $sortingexporter = new custom_report_columns_sorting_exporter(null, ['report' => $report]); + $sorting = (array) $sortingexporter->export($output); } return [ 'table' => $output->render($table), - 'sidebarmenucards' => $menucards, - 'conditions' => (array) $conditionsexporter->export($output), - 'filters' => (array) $filtersexporter->export($output), - 'sorting' => (array) $sortingexporter->export($output), + 'sidebarmenucards' => $menucards ?? [], + 'conditions' => $conditions ?? [], + 'filters' => $filters ?? [], + 'sorting' => $sorting ?? [], 'filtersapplied' => $report->get_applied_filter_count(), + 'filterspresent' => $filterspresent, 'filtersform' => $filtersform, 'editmode' => (int)$this->editmode, - 'showeditbutton' => $this->showeditbutton, 'javascript' => '', ]; } diff --git a/reportbuilder/classes/external/custom_report_filters_exporter.php b/reportbuilder/classes/external/custom_report_filters_exporter.php index 53be1597234..d94bcaaf4f7 100644 --- a/reportbuilder/classes/external/custom_report_filters_exporter.php +++ b/reportbuilder/classes/external/custom_report_filters_exporter.php @@ -53,6 +53,7 @@ class custom_report_filters_exporter extends exporter { return [ 'hasavailablefilters' => [ 'type' => PARAM_BOOL, + 'optional' => true, ], 'availablefilters' => [ 'type' => [ @@ -74,6 +75,7 @@ class custom_report_filters_exporter extends exporter { ], 'hasactivefilters' => [ 'type' => PARAM_BOOL, + 'optional' => true, ], 'activefilters' => [ 'type' => [ @@ -89,6 +91,7 @@ class custom_report_filters_exporter extends exporter { ], 'helpicon' => [ 'type' => PARAM_RAW, + 'optional' => true, ], ]; } diff --git a/reportbuilder/classes/external/system_report_exporter.php b/reportbuilder/classes/external/system_report_exporter.php index 4593a73ebdf..a75feacee07 100644 --- a/reportbuilder/classes/external/system_report_exporter.php +++ b/reportbuilder/classes/external/system_report_exporter.php @@ -103,7 +103,7 @@ class system_report_exporter extends persistent_exporter { $table->set_filterset($filterset); // Generate filters form if report contains any filters. - $filterspresent = !empty($source->get_filters()); + $filterspresent = !empty($source->get_active_filters()); if ($filterspresent) { $filtersform = new filter(null, null, 'post', '', [], true, [ 'reportid' => $reportid, diff --git a/reportbuilder/classes/output/custom_report.php b/reportbuilder/classes/output/custom_report.php index 3c3a25ebac1..f907ff824fb 100644 --- a/reportbuilder/classes/output/custom_report.php +++ b/reportbuilder/classes/output/custom_report.php @@ -40,9 +40,6 @@ class custom_report implements renderable, templatable { /** @var bool $editmode */ protected $editmode; - /** @var bool $showeditbutton */ - protected $showeditbutton; - /** @var string $download */ protected $download; @@ -51,15 +48,11 @@ class custom_report implements renderable, templatable { * * @param report $reportpersistent * @param bool $editmode - * @param bool $showeditbutton * @param string $download */ - public function __construct(report $reportpersistent, bool $editmode = true, bool $showeditbutton = true, - string $download = '') { - + public function __construct(report $reportpersistent, bool $editmode = true, string $download = '') { $this->persistent = $reportpersistent; $this->editmode = $editmode; - $this->showeditbutton = $showeditbutton; $this->download = $download; } @@ -70,7 +63,7 @@ class custom_report implements renderable, templatable { * @return stdClass */ public function export_for_template(renderer_base $output): stdClass { - $exporter = new custom_report_exporter($this->persistent, [], $this->editmode, $this->showeditbutton, $this->download); + $exporter = new custom_report_exporter($this->persistent, [], $this->editmode, $this->download); return $exporter->export($output); } diff --git a/reportbuilder/classes/output/renderer.php b/reportbuilder/classes/output/renderer.php index 09ae0d1535c..b76f5bc486e 100644 --- a/reportbuilder/classes/output/renderer.php +++ b/reportbuilder/classes/output/renderer.php @@ -42,7 +42,7 @@ class renderer extends plugin_renderer_base { protected function render_system_report(system_report $report): string { $context = $report->export_for_template($this); - return $this->render_from_template('core_reportbuilder/system_report', $context); + return $this->render_from_template('core_reportbuilder/report', $context); } /** diff --git a/reportbuilder/download.php b/reportbuilder/download.php index 2a646cf7ee9..97b1ce28f3c 100644 --- a/reportbuilder/download.php +++ b/reportbuilder/download.php @@ -58,6 +58,6 @@ if ($reportpersistent->get('type') === \core_reportbuilder\local\report\base::TY } else { permission::require_can_view_report($reportpersistent); - $customreport = new \core_reportbuilder\output\custom_report($reportpersistent, false, false, $download); + $customreport = new \core_reportbuilder\output\custom_report($reportpersistent, false, $download); echo $PAGE->get_renderer('core_reportbuilder')->render($customreport); } diff --git a/reportbuilder/templates/local/dynamictabs/editor.mustache b/reportbuilder/templates/local/dynamictabs/editor.mustache index 0554f7a4c61..9e0a4bfc59c 100644 --- a/reportbuilder/templates/local/dynamictabs/editor.mustache +++ b/reportbuilder/templates/local/dynamictabs/editor.mustache @@ -22,10 +22,9 @@ Example context (json): { "id": 1, - "source": "some\\class\\name", + "type": 1, "table": "table", "editmode": true, - "showeditbutton": true, "sidebarmenucards": [{ "menucards": [{ "name": "General", @@ -87,8 +86,9 @@ }}
+ data-report-type="{{type}}" + data-parameter="[]" + {{#editmode}}data-editing{{/editmode}}>
{{#editmode}} @@ -99,19 +99,17 @@
@@ -133,9 +131,11 @@
- - {{> core_reportbuilder/local/settings/area}} -
+ {{#editmode}} + + {{> core_reportbuilder/local/settings/area}} + {{/editmode}} + {{#js}} diff --git a/reportbuilder/templates/local/filters/area.mustache b/reportbuilder/templates/local/filters/area.mustache index 15bda276340..b55a1293876 100644 --- a/reportbuilder/templates/local/filters/area.mustache +++ b/reportbuilder/templates/local/filters/area.mustache @@ -24,13 +24,12 @@ "id": 3, "contextid": 1, "filtersapplied": 3, - "showeditbutton": false, "filtersform": "form" } }} -