Fixed context switch not working in chrome

This commit is contained in:
PMKuipers 2023-12-14 21:42:34 +01:00
parent b8c0f910c1
commit 7b980405f3
9 changed files with 43 additions and 19 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -233,11 +233,14 @@ export function init(contextid,categoryid,options) {
app.selectStudyplan(newstudyplan); app.selectStudyplan(newstudyplan);
} }
}, },
switchContext(cat){ switchContext(ctxid){
const params = new URLSearchParams(location.search); const params = new URLSearchParams(location.search);
params.delete('categoryid'); params.delete('categoryid');
params.set('contextid', cat.context_id); params.set('contextid', ctxid);
window.location.search = params.toString(); setTimeout(() => {
// Reload page in a timeout to give other form javasccript the change to remove the beforeunload handler.
window.location.href = window.location.pathname + "?" + params.toString();
},50);
}, },
selectStudyplan(studyplan){ selectStudyplan(studyplan){
// fetch studyplan // fetch studyplan

View File

@ -126,11 +126,14 @@ export function init(contextid,categoryid) {
} }
}, },
methods: { methods: {
switchContext(cat){ switchContext(ctxid){
const params = new URLSearchParams(location.search); const params = new URLSearchParams(location.search);
params.delete('categoryid'); params.delete('categoryid');
params.set('contextid', cat.context_id); params.set('contextid', ctxid);
window.location.search = params.toString(); setTimeout(() => {
// Reload page in a timeout to give other form javasccript the change to remove the beforeunload handler.
window.location.href = window.location.pathname + "?" + params.toString();
},50);
}, },
closeStudyplan() { closeStudyplan() {
app.activestudyplan = null; app.activestudyplan = null;

View File

@ -314,6 +314,11 @@ class courseservice extends \external_api {
$contextids[] = $r->context_id; $contextids[] = $r->context_id;
} }
// Add system context to list if needed.
if (!in_array(1,$contextids)) {
array_unshift($contextids,1);
}
$rs->close(); $rs->close();
$cats = []; $cats = [];
@ -332,13 +337,15 @@ class courseservice extends \external_api {
array_reverse(array_slice($refpath,0,$i)), array_reverse(array_slice($refpath,0,$i)),
array_slice($contextids, $idx+1, count($contextids) - 1) array_slice($contextids, $idx+1, count($contextids) - 1)
) ; ) ;
$found = true; $found = true;
break; break;
} }
} }
if(!$found) { if(!$found) {
array_unshift($contextids,$refctxid); array_unshift($contextids,$refctxid);
debug::write("After two");
debug::print_r($contextids);
} }
} catch(\dml_missing_record_exception $x) { } catch(\dml_missing_record_exception $x) {
// ignore context // ignore context
@ -358,7 +365,10 @@ class courseservice extends \external_api {
if ($operation == "edit" && $ctxid == $refctxid) { if ($operation == "edit" && $ctxid == $refctxid) {
// Include direct children for navigation purposes // Include direct children for navigation purposes
foreach ($cat->get_children() as $ccat) { foreach ($cat->get_children() as $ccat) {
$cats[] = $ccat; $ccatctx = \context_coursecat::instance($ccat->id);
if (!in_array($ccatctx->id,$contextids)) {
$cats[] = $ccat;
}
} }
} }
} }
@ -408,6 +418,11 @@ class courseservice extends \external_api {
} }
$rs->close(); $rs->close();
// Add system context to list if needed.
if (!in_array(1,$contextids)) {
array_unshift($contextids,1);
}
$cats = []; $cats = [];
// If the reference context id is not in the list, push it there // If the reference context id is not in the list, push it there
if ($refctxid > 1 && !in_array($refctxid, $contextids)) { if ($refctxid > 1 && !in_array($refctxid, $contextids)) {
@ -451,7 +466,10 @@ class courseservice extends \external_api {
if ($operation == "view" && $ctxid == $refctxid) { if ($operation == "view" && $ctxid == $refctxid) {
// Include direct children for navigation purposes // Include direct children for navigation purposes
foreach ($cat->get_children() as $ccat) { foreach ($cat->get_children() as $ccat) {
$cats[] = $ccat; $ccatctx = \context_coursecat::instance($ccat->id);
if (!in_array($ccatctx->id,$contextids)) {
$cats[] = $ccat;
}
} }
} }
} }

View File

@ -107,9 +107,9 @@ print $OUTPUT->header();
</div> </div>
<div v-cloak> <div v-cloak>
<div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'> <div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'>
<b-form-select text='<?php print($contextname);?>' :value="contextid"> <b-form-select text='<?php print($contextname);?>' :value="contextid" @change='switchContext'>
<b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id" @click='switchContext(ctx)' <b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id"
:active="ctx.context_id == contextid" :class="(ctx.studyplancount > 0) ? 'font-weight-bold' : ''" :class="(ctx.studyplancount > 0) ? 'font-weight-bold' : '' + (ctx.context_id == contextid)?' active':''"
><span v-for="(p, i) in ctx.category.path" ><span v-for="(p, i) in ctx.category.path"
><span v-if="i>0"> / </span>{{ p }}</span> <span>({{ ctx.studyplancount }})</span> ><span v-if="i>0"> / </span>{{ p }}</span> <span>({{ ctx.studyplancount }})</span>
</b-form-select-option> </b-form-select-option>

View File

@ -104,9 +104,9 @@ print $OUTPUT->header();
</div> </div>
<div v-cloak> <div v-cloak>
<div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'> <div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'>
<b-form-select text='<?php print($contextname);?>' :value="contextid"> <b-form-select text='<?php print($contextname);?>' :value="contextid" @change='switchContext'>
<b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id" @click='switchContext(ctx)' <b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id"
:active="ctx.context_id == contextid" :class="(ctx.studyplancount > 0) ? 'font-weight-bold' : ''" :class="(ctx.studyplancount > 0) ? 'font-weight-bold' : '' + (ctx.context_id == contextid)?' active':''"
><span v-for="(p, i) in ctx.category.path"><span v-if="i>0"> / </span>{{ p }}</span> ><span v-for="(p, i) in ctx.category.path"><span v-if="i>0"> / </span>{{ p }}</span>
<span>({{ ctx.studyplancount }})</span></b-form-select-option> <span>({{ ctx.studyplancount }})</span></b-form-select-option>
</b-form-select> </b-form-select>