API Konsolodierung: stv address

This commit is contained in:
cgfhtw
2024-04-30 08:48:15 +02:00
parent c8009a8a6c
commit fe06b2360e
4 changed files with 88 additions and 78 deletions
@@ -0,0 +1,66 @@
<?php
/**
* Copyright (C) 2024 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 <https://www.gnu.org/licenses/>.
*/
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* This controller operates between (interface) the JS (GUI) and the back-end
* Provides data to the ajax get calls about addresses
* This controller works with JSON calls on the HTTP GET or POST and the output is always JSON
*/
class Address extends FHCAPI_Controller
{
public function __construct()
{
parent::__construct([
'getNations' => self::PERM_LOGGED,
'getPlaces' => self::PERM_LOGGED
]);
}
public function getNations()
{
$this->load->model('codex/Nation_model', 'NationModel');
$this->NationModel->addOrder('kurztext');
$result = $this->NationModel->load();
$data = $this->getDataOrTerminateWithError($result);
$this->terminateWithSuccess($data);
}
public function getPlaces($plz)
{
$this->load->model('codex/Gemeinde_model', 'GemeindeModel');
$this->load->library('form_validation');
$this->form_validation->set_data(['address.plz' => $plz]);
$this->form_validation->set_rules('address.plz', 'PLZ', 'numeric|less_than[10000]');
if (!$this->form_validation->run())
$this->terminateWithValidationErrors($this->form_validation->error_array());
$result = $this->GemeindeModel->getGemeindeByPlz($plz);
$data = $this->getDataOrTerminateWithError($result);
$this->terminateWithSuccess($data);
}
}
@@ -1,47 +0,0 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
class Address extends FHC_Controller
{
public function __construct()
{
// TODO(chris): access!
parent::__construct();
}
public function getNations()
{
$this->load->model('codex/Nation_model', 'NationModel');
$this->NationModel->addOrder('kurztext');
$result = $this->NationModel->load();
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
}
$this->outputJson($result);
}
public function getPlaces($plz)
{
$this->load->model('codex/Gemeinde_model', 'GemeindeModel');
$this->load->library('form_validation');
$this->form_validation->set_data(['address.plz' => $plz]);
$this->form_validation->set_rules('address.plz', 'PLZ', 'numeric|less_than[10000]');
if ($this->form_validation->run() == false) {
$this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST);
return $this->outputJsonError($this->form_validation->error_array());
}
$result = $this->GemeindeModel->getGemeindeByPlz($plz);
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
}
$this->outputJson($result);
}
}
@@ -21,7 +21,6 @@ import StvVerband from "./Studentenverwaltung/Verband.js";
import StvList from "./Studentenverwaltung/List.js";
import StvDetails from "./Studentenverwaltung/Details.js";
import StvStudiensemester from "./Studentenverwaltung/Studiensemester.js";
import {CoreRESTClient} from '../../RESTClient.js';
export default {
@@ -107,25 +106,20 @@ export default {
this.studiengangKz = studiengang_kz;
this.$refs.stvList.updateUrl(link);
},
searchfunction(searchsettings) {
return Vue.$fhcapi.Search.search(searchsettings);
},
studiensemesterChanged(v) {
this.studiensemesterKurzbz = v;
this.$refs.stvList.updateUrl();
this.$refs.details.reload();
},
reloadList() {
console.log('reloadList2');
this.$refs.stvList.reload();
}
},
created() {
CoreRESTClient
.get('components/stv/Address/getNations')
.then(result => CoreRESTClient.getData(result.data) || [])
this.$fhcApi
.get('api/frontend/v1/stv/address/getNations')
.then(result => {
this.lists.nations = result;
this.lists.nations = result.data;
})
.catch(this.$fhcAlert.handleSystemError);
this.$fhcApi
@@ -187,7 +181,7 @@ export default {
<header class="navbar navbar-expand-lg navbar-dark bg-dark flex-md-nowrap p-0 shadow">
<a class="navbar-brand col-md-4 col-lg-3 col-xl-2 me-0 px-3" :href="stvRoot">FHC 4.0</a>
<button class="navbar-toggler d-md-none m-1 collapsed" type="button" data-bs-toggle="offcanvas" data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false" :aria-label="$p.t('ui/toggle_nav')"><span class="navbar-toggler-icon"></span></button>
<core-searchbar :searchoptions="searchbaroptions" :searchfunction="searchfunction" class="searchbar w-100"></core-searchbar>
<core-searchbar :searchoptions="searchbaroptions" :searchfunction="$fhcApi.factory.search.search" class="searchbar w-100"></core-searchbar>
</header>
<div class="container-fluid overflow-hidden">
<div class="row h-100">
@@ -1,5 +1,4 @@
import {CoreFilterCmpt} from "../../../../filter/Filter.js";
import {CoreRESTClient} from "../../../../../RESTClient";
import PvAutoComplete from "../../../../../../../index.ci.php/public/js/components/primevue/autocomplete/autocomplete.esm.min.js";
import FhcFormValidation from '../../../../Form/Validation.js';
import BsModal from "../../../../Bootstrap/Modal.js";
@@ -17,7 +16,7 @@ export default{
data() {
return{
tabulatorOptions: {
ajaxURL: 'api/frontend/v1/stv/Kontakt/getAdressen/' + this.uid,
ajaxURL: 'api/frontend/v1/stv/kontakt/getAdressen/' + this.uid,
ajaxRequestFunc: this.$fhcApi.get,
ajaxResponse: (url, params, response) => response.data,
//autoColumns: true,
@@ -169,21 +168,21 @@ export default{
}
},
watch: {
uid(){
uid() {
this.$refs.table.tabulator.setData('api/frontend/v1/stv/Kontakt/getAdressen/' + this.uid);
}
},
methods:{
actionNewAdress(){
actionNewAdress() {
this.$refs.newAdressModal.show();
},
actionEditAdress(adress_id){
actionEditAdress(adress_id) {
this.loadAdress(adress_id).then(() => {
if(this.addressData.adresse_id)
this.$refs.editAdressModal.show();
});
},
actionDeleteAdress(adress_id){
actionDeleteAdress(adress_id) {
this.loadAdress(adress_id).then(() => {
if(this.addressData.adresse_id)
if(this.addressData.heimatadresse)
@@ -205,10 +204,10 @@ export default{
this.reload();
});
},
reload(){
reload() {
this.$refs.table.reloadTable();
},
loadAdress(adress_id){
loadAdress(adress_id) {
return this.$fhcApi.get('api/frontend/v1/stv/kontakt/loadAddress/' + adress_id)
.then(result => {
this.addressData = result.data;
@@ -216,7 +215,7 @@ export default{
})
.catch(this.$fhcAlert.handleSystemError);
},
updateAddress(adress_id){
updateAddress(adress_id) {
this.$fhcApi.post('api/frontend/v1/stv/kontakt/updateAddress/' + adress_id,
this.addressData
).then(response => {
@@ -229,7 +228,7 @@ export default{
this.reload();
});
},
deleteAddress(adress_id){
deleteAddress(adress_id) {
this.$fhcApi.post('api/frontend/v1/stv/kontakt/deleteAddress/' + adress_id)
.then(response => {
this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete'));
@@ -247,13 +246,12 @@ export default{
return;
this.abortController.places = new AbortController();
CoreRESTClient
.get('components/stv/address/getPlaces/' + this.addressData.plz, undefined, {
this.$fhcApi
.get('api/frontend/v1/stv/address/getPlaces/' + this.addressData.plz, undefined, {
signal: this.abortController.places.signal
})
.then(result => CoreRESTClient.getData(result.data) || [])
.then(result => {
this.places = result;
this.places = result.data;
});
/* .catch(error => {
if (error.code == 'ERR_BAD_REQUEST') {
@@ -271,20 +269,19 @@ export default{
this.filteredFirmen = result.data.retval;
});
},
hideModal(modalRef){
hideModal(modalRef) {
this.$refs[modalRef].hide();
},
resetModal(){
resetModal() {
this.addressData = {};
this.addressData = this.initData;
},
},
created(){
CoreRESTClient
.get('components/stv/Address/getNations')
.then(result => CoreRESTClient.getData(result.data) || [])
created() {
this.$fhcApi
.get('api/frontend/v1/stv/address/getNations')
.then(result => {
this.nations = result;
this.nations = result.data;
})
.catch(this.$fhcAlert.handleSystemError);
this.$fhcApi