This repository has been archived on 2025-01-01. You can view files and clone it, but cannot push or open issues or pull requests.
moodle-local_treestudyplan/amd/src/page-result-overview.js

122 lines
3.9 KiB
JavaScript
Raw Normal View History

2024-06-03 23:24:16 +02:00
/* eslint no-var: "error" */
/* eslint no-unused-vars: "off" */
/* eslint linebreak-style: "off" */
/* eslint no-trailing-spaces: "off" */
/* eslint-env es6*/
2024-02-09 14:48:15 +01:00
import {call} from 'core/ajax';
import notification from 'core/notification';
import Vue from './vue/vue';
import Debugger from './util/debugger';
2024-06-03 23:24:16 +02:00
import {loadStrings} from './util/string-helper';
2024-02-09 14:48:15 +01:00
import SRComponents from './studyplan-report-components';
Vue.use(SRComponents);
2024-02-18 23:27:57 +01:00
import RVComponents from './report-viewer-components';
Vue.use(RVComponents);
2024-02-09 14:48:15 +01:00
import ModalComponents from './modedit-modal';
Vue.use(ModalComponents);
import PortalVue from './portal-vue/portal-vue.esm';
Vue.use(PortalVue);
import BootstrapVue from './bootstrap-vue/bootstrap-vue';
Vue.use(BootstrapVue);
let debug = new Debugger("treestudyplanviewer");
2024-06-03 23:24:16 +02:00
let strings = loadStrings({
studyplanReport: {
studyplan: 'studyplan',
page: 'studyplanpage',
periods: 'periods',
period: 'period',
loading: 'loading@core',
all: 'all@core',
from: 'from@core',
to: 'to@core',
2024-02-09 14:48:15 +01:00
},
});
/**
* Initialize the Page
* @param {Number} studyplanid The id of the studyplan we need to view
* @param {Number} pageid The id of the studyplan page we need to view
* @param {Number} firstperiod The number of the first period to view
* @param {Number} lastperiod The number of the last period to view
2024-02-09 14:48:15 +01:00
*/
export function init(studyplanid, pageid, firstperiod, lastperiod) {
if (undefined === pageid || !Number.isInteger(Number(pageid)) ||
undefined === studyplanid || !Number.isInteger(Number(studyplanid))) {
debug.error("Error: studyplan id and page id not provided as integer numbers to script.",
studyplanid, pageid, firstperiod, lastperiod);
return; // Do not continue if plan and page are not proper integers
}
// Ensure a numeric value instead of string.
studyplanid = Number(studyplanid);
pageid = Number(pageid);
2024-02-09 14:48:15 +01:00
// Startup app.
2024-02-09 14:48:15 +01:00
const app = new Vue({
el: '#root',
data: {
structure: null,
studyplan: null,
page: null,
2024-06-03 23:24:16 +02:00
text: strings.studyplanReport,
2024-02-09 14:48:15 +01:00
},
created() {
// On creation, load the page as specified
2024-06-03 23:24:16 +02:00
this.loadStructure(pageid, firstperiod, lastperiod);
2024-02-09 14:48:15 +01:00
},
computed: {
},
methods: {
2024-06-03 23:24:16 +02:00
loadStructure(pageid, firstperiod, lastperiod) {
const self = this;
this.structure = null; // Starts loading icon. Hides old data.
call([{
methodname: 'local_treestudyplan_get_report_structure',
2024-06-03 23:24:16 +02:00
args: {pageid: pageid,
2024-02-18 23:27:57 +01:00
firstperiod: firstperiod,
lastperiod: lastperiod
}
2024-06-03 23:24:16 +02:00
}])[0].then((response) => {
self.structure = response;
self.studyplan = response.studyplan;
self.page = response.page;
2024-06-03 23:24:16 +02:00
return;
}).catch(notification.exception);
},
selectedPage(e) {
2024-06-03 23:24:16 +02:00
debug.info("SelectedPage", e);
const pageid = e.target.value;
this.loadStructure(pageid);
},
selectedFirstPeriod(e) {
2024-06-03 23:24:16 +02:00
debug.info("selectedFirstPeriod", e);
let f = e.target.value;
let l = this.structure.lastperiod;
2024-06-03 23:24:16 +02:00
if (l < f) {
l = f;
}
2024-06-03 23:24:16 +02:00
this.loadStructure(this.page.id, f, l);
},
selectedLastPeriod(e) {
2024-06-03 23:24:16 +02:00
debug.info("selectedLastPeriod", e);
let f = this.structure.firstperiod;
let l = e.target.value;
2024-06-03 23:24:16 +02:00
if (l < f) {
l = f;
}
2024-06-03 23:24:16 +02:00
this.loadStructure(this.page.id, f, l);
},
2024-02-09 14:48:15 +01:00
},
});
}