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 {get_string,get_strings} from 'core/str';
|
|
|
|
import {call} from 'core/ajax';
|
|
|
|
import notification from 'core/notification';
|
2023-08-19 17:54:40 +02:00
|
|
|
|
2023-08-22 23:12:33 +02:00
|
|
|
import Vue from './vue/vue';
|
|
|
|
|
2023-08-19 17:54:40 +02:00
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
import EditorComponents from './studyplan-editor-components';
|
2023-08-19 17:54:40 +02:00
|
|
|
Vue.use(EditorComponents);
|
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
import TSComponents from './treestudyplan-components';
|
2023-08-19 17:54:40 +02:00
|
|
|
Vue.use(TSComponents);
|
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
import ModalComponents from './modedit-modal';
|
2023-08-19 17:54:40 +02:00
|
|
|
Vue.use(ModalComponents);
|
|
|
|
import Debugger from './util/debugger';
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-08-19 17:54:40 +02:00
|
|
|
import {load_strings} from './util/string-helper';
|
2023-07-18 13:19:48 +02:00
|
|
|
import {ProcessStudyplan} from './studyplan-processor';
|
2023-05-17 21:19:14 +02:00
|
|
|
import {download,upload} from './downloader';
|
2023-11-23 07:44:04 +01:00
|
|
|
import {studyplanTiming} from './util/date-helper';
|
2023-05-17 21:19:14 +02:00
|
|
|
|
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);
|
2023-08-19 17:54:40 +02:00
|
|
|
|
2023-08-23 23:03:53 +02:00
|
|
|
import {Drag, Drop, DropList} from './vue-easy-dnd/vue-easy-dnd.esm';
|
2023-05-17 21:19:14 +02:00
|
|
|
Vue.component('drag',Drag);
|
|
|
|
Vue.component('drop',Drop);
|
|
|
|
Vue.component('drop-list',DropList);
|
|
|
|
|
|
|
|
const debug = new Debugger("treestudyplan");
|
|
|
|
|
|
|
|
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-09-09 21:06:11 +02:00
|
|
|
* @param {object} options Options to be passed to this script
|
2023-05-17 21:19:14 +02:00
|
|
|
*/
|
2023-09-09 21:06:11 +02:00
|
|
|
export function init(contextid,categoryid,options) {
|
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
|
|
|
|
2023-09-09 21:06:11 +02:00
|
|
|
debug.info("options",options);
|
|
|
|
if ( options !== null && typeof options === 'object' && !Array.isArray(options) ) {
|
|
|
|
if ( !options.defaultAggregation ) {
|
|
|
|
options.defaultAggregation = "core";
|
|
|
|
}
|
2023-11-27 23:11:17 +01:00
|
|
|
if ( !options.editMode ) {
|
|
|
|
options.editMode = false;
|
|
|
|
}
|
2023-09-09 21:06:11 +02:00
|
|
|
} else {
|
2023-11-27 23:11:17 +01:00
|
|
|
options = { defaultAggregation: "core", editMode: false};
|
2023-09-09 21:06:11 +02:00
|
|
|
}
|
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
// Setup the initial Vue app for this page
|
|
|
|
let app = new Vue({
|
|
|
|
el: '#root',
|
|
|
|
data: {
|
|
|
|
create: {
|
|
|
|
studyplan: {
|
|
|
|
name: '',
|
|
|
|
shortname: '',
|
|
|
|
description: '',
|
2023-08-09 09:48:06 +02:00
|
|
|
idnumber: '',
|
2023-05-17 21:19:14 +02:00
|
|
|
slots : 4,
|
|
|
|
startdate: '2020-08-01',
|
|
|
|
enddate: '',
|
2023-08-07 17:03:49 +02:00
|
|
|
context: contextid,
|
2023-09-09 21:06:11 +02:00
|
|
|
aggregation: options.defaultAggregation,
|
2023-05-17 21:19:14 +02:00
|
|
|
aggregation_config: '',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toolbox: {
|
2023-09-03 20:57:14 +02:00
|
|
|
shown: false,
|
2023-05-17 21:19:14 +02:00
|
|
|
right: true,
|
|
|
|
},
|
2023-12-02 23:22:00 +01:00
|
|
|
filters: {
|
|
|
|
systembadges: "",
|
|
|
|
relatedbadges: "",
|
|
|
|
},
|
2023-05-17 21:19:14 +02:00
|
|
|
activestudyplan: null,
|
2023-12-02 23:22:00 +01:00
|
|
|
activepage: null,
|
2023-05-17 21:19:14 +02:00
|
|
|
loadingstudyplan: false,
|
|
|
|
studyplans: [],
|
|
|
|
frameworks: [],
|
2023-12-02 23:22:00 +01:00
|
|
|
relatedbadges: [],
|
|
|
|
systembadges: [],
|
2023-05-17 21:19:14 +02:00
|
|
|
courses: [],
|
|
|
|
text: strings.studyplan,
|
|
|
|
usedcontexts: [],
|
2023-11-27 23:11:17 +01:00
|
|
|
initialEditMode: !!options.editMode,
|
2023-05-17 21:19:14 +02:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.$root.$on('studyplanRemoved',(studyplan)=>{
|
2023-09-08 12:47:29 +02:00
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
if(app.activestudyplan == studyplan){
|
|
|
|
app.activestudyplan = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove studyplan from index list
|
|
|
|
let index = null;
|
|
|
|
for(let idx in app.studyplans){
|
|
|
|
if(app.studyplans[idx].id == studyplan.id){
|
|
|
|
index = idx;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(index){
|
|
|
|
app.studyplans.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
|
|
|
mounted() {
|
2023-12-02 23:22:00 +01:00
|
|
|
this.initialize();
|
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;
|
2023-08-04 11:54:16 +02:00
|
|
|
},
|
|
|
|
filterComponentType(){
|
|
|
|
return {
|
2023-08-15 15:34:53 +02:00
|
|
|
item: false,
|
|
|
|
component: true,
|
2023-08-04 11:54:16 +02:00
|
|
|
span: 1,
|
|
|
|
type: 'filter',
|
|
|
|
};
|
|
|
|
},
|
2023-05-17 21:19:14 +02:00
|
|
|
},
|
|
|
|
methods: {
|
2023-12-02 23:22:00 +01:00
|
|
|
initialize() {
|
|
|
|
call([{
|
|
|
|
methodname: 'local_treestudyplan_list_studyplans',
|
|
|
|
args: { context_id: contextid}
|
|
|
|
}])[0].then(function(response){
|
|
|
|
const timingval = { future: 0, present: 1, past: 2, };
|
|
|
|
response.sort((a,b) => {
|
|
|
|
const timinga = studyplanTiming(a);
|
|
|
|
const timingb = 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
});
|
|
|
|
app.studyplans = response;
|
|
|
|
|
|
|
|
// load studyplan from hash if applicable
|
|
|
|
const hash = location.hash.replace('#','');
|
|
|
|
if(hash){
|
2024-02-02 23:09:16 +01:00
|
|
|
const id = hash;
|
|
|
|
app.selectStudyplan(id);
|
2023-12-02 23:22:00 +01:00
|
|
|
}
|
|
|
|
}).catch(notification.exception);
|
|
|
|
call([{
|
|
|
|
methodname: 'local_treestudyplan_map_categories',
|
2024-02-02 23:36:56 +01:00
|
|
|
args: { }
|
2023-12-02 23:22:00 +01:00
|
|
|
}])[0].then(function(response){
|
|
|
|
app.courses = response;
|
|
|
|
}).catch(notification.exception);
|
|
|
|
call([{
|
|
|
|
methodname: 'local_treestudyplan_list_used_categories',
|
2023-12-13 23:49:06 +01:00
|
|
|
args: { operation: 'edit', refcontext_id: contextid}
|
2023-12-02 23:22:00 +01:00
|
|
|
}])[0].then(function(response){
|
|
|
|
app.usedcontexts = response;
|
|
|
|
}).catch(notification.exception);
|
|
|
|
this.filter_systembadges();
|
|
|
|
},
|
2023-05-17 21:19:14 +02:00
|
|
|
closeStudyplan() {
|
|
|
|
app.activestudyplan = null;
|
2023-09-03 17:12:44 +02:00
|
|
|
window.location.hash = '';
|
2023-09-08 12:47:29 +02:00
|
|
|
},
|
2023-05-17 21:19:14 +02:00
|
|
|
movedStudyplan(plan,from,to) {
|
|
|
|
// reload the page in the new context (needed, since a number of links are not reactive in the page)
|
|
|
|
const params = new URLSearchParams(location.search);
|
|
|
|
params.delete('categoryid');
|
|
|
|
params.set("contextid", to);
|
2023-12-12 23:44:02 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
// Reload page in a timeout to give other form javasccript the change to remove the beforeunload handler.
|
|
|
|
window.location.search = params.toString();
|
|
|
|
},50);
|
2023-05-17 21:19:14 +02:00
|
|
|
},
|
|
|
|
onStudyPlanCreated(newstudyplan){
|
2023-12-12 23:44:02 +01:00
|
|
|
if (newstudyplan.context_id != contextid) {
|
|
|
|
// Study plan has changed context id - reload page into new context id and show the plan
|
|
|
|
const params = new URLSearchParams(location.search);
|
|
|
|
params.delete('categoryid');
|
|
|
|
params.set("contextid", newstudyplan.context_id);
|
|
|
|
setTimeout(() => {
|
|
|
|
// Reload page in a timeout to give other form javasccript the change to remove the beforeunload handler.
|
|
|
|
window.location = window.location.pathname + "?" + params.toString() + "#" + newstudyplan.id;
|
|
|
|
},50);
|
|
|
|
} else {
|
|
|
|
app.studyplans.push(newstudyplan);
|
|
|
|
app.selectStudyplan(newstudyplan);
|
|
|
|
}
|
2023-05-17 21:19:14 +02:00
|
|
|
},
|
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
|
|
|
},
|
2024-02-02 23:09:16 +01:00
|
|
|
selectStudyplan(studyplanid){
|
2023-05-17 21:19:14 +02:00
|
|
|
// fetch studyplan
|
|
|
|
app.loadingstudyplan = true;
|
|
|
|
app.activestudyplan = null;
|
|
|
|
call([{
|
|
|
|
methodname: 'local_treestudyplan_get_studyplan_map',
|
2024-02-02 23:09:16 +01:00
|
|
|
args: { id: studyplanid}
|
2023-12-13 23:49:06 +01:00
|
|
|
}])[0].then(function(response){
|
2023-11-05 15:49:32 +01:00
|
|
|
app.activestudyplan = ProcessStudyplan(response);
|
2023-05-17 21:19:14 +02:00
|
|
|
debug.info('studyplan processed');
|
|
|
|
app.loadingstudyplan = false;
|
2023-09-03 17:12:44 +02:00
|
|
|
window.location.hash = app.activestudyplan.id;
|
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;
|
|
|
|
});
|
|
|
|
},
|
2023-12-02 23:22:00 +01:00
|
|
|
onPageChange(page) {
|
|
|
|
this.activepage = page;
|
|
|
|
this.filter_relatedbadges();
|
|
|
|
},
|
2023-05-17 21:19:14 +02:00
|
|
|
import_studyplan(){
|
2023-12-02 23:22:00 +01:00
|
|
|
const self = this;
|
2023-05-17 21:19:14 +02:00
|
|
|
upload((filename,content)=>{
|
|
|
|
call([{
|
|
|
|
methodname: 'local_treestudyplan_import_plan',
|
|
|
|
args: {
|
|
|
|
content: content,
|
|
|
|
format: "application/json",
|
2023-05-19 16:45:15 +02:00
|
|
|
context_id: contextid,
|
2023-05-17 21:19:14 +02:00
|
|
|
},
|
2023-12-13 23:49:06 +01:00
|
|
|
}])[0].then(function(response){
|
2023-05-17 21:19:14 +02:00
|
|
|
if(response.success){
|
2023-12-02 23:22:00 +01:00
|
|
|
self.initialize();
|
2023-05-17 21:19:14 +02:00
|
|
|
} else {
|
|
|
|
debug.error("Import failed: ",response.msg);
|
|
|
|
}
|
2023-09-08 12:47:29 +02:00
|
|
|
|
2023-12-13 23:49:06 +01:00
|
|
|
}).catch(notification.exception);
|
2023-05-17 21:19:14 +02:00
|
|
|
}, "application/json");
|
|
|
|
},
|
|
|
|
export_plan(plan,format){
|
|
|
|
let self = this;
|
|
|
|
if(format == undefined || !["json","csv"].includes(format)){
|
|
|
|
format = "json";
|
|
|
|
}
|
|
|
|
call([{
|
|
|
|
methodname: 'local_treestudyplan_export_plan',
|
|
|
|
args: {
|
|
|
|
studyplan_id: plan.id,
|
|
|
|
format: format
|
|
|
|
},
|
2023-12-13 23:49:06 +01:00
|
|
|
}])[0].then(function(response){
|
2023-09-08 12:47:29 +02:00
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
download(plan.shortname+".json",response.content,response.format);
|
2023-12-13 23:49:06 +01:00
|
|
|
}).catch(notification.exception);
|
2023-05-17 21:19:14 +02:00
|
|
|
},
|
2023-09-03 20:57:14 +02:00
|
|
|
toggletoolbox(event) {
|
|
|
|
debug.info(event);
|
|
|
|
this.toolbox.shown = event;
|
2023-12-02 23:22:00 +01:00
|
|
|
},
|
|
|
|
filter_systembadges() {
|
|
|
|
const self = this;
|
|
|
|
call([{
|
|
|
|
methodname: 'local_treestudyplan_search_badges',
|
|
|
|
args: {
|
|
|
|
search: this.filters.systembadges || ""
|
|
|
|
}
|
|
|
|
}])[0].then(function(response){
|
|
|
|
self.systembadges = response;
|
|
|
|
}).catch(notification.exception);
|
|
|
|
},
|
|
|
|
filter_relatedbadges() {
|
|
|
|
const self = this;
|
|
|
|
if (this.activepage) {
|
|
|
|
call([{
|
|
|
|
methodname: 'local_treestudyplan_search_related_badges',
|
|
|
|
args: {
|
|
|
|
page_id: this.activepage.id,
|
|
|
|
search: this.filters.relatedbadges || ""
|
|
|
|
}
|
|
|
|
}])[0].then(function(response){
|
|
|
|
self.relatedbadges = response;
|
|
|
|
}).catch(notification.exception);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
reset_systembadges() {
|
|
|
|
this.filters.systembadges = "";
|
|
|
|
this.filter_systembadges();
|
|
|
|
},
|
|
|
|
reset_relatedbadges() {
|
|
|
|
this.filters.relatedbadges = "";
|
|
|
|
this.filter_relatedbadges();
|
|
|
|
},
|
2023-05-17 21:19:14 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|