Added methods to sum total ECTS, to be displayed on Anrechnung Details and Uebersicht

This commit is contained in:
Cris
2022-07-07 10:21:23 +02:00
parent 9d7589ddc4
commit 1dc49ec494
2 changed files with 147 additions and 2 deletions
@@ -4,6 +4,7 @@ const ANRECHNUNGSTATUS_PROGRESSED_BY_LEKTOR = 'inProgressLektor';
const ANRECHNUNGSTATUS_APPROVED = 'approved';
const ANRECHNUNGSTATUS_REJECTED = 'rejected';
const COLOR_DANGER = '#f2dede';
$(function(){
@@ -36,6 +37,8 @@ $(function(){
// Init tooltips
approveAnrechnungDetail.initTooltips();
approveAnrechnungDetail.alertIfMaxEctsExceeded();
// Ask if Approve Anrechnungen
$("#approveAnrechnungDetail-approve-anrechnung-ask").click(function(){
@@ -93,6 +96,9 @@ $(function(){
data.retval[0].abgeschlossen_von,
data.retval[0].status_bezeichnung
);
approveAnrechnungDetail.sumUpEcts(ects, sumEctsSchulisch, sumEctsBeruflich);
approveAnrechnungDetail.alertIfMaxEctsExceeded();
}
},
errorCallback: function (jqXHR, textStatus, errorThrown)
@@ -251,18 +257,19 @@ $(function(){
console.log(data);
if (data.error && data.retval != null)
{
console.log('inside error');
// Print error message
FHC_DialogLib.alertWarning(data.retval);
}
if (!data.error && data.retval != null)
{
console.log('inside success');
approveAnrechnungDetail.formatGenehmigungIsWithdrawed(
data.retval.status_bezeichnung
);
approveAnrechnungDetail.substractEcts(ects, sumEctsSchulisch, sumEctsBeruflich);
approveAnrechnungDetail.alertIfMaxEctsExceeded();
FHC_DialogLib.alertSuccess(FHC_PhrasesLib.t("anrechnung", "erfolgreichZurueckgenommen"));
}
@@ -544,5 +551,29 @@ var approveAnrechnungDetail = {
$('#approveAnrechnungDetail-reject-anrechnung-ask').prop('disabled', false);
// Hide button to withdraw approval
$('#approveAnrechnungDetail-withdraw-request-recommedation').addClass('hidden');
},
sumUpEcts: function(ects, sumEctsSchulisch, sumEctsBeruflich){
$('#sumEctsTotal').text(parseFloat($('#sumEctsSchulisch').text()) + parseFloat($('#sumEctsBeruflich').text()) + parseFloat($('#ects').text()));
$('#sumEctsSchulisch').text(parseFloat($('#sumEctsSchulisch').text()) + parseFloat($('#ects').text()));
},
substractEcts: function(ects, sumEctsSchulisch, sumEctsBeruflich){
$('#sumEctsTotal').text(parseFloat($('#sumEctsSchulisch').text()) + parseFloat($('#sumEctsBeruflich').text()) - parseFloat($('#ects').text()));
$('#sumEctsSchulisch').text(parseFloat($('#sumEctsSchulisch').text()) - parseFloat($('#ects').text()));
},
alertIfMaxEctsExceeded: function(){
if(
(parseFloat($('#ects').text()) + parseFloat($('#sumEctsSchulisch').text())) > 60 ||
(parseFloat($('#ects').text()) + parseFloat($('#sumEctsBeruflich').text())) > 60 ||
(parseFloat($('#ects').text()) + parseFloat($('#sumEctsSchulisch').text()) + parseFloat($('#sumEctsBeruflich').text())) > 90
)
{
console.log('inside');
$('#sumEctsMsg').html("<br><b>ACHTUNG! Bei Anrechnung von LV: Maximale ECTS überschritten.</b></br>").css('backgroundColor', COLOR_DANGER);
}
else
{
$('#sumEctsMsg').html('').css('border', 'none');
}
}
}
@@ -8,6 +8,9 @@ const ANRECHNUNGSTATUS_APPROVED = 'approved';
const ANRECHNUNGSTATUS_REJECTED = 'rejected';
const COLOR_LIGHTGREY = "#f5f5f5";
const COLOR_DANGER = '#f2dede';
var previousSelectedRows = [];
// -----------------------------------------------------------------------------------------------------------------
// Mutators - setter methods to manipulate table data when entering the tabulator
@@ -99,6 +102,75 @@ function func_selectableCheck(row){
);
}
// Unformat row when single row is deselected (is not done by func_rowSelectionChanged yet)
function func_rowDeselected(row){
// Removes bg-color on single row deselection.
approveAnrechnung.unmarkEctsRow(row);
}
// Format rows when maximum ECTS are exceeded.
function func_rowSelectionChanged(data, rows){
var selectedData = data;
var selectedRows = rows;
// If no rows selected
if (selectedRows.length == 0)
{
// Check there are still rows marked from previous selection...
if (previousSelectedRows.length > 0)
{
// ... and unmark them
previousSelectedRows.forEach((row) => approveAnrechnung.unmarkEctsRow(row));
}
// Show number of selected Rows
approveAnrechnung.showNumberSelectedRows(selectedRows);
return;
}
// Sum up over all anzurechnenden LV-ECTS by Prestudent
var result = [];
result = approveAnrechnung.getSumLvEctsByPreStudent(selectedData);
// Filter only Prestudenten, where ECTS exceed maximum
exceededEctsByPreStud =
result.filter((val) =>
(val.ectsSumAnzurechnendeLvs + val.ectsSumSchulisch) > 60 ||
(val.ectsSumBeruflich) > 60 ||
(val.ectsSumAnzurechnendeLvs + val.ectsSumSchulisch + val.ectsSumBeruflich) > 90
);
// Mark all Prestudenten
if (selectedRows.length > 0)
{
selectedRows.forEach((row) => {
//row.reformat();
approveAnrechnung.unmarkEctsRow(row);
if (exceededEctsByPreStud.length > 0)
{
exceededEctsByPreStud.forEach((val) => {
if (row.getData().prestudent_id == val.prestudent_id)
{
approveAnrechnung.markEctsRow(row);
}
})
}
});
}
// Keep the selected rows for next selection.
previousSelectedRows = selectedRows;
// Show number of selected rows.
approveAnrechnung.showNumberSelectedRows(selectedRows);
}
// Performes after row was updated
function func_rowUpdated(row){
// Refresh row formatters
@@ -595,5 +667,47 @@ var approveAnrechnung = {
break;
}
},
markEctsRow(row){
row.getElement().style["background-color"] = COLOR_DANGER;
// row.getCell('ects').getElement().style["background-color"] = COLOR_DANGER;
// row.getCell('ectsSumTotal').getElement().style["background-color"] = COLOR_DANGER;
// row.getCell('student').getElement().style["background-color"] = COLOR_DANGER;
},
unmarkEctsRow(row){
row.getElement().style.removeProperty('background-color');
// row.getCell('ects').getElement().style.removeProperty('background-color');
// row.getCell('ectsSumTotal').getElement().style.removeProperty('background-color');
// row.getCell('student').getElement().style.removeProperty('background-color');
},
getSumLvEctsByPreStudent(selectedData){
var result = [];
selectedData.reduce((prev, curr) => {
if (!prev[curr.prestudent_id])
{
prev[curr.prestudent_id] = {
anrechnung_id: curr.anrechnung_id,
prestudent_id: curr.prestudent_id,
ectsSumAnzurechnendeLvs: 0,
ectsSumSchulisch: parseFloat(curr.ectssumschulisch),
ectsSumBeruflich: parseFloat(curr.ectssumberuflich)
};
result.push(prev[curr.prestudent_id])
}
prev[curr.prestudent_id].ectsSumAnzurechnendeLvs+= parseFloat(curr.ects);
return prev;
}, {});
return result;
},
showNumberSelectedRows(rows){
$('#number-selected').html("Ausgewählte Zeilen: <strong>" + rows.length + "</strong>");
}
}