diff --git a/amd/build/package_search/components/pagination.min.js b/amd/build/package_search/components/pagination.min.js index 88e23b1a..34f9b0e0 100644 --- a/amd/build/package_search/components/pagination.min.js +++ b/amd/build/package_search/components/pagination.min.js @@ -1,3 +1,3 @@ -define("qtype_questionpy/package_search/components/pagination",["exports","qtype_questionpy/package_search/component"],(function(_exports,_component){var obj;Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_component=(obj=_component)&&obj.__esModule?obj:{default:obj};class _default extends _component.default{getWatchers(){return[{watch:"".concat(this.category,".data:updated"),handler:this.updateCurrentPage}]}create(descriptor){this.category=descriptor.category,this.selectors={PREVIOUS_BUTTON:'[data-for="pagination-previous"]',NEXT_BUTTON:'[data-for="pagination-next"]',CURRENT:'[data-for="pagination-current"]'}}stateReady(){this.addEventListener(this.getElement(this.selectors.PREVIOUS_BUTTON),"click",this.previousPage),this.addEventListener(this.getElement(this.selectors.NEXT_BUTTON),"click",this.nextPage)}_getCurrentPage(){return this.getState()[this.category].page}_getLastPage(){const state=this.getState()[this.category];return 0===state.data.total?0:Math.floor((state.data.total-1)/this.reactive.options.limit)}updateCurrentPage(){const currentPage=this._getCurrentPage(),lastPage=this._getLastPage();this.getElement(this.selectors.CURRENT).innerHTML="".concat(currentPage+1," / ").concat(lastPage+1),0===currentPage?this.getElement(this.selectors.PREVIOUS_BUTTON).classList.add("disabled"):this.getElement(this.selectors.PREVIOUS_BUTTON).classList.remove("disabled"),currentPage===lastPage?this.getElement(this.selectors.NEXT_BUTTON).classList.add("disabled"):this.getElement(this.selectors.NEXT_BUTTON).classList.remove("disabled")}previousPage(){const currentPage=this._getCurrentPage();currentPage>0&&this.reactive.dispatch("changePage",this.category,currentPage-1)}nextPage(){const currentPage=this._getCurrentPage();currentPage0&&this.reactive.dispatch("changePage",this.category,currentPage-1)}nextPage(){const currentPage=this._getCurrentPage();currentPage.\n */\n\n/**\n * @module qtype_questionpy/package_search/components/pagination\n */\n\nimport Component from 'qtype_questionpy/package_search/component';\n\nexport default class extends Component {\n getWatchers() {\n return [\n {watch: `${this.category}.data:updated`, handler: this.updateCurrentPage},\n ];\n }\n\n create(descriptor) {\n this.category = descriptor.category;\n this.selectors = {\n PREVIOUS_BUTTON: `[data-for=\"pagination-previous\"]`,\n NEXT_BUTTON: `[data-for=\"pagination-next\"]`,\n CURRENT: `[data-for=\"pagination-current\"]`,\n };\n }\n\n stateReady() {\n this.addEventListener(this.getElement(this.selectors.PREVIOUS_BUTTON), \"click\", this.previousPage);\n this.addEventListener(this.getElement(this.selectors.NEXT_BUTTON), \"click\", this.nextPage);\n }\n\n /**\n * Returns the current page number starting form zero.\n *\n * @returns {number}\n * @private\n */\n _getCurrentPage() {\n return this.getState()[this.category].page;\n }\n\n /**\n * Returns the last page number starting from zero.\n *\n * @returns {number}\n * @private\n */\n _getLastPage() {\n const state = this.getState()[this.category];\n if (state.data.total === 0) {\n return 0;\n }\n return Math.floor((state.data.total - 1) / this.reactive.options.limit);\n }\n\n /**\n * Updates the current page status and disables or enables the previous and next button.\n */\n updateCurrentPage() {\n const currentPage = this._getCurrentPage();\n const lastPage = this._getLastPage();\n\n this.getElement(this.selectors.CURRENT).innerHTML = `${currentPage + 1} / ${lastPage + 1}`;\n\n if (currentPage === 0) {\n this.getElement(this.selectors.PREVIOUS_BUTTON).classList.add(\"disabled\");\n } else {\n this.getElement(this.selectors.PREVIOUS_BUTTON).classList.remove(\"disabled\");\n }\n if (currentPage === lastPage) {\n this.getElement(this.selectors.NEXT_BUTTON).classList.add(\"disabled\");\n } else {\n this.getElement(this.selectors.NEXT_BUTTON).classList.remove(\"disabled\");\n }\n }\n\n /**\n * Dispatches mutation that retrieves packages from the previous page.\n */\n previousPage() {\n const currentPage = this._getCurrentPage();\n if (currentPage > 0) {\n this.reactive.dispatch(\"changePage\", this.category, currentPage - 1);\n }\n }\n\n /**\n * Dispatches mutation that retrieves packages from the next page.\n */\n nextPage() {\n const currentPage = this._getCurrentPage();\n const lastPage = this._getLastPage();\n if (currentPage < lastPage) {\n this.reactive.dispatch(\"changePage\", this.category, currentPage + 1);\n }\n }\n\n}\n"],"names":["Component","getWatchers","watch","this","category","handler","updateCurrentPage","create","descriptor","selectors","PREVIOUS_BUTTON","NEXT_BUTTON","CURRENT","stateReady","addEventListener","getElement","previousPage","nextPage","_getCurrentPage","getState","page","_getLastPage","state","data","total","Math","floor","reactive","options","limit","currentPage","lastPage","innerHTML","classList","add","remove","dispatch"],"mappings":"mUAuB6BA,mBACzBC,oBACW,CACH,CAACC,gBAAUC,KAAKC,0BAAyBC,QAASF,KAAKG,oBAI/DC,OAAOC,iBACEJ,SAAWI,WAAWJ,cACtBK,UAAY,CACbC,mDACAC,2CACAC,2CAIRC,kBACSC,iBAAiBX,KAAKY,WAAWZ,KAAKM,UAAUC,iBAAkB,QAASP,KAAKa,mBAChFF,iBAAiBX,KAAKY,WAAWZ,KAAKM,UAAUE,aAAc,QAASR,KAAKc,UASrFC,yBACWf,KAAKgB,WAAWhB,KAAKC,UAAUgB,KAS1CC,qBACUC,MAAQnB,KAAKgB,WAAWhB,KAAKC,iBACV,IAArBkB,MAAMC,KAAKC,MACJ,EAEJC,KAAKC,OAAOJ,MAAMC,KAAKC,MAAQ,GAAKrB,KAAKwB,SAASC,QAAQC,OAMrEvB,0BACUwB,YAAc3B,KAAKe,kBACnBa,SAAW5B,KAAKkB,oBAEjBN,WAAWZ,KAAKM,UAAUG,SAASoB,oBAAeF,YAAc,gBAAOC,SAAW,GAEnE,IAAhBD,iBACKf,WAAWZ,KAAKM,UAAUC,iBAAiBuB,UAAUC,IAAI,iBAEzDnB,WAAWZ,KAAKM,UAAUC,iBAAiBuB,UAAUE,OAAO,YAEjEL,cAAgBC,cACXhB,WAAWZ,KAAKM,UAAUE,aAAasB,UAAUC,IAAI,iBAErDnB,WAAWZ,KAAKM,UAAUE,aAAasB,UAAUE,OAAO,YAOrEnB,qBACUc,YAAc3B,KAAKe,kBACrBY,YAAc,QACTH,SAASS,SAAS,aAAcjC,KAAKC,SAAU0B,YAAc,GAO1Eb,iBACUa,YAAc3B,KAAKe,kBAErBY,YADa3B,KAAKkB,qBAEbM,SAASS,SAAS,aAAcjC,KAAKC,SAAU0B,YAAc"} \ No newline at end of file +{"version":3,"file":"pagination.min.js","sources":["../../../src/package_search/components/pagination.js"],"sourcesContent":["/*\n * This file is part of the QuestionPy Moodle plugin - https://questionpy.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/**\n * @module qtype_questionpy/package_search/components/pagination\n */\n\nimport Component from 'qtype_questionpy/package_search/component';\n\nexport default class extends Component {\n getWatchers() {\n return [\n {watch: `${this.category}.data:updated`, handler: this.updateCurrentPage},\n ];\n }\n\n create(descriptor) {\n this.category = descriptor.category;\n this.selectors = {\n PREVIOUS_BUTTON: `[data-for=\"pagination-previous\"]`,\n NEXT_BUTTON: `[data-for=\"pagination-next\"]`,\n CURRENT: `[data-for=\"pagination-current\"]`,\n };\n }\n\n stateReady() {\n this.addEventListener(this.getElement(this.selectors.PREVIOUS_BUTTON), \"click\", this.previousPage);\n this.addEventListener(this.getElement(this.selectors.NEXT_BUTTON), \"click\", this.nextPage);\n }\n\n /**\n * Returns the current page number starting form zero.\n *\n * @returns {number}\n * @private\n */\n _getCurrentPage() {\n return this.getState()[this.category].page;\n }\n\n /**\n * Returns the last page number starting from zero.\n *\n * @returns {number}\n * @private\n */\n _getLastPage() {\n const state = this.getState()[this.category];\n if (state.data.total === 0) {\n return 0;\n }\n return Math.floor((state.data.total - 1) / this.reactive.options.limit);\n }\n\n /**\n * Updates the current page status and disables or enables the previous and next button.\n */\n updateCurrentPage() {\n const currentPage = this._getCurrentPage();\n const lastPage = this._getLastPage();\n\n this.getElement(this.selectors.CURRENT).innerHTML = `${currentPage + 1} / ${lastPage + 1}`;\n\n // Disable or enable buttons.\n this.getElement(this.selectors.PREVIOUS_BUTTON).classList.toggle(\"disabled\", currentPage === 0);\n this.getElement(this.selectors.NEXT_BUTTON).classList.toggle(\"disabled\", currentPage === lastPage);\n }\n\n /**\n * Dispatches mutation that retrieves packages from the previous page.\n */\n previousPage() {\n const currentPage = this._getCurrentPage();\n if (currentPage > 0) {\n this.reactive.dispatch(\"changePage\", this.category, currentPage - 1);\n }\n }\n\n /**\n * Dispatches mutation that retrieves packages from the next page.\n */\n nextPage() {\n const currentPage = this._getCurrentPage();\n const lastPage = this._getLastPage();\n if (currentPage < lastPage) {\n this.reactive.dispatch(\"changePage\", this.category, currentPage + 1);\n }\n }\n\n}\n"],"names":["Component","getWatchers","watch","this","category","handler","updateCurrentPage","create","descriptor","selectors","PREVIOUS_BUTTON","NEXT_BUTTON","CURRENT","stateReady","addEventListener","getElement","previousPage","nextPage","_getCurrentPage","getState","page","_getLastPage","state","data","total","Math","floor","reactive","options","limit","currentPage","lastPage","innerHTML","classList","toggle","dispatch"],"mappings":"mUAuB6BA,mBACzBC,oBACW,CACH,CAACC,gBAAUC,KAAKC,0BAAyBC,QAASF,KAAKG,oBAI/DC,OAAOC,iBACEJ,SAAWI,WAAWJ,cACtBK,UAAY,CACbC,mDACAC,2CACAC,2CAIRC,kBACSC,iBAAiBX,KAAKY,WAAWZ,KAAKM,UAAUC,iBAAkB,QAASP,KAAKa,mBAChFF,iBAAiBX,KAAKY,WAAWZ,KAAKM,UAAUE,aAAc,QAASR,KAAKc,UASrFC,yBACWf,KAAKgB,WAAWhB,KAAKC,UAAUgB,KAS1CC,qBACUC,MAAQnB,KAAKgB,WAAWhB,KAAKC,iBACV,IAArBkB,MAAMC,KAAKC,MACJ,EAEJC,KAAKC,OAAOJ,MAAMC,KAAKC,MAAQ,GAAKrB,KAAKwB,SAASC,QAAQC,OAMrEvB,0BACUwB,YAAc3B,KAAKe,kBACnBa,SAAW5B,KAAKkB,oBAEjBN,WAAWZ,KAAKM,UAAUG,SAASoB,oBAAeF,YAAc,gBAAOC,SAAW,QAGlFhB,WAAWZ,KAAKM,UAAUC,iBAAiBuB,UAAUC,OAAO,WAA4B,IAAhBJ,kBACxEf,WAAWZ,KAAKM,UAAUE,aAAasB,UAAUC,OAAO,WAAYJ,cAAgBC,UAM7Ff,qBACUc,YAAc3B,KAAKe,kBACrBY,YAAc,QACTH,SAASQ,SAAS,aAAchC,KAAKC,SAAU0B,YAAc,GAO1Eb,iBACUa,YAAc3B,KAAKe,kBAErBY,YADa3B,KAAKkB,qBAEbM,SAASQ,SAAS,aAAchC,KAAKC,SAAU0B,YAAc"} \ No newline at end of file diff --git a/amd/src/package_search/components/pagination.js b/amd/src/package_search/components/pagination.js index 4cdb319e..078e806b 100644 --- a/amd/src/package_search/components/pagination.js +++ b/amd/src/package_search/components/pagination.js @@ -73,18 +73,12 @@ export default class extends Component { const currentPage = this._getCurrentPage(); const lastPage = this._getLastPage(); + // Update page status. this.getElement(this.selectors.CURRENT).innerHTML = `${currentPage + 1} / ${lastPage + 1}`; - if (currentPage === 0) { - this.getElement(this.selectors.PREVIOUS_BUTTON).classList.add("disabled"); - } else { - this.getElement(this.selectors.PREVIOUS_BUTTON).classList.remove("disabled"); - } - if (currentPage === lastPage) { - this.getElement(this.selectors.NEXT_BUTTON).classList.add("disabled"); - } else { - this.getElement(this.selectors.NEXT_BUTTON).classList.remove("disabled"); - } + // Disable or enable buttons. + this.getElement(this.selectors.PREVIOUS_BUTTON).classList.toggle("disabled", currentPage === 0); + this.getElement(this.selectors.NEXT_BUTTON).classList.toggle("disabled", currentPage === lastPage); } /** diff --git a/templates/package_search/pagination.mustache b/templates/package_search/pagination.mustache index 52949037..09ba4e58 100644 --- a/templates/package_search/pagination.mustache +++ b/templates/package_search/pagination.mustache @@ -25,16 +25,16 @@ Example context (json): {} }} -