Optimization when block not relevant

This commit is contained in:
PMKuipers 2023-08-18 19:29:56 +02:00
parent 6a5de18359
commit a669e34796
2 changed files with 57 additions and 56 deletions

View File

@ -43,64 +43,65 @@ let strings = load_strings({
* @param {Object} arg Arguments passed * @param {Object} arg Arguments passed
*/ */
export function init(type="myreport",arg) { export function init(type="myreport",arg) {
// Make sure on window resize, the line wrappers are repositioned, to fix scrolling issues // Save time by only starting up the Vue app if the required block element is present
window.addEventListener('resize',fixLineWrappers); const blockelement = document.getElementById('block_mytreestudyplan');
let app = new Vue({ if(blockelement){
el: '#block_mytreestudyplan', const app = new Vue({
data: { el: '#block_mytreestudyplan',
"studyplans": [], data: {
}, "studyplans": [],
mounted() { },
let call_method; mounted() {
let call_args; let call_method;
if(type == "teacher"){ let call_args;
call_method = 'local_treestudyplan_get_teacher_studyplan'; if(type == "teacher"){
call_args = {}; call_method = 'local_treestudyplan_get_teacher_studyplan';
} call_args = {};
else if(type == "teaching"){ }
call_method = 'local_treestudyplan_get_teaching_studyplans'; else if(type == "teaching"){
call_args = {}; call_method = 'local_treestudyplan_get_teaching_studyplans';
} call_args = {};
else{ }
call_method = 'local_treestudyplan_get_own_studyplan'; else{
call_args = {}; call_method = 'local_treestudyplan_get_own_studyplan';
} call_args = {};
call([{ }
methodname: call_method, call([{
args: call_args methodname: call_method,
}])[0].done(function(response){ args: call_args
debug.info("Studyplans:",response); }])[0].done(function(response){
const timingval = { future: 0, present: 1, past: 2, }; debug.info("Studyplans:",response);
response.sort((a,b) => { const timingval = { future: 0, present: 1, past: 2, };
const timinga = TSComponents.studyplanTiming(a); response.sort((a,b) => {
const timingb = TSComponents.studyplanTiming(b); const timinga = TSComponents.studyplanTiming(a);
const timingb = TSComponents.studyplanTiming(b);
let t = timingval[timinga] - timingval[timingb]; let t = timingval[timinga] - timingval[timingb];
if(t == 0){ if(t == 0){
// sort by start date if timing is equal // sort by start date if timing is equal
t = new Date(b.startdate).getTime() - new Date(a.startdate).getTime(); t = new Date(b.startdate).getTime() - new Date(a.startdate).getTime();
if (t == 0) { if (t == 0) {
// sort by name if timing is equal // sort by name if timing is equal
t = a.name.localeCompare(b.name); t = a.name.localeCompare(b.name);
}
} }
} return t;
return t; });
}); app.studyplans = ProcessStudyplans(response);
app.studyplans = ProcessStudyplans(response); }).fail(notification.exception);
}).fail(notification.exception);
},
created() {
}, },
updated() { created() {
},
methods: { },
updated() {
}, },
}); methods: {
},
});
}
} }

View File

@ -1,6 +1,6 @@
<?php <?php
$plugin->component = 'block_mytreestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494) $plugin->component = 'block_mytreestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494)
$plugin->version = 2023081600; // YYYYMMDDHH (year, month, day, iteration) $plugin->version = 2023081800; // YYYYMMDDHH (year, month, day, iteration)
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11) $plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11)
$plugin->dependencies = [ $plugin->dependencies = [