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

View File

@ -1,6 +1,6 @@
<?php
$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->dependencies = [