From 0536deda1acfcd0f60cf0b57fee0d0073de0c2db Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Mon, 29 Apr 2024 14:47:44 +0200 Subject: [PATCH 1/5] StV: static primevue --- application/views/Studentenverwaltung.php | 2 +- public/js/apps/Studentenverwaltung.js | 49 ++++++++++------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/application/views/Studentenverwaltung.php b/application/views/Studentenverwaltung.php index 54354578e..8993053b3 100644 --- a/application/views/Studentenverwaltung.php +++ b/application/views/Studentenverwaltung.php @@ -5,7 +5,7 @@ 'bootstrap5' => true, 'fontawesome6' => true, 'vue3' => true, - #'primevue3' => true, + 'primevue3' => true, #'filtercomponent' => true, 'tabulator5' => true, 'tinymce5' => true, diff --git a/public/js/apps/Studentenverwaltung.js b/public/js/apps/Studentenverwaltung.js index 9b24008e3..0d9ea90f5 100644 --- a/public/js/apps/Studentenverwaltung.js +++ b/public/js/apps/Studentenverwaltung.js @@ -20,33 +20,28 @@ import fhcapifactory from "./api/fhcapifactory.js"; import Phrasen from "../plugin/Phrasen.js"; -//import PrimeVue form "../../../../index.ci.php/public/js/components/primevue/config/config.esm.min.js"); -//const PrimeVue = await import(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/public/js/components/primevue/config/config.esm.min.js").default; -import(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + "/public/js/components/primevue/config/config.esm.min.js").then(result => result.default).then(PrimeVue => { - Vue.$fhcapi = fhcapifactory; - const ciPath = FHC_JS_DATA_STORAGE_OBJECT.app_root.replace(/(https:|)(^|\/\/)(.*?\/)/g, '') + FHC_JS_DATA_STORAGE_OBJECT.ci_router; +const ciPath = FHC_JS_DATA_STORAGE_OBJECT.app_root.replace(/(https:|)(^|\/\/)(.*?\/)/g, '') + FHC_JS_DATA_STORAGE_OBJECT.ci_router; - const router = VueRouter.createRouter({ - history: VueRouter.createWebHistory(), - routes: [ - { path: `/${ciPath}/studentenverwaltung`, component: FhcStudentenverwaltung }, - { path: `/${ciPath}/studentenverwaltung/prestudent/:prestudent_id`, component: FhcStudentenverwaltung }, - { path: `/${ciPath}/studentenverwaltung/prestudent/:prestudent_id/:tab`, component: FhcStudentenverwaltung }, - { path: `/${ciPath}/studentenverwaltung/student/:id`, component: FhcStudentenverwaltung }, - { path: `/${ciPath}/studentenverwaltung/person/:person_id`, component: FhcStudentenverwaltung } - ] - }); - - const app = Vue.createApp(); - - app - .use(router) - .use(PrimeVue, { - zIndex: { - overlay: 1100 - } - }) - .use(Phrasen) - .mount('#main'); +const router = VueRouter.createRouter({ + history: VueRouter.createWebHistory(), + routes: [ + { path: `/${ciPath}/studentenverwaltung`, component: FhcStudentenverwaltung }, + { path: `/${ciPath}/studentenverwaltung/prestudent/:prestudent_id`, component: FhcStudentenverwaltung }, + { path: `/${ciPath}/studentenverwaltung/prestudent/:prestudent_id/:tab`, component: FhcStudentenverwaltung }, + { path: `/${ciPath}/studentenverwaltung/student/:id`, component: FhcStudentenverwaltung }, + { path: `/${ciPath}/studentenverwaltung/person/:person_id`, component: FhcStudentenverwaltung } + ] }); + +const app = Vue.createApp(); + +app + .use(router) + .use(primevue.config.default, { + zIndex: { + overlay: 1100 + } + }) + .use(Phrasen) + .mount('#main'); From c2ffd0290734c698df9e85de4a857e559f447d0a Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Mon, 29 Apr 2024 15:00:38 +0200 Subject: [PATCH 2/5] Consolidate FHCApi childs --- .../api/frontend/v1/stv/Config.php | 2 +- .../api/frontend/v1/stv/Filter.php | 14 +--- .../controllers/api/frontend/v1/stv/Konto.php | 34 +++----- .../controllers/api/frontend/v1/stv/Lists.php | 15 +--- .../api/frontend/v1/stv/Student.php | 78 ++++++------------- public/js/apps/Studentenverwaltung.js | 2 +- 6 files changed, 42 insertions(+), 103 deletions(-) diff --git a/application/controllers/api/frontend/v1/stv/Config.php b/application/controllers/api/frontend/v1/stv/Config.php index 9aaf49651..d97c1a86b 100644 --- a/application/controllers/api/frontend/v1/stv/Config.php +++ b/application/controllers/api/frontend/v1/stv/Config.php @@ -31,7 +31,7 @@ class Config extends FHCAPI_Controller public function __construct() { - // TODO(chris): access! + // TODO(chris): permissions parent::__construct([ 'student' => self::PERM_LOGGED, 'students' => self::PERM_LOGGED diff --git a/application/controllers/api/frontend/v1/stv/Filter.php b/application/controllers/api/frontend/v1/stv/Filter.php index d5ee44d13..dbf70e4fb 100644 --- a/application/controllers/api/frontend/v1/stv/Filter.php +++ b/application/controllers/api/frontend/v1/stv/Filter.php @@ -31,10 +31,9 @@ class Filter extends FHCAPI_Controller */ public function __construct() { - // TODO(chris): permissions parent::__construct([ - 'getStg' => 'student/stammdaten:r',#self::PERM_LOGGED, - 'setStg' => 'student/stammdaten:r'#self::PERM_LOGGED + 'getStg' => self::PERM_LOGGED, + 'setStg' => self::PERM_LOGGED ]); // Load models @@ -53,10 +52,7 @@ class Filter extends FHCAPI_Controller { $result = $this->VariableModel->getVariables(getAuthUID(), ['kontofilterstg']); - #$data = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $data = $result->retval; + $data = $this->getDataOrTerminateWithError($result); $this->terminateWithSuccess($data['kontofilterstg'] == 'true'); } @@ -81,9 +77,7 @@ class Filter extends FHCAPI_Controller $result = $this->VariableModel->setVariable(getAuthUID(), 'kontofilterstg', $studiengang_kz ? 'true' : 'false'); - #$this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $this->getDataOrTerminateWithError($result); $this->terminateWithSuccess(true); } diff --git a/application/controllers/api/frontend/v1/stv/Konto.php b/application/controllers/api/frontend/v1/stv/Konto.php index 4606f5abc..a4344889c 100644 --- a/application/controllers/api/frontend/v1/stv/Konto.php +++ b/application/controllers/api/frontend/v1/stv/Konto.php @@ -33,10 +33,9 @@ class Konto extends FHCAPI_Controller */ public function __construct() { - // TODO(chris): permissions parent::__construct([ 'get' => 'student/stammdaten:r', - 'getBuchungstypen' => 'student/stammdaten:r', // alle? + 'getBuchungstypen' => self::PERM_LOGGED, 'checkDoubles' => ['admin:r', 'assistenz:r'], 'insert' => ['admin:w', 'assistenz:w'], 'counter' => ['admin:w', 'assistenz:w'], @@ -82,10 +81,7 @@ class Konto extends FHCAPI_Controller $result = $this->KontoModel->getAlleBuchungen($person_id, $studiengang_kz); } - #$result = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $result = $result->retval; + $result = $this->getDataOrTerminateWithError($result); // sort into tree $childs = []; @@ -122,10 +118,7 @@ class Konto extends FHCAPI_Controller $result = $this->BuchungstypModel->load(); - #$data = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $data = $result->retval; + $data = $this->getDataOrTerminateWithError($result); $this->terminateWithSuccess($data); } @@ -163,10 +156,7 @@ class Konto extends FHCAPI_Controller $result = $this->KontoModel->checkDoubleBuchung($person_ids, $this->input->post('studiensemester_kurzbz'), $buchungstypen[$buchung]); - #$result = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $result = $result->retval; + $result = $this->getDataOrTerminateWithError($result); if (!$result) $this->terminateWithSuccess(false); @@ -441,9 +431,7 @@ class Konto extends FHCAPI_Controller $result = $this->KontoModel->update($id, $data); - #$this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $this->getDataOrTerminateWithError($result); $result = null; // TODO(chris): get as tree? @@ -475,15 +463,13 @@ class Konto extends FHCAPI_Controller $buchungsnr = $this->input->post('buchungsnr'); $result = $this->KontoModel->load($buchungsnr); - #$result = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $result = $result->retval; + + $result = $this->getDataOrTerminateWithError($result); if (!$result) $this->terminateWithError($this->p->t('konto', 'error_missing', [ 'buchungsnr' => $buchungsnr - ]), self::ERROR_TYPE_GENERAL); + ])); $_POST['studiengang_kz'] = current($result)->studiengang_kz; @@ -500,8 +486,8 @@ class Konto extends FHCAPI_Controller $result = $this->KontoModel->delete($buchungsnr); if (isError($result)) { if (getCode($result) != 42) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $this->terminateWithError($this->p->t('konto', 'error_delete_level'), self::ERROR_TYPE_GENERAL); + $this->terminateWithError(getError($result)); + $this->terminateWithError($this->p->t('konto', 'error_delete_level')); } $this->terminateWithSuccess(); diff --git a/application/controllers/api/frontend/v1/stv/Lists.php b/application/controllers/api/frontend/v1/stv/Lists.php index 2a8335b7e..9b0c705d1 100644 --- a/application/controllers/api/frontend/v1/stv/Lists.php +++ b/application/controllers/api/frontend/v1/stv/Lists.php @@ -27,10 +27,9 @@ class Lists extends FHCAPI_Controller { public function __construct() { - // TODO(chris): permissions parent::__construct([ - 'getStudiensemester' => ['admin:r', 'assistenz:r', 'student/stammdaten:r'], // alle? - 'getStgs' => ['admin:r', 'assistenz:r', 'student/stammdaten:r'] // alle? + 'getStudiensemester' => self::PERM_LOGGED, + 'getStgs' => self::PERM_LOGGED ]); } @@ -42,10 +41,7 @@ class Lists extends FHCAPI_Controller $result = $this->StudiensemesterModel->load(); - #$data = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $data = $result->retval; + $data = $this->getDataOrTerminateWithError($result); $this->terminateWithSuccess($data); } @@ -62,10 +58,7 @@ class Lists extends FHCAPI_Controller $result = $this->StudiengangModel->load(); - #$data = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $data = $result->retval; + $data = $this->getDataOrTerminateWithError($result); $this->terminateWithSuccess($data); } diff --git a/application/controllers/api/frontend/v1/stv/Student.php b/application/controllers/api/frontend/v1/stv/Student.php index 101d34863..31fc7075c 100644 --- a/application/controllers/api/frontend/v1/stv/Student.php +++ b/application/controllers/api/frontend/v1/stv/Student.php @@ -100,10 +100,7 @@ class Student extends FHCAPI_Controller $result = $this->PrestudentModel->loadWhere(['prestudent_id' => $prestudent_id]); - #$student = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $student = $result->retval; + $student = $this->getDataOrTerminateWithError($result); if (!$student) return show_404(); @@ -136,10 +133,7 @@ class Student extends FHCAPI_Controller $result = $this->udflib->getCiValidations($this->PersonModel, $this->input->post()); - #$fieldValidations = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result)); - $fieldvalidations = $result->retval; + $fieldValidations = $this->getDataOrTerminateWithError($result); $this->form_validation->set_rules($fieldvalidations); @@ -148,19 +142,13 @@ class Student extends FHCAPI_Controller $result = $this->StudentModel->loadWhere(['prestudent_id' => $prestudent_id]); - #$student = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $student = $result->retval; + $student = $this->getDataOrTerminateWithError($result); $uid = $student ? current($student)->student_uid : null; $result = $this->PrestudentModel->loadWhere(['prestudent_id' => $prestudent_id]); - #$person = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result)); - $person = $result->retval; + $person = $this->getDataOrTerminateWithError($result); $person_id = $person ? current($person)->person_id : null; @@ -201,10 +189,7 @@ class Student extends FHCAPI_Controller // add UDFs $result = $this->udflib->getDefinitionForModel($this->PersonModel); - #$definitions = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $definitions = $result->retval; + $definitions = $this->getDataOrTerminateWithError($result); foreach ($definitions as $def) $array_allowed_props_person[] = $def['name']; @@ -242,9 +227,7 @@ class Student extends FHCAPI_Controller 'studiensemester_kurzbz' => $studiensemester_kurzbz, 'student_uid' => $uid ], $update_lehrverband); - #$this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $this->getDataOrTerminateWithError($result); } if (count($update_person)) { @@ -252,9 +235,7 @@ class Student extends FHCAPI_Controller $person_id, $update_person ); - #$this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $this->getDataOrTerminateWithError($result); } @@ -263,9 +244,7 @@ class Student extends FHCAPI_Controller [$uid], $update_student ); - #$this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $this->getDataOrTerminateWithError($result); } $this->terminateWithSuccess(array_fill_keys(array_merge( @@ -308,10 +287,7 @@ class Student extends FHCAPI_Controller $result = $this->PersonModel->load(); - #$data = $this->getDataOrTerminateWithError($result); - if (isError($result)) - $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); - $data = $result->retval; + $data = $this->getDataOrTerminateWithError($result); $this->terminateWithSuccess($data); } @@ -413,9 +389,7 @@ class Student extends FHCAPI_Controller $data['staatsbuergerschaft'] = $this->input->post('staatsbuergerschaft'); $result = $this->PersonModel->insert($data); - if (isError($result)) - return $result; - $person_id = getData($result); + $person_id = $this->getDataOrTerminateWithError($result); } // Addresse anlegen @@ -438,17 +412,15 @@ class Student extends FHCAPI_Controller $result = $this->AdresseModel->loadWhere([ 'person_id' => $person_id ]); - if (isError($result)) - return $result; - if (hasData($result)) { - $address = current(getData($result)); + $address = $this->getDataOrTerminateWithError($result); + if ($address) { + $address = current($address); $data['updateamum'] = date('c'); $data['updatevon'] = getAuthUID(); $result = $this->AdresseModel->update($address->adresse_id, $data); - if (isError($result)) - return $result; + $this->getDataOrTerminateWithError($result); } else { //Wenn keine Adrese vorhanden ist dann eine neue Anlegen $anlegen = 1; @@ -463,8 +435,7 @@ class Student extends FHCAPI_Controller $data['heimatadresse'] = !$this->input->post('person_id'); $result = $this->AdresseModel->insert($data); - if (isError($result)) - return $result; + $this->getDataOrTerminateWithError($result); } } @@ -488,8 +459,7 @@ class Student extends FHCAPI_Controller 'insertvon' => getAuthUID() ]; $result = $this->KontaktModel->insert($data); - if (isError($result)) - return $result; + $this->getDataOrTerminateWithError($result); } } @@ -517,10 +487,9 @@ class Student extends FHCAPI_Controller $result = $this->PrestudentModel->loadWhere([ 'person_id' => $person_id ]); - if (isError($result)) - return $result; - if (hasData($result)) { - $prestudent = current(getData($result)); + $prestudent = $this->getDataOrTerminateWithError($result); + if ($prestudent) { + $prestudent = current($prestudent); if ($prestudent->zgv_code) { $data['zgv_code'] = $prestudent->zgv_code; $data['zgvort'] = $prestudent->zgvort; @@ -533,9 +502,7 @@ class Student extends FHCAPI_Controller } // Prestudent speichern $result = $this->PrestudentModel->insert($data); - if (isError($result)) - return $result; - $prestudent_id = getData($result); + $prestudent_id = $this->getDataOrTerminateWithError($result); // Prestudent Rolle Anlegen $data = [ @@ -550,8 +517,7 @@ class Student extends FHCAPI_Controller 'insertvon' => getAuthUID() ]; $result = $this->PrestudentstatusModel->insert($data); - if (isError($result)) - return $result; + $this->getDataOrTerminateWithError($result); if ($incoming) { // TODO(chris): IMPLEMENT! @@ -569,7 +535,7 @@ class Student extends FHCAPI_Controller return $result; }*/ - return success(true); + $this->terminateWithSuccess(true); } public function requiredIfNotPersonId($value) diff --git a/public/js/apps/Studentenverwaltung.js b/public/js/apps/Studentenverwaltung.js index 0d9ea90f5..fbbee8e1d 100644 --- a/public/js/apps/Studentenverwaltung.js +++ b/public/js/apps/Studentenverwaltung.js @@ -1,5 +1,5 @@ /** - * Copyright (C) 2022 fhcomplete.org + * 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 From c8009a8a6cc498d0e4d2590f6a2d946077646f63 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Tue, 30 Apr 2024 08:33:39 +0200 Subject: [PATCH 3/5] API Konsolodierung: stv lists --- .../controllers/api/frontend/v1/stv/Lists.php | 58 ++++++++++++- .../controllers/components/stv/Lists.php | 85 ------------------- .../js/components/Stv/Studentenverwaltung.js | 28 +++--- 3 files changed, 69 insertions(+), 102 deletions(-) delete mode 100644 application/controllers/components/stv/Lists.php diff --git a/application/controllers/api/frontend/v1/stv/Lists.php b/application/controllers/api/frontend/v1/stv/Lists.php index 9b0c705d1..eceaf8c8c 100644 --- a/application/controllers/api/frontend/v1/stv/Lists.php +++ b/application/controllers/api/frontend/v1/stv/Lists.php @@ -29,7 +29,11 @@ class Lists extends FHCAPI_Controller { parent::__construct([ 'getStudiensemester' => self::PERM_LOGGED, - 'getStgs' => self::PERM_LOGGED + 'getStgs' => self::PERM_LOGGED, + 'getSprachen' => self::PERM_LOGGED, + 'getGeschlechter' => self::PERM_LOGGED, + 'getAusbildungen' => self::PERM_LOGGED, + 'getOrgforms' => self::PERM_LOGGED ]); } @@ -62,4 +66,56 @@ class Lists extends FHCAPI_Controller $this->terminateWithSuccess($data); } + + public function getSprachen() + { + $this->load->model('system/Sprache_model', 'SpracheModel'); + + $this->SpracheModel->addOrder('sprache'); + + $result = $this->SpracheModel->load(); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getGeschlechter() + { + $this->load->model('person/Geschlecht_model', 'GeschlechtModel'); + + $this->GeschlechtModel->addOrder('sort'); + $this->GeschlechtModel->addOrder('geschlecht'); + + $this->GeschlechtModel->addSelect('*'); + $this->GeschlechtModel->addSelect("bezeichnung_mehrsprachig[(SELECT index FROM public.tbl_sprache WHERE sprache=" . $this->GeschlechtModel->escape(DEFAULT_LANGUAGE) . " LIMIT 1)] AS bezeichnung"); + + $result = $this->GeschlechtModel->load(); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getAusbildungen() + { + $this->load->model('codex/Ausbildung_model', 'AusbildungModel'); + + $this->AusbildungModel->addOrder('ausbildungcode'); + + $result = $this->AusbildungModel->load(); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getOrgforms() + { + $this->load->model('codex/Orgform_model', 'OrgformModel'); + + $this->OrgformModel->addOrder('bezeichnung'); + + $result = $this->OrgformModel->loadWhere(['rolle' => true]); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } } diff --git a/application/controllers/components/stv/Lists.php b/application/controllers/components/stv/Lists.php deleted file mode 100644 index 959de7a12..000000000 --- a/application/controllers/components/stv/Lists.php +++ /dev/null @@ -1,85 +0,0 @@ -load->model('system/Sprache_model', 'SpracheModel'); - - $this->SpracheModel->addOrder('sprache'); - - $result = $this->SpracheModel->load(); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - } - $this->outputJson($result); - } - - public function getGeschlechter() - { - $this->load->model('person/Geschlecht_model', 'GeschlechtModel'); - - $this->GeschlechtModel->addOrder('sort'); - $this->GeschlechtModel->addOrder('geschlecht'); - - $this->GeschlechtModel->addSelect('*'); - $this->GeschlechtModel->addSelect("bezeichnung_mehrsprachig[(SELECT index FROM public.tbl_sprache WHERE sprache=" . $this->GeschlechtModel->escape(DEFAULT_LANGUAGE) . " LIMIT 1)] AS bezeichnung"); - - $result = $this->GeschlechtModel->load(); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - } - $this->outputJson($result); - } - - public function getAusbildungen() - { - $this->load->model('codex/Ausbildung_model', 'AusbildungModel'); - - $this->AusbildungModel->addOrder('ausbildungcode'); - - $result = $this->AusbildungModel->load(); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - } - $this->outputJson($result); - } - - public function getStgs() - { - $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); - - $this->StudiengangModel->addSelect('*'); - $this->StudiengangModel->addSelect('UPPER(typ || kurzbz) AS kuerzel'); - - $this->StudiengangModel->addOrder('typ'); - $this->StudiengangModel->addOrder('kurzbz'); - - $result = $this->StudiengangModel->loadWhere(['aktiv' => true]); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - } - $this->outputJson($result); - } - - public function getOrgforms() - { - $this->load->model('codex/Orgform_model', 'OrgformModel'); - - $this->OrgformModel->addOrder('bezeichnung'); - - $result = $this->OrgformModel->loadWhere(['rolle' => true]); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - } - $this->outputJson($result); - } -} diff --git a/public/js/components/Stv/Studentenverwaltung.js b/public/js/components/Stv/Studentenverwaltung.js index 69fa03dee..05a84499d 100644 --- a/public/js/components/Stv/Studentenverwaltung.js +++ b/public/js/components/Stv/Studentenverwaltung.js @@ -128,25 +128,22 @@ export default { this.lists.nations = result; }) .catch(this.$fhcAlert.handleSystemError); - CoreRESTClient - .get('components/stv/Lists/getSprachen') - .then(result => CoreRESTClient.getData(result.data) || []) + this.$fhcApi + .get('api/frontend/v1/stv/lists/getSprachen') .then(result => { - this.lists.sprachen = result; + this.lists.sprachen = result.data; }) .catch(this.$fhcAlert.handleSystemError); - CoreRESTClient - .get('components/stv/Lists/getGeschlechter') - .then(result => CoreRESTClient.getData(result.data) || []) + this.$fhcApi + .get('api/frontend/v1/stv/lists/getGeschlechter') .then(result => { - this.lists.geschlechter = result; + this.lists.geschlechter = result.data; }) .catch(this.$fhcAlert.handleSystemError); - CoreRESTClient - .get('components/stv/Lists/getAusbildungen') - .then(result => CoreRESTClient.getData(result.data) || []) + this.$fhcApi + .get('api/frontend/v1/stv/lists/getAusbildungen') .then(result => { - this.lists.ausbildungen = result; + this.lists.ausbildungen = result.data; }) .catch(this.$fhcAlert.handleSystemError); this.$fhcApi @@ -156,11 +153,10 @@ export default { this.lists.active_stgs = this.lists.stgs.filter(stg => stg.aktiv); }) .catch(this.$fhcAlert.handleSystemError); - CoreRESTClient - .get('components/stv/Lists/getOrgforms') - .then(result => CoreRESTClient.getData(result.data) || []) + this.$fhcApi + .get('api/frontend/v1/stv/lists/getOrgforms') .then(result => { - this.lists.orgforms = result; + this.lists.orgforms = result.data; }) .catch(this.$fhcAlert.handleSystemError); this.$fhcApi From fe06b2360eef8d2149bf7b536465f3495e56787d Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Tue, 30 Apr 2024 08:48:15 +0200 Subject: [PATCH 4/5] API Konsolodierung: stv address --- .../api/frontend/v1/stv/Address.php | 66 +++++++++++++++++++ .../controllers/components/stv/Address.php | 47 ------------- .../js/components/Stv/Studentenverwaltung.js | 14 ++-- .../Details/Kontakt/Address.js | 39 +++++------ 4 files changed, 88 insertions(+), 78 deletions(-) create mode 100644 application/controllers/api/frontend/v1/stv/Address.php delete mode 100644 application/controllers/components/stv/Address.php diff --git a/application/controllers/api/frontend/v1/stv/Address.php b/application/controllers/api/frontend/v1/stv/Address.php new file mode 100644 index 000000000..7685fcd04 --- /dev/null +++ b/application/controllers/api/frontend/v1/stv/Address.php @@ -0,0 +1,66 @@ +. + */ + +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); + } +} diff --git a/application/controllers/components/stv/Address.php b/application/controllers/components/stv/Address.php deleted file mode 100644 index c0e34c0c3..000000000 --- a/application/controllers/components/stv/Address.php +++ /dev/null @@ -1,47 +0,0 @@ -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); - } -} diff --git a/public/js/components/Stv/Studentenverwaltung.js b/public/js/components/Stv/Studentenverwaltung.js index 05a84499d..2fe6c9713 100644 --- a/public/js/components/Stv/Studentenverwaltung.js +++ b/public/js/components/Stv/Studentenverwaltung.js @@ -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 {
diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Kontakt/Address.js b/public/js/components/Stv/Studentenverwaltung/Details/Kontakt/Address.js index 017f3a056..e2301f7a3 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Kontakt/Address.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Kontakt/Address.js @@ -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 From 9d0e63e6953d9303ddf29a9204df0050bb91ad20 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Tue, 30 Apr 2024 13:22:08 +0200 Subject: [PATCH 5/5] API Konsolidierung Verband --- .../frontend/v1}/stv/Verband.php | 99 +++++++++---------- .../Stv/Studentenverwaltung/List/New.js | 10 +- .../Stv/Studentenverwaltung/Verband.js | 15 ++- 3 files changed, 61 insertions(+), 63 deletions(-) rename application/controllers/{components => api/frontend/v1}/stv/Verband.php (86%) diff --git a/application/controllers/components/stv/Verband.php b/application/controllers/api/frontend/v1/stv/Verband.php similarity index 86% rename from application/controllers/components/stv/Verband.php rename to application/controllers/api/frontend/v1/stv/Verband.php index 18ce5c999..5a7960fd5 100644 --- a/application/controllers/components/stv/Verband.php +++ b/application/controllers/api/frontend/v1/stv/Verband.php @@ -1,17 +1,41 @@ . + */ if (! defined('BASEPATH')) exit('No direct script access allowed'); -class Verband extends FHC_Controller +/** + * This controller operates between (interface) the JS (GUI) and the back-end + * Provides data to the ajax get calls about verbände + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + */ +class Verband extends FHCAPI_Controller { public function __construct() { - // TODO(chris): access! - parent::__construct(); - + // TODO(chris): permissions + $permissions = []; + $router = load_class('Router'); + $permissions[$router->method] = self::PERM_LOGGED; + parent::__construct($permissions); + + // Load Models $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); } - /** * Remap calls: * / @@ -75,12 +99,9 @@ class Verband extends FHC_Controller $this->StudiengangModel->addOrder('kurzbz'); $result = $this->StudiengangModel->loadWhere(['v.aktiv' => true]); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson(getError($result)); - } - $list = getData($result) ?: []; + $list = $this->getDataOrTerminateWithError($result); + $list[] = [ 'name' => 'International', 'link' => 'inout', @@ -102,7 +123,7 @@ class Verband extends FHC_Controller ] ] ]; - $this->outputJson($list); + $this->terminateWithSuccess($list); } /** @@ -139,12 +160,8 @@ class Verband extends FHC_Controller 'v.studiengang_kz' => $studiengang_kz, 'v.aktiv' => true ]); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson(getError($result)); - } + $list = $this->getDataOrTerminateWithError($result); - $list = getData($result) ?: []; array_unshift($list, [ 'name' => 'PreStudent', 'link' => $link . 'prestudent', @@ -154,12 +171,9 @@ class Verband extends FHC_Controller if ($org_form === null) { // NOTE(chris): if mischform show orgforms $result = $this->StudiengangModel->load($studiengang_kz); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson(getError($result)); - } - if (hasData($result)) { - if (current(getData($result))->mischform) { + $result = $this->getDataOrTerminateWithError($result); + if ($result) { + if (current($result)->mischform) { $this->load->model('organisation/Studienordnung_model', 'StudienordnungModel'); $this->StudienordnungModel->addDistinct(); @@ -175,18 +189,14 @@ class Verband extends FHC_Controller 'studiengang_kz' => $studiengang_kz, 'p.orgform_kurzbz !=' => 'DDP' ]); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson(getError($result)); - } + $result = $this->getDataOrTerminateWithError($result); - if (hasData($result)) - $list = array_merge($list, getData($result)); + $list = array_merge($list, $result); } } } - $this->outputJson($list); + $this->terminateWithSuccess($list); } /** @@ -231,13 +241,8 @@ class Verband extends FHC_Controller $where['orgform_kurzbz'] = $org_form; $result = $this->GruppeModel->loadWhere($where); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson(getError($result)); - } - - $list = getData($result) ?: []; + $list = $this->getDataOrTerminateWithError($result); $this->StudiengangModel->addJoin('public.tbl_lehrverband v', 'studiengang_kz'); @@ -263,14 +268,11 @@ class Verband extends FHC_Controller $where['v.orgform_kurzbz'] = $org_form; $result = $this->StudiengangModel->loadWhere($where); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson(getError($result)); - } + $result = $this->getDataOrTerminateWithError($result); - $list = array_merge($list, getData($result) ?: []); + $list = array_merge($list, $result); - $this->outputJson($list); + $this->terminateWithSuccess($list); } /** @@ -313,14 +315,10 @@ class Verband extends FHC_Controller $where['v.orgform_kurzbz'] = $org_form; $result = $this->StudiengangModel->loadWhere($where); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJson(getError($result)); - } - $list = getData($result) ?: []; + $list = $this->getDataOrTerminateWithError($result); - $this->outputJson($list); + $this->terminateWithSuccess($list); } /** @@ -341,13 +339,8 @@ class Verband extends FHC_Controller * - then: $stsem_obj->getPlusMinus(NULL, $number_displayed_past_studiensemester, 'ende ASC'); */ $result = $this->StudiensemesterModel->load(); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - $this->outputJson(getError($result)); - exit; - } - $studiensemester = getData($result) ?: []; + $studiensemester = $this->getDataOrTerminateWithError($result); $result = []; foreach ($studiensemester as $sem) { diff --git a/public/js/components/Stv/Studentenverwaltung/List/New.js b/public/js/components/Stv/Studentenverwaltung/List/New.js index f23245b7c..351737e23 100644 --- a/public/js/components/Stv/Studentenverwaltung/List/New.js +++ b/public/js/components/Stv/Studentenverwaltung/List/New.js @@ -130,21 +130,21 @@ export default { this.abortController.places = new AbortController(); this.$refs.form - .send(CoreRESTClient.get( - 'components/stv/address/getPlaces/' + this.formData.address.plz, + .get( + 'api/frontend/v1/stv/address/getPlaces/' + this.formData.address.plz, undefined, { signal: this.abortController.places.signal } - )) + ) .then(result => { - this.places = result + this.places = result.data }) .catch(error => { if (error.code != "ERR_CANCELED") window.setTimeout(this.loadPlaces, 100); else - console.error(error); + this.$fhcAlert.handleSystemError(error); }); }, loadStudienplaene() { diff --git a/public/js/components/Stv/Studentenverwaltung/Verband.js b/public/js/components/Stv/Studentenverwaltung/Verband.js index 92d343f08..bdc5500a6 100644 --- a/public/js/components/Stv/Studentenverwaltung/Verband.js +++ b/public/js/components/Stv/Studentenverwaltung/Verband.js @@ -53,8 +53,8 @@ export default { }); this.loading = true; - CoreRESTClient - .get("components/stv/verband/" + node.data.link) + this.$fhcApi + .get('api/frontend/v1/stv/verband/' + node.data.link) .then(result => result.data) .then(result => { const subNodes = result.map(this.mapResultToTreeData); @@ -128,7 +128,12 @@ export default { let promises = []; for (let parent in sortedInParents) - promises.push(CoreRESTClient.get("components/stv/verband/" + (parent == '_' ? '' : parent)).then(res => res.data).then(res => res.filter(node => sortedInParents[parent].includes(node.link + '')))); + promises.push( + this.$fhcApi + .get('api/frontend/v1/stv/verband/' + (parent == '_' ? '' : parent)) + .then(res => res.data) + .then(res => res.filter(node => sortedInParents[parent].includes(node.link + ''))) + ); // NOTE(chris): merge the resulting arrays and transform them to an associative one let result = [].concat.apply([], await Promise.all(promises)).reduce((o, node) => { @@ -171,8 +176,8 @@ export default { } }, mounted() { - CoreRESTClient - .get("components/stv/verband") + this.$fhcApi + .get('api/frontend/v1/stv/verband') .then(result => result.data) .then(result => { this.nodes = result.map(this.mapResultToTreeData);