From 3295288d6edcc56c16f8c70bbc89546243708d93 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Wed, 15 Jul 2020 16:37:13 +0800 Subject: [PATCH] MDL-69079 course: Handle fetch module data failures in activity chooser --- course/amd/build/activitychooser.min.js | Bin 6349 -> 6790 bytes course/amd/build/activitychooser.min.js.map | Bin 24891 -> 25646 bytes course/amd/src/activitychooser.js | 13 +++++- .../local/activitychooser/error.mustache | 39 ++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 course/templates/local/activitychooser/error.mustache diff --git a/course/amd/build/activitychooser.min.js b/course/amd/build/activitychooser.min.js index 0ea080eb7586eeeb67f890105e382a304e9741a3..da00bcf7ae92e2bd62204bacfb652b46c82e9ddb 100644 GIT binary patch delta 313 zcmX?W*k-z6ItP2cPJvFLPU+-%98;N$3@4j%{uIc!P1Gw+%`34kur1NZ)ybc1$0f$D zmz-FVoS`u}fWwRs zp=LGI3_}y^q@vWs?AoH#lG36)g+#r?q@vP-5)CDYfD+V5Lldh~+ais^$=O_v1_e5$ zI%OJ#I;naoi6uY_OMt#hF3HT#%S_SK$=5`4rlBR!orb)nI_a7)!z@7#1cuILTkZ+G E06XPossI20 delta 158 zcmZoOJ!`mOItP26PQFfoPT}Nv98;MLEhn3D{uIcwP1Gw+%`36aw=L1g)ybP|$0a6i zot#*ls$ghnRREJMv@Oyon5@F%XppZ{s8gm5FYk?auR&$^yQ<7 zTuexzfPO3;kp;*`q{stQrI;quo)jwp1=2`a6rBvH4OL^!aurFn%AzfW4N#VK?Z$Rc z4JnFX<=E2}1<38Hdvw0LqeNLkZgrUy?CT32fh$Fa0ycE)w6(y|35$Jg5l;i`OR;A` zR2IZCM5qL(j7q|=0y}C;GV)!n*05k&)g@O?co3(RrLj0<0+nIOd7;Rlp`fk!%oo6- zZzyRC2cW|D3AILYRvqYE#0p0%QKDw$%ZCeMD zn`m03x{`FYjIZ?FK3XCpXzoBQ@>zq~lqn5TQ=G}_KugR};~R<_k84H}7CX=Inf~9& zM=l!65-*^1H#(u~!S?vvmby}tfcFD*I4YgA_?-(yeA?#@?kjpGpavr?z(AoN?t zB7WKrMiEc@qhoLKtxjG{>cZMU?d2$&n#JI?kCR(zcCuNh?KCG{r}KSsBD_dZv-cLu5M(+1L}PMYUO&jijRiho3H8@C~GFYM=xtmwArrn=;%fv&h?inX|ZY1uVsM zn%@}z7j*cd^S9%v;8HYd=GINSZtA^gHcF+PX3N~GxK+nocW7n0^|INnIOZCyN@1?K zEn1u%ZSf-Z+&1}WL#?r9SMh8%*?UKC+pyj0)JtI;i;m(~Q(}9>9lv6b<*M%52&~moH@79STu{t{pRtVZ|2N-b8LJ%GT!aG@Pq3q zzH|j!Q|FE^&L!ooF)0+#kL{|kU{cPDA|z!)4sc{r)}@#QTQ#I2SXBfSL6Z>`kWneN zCY!<>4ts+b_r@n?#VSCBy;ZeBwyyRx!%2-2_bALrt*EN*o6gf#6YGeMIxtO--30rEvW?6d=$N)!M{ z6@`;hmu+FpXHriqJ}`>-$~PFB=cqHVU3~~o0I0Prv8fUKMaPKO?~p|2r0MXjF8SB*B93b#Yt?p=

xq{2K%EP# z>E5-wRKf4P5yM7LBp*CE@qrY1fZHSnY+1+kNTy>qrL`pROQg_tT2HiOz?$CkRZds- z>CP{X@N)O$A$>Q_*XG02}Hf AQ2+n{ diff --git a/course/amd/src/activitychooser.js b/course/amd/src/activitychooser.js index a1d1bbca3a0..ab56979778f 100644 --- a/course/amd/src/activitychooser.js +++ b/course/amd/src/activitychooser.js @@ -133,7 +133,18 @@ const registerListenerEvents = (courseId, chooserConfig) => { const sectionModal = buildModal(bodyPromise, footerData); // Now we have a modal we should start fetching data. - const data = await fetchModuleData(); + // If an error occurs while fetching the data, display the error within the modal. + const data = await fetchModuleData().catch(async(e) => { + const errorTemplateData = { + 'errormessage': e.message + }; + bodyPromiseResolver(await Templates.render('core_course/local/activitychooser/error', errorTemplateData)); + }); + + // Early return if there is no module data. + if (!data) { + return; + } // Apply the section id to all the module instance links. const builtModuleData = sectionIdMapper(data, caller.dataset.sectionid, caller.dataset.sectionreturnid); diff --git a/course/templates/local/activitychooser/error.mustache b/course/templates/local/activitychooser/error.mustache new file mode 100644 index 00000000000..98ac463c487 --- /dev/null +++ b/course/templates/local/activitychooser/error.mustache @@ -0,0 +1,39 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template core_course/local/activitychooser/error + + Chooser error template. + + Variables required for this template: + * errormessage - The error message + + Example context (json): + { + "errormessage": "Error" + } +}} +

+ +
-- 2.43.0