From 6f60d7c99ece06986717a0ecb3751dcef8204cc1 Mon Sep 17 00:00:00 2001 From: ma0068 Date: Tue, 10 Jun 2025 11:57:43 +0200 Subject: [PATCH] API Refactoring, some other minor fixes --- .../api/frontend/v1/vertraege/Config.php | 1 + .../api/frontend/v1/vertraege/Vertraege.php | 24 +-- public/js/api/factory/vertraege/vertraege.js | 158 ++++++++++++++++++ .../js/components/Vertraege/List/Details.js | 14 +- public/js/components/Vertraege/List/Status.js | 15 +- .../components/Vertraege/List/Unassigned.js | 9 +- .../components/Vertraege/MitarbeiterHeader.js | 18 +- public/js/components/Vertraege/Vertraege.js | 78 ++++----- .../Vertraege/Vertragsverwaltung.js | 9 +- 9 files changed, 246 insertions(+), 80 deletions(-) create mode 100644 public/js/api/factory/vertraege/vertraege.js diff --git a/application/controllers/api/frontend/v1/vertraege/Config.php b/application/controllers/api/frontend/v1/vertraege/Config.php index 8ff241914..72d38e93e 100644 --- a/application/controllers/api/frontend/v1/vertraege/Config.php +++ b/application/controllers/api/frontend/v1/vertraege/Config.php @@ -47,6 +47,7 @@ class Config extends FHCAPI_Controller $params ); + //TODO(Manu) check warning $this->terminateWithSuccess($menu[0]); } } diff --git a/application/controllers/api/frontend/v1/vertraege/Vertraege.php b/application/controllers/api/frontend/v1/vertraege/Vertraege.php index d1376c484..579883c8d 100644 --- a/application/controllers/api/frontend/v1/vertraege/Vertraege.php +++ b/application/controllers/api/frontend/v1/vertraege/Vertraege.php @@ -467,7 +467,7 @@ class Vertraege extends FHCAPI_Controller return $this->terminateWithSuccess(current(getData($result))); } - public function insertContractStatus($vertrag_id) + public function insertContractStatus() { $this->load->library('form_validation'); @@ -486,7 +486,7 @@ class Vertraege extends FHCAPI_Controller $result = $this->VertragvertragsstatusModel->loadWhere( array( - 'vertrag_id' => $vertrag_id, + 'vertrag_id' => $this->input->post('vertrag_id'), 'vertragsstatus_kurzbz' => $this->input->post('vertragsstatus_kurzbz') ) ); @@ -497,7 +497,7 @@ class Vertraege extends FHCAPI_Controller } $status_result = $this->VertragvertragsstatusModel->insert([ - 'vertrag_id' => $vertrag_id, + 'vertrag_id' => $this->input->post('vertrag_id'), 'uid' => getAuthUID(), 'vertragsstatus_kurzbz' => $this->input->post('vertragsstatus_kurzbz'), 'insertamum' => date('c'), @@ -512,9 +512,10 @@ class Vertraege extends FHCAPI_Controller return $this->terminateWithSuccess(current(getData($status_result))); } - public function deleteContractStatus($vertrag_id) + public function deleteContractStatus() { $status = $this->input->post('vertragsstatus_kurzbz'); + $vertrag_id = $this->input->post('vertrag_id'); $result = $this->VertragvertragsstatusModel->delete( array( @@ -534,9 +535,10 @@ class Vertraege extends FHCAPI_Controller return $this->terminateWithSuccess(current(getData($result))); } - public function loadContractStatus($vertrag_id) + public function loadContractStatus() { - $status = $this->input->post('vertragsstatus_kurzbz'); + $status = $this->input->get('vertragsstatus_kurzbz'); + $vertrag_id = $this->input->get('vertrag_id'); $result = $this->VertragvertragsstatusModel->loadWhere( array( @@ -550,7 +552,7 @@ class Vertraege extends FHCAPI_Controller return $this->terminateWithSuccess(current(getData($result))); } - public function updateContractStatus($vertrag_id) + public function updateContractStatus() { $this->load->library('form_validation'); @@ -569,7 +571,7 @@ class Vertraege extends FHCAPI_Controller $status_result = $this->VertragvertragsstatusModel->update( [ - 'vertrag_id' => $vertrag_id, + 'vertrag_id' => $this->input->post('vertrag_id'), 'vertragsstatus_kurzbz' => $this->input->post('vertragsstatus_kurzbz')], [ 'uid' => getAuthUID(), @@ -586,10 +588,11 @@ class Vertraege extends FHCAPI_Controller return $this->terminateWithSuccess(current(getData($status_result))); } - public function deleteLehrauftrag($vertrag_id) + public function deleteLehrauftrag() { $lehreinheit_id = $this->input->post('lehreinheit_id'); $mitarbeiter_uid = $this->input->post('mitarbeiter_uid'); + $vertrag_id = $this->input->post('vertrag_id '); $this->load->model('education/Lehreinheitmitarbeiter_model', 'LehreinheitmitarbeiterModel'); @@ -616,11 +619,12 @@ class Vertraege extends FHCAPI_Controller return $this->terminateWithSuccess(current(getData($result))); } - public function deleteBetreuung($vertrag_id) + public function deleteBetreuung() { $person_id= $this->input->post('person_id'); $projektarbeit_id = $this->input->post('projektarbeit_id'); $betreuerart_kurzbz = $this->input->post('betreuerart_kurzbz'); + $vertrag_id = $this->input->post('vertrag_id '); $this->load->model('education/Projektbetreuer_model', 'Projektbetreuermodel'); diff --git a/public/js/api/factory/vertraege/vertraege.js b/public/js/api/factory/vertraege/vertraege.js new file mode 100644 index 000000000..8d39a24c9 --- /dev/null +++ b/public/js/api/factory/vertraege/vertraege.js @@ -0,0 +1,158 @@ +/** + * Copyright (C) 2025 fhcomplete.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +export default { + getAllVertraege(person_id) { + return { + method: 'get', + url: 'api/frontend/v1/vertraege/Vertraege/getAllVertraege/' + person_id + }; + }, +/* getAllContractsNotAssigned2(person_id) { + return { + method: 'get', + url: 'api/frontend/v1/vertraege/Vertraege/getAllContractsNotAssigned/' + person_id + }; + },*/ + getAllContractsNotAssigned(person_id) { + return { + method: 'get', + url: 'api/frontend/v1/vertraege/Vertraege/getAllContractsNotAssigned/' + person_id + }; + }, + getAllContractsAssigned(person_id, vertrag_id) { + return { + method: 'get', + url: 'api/frontend/v1/vertraege/Vertraege/getAllContractsAssigned/' + person_id + '/' + vertrag_id + '' + }; + }, + getAllContractTypes() { + return { + method: 'get', + url: 'api/frontend/v1/vertraege/Vertraege/getAllContractTypes/' + }; + }, + getStatiOfContract(vertrag_id){ + return { + method: 'get', + url: 'api/frontend/v1/vertraege/Vertraege/getStatiOfContract/' + vertrag_id + }; + }, + configPrintDocument() { + return { + method: 'get', + url: 'api/frontend/v1/vertraege/Config/printDocument/' + }; + }, + getAllContractStati() { + return { + method: 'get', + url: 'api/frontend/v1/vertraege/vertraege/getAllContractStati/' + }; + }, + deleteContract(vertrag_id) { + return { + method: 'post', + url: 'api/frontend/v1/vertraege/vertraege/deleteContract/' + vertrag_id + }; + }, + addNewContract(params) { + return { + method: 'post', + url: 'api/frontend/v1/vertraege/vertraege/addNewContract/', + params + }; + }, + loadContract(vertrag_id){ + return { + method: 'get', + url: 'api/frontend/v1/vertraege/vertraege/loadContract/' + vertrag_id + }; + }, + updateContract(params) { + return { + method: 'post', + url: 'api/frontend/v1/vertraege/vertraege/updateContract/', + params + }; + }, + loadContractStatus(params){ + return { + method: 'get', + url: 'api/frontend/v1/vertraege/vertraege/loadContractStatus/', + params + }; + }, + insertContractStatus(params) { + return { + method: 'post', + url: 'api/frontend/v1/vertraege/vertraege/insertContractStatus/', + params + }; + }, + updateContractStatus(params) { + return { + method: 'post', + url: 'api/frontend/v1/vertraege/vertraege/updateContractStatus/', + params + }; + }, + deleteContractStatus(params) { + return { + method: 'post', + url: 'api/frontend/v1/vertraege/vertraege/deleteContractStatus/', + params + }; + }, + deleteLehrauftrag(params) { + return { + method: 'post', + url: 'api/frontend/v1/vertraege/vertraege/deleteLehrauftrag/', + params + }; + }, + deleteBetreuung(params) { + return { + method: 'post', + url: 'api/frontend/v1/vertraege/vertraege/deleteBetreuung/', + params + }; + }, + getMitarbeiter(){ + return { + method: 'post', + url: 'api/frontend/v1/vertraege/vertraege/getMitarbeiter/', + }; + //return this.$fhcApi.post('api/frontend/v1/vertraege/vertraege/getMitarbeiter/'); + }, + getHeader(person_id){ + return this.$fhcApi.post('api/frontend/v1/vertraege/vertraege/getHeader/' + person_id); + }, + getPersonAbteilung(person_id){ + return this.$fhcApi.post('api/frontend/v1/vertraege/vertraege/getPersonAbteilung/' + person_id); + }, + getLeitungOrg(oekurzbz){ + return this.$fhcApi.post('api/frontend/v1/vertraege/vertraege/getLeitungOrg/' + oekurzbz); + }, + getMitarbeiterUid(person_id){ + return { + method: 'get', + url: 'api/frontend/v1/vertraege/vertraege/getMitarbeiterUid/' + person_id + }; + // return this.$fhcApi.get('api/frontend/v1/vertraege/vertraege/getMitarbeiterUid/' + person_id); + }, +}; \ No newline at end of file diff --git a/public/js/components/Vertraege/List/Details.js b/public/js/components/Vertraege/List/Details.js index 60ec5110e..47eb629a3 100644 --- a/public/js/components/Vertraege/List/Details.js +++ b/public/js/components/Vertraege/List/Details.js @@ -26,19 +26,19 @@ export default { type: [Number], required: true }, + endpoint: { + type: Object, + required: true + }, }, data() { return { //tableData: [], tabulatorOptions: { ajaxURL: 'dummy', - ajaxRequestFunc: this.$fhcApi.factory.vertraege.person.getAllContractsAssigned, - ajaxParams: () => { - return { - person_id: this.person_id, - vertrag_id: this.vertrag_id - }; - }, + ajaxRequestFunc: () => this.$api.call( + this.endpoint.getAllContractsAssigned(this.person_id, this.vertrag_id) + ), ajaxResponse: (url, params, response) => response.data, columns: [ {title: "Typ", field: "type"}, diff --git a/public/js/components/Vertraege/List/Status.js b/public/js/components/Vertraege/List/Status.js index 60475d3e2..11410bfff 100644 --- a/public/js/components/Vertraege/List/Status.js +++ b/public/js/components/Vertraege/List/Status.js @@ -29,18 +29,19 @@ export default { formDataParent: { type: Object, required: true - } + }, + endpoint: { + type: Object, + required: true + }, }, data() { return { tabulatorOptions: { ajaxURL: 'dummy', - ajaxRequestFunc: this.$fhcApi.factory.vertraege.person.getStatiOfContract, - ajaxParams: () => { - return { - vertrag_id: this.vertrag_id - }; - }, + ajaxRequestFunc: () => this.$api.call( + this.endpoint.getStatiOfContract(this.vertrag_id) + ), ajaxResponse: (url, params, response) => response.data, columns: [ {title: "Status", field: "bezeichnung"}, diff --git a/public/js/components/Vertraege/List/Unassigned.js b/public/js/components/Vertraege/List/Unassigned.js index 9ffb1c3c8..4b0d20bb8 100644 --- a/public/js/components/Vertraege/List/Unassigned.js +++ b/public/js/components/Vertraege/List/Unassigned.js @@ -25,12 +25,9 @@ export default { return { tabulatorOptions: { ajaxURL: 'dummy', - ajaxRequestFunc: this.$fhcApi.factory.vertraege.person.getAllContractsNotAssigned, - ajaxParams: () => { - return { - person_id: this.person_id - }; - }, + ajaxRequestFunc: () => this.$api.call( + this.endpoint.getAllContractsNotAssigned(this.person_id) + ), ajaxResponse: (url, params, response) => response.data, columns: [ {title: "Typ", field: "type", width: 100}, diff --git a/public/js/components/Vertraege/MitarbeiterHeader.js b/public/js/components/Vertraege/MitarbeiterHeader.js index ff361eaea..175c61006 100644 --- a/public/js/components/Vertraege/MitarbeiterHeader.js +++ b/public/js/components/Vertraege/MitarbeiterHeader.js @@ -6,15 +6,19 @@ export default { CoreFilterCmpt, FormInput }, - inject: { +/* inject: { cisRoot: { from: 'cisRoot' }, - }, + },*/ emits: [ "selectedPerson" ], props: { + endpoint: { + type: Object, + required: true + }, // maybe later nur fixe oder alle Mitarbeiter: gleich funktionsaufruf //oder Mitarbeiter mit Verträgen /* filterMa: { @@ -41,12 +45,9 @@ export default { return { tabulatorOptions: { ajaxURL: 'dummy', - ajaxRequestFunc: this.$fhcApi.factory.vertraege.person.getMitarbeiter, - ajaxParams: () => { - return { - fix: this.filterMa - }; - }, + ajaxRequestFunc: () => this.$api.call( + this.endpoint.getMitarbeiter() + ), ajaxResponse: (url, params, response) => response.data, columns: [ {title: "UID", field: "uid", headerFilter:"input"}, @@ -148,6 +149,7 @@ export default {

{{$p.t('vertrag', 'vertragsverwaltung')}}

+
{ - return { - person_id: this.person_id - }; - }, + ajaxRequestFunc: () => this.$api.call( + this.endpoint.getAllVertraege(this.person_id) + ), ajaxResponse: (url, params, response) => response.data, columns: [ {title: "Bezeichnung", field: "bezeichnung", width: 150}, @@ -176,9 +174,9 @@ export default { cm.getColumnByField('isabgerechnet').component.updateDefinition({ title: this.$p.t('vertrag', 'abgerechnet') }); - cm.getColumnByField('actions').component.updateDefinition({ +/* cm.getColumnByField('actions').component.updateDefinition({ title: this.$p.t('global', 'aktionen') - }); + });*/ } }, { @@ -242,7 +240,9 @@ export default { .then(result => result ? vertrag_id : Promise.reject({handled: true})) - .then(this.endpoint.deleteContract) + .then(vertrag_id => this.$api.call( + this.endpoint.deleteContract(vertrag_id)) + ) .then(result => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete')); //window.scrollTo(0, 0); @@ -258,9 +258,8 @@ export default { formData: this.formData, clickedRows: this.childData, //all data needed, maybe smaller array? }; - - return this.endpoint - .addNewContract(this.$refs.contractData, dataToSend) + return this.$refs.contractData + .call(this.endpoint.addNewContract(dataToSend)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); this.$refs.contractModal.hide(); @@ -280,9 +279,8 @@ export default { formData: this.formData, clickedRows: this.childData, }; - - return this.endpoint - .updateContract(this.$refs.contractData, dataToSend) + return this.$refs.contractData + .call(this.endpoint.updateContract(dataToSend)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); this.$refs.contractModal.hide(); @@ -296,8 +294,8 @@ export default { loadContract(vertrag_id) { this.resetModal(); this.statusNew = false; - return this.endpoint - .loadContract(vertrag_id) + return this.$api + .call(this.endpoint.loadContract(vertrag_id)) .then(result => { this.formData = result.data; }) @@ -322,8 +320,8 @@ export default { datum: formattedDate }; - return this.endpoint - .insertContractStatus(this.$refs.contractstati.$refs.statusData, params) + return this.$refs.contractstati.$refs.statusData + .call(this.endpoint.insertContractStatus(params)) .then(response => { //this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); @@ -338,8 +336,8 @@ export default { vertrag_id : vertrag_id, vertragsstatus_kurzbz: status }; - return this.endpoint - .deleteContractStatus(params) + return this.$api + .call(this.endpoint.deleteContractStatus(params)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete')); @@ -364,8 +362,8 @@ export default { datum : formattedDate, vertragsstatus_kurzbz: status }; - return this.endpoint - .updateContractStatus(this.$refs.contractstati.$refs.statusData, params) + return this.$refs.contractstati.$refs.statusData + .call(this.endpoint.updateContractStatus(params)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSave')); this.$refs.contractstati.closeModal(); @@ -379,8 +377,8 @@ export default { vertrag_id : vertrag_id, vertragsstatus_kurzbz: status }; - return this.endpoint - .loadContractStatus(params) + return this.$api + .call(this.endpoint.loadContractStatus(params)) .then(response => { this.contractFormData = response.data; this.$refs.contractstati.openModal(); @@ -394,8 +392,8 @@ export default { lehreinheit_id: lehreinheit_id, mitarbeiter_uid: mitarbeiter_uid }; - return this.endpoint - .deleteLehrauftrag(params) + return this.$api + .call(this.endpoint.deleteLehrauftrag(params)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete')); this.resetModal(); @@ -411,8 +409,8 @@ export default { projektarbeit_id: projektarbeit_id, betreuerart_kurzbz: betreuerart_kurzbz }; - return this.endpoint - .deleteBetreuung(params) + return this.$api + .call(this.endpoint.deleteBetreuung(params)) .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete')); this.$refs.contractdetails.reload(); @@ -437,7 +435,7 @@ export default { this.statusNew = true; //this.childData = {}; - //gefährlich, immer null?? + //always null?? //TODO(Manu) check if this.childData = {}, }, updateBetrag(sumBetrag){ @@ -488,8 +486,8 @@ export default { }); }, getMitarbeiterUid(){ - return this.endpoint - .getMitarbeiterUid(this.person_id) + return this.$api + .call(this.endpoint.getMitarbeiterUid(this.person_id)) .then(response => { this.ma_uid = response.data; }) @@ -511,10 +509,10 @@ export default { }, created() { Promise.all([ - this.endpoint.getAllContractTypes(), - this.endpoint.getAllContractsNotAssigned2(this.person_id), - this.endpoint.getAllContractStati(), - this.$fhcApi.factory.vertraege.configPrintDocument() + this.$api.call(this.endpoint.getAllContractTypes()), + this.$api.call(this.endpoint.getAllContractsNotAssigned(this.person_id)), + this.$api.call(this.endpoint.getAllContractStati()), + this.$api.call(this.endpoint.configPrintDocument()) ]) .then(([result1, result2, result3, result4]) => { this.listContractTypes = result1.data; @@ -591,6 +589,7 @@ export default {