Code Cleanup
This commit is contained in:
parent
3bef1118b2
commit
c2c5383e10
|
@ -2,15 +2,15 @@
|
||||||
/* eslint no-unused-vars: "off" */
|
/* eslint no-unused-vars: "off" */
|
||||||
/* eslint linebreak-style: "off" */
|
/* eslint linebreak-style: "off" */
|
||||||
/* eslint no-trailing-spaces: "off" */
|
/* eslint no-trailing-spaces: "off" */
|
||||||
|
/* eslint no-empty-function: "off" */
|
||||||
/* eslint-env es6*/
|
/* eslint-env es6*/
|
||||||
// Put this file in path/to/plugin/amd/src
|
// Put this file in path/to/plugin/amd/src
|
||||||
// You can call it anything you like
|
// You can call it anything you like
|
||||||
|
|
||||||
import {get_string,get_strings} from 'core/str';
|
|
||||||
import {call} from 'core/ajax';
|
import {call} from 'core/ajax';
|
||||||
import notification from 'core/notification';
|
import notification from 'core/notification';
|
||||||
|
|
||||||
//import {resetAllFormDirtyStates} from 'core_form/changechecker'; // Moodle 4.00+ only
|
// Commented out: import {resetAllFormDirtyStates} from 'core_form/changechecker'; // Moodle 4.00+ only
|
||||||
|
|
||||||
import Vue from './vue/vue';
|
import Vue from './vue/vue';
|
||||||
|
|
||||||
|
@ -47,16 +47,15 @@ import('core_form/changechecker').then((ns) => {
|
||||||
if (ns.resetAllFormDirtyStates) {
|
if (ns.resetAllFormDirtyStates) {
|
||||||
resetAllFormDirtyStates = ns.resetAllFormDirtyStates;
|
resetAllFormDirtyStates = ns.resetAllFormDirtyStates;
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}).catch(()=>{});
|
}).catch(()=>{});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let strings = loadStrings({
|
let strings = loadStrings({
|
||||||
studyplan: {
|
studyplan: {
|
||||||
studyplan_select_placeholder: 'studyplan_select_placeholder',
|
'studyplan_select_placeholder': 'studyplan_select_placeholder',
|
||||||
advanced_import_from_file: 'advanced_import_from_file',
|
'advanced_import_from_file': 'advanced_import_from_file',
|
||||||
advanced_create_from_template: 'advanced_create_from_template',
|
'advanced_create_from_template': 'advanced_create_from_template',
|
||||||
studyplan_add: "studyplan_add",
|
'studyplan_add': "studyplan_add",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -68,10 +67,16 @@ let strings = loadStrings({
|
||||||
*/
|
*/
|
||||||
export function init(contextid, categoryid, options) {
|
export function init(contextid, categoryid, options) {
|
||||||
// Make sure the id's are numeric and integer
|
// Make sure the id's are numeric and integer
|
||||||
if(undefined === contextid || !Number.isInteger(Number(contextid)) || contextid < 1 ){ contextid = 1;}
|
if (undefined === contextid || !Number.isInteger(Number(contextid)) || contextid < 1) {
|
||||||
else { contextid = Number(contextid);} // ensure a numeric value instead of string
|
contextid = 1;
|
||||||
if(undefined === categoryid || !Number.isInteger(Number(categoryid))){ categoryid = 0;}
|
} else {
|
||||||
else { categoryid = Number(categoryid);} // ensure a numeric value instead of string
|
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
|
||||||
|
}
|
||||||
|
|
||||||
debug.info("options", options);
|
debug.info("options", options);
|
||||||
if (options !== null && typeof options === 'object' && !Array.isArray(options)) {
|
if (options !== null && typeof options === 'object' && !Array.isArray(options)) {
|
||||||
|
@ -98,7 +103,7 @@ export function init(contextid,categoryid,options) {
|
||||||
enddate: '',
|
enddate: '',
|
||||||
context: contextid,
|
context: contextid,
|
||||||
aggregation: options.defaultAggregation,
|
aggregation: options.defaultAggregation,
|
||||||
aggregation_config: '',
|
'aggregation_config': '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -118,7 +123,7 @@ export function init(contextid,categoryid,options) {
|
||||||
app.activestudyplan = null;
|
app.activestudyplan = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove studyplan from index list
|
// Remove studyplan from index list
|
||||||
let index = null;
|
let index = null;
|
||||||
for (let idx in app.studyplans) {
|
for (let idx in app.studyplans) {
|
||||||
if (app.studyplans[idx].id == studyplan.id) {
|
if (app.studyplans[idx].id == studyplan.id) {
|
||||||
|
@ -141,11 +146,10 @@ export function init(contextid,categoryid,options) {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
premiumenabled,
|
premiumenabled,
|
||||||
dropdown_title(){
|
dropdownTitle() {
|
||||||
if (this.activestudyplan && this.activestudyplan.name) {
|
if (this.activestudyplan && this.activestudyplan.name) {
|
||||||
return this.activestudyplan.name;
|
return this.activestudyplan.name;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
return this.text.studyplan_select_placeholder;
|
return this.text.studyplan_select_placeholder;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -165,20 +169,20 @@ export function init(contextid,categoryid,options) {
|
||||||
initialize() {
|
initialize() {
|
||||||
call([{
|
call([{
|
||||||
methodname: 'local_treestudyplan_list_studyplans',
|
methodname: 'local_treestudyplan_list_studyplans',
|
||||||
args: { context_id: contextid}
|
args: {'context_id': contextid}
|
||||||
}])[0].then(function(response) {
|
}])[0].then(function(response) {
|
||||||
const timingval = { future: 0, present: 1, past: 2, };
|
const timingval = {future: 0, present: 1, past: 2};
|
||||||
response.sort((a, b) => {
|
response.sort((a, b) => {
|
||||||
const timinga = studyplanTiming(a);
|
const timinga = studyplanTiming(a);
|
||||||
const timingb = studyplanTiming(b);
|
const timingb = 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,7 +190,7 @@ export function init(contextid,categoryid,options) {
|
||||||
});
|
});
|
||||||
app.studyplans = response;
|
app.studyplans = response;
|
||||||
|
|
||||||
// load studyplan from hash if applicable
|
// Load studyplan from hash if applicable
|
||||||
const hash = location.hash.replace('#', '');
|
const hash = location.hash.replace('#', '');
|
||||||
if (hash) {
|
if (hash) {
|
||||||
const id = hash;
|
const id = hash;
|
||||||
|
@ -197,13 +201,15 @@ export function init(contextid,categoryid,options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}).catch(notification.exception);
|
}).catch(notification.exception);
|
||||||
|
|
||||||
call([{
|
call([{
|
||||||
methodname: 'local_treestudyplan_list_available_categories',
|
methodname: 'local_treestudyplan_list_available_categories',
|
||||||
args: { operation: 'edit', refcontext_id: contextid}
|
args: {operation: 'edit', 'refcontext_id': contextid}
|
||||||
}])[0].then(function(response) {
|
}])[0].then(function(response) {
|
||||||
app.usedcontexts = response;
|
app.usedcontexts = response;
|
||||||
|
return;
|
||||||
}).catch(notification.exception);
|
}).catch(notification.exception);
|
||||||
|
|
||||||
this.refreshTemplateCount();
|
this.refreshTemplateCount();
|
||||||
|
@ -214,6 +220,7 @@ export function init(contextid,categoryid,options) {
|
||||||
args: { }
|
args: { }
|
||||||
}])[0].then(function(response) {
|
}])[0].then(function(response) {
|
||||||
app.templatecount = response;
|
app.templatecount = response;
|
||||||
|
return;
|
||||||
}).catch(notification.exception);
|
}).catch(notification.exception);
|
||||||
},
|
},
|
||||||
closeStudyplan() {
|
closeStudyplan() {
|
||||||
|
@ -221,7 +228,7 @@ export function init(contextid,categoryid,options) {
|
||||||
window.location.hash = '';
|
window.location.hash = '';
|
||||||
},
|
},
|
||||||
movedStudyplan(plan, from, to) {
|
movedStudyplan(plan, from, to) {
|
||||||
// reload the page in the new context (needed, since a number of links are not reactive in the page)
|
// 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);
|
const params = new URLSearchParams(location.search);
|
||||||
params.delete('categoryid');
|
params.delete('categoryid');
|
||||||
params.set("contextid", to);
|
params.set("contextid", to);
|
||||||
|
@ -254,7 +261,7 @@ export function init(contextid,categoryid,options) {
|
||||||
}, 50);
|
}, 50);
|
||||||
},
|
},
|
||||||
selectStudyplan(studyplanid) {
|
selectStudyplan(studyplanid) {
|
||||||
// fetch studyplan
|
// Fetch studyplan
|
||||||
app.loadingstudyplan = true;
|
app.loadingstudyplan = true;
|
||||||
app.activestudyplan = null;
|
app.activestudyplan = null;
|
||||||
call([{
|
call([{
|
||||||
|
@ -265,12 +272,13 @@ export function init(contextid,categoryid,options) {
|
||||||
debug.info('studyplan processed');
|
debug.info('studyplan processed');
|
||||||
app.loadingstudyplan = false;
|
app.loadingstudyplan = false;
|
||||||
window.location.hash = app.activestudyplan.id;
|
window.location.hash = app.activestudyplan.id;
|
||||||
|
return;
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
notification.exception(error);
|
notification.exception(error);
|
||||||
app.loadingstudyplan = false;
|
app.loadingstudyplan = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
import_studyplan(){
|
importStudyplan() {
|
||||||
const self = this;
|
const self = this;
|
||||||
upload((filename, content)=>{
|
upload((filename, content)=>{
|
||||||
call([{
|
call([{
|
||||||
|
@ -278,7 +286,7 @@ export function init(contextid,categoryid,options) {
|
||||||
args: {
|
args: {
|
||||||
content: content,
|
content: content,
|
||||||
format: "application/json",
|
format: "application/json",
|
||||||
context_id: contextid,
|
'context_id': contextid,
|
||||||
},
|
},
|
||||||
}])[0].then(function(response) {
|
}])[0].then(function(response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
@ -286,27 +294,10 @@ export function init(contextid,categoryid,options) {
|
||||||
} else {
|
} else {
|
||||||
debug.error("Import failed: ", response.msg);
|
debug.error("Import failed: ", response.msg);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}).catch(notification.exception);
|
}).catch(notification.exception);
|
||||||
}, "application/json");
|
}, "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
|
|
||||||
},
|
|
||||||
}])[0].then(function(response){
|
|
||||||
|
|
||||||
download(plan.shortname+".json",response.content,response.format);
|
|
||||||
}).catch(notification.exception);
|
|
||||||
},
|
|
||||||
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user