diff --git a/application/controllers/api/frontend/v1/stv/Status.php b/application/controllers/api/frontend/v1/stv/Status.php index fcc8007cd..7e649f3cf 100644 --- a/application/controllers/api/frontend/v1/stv/Status.php +++ b/application/controllers/api/frontend/v1/stv/Status.php @@ -24,7 +24,6 @@ class Status extends FHCAPI_Controller 'updateStatus' => ['admin:rw', 'assistenz:rw'], 'advanceStatus' => ['admin:rw', 'assistenz:rw'], 'confirmStatus' => ['admin:rw', 'assistenz:rw'], - ]); //Load Models @@ -435,9 +434,10 @@ class Status extends FHCAPI_Controller ]); if (!$this->form_validation->run()) + { $this->terminateWithValidationErrors($this->form_validation->error_array()); + } - $this->load->library('PrestudentLib'); $this->db->trans_start(); @@ -623,8 +623,9 @@ class Status extends FHCAPI_Controller ]); if (!$this->form_validation->run()) + { $this->terminateWithValidationErrors($this->form_validation->error_array()); - + } // Start DB transaction $this->db->trans_start(); diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js b/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js index ab8f83fab..cff6b2be6 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Status/Dropdown.js @@ -142,14 +142,15 @@ export default { this.addStudent({status_kurzbz: 'student', statusgrund_id}); }, addStudent(data) { - Promise - .allSettled( - this.prestudentIds.map(prestudent_id => this.$api.call( - ApiStvStatus.addStudent(prestudent_id, data), - { errorHeader: prestudent_id } - )) - ) - .then(res => this.showFeedback(res, data.status_kurzbz)); + this.$api.call(this.prestudentIds.map(prestudent_id => [ + prestudent_id, + ApiStvStatus.addStudent(prestudent_id, data), + { errorHeader: prestudent_id } + ])) + .then(() => { + this.$emit('reloadTable'); + this.$reloadList(); + }); }, changeStatusToAbbrecher(statusgrund_id) { this @@ -242,31 +243,15 @@ export default { return askForSemester(); }, changeStatus(data) { - Promise - .allSettled( - this.prestudentIds.map(prestudent_id => this.$api.call( - ApiStvStatus.changeStatus(prestudent_id, data), - { errorHeader: prestudent_id } - )) - ) - .then(res => this.showFeedback(res, data.status_kurzbz)); - }, - showFeedback(results, status_kurzbz) { - const countSuccess = results.filter(result => result.status == "fulfilled").length; - const countError = results.length - countSuccess; - - //Feedback Success als infoalert - this.$fhcAlert.alertInfo(this.$p.t('ui', 'successNewStatus', { - countSuccess, - status: status_kurzbz, - countError - })); - - if(results.length == 1 && countSuccess > 0){ + this.$api.call(this.prestudentIds.map(prestudent_id => [ + prestudent_id, + ApiStvStatus.changeStatus(prestudent_id, data) + ])) + .then(() => { this.$emit('reloadTable'); - } - this.$reloadList(); - } + this.$reloadList(); + }); + }, }, created() { this.$api diff --git a/public/js/plugins/Api.js b/public/js/plugins/Api.js index d0ffaa439..47139b79f 100644 --- a/public/js/plugins/Api.js +++ b/public/js/plugins/Api.js @@ -42,10 +42,13 @@ export default { } function _clean_return_value(response) { + if (typeof response.data === 'string' || response.data instanceof String) + return _clean_return_value({ data: response }); + const result = response.data; delete response.data; if (!result.meta) - result.meta = {response}; + result.meta = { response }; else result.meta.response = response; return result; @@ -159,6 +162,77 @@ export default { return fhcApiAxios.post(uri, data, config); }, call(factory, configoverwrite, form) { + if (Array.isArray(factory)) { + const $fhcAlert = app.config.globalProperties.$fhcAlert; + const $api = app.config.globalProperties.$api; + + Promise + .allSettled(factory.map((config, index) => { + if (Array.isArray(config)) + return $api.call(config[1], { + errorHeader: config[0], + errorHandling: false + }); + else + return $api.call(config, { + errorHeader: '#' + index, + errorHandling: false + }); + })) + .then(res => { + // TODO(chris): obey form & configoverwrite + let messagesError = []; + let messagesSuccessful = []; + + res.forEach(result => { + if (result.status === 'fulfilled') { + //console.log(JSON.parse(result.value.data)); + const successTitle = "
" + result.value.data + "
"; + messagesSuccessful.push(successTitle + "ok"); + } else { + const errorTitle = "
" + result.reason.config.errorHeader + "
"; + const errorMsg = JSON.parse(result.reason.request.response); + const fullMessage = errorMsg.errors.map(error => { + if (error.type == 'validation') { + // TODO(chris): do we want the keys? + return '
' + Object.values(error.messages).join("
") + '
'; + } + // TODO(chris): other types + if (error.message) + return '
' + error.message + '
'; + if (error.messages) + return '
' + error.messages.join("\n") + '
'; + // TODO(chris): what to do here + return '
' + "Generic Error" + '
'; // TODO(chris): translate + }).join("\n"); + messagesError.push(errorTitle + fullMessage); + } + }); + + if (messagesError.length) + { + const test = document.createElement('b'); + $fhcAlert.alertDefault( + 'error', + messagesError.length + " Fehler", // TODO(chris): translate + '
' + messagesError.join("") + '
', + true, + true + ); + } + if (messagesSuccessful.length) + { + const test = document.createElement('b'); + $fhcAlert.alertDefault( + 'info', + 'Feedback', + messagesSuccessful.length + " erfolgreiche Statusänderung(en) durchgeführt", // TODO(chris): translate + false, + true + ); + } + }); + } let {method, url, params, config} = factory; if (configoverwrite !== undefined) { config = configoverwrite; diff --git a/public/js/plugins/FhcAlert.js b/public/js/plugins/FhcAlert.js index f90b61ac2..5d84b1de9 100644 --- a/public/js/plugins/FhcAlert.js +++ b/public/js/plugins/FhcAlert.js @@ -140,7 +140,16 @@ const helperApp = Vue.createApp({ } }, template: /* html */` - + + +