2023-05-17 21:19:14 +02:00
|
|
|
/*eslint no-var: "error" */
|
|
|
|
/*eslint no-unused-vars: "off" */
|
|
|
|
/*eslint linebreak-style: "off" */
|
|
|
|
/*eslint no-trailing-spaces: "off" */
|
|
|
|
/*eslint-env es6*/
|
|
|
|
// Put this file in path/to/plugin/amd/src
|
|
|
|
// You can call it anything you like
|
|
|
|
|
|
|
|
import {call} from 'core/ajax';
|
|
|
|
import notification from 'core/notification';
|
|
|
|
|
2023-08-22 23:12:33 +02:00
|
|
|
import Vue from './vue/vue';
|
2023-08-19 17:54:40 +02:00
|
|
|
|
|
|
|
import Debugger from './util/debugger';
|
|
|
|
import {load_strings} from './util/string-helper';
|
2023-07-18 16:12:31 +02:00
|
|
|
import {ProcessStudyplan} from './studyplan-processor';
|
2023-11-13 22:18:28 +01:00
|
|
|
import {studyplanTiming} from './util/date-helper';
|
2023-05-17 21:19:14 +02:00
|
|
|
|
|
|
|
import RVComponents from './report-viewer-components';
|
|
|
|
Vue.use(RVComponents);
|
2023-09-03 17:12:44 +02:00
|
|
|
import TSComponents from './treestudyplan-components';
|
2023-05-17 21:19:14 +02:00
|
|
|
import ModalComponents from './modedit-modal';
|
|
|
|
Vue.use(ModalComponents);
|
|
|
|
|
2023-08-19 17:54:40 +02:00
|
|
|
import PortalVue from './portal-vue/portal-vue.esm';
|
2023-05-17 21:19:14 +02:00
|
|
|
Vue.use(PortalVue);
|
2023-08-31 07:40:55 +02:00
|
|
|
import BootstrapVue from './bootstrap-vue/bootstrap-vue';
|
2023-05-17 21:19:14 +02:00
|
|
|
Vue.use(BootstrapVue);
|
|
|
|
|
|
|
|
|
|
|
|
let debug = new Debugger("treestudyplanviewer");
|
|
|
|
|
|
|
|
let strings = load_strings({
|
|
|
|
studyplan: {
|
|
|
|
studyplan_select_placeholder: 'studyplan_select_placeholder',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the Page
|
|
|
|
* @param {int} contextid The context we should attempt to work in (1:1 related to the category)
|
|
|
|
* @param {int} categoryid The category we shoud attempt to work in (1:1 related to the context)
|
|
|
|
*/
|
2023-08-19 17:54:40 +02:00
|
|
|
export function init(contextid,categoryid) {
|
2023-05-17 21:19:14 +02:00
|
|
|
// Make sure the id's are numeric and integer
|
2023-09-08 12:47:29 +02:00
|
|
|
if(undefined === contextid || !Number.isInteger(Number(contextid)) || contextid < 1 ){ contextid = 1;}
|
2023-08-17 23:29:32 +02:00
|
|
|
else { contextid = Number(contextid);} // ensure a numeric value instead of string
|
|
|
|
if(undefined === categoryid || !Number.isInteger(Number(categoryid))){ categoryid = 0;}
|
|
|
|
else { categoryid = Number(categoryid);} // ensure a numeric value instead of string
|
2023-05-17 21:19:14 +02:00
|
|
|
|
|
|
|
const in_systemcontext = (contextid <= 1);
|
|
|
|
|
|
|
|
let app = new Vue({
|
|
|
|
el: '#root',
|
|
|
|
data: {
|
|
|
|
displayedstudyplan: null,
|
|
|
|
activestudyplan: null,
|
|
|
|
associatedstudents: [],
|
|
|
|
selectedstudent: null,
|
|
|
|
studentstudyplan: null,
|
|
|
|
loadingstudyplan: false,
|
|
|
|
studyplans: [],
|
|
|
|
text: strings.studyplan,
|
|
|
|
toolbox: {
|
|
|
|
right: true,
|
|
|
|
},
|
|
|
|
usedcontexts: [],
|
|
|
|
},
|
|
|
|
async mounted() {
|
|
|
|
call([{
|
|
|
|
methodname: 'local_treestudyplan_list_studyplans',
|
|
|
|
args: {context_id: contextid}
|
2023-12-13 23:49:06 +01:00
|
|
|
}])[0].then(function(response){
|
2023-05-17 21:19:14 +02:00
|
|
|
const timingval = { present: 0, past: 1, future: 2};
|
|
|
|
response.sort((a,b) => {
|
2023-11-13 22:18:28 +01:00
|
|
|
const timinga = studyplanTiming(a);
|
|
|
|
const timingb = studyplanTiming(b);
|
2023-05-17 21:19:14 +02:00
|
|
|
|
|
|
|
const t = timingval[timinga] - timingval[timingb];
|
|
|
|
if(t == 0){
|
|
|
|
// sort by name if timing is equal
|
|
|
|
return a.name.localeCompare(b.name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
app.studyplans = response;
|
|
|
|
// load studyplan from hash if applicable
|
2023-09-03 17:12:44 +02:00
|
|
|
const hash = window.location.hash.replace('#','');
|
2023-05-17 21:19:14 +02:00
|
|
|
const parts = hash.split("-");
|
2023-05-19 16:45:25 +02:00
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
if(!!parts && parts.length > 0){
|
|
|
|
for(let idx in app.studyplans){
|
|
|
|
if(app.studyplans[idx].id == parts[0]){
|
|
|
|
app.selectStudyplan(app.studyplans[idx],parts[1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-13 23:49:06 +01:00
|
|
|
}).catch(notification.exception);
|
2023-05-17 21:19:14 +02:00
|
|
|
call([{
|
2024-02-04 23:18:11 +01:00
|
|
|
methodname: 'local_treestudyplan_list_available_categories',
|
2023-12-13 23:49:06 +01:00
|
|
|
args: { operation: 'view', refcontext_id: contextid}
|
|
|
|
}])[0].then(function(response){
|
2023-05-17 21:19:14 +02:00
|
|
|
const contexts = [];
|
|
|
|
for(const ix in response){
|
2024-02-04 23:18:11 +01:00
|
|
|
const cat = response[ix];
|
|
|
|
if(cat.studyplancount > 0 || cat.context_id == contextid){
|
|
|
|
contexts.push(cat);
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
app.usedcontexts = contexts;
|
2023-12-13 23:49:06 +01:00
|
|
|
}).catch(notification.exception);
|
2023-05-17 21:19:14 +02:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
dropdown_title(){
|
|
|
|
if(this.activestudyplan && this.activestudyplan.name){
|
|
|
|
return this.activestudyplan.name;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return this.text.studyplan_select_placeholder;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
contextid(){
|
|
|
|
return contextid;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2023-12-14 21:42:34 +01:00
|
|
|
switchContext(ctxid){
|
2023-05-17 21:19:14 +02:00
|
|
|
const params = new URLSearchParams(location.search);
|
2023-12-12 23:44:02 +01:00
|
|
|
params.delete('categoryid');
|
2023-12-14 21:42:34 +01:00
|
|
|
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);
|
2023-05-17 21:19:14 +02:00
|
|
|
},
|
|
|
|
closeStudyplan() {
|
|
|
|
app.activestudyplan = null;
|
|
|
|
app.associatedstudents = [];
|
|
|
|
app.studentstudyplan = [];
|
|
|
|
app.displayedstudyplan = null;
|
2023-09-03 17:12:44 +02:00
|
|
|
window.location.hash = '';
|
2023-05-19 16:45:25 +02:00
|
|
|
},
|
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
selectStudyplan(studyplan,studentid){
|
|
|
|
// fetch studyplan
|
|
|
|
app.loadingstudyplan = true;
|
|
|
|
app.activestudyplan = null;
|
|
|
|
app.associatedstudents = [];
|
|
|
|
app.selectedstudent = null;
|
|
|
|
app.studentstudyplan = null;
|
|
|
|
call([{
|
|
|
|
methodname: 'local_treestudyplan_get_studyplan_map',
|
|
|
|
args: { id: studyplan.id}
|
2023-12-13 23:49:06 +01:00
|
|
|
}])[0].then(function(response){
|
2023-05-17 21:19:14 +02:00
|
|
|
app.activestudyplan = ProcessStudyplan(response,true);
|
|
|
|
app.displayedstudyplan = app.activestudyplan;
|
|
|
|
app.loadingstudyplan = false;
|
2023-09-03 17:12:44 +02:00
|
|
|
window.location.hash = app.activestudyplan.id;
|
2023-05-17 21:19:14 +02:00
|
|
|
call([{
|
2024-01-28 22:45:55 +01:00
|
|
|
methodname: 'local_treestudyplan_all_associated_grouped',
|
2023-05-17 21:19:14 +02:00
|
|
|
args: { studyplan_id: studyplan.id}
|
2023-12-13 23:49:06 +01:00
|
|
|
}])[0].then(function(response){
|
2023-05-17 21:19:14 +02:00
|
|
|
app.associatedstudents = response;
|
|
|
|
if(studentid){
|
2024-02-18 13:47:08 +01:00
|
|
|
for(const group of app.associatedstudents) {
|
|
|
|
for(const student of group.users){
|
|
|
|
if(student.id == studentid){
|
|
|
|
app.showStudentView(student);
|
|
|
|
break;
|
|
|
|
}
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-12-13 23:49:06 +01:00
|
|
|
}).catch(notification.exception);
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-12-13 23:49:06 +01:00
|
|
|
}).catch(function(error){
|
2023-05-17 21:19:14 +02:00
|
|
|
notification.exception(error);
|
|
|
|
app.loadingstudyplan = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
showStudentView(student){
|
|
|
|
app.selectedstudent = student;
|
|
|
|
app.studentstudyplan = null;
|
2024-01-28 14:41:35 +01:00
|
|
|
if (student) {
|
|
|
|
app.loadingstudyplan = true;
|
|
|
|
call([{
|
|
|
|
methodname: 'local_treestudyplan_get_user_studyplan',
|
|
|
|
args: { userid: student.id, studyplanid: app.activestudyplan.id}
|
|
|
|
}])[0].then(function(response){
|
|
|
|
app.studentstudyplan = ProcessStudyplan(response,false);
|
|
|
|
app.displayedstudyplan = app.studentstudyplan;
|
|
|
|
app.loadingstudyplan = false;
|
|
|
|
window.location.hash = app.activestudyplan.id + "-" + student.id;
|
|
|
|
}).catch(function(error){
|
|
|
|
notification.exception(error);
|
|
|
|
app.loadingstudyplan = false;
|
|
|
|
});
|
|
|
|
}
|
2023-05-17 21:19:14 +02:00
|
|
|
|
|
|
|
},
|
|
|
|
showOverview(){
|
|
|
|
app.selectedstudent = null;
|
|
|
|
app.studentstudyplan = null;
|
|
|
|
app.displayedstudyplan = app.activestudyplan;
|
2023-09-03 17:12:44 +02:00
|
|
|
window.location.hash = app.activestudyplan.id;
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
2023-05-19 16:45:25 +02:00
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|