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);
}
},
switchContext(cat){
switchContext(ctxid){
const params = new URLSearchParams(location.search);
params.delete('categoryid');
params.set('contextid', cat.context_id);
window.location.search = params.toString();
params.set('contextid', ctxid);
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){
// fetch studyplan

View File

@ -126,11 +126,14 @@ export function init(contextid,categoryid) {
}
},
methods: {
switchContext(cat){
switchContext(ctxid){
const params = new URLSearchParams(location.search);
params.delete('categoryid');
params.set('contextid', cat.context_id);
window.location.search = params.toString();
params.set('contextid', ctxid);
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() {
app.activestudyplan = null;

View File

@ -314,6 +314,11 @@ class courseservice extends \external_api {
$contextids[] = $r->context_id;
}
// Add system context to list if needed.
if (!in_array(1,$contextids)) {
array_unshift($contextids,1);
}
$rs->close();
$cats = [];
@ -332,13 +337,15 @@ class courseservice extends \external_api {
array_reverse(array_slice($refpath,0,$i)),
array_slice($contextids, $idx+1, count($contextids) - 1)
) ;
$found = true;
break;
}
}
if(!$found) {
array_unshift($contextids,$refctxid);
debug::write("After two");
debug::print_r($contextids);
}
} catch(\dml_missing_record_exception $x) {
// ignore context
@ -358,7 +365,10 @@ class courseservice extends \external_api {
if ($operation == "edit" && $ctxid == $refctxid) {
// Include direct children for navigation purposes
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();
// Add system context to list if needed.
if (!in_array(1,$contextids)) {
array_unshift($contextids,1);
}
$cats = [];
// If the reference context id is not in the list, push it there
if ($refctxid > 1 && !in_array($refctxid, $contextids)) {
@ -451,7 +466,10 @@ class courseservice extends \external_api {
if ($operation == "view" && $ctxid == $refctxid) {
// Include direct children for navigation purposes
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 v-cloak>
<div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'>
<b-form-select text='<?php print($contextname);?>' :value="contextid">
<b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id" @click='switchContext(ctx)'
:active="ctx.context_id == contextid" :class="(ctx.studyplancount > 0) ? 'font-weight-bold' : ''"
<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"
: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>({{ ctx.studyplancount }})</span>
</b-form-select-option>

View File

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