From 48e42037619a11e7a922f5c664a355feaefb5594 Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Fri, 7 Jul 2023 21:45:09 +0200 Subject: [PATCH] Reordering --- amd/src/studyplan-editor-components.js | 835 +++++++++++++------------ 1 file changed, 429 insertions(+), 406 deletions(-) diff --git a/amd/src/studyplan-editor-components.js b/amd/src/studyplan-editor-components.js index b147249..f7ebbdf 100644 --- a/amd/src/studyplan-editor-components.js +++ b/amd/src/studyplan-editor-components.js @@ -192,406 +192,6 @@ export default { }); - /* - * T-STUDYPLAN - */ - Vue.component('t-studyplan', { - props: ['value', 'index'], - data() { - return { - config: { - userfields: [ - { key: "selected",}, - { key: "firstname", "sortable": true,}, - { key: "lastname", "sortable": true,}, - ], - cohortfields:[ - { key: "selected",}, - { key: "name", "sortable": true,}, - { key: "context", "sortable": true,}, - ] - }, - create: { - studyline: { - 'name': '', - 'shortname': '', - 'color': '#DDDDDD', - }, - }, - edit: { - studyline: { - editmode: false, - data: { - name: '', - shortname: '', - color: '#DDDDDD', - }, - original: {}, - }, - studyplan: { - data: { - name: '', - shortname: '', - description: '', - slots : 4, - startdate: '2020-08-01', - enddate: '', - aggregation: '', - aggregation_config: '', - aggregation_info: { - useRequiredGrades: true, - useItemCondition: false, - }, - - }, - original: {}, - } - }, - text: strings.studyplan_text, - }; - }, - created() { - - }, - mounted() { - if(this.value.studylines.length == 0){ - // start in editmode if studylines are empty - this.edit.studyline.editmode = true; - } - this.$root.$emit('redrawLines'); - }, - updated() { - console.info("UPDATED Studyplan"); - this.$root.$emit('redrawLines'); - ItemEventBus.$emit('redrawLines'); - }, - computed: { - }, - methods: { - slotsempty(slots) { - if(Array.isArray(slots)){ - let count = 0; - for(let i = 0; i < slots.length; i++) { - if(Array.isArray(slots[i].competencies)){ - count += slots[i].competencies.length; - } - if(Array.isArray(slots[i].filters)){ - count += slots[i].filters.length; - } - } - return (count == 0); - } else { - return false; - } - }, - movedStudyplan(plan,from,to) { - this.$emit('moved',plan,from,to); // Throw the event up.... - }, - addStudyLine(studyplan,newlineinfo) { - call([{ - methodname: 'local_treestudyplan_add_studyline', - args: { - 'studyplan_id': studyplan.id, - 'name': newlineinfo.name, - 'shortname': newlineinfo.shortname, - 'color': newlineinfo.color, - 'sequence': studyplan.studylines.length, - } - }])[0].done(function(response){ - debug.info("New studyline:",response); - studyplan.studylines.push(response); - newlineinfo.name = ''; - newlineinfo.shortname = ''; - newlineinfo.color = "#dddddd"; - }).fail(notification.exception); - }, - editLineStart(line) { - Object.assign(this.edit.studyline.data,line); - this.edit.studyline.original = line; - this.$bvModal.show('modal-edit-studyline-'+this.value.id); - }, - editLineFinish() { - let editedline = this.edit.studyline.data; - let originalline = this.edit.studyline.original; - debug.info('Edit Line',this.edit.studyline); - call([{ - methodname: 'local_treestudyplan_edit_studyline', - args: { 'id': editedline.id, - 'name': editedline.name, - 'shortname': editedline.shortname, - 'color': editedline.color,} - }])[0].done(function(response){ - debug.info('Edit response:', response); - originalline['name'] = response['name']; - originalline['shortname'] = response['shortname']; - originalline['color'] = response['color']; - }).fail(notification.exception); - }, - deleteLine(studyplan,line) { - debug.info('Delete Line',line); - const self=this; - get_strings([ - {key: 'studyline_confirm_remove', param: line.name, component: 'local_treestudyplan' }, - {key: 'delete', component: 'core' }, - ]).then(function(s){ - self.$bvModal.msgBoxConfirm(s[0], { - okTitle: s[1], - okVariant: 'danger', - }).then(function(modalresponse){ - if(modalresponse){ - call([{ - methodname: 'local_treestudyplan_delete_studyline', - args: { 'id': line.id, } - }])[0].done(function(response){ - debug.info('Delete response:', response); - if(response.success == true){ - let index = studyplan.studylines.indexOf(line); - studyplan.studylines.splice(index, 1); - } - }).fail(notification.exception); - } - }); - }); - }, - reorderLines(event,lines){ - debug.info("Reorder lines",event,lines); - - // apply reordering - event.apply(lines); - // send the new sequence to the server - let sequence = []; - for(let idx in lines) - { - sequence.push({'id': lines[idx].id,'sequence': idx}); - } - call([{ - methodname: 'local_treestudyplan_reorder_studylines', - args: { 'sequence': sequence } - }])[0].done(function(response){ - debug.info('Reorder response:', response); - }).fail(notification.exception); - }, - deletePlan(studyplan){ - const self=this; - debug.info('Delete studyplan:', studyplan); - get_strings([ - {key: 'studyplan_confirm_remove', param: studyplan.name, component: 'local_treestudyplan' }, - {key: 'delete', component: 'core' }, - ]).then(function(s){ - self.$bvModal.msgBoxConfirm(s[0], { - okTitle: s[1], - okVariant: 'danger', - }).then(function(modalresponse){ - if(modalresponse){ - call([{ - methodname: 'local_treestudyplan_delete_studyplan', - args: { 'id': studyplan.id, } - }])[0].done(function(response){ - debug.info('Delete response:', response); - if(response.success == true){ - self.$root.$emit("studyplanRemoved",studyplan); - } - }).fail(notification.exception); - } - }); - }); - }, - deleteStudyItem(event){ - debug.info('Delete studyitem:', event); - //const self = this; - let item = event.data; - - call([{ - methodname: 'local_treestudyplan_delete_studyitem', - args: { 'id': item.id, } - }])[0].done(function(response){ - debug.info('Delete response:', response); - if(response.success == true){ - event.source.$emit('cut',event); - } - }).fail(notification.exception); - - }, - } - , - template: - ` -
-
- {{ text.studyline_editmode }} - - - - - - - {{text.edit$core}} - - - {{text.associations}} - - - - -
-
- - - - - -
-
- - - - - {{text.studyline_name}} - - - - - - {{text.studyline_shortname}} - - - - - - {{text.studyline_color}} - - - - - - - - - - - {{ text.studyline_name}} - - - - - - {{ text.studyline_shortname}} - - - - - - {{ text.studyline_color}} - - - - - - - -
- ` - }); - /* * T-STUDYPLAN-ADVANCED */ @@ -841,6 +441,7 @@ export default { ` }); + /* * T-STUDYPLAN-EDIT */ @@ -1444,7 +1045,433 @@ export default { }); /* - * T-STUDYLINE + * T-STUDYPLAN + */ + Vue.component('t-studyplan', { + props: ['value', 'index'], + data() { + return { + config: { + userfields: [ + { key: "selected",}, + { key: "firstname", "sortable": true,}, + { key: "lastname", "sortable": true,}, + ], + cohortfields:[ + { key: "selected",}, + { key: "name", "sortable": true,}, + { key: "context", "sortable": true,}, + ] + }, + create: { + studyline: { + 'name': '', + 'shortname': '', + 'color': '#DDDDDD', + }, + }, + edit: { + studyline: { + editmode: false, + data: { + name: '', + shortname: '', + color: '#DDDDDD', + }, + original: {}, + }, + studyplan: { + data: { + name: '', + shortname: '', + description: '', + slots : 4, + startdate: '2020-08-01', + enddate: '', + aggregation: '', + aggregation_config: '', + aggregation_info: { + useRequiredGrades: true, + useItemCondition: false, + }, + + }, + original: {}, + } + }, + text: strings.studyplan_text, + }; + }, + created() { + + }, + mounted() { + if(this.value.studylines.length == 0){ + // start in editmode if studylines are empty + this.edit.studyline.editmode = true; + } + this.$root.$emit('redrawLines'); + }, + updated() { + console.info("UPDATED Studyplan"); + this.$root.$emit('redrawLines'); + ItemEventBus.$emit('redrawLines'); + }, + computed: { + }, + methods: { + slotsempty(slots) { + if(Array.isArray(slots)){ + let count = 0; + for(let i = 0; i < slots.length; i++) { + if(Array.isArray(slots[i].competencies)){ + count += slots[i].competencies.length; + } + if(Array.isArray(slots[i].filters)){ + count += slots[i].filters.length; + } + } + return (count == 0); + } else { + return false; + } + }, + movedStudyplan(plan,from,to) { + this.$emit('moved',plan,from,to); // Throw the event up.... + }, + addStudyLine(studyplan,newlineinfo) { + call([{ + methodname: 'local_treestudyplan_add_studyline', + args: { + 'studyplan_id': studyplan.id, + 'name': newlineinfo.name, + 'shortname': newlineinfo.shortname, + 'color': newlineinfo.color, + 'sequence': studyplan.studylines.length, + } + }])[0].done(function(response){ + debug.info("New studyline:",response); + studyplan.studylines.push(response); + newlineinfo.name = ''; + newlineinfo.shortname = ''; + newlineinfo.color = "#dddddd"; + }).fail(notification.exception); + }, + editLineStart(line) { + Object.assign(this.edit.studyline.data,line); + this.edit.studyline.original = line; + this.$bvModal.show('modal-edit-studyline-'+this.value.id); + }, + editLineFinish() { + let editedline = this.edit.studyline.data; + let originalline = this.edit.studyline.original; + debug.info('Edit Line',this.edit.studyline); + call([{ + methodname: 'local_treestudyplan_edit_studyline', + args: { 'id': editedline.id, + 'name': editedline.name, + 'shortname': editedline.shortname, + 'color': editedline.color,} + }])[0].done(function(response){ + debug.info('Edit response:', response); + originalline['name'] = response['name']; + originalline['shortname'] = response['shortname']; + originalline['color'] = response['color']; + }).fail(notification.exception); + }, + deleteLine(studyplan,line) { + debug.info('Delete Line',line); + const self=this; + get_strings([ + {key: 'studyline_confirm_remove', param: line.name, component: 'local_treestudyplan' }, + {key: 'delete', component: 'core' }, + ]).then(function(s){ + self.$bvModal.msgBoxConfirm(s[0], { + okTitle: s[1], + okVariant: 'danger', + }).then(function(modalresponse){ + if(modalresponse){ + call([{ + methodname: 'local_treestudyplan_delete_studyline', + args: { 'id': line.id, } + }])[0].done(function(response){ + debug.info('Delete response:', response); + if(response.success == true){ + let index = studyplan.studylines.indexOf(line); + studyplan.studylines.splice(index, 1); + } + }).fail(notification.exception); + } + }); + }); + }, + reorderLines(event,lines){ + debug.info("Reorder lines",event,lines); + + // apply reordering + event.apply(lines); + // send the new sequence to the server + let sequence = []; + for(let idx in lines) + { + sequence.push({'id': lines[idx].id,'sequence': idx}); + } + call([{ + methodname: 'local_treestudyplan_reorder_studylines', + args: { 'sequence': sequence } + }])[0].done(function(response){ + debug.info('Reorder response:', response); + }).fail(notification.exception); + }, + deletePlan(studyplan){ + const self=this; + debug.info('Delete studyplan:', studyplan); + get_strings([ + {key: 'studyplan_confirm_remove', param: studyplan.name, component: 'local_treestudyplan' }, + {key: 'delete', component: 'core' }, + ]).then(function(s){ + self.$bvModal.msgBoxConfirm(s[0], { + okTitle: s[1], + okVariant: 'danger', + }).then(function(modalresponse){ + if(modalresponse){ + call([{ + methodname: 'local_treestudyplan_delete_studyplan', + args: { 'id': studyplan.id, } + }])[0].done(function(response){ + debug.info('Delete response:', response); + if(response.success == true){ + self.$root.$emit("studyplanRemoved",studyplan); + } + }).fail(notification.exception); + } + }); + }); + }, + deleteStudyItem(event){ + debug.info('Delete studyitem:', event); + //const self = this; + let item = event.data; + + call([{ + methodname: 'local_treestudyplan_delete_studyitem', + args: { 'id': item.id, } + }])[0].done(function(response){ + debug.info('Delete response:', response); + if(response.success == true){ + event.source.$emit('cut',event); + } + }).fail(notification.exception); + + }, + } + , + template: + ` +
+
+ {{ text.studyline_editmode }} + + + + + + + {{text.edit$core}} + + + {{text.associations}} + + + + +
+
+ + + + + +
+
+ + + + + {{text.studyline_name}} + + + + + + {{text.studyline_shortname}} + + + + + + {{text.studyline_color}} + + + + + + + + + + + {{ text.studyline_name}} + + + + + + {{ text.studyline_shortname}} + + + + + + {{ text.studyline_color}} + + + + + + + +
+ ` + }); + + + /* + * T-STUDYLINE-HEADER + */ + Vue.component('t-studyline-header', { + props: ['color','name','code', 'slots','sequence','numlines',], + data() { + return { + }; + }, + computed: { + + }, + methods: { + }, + template: ` +
+
+
+ {{ code }} +
+
+ `, + }); + + /* + * T-STUDYLINE (Used only for study line edit mode) */ Vue.component('t-studyline', { props: ['color','name','code', 'slots','deletable','editable','sequence','numlines'], @@ -1466,16 +1493,13 @@ export default { }, template: `
+ (sequence==0?' first':'') + (sequence==numlines-1?' last':'')" >
{{ code }} - - -
@@ -1714,7 +1738,6 @@ export default { }); - Vue.component('t-item', { props: { 'value' :{