From 1b65378d6c9a221e4bfaf81732eeb370b9147591 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Wed, 6 Mar 2024 11:47:34 +0100 Subject: [PATCH 01/30] Auth_Controller private functions --- application/core/Auth_Controller.php | 46 +++++++++++++++++++--------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/application/core/Auth_Controller.php b/application/core/Auth_Controller.php index c407a106f..899497872 100644 --- a/application/core/Auth_Controller.php +++ b/application/core/Auth_Controller.php @@ -25,6 +25,9 @@ abstract class Auth_Controller extends FHC_Controller * Checks if the caller is allowed to access to this content with the given permissions * If it is not allowed will set the HTTP header with code 401 * Wrapper for permissionlib->isEntitled + * + * @param array $requiredPermissions + * @return void */ private function _isAllowed($requiredPermissions) { @@ -34,28 +37,43 @@ abstract class Auth_Controller extends FHC_Controller // Checks if this user is entitled to access to this content if (!$this->permissionlib->isEntitled($requiredPermissions, $this->router->method)) { - $this->output->set_status_header(REST_Controller::HTTP_UNAUTHORIZED); // set the HTTP header as unauthorized - - $this->load->library('EPrintfLib'); // loads the EPrintfLib to format the output - - // Prints the main error message - $this->eprintflib->printError('You are not allowed to access to this content'); - // Prints the called controller name - $this->eprintflib->printInfo('Controller name: '.$this->router->class); - // Prints the called controller method name - $this->eprintflib->printInfo('Method name: '.$this->router->method); - // Prints the required permissions needed to access to this method - $this->eprintflib->printInfo('Required permissions: '.$this->_rpsToString($requiredPermissions, $this->router->method)); - + $this->_outputAuthError($requiredPermissions); exit; // immediately terminate the execution } } + /** + * Outputs an error message and sets the HTTP Header. + * This function is protected so that it can be overwritten. + * + * @param array $requiredPermissions + * @return void + */ + protected function _outputAuthError($requiredPermissions) + { + $this->output->set_status_header(REST_Controller::HTTP_UNAUTHORIZED); // set the HTTP header as unauthorized + + $this->load->library('EPrintfLib'); // loads the EPrintfLib to format the output + + // Prints the main error message + $this->eprintflib->printError('You are not allowed to access to this content'); + // Prints the called controller name + $this->eprintflib->printInfo('Controller name: '.$this->router->class); + // Prints the called controller method name + $this->eprintflib->printInfo('Method name: '.$this->router->method); + // Prints the required permissions needed to access to this method + $this->eprintflib->printInfo('Required permissions: '.$this->_rpsToString($requiredPermissions, $this->router->method)); + } + /** * Converts an array of permissions to a string that contains them as a comma separated list * Ex: ", , " + * + * @param array $requiredPermissions + * @param string $method + * @return void */ - private function _rpsToString($requiredPermissions, $method) + final protected function _rpsToString($requiredPermissions, $method) { $strRequiredPermissions = ''; // string that contains all the required permissions needed to access to this method From e89aa824d280c13179cbdd68613f6553be9160f1 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Wed, 6 Mar 2024 11:48:15 +0100 Subject: [PATCH 02/30] FHCAPI_Controller extends Auth_Controller + auth error handling in FhcApi --- application/core/FHCAPI_Controller.php | 109 ++++++++++--------------- public/js/plugin/FhcApi.js | 10 +++ 2 files changed, 52 insertions(+), 67 deletions(-) diff --git a/application/core/FHCAPI_Controller.php b/application/core/FHCAPI_Controller.php index e59740ded..ebb2f7978 100644 --- a/application/core/FHCAPI_Controller.php +++ b/application/core/FHCAPI_Controller.php @@ -5,7 +5,7 @@ if (!defined('BASEPATH')) exit('No direct script access allowed'); /** * Controller using JSON */ -class FHCAPI_Controller extends FHC_Controller +class FHCAPI_Controller extends Auth_Controller { /** @@ -19,12 +19,13 @@ class FHCAPI_Controller extends FHC_Controller /** * Error types */ - const ERROR_TYPE_PHP = 'php'; // TODO(chris): php types from severity? + const ERROR_TYPE_PHP = 'php'; const ERROR_TYPE_EXCEPTION = 'exception'; const ERROR_TYPE_GENERAL = 'general'; const ERROR_TYPE_404 = '404'; const ERROR_TYPE_DB = 'db'; const ERROR_TYPE_VALIDATION = 'validation'; + const ERROR_TYPE_AUTH = 'auth'; /** * Return Object @@ -45,10 +46,6 @@ class FHCAPI_Controller extends FHC_Controller if (is_cli()) show_404(); - parent::__construct(); - - $this->config->set_item('error_views_path', VIEWPATH.'errors'.DIRECTORY_SEPARATOR.'json'.DIRECTORY_SEPARATOR); - global $g_result; $g_result = $this; @@ -74,18 +71,14 @@ class FHCAPI_Controller extends FHC_Controller } } - #$this->returnObj['test'] = implode('/n', headers_list()); - return json_encode($this->returnObj); }); - // Load libraries - $this->load->library('AuthLib'); - $this->load->library('PermissionLib'); - - // Checks if the caller is allowed to access to this content - $this->_isAllowed($requiredPermissions); + // NOTE(chris): overwrite error_views_path before constructor + load_class('Config')->set_item('error_views_path', VIEWPATH.'errors'.DIRECTORY_SEPARATOR.'json'.DIRECTORY_SEPARATOR); + parent::__construct($requiredPermissions); + // For JSON Requests (as opposed to multipart/form-data) get the $_POST variable from the input stream instead if ($this->input->get_request_header('Content-Type', true) == 'application/json') $_POST = json_decode($this->security->xss_clean($this->input->raw_input_stream), true); @@ -136,15 +129,25 @@ class FHCAPI_Controller extends FHC_Controller $this->returnObj['data'] = $data; } + /** + * @param string $key + * @param mixed $value + * @return void + */ + public function addMeta($key, $value) + { + if (!isset($this->returnObj['meta'])) + $this->returnObj['meta'] = []; + $this->returnObj['meta'][$key] = $value; + } + /** * @param string $status * @return void */ public function setStatus($status) { - if (!isset($this->returnObj['meta'])) - $this->returnObj['meta'] = []; - $this->returnObj['meta']['status'] = $status; + $this->addMeta('status', $status); } @@ -152,6 +155,17 @@ class FHCAPI_Controller extends FHC_Controller // Handle Output object - Shortcut functions // --------------------------------------------------------------- + /** + * @param mixed $data (optional) + * @return void + */ + protected function terminateWithSuccess($data = null) + { + $this->setData($data); + $this->setStatus(self::STATUS_SUCCESS); + exit; + } + /** * @param array $errors * @return void @@ -164,17 +178,6 @@ class FHCAPI_Controller extends FHC_Controller exit(EXIT_ERROR); } - /** - * @param mixed $data (optional) - * @return void - */ - protected function terminateWithSuccess($data = null) - { - $this->setData($data); - $this->setStatus(self::STATUS_SUCCESS); - exit; - } - /** * @param array $error * @param string $type (optional) @@ -193,63 +196,35 @@ class FHCAPI_Controller extends FHC_Controller * @param string $errortype * @return void */ - protected function checkForErrors($result, $errortype = self::ERROR_TYPE_GENERAL) + protected function getDataOrTerminateWithError($result, $errortype = self::ERROR_TYPE_GENERAL) { - // TODO(chris): IMPLEMENT! if (isError($result)) { $this->terminateWithError(getError($result), $errortype); } return $result->retval; } - // TODO(chris): complete list - // --------------------------------------------------------------- // Security // --------------------------------------------------------------- /** - * Checks if the caller is allowed to access to this content with the given permissions - * If it is not allowed will set the HTTP header with code 401 - * Wrapper for permissionlib->isEntitled + * Outputs an error message and sets the HTTP Header. + * This overwrites the default behaviour to output a json object. * * @param array $requiredPermissions * @return void */ - protected function _isAllowed($requiredPermissions) + protected function _outputAuthError($requiredPermissions) { - // Checks if this user is entitled to access to this content - if (!$this->permissionlib->isEntitled($requiredPermissions, $this->router->method)) - { - $this->output->set_status_header(isLogged() ? REST_Controller::HTTP_FORBIDDEN : REST_Controller::HTTP_UNAUTHORIZED); + $this->output->set_status_header(isLogged() ? REST_Controller::HTTP_FORBIDDEN : REST_Controller::HTTP_UNAUTHORIZED); - $this->addError([ - 'message' => 'You are not allowed to access to this content', - 'controller' => $this->router->class, - 'method' => $this->router->method, - 'required_permissions' => $this->_rpsToString($requiredPermissions, $this->router->method) - ]); - exit; // immediately terminate the execution - } - } - - /** - * Converts an array of permissions to a string that contains them as a comma separated list - * Ex: ", , " - * - * @param array $requiredPermissions - * @param string $method - * @return void - */ - protected function _rpsToString($requiredPermissions, $method) - { - if (!isset($requiredPermissions[$method])) - return ''; - - if (!is_array($requiredPermissions[$method])) - return $requiredPermissions[$method]; - - return implode(', ', $requiredPermissions[$method]); + $this->addError([ + 'message' => 'You are not allowed to access to this content', + 'controller' => $this->router->class, + 'method' => $this->router->method, + 'required_permissions' => $this->_rpsToString($requiredPermissions, $this->router->method) + ], self::ERROR_TYPE_AUTH); } } diff --git a/public/js/plugin/FhcApi.js b/public/js/plugin/FhcApi.js index bacd27d43..8d5c6a38f 100644 --- a/public/js/plugin/FhcApi.js +++ b/public/js/plugin/FhcApi.js @@ -250,6 +250,16 @@ export default { message += 'Line Number: ' + error.line + '\n'; $fhcAlert.alertSystemError(message); + }, + auth(error) { + const $fhcAlert = app.config.globalProperties.$fhcAlert; + + + var message = ''; + message += 'Controller name: ' + error.controller + '\n'; + message += 'Method name: ' + error.method + '\n'; + message += 'Required permissions: ' + error.required_permissions + $fhcAlert.alertDefault('error', error.message, message); } } }; From 872ef7c31c3ab0eca33e8b93222d668713ee6d92 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Wed, 6 Mar 2024 13:02:34 +0100 Subject: [PATCH 03/30] Move Phrasen API --- .../controllers/api/frontend/v1/Phrasen.php | 27 +++++++++++++++++++ .../controllers/components/Phrasen.php | 2 +- public/js/plugin/Phrasen.js | 6 ++--- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Phrasen.php diff --git a/application/controllers/api/frontend/v1/Phrasen.php b/application/controllers/api/frontend/v1/Phrasen.php new file mode 100644 index 000000000..e8d99f472 --- /dev/null +++ b/application/controllers/api/frontend/v1/Phrasen.php @@ -0,0 +1,27 @@ +load->library('PhrasesLib', [$module], 'pj'); + $this->outputJson([ + 'data' => json_decode($this->pj->getJSON()), + 'meta' => [ + 'status' => FHCAPI_Controller::STATUS_SUCCESS + ] + ]); + } +} diff --git a/application/controllers/components/Phrasen.php b/application/controllers/components/Phrasen.php index 87516ce00..abcb051e9 100644 --- a/application/controllers/components/Phrasen.php +++ b/application/controllers/components/Phrasen.php @@ -3,7 +3,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** - * + * TODO(chris): depricated */ class Phrasen extends FHC_Controller { diff --git a/public/js/plugin/Phrasen.js b/public/js/plugin/Phrasen.js index 162dc2179..7dc9c71c7 100644 --- a/public/js/plugin/Phrasen.js +++ b/public/js/plugin/Phrasen.js @@ -24,10 +24,10 @@ const phrasen = { return Promise.all(category.map(cat => this.loadCategory(cat))); if (!loadingModules[category]) loadingModules[category] = axios - .get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/components/Phrasen/loadModule/' + category) + .get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/api/frontend/v1/phrasen/loadModule/' + category) .then(res => { - if (res.data.retval) - categories[category] = extractCategory(res.data.retval, category); + if (res?.data?.data) + categories[category] = extractCategory(res.data.data, category); else categories[category] = {}; }); From 68459e086a2105e56c50fd03aafc84dba59399de Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Wed, 6 Mar 2024 16:15:04 +0100 Subject: [PATCH 04/30] Auth_Controller special permissions --- application/core/Auth_Controller.php | 33 ++++++++++++++++++++++--- application/libraries/PermissionLib.php | 16 +++++++++++- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/application/core/Auth_Controller.php b/application/core/Auth_Controller.php index 899497872..d170a7eca 100644 --- a/application/core/Auth_Controller.php +++ b/application/core/Auth_Controller.php @@ -7,6 +7,10 @@ if (!defined('BASEPATH')) exit('No direct script access allowed'); */ abstract class Auth_Controller extends FHC_Controller { + // Special Permissions + const PERM_ANONYMOUS = 'anonymous'; // Everyone + const PERM_LOGGED = 'logged_in'; // Every registered user + /** * Extends this controller if authentication is required */ @@ -14,11 +18,32 @@ abstract class Auth_Controller extends FHC_Controller { parent::__construct(); - // Loads authentication library and starts authentication - $this->load->library('AuthLib'); + if (!is_array($requiredPermissions) || isEmptyArray($requiredPermissions)) + show_error('The given permissions is not a valid array or it is an empty one'); + + if (!isset($requiredPermissions[$this->router->method])) + show_error('The given permission array does not contain the given method or is not correctly set'); + + $anonAllowed = false; + if ($requiredPermissions[$this->router->method] == self::PERM_ANONYMOUS) + $anonAllowed = true; + elseif (is_array($requiredPermissions[$this->router->method]) + && in_array(self::PERM_ANONYMOUS, $requiredPermissions[$this->router->method])) + $anonAllowed = true; - // Checks if the caller is allowed to access to this content - $this->_isAllowed($requiredPermissions); + if ($anonAllowed) { + // Loads authentication library without authentication + $this->load->library('AuthLib', [false]); + + // Loads helper since it would only be called on authentication + $this->load->helper('hlp_authentication'); + } else { + // Loads authentication library and starts authentication + $this->load->library('AuthLib'); + + // Checks if the caller is allowed to access to this content + $this->_isAllowed($requiredPermissions); + } } /** diff --git a/application/libraries/PermissionLib.php b/application/libraries/PermissionLib.php index 09f89abee..bf8174cf4 100644 --- a/application/libraries/PermissionLib.php +++ b/application/libraries/PermissionLib.php @@ -21,6 +21,8 @@ require_once(FHCPATH.'include/functions.inc.php'); require_once(FHCPATH.'include/wawi_kostenstelle.class.php'); require_once(FHCPATH.'include/benutzerberechtigung.class.php'); +use \benutzerberechtigung as benutzerberechtigung; + class PermissionLib { // Available rights in the DB @@ -65,8 +67,10 @@ class PermissionLib if (!is_cli()) { // API Caller rights initialization + $authObj = $this->_ci->authlib->getAuthObj(); self::$bb = new benutzerberechtigung(); - self::$bb->getBerechtigungen(($this->_ci->authlib->getAuthObj())->{AuthLib::AO_USERNAME}); + if ($authObj) + self::$bb->getBerechtigungen($authObj->{AuthLib::AO_USERNAME}); } } @@ -166,6 +170,16 @@ class PermissionLib if ($checkPermissions === true) break; } } + elseif ($permissions[$pCounter] == Auth_Controller::PERM_ANONYMOUS) + { + $checkPermissions = true; + break; + } + elseif ($permissions[$pCounter] == Auth_Controller::PERM_LOGGED) + { + $checkPermissions = isLogged(); + break; + } else { show_error('The given permission does not use the correct format'); From f6427f57b8759bdd2f415d0b8c402990acc2bf46 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Wed, 6 Mar 2024 16:49:35 +0100 Subject: [PATCH 05/30] Use FHCAPI Controller for Phrasen --- .../controllers/api/frontend/v1/Phrasen.php | 13 ++++++------- public/js/plugin/Phrasen.js | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/application/controllers/api/frontend/v1/Phrasen.php b/application/controllers/api/frontend/v1/Phrasen.php index e8d99f472..6005b2c9c 100644 --- a/application/controllers/api/frontend/v1/Phrasen.php +++ b/application/controllers/api/frontend/v1/Phrasen.php @@ -5,8 +5,12 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** * */ -class Phrasen extends FHC_Controller +class Phrasen extends FHCAPI_Controller { + public function __construct() + { + parent::__construct(['loadModule' => [self::PERM_ANONYMOUS]]); + } //------------------------------------------------------------------------------------------------------------------ // Public methods @@ -17,11 +21,6 @@ class Phrasen extends FHC_Controller public function loadModule($module) { $this->load->library('PhrasesLib', [$module], 'pj'); - $this->outputJson([ - 'data' => json_decode($this->pj->getJSON()), - 'meta' => [ - 'status' => FHCAPI_Controller::STATUS_SUCCESS - ] - ]); + $this->terminateWithSuccess(json_decode($this->pj->getJSON())); } } diff --git a/public/js/plugin/Phrasen.js b/public/js/plugin/Phrasen.js index 7dc9c71c7..9365fa5f3 100644 --- a/public/js/plugin/Phrasen.js +++ b/public/js/plugin/Phrasen.js @@ -1,3 +1,5 @@ +import FhcApi from './FhcApi.js'; + const categories = Vue.reactive({}); const loadingModules = {}; @@ -23,13 +25,11 @@ const phrasen = { if (Array.isArray(category)) return Promise.all(category.map(cat => this.loadCategory(cat))); if (!loadingModules[category]) - loadingModules[category] = axios - .get(FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/api/frontend/v1/phrasen/loadModule/' + category) + loadingModules[category] = this.config.globalProperties.$fhcApi + .get('/api/frontend/v1/phrasen/loadModule/' + category) + .then(res => res?.data ? extractCategory(res.data, category) : {}) .then(res => { - if (res?.data?.data) - categories[category] = extractCategory(res.data.data, category); - else - categories[category] = {}; + categories[category] = res; }); return loadingModules[category]; }, @@ -62,6 +62,11 @@ const phrasen = { export default { install(app, options) { - app.config.globalProperties.$p = phrasen; + app.use(FhcApi); + app.config.globalProperties.$p = { + t: phrasen.t, + loadCategory: cat => phrasen.loadCategory.call(app, cat), + t_ref: phrasen.t_ref + }; } } From f2ebf25640737470e54aef0992a9f98bdf664a81 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Wed, 6 Mar 2024 16:51:25 +0100 Subject: [PATCH 06/30] Use new FhcApiFactory Folder --- public/js/api/fhcapifactory.js | 7 +++++++ public/js/api/phrasen.js | 5 +++++ public/js/api/search.js | 12 ++++++++++++ public/js/plugin/FhcApi.js | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 public/js/api/fhcapifactory.js create mode 100644 public/js/api/phrasen.js create mode 100644 public/js/api/search.js diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js new file mode 100644 index 000000000..e0ea89211 --- /dev/null +++ b/public/js/api/fhcapifactory.js @@ -0,0 +1,7 @@ +import search from "./search.js"; +import phrasen from "./phrasen.js"; + +export default { + search, + phrasen +}; diff --git a/public/js/api/phrasen.js b/public/js/api/phrasen.js new file mode 100644 index 000000000..5f1fff3e4 --- /dev/null +++ b/public/js/api/phrasen.js @@ -0,0 +1,5 @@ +export default { + loadCategory(category) { + return this.$fhcApi.get('/api/frontend/v1/phrasen/loadModule/' + category); + } +}; diff --git a/public/js/api/search.js b/public/js/api/search.js new file mode 100644 index 000000000..8544d9fe3 --- /dev/null +++ b/public/js/api/search.js @@ -0,0 +1,12 @@ +export default { + search: function(searchsettings) { + const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + + 'index.ci.php/components/SearchBar/search'; + return axios.post(url, searchsettings); + }, + searchdummy: function(searchsettings) { + const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + + 'public/js/apps/api/dummyapi.php/Search'; + return axios.post(url, searchsettings); + } +}; \ No newline at end of file diff --git a/public/js/plugin/FhcApi.js b/public/js/plugin/FhcApi.js index 8d5c6a38f..bca19619e 100644 --- a/public/js/plugin/FhcApi.js +++ b/public/js/plugin/FhcApi.js @@ -1,5 +1,5 @@ import FhcAlert from './FhcAlert.js'; -import FhcApiFactory from '../apps/api/fhcapifactory.js'; +import FhcApiFactory from '../api/fhcapifactory.js'; export default { From 1dcece85636e8b078bec2b2049d6cd2ff9096494 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Wed, 6 Mar 2024 16:52:10 +0100 Subject: [PATCH 07/30] Use Factory for Phrasen --- public/js/plugin/Phrasen.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/js/plugin/Phrasen.js b/public/js/plugin/Phrasen.js index 9365fa5f3..c0baf8629 100644 --- a/public/js/plugin/Phrasen.js +++ b/public/js/plugin/Phrasen.js @@ -25,8 +25,8 @@ const phrasen = { if (Array.isArray(category)) return Promise.all(category.map(cat => this.loadCategory(cat))); if (!loadingModules[category]) - loadingModules[category] = this.config.globalProperties.$fhcApi - .get('/api/frontend/v1/phrasen/loadModule/' + category) + loadingModules[category] = this.config.globalProperties + .$fhcApi.factory.phrasen.loadCategory(category) .then(res => res?.data ? extractCategory(res.data, category) : {}) .then(res => { categories[category] = res; From 1344ab987eabe2b671fdf1b26460caf1e51d822c Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Wed, 6 Mar 2024 16:52:42 +0100 Subject: [PATCH 08/30] Options for custom FhcApiFactory --- public/js/plugin/FhcApi.js | 4 +++- public/js/plugin/Phrasen.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/public/js/plugin/FhcApi.js b/public/js/plugin/FhcApi.js index bca19619e..ae8fdfdc1 100644 --- a/public/js/plugin/FhcApi.js +++ b/public/js/plugin/FhcApi.js @@ -286,7 +286,9 @@ export default { } } - app.config.globalProperties.$fhcApi.factory = new FhcApiFactoryWrapper(FhcApiFactory); + const mergedFhcApiFactory = options?.factory ? {...FhcApiFactory, ...options.factory} : FhcApiFactory; + + app.config.globalProperties.$fhcApi.factory = new FhcApiFactoryWrapper(mergedFhcApiFactory); } }; \ No newline at end of file diff --git a/public/js/plugin/Phrasen.js b/public/js/plugin/Phrasen.js index c0baf8629..0f3cb4ace 100644 --- a/public/js/plugin/Phrasen.js +++ b/public/js/plugin/Phrasen.js @@ -62,7 +62,7 @@ const phrasen = { export default { install(app, options) { - app.use(FhcApi); + app.use(FhcApi, options?.fhcApi || undefined); app.config.globalProperties.$p = { t: phrasen.t, loadCategory: cat => phrasen.loadCategory.call(app, cat), From b6723e92d8ce0ac07db38c9fe519254f18385f1a Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 08:01:11 +0100 Subject: [PATCH 09/30] Code Quality --- application/controllers/api/frontend/v1/Phrasen.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/application/controllers/api/frontend/v1/Phrasen.php b/application/controllers/api/frontend/v1/Phrasen.php index 6005b2c9c..6215c814b 100644 --- a/application/controllers/api/frontend/v1/Phrasen.php +++ b/application/controllers/api/frontend/v1/Phrasen.php @@ -9,7 +9,9 @@ class Phrasen extends FHCAPI_Controller { public function __construct() { - parent::__construct(['loadModule' => [self::PERM_ANONYMOUS]]); + parent::__construct([ + 'loadModule' => self::PERM_ANONYMOUS + ]); } //------------------------------------------------------------------------------------------------------------------ From 8f6fbda4cf89617c02d576b6da6161bddd748a59 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 08:11:58 +0100 Subject: [PATCH 10/30] Testsearch: Bugfixes --- application/views/system/logs/testSearch.php | 7 ++----- public/js/apps/TestSearch.js | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/application/views/system/logs/testSearch.php b/application/views/system/logs/testSearch.php index 882b953f5..34c2c3b54 100644 --- a/application/views/system/logs/testSearch.php +++ b/application/views/system/logs/testSearch.php @@ -1,13 +1,11 @@ 'Test Search', - 'jquery3' => true, 'bootstrap5' => true, 'fontawesome6' => true, - 'tablesorter2' => true, + 'tabulator5' => true, + 'axios027' => true, 'vue3' => true, - 'ajaxlib' => true, - 'jqueryui1' => true, 'filtercomponent' => true, 'navigationcomponent' => true, 'phrases' => array( @@ -18,7 +16,6 @@ 'public/css/components/verticalsplit.css', 'public/css/components/searchbar.css', ), - 'customJSs' => array('vendor/axios/axios/axios.min.js'), 'customJSModules' => array('public/js/apps/TestSearch.js') ); diff --git a/public/js/apps/TestSearch.js b/public/js/apps/TestSearch.js index d4aa35312..f4bd1f257 100644 --- a/public/js/apps/TestSearch.js +++ b/public/js/apps/TestSearch.js @@ -1,5 +1,5 @@ -import {CoreFilterCmpt} from '../components/Filter.js'; -import {CoreNavigationCmpt} from '../components/Navigation.js'; +import {CoreFilterCmpt} from '../components/filter/Filter.js'; +import {CoreNavigationCmpt} from '../components/navigation/Navigation.js'; import verticalsplit from "../components/verticalsplit/verticalsplit.js"; import searchbar from "../components/searchbar/searchbar.js"; import fhcapifactory from "./api/fhcapifactory.js"; From dad459e023ed9644bc1be1990e7e82ceb301442c Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 08:18:49 +0100 Subject: [PATCH 11/30] Testsearch: Codequality --- public/js/apps/TestSearch.js | 382 +++++++++++++++++------------------ 1 file changed, 190 insertions(+), 192 deletions(-) diff --git a/public/js/apps/TestSearch.js b/public/js/apps/TestSearch.js index f4bd1f257..f2696d008 100644 --- a/public/js/apps/TestSearch.js +++ b/public/js/apps/TestSearch.js @@ -1,195 +1,193 @@ import {CoreFilterCmpt} from '../components/filter/Filter.js'; import {CoreNavigationCmpt} from '../components/navigation/Navigation.js'; -import verticalsplit from "../components/verticalsplit/verticalsplit.js"; -import searchbar from "../components/searchbar/searchbar.js"; -import fhcapifactory from "./api/fhcapifactory.js"; +import CoreVerticalsplit from "../components/verticalsplit/verticalsplit.js"; +import CoreSearchbar from "../components/searchbar/searchbar.js"; -Vue.$fhcapi = fhcapifactory; - -Vue.createApp({ - "data": function() { - return { - "title": "Test Search", - "appSideMenuEntries": {}, - "searchbaroptions": { - "types": [ - "person", - "raum", - "mitarbeiter", - "student", - "prestudent", - "document", - "cms", - "organisationunit" - ], - "actions": { - "person": { - "defaultaction": { - "type": "link", - "action": function(data) { - //alert('person defaultaction ' + JSON.stringify(data)); - //window.location.href = data.profil; - return data.profil; - } - }, - "childactions": [ - { - "label": "testchildaction1", - "icon": "fas fa-check-circle", - "type": "function", - "action": function(data) { - alert('person testchildaction 01 ' + JSON.stringify(data)); - } - }, - { - "label": "testchildaction2", - "icon": "fas fa-file-csv", - "type": "function", - "action": function(data) { - alert('person testchildaction 02 ' + JSON.stringify(data)); - } - } - ] - }, - "raum": { - "defaultaction": { - "type": "function", - "action": function(data) { - alert('raum defaultaction ' + JSON.stringify(data)); - } - }, - "childactions": [ - { - "label": "Rauminformation", - "icon": "fas fa-info-circle", - "type": "link", - "action": function(data) { - return data.infolink; - } - }, - { - "label": "Raumreservierung", - "icon": "fas fa-bookmark", - "type": "link", - "action": function(data) { - return data.booklink; - } - } - ] - }, - "employee": { - "defaultaction": { - "type": "function", - "action": function(data) { - alert('employee defaultaction ' + JSON.stringify(data)); - } - }, - "childactions": [ - { - "label": "testchildaction1", - "icon": "fas fa-address-book", - "type": "function", - "action": function(data) { - alert('employee testchildaction 01 ' + JSON.stringify(data)); - } - }, - { - "label": "testchildaction2", - "icon": "fas fa-user-slash", - "type": "function", - "action": function(data) { - alert('employee testchildaction 02 ' + JSON.stringify(data)); - } - }, - { - "label": "testchildaction3", - "icon": "fas fa-bell", - "type": "function", - "action": function(data) { - alert('employee testchildaction 03 ' + JSON.stringify(data)); - } - }, - { - "label": "testchildaction4", - "icon": "fas fa-calculator", - "type": "function", - "action": function(data) { - alert('employee testchildaction 04 ' + JSON.stringify(data)); - } - } - ] - }, - "organisationunit": { - "defaultaction": { - "type": "function", - "action": function(data) { - alert('organisationunit defaultaction ' + JSON.stringify(data)); - } - }, - "childactions": [] - } - } - }, - "searchbaroptions2": { - "types": [ - "raum", - "organisationunit" - ], - "actions": { - "raum": { - "defaultaction": { - "type": "function", - "action": function(data) { - alert('raum defaultaction ' + JSON.stringify(data)); - } - }, - "childactions": [ - { - "label": "Rauminformation", - "icon": "fas fa-info-circle", - "type": "link", - "action": function(data) { - return data.infolink; - } - }, - { - "label": "Raumreservierung", - "icon": "fas fa-bookmark", - "type": "link", - "action": function(data) { - return data.booklink; - } - } - ] - }, - "organisationunit": { - "defaultaction": { - "type": "function", - "action": function(data) { - alert('organisationunit defaultaction ' + JSON.stringify(data)); - } - }, - "childactions": [] - } - } - } - }; - }, - "components": { - "CoreNavigationCmpt": CoreNavigationCmpt, - "CoreFilterCmpt": CoreFilterCmpt, - "verticalsplit": verticalsplit, - "searchbar": searchbar - }, - "methods": { - "newSideMenuEntryHandler": function(payload) { - this.appSideMenuEntries = payload; - }, - "searchfunction": function(searchsettings) { - return Vue.$fhcapi.Search.search(searchsettings); - }, - "searchfunctiondummy": function(searchsettings) { - return Vue.$fhcapi.Search.searchdummy(searchsettings); - } - } -}).mount('#main'); +const app = Vue.createApp({ + components: { + CoreNavigationCmpt, + CoreFilterCmpt, + CoreVerticalsplit, + CoreSearchbar + }, + data() { + return { + title: "Test Search", + appSideMenuEntries: {}, + searchbaroptions: { + types: [ + "person", + "raum", + "mitarbeiter", + "student", + "prestudent", + "document", + "cms", + "organisationunit" + ], + actions: { + person: { + defaultaction: { + type: "link", + action(data) { + //alert('person defaultaction ' + JSON.stringify(data)); + //window.location.href = data.profil; + return data.profil; + } + }, + childactions: [ + { + label: "testchildaction1", + icon: "fas fa-check-circle", + type: "function", + action(data) { + alert('person testchildaction 01 ' + JSON.stringify(data)); + } + }, + { + label: "testchildaction2", + icon: "fas fa-file-csv", + type: "function", + action(data) { + alert('person testchildaction 02 ' + JSON.stringify(data)); + } + } + ] + }, + raum: { + defaultaction: { + type: "function", + action(data) { + alert('raum defaultaction ' + JSON.stringify(data)); + } + }, + childactions: [ + { + label: "Rauminformation", + icon: "fas fa-info-circle", + type: "link", + action(data) { + return data.infolink; + } + }, + { + label: "Raumreservierung", + icon: "fas fa-bookmark", + type: "link", + action(data) { + return data.booklink; + } + } + ] + }, + employee: { + defaultaction: { + type: "function", + action(data) { + alert('employee defaultaction ' + JSON.stringify(data)); + } + }, + childactions: [ + { + label: "testchildaction1", + icon: "fas fa-address-book", + type: "function", + action(data) { + alert('employee testchildaction 01 ' + JSON.stringify(data)); + } + }, + { + label: "testchildaction2", + icon: "fas fa-user-slash", + type: "function", + action(data) { + alert('employee testchildaction 02 ' + JSON.stringify(data)); + } + }, + { + label: "testchildaction3", + icon: "fas fa-bell", + type: "function", + action(data) { + alert('employee testchildaction 03 ' + JSON.stringify(data)); + } + }, + { + label: "testchildaction4", + icon: "fas fa-calculator", + type: "function", + action(data) { + alert('employee testchildaction 04 ' + JSON.stringify(data)); + } + } + ] + }, + organisationunit: { + defaultaction: { + type: "function", + action(data) { + alert('organisationunit defaultaction ' + JSON.stringify(data)); + } + }, + childactions: [] + } + } + }, + searchbaroptions2: { + types: [ + "raum", + "organisationunit" + ], + actions: { + raum: { + defaultaction: { + type: "function", + action(data) { + alert('raum defaultaction ' + JSON.stringify(data)); + } + }, + childactions: [ + { + label: "Rauminformation", + icon: "fas fa-info-circle", + type: "link", + action(data) { + return data.infolink; + } + }, + { + label: "Raumreservierung", + icon: "fas fa-bookmark", + type: "link", + action(data) { + return data.booklink; + } + } + ] + }, + organisationunit: { + defaultaction: { + type: "function", + action(data) { + alert('organisationunit defaultaction ' + JSON.stringify(data)); + } + }, + childactions: [] + } + } + } + }; + }, + methods: { + newSideMenuEntryHandler(payload) { + this.appSideMenuEntries = payload; + }, + searchfunction(searchsettings) { + return Vue.$fhcapi.Search.search(searchsettings); + }, + searchfunctiondummy(searchsettings) { + return Vue.$fhcapi.Search.searchdummy(searchsettings); + } + } +}); +app.mount('#main'); From 4ac46d19e9f24f5c38bd1921ae6987ad45df6292 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 08:23:29 +0100 Subject: [PATCH 12/30] Testsearch view: naming convention --- application/views/system/logs/testSearch.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/views/system/logs/testSearch.php b/application/views/system/logs/testSearch.php index 34c2c3b54..6f33a11cb 100644 --- a/application/views/system/logs/testSearch.php +++ b/application/views/system/logs/testSearch.php @@ -37,17 +37,17 @@
- + - + - +
From 20619311e374335d79d49336918a083644ebc827 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 08:50:27 +0100 Subject: [PATCH 13/30] Use fhcApi in Searchbar --- .../controllers/api/frontend/v1/Searchbar.php | 51 +++++++++++++++++++ application/views/system/logs/testSearch.php | 2 + public/js/api/search.js | 18 +++---- public/js/apps/TestSearch.js | 6 ++- 4 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Searchbar.php diff --git a/application/controllers/api/frontend/v1/Searchbar.php b/application/controllers/api/frontend/v1/Searchbar.php new file mode 100644 index 000000000..526de927c --- /dev/null +++ b/application/controllers/api/frontend/v1/Searchbar.php @@ -0,0 +1,51 @@ + self::PERM_LOGGED + ]); + + // Load the library SearchBarLib + $this->load->library('SearchBarLib'); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Gets a JSON body via HTTP POST and provides the parameters + */ + public function search() + { + $this->load->library('form_validation'); + + // Checks if the searchstr and the types parameters are in the POSTed JSON + $this->form_validation->set_rules(self::SEARCHSTR_PARAM, null, 'required'); + $this->form_validation->set_rules(self::TYPES_PARAM . '[]', null, 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithError(SearchBarLib::ERROR_WRONG_JSON, self::ERROR_TYPE_GENERAL); + + // Convert to json the result from searchbarlib->search + $result = $this->searchbarlib->search($this->input->post(self::SEARCHSTR_PARAM), $this->input->post(self::TYPES_PARAM)); + if (property_exists($result, 'error')) + $this->terminateWithError(getError($result), self::ERROR_TYPE_GENERAL); + $this->terminateWithSuccess($result); + } +} + diff --git a/application/views/system/logs/testSearch.php b/application/views/system/logs/testSearch.php index 6f33a11cb..57ed0d48a 100644 --- a/application/views/system/logs/testSearch.php +++ b/application/views/system/logs/testSearch.php @@ -4,6 +4,7 @@ 'bootstrap5' => true, 'fontawesome6' => true, 'tabulator5' => true, + 'primevue3' => true, 'axios027' => true, 'vue3' => true, 'filtercomponent' => true, @@ -15,6 +16,7 @@ 'customCSSs' => array( 'public/css/components/verticalsplit.css', 'public/css/components/searchbar.css', + 'public/css/components/primevue.css', ), 'customJSModules' => array('public/js/apps/TestSearch.js') ); diff --git a/public/js/api/search.js b/public/js/api/search.js index 8544d9fe3..e75ad9832 100644 --- a/public/js/api/search.js +++ b/public/js/api/search.js @@ -1,12 +1,10 @@ export default { - search: function(searchsettings) { - const url = FHC_JS_DATA_STORAGE_OBJECT.app_root - + 'index.ci.php/components/SearchBar/search'; - return axios.post(url, searchsettings); - }, - searchdummy: function(searchsettings) { - const url = FHC_JS_DATA_STORAGE_OBJECT.app_root - + 'public/js/apps/api/dummyapi.php/Search'; - return axios.post(url, searchsettings); - } + search(searchsettings) { + const url = '/api/frontend/v1/searchbar/search'; + return this.$fhcApi.post(url, searchsettings); + }, + searchdummy(searchsettings) { + const url = 'public/js/apps/api/dummyapi.php/Search'; + return this.$fhcApi.post(url, searchsettings); + } }; \ No newline at end of file diff --git a/public/js/apps/TestSearch.js b/public/js/apps/TestSearch.js index f2696d008..469aaeb09 100644 --- a/public/js/apps/TestSearch.js +++ b/public/js/apps/TestSearch.js @@ -2,6 +2,7 @@ import {CoreFilterCmpt} from '../components/filter/Filter.js'; import {CoreNavigationCmpt} from '../components/navigation/Navigation.js'; import CoreVerticalsplit from "../components/verticalsplit/verticalsplit.js"; import CoreSearchbar from "../components/searchbar/searchbar.js"; +import FhcApi from "../plugin/FhcApi.js"; const app = Vue.createApp({ components: { @@ -183,11 +184,12 @@ const app = Vue.createApp({ this.appSideMenuEntries = payload; }, searchfunction(searchsettings) { - return Vue.$fhcapi.Search.search(searchsettings); + return this.$fhcApi.factory.search.search(searchsettings); }, searchfunctiondummy(searchsettings) { - return Vue.$fhcapi.Search.searchdummy(searchsettings); + return this.$fhcApi.factory.search.searchdummy(searchsettings); } } }); +app.use(FhcApi) app.mount('#main'); From f539ed89774691050a5519e61905e25855572b2d Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 08:54:28 +0100 Subject: [PATCH 14/30] Depricated comment --- application/controllers/components/SearchBar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/components/SearchBar.php b/application/controllers/components/SearchBar.php index d19113177..5af3c4ee0 100644 --- a/application/controllers/components/SearchBar.php +++ b/application/controllers/components/SearchBar.php @@ -3,7 +3,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** - * + * TODO(chris): depricated */ class SearchBar extends FHC_Controller { From 291f32bfe22c03de57ded6d9b8a85a971e4deb8d Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 14:35:29 +0100 Subject: [PATCH 15/30] Tabs => FhcApi --- public/js/components/Tabs.js | 50 +++++++++++++++++------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/public/js/components/Tabs.js b/public/js/components/Tabs.js index 8090a9d29..49d3fabf7 100644 --- a/public/js/components/Tabs.js +++ b/public/js/components/Tabs.js @@ -1,4 +1,3 @@ -import {CoreRESTClient} from '../RESTClient.js'; import accessibility from "../directives/accessibility.js"; export default { @@ -12,7 +11,7 @@ export default { ], props: { config: { - type: [String, Object], + type: [String, Array, Object, Promise], required: true }, default: String, @@ -56,40 +55,37 @@ export default { initConfig(config) { if (!config) return; + if (config instanceof Promise) + return config + .then(result => result.data) + .then(this.initConfig) + .catch(this.$fhcAlert.handleSystemError); if (typeof config === 'string' || config instanceof String) - return CoreRESTClient.get(config) - .then(result => CoreRESTClient.getData(result.data)) + return this.$fhcApi + .get(config) + .then(result => result.data) .then(this.initConfig) .catch(this.$fhcAlert.handleSystemError); const tabs = {}; - if (Array.isArray(config)) { - config.forEach((item, key) => { - if (!item.component) - return console.error('Component missing for ' + key); + function _addToTabs(key, item) { + if (!item.component) + return console.error('Component missing for ' + key); - tabs[key] = { - component: Vue.markRaw(Vue.defineAsyncComponent(() => import(item.component))), - title: item.title || key, - config: item.config, - key - } - }); - } else { - Object.entries(config).forEach(([key, item]) => { - if (!item.component) - return console.error('Component missing for ' + key); - - tabs[key] = { - component: Vue.markRaw(Vue.defineAsyncComponent(() => import(item.component))), - title: item.title || key, - config: item.config, - key - } - }); + tabs[key] = { + component: Vue.markRaw(Vue.defineAsyncComponent(() => import(item.component))), + title: item.title || key, + config: item.config, + key + } } + if (Array.isArray(config)) + config.forEach((item, key) => _addToTabs(key, item)); + else + Object.entries(config).forEach(([key, item]) => _addToTabs(key, item)); + if (this.current === null || !tabs[this.current]) { if (tabs[this.default]) this.current = this.default; From d2eadb98ce10e41979672c55dd04b3e145a58521 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 16:56:14 +0100 Subject: [PATCH 16/30] Navigation => FhcApi --- .../api/frontend/v1/Navigation.php | 101 ++++++++++++++++++ application/controllers/system/Navigation.php | 1 + public/js/api/fhcapifactory.js | 21 +++- public/js/api/navigation.js | 32 ++++++ public/js/components/navigation/API.js | 2 +- public/js/components/navigation/Navigation.js | 48 ++++----- 6 files changed, 179 insertions(+), 26 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Navigation.php create mode 100644 public/js/api/navigation.js diff --git a/application/controllers/api/frontend/v1/Navigation.php b/application/controllers/api/frontend/v1/Navigation.php new file mode 100644 index 000000000..6cbbbd385 --- /dev/null +++ b/application/controllers/api/frontend/v1/Navigation.php @@ -0,0 +1,101 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller operates between (interface) the JS (GUI) and the NavigationLib (back-end) + * Provides data to the ajax get calls about the filter + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + */ +class Navigation extends FHCAPI_Controller +{ + const NAVIGATION_PAGE_PARAM = 'navigation_page'; // Navigation page parameter name + + /** + * Loads the NavigationLib where the used logic lies + */ + public function __construct() + { + parent::__construct([ + 'menu' => self::PERM_LOGGED, + 'header' => self::PERM_LOGGED + ]); + + $this->_loadNavigationLib(); // Loads the NavigationLib with parameters + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * This function creates the left Menu for each Page + * @param NAVIGATION_PAGE_PARAM GET Parameter witch holds the currently called Page + * @return JSON object with the Menu Entries + */ + public function menu() + { + $menuArray = $this->navigationlib->getMenuArray($this->input->get(self::NAVIGATION_PAGE_PARAM)); + + $this->terminateWithSuccess($menuArray); + } + + /** + * This function creates the Top Menu for each Page + * @param NAVIGATION_PAGE_PARAM GET Parameter witch holds the currently called Page + * @return JSON object with the Menu Entries + */ + public function header() + { + $headerArray = $this->navigationlib->getHeaderArray($this->input->get(self::NAVIGATION_PAGE_PARAM)); + + $this->terminateWithSuccess($headerArray); + } + + //------------------------------------------------------------------------------------------------------------------ + // Private methods + + /** + * Loads the NavigationLib with the NAVIGATION_PAGE_PARAM parameter + * If the parameter NAVIGATION_PAGE_PARAM is not given then the execution of the controller is terminated and + * an error message is printed + */ + private function _loadNavigationLib() + { + // If the parameter NAVIGATION_PAGE_PARAM is present in the HTTP GET or POST + if (isset($_GET[self::NAVIGATION_PAGE_PARAM]) || isset($_POST[self::NAVIGATION_PAGE_PARAM])) + { + // If it is present in the HTTP GET + if (isset($_GET[self::NAVIGATION_PAGE_PARAM])) + { + $navigationPage = $this->input->get(self::NAVIGATION_PAGE_PARAM); // is retrieved from the HTTP GET + } + elseif (isset($_POST[self::NAVIGATION_PAGE_PARAM])) // Else if it is present in the HTTP POST + { + $navigationPage = $this->input->post(self::NAVIGATION_PAGE_PARAM); // is retrieved from the HTTP POST + } + + // Loads the NavigationLib that contains all the used logic + $this->load->library('NavigationLib', array(self::NAVIGATION_PAGE_PARAM => $navigationPage)); + } + else // Otherwise an error will be written in the output + { + show_error('Parameter "' . self::NAVIGATION_PAGE_PARAM . '" not provided!'); + } + } +} diff --git a/application/controllers/system/Navigation.php b/application/controllers/system/Navigation.php index c3764b612..71ab1c81b 100644 --- a/application/controllers/system/Navigation.php +++ b/application/controllers/system/Navigation.php @@ -22,6 +22,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); * This controller operates between (interface) the JS (GUI) and the NavigationLib (back-end) * Provides data to the ajax get calls about the filter * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + * TODO(chris): deprecated */ class Navigation extends FHC_Controller { diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js index e0ea89211..2d3308e9f 100644 --- a/public/js/api/fhcapifactory.js +++ b/public/js/api/fhcapifactory.js @@ -1,7 +1,26 @@ +/** + * 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 . + */ + import search from "./search.js"; import phrasen from "./phrasen.js"; +import navigation from "./navigation.js"; export default { search, - phrasen + phrasen, + navigation }; diff --git a/public/js/api/navigation.js b/public/js/api/navigation.js new file mode 100644 index 000000000..05006331f --- /dev/null +++ b/public/js/api/navigation.js @@ -0,0 +1,32 @@ +/** + * 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 . + */ + +export default { + getHeader(navigation_page) { + return this.$fhcApi.get( + '/api/frontend/v1/navigation/header', + { navigation_page } + ); + }, + getMenu: function(navigation_page) { + return this.$fhcApi.get( + '/api/frontend/v1/navigation/menu', + { navigation_page } + ); + } +}; + diff --git a/public/js/components/navigation/API.js b/public/js/components/navigation/API.js index 3e862a02c..8e2c66a7c 100644 --- a/public/js/components/navigation/API.js +++ b/public/js/components/navigation/API.js @@ -21,7 +21,7 @@ import {CoreRESTClient} from '../../RESTClient.js'; const CORE_NAVIGATION_CMPT_TIMEOUT = 5000; /** - * + * TODO(chris): deprecated */ export const CoreNavigationAPIs = { /** diff --git a/public/js/components/navigation/Navigation.js b/public/js/components/navigation/Navigation.js index 3b32fd38c..6bcd9baf5 100644 --- a/public/js/components/navigation/Navigation.js +++ b/public/js/components/navigation/Navigation.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 @@ -15,8 +15,6 @@ * along with this program. If not, see . */ -import {CoreNavigationAPIs} from './API.js'; -import {CoreRESTClient} from '../../RESTClient.js'; import {CoreFetchCmpt} from '../../components/Fetch.js'; /** @@ -30,12 +28,12 @@ export const CoreNavigationCmpt = { addHeaderMenuEntries: Object, // property used to add new header menu entries from another app/component addSideMenuEntries: Object, // property used to add new side menu entries from another app/component hideTopMenu: Boolean, - leftNavCssClasses: { - type: String, - default: 'navbar navbar-left-side' - } + leftNavCssClasses: { + type: String, + default: 'navbar navbar-left-side' + } }, - data: function() { + data() { return { headerMenu: {}, // header menu entries sideMenu: {} // side menu entries @@ -45,61 +43,63 @@ export const CoreNavigationCmpt = { /** * */ - headerMenuEntries: function() { + headerMenuEntries() { // + let hm = this.headerMenu ? {...this.headerMenu} : {}; if (this.headerMenu != null && this.addHeaderMenuEntries != null && Object.keys(this.addHeaderMenuEntries).length > 0) { - this.headerMenu[this.addHeaderMenuEntries.description] = this.addHeaderMenuEntries; + hm[this.addHeaderMenuEntries.description] = this.addHeaderMenuEntries; } - return this.headerMenu; + return hm; }, /** * */ - sideMenuEntries: function() { + sideMenuEntries() { // + let sm = this.sideMenu ? {...this.sideMenu} : {}; if (this.sideMenu != null && this.addSideMenuEntries != null && Object.keys(this.addSideMenuEntries).length > 0) { - this.sideMenu[this.addSideMenuEntries.description] = this.addSideMenuEntries; + sm[this.addSideMenuEntries.description] = this.addSideMenuEntries; } - return this.sideMenu; + return sm; } }, methods: { /** * */ - getNavigationPage: function() { + getNavigationPage() { return FHC_JS_DATA_STORAGE_OBJECT.called_path + "/" + FHC_JS_DATA_STORAGE_OBJECT.called_method; }, /** * */ - fetchCmptApiFunctionHeader: function() { - return CoreNavigationAPIs.getHeader(this.getNavigationPage()); + fetchCmptApiFunctionHeader() { + return this.$fhcApi.factory.navigation.getHeader(this.getNavigationPage()); }, /** * */ - fetchCmptApiFunctionSideMenu: function() { - return CoreNavigationAPIs.getMenu(this.getNavigationPage()); + fetchCmptApiFunctionSideMenu() { + return this.$fhcApi.factory.navigation.getMenu(this.getNavigationPage()); }, /** * */ - fetchCmptDataFetchedHeader: function(data) { - if (CoreRESTClient.hasData(data)) this.headerMenu = CoreRESTClient.getData(data); + fetchCmptDataFetchedHeader(data) { + this.headerMenu = data || {}; }, /** * */ - fetchCmptDataFetchedMenu: function(data) { - if (CoreRESTClient.hasData(data)) this.sideMenu = CoreRESTClient.getData(data); + fetchCmptDataFetchedMenu(data) { + this.sideMenu = data || {}; }, /** * */ - getDataBsToggle: function(header) { + getDataBsToggle(header) { return !header.children ? null : 'dropdown'; } }, From 5f77bdd6fcfea7038ee78245f0a54cee75e89831 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 16:56:30 +0100 Subject: [PATCH 17/30] Spelling --- application/controllers/components/Phrasen.php | 2 +- application/controllers/components/SearchBar.php | 2 +- public/js/plugin/Phrasen.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/application/controllers/components/Phrasen.php b/application/controllers/components/Phrasen.php index abcb051e9..3ac35a652 100644 --- a/application/controllers/components/Phrasen.php +++ b/application/controllers/components/Phrasen.php @@ -3,7 +3,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** - * TODO(chris): depricated + * TODO(chris): deprecated */ class Phrasen extends FHC_Controller { diff --git a/application/controllers/components/SearchBar.php b/application/controllers/components/SearchBar.php index 5af3c4ee0..0ff299817 100644 --- a/application/controllers/components/SearchBar.php +++ b/application/controllers/components/SearchBar.php @@ -3,7 +3,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** - * TODO(chris): depricated + * TODO(chris): deprecated */ class SearchBar extends FHC_Controller { diff --git a/public/js/plugin/Phrasen.js b/public/js/plugin/Phrasen.js index 0f3cb4ace..ab4da95db 100644 --- a/public/js/plugin/Phrasen.js +++ b/public/js/plugin/Phrasen.js @@ -34,7 +34,7 @@ const phrasen = { return loadingModules[category]; }, t_ref(category, phrase, params) { - console.warn('depricated'); + console.warn('deprecated'); return Vue.computed(() => this.t(category, phrase, params)); }, t(category, phrase, params) { From 85f9b1432681c01d8b937e5fe72fff1a293bb87b Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 7 Mar 2024 16:56:37 +0100 Subject: [PATCH 18/30] Comments --- public/js/api/phrasen.js | 17 +++++++++++++++++ public/js/api/search.js | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/public/js/api/phrasen.js b/public/js/api/phrasen.js index 5f1fff3e4..896641bcf 100644 --- a/public/js/api/phrasen.js +++ b/public/js/api/phrasen.js @@ -1,3 +1,20 @@ +/** + * 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 . + */ + export default { loadCategory(category) { return this.$fhcApi.get('/api/frontend/v1/phrasen/loadModule/' + category); diff --git a/public/js/api/search.js b/public/js/api/search.js index e75ad9832..4655d8fa8 100644 --- a/public/js/api/search.js +++ b/public/js/api/search.js @@ -1,3 +1,20 @@ +/** + * 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 . + */ + export default { search(searchsettings) { const url = '/api/frontend/v1/searchbar/search'; From 011b4a83eb1474b4eb619f94560f0b49fca07f2e Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Mon, 11 Mar 2024 09:46:39 +0100 Subject: [PATCH 19/30] Filter => FhcApi --- .../controllers/api/frontend/v1/Filter.php | 231 ++++++++++++++++++ application/controllers/components/Filter.php | 1 + public/js/api/fhcapifactory.js | 4 +- public/js/api/filter.js | 89 +++++++ public/js/components/filter/API.js | 2 +- public/js/components/filter/Filter.js | 84 +++---- 6 files changed, 362 insertions(+), 49 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Filter.php create mode 100644 public/js/api/filter.js diff --git a/application/controllers/api/frontend/v1/Filter.php b/application/controllers/api/frontend/v1/Filter.php new file mode 100644 index 000000000..45838fc5f --- /dev/null +++ b/application/controllers/api/frontend/v1/Filter.php @@ -0,0 +1,231 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +/** + * This controller operates between (interface) the JS (GUI) and the FilterCmptLib (back-end) + * Provides data to the ajax get calls about the filter component + * Listens to ajax post calls to change the filter data + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + */ +class Filter extends FHCAPI_Controller +{ + const FILTER_UNIQUE_ID = 'filterUniqueId'; // Name of the filter cmpt unique id (mandatory) + const FILTER_TYPE = 'filterType'; // The filter type (PHP filter definition) used (mandatory) + const FILTER_ID = 'filterId'; // The id of the used filter (optional) + + /** + * Calls the parent's constructor and loads the FilterCmptLib + */ + public function __construct() + { + // NOTE: FilterCmpt has its own permissions checks + parent::__construct([ + 'getFilter' => self::PERM_LOGGED, + 'removeFilterField' => self::PERM_LOGGED, + 'addFilterField' => self::PERM_LOGGED, + 'applyFilterFields' => self::PERM_LOGGED, + 'removeCustomFilter' => self::PERM_LOGGED, + 'saveCustomFilter' => self::PERM_LOGGED, + 'reloadDataset' => self::PERM_LOGGED + ]); + + // Loads the FiltersModel + $this->load->model('system/Filters_model', 'FiltersModel'); + + // Loads the FilterCmptLib with HTTP GET/POST parameters + $this->_startFilterCmptLib(); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Retrieves data about the current filter from the session and will be written on the output in JSON format + */ + public function getFilter() + { + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $session = $this->filtercmptlib->getSession(); + if (is_object($session)) { + // If stdClass it is an retval object + $session = $this->getDataOrTerminateWithError($session); + } + $this->terminateWithSuccess($session); + } + + /** + * Remove an applied filter (SQL where condition) from the current filter + */ + public function removeFilterField() + { + $this->form_validation->set_rules('filterField', 'filterField', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $result = $this->filtercmptlib->removeFilterField($this->input->post('filterField')); + + if (!$result) + $this->terminateWithError('Error occurred', self::ERROR_TYPE_GENERAL); + + $this->terminateWithSuccess('Field removed'); + } + + /** + * Add a filter (SQL where clause) to be applied to the current filter + */ + public function addFilterField() + { + $this->form_validation->set_rules('filterField', 'filterField', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $result = $this->filtercmptlib->addFilterField($this->input->post('filterField')); + + if (!$result) + $this->terminateWithError('Error occurred', self::ERROR_TYPE_GENERAL); + + $this->terminateWithSuccess('Field added'); + } + + /** + * Apply the filter changes + */ + public function applyFilterFields() + { + $this->form_validation->set_rules('filterFields', 'filterFields', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $result = $this->filtercmptlib->applyFilterFields($this->input->post('filterFields')); + + if (!$result) + $this->terminateWithError('Error occurred', self::ERROR_TYPE_GENERAL); + + $this->terminateWithSuccess('Applied'); + } + + /** + * Save the current filter as a custom filter for this user with the given description + */ + public function saveCustomFilter() + { + $this->form_validation->set_rules('customFilterName', 'customFilterName', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $result = $this->filtercmptlib->saveCustomFilter($this->input->post('customFilterName')); + + if (!$result) + $this->terminateWithError('Error occurred', self::ERROR_TYPE_GENERAL); + + $this->terminateWithSuccess('Saved'); + } + + /** + * Remove a custom filter by its filterId + */ + public function removeCustomFilter() + { + $this->form_validation->set_rules('filterId', 'filterId', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $result = $this->filtercmptlib->removeCustomFilter($this->input->post('filterId')); + + if (!$result) + $this->terminateWithError('Error occurred', self::ERROR_TYPE_GENERAL); + + $this->terminateWithSuccess('Removed'); + } + + /** + * Reloads the dataset + */ + public function reloadDataset() + { + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $this->filtercmptlib->reloadDataset(); + + $this->terminateWithSuccess('Success'); + } + + //------------------------------------------------------------------------------------------------------------------ + // Private methods + + /** + * Loads the FilterCmptLib with the FILTER_UNIQUE_ID parameter + * If the parameter FILTER_UNIQUE_ID is not given then the execution of the controller is terminated and + * an error message is printed + */ + private function _startFilterCmptLib() + { + $filterUniqueId = null; + $filterType = null; + $filterId = null; + + $validations = [ + [ + 'field' => self::FILTER_UNIQUE_ID, + 'label' => self::FILTER_UNIQUE_ID, + 'rules' => 'required' + ], + [ + 'field' => self::FILTER_TYPE, + 'label' => self::FILTER_TYPE, + 'rules' => 'required' + ], + ]; + + $this->load->library('form_validation'); + + if ($this->input->method() == 'get') + $this->form_validation->set_data($this->input->get()); + $this->form_validation->set_rules($validations); + + if ($this->form_validation->run()) { + $filterUniqueId = $this->input->post_get(self::FILTER_UNIQUE_ID); + $filterType = $this->input->post_get(self::FILTER_TYPE); + $filterId = $this->input->post_get(self::FILTER_ID); + + // Loads the FilterCmptLib that contains all the used logic + $this->load->library( + 'FilterCmptLib', + array( + 'filterUniqueId' => $filterUniqueId, + 'filterType' => $filterType, + 'filterId' => $filterId + ) + ); + + // Start the component + $this->filtercmptlib->start(); + } + } +} + diff --git a/application/controllers/components/Filter.php b/application/controllers/components/Filter.php index bde7d7ed7..617edd69f 100644 --- a/application/controllers/components/Filter.php +++ b/application/controllers/components/Filter.php @@ -9,6 +9,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON * NOTE: extends the FHC_Controller instead of the Auth_Controller because the FilterCmpt has its * own permissions check + * TODO(chris): deprecated */ class Filter extends FHC_Controller { diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js index 2d3308e9f..08deb26b3 100644 --- a/public/js/api/fhcapifactory.js +++ b/public/js/api/fhcapifactory.js @@ -18,9 +18,11 @@ import search from "./search.js"; import phrasen from "./phrasen.js"; import navigation from "./navigation.js"; +import filter from "./filter.js"; export default { search, phrasen, - navigation + navigation, + filter }; diff --git a/public/js/api/filter.js b/public/js/api/filter.js new file mode 100644 index 000000000..a5920c758 --- /dev/null +++ b/public/js/api/filter.js @@ -0,0 +1,89 @@ +/** + * 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 . + */ + +export default { + saveCustomFilter(wsParams) { + return this.$fhcApi.post( + '/api/frontend/v1/filter/saveCustomFilter', + { + filterUniqueId: wsParams.filterUniqueId, + filterType: wsParams.filterType, + customFilterName: wsParams.customFilterName + } + ); + }, + removeCustomFilter(wsParams) { + return this.$fhcApi.post( + '/api/frontend/v1/filter/removeCustomFilter', + { + filterUniqueId: wsParams.filterUniqueId, + filterType: wsParams.filterType, + filterId: wsParams.filterId + } + ); + }, + applyFilterFields(wsParams) { + return this.$fhcApi.post( + '/api/frontend/v1/filter/applyFilterFields', + { + filterUniqueId: wsParams.filterUniqueId, + filterType: wsParams.filterType, + filterFields: wsParams.filterFields + } + ); + }, + addFilterField(wsParams) { + return this.$fhcApi.post( + '/api/frontend/v1/filter/addFilterField', + { + filterUniqueId: wsParams.filterUniqueId, + filterType: wsParams.filterType, + filterField: wsParams.filterField + } + ); + }, + removeFilterField(wsParams) { + return this.$fhcApi.post( + '/api/frontend/v1/filter/removeFilterField', + { + filterUniqueId: wsParams.filterUniqueId, + filterType: wsParams.filterType, + filterField: wsParams.filterField + } + ); + }, + getFilterById(wsParams) { + return this.$fhcApi.get( + '/api/frontend/v1/filter/getFilter', + { + filterUniqueId: wsParams.filterUniqueId, + filterType: wsParams.filterType, + filterId: wsParams.filterId + } + ); + }, + getFilter(wsParams) { + return this.$fhcApi.get( + '/api/frontend/v1/filter/getFilter', + { + filterUniqueId: wsParams.filterUniqueId, + filterType: wsParams.filterType + } + ); + } +}; + diff --git a/public/js/components/filter/API.js b/public/js/components/filter/API.js index ff09c452d..58afc5bb3 100644 --- a/public/js/components/filter/API.js +++ b/public/js/components/filter/API.js @@ -21,7 +21,7 @@ import {CoreRESTClient} from '../../RESTClient.js'; const CORE_FILTER_CMPT_TIMEOUT = 7000; /** - * + * TODO(chris): deprecated */ export const CoreFilterAPIs = { /** diff --git a/public/js/components/filter/Filter.js b/public/js/components/filter/Filter.js index 64a75c910..6420c0dcf 100644 --- a/public/js/components/filter/Filter.js +++ b/public/js/components/filter/Filter.js @@ -15,8 +15,6 @@ * along with this program. If not, see . */ -import {CoreFilterAPIs} from './API.js'; -import {CoreRESTClient} from '../../RESTClient.js'; import {CoreFetchCmpt} from '../../components/Fetch.js'; import FilterConfig from './Filter/Config.js'; import FilterColumns from './Filter/Columns.js'; @@ -252,12 +250,12 @@ export const CoreFilterCmpt = { /** * */ - getFilter: function() { + getFilter() { if (this.selectedFilter === null) - this.startFetchCmpt(CoreFilterAPIs.getFilter, null, this.render); + this.startFetchCmpt(this.$fhcApi.factory.filter.getFilter, null, this.render); else this.startFetchCmpt( - CoreFilterAPIs.getFilterById, + this.$fhcApi.factory.filter.getFilterById, { filterId: this.selectedFilter }, @@ -267,55 +265,47 @@ export const CoreFilterCmpt = { /** * */ - render: function(response) { + render(response) { + let data = response; + this.filterName = data.filterName; + this.dataset = data.dataset; + this.datasetMetadata = data.datasetMetadata; - if (CoreRESTClient.hasData(response)) + this.fields = data.fields; + this.selectedFields = data.selectedFields; + this.notSelectedFields = this.fields.filter(x => this.selectedFields.indexOf(x) === -1); + this.filterFields = []; + + for (let i = 0; i < data.datasetMetadata.length; i++) { - let data = CoreRESTClient.getData(response); - this.filterName = data.filterName; - this.dataset = data.dataset; - this.datasetMetadata = data.datasetMetadata; - - this.fields = data.fields; - this.selectedFields = data.selectedFields; - this.notSelectedFields = this.fields.filter(x => this.selectedFields.indexOf(x) === -1); - this.filterFields = []; - - for (let i = 0; i < data.datasetMetadata.length; i++) + for (let j = 0; j < data.filters.length; j++) { - for (let j = 0; j < data.filters.length; j++) + if (data.datasetMetadata[i].name == data.filters[j].name) { - if (data.datasetMetadata[i].name == data.filters[j].name) - { - let filter = data.filters[j]; - filter.type = data.datasetMetadata[i].type; + let filter = data.filters[j]; + filter.type = data.datasetMetadata[i].type; - this.filterFields.push(filter); - //break; - } + this.filterFields.push(filter); + //break; } } + } - // If the side menu is active - if (this.sideMenu === true) - { - this.setSideMenu(data); - } - else // otherwise use the dropdown in the filter options - { - this.setDropDownMenu(data); - } - this.updateTabulator(); - } - else + // If the side menu is active + if (this.sideMenu === true) { - console.error(CoreRESTClient.getError(response)); + this.setSideMenu(data); } + else // otherwise use the dropdown in the filter options + { + this.setDropDownMenu(data); + } + this.updateTabulator(); }, /** * Set the menu */ - setSideMenu: function(data) { + setSideMenu(data) { let filters = data.sideMenu.filters; let personalFilters = data.sideMenu.personalFilters; let filtersArray = []; @@ -369,7 +359,7 @@ export const CoreFilterCmpt = { /** * Set the drop down menu */ - setDropDownMenu: function(data) { + setDropDownMenu(data) { let filters = data.sideMenu.filters; let personalFilters = data.sideMenu.personalFilters; let filtersArray = []; @@ -405,7 +395,7 @@ export const CoreFilterCmpt = { /** * Used to start/refresh the FetchCmpt */ - startFetchCmpt: function(apiFunction, apiFunctionParameters, dataFetchedCallback) { + startFetchCmpt(apiFunction, apiFunctionParameters, dataFetchedCallback) { // Assign the function api of the FetchCmpt binded property this.fetchCmptApiFunction = apiFunction; @@ -431,11 +421,11 @@ export const CoreFilterCmpt = { /** * */ - handlerSaveCustomFilter: function(customFilterName) { + handlerSaveCustomFilter(customFilterName) { this.selectedFilter = null; // this.startFetchCmpt( - CoreFilterAPIs.saveCustomFilter, + this.$fhcApi.factory.filter.saveCustomFilter, { customFilterName }, @@ -445,13 +435,13 @@ export const CoreFilterCmpt = { /** * */ - handlerRemoveCustomFilter: function(event) { + handlerRemoveCustomFilter(event) { let filterId = event.currentTarget.getAttribute("href").substring(1); if (filterId === this.selectedFilter) this.selectedFilter = null; // this.startFetchCmpt( - CoreFilterAPIs.removeCustomFilter, + this.$fhcApi.factory.filter.removeCustomFilter, { filterId: filterId }, @@ -488,7 +478,7 @@ export const CoreFilterCmpt = { applyFilterConfig(filterFields) { this.selectedFilter = null; this.startFetchCmpt( - CoreFilterAPIs.applyFilterFields, + this.$fhcApi.factory.filter.applyFilterFields, { filterFields }, From d259c0d35c3dd23ed9cdf2b82f707534c5768de9 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Mon, 11 Mar 2024 09:46:59 +0100 Subject: [PATCH 20/30] Fetch: more robust error handling --- public/js/components/Fetch.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/js/components/Fetch.js b/public/js/components/Fetch.js index 9a34e1a3f..2f7985649 100644 --- a/public/js/components/Fetch.js +++ b/public/js/components/Fetch.js @@ -99,8 +99,10 @@ export const CoreFetchCmpt = { * */ errorHandler: function(error) { - if (error.response.data.retval) + if (error.response?.data?.retval) this.setError(error.response.data.retval); + else if (error.data?.message) + this.setError(error.data.message); else this.setError(error.message); }, From b359a77a8d0f0e99575dcec0e45f075f03155127 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Mon, 11 Mar 2024 09:56:34 +0100 Subject: [PATCH 21/30] Comments --- .../controllers/api/frontend/v1/Phrasen.php | 20 ++++++++++++++++++- .../controllers/api/frontend/v1/Searchbar.php | 20 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/application/controllers/api/frontend/v1/Phrasen.php b/application/controllers/api/frontend/v1/Phrasen.php index 6215c814b..472308d2b 100644 --- a/application/controllers/api/frontend/v1/Phrasen.php +++ b/application/controllers/api/frontend/v1/Phrasen.php @@ -1,9 +1,27 @@ . + */ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** - * + * This controller operates between (interface) the JS (GUI) and the PhrasesLib (back-end) + * Provides data to the ajax get calls about the Phrasen plugin + * This controller works with JSON calls on the HTTP GET and the output is always JSON */ class Phrasen extends FHCAPI_Controller { diff --git a/application/controllers/api/frontend/v1/Searchbar.php b/application/controllers/api/frontend/v1/Searchbar.php index 526de927c..8b383e042 100644 --- a/application/controllers/api/frontend/v1/Searchbar.php +++ b/application/controllers/api/frontend/v1/Searchbar.php @@ -1,9 +1,27 @@ . + */ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** - * + * This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end) + * Provides data to the ajax get calls about the searchbar component + * This controller works with JSON calls on the HTTP GET and the output is always JSON */ class Searchbar extends FHCAPI_Controller { From 40c98b1dcc75cc905e9f5f4937193f75eaf72818 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Mon, 11 Mar 2024 15:23:54 +0100 Subject: [PATCH 22/30] FHCAPI Controller: optional status param for error function --- application/core/FHCAPI_Controller.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/core/FHCAPI_Controller.php b/application/core/FHCAPI_Controller.php index ebb2f7978..647032795 100644 --- a/application/core/FHCAPI_Controller.php +++ b/application/core/FHCAPI_Controller.php @@ -181,11 +181,12 @@ class FHCAPI_Controller extends Auth_Controller /** * @param array $error * @param string $type (optional) + * @param integer $status (optional) * @return void */ - protected function terminateWithError($error, $type = null) + protected function terminateWithError($error, $type = null, $status = REST_Controller::HTTP_INTERNAL_SERVER_ERROR) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + $this->output->set_status_header($status); $this->addError($error, $type); $this->setStatus(self::STATUS_ERROR); exit; From 6acf65b49ff11cbab2b891b02b53eb724efec442 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Mon, 11 Mar 2024 15:24:48 +0100 Subject: [PATCH 23/30] Form Component: expose _defaultErrorHandlers --- public/js/components/Form/Form.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/js/components/Form/Form.js b/public/js/components/Form/Form.js index 9a729b88f..fb264e0fe 100644 --- a/public/js/components/Form/Form.js +++ b/public/js/components/Form/Form.js @@ -46,7 +46,8 @@ export default { const factory = Object.create(Object.getPrototypeOf(this.$fhcApi.factory), Object.getOwnPropertyDescriptors(this.$fhcApi.factory)); factory.$fhcApi = { get: this.get, - post: this.post + post: this.post, + _defaultErrorHandlers: this.$fhcApi._defaultErrorHandlers }; return factory; } From 8f0e837fb727d44719310b0225b7590ed8957d4f Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Tue, 19 Mar 2024 08:45:10 +0100 Subject: [PATCH 24/30] Phrasen Plugin: Bugfix this --- public/js/plugin/Phrasen.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/js/plugin/Phrasen.js b/public/js/plugin/Phrasen.js index ab4da95db..0206e6f57 100644 --- a/public/js/plugin/Phrasen.js +++ b/public/js/plugin/Phrasen.js @@ -23,7 +23,8 @@ function getValueForLoadedPhrase(category, phrase, params) { const phrasen = { loadCategory(category) { if (Array.isArray(category)) - return Promise.all(category.map(cat => this.loadCategory(cat))); + return Promise.all(category.map(cat => this.config.globalProperties + .$fhcApi.factory.phrasen.loadCategory(cat))); if (!loadingModules[category]) loadingModules[category] = this.config.globalProperties .$fhcApi.factory.phrasen.loadCategory(category) From 30efd55d6c618724fcbf382c54a9812096a6ff91 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Tue, 19 Mar 2024 16:53:36 +0100 Subject: [PATCH 25/30] FhcApi: settle handled Promises & discard them in FhcAlert --- public/js/plugin/FhcAlert.js | 4 ++++ public/js/plugin/FhcApi.js | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/public/js/plugin/FhcAlert.js b/public/js/plugin/FhcAlert.js index eca2e6944..eb6516820 100644 --- a/public/js/plugin/FhcAlert.js +++ b/public/js/plugin/FhcAlert.js @@ -250,6 +250,10 @@ export default { // Error is array of strings if (Array.isArray(error) && error.every(err => typeof err === 'string')) return error.every($fhcAlert.alertSystemError); + + // Error has been handled already + if (error.hasOwnProperty('handled') && error.handled) + return; // Error is object if (typeof error === 'object' && error !== null) { diff --git a/public/js/plugin/FhcApi.js b/public/js/plugin/FhcApi.js index ae8fdfdc1..addc2a679 100644 --- a/public/js/plugin/FhcApi.js +++ b/public/js/plugin/FhcApi.js @@ -106,7 +106,7 @@ export default { return _clean_return_value(response); }, error => { if (error.code == 'ERR_CANCELED') - return new Promise(() => {}); + return Promise.reject({...{handled: true}, ...error}); if (error.config?.errorHandling == 'off' || error.config?.errorHandling === false @@ -116,7 +116,7 @@ export default { if (error.response) { if (error.response.status == 404) { app.config.globalProperties.$fhcAlert.alertDefault('error', error.message, error.request.responseURL, true); - return new Promise(() => {}); + return Promise.reject({...{handled: true}, ...error}); } // NOTE(chris): loop through errors @@ -124,13 +124,13 @@ export default { err => (error.config[err.type + 'ErrorHandler'] || app.config.globalProperties.$fhcApi._defaultErrorHandlers[err.type])(err, error.config.form) ); if (!error.response.data.errors.length) - return new Promise(() => {}); + return Promise.reject({...{handled: true}, ...error}); } else if (error.request) { app.config.globalProperties.$fhcAlert.alertDefault('error', error.message, error.request.responseURL); - return new Promise(() => {}); + return Promise.reject({...{handled: true}, ...error}); } else { app.config.globalProperties.$fhcAlert.alertError(error.message); - return new Promise(() => {}); + return Promise.reject({...{handled: true}, ...error}); } return Promise.reject(error); From 4e6b7a845bf18edbe61344c8617a8c8dccba907f Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Tue, 19 Mar 2024 16:54:14 +0100 Subject: [PATCH 26/30] FhcApi: use errorHeader for multiple calls --- public/js/plugin/FhcApi.js | 56 +++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/public/js/plugin/FhcApi.js b/public/js/plugin/FhcApi.js index addc2a679..d85ae8939 100644 --- a/public/js/plugin/FhcApi.js +++ b/public/js/plugin/FhcApi.js @@ -100,7 +100,7 @@ export default { // NOTE(chris): loop through errors if (response.data.errors) response.data.errors = response.data.errors.filter( - err => (response.config[err.type + 'ErrorHandler'] || app.config.globalProperties.$fhcApi._defaultErrorHandlers[err.type])(err, response.config.form) + err => (response.config[err.type + 'ErrorHandler'] || app.config.globalProperties.$fhcApi._defaultErrorHandlers[err.type])(err, response.config) ); return _clean_return_value(response); @@ -121,7 +121,7 @@ export default { // NOTE(chris): loop through errors error.response.data.errors = error.response.data.errors.filter( - err => (error.config[err.type + 'ErrorHandler'] || app.config.globalProperties.$fhcApi._defaultErrorHandlers[err.type])(err, error.config.form) + err => (error.config[err.type + 'ErrorHandler'] || app.config.globalProperties.$fhcApi._defaultErrorHandlers[err.type])(err, error.config) ); if (!error.response.data.errors.length) return Promise.reject({...{handled: true}, ...error}); @@ -152,30 +152,47 @@ export default { return fhcApiAxios.post(uri, data, config); }, _defaultErrorHandlers: { - validation(error, form) { + validation(error, config) { const $fhcAlert = app.config.globalProperties.$fhcAlert; - if (form) { - form.clearValidation(); - form.setFeedback(false, error.messages); + if (config?.form) { + config.form.clearValidation(); + config.form.setFeedback(false, error.messages); return false; } if (Array.isArray(error.messages)) { error.messages.forEach($fhcAlert.alertError); return false; } else if (typeof error.messages == 'object') { - Object.entries(error.messages).forEach( - ([key, value]) => $fhcAlert.alertDefault('error', key, value, true) - ); + if (config?.errorHeader) + Object.values(error.messages).forEach( + value => $fhcAlert.alertDefault( + 'error', + Array.isArray(config.errorHeader) ? app.config.globalProperties.$p.t.apply(null, config.errorHeader) : config.errorHeader, + value, + true + ) + ); + else + Object.entries(error.messages).forEach( + ([key, value]) => $fhcAlert.alertDefault('error', key, value, true) + ); return false; } return true; }, - general(error, form) { + general(error, config) { const $fhcAlert = app.config.globalProperties.$fhcAlert; - if (form) - form.setFeedback(false, error.message); + if (config?.form) + config.form.setFeedback(false, error.message); + else if (config?.errorHeader) + $fhcAlert.alertDefault( + 'error', + Array.isArray(config.errorHeader) ? app.config.globalProperties.$p.t.apply(null, config.errorHeader) : config.errorHeader, + error.message, + true + ); else $fhcAlert.alertError(error.message); }, @@ -251,15 +268,22 @@ export default { $fhcAlert.alertSystemError(message); }, - auth(error) { + auth(error, config) { const $fhcAlert = app.config.globalProperties.$fhcAlert; - var message = ''; message += 'Controller name: ' + error.controller + '\n'; message += 'Method name: ' + error.method + '\n'; - message += 'Required permissions: ' + error.required_permissions - $fhcAlert.alertDefault('error', error.message, message); + message += 'Required permissions: ' + error.required_permissions; + if (config?.errorHeader) + $fhcAlert.alertDefault( + 'error', + Array.isArray(config.errorHeader) ? app.config.globalProperties.$p.t.apply(null, config.errorHeader) : config.errorHeader, + error.message, + true + ); + else + $fhcAlert.alertDefault('error', error.message, message); } } }; From 69803cdb0d9709935aba769f4399d4064075ad60 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Wed, 20 Mar 2024 08:27:26 +0100 Subject: [PATCH 27/30] Phrasen: Bugfix - correct function for multiple categories --- public/js/plugin/Phrasen.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/js/plugin/Phrasen.js b/public/js/plugin/Phrasen.js index 0206e6f57..277402639 100644 --- a/public/js/plugin/Phrasen.js +++ b/public/js/plugin/Phrasen.js @@ -23,8 +23,8 @@ function getValueForLoadedPhrase(category, phrase, params) { const phrasen = { loadCategory(category) { if (Array.isArray(category)) - return Promise.all(category.map(cat => this.config.globalProperties - .$fhcApi.factory.phrasen.loadCategory(cat))); + return Promise.all(category.map(this.config.globalProperties + .$p.loadCategory)); if (!loadingModules[category]) loadingModules[category] = this.config.globalProperties .$fhcApi.factory.phrasen.loadCategory(category) From c4942cc70e145cc91d381bacc340f825a0ba0507 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Thu, 21 Mar 2024 15:45:55 +0100 Subject: [PATCH 28/30] Studstatus => FhcApi --- .../frontend/fas/studstatus/Wiederholung.php | 161 ++++++ .../api/frontend/v1/studstatus/Abmeldung.php | 187 +++++++ .../api/frontend/v1/studstatus/Leitung.php | 428 ++++++++++++++++ .../frontend/v1/studstatus}/Unterbrechung.php | 181 ++++--- .../frontend/v1/studstatus/Wiederholung.php | 258 ++++++++++ .../components/Antrag/Abmeldung.php | 218 -------- .../controllers/components/Antrag/Leitung.php | 479 ------------------ .../components/Antrag/Wiederholung.php | 384 -------------- application/libraries/AntragLib.php | 2 +- application/views/lehre/Antrag/Create.php | 1 + .../views/lehre/Antrag/Leitung/List.php | 3 +- .../views/lehre/Antrag/Student/List.php | 3 +- .../lehre/Antrag/Wiederholung/Student.php | 4 +- content/student/studentoverlay.js.php | 4 +- public/js/api/fhcapifactory.js | 4 +- public/js/api/studstatus.js | 220 ++++++++ public/js/apps/lehre/Antrag.js | 2 - .../Studierendenantrag/Form/Abmeldung.js | 205 +++----- .../Studierendenantrag/Form/AbmeldungStgl.js | 154 +++--- .../Studierendenantrag/Form/Unterbrechung.js | 368 ++++++-------- .../Studierendenantrag/Form/Wiederholung.js | 112 ++-- .../components/Studierendenantrag/Leitung.js | 203 ++------ .../Studierendenantrag/Leitung/Actions/New.js | 24 +- .../Studierendenantrag/Leitung/LvPopup.js | 16 +- .../Studierendenantrag/Leitung/Table.js | 22 +- .../Studierendenantrag/Lvzuweisung.js | 296 +++++------ 26 files changed, 1895 insertions(+), 2044 deletions(-) create mode 100644 application/controllers/api/frontend/fas/studstatus/Wiederholung.php create mode 100644 application/controllers/api/frontend/v1/studstatus/Abmeldung.php create mode 100644 application/controllers/api/frontend/v1/studstatus/Leitung.php rename application/controllers/{components/Antrag => api/frontend/v1/studstatus}/Unterbrechung.php (52%) create mode 100644 application/controllers/api/frontend/v1/studstatus/Wiederholung.php delete mode 100644 application/controllers/components/Antrag/Abmeldung.php delete mode 100644 application/controllers/components/Antrag/Leitung.php delete mode 100644 application/controllers/components/Antrag/Wiederholung.php create mode 100644 public/js/api/studstatus.js diff --git a/application/controllers/api/frontend/fas/studstatus/Wiederholung.php b/application/controllers/api/frontend/fas/studstatus/Wiederholung.php new file mode 100644 index 000000000..c6e5a4fa9 --- /dev/null +++ b/application/controllers/api/frontend/fas/studstatus/Wiederholung.php @@ -0,0 +1,161 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + + +/** + * This controller operates between (interface) the JS (FAS) and the AntragLib (back-end) + * This controller works with calls on the HTTP GET or POST and the output is always RDF + */ +class Wiederholung extends Auth_Controller +{ + + /** + * Calls the parent's constructor and loads the FilterCmptLib + */ + public function __construct() + { + parent::__construct([ + 'getLvs' => ['student/studierendenantrag:r', 'student/noten:r'], + 'moveLvsToZeugnis' => ['student/studierendenantrag:w', 'student/noten:w'] + ]); + + // Libraries + $this->load->library('AntragLib'); + + // Load language phrases + $this->loadPhrases([ + 'global', + 'studierendenantrag' + ]); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + public function getLvs($prestudent_id) + { + // header für no cache + $this->output->set_header("Cache-Control: no-cache"); + $this->output->set_header("Cache-Control: post-check=0, pre-check=0", false); + $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); + $this->output->set_header("Pragma: no-cache"); + $this->output->set_header("Content-type: application/xhtml+xml"); + + $this->load->library('VariableLib', ['uid' => getAuthUID()]); + $sem_akt = $this->variablelib->getVar('semester_aktuell'); + + + $result = $this->antraglib->getLvsForPrestudent($prestudent_id, $sem_akt); + $lvs = $this->getDataOrTerminateWithError($result) ?: []; + + $rdf_url = 'http://www.technikum-wien.at/antragnote'; + + $this->load->view('lehre/Antrag/Wiederholung/getLvs.rdf.php', [ + 'url' => $rdf_url, + 'lvs' => $lvs + ]); + } + + public function moveLvsToZeugnis() + { + $anzahl = $this->input->post('anzahl'); + $student_uid = $this->input->post('student_uid'); + $this->load->model('education/Studierendenantraglehrveranstaltung_model', 'StudierendenantraglehrveranstaltungModel'); + $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); + + $errormsg = array(); + + for($i=0; $i<$anzahl; $i++) + { + $id = $this->input->post('studierendenantrag_lehrveranstaltung_id_' . $i); + $result =$this->StudierendenantraglehrveranstaltungModel->load($id); + if(isError($result)) + { + $errormsg[] = getError($result); + } + elseif(!hasData($result)) + { + $errormsg[] = $this->p->t('studierendenantrag', 'error_no_lv_in_application'); + } + else + { + $antragLv = getData($result)[0]; + $result= $this->ZeugnisnoteModel->load([ + 'lehrveranstaltung_id'=> $antragLv->lehrveranstaltung_id, + 'student_uid'=> $student_uid, + 'studiensemester_kurzbz' => $antragLv->studiensemester_kurzbz + ]); + if(isError($result)) + { + $errormsg[] = getError($result); + } + else + { + if (hasData($result)) + { + $result = $this->ZeugnisnoteModel->update( + [ + 'lehrveranstaltung_id'=> $antragLv->lehrveranstaltung_id, + 'student_uid'=> $student_uid, + 'studiensemester_kurzbz' => $antragLv->studiensemester_kurzbz + ], + [ + 'note'=> $antragLv->note, + 'uebernahmedatum' => date('c'), + 'benotungsdatum' => $antragLv->insertamum, + 'updateamum' => date('c'), + 'bemerkung'=>$antragLv->anmerkung, + 'updatevon'=>getAuthUID() + ] + ); + } + else + { + $result = $this->ZeugnisnoteModel->insert([ + 'lehrveranstaltung_id'=> $antragLv->lehrveranstaltung_id, + 'student_uid'=> $student_uid, + 'studiensemester_kurzbz' => $antragLv->studiensemester_kurzbz, + 'note'=> $antragLv->note, + 'uebernahmedatum' => date('c'), + 'benotungsdatum' => $antragLv->insertamum, + 'insertamum' => date('c'), + 'bemerkung'=>$antragLv->anmerkung, + 'insertvon'=>getAuthUID() + ]); + } + if(isError($result)) + { + $errormsg[] = getError($result); + } + } + } + } + + if($errormsg) + $return = false; + else + $return = true; + + $this->load->view('lehre/Antrag/Wiederholung/moveLvs.rdf.php', [ + 'return' => $return, + 'errormsg' => $errormsg + ]); + } +} diff --git a/application/controllers/api/frontend/v1/studstatus/Abmeldung.php b/application/controllers/api/frontend/v1/studstatus/Abmeldung.php new file mode 100644 index 000000000..875b6484c --- /dev/null +++ b/application/controllers/api/frontend/v1/studstatus/Abmeldung.php @@ -0,0 +1,187 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +use \REST_Controller as REST_Controller; +use \Studierendenantrag_model as Studierendenantrag_model; + +/** + * This controller operates between (interface) the JS (GUI) and the AntragLib (back-end) + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + */ +class Abmeldung extends FHCAPI_Controller +{ + + /** + * Calls the parent's constructor and loads the AntragLib + */ + public function __construct() + { + parent::__construct([ + 'getDetailsForNewAntrag' => self::PERM_LOGGED, + 'getDetailsForAntrag' => self::PERM_LOGGED, + 'createAntrag' => self::PERM_LOGGED, + 'cancelAntrag' => self::PERM_LOGGED + ]); + + // Libraries + $this->load->library('AntragLib'); + + // Load language phrases + $this->loadPhrases([ + 'studierendenantrag' + ]); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Retrieves data of the current studiengang for the current user + */ + + public function getDetailsForNewAntrag($prestudent_id) + { + if (!$this->antraglib->isEntitledToCreateAntragFor($prestudent_id, true)) + $this->terminateWithError('Forbidden', self::ERROR_TYPE_AUTH, REST_Controller::HTTP_FORBIDDEN); + + $result = $this->antraglib->getPrestudentAbmeldeBerechtigt($prestudent_id); + $result = $this->getDataOrTerminateWithError($result); + + if (!$result) { + $this->terminateWithError( + $this->p->t('studierendenantrag', 'error_no_student'), + self::ERROR_TYPE_AUTH, + REST_Controller::HTTP_FORBIDDEN + ); + } elseif ($result == -3) { + $this->terminateWithError( + $this->p->t('studierendenantrag', 'error_stg_blacklist'), + self::ERROR_TYPE_AUTH, + REST_Controller::HTTP_FORBIDDEN + ); + } elseif ($result == -1) { + $result = $this->antraglib->getDetailsForLastAntrag( + $prestudent_id, + [ + Studierendenantrag_model::TYP_ABMELDUNG, + Studierendenantrag_model::TYP_ABMELDUNG_STGL + ] + ); + + $data = $this->getDataOrTerminateWithError($result); + + $data->canCancel = ( + $data->status == Studierendenantragstatus_model::STATUS_CREATED && + $this->antraglib->isEntitledToCancelAntrag($data->studierendenantrag_id) + ); + + $this->terminateWithSuccess($data); + } + + $result = $this->antraglib->getDetailsForNewAntrag($prestudent_id); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getDetailsForAntrag($studierendenantrag_id) + { + if (!$this->antraglib->isEntitledToShowAntrag($studierendenantrag_id)) + return show_404(); + + $result = $this->antraglib->getDetailsForAntrag($studierendenantrag_id); + + $data = $this->getDataOrTerminateWithError($result); + + if ($data->typ !== Studierendenantrag_model::TYP_ABMELDUNG_STGL && $data->typ !== Studierendenantrag_model::TYP_ABMELDUNG) + return show_404(); + + $data->canCancel = ( + $data->status == Studierendenantragstatus_model::STATUS_CREATED && + $this->antraglib->isEntitledToCancelAntrag($data->studierendenantrag_id) + ); + + $this->terminateWithSuccess($data); + } + + public function createAntrag() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('studiensemester', 'Studiensemester', 'required'); + $this->form_validation->set_rules('prestudent_id', 'Prestudent ID', 'required'); + $this->form_validation->set_rules('grund', 'Grund', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $grund = $this->input->post('grund'); + $studiensemester = $this->input->post('studiensemester'); + $prestudent_id = $this->input->post('prestudent_id'); + + $result = $this->antraglib->getPrestudentAbmeldeBerechtigt($prestudent_id); + $result = $this->getDataOrTerminateWithError($result); + if (!$result) + $this->terminateWithError($this->p->t('studierendenantrag', 'error_no_student'), self::ERROR_TYPE_GENERAL); + elseif ($result == -3) + $this->terminateWithError($this->p->t('studierendenantrag', 'error_stg_blacklist'), self::ERROR_TYPE_GENERAL); + elseif ($result < 0) + $this->terminateWithError($this->p->t('studierendenantrag', 'error_antrag_exists'), self::ERROR_TYPE_GENERAL); + + $result = $this->antraglib->createAbmeldung($prestudent_id, $studiensemester, getAuthUID(), $grund); + $data = $this->getDataOrTerminateWithError($result); + + $result = $this->antraglib->getDetailsForAntrag($data); + if (!hasData($result)) + return $this->terminateWithSuccess(true); + + $data = getData($result); + $data->canCancel = (boolean)$this->antraglib->isEntitledToCancelAntrag($data->studierendenantrag_id); + + $this->terminateWithSuccess($data); + } + + public function cancelAntrag() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('antrag_id', 'Antrag ID', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $antrag_id = $this->input->post('antrag_id'); + + if (!$this->antraglib->isEntitledToCancelAntrag($antrag_id)) + $this->terminateWithError('Forbidden', self::ERROR_TYPE_AUTH, REST_Controller::HTTP_FORBIDDEN); + + $result = $this->antraglib->cancelAntrag($antrag_id, getAuthUID()); + $this->getDataOrTerminateWithError($result); + + $result = $this->antraglib->getDetailsForAntrag($antrag_id); + if (!hasData($result)) + $this->terminateWithSuccess($antrag_id); + + $data = getData($result); + + $this->terminateWithSuccess($data); + } +} diff --git a/application/controllers/api/frontend/v1/studstatus/Leitung.php b/application/controllers/api/frontend/v1/studstatus/Leitung.php new file mode 100644 index 000000000..2699a3dbb --- /dev/null +++ b/application/controllers/api/frontend/v1/studstatus/Leitung.php @@ -0,0 +1,428 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +use \stdClass as stdClass; +use \Studierendenantrag_model as Studierendenantrag_model; + +/** + * This controller operates between (interface) the JS (GUI) and the AntragLib (back-end) + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + */ +class Leitung extends FHCAPI_Controller +{ + + /** + * Calls the parent's constructor and loads the AntragLib + */ + public function __construct() + { + parent::__construct([ + 'getActiveStgs' => ['student/antragfreigabe:r', 'student/studierendenantrag:r'], + 'getAntraege' => ['student/antragfreigabe:r', 'student/studierendenantrag:r'], + 'getHistory' => ['student/antragfreigabe:r', 'student/studierendenantrag:r'], + 'getPrestudents' => 'student/studierendenantrag:w', + 'approveAntrag' => 'student/antragfreigabe:w', + 'rejectAntrag' => 'student/antragfreigabe:w', + 'reopenAntrag' => 'student/studierendenantrag:w', + 'pauseAntrag' => ['student/antragfreigabe:w', 'student/studierendenantrag:w'], + 'unpauseAntrag' => ['student/antragfreigabe:w', 'student/studierendenantrag:w'], + 'objectAntrag' => ['student/antragfreigabe:w', 'student/studierendenantrag:w'], + 'approveObjection' => ['student/antragfreigabe:w', 'student/studierendenantrag:w'], + 'denyObjection' => ['student/antragfreigabe:w', 'student/studierendenantrag:w'] + ]); + + // Libraries + $this->load->library('AntragLib'); + + // Load language phrases + $this->loadPhrases([ + 'studierendenantrag' + ]); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + public function getActiveStgs() + { + $studiengaenge = $this->permissionlib->getSTG_isEntitledFor('student/antragfreigabe') ?: []; + $studiengaenge = array_merge($studiengaenge, $this->permissionlib->getSTG_isEntitledFor('student/studierendenantrag') ?: []); + + $result = $this->StudierendenantragModel->loadStgsWithAntraege($studiengaenge); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + public function getAntraege($studiengang = null, $extra = null) + { + if ($studiengang && $studiengang == 'todo') { + $studiengang = $extra; + $extra = true; + } else { + $extra = false; + } + + $studiengaenge = $this->permissionlib->getSTG_isEntitledFor('student/antragfreigabe'); + if(!is_array($studiengaenge)) + $studiengaenge = []; + + + $stgsNeuanlage = $this->permissionlib->getSTG_isEntitledFor('student/studierendenantrag'); + if(!is_array($stgsNeuanlage)) + $stgsNeuanlage = []; + + $studiengaenge = array_unique(array_merge($studiengaenge, $stgsNeuanlage)); + + if ($studiengang) { + if (!in_array($studiengang, $studiengaenge)) + $this->terminateWithError( + 'Forbidden', + self::ERROR_TYPE_AUTH, + REST_Controller::HTTP_FORBIDDEN + ); + $studiengaenge = [$studiengang]; + } + + $antraege = []; + if ($studiengaenge) { + $result = $extra + ? $this->StudierendenantragModel->loadActiveForStudiengaenge($studiengaenge) + : $this->StudierendenantragModel->loadForStudiengaenge($studiengaenge); + + $antraege = $this->getDataOrTerminateWithError($result); + } + + $this->terminateWithSuccess($antraege ?: []); + } + + public function getHistory($studierendenantrag_id) + { + if (!$this->antraglib->isEntitledToSeeHistoryForAntrag($studierendenantrag_id)) + $this->terminateWithError( + 'Forbidden', + self::ERROR_TYPE_AUTH, + REST_Controller::HTTP_FORBIDDEN + ); + + $result = $this->antraglib->getAntragHistory($studierendenantrag_id); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data ?: []); + } + + public function getPrestudents() + { + $query = $this->input->post('query'); + + $studiengaenge = $this->permissionlib->getSTG_isEntitledFor('student/studierendenantrag'); + + $result = $this->antraglib->getAktivePrestudentenInStgs($studiengaenge, $query); + $result = $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($result ?: []); + } + + public function approveAntrag() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules( + 'studierendenantrag_id', + 'Studierenden Antrag', + [ + 'required', + ['isEntitledToApproveAntrag', [$this->antraglib, 'isEntitledToApproveAntrag']], + ], + [ + 'isEntitledToApproveAntrag' => $this->p->t('studierendenantrag', 'error_no_right') + ] + ); + $this->form_validation->set_rules( + 'typ', + 'Typ', + 'required|in_list[' . implode(',', [ + Studierendenantrag_model::TYP_ABMELDUNG, + Studierendenantrag_model::TYP_ABMELDUNG_STGL, + Studierendenantrag_model::TYP_UNTERBRECHUNG, + Studierendenantrag_model::TYP_WIEDERHOLUNG + ]) . ']' + ); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $studierendenantrag_id = $this->input->post('studierendenantrag_id'); + switch ($this->input->post('typ')) { + case Studierendenantrag_model::TYP_ABMELDUNG: + case Studierendenantrag_model::TYP_ABMELDUNG_STGL: + $result = $this->antraglib->approveAbmeldung([$studierendenantrag_id], getAuthUID()); + break; + case Studierendenantrag_model::TYP_UNTERBRECHUNG: + $result = $this->antraglib->approveUnterbrechung([$studierendenantrag_id], getAuthUID()); + break; + case Studierendenantrag_model::TYP_WIEDERHOLUNG: + $result = $this->antraglib->approveWiederholung($studierendenantrag_id, getAuthUID()); + break; + } + $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($studierendenantrag_id); + } + + public function rejectAntrag() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules( + 'studierendenantrag_id', + 'Studierenden Antrag', + [ + 'required', + ['isEntitledToRejectAntrag', [$this->antraglib, 'isEntitledToRejectAntrag']], + ], + [ + 'isEntitledToRejectAntrag' => $this->p->t('studierendenantrag', 'error_no_right') + ] + ); + $this->form_validation->set_rules('grund', 'Grund', 'required'); + $this->form_validation->set_rules( + 'typ', + 'Typ', + 'required|in_list[' . implode(',', [ + Studierendenantrag_model::TYP_UNTERBRECHUNG + ]) . ']' + ); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $studierendenantrag_id = $this->input->post('studierendenantrag_id'); + $grund = $this->input->post('grund'); + + $result = $this->antraglib->rejectUnterbrechung([$studierendenantrag_id], getAuthUID(), $grund); + $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($studierendenantrag_id); + } + + public function reopenAntrag() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules( + 'studierendenantrag_id', + 'Studierenden Antrag', + [ + 'required', + ['isEntitledToReopenAntrag', [$this->antraglib, 'isEntitledToReopenAntrag']], + ], + [ + 'isEntitledToReopenAntrag' => $this->p->t('studierendenantrag', 'error_no_right') + ] + ); + $this->form_validation->set_rules( + 'typ', + 'Typ', + 'required|in_list[' . implode(',', [ + Studierendenantrag_model::TYP_WIEDERHOLUNG + ]) . ']' + ); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $studierendenantrag_id = $this->input->post('studierendenantrag_id'); + + $result = $this->antraglib->reopenWiederholung($studierendenantrag_id, getAuthUID()); + $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($studierendenantrag_id); + } + + public function pauseAntrag() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules( + 'studierendenantrag_id', + 'Studierenden Antrag', + [ + 'required', + ['isEntitledToPauseAntrag', [$this->antraglib, 'isEntitledToPauseAntrag']], + ['antragCanBeManualPaused', [$this->antraglib, 'antragCanBeManualPaused']] + ], + [ + 'isEntitledToPauseAntrag' => $this->p->t('studierendenantrag', 'error_no_right'), + 'antragCanBeManualPaused' => $this->p->t( + 'studierendenantrag', + 'error_not_pauseable', + ['id' => $this->input->post('studierendenantrag_id')] + ) + ] + ); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $studierendenantrag_id = $this->input->post('studierendenantrag_id'); + + $result = $this->antraglib->pauseAntrag($studierendenantrag_id, getAuthUID()); + $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($studierendenantrag_id); + } + + public function unpauseAntrag() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules( + 'studierendenantrag_id', + 'Studierenden Antrag', + [ + 'required', + ['isEntitledToUnpauseAntrag', [$this->antraglib, 'isEntitledToUnpauseAntrag']], + ['antragCanBeManualUnpaused', [$this->antraglib, 'antragCanBeManualUnpaused']] + ], + [ + 'isEntitledToUnpauseAntrag' => $this->p->t('studierendenantrag', 'error_no_right'), + 'antragCanBeManualUnpaused' => $this->p->t( + 'studierendenantrag', + 'error_not_paused', + ['id' => $this->input->post('studierendenantrag_id')] + ) + ] + ); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $studierendenantrag_id = $this->input->post('studierendenantrag_id'); + + $result = $this->antraglib->unpauseAntrag($studierendenantrag_id, getAuthUID()); + $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($studierendenantrag_id); + } + + public function objectAntrag() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules( + 'studierendenantrag_id', + 'Studierenden Antrag', + [ + 'required', + ['isEntitledToObjectAntrag', [$this->antraglib, 'isEntitledToObjectAntrag']], + ['canBeObjected', function ($a) { + return $this->antraglib->hasType($a, Studierendenantrag_model::TYP_ABMELDUNG_STGL); + }] + ], + [ + 'isEntitledToObjectAntrag' => $this->p->t('studierendenantrag', 'error_no_right'), + 'canBeObjected' => $this->p->t( + 'studierendenantrag', + 'error_no_objection' + ) + ] + ); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $studierendenantrag_id = $this->input->post('studierendenantrag_id'); + + $result = $this->antraglib->objectAbmeldung($studierendenantrag_id, getAuthUID()); + $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($studierendenantrag_id); + } + + public function approveObjection() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules( + 'studierendenantrag_id', + 'Studierenden Antrag', + [ + 'required', + ['isEntitledToObjectAntrag', [$this->antraglib, 'isEntitledToObjectAntrag']], + ['isObjected', function ($a) { + return $this->antraglib->hasStatus($a, Studierendenantragstatus_model::STATUS_OBJECTED); + }] + ], + [ + 'isEntitledToObjectAntrag' => $this->p->t('studierendenantrag', 'error_no_right'), + 'isObjected' => $this->p->t( + 'studierendenantrag', + 'error_not_objected' + ) + ] + ); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $studierendenantrag_id = $this->input->post('studierendenantrag_id'); + + $result = $this->antraglib->cancelAntrag($studierendenantrag_id, getAuthUID()); + $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($studierendenantrag_id); + } + + public function denyObjection() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules( + 'studierendenantrag_id', + 'Studierenden Antrag', + [ + 'required', + ['isEntitledToObjectAntrag', [$this->antraglib, 'isEntitledToObjectAntrag']], + ['isObjected', function ($a) { + return $this->antraglib->hasStatus($a, Studierendenantragstatus_model::STATUS_OBJECTED); + }] + ], + [ + 'isEntitledToObjectAntrag' => $this->p->t('studierendenantrag', 'error_no_right'), + 'isObjected' => $this->p->t( + 'studierendenantrag', + 'error_not_objected' + ) + ] + ); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $studierendenantrag_id = $this->input->post('studierendenantrag_id'); + $grund = $this->input->post('grund'); + + $result = $this->antraglib->denyObjectionAbmeldung($studierendenantrag_id, getAuthUID(), $grund); + $this->getDataOrTerminateWithError($result); + + return $this->terminateWithSuccess($studierendenantrag_id); + } +} diff --git a/application/controllers/components/Antrag/Unterbrechung.php b/application/controllers/api/frontend/v1/studstatus/Unterbrechung.php similarity index 52% rename from application/controllers/components/Antrag/Unterbrechung.php rename to application/controllers/api/frontend/v1/studstatus/Unterbrechung.php index f19139e00..abf58cf4f 100644 --- a/application/controllers/components/Antrag/Unterbrechung.php +++ b/application/controllers/api/frontend/v1/studstatus/Unterbrechung.php @@ -1,4 +1,20 @@ . + */ if (! defined('BASEPATH')) exit('No direct script access allowed'); @@ -6,23 +22,28 @@ use \Studierendenantrag_model as Studierendenantrag_model; use \DateTime as DateTime; /** - * + * This controller operates between (interface) the JS (GUI) and the AntragLib (back-end) + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON */ -class Unterbrechung extends FHC_Controller +class Unterbrechung extends FHCAPI_Controller { /** - * Calls the parent's constructor and loads the FilterCmptLib + * Calls the parent's constructor and loads the AntragLib */ public function __construct() { - parent::__construct(); + parent::__construct([ + 'getDetailsForNewAntrag' => self::PERM_LOGGED, + 'getDetailsForAntrag' => self::PERM_LOGGED, + 'createAntrag' => self::PERM_LOGGED, + 'cancelAntrag' => self::PERM_LOGGED + ]); // Configs $this->load->config('studierendenantrag'); // Libraries - $this->load->library('AuthLib'); $this->load->library('AntragLib'); // Load language phrases @@ -38,74 +59,62 @@ class Unterbrechung extends FHC_Controller public function getDetailsForNewAntrag($prestudent_id) { - if (!$this->antraglib->isEntitledToCreateAntragFor($prestudent_id, false)) { - $this->output->set_status_header(403); - return $this->outputJsonError('Forbidden'); - } + if (!$this->antraglib->isEntitledToCreateAntragFor($prestudent_id, false)) + $this->terminateWithError('Forbidden', self::ERROR_TYPE_AUTH, REST_Controller::HTTP_FORBIDDEN); + $result = $this->antraglib->getPrestudentUnterbrechungsBerechtigt($prestudent_id); - if (isError($result)) { - $this->output->set_status_header(500); - return $this->outputJsonError(getError($result)); - } - $result = $result->retval; + $result = $this->getDataOrTerminateWithError($result); + if (!$result) { - $this->output->set_status_header(403); - return $this->outputJsonError($this->p->t('studierendenantrag', 'error_no_student')); - } - elseif ($result == -1) - { + $this->terminateWithError( + $this->p->t('studierendenantrag', 'error_no_student'), + self::ERROR_TYPE_AUTH, + REST_Controller::HTTP_FORBIDDEN + ); + } elseif ($result == -1) { $result = $this->antraglib->getDetailsForLastAntrag($prestudent_id, Studierendenantrag_model::TYP_UNTERBRECHUNG); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } + + $data = $this->getDataOrTerminateWithError($result); - return $this->outputJsonSuccess(getData($result)); - } - elseif ($result == -2) - { + return $this->terminateWithSuccess($data); + } elseif ($result == -2) { $result = $this->antraglib->getDetailsForLastAntrag($prestudent_id); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } - $result = getData($result); - $this->output->set_status_header(400); - return $this->outputJsonError($this->p->t('studierendenantrag', 'error_antrag_pending', [ + $data = $this->getDataOrTerminateWithError($result); + + return $this->terminateWithError($this->p->t('studierendenantrag', 'error_antrag_pending', [ 'typ' => $this->p->t('studierendenantrag', 'antrag_typ_' . $result->typ) ])); - } - elseif ($result == -3) - { - $this->output->set_status_header(403); - return $this->outputJsonError($this->p->t('studierendenantrag', 'error_stg_blacklist')); - } - $result = $this->antraglib->getDetailsForNewAntrag($prestudent_id); - if (isError($result)) { - return $this->outputJsonError(getError($result)); + } elseif ($result == -3) { + $this->terminateWithError( + $this->p->t('studierendenantrag', 'error_stg_blacklist'), + self::ERROR_TYPE_AUTH, + REST_Controller::HTTP_FORBIDDEN + ); } - $data = getData($result); + $result = $this->antraglib->getDetailsForNewAntrag($prestudent_id); + + $data = $this->getDataOrTerminateWithError($result); $data->studiensemester = $this->antraglib->getSemesterForUnterbrechung($prestudent_id, null); - $this->outputJsonSuccess($data); + $this->terminateWithSuccess($data); } public function getDetailsForAntrag($studierendenantrag_id) { - if (!$this->antraglib->isEntitledToShowAntrag($studierendenantrag_id)) return show_404(); + if (!$this->antraglib->isEntitledToShowAntrag($studierendenantrag_id)) + return show_404(); $result = $this->antraglib->getDetailsForAntrag($studierendenantrag_id); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } - $data = getData($result); + $data = $this->getDataOrTerminateWithError($result); if ($data->typ !== Studierendenantrag_model::TYP_UNTERBRECHUNG) return show_404(); - $this->outputJsonSuccess($data); + $this->terminateWithSuccess($data); } public function createAntrag() @@ -125,9 +134,8 @@ class Unterbrechung extends FHC_Controller ] ); - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); + if (!$this->form_validation->run()) { + $this->terminateWithValidationErrors($this->form_validation->error_array()); } $grund = $this->input->post('grund'); @@ -137,25 +145,17 @@ class Unterbrechung extends FHC_Controller $dms_id = null; $result = $this->antraglib->getPrestudentUnterbrechungsBerechtigt($prestudent_id, $studiensemester, $datum_wiedereinstieg); - if (isError($result)) { - return $this->outputJsonError(['db' => getError($result)]); - } - $result = $result->retval; - if (!$result) - { - return $this->outputJsonError(['db' => $this->p->t('studierendenantrag', 'error_no_student')]); - } - elseif ($result == -3) - { - return $this->outputJsonError(['db' => $this->p->t('studierendenantrag', 'error_stg_blacklist')]); - } - elseif ($result < 0) - { - return $this->outputJsonError(['db' => $this->p->t('studierendenantrag', 'error_antrag_exists')]); - } - if(isset($_FILES['attachment']) && (!isset($_FILES['attachment']['error']) || $_FILES['attachment']['error'] != UPLOAD_ERR_NO_FILE)) - { + $result = $this->getDataOrTerminateWithError($result); + + if (!$result) + $this->terminateWithError($this->p->t('studierendenantrag', 'error_no_student'), self::ERROR_TYPE_GENERAL); + elseif ($result == -3) + $this->terminateWithError($this->p->t('studierendenantrag', 'error_stg_blacklist'), self::ERROR_TYPE_GENERAL); + elseif ($result < 0) + $this->terminateWithError($this->p->t('studierendenantrag', 'error_antrag_exists'), self::ERROR_TYPE_GENERAL); + + if (isset($_FILES['attachment']) && (!isset($_FILES['attachment']['error']) || $_FILES['attachment']['error'] != UPLOAD_ERR_NO_FILE)) { $this->load->library('DmsLib'); $dms = $this->config->item('unterbrechung_dms'); @@ -167,53 +167,46 @@ class Unterbrechung extends FHC_Controller $allowed_filetypes = $this->config->item('unterbrechung_dms_filetypes') ?: ['*']; $result = $this->dmslib->upload($dms, 'attachment', $allowed_filetypes); - if(isError($result)) - { - return $this->outputJsonError(['db' => getError($result)]); - } - $dms_id = getData($result)['dms_id']; + + $data = $this->getDataOrTerminateWithError($result); + + $dms_id = $data['dms_id']; } $result = $this->antraglib->createUnterbrechung($prestudent_id, $studiensemester, getAuthUID(), $grund, $datum_wiedereinstieg, $dms_id); - if(isError($result)) - { - return $this->outputJsonError(['db' => getError($result)]); - } - $antragId = getData($result); + $antragId = $this->getDataOrTerminateWithError($result); + $result = $this->antraglib->getDetailsForAntrag($antragId); - if(!hasData($result)) - return $this->outputJsonSuccess($antragId); - $this->outputJsonSuccess(getData($result)); + if (!hasData($result)) + $this->terminateWithSuccess($antragId); + + $this->terminateWithSuccess(getData($result)); } public function cancelAntrag() { $this->load->library('form_validation'); - $_POST = json_decode($this->input->raw_input_stream, true); - $this->form_validation->set_rules('antrag_id', 'Antrag ID', 'required'); - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); + if (!$this->form_validation->run()) { + $this->terminateWithValidationErrors($this->form_validation->error_array()); } $antrag_id = $this->input->post('antrag_id'); $result = $this->antraglib->cancelAntrag($antrag_id, getAuthUID()); - if (isError($result)) - { - return $this->outputJsonError(['db' => getError($result)]); - } + + $this->getDataOrTerminateWithError($result); $result = $this->antraglib->getDetailsForAntrag($antrag_id); if (!hasData($result)) - return $this->outputJsonSuccess($antrag_id); - $this->outputJsonSuccess(getData($result)); + return $this->terminateWithSuccess($antrag_id); + + $this->terminateWithSuccess(getData($result)); } public function isValidDate($date) diff --git a/application/controllers/api/frontend/v1/studstatus/Wiederholung.php b/application/controllers/api/frontend/v1/studstatus/Wiederholung.php new file mode 100644 index 000000000..1a8f70d52 --- /dev/null +++ b/application/controllers/api/frontend/v1/studstatus/Wiederholung.php @@ -0,0 +1,258 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +use \REST_Controller as REST_Controller; +use \Studierendenantragstatus_model as Studierendenantragstatus_model; + +/** + * This controller operates between (interface) the JS (GUI) and the AntragLib (back-end) + * This controller works with JSON calls on the HTTP GET or POST and the output is always JSON + */ +class Wiederholung extends FHCAPI_Controller +{ + + /** + * Calls the parent's constructor and loads the FilterCmptLib + */ + public function __construct() + { + parent::__construct([ + 'getDetailsForNewAntrag' => self::PERM_LOGGED, + 'createAntrag' => self::PERM_LOGGED, + 'cancelAntrag' => self::PERM_LOGGED, + 'getLvs' => self::PERM_LOGGED, + 'saveLvs' => ['student/studierendenantrag:w'] + ]); + + // Libraries + $this->load->library('AntragLib'); + + // Load language phrases + $this->loadPhrases([ + 'global', + 'studierendenantrag' + ]); + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + /** + * Retrieves data of the current studiengang for the current user + */ + + public function getDetailsForNewAntrag($prestudent_id) + { + if (!$this->antraglib->isEntitledToCreateAntragFor($prestudent_id, false)) + $this->terminateWithError('Forbidden', self::ERROR_TYPE_AUTH, REST_Controller::HTTP_FORBIDDEN); + + $result = $this->antraglib->getPrestudentWiederholungsBerechtigt($prestudent_id); + $result = $this->getDataOrTerminateWithError($result); + + if (!$result) { + $this->terminateWithError( + $this->p->t('studierendenantrag', 'error_no_student_no_failed_exam'), + self::ERROR_TYPE_AUTH, + REST_Controller::HTTP_FORBIDDEN + ); + } elseif ($result == -1) { + $result = $this->antraglib->getDetailsForLastAntrag($prestudent_id, Studierendenantrag_model::TYP_WIEDERHOLUNG); + $data = $this->getDataOrTerminateWithError($result); + + $result = $this->antraglib->getFailedExamForPrestudent($prestudent_id, $data->datum, $data->studiensemester_kurzbz); + // NOTE(chris): error handling for this function should already happenden in antraglib->getPrestudentWiederholungsBerechtigt() + $pruefungsdata = current(getData($result)); + + $data->studiensemester_kurzbz = $pruefungsdata->studiensemester_kurzbz; + $data->lvbezeichnung = $pruefungsdata->lvbezeichnung; + $data->pruefungsdatum = $pruefungsdata->datum; + + $this->terminateWithSuccess($data); + } elseif ($result == -2) { + $result = $this->antraglib->getDetailsForLastAntrag($prestudent_id); + $result = $this->getDataOrTerminateWithError($result); + + $this->terminateWithError( + $this->p->t('studierendenantrag', 'error_antrag_pending', [ + 'typ' => $this->p->t('studierendenantrag', 'antrag_typ_' . $result->typ) + ]), + self::ERROR_TYPE_GENERAL, + REST_Controller::HTTP_BAD_REQUEST + ); + } elseif ($result == -3) { + $this->terminateWithError( + $this->p->t('studierendenantrag', 'error_stg_blacklist'), + self::ERROR_TYPE_GENERAL, + REST_Controller::HTTP_BAD_REQUEST + ); + } + + $result = $this->antraglib->getDetailsForNewAntrag($prestudent_id); + $data = $this->getDataOrTerminateWithError($result); + + $result = $this->antraglib->getFailedExamForPrestudent($prestudent_id); + // NOTE(chris): error handling for this function should already happenden in antraglib->getPrestudentWiederholungsBerechtigt() + $pruefungsdata = current(getData($result)); + + $data->studiensemester_kurzbz = $pruefungsdata->studiensemester_kurzbz; + $data->lvbezeichnung = $pruefungsdata->lvbezeichnung; + $data->pruefungsdatum = $pruefungsdata->datum; + + $this->terminateWithSuccess($data); + } + + public function createAntrag() + { + $this->createAntragWithStatus(true); + } + + public function cancelAntrag() + { + $this->createAntragWithStatus(false); + } + + protected function createAntragWithStatus($repeat) + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('prestudent_id', 'Prestudent ID', 'required'); + $this->form_validation->set_rules('studiensemester', 'Studiensemester', 'required'); + + if (!$this->form_validation->run()) + $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $prestudent_id = $this->input->post('prestudent_id'); + $studiensemester = $this->input->post('studiensemester'); + + $result = $this->antraglib->getPrestudentWiederholungsBerechtigt($prestudent_id); + $result = $this->getDataOrTerminateWithError($result); + + if (!$result) { + $this->terminateWithError($this->p->t('studierendenantrag', 'error_no_student'), self::ERROR_TYPE_GENERAL); + } elseif ($result == -1) { + $result = $this->PrestudentstatusModel->getLastStatus($prestudent_id); + $result = $this->getDataOrTerminateWithError($result); + if (!$result) + $this->terminateWithError($this->p->t('studierendenantrag', 'error_no_prestudentstatus', [ + 'prestudent_id' => $prestudent_id + ]), self::ERROR_TYPE_GENERAL); + if (!in_array(current($result)->status_kurzbz, $this->config->item('antrag_prestudentstatus_whitelist'))) + $this->terminateWithError($this->p->t('studierendenantrag', 'error_no_student'), self::ERROR_TYPE_GENERAL); + } elseif ($result == -2) { + $this->terminateWithError($this->p->t('studierendenantrag', 'error_antrag_exists'), self::ERROR_TYPE_GENERAL); + } elseif ($result == -3) { + $this->terminateWithError($this->p->t('studierendenantrag', 'error_stg_blacklist'), self::ERROR_TYPE_GENERAL); + } + + $result = $this->antraglib->createWiederholung($prestudent_id, $studiensemester, getAuthUID(), $repeat); + $antragId = $this->getDataOrTerminateWithError($result); + + $result = $this->antraglib->getDetailsForAntrag($antragId); + + if (!hasData($result)) + $this->terminateWithSuccess(true); + + $data = getData($result); + + $result = $this->antraglib->getFailedExamForPrestudent($prestudent_id); + // NOTE(chris): error handling for this function should already happenden in antraglib->getPrestudentWiederholungsBerechtigt() + $pruefungsdata = current(getData($result)); + + $data->studiensemester_kurzbz = $pruefungsdata->studiensemester_kurzbz; + $data->lvbezeichnung = $pruefungsdata->lvbezeichnung; + $data->pruefungsdatum = $pruefungsdata->datum; + + $this->terminateWithSuccess($data); + } + + + public function getLvs($antrag_id) + { + $result = $this->antraglib->getLvsForAntrag($antrag_id); + if (isError($result)) { + $error = getError($result); + if ($error == 'Forbidden') + $this->terminateWithError( + $error, + self::ERROR_TYPE_AUTH, + REST_Controller::HTTP_FORBIDDEN + ); + $this->terminateWithError( + $error, + self::ERROR_TYPE_GENERAL + ); + } + $lvs = getData($result); + + $this->terminateWithSuccess($lvs); + } + + public function saveLvs() + { + $forbiddenLvs = $this->input->post('forbiddenLvs'); + $mandatoryLvs = $this->input->post('mandatoryLvs'); + $antragsLvs = array_merge($forbiddenLvs, $mandatoryLvs); + + if (!$antragsLvs) + $this->terminateWithError($this->p->t('studierendenantrag', 'error_no_lv'), self::ERROR_TYPE_GENERAL); + + $insert = array_map(function ($lv) { + return [ + 'studierendenantrag_id' => $lv['studierendenantrag_id'], + 'lehrveranstaltung_id' => $lv['lehrveranstaltung_id'], + 'note' => $lv['zugelassen'] + ? ($lv['zugelassen'] == 1 ? 0 : $this->config->item('wiederholung_note_angerechnet')) + : $this->config->item('wiederholung_note_nicht_zugelassen'), + 'anmerkung' => $lv['anmerkung'], + 'insertvon' => getAuthUID(), + 'studiensemester_kurzbz' => $lv['studiensemester_kurzbz'] + ]; + }, $antragsLvs); + + $antrag_ids = array_unique(array_map(function ($lv) { + return $lv['studierendenantrag_id']; + }, $insert)); + + foreach ($antrag_ids as $antrag_id) { + $result = $this->StudierendenantragModel->loadIdAndStatusWhere([ + 'studierendenantrag_id' => $antrag_id + ]); + $antrag = $this->getDataOrTerminateWithError($result); + if (!$antrag) + $this->terminateWithError( + $this->p->t('studierendenantrag', 'error_no_antrag_found', ['id' => $antrag_id]), + self::ERROR_TYPE_GENERAL + ); + $antrag = current($antrag); + + if ($antrag->status != Studierendenantragstatus_model::STATUS_CREATED + && $antrag->status != Studierendenantragstatus_model::STATUS_LVSASSIGNED) + $this->terminateWithError( + $this->p->t('studierendenantrag', 'error_antrag_locked'), + self::ERROR_TYPE_GENERAL + ); + } + + $result = $this->antraglib->saveLvs($insert); + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } +} diff --git a/application/controllers/components/Antrag/Abmeldung.php b/application/controllers/components/Antrag/Abmeldung.php deleted file mode 100644 index f30de6803..000000000 --- a/application/controllers/components/Antrag/Abmeldung.php +++ /dev/null @@ -1,218 +0,0 @@ -load->library('AuthLib'); - $this->load->library('AntragLib'); - - // Load language phrases - $this->loadPhrases([ - 'studierendenantrag' - ]); - } - - //------------------------------------------------------------------------------------------------------------------ - // Public methods - - /** - * Retrieves data of the current studiengang for the current user - */ - - public function getDetailsForNewAntrag($prestudent_id) - { - if (!$this->antraglib->isEntitledToCreateAntragFor($prestudent_id, true)) { - $this->output->set_status_header(403); - return $this->outputJsonError('Forbidden'); - } - $result = $this->antraglib->getPrestudentAbmeldeBerechtigt($prestudent_id); - if (isError($result)) { - $this->output->set_status_header(500); - return $this->outputJsonError(getError($result)); - } - $result = $result->retval; - if (!$result) { - $this->output->set_status_header(403); - return $this->outputJsonError($this->p->t('studierendenantrag', 'error_no_student')); - } - elseif ($result == -3) - { - $this->output->set_status_header(403); - return $this->outputJsonError($this->p->t('studierendenantrag', 'error_stg_blacklist')); - } - elseif ($result == -1) - { - $result = $this->antraglib->getDetailsForLastAntrag( - $prestudent_id, - [ - Studierendenantrag_model::TYP_ABMELDUNG, - Studierendenantrag_model::TYP_ABMELDUNG_STGL - ] - ); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } - - $data = getData($result); - - $data->canCancel = ( - $data->status == Studierendenantragstatus_model::STATUS_CREATED && - $this->antraglib->isEntitledToCancelAntrag($data->studierendenantrag_id) - ); - - return $this->outputJsonSuccess($data); - } - - $result = $this->antraglib->getDetailsForNewAntrag($prestudent_id); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } - - $this->outputJsonSuccess(getData($result)); - } - - public function getDetailsForAntrag($studierendenantrag_id) - { - if (!$this->antraglib->isEntitledToShowAntrag($studierendenantrag_id)) return show_404(); - - $result = $this->antraglib->getDetailsForAntrag($studierendenantrag_id); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } - - $data = getData($result); - - if ($data->typ !== Studierendenantrag_model::TYP_ABMELDUNG_STGL && $data->typ !== Studierendenantrag_model::TYP_ABMELDUNG) - return show_404(); - - $data->canCancel = ( - $data->status == Studierendenantragstatus_model::STATUS_CREATED && - $this->antraglib->isEntitledToCancelAntrag($data->studierendenantrag_id) - ); - - $this->outputJsonSuccess($data); - } - - public function createAntrag() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules('studiensemester', 'Studiensemester', 'required'); - $this->form_validation->set_rules('prestudent_id', 'Prestudent ID', 'required'); - $this->form_validation->set_rules('grund', 'Grund', 'required'); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $grund = $this->input->post('grund'); - $studiensemester = $this->input->post('studiensemester'); - $prestudent_id = $this->input->post('prestudent_id'); - - $result = $this->antraglib->getPrestudentAbmeldeBerechtigt($prestudent_id); - if (isError($result)) { - return $this->outputJsonError(['db' => getError($result)]); - } - $result = $result->retval; - if (!$result) - { - return $this->outputJsonError(['db' => $this->p->t('studierendenantrag', 'error_no_student')]); - } - elseif ($result == -3) - { - return $this->outputJsonError(['db' => $this->p->t('studierendenantrag', 'error_stg_blacklist')]); - } - elseif ($result < 0) - { - return $this->outputJsonError(['db' => $this->p->t('studierendenantrag', 'error_antrag_exists')]); - } - - $result = $this->antraglib->createAbmeldung($prestudent_id, $studiensemester, getAuthUID(), $grund); - if (isError($result)) - { - return $this->outputJsonError(['db' => getError($result)]); - } - - $result = $this->antraglib->getDetailsForAntrag(getData($result)); - if (!hasData($result)) - return $this->outputJsonSuccess(true); - - $data = getData($result); - $data->canCancel = (boolean)$this->antraglib->isEntitledToCancelAntrag($data->studierendenantrag_id); - - $this->outputJsonSuccess($data); - } - - public function cancelAntrag() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules('antrag_id', 'Antrag ID', 'required'); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $antrag_id = $this->input->post('antrag_id'); - if(!$this->antraglib->isEntitledToCancelAntrag($antrag_id)) - { - $this->output->set_status_header(403); - - return $this->outputJsonError('Forbidden'); - } - - $result = $this->antraglib->cancelAntrag($antrag_id, getAuthUID()); - if(isError($result)) - { - return $this->outputJsonError(['db' => getError($result)]); - } - - $result = $this->antraglib->getDetailsForAntrag($antrag_id); - - if (!hasData($result)) - return $this->outputJsonSuccess($antrag_id); - $this->outputJsonSuccess(getData($result)); - } - - public function getStudiengaengeAssistenz() - { - $this->load->library('PermissionLib'); - - $_POST = json_decode($this->input->raw_input_stream, true); - $query = $this->input->post('query'); - - $studiengaenge = $this->permissionlib->getSTG_isEntitledFor('student/studierendenantrag'); - - $result = $this->antraglib->getAktivePrestudentenInStgs($studiengaenge, $query); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } - $result = getData($result); - if (!$result) { - return $this->outputJsonSuccess([]); - } - - return $this->outputJsonSuccess($result); - } -} diff --git a/application/controllers/components/Antrag/Leitung.php b/application/controllers/components/Antrag/Leitung.php deleted file mode 100644 index 437030d08..000000000 --- a/application/controllers/components/Antrag/Leitung.php +++ /dev/null @@ -1,479 +0,0 @@ -load->library('AuthLib'); - $this->load->library('AntragLib'); - - // Load language phrases - $this->loadPhrases([ - 'studierendenantrag' - ]); - } - - - //------------------------------------------------------------------------------------------------------------------ - // Public methods - - public function getActiveStgs() - { - $studiengaenge = $this->permissionlib->getSTG_isEntitledFor('student/antragfreigabe') ?: []; - $studiengaenge = array_merge($studiengaenge, $this->permissionlib->getSTG_isEntitledFor('student/studierendenantrag') ?: []); - - $result = $this->StudierendenantragModel->loadStgsWithAntraege($studiengaenge); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - } - $this->outputJson($result); - } - - public function getAntraege($studiengang = null, $extra = null) - { - if ($studiengang && $studiengang == 'todo') { - $studiengang = $extra; - $extra = true; - } else { - $extra = false; - } - - if ($studiengang) { - $studiengaenge = [$studiengang]; - } else { - $studiengaenge =$this->permissionlib->getSTG_isEntitledFor('student/antragfreigabe'); - if(!is_array($studiengaenge)) - $studiengaenge = []; - - - $stgsNeuanlage = $this->permissionlib->getSTG_isEntitledFor('student/studierendenantrag'); - if(!is_array($stgsNeuanlage)) - $stgsNeuanlage = []; - - $studiengaenge = array_unique(array_merge($studiengaenge, $stgsNeuanlage)); - } - - - $antraege = []; - if ($studiengaenge) { - $result = $extra - ? $this->StudierendenantragModel->loadActiveForStudiengaenge($studiengaenge) - : $this->StudierendenantragModel->loadForStudiengaenge($studiengaenge); - if (isError($result)) { - $this->output->set_status_header(500); - return $this->outputJson('Internal Server Error'); - } - if(hasData($result)) - { - $antraege = getData($result); - } - } - - $this->outputJson($antraege); - } - - public function reopenAntrag() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules( - 'studierendenantrag_id', - 'Studierenden Antrag', - 'required|callback_isEntitledToReopenAntrag', - [ - 'isEntitledToReopenAntrag' => $this->p->t('studierendenantrag', 'error_no_right') - ] - ); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $studierendenantrag_id = $this->input->post('studierendenantrag_id'); - - $result = $this->antraglib->reopenWiederholung($studierendenantrag_id, getAuthUID()); - - if (isError($result)) - return $this->outputJsonError(['studierendenantrag_id' => getError($result)]); - - $this->outputJsonSuccess($studierendenantrag_id); - } - - public function pauseAntrag() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules( - 'studierendenantrag_id', - 'Studierenden Antrag', - [ - 'required', - [ - 'isEntitledToPauseAntrag', - [$this->antraglib, 'isEntitledToPauseAntrag'] - ], - [ - 'antragCanBeManualPaused', - [$this->antraglib, 'antragCanBeManualPaused'] - ] - ], - [ - 'isEntitledToPauseAntrag' => $this->p->t('studierendenantrag', 'error_no_right'), - 'antragCanBeManualPaused' => $this->p->t( - 'studierendenantrag', - 'error_not_pauseable', - ['id' => $this->input->post('studierendenantrag_id')] - ) - ] - ); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $studierendenantrag_id = $this->input->post('studierendenantrag_id'); - - $result = $this->antraglib->pauseAntrag($studierendenantrag_id, getAuthUID()); - - if (isError($result)) - return $this->outputJsonError(['studierendenantrag_id' => getError($result)]); - - $this->outputJsonSuccess($studierendenantrag_id); - } - - public function unpauseAntrag() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules( - 'studierendenantrag_id', - 'Studierenden Antrag', - [ - 'required', - [ - 'isEntitledToUnpauseAntrag', - [$this->antraglib, 'isEntitledToUnpauseAntrag'] - ], - [ - 'antragCanBeManualUnpaused', - [$this->antraglib, 'antragCanBeManualUnpaused'] - ] - ], - [ - 'isEntitledToUnpauseAntrag' => $this->p->t('studierendenantrag', 'error_no_right'), - 'antragCanBeManualUnpaused' => $this->p->t( - 'studierendenantrag', - 'error_not_paused', - ['id' => $this->input->post('studierendenantrag_id')] - ) - ] - ); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $studierendenantrag_id = $this->input->post('studierendenantrag_id'); - - $result = $this->antraglib->unpauseAntrag($studierendenantrag_id, getAuthUID()); - - if (isError($result)) - return $this->outputJsonError(['studierendenantrag_id' => getError($result)]); - - $this->outputJsonSuccess($studierendenantrag_id); - } - - public function objectAntrag() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules( - 'studierendenantrag_id', - 'Studierenden Antrag', - 'required|callback_isEntitledToObjectAntrag|callback_canBeObjected', - [ - 'isEntitledToObjectAntrag' => $this->p->t('studierendenantrag', 'error_no_right'), - 'canBeObjected' => $this->p->t('studierendenantrag', 'error_no_objection') - ] - ); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $studierendenantrag_id = $this->input->post('studierendenantrag_id'); - - $result = $this->antraglib->objectAbmeldung($studierendenantrag_id, getAuthUID()); - - if (isError($result)) - return $this->outputJsonError(['studierendenantrag_id' => getError($result)]); - - $this->outputJsonSuccess($studierendenantrag_id); - } - - public function objectionDeny() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules( - 'studierendenantrag_id', - 'Studierenden Antrag', - 'required|callback_isEntitledToObjectAntrag|callback_isObjected', - [ - 'isEntitledToObjectAntrag' => $this->p->t('studierendenantrag', 'error_no_right'), - 'isObjected' => $this->p->t('studierendenantrag', 'error_not_objected') - ] - ); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $studierendenantrag_id = $this->input->post('studierendenantrag_id'); - $grund = $this->input->post('grund'); - - $result = $this->antraglib->denyObjectionAbmeldung($studierendenantrag_id, getAuthUID(), $grund); - - if (isError($result)) - return $this->outputJsonError(['studierendenantrag_id' => getError($result)]); - - $this->outputJsonSuccess($studierendenantrag_id); - } - - public function objectionApprove() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules( - 'studierendenantrag_id', - 'Studierenden Antrag', - 'required|callback_isEntitledToObjectAntrag|callback_isObjected', - [ - 'isEntitledToObjectAntrag' => $this->p->t('studierendenantrag', 'error_no_right'), - 'isObjected' => $this->p->t('studierendenantrag', 'error_not_objected') - ] - ); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $studierendenantrag_id = $this->input->post('studierendenantrag_id'); - - $result = $this->antraglib->cancelAntrag($studierendenantrag_id, getAuthUID()); - - if (isError($result)) - return $this->outputJsonError(['studierendenantrag_id' => getError($result)]); - - $this->outputJsonSuccess($studierendenantrag_id); - } - - public function isEntitledToReopenAntrag($studierendenantrag_id) - { - return $this->antraglib->isEntitledToReopenAntrag($studierendenantrag_id); - } - - public function isEntitledToObjectAntrag($studierendenantrag_id) - { - return $this->antraglib->isEntitledToObjectAntrag($studierendenantrag_id); - } - - public function isEntitledToRejectAntrag($studierendenantrag_id) - { - return $this->antraglib->isEntitledToRejectAntrag($studierendenantrag_id); - } - - public function canBeObjected($studierendenantrag_id) - { - return $this->antraglib->hasType($studierendenantrag_id, Studierendenantrag_model::TYP_ABMELDUNG_STGL); - } - - public function isObjected($studierendenantrag_id) - { - return $this->antraglib->hasStatus($studierendenantrag_id, Studierendenantragstatus_model::STATUS_OBJECTED); - } - - - public function approveAbmeldung() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules( - 'studierendenantrag_id', - 'Studierenden Antrag', - 'required|callback_isEntitledToApproveAntrag', - [ - 'isEntitledToApproveAntrag' => $this->p->t('studierendenantrag', 'error_no_right') - ] - ); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $studierendenantrag_id = $this->input->post('studierendenantrag_id'); - - $result = $this->antraglib->approveAbmeldung([$studierendenantrag_id], getAuthUID()); - if (isError($result)) - { - return $this->outputJsonError(['db' => getError($result)]); - } - - return $this->outputJsonSuccess($studierendenantrag_id); - } - - public function approveAbmeldungStgl() - { - return $this->approveAbmeldung(); - } - - public function approveUnterbrechung() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules( - 'studierendenantrag_id', - 'Studierenden Antrag', - 'required|callback_isEntitledToApproveAntrag', - [ - 'isEntitledToApproveAntrag' => $this->p->t('studierendenantrag', 'error_no_right') - ] - ); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $studierendenantrag_id = $this->input->post('studierendenantrag_id'); - - $result = $this->antraglib->approveUnterbrechung([$studierendenantrag_id], getAuthUID()); - if (isError($result)) - { - return $this->outputJsonError(['db' => getError($result)]); - } - - return $this->outputJsonSuccess($studierendenantrag_id); - } - - public function rejectUnterbrechung() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules( - 'studierendenantrag_id', - 'Studierenden Antrag', - 'required|callback_isEntitledToRejectAntrag', - [ - 'isEntitledToRejectAntrag' => $this->p->t('studierendenantrag', 'error_no_right') - ] - ); - $this->form_validation->set_rules('grund', 'Grund', 'required'); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $studierendenantrag_id = $this->input->post('studierendenantrag_id'); - $grund = $this->input->post('grund'); - - $result = $this->antraglib->rejectUnterbrechung([$studierendenantrag_id], getAuthUID(), $grund); - if (isError($result)) - { - return $this->outputJsonError(['db' => getError($result)]); - } - - return $this->outputJsonSuccess($studierendenantrag_id); - } - - public function approveWiederholung() - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules( - 'studierendenantrag_id', - 'Studierenden Antrag', - 'required|callback_isEntitledToApproveAntrag', - [ - 'isEntitledToApproveAntrag' => $this->p->t('studierendenantrag', 'error_no_right') - ] - ); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $studierendenantrag_id = $this->input->post('studierendenantrag_id'); - - $result = $this->antraglib->approveWiederholung($studierendenantrag_id, getAuthUID()); - if (isError($result)) - { - return $this->outputJsonError(['db' => getError($result)]); - } - - return $this->outputJsonSuccess($studierendenantrag_id); - } - - public function isEntitledToApproveAntrag($studierendenantrag_id) - { - return $this->antraglib->isEntitledToApproveAntrag($studierendenantrag_id); - } - - public function getHistory($studierendenantrag_id) - { - if (!$this->antraglib->isEntitledToSeeHistoryForAntrag($studierendenantrag_id)) { - $this->output->set_status_header(403); - return $this->outputJson('Forbidden'); - } - - $result = $this->antraglib->getAntragHistory($studierendenantrag_id); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } - - $this->outputJsonSuccess(getData($result) ?: []); - } -} diff --git a/application/controllers/components/Antrag/Wiederholung.php b/application/controllers/components/Antrag/Wiederholung.php deleted file mode 100644 index 2c672be54..000000000 --- a/application/controllers/components/Antrag/Wiederholung.php +++ /dev/null @@ -1,384 +0,0 @@ -load->config('studierendenantrag'); - - // Libraries - $this->load->library('AuthLib'); - $this->load->library('PermissionLib'); - $this->load->library('AntragLib'); - - $requiredPermissions = [ - 'saveLvs' => ['student/studierendenantrag:w'], - 'getLvsAsRdf' => ['student/studierendenantrag:r', 'student/noten:r'], - 'moveLvsToZeugnis' => ['student/studierendenantrag:w', 'student/noten:w'] - ]; - - if (isset($requiredPermissions[$this->router->method])) { - if (!$this->permissionlib->isEntitled($requiredPermissions, $this->router->method)) { - $this->output->set_status_header(REST_Controller::HTTP_FORBIDDEN); - $this->outputJson('Forbidden'); - exit; - } - } - - // Load language phrases - $this->loadPhrases([ - 'global', - 'studierendenantrag' - ]); - } - - - //------------------------------------------------------------------------------------------------------------------ - // Public methods - - /** - * Retrieves data of the current studiengang for the current user - */ - - public function getDetailsForNewAntrag($prestudent_id) - { - if (!$this->antraglib->isEntitledToCreateAntragFor($prestudent_id, false)) { - $this->output->set_status_header(REST_Controller::HTTP_FORBIDDEN); - return $this->outputJsonError('Forbidden'); - } - $result = $this->antraglib->getPrestudentWiederholungsBerechtigt($prestudent_id); - if (isError($result)) { - $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - return $this->outputJsonError(getError($result)); - } - $result = $result->retval; - if (!$result) { - $this->output->set_status_header(REST_Controller::HTTP_FORBIDDEN); - return $this->outputJsonError($this->p->t('studierendenantrag', 'error_no_student_no_failed_exam')); - } - elseif ($result == -1) - { - $result = $this->antraglib->getDetailsForLastAntrag($prestudent_id, Studierendenantrag_model::TYP_WIEDERHOLUNG); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } - $data = getData($result); - - $result = $this->antraglib->getFailedExamForPrestudent($prestudent_id, $data->datum, $data->studiensemester_kurzbz); - // NOTE(chris): error handling for this function should already happenden in antraglib->getPrestudentWiederholungsBerechtigt() - $pruefungsdata = current(getData($result)); - - $data->studiensemester_kurzbz = $pruefungsdata->studiensemester_kurzbz; - $data->lvbezeichnung = $pruefungsdata->lvbezeichnung; - $data->pruefungsdatum = $pruefungsdata->datum; - - return $this->outputJsonSuccess($data); - } - elseif ($result == -2) - { - $result = $this->antraglib->getDetailsForLastAntrag($prestudent_id); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } - - $result = getData($result); - $this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST); - return $this->outputJsonError($this->p->t('studierendenantrag', 'error_antrag_pending', [ - 'typ' => $this->p->t('studierendenantrag', 'antrag_typ_' . $result->typ) - ])); - } - elseif ($result == -3) - { - $this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST); - return $this->outputJsonError($this->p->t('studierendenantrag', 'error_stg_blacklist')); - } - - $result = $this->antraglib->getDetailsForNewAntrag($prestudent_id); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } - - $data = getData($result); - - $result = $this->antraglib->getFailedExamForPrestudent($prestudent_id); - // NOTE(chris): error handling for this function should already happenden in antraglib->getPrestudentWiederholungsBerechtigt() - $pruefungsdata = current(getData($result)); - - $data->studiensemester_kurzbz = $pruefungsdata->studiensemester_kurzbz; - $data->lvbezeichnung = $pruefungsdata->lvbezeichnung; - $data->pruefungsdatum = $pruefungsdata->datum; - - $this->outputJsonSuccess($data); - } - - public function createAntrag() - { - $this->createAntragWithStatus(true); - } - - public function cancelAntrag() - { - $this->createAntragWithStatus(false); - } - - protected function createAntragWithStatus($repeat) - { - $this->load->library('form_validation'); - - $_POST = json_decode($this->input->raw_input_stream, true); - - $this->form_validation->set_rules('prestudent_id', 'Prestudent ID', 'required'); - $this->form_validation->set_rules('studiensemester', 'Studiensemester', 'required'); - - if ($this->form_validation->run() == false) - { - return $this->outputJsonError($this->form_validation->error_array()); - } - - $prestudent_id = $this->input->post('prestudent_id'); - $studiensemester = $this->input->post('studiensemester'); - - $result = $this->antraglib->getPrestudentWiederholungsBerechtigt($prestudent_id); - if (isError($result)) { - return $this->outputJsonError(['db' => getError($result)]); - } - $result = $result->retval; - if (!$result) - { - return $this->outputJsonError(['db' => $this->p->t('studierendenantrag', 'error_no_student')]); - } - elseif ($result == -1) - { - $result = $this->PrestudentstatusModel->getLastStatus($prestudent_id); - if (isError($result)) - return $this->outputJsonError(['db' => getError($result)]); - if (!hasData($result)) - return $this->outputJsonError(['db' => $this->p->t('studierendenantrag', 'error_no_prestudentstatus', [ - 'prestudent_id' => $prestudent_id - ])]); - if (!in_array(current(getData($result))->status_kurzbz, $this->config->item('antrag_prestudentstatus_whitelist'))) - return $this->outputJsonError(['db' => $this->p->t('studierendenantrag', 'error_no_student')]); - } - elseif ($result == -2) - { - return $this->outputJsonError(['db' => $this->p->t('studierendenantrag', 'error_antrag_exists')]); - } - elseif ($result == -3) - { - return $this->outputJsonError(['db' => $this->p->t('studierendenantrag', 'error_stg_blacklist')]); - } - - $result = $this->antraglib->createWiederholung($prestudent_id, $studiensemester, getAuthUID(), $repeat); - if(isError($result)) - { - return $this->outputJsonError(['db' => getError($result)]); - } - - $antragId = getData($result); - $result = $this->antraglib->getDetailsForAntrag($antragId); - - if(!hasData($result)) - return $this->outputJsonSuccess(true); - - $data = getData($result); - - $result = $this->antraglib->getFailedExamForPrestudent($prestudent_id); - // NOTE(chris): error handling for this function should already happenden in antraglib->getPrestudentWiederholungsBerechtigt() - $pruefungsdata = current(getData($result)); - - $data->studiensemester_kurzbz = $pruefungsdata->studiensemester_kurzbz; - $data->lvbezeichnung = $pruefungsdata->lvbezeichnung; - $data->pruefungsdatum = $pruefungsdata->datum; - - $this->outputJsonSuccess($data); - } - - - public function getLvs($antrag_id) - { - $result = $this->antraglib->getLvsForAntrag($antrag_id); - if (isError($result)) { - $error = getError($result); - if ($error == 'Forbidden') - $this->output->set_status_header(REST_Controller::HTTP_FORBIDDEN); - return $this->outputJsonError(getError($result)); - } - $lvs = getData($result); - - $this->outputJsonSuccess($lvs); - } - - public function saveLvs() - { - $result = $this->getPostJSON(); - $antragsLvs = array_merge($result->forbiddenLvs, $result->mandatoryLvs); - - $insert = array_map(function ($lv) { - return [ - 'studierendenantrag_id' => $lv->studierendenantrag_id, - 'lehrveranstaltung_id' => $lv->lehrveranstaltung_id, - 'note' => $lv->zugelassen - ? ($lv->zugelassen == 1 ? 0 : $this->config->item('wiederholung_note_angerechnet')) - : $this->config->item('wiederholung_note_nicht_zugelassen'), - 'anmerkung' => $lv->anmerkung, - 'insertvon' => getAuthUID(), - 'studiensemester_kurzbz' => $lv->studiensemester_kurzbz - ]; - }, $antragsLvs); - - $antrag_ids = array_unique(array_map(function ($lv) { - return $lv['studierendenantrag_id']; - }, $insert)); - - foreach ($antrag_ids as $antrag_id) { - $result = $this->StudierendenantragModel->loadIdAndStatusWhere([ - 'studierendenantrag_id' => $antrag_id - ]); - if (isError($result)) - return $this->outputJsonError(getError($result)); - if (!hasData($result)) - return $this->outputJsonError($this->p->t('studierendenantrag', 'error_no_antrag_found', ['id' => $antrag_id])); - $antrag = current(getData($result)); - if ($antrag->status != Studierendenantragstatus_model::STATUS_CREATED - && $antrag->status != Studierendenantragstatus_model::STATUS_LVSASSIGNED) - return $this->outputJsonError($this->p->t('studierendenantrag', 'error_antrag_locked')); - } - - if(!$antragsLvs) - return $this->outputJsonError($this->p->t('studierendenantrag', 'error_no_lv')); - - $result = $this->antraglib->saveLvs($insert); - - if (isError($result)) - return $this->outputJsonError(getError($result)); - - $this->outputJsonSuccess(getData($result)); - } - - public function getLvsAsRdf($prestudent_id) - { - // header für no cache - $this->output->set_header("Cache-Control: no-cache"); - $this->output->set_header("Cache-Control: post-check=0, pre-check=0", false); - $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); - $this->output->set_header("Pragma: no-cache"); - $this->output->set_header("Content-type: application/xhtml+xml"); - - $this->load->library('VariableLib', ['uid' => getAuthUID()]); - $sem_akt = $this->variablelib->getVar('semester_aktuell'); - - - $result = $this->antraglib->getLvsForPrestudent($prestudent_id, $sem_akt); - if (isError($result)) { - return $this->outputJsonError(getError($result)); - } - - $lvs = getData($result) ?: []; - $rdf_url = 'http://www.technikum-wien.at/antragnote'; - - $this->load->view('lehre/Antrag/Wiederholung/getLvs.rdf.php', [ - 'url' => $rdf_url, - 'lvs' => $lvs - ]); - } - - public function moveLvsToZeugnis() - { - $anzahl = $this->input->post('anzahl'); - $student_uid = $this->input->post('student_uid'); - $this->load->model('education/Studierendenantraglehrveranstaltung_model', 'StudierendenantraglehrveranstaltungModel'); - $this->load->model('education/Zeugnisnote_model', 'ZeugnisnoteModel'); - - $errormsg = array(); - - for($i=0; $i<$anzahl; $i++) - { - $id = $this->input->post('studierendenantrag_lehrveranstaltung_id_' . $i); - $result =$this->StudierendenantraglehrveranstaltungModel->load($id); - if(isError($result)) - { - $errormsg[] = getError($result); - } - elseif(!hasData($result)) - { - $errormsg[] = $this->p->t('studierendenantrag', 'error_no_lv_in_application'); - } - else - { - $antragLv = getData($result)[0]; - $result= $this->ZeugnisnoteModel->load([ - 'lehrveranstaltung_id'=> $antragLv->lehrveranstaltung_id, - 'student_uid'=> $student_uid, - 'studiensemester_kurzbz' => $antragLv->studiensemester_kurzbz - ]); - if(isError($result)) - { - $errormsg[] = getError($result); - } - else - { - if (hasData($result)) - { - $result = $this->ZeugnisnoteModel->update( - [ - 'lehrveranstaltung_id'=> $antragLv->lehrveranstaltung_id, - 'student_uid'=> $student_uid, - 'studiensemester_kurzbz' => $antragLv->studiensemester_kurzbz - ], - [ - 'note'=> $antragLv->note, - 'uebernahmedatum' => date('c'), - 'benotungsdatum' => $antragLv->insertamum, - 'updateamum' => date('c'), - 'bemerkung'=>$antragLv->anmerkung, - 'updatevon'=>getAuthUID() - ] - ); - } - else - { - $result = $this->ZeugnisnoteModel->insert([ - 'lehrveranstaltung_id'=> $antragLv->lehrveranstaltung_id, - 'student_uid'=> $student_uid, - 'studiensemester_kurzbz' => $antragLv->studiensemester_kurzbz, - 'note'=> $antragLv->note, - 'uebernahmedatum' => date('c'), - 'benotungsdatum' => $antragLv->insertamum, - 'insertamum' => date('c'), - 'bemerkung'=>$antragLv->anmerkung, - 'insertvon'=>getAuthUID() - ]); - } - if(isError($result)) - { - $errormsg[] = getError($result); - } - } - } - } - - if($errormsg) - $return = false; - else - $return = true; - - $this->load->view('lehre/Antrag/Wiederholung/moveLvs.rdf.php', [ - 'return' => $return, - 'errormsg' => $errormsg - ]); - } -} diff --git a/application/libraries/AntragLib.php b/application/libraries/AntragLib.php index 7d1b6a5ac..ce4485279 100644 --- a/application/libraries/AntragLib.php +++ b/application/libraries/AntragLib.php @@ -2058,7 +2058,7 @@ class AntragLib */ public function isEntitledToUnpauseAntrag($antrag_id) { - return $this->hasAccessToAntrag($antrag_id, 'student/studierendenantrag'); + return ($this->hasAccessToAntrag($antrag_id, 'student/antragfreigabe') || $this->hasAccessToAntrag($antrag_id, 'student/studierendenantrag')); } /** diff --git a/application/views/lehre/Antrag/Create.php b/application/views/lehre/Antrag/Create.php index f0b681c2a..91b20c9b7 100644 --- a/application/views/lehre/Antrag/Create.php +++ b/application/views/lehre/Antrag/Create.php @@ -11,6 +11,7 @@ $sitesettings = array( 'customJSModules' => array('public/js/apps/lehre/Antrag.js'), 'customCSSs' => array( 'public/css/Fhc.css', + 'public/css/components/primevue.css', 'vendor/vuejs/vuedatepicker_css/main.css' ), 'customJSs' => array( diff --git a/application/views/lehre/Antrag/Leitung/List.php b/application/views/lehre/Antrag/Leitung/List.php index 9c0749dae..1225b16b6 100644 --- a/application/views/lehre/Antrag/Leitung/List.php +++ b/application/views/lehre/Antrag/Leitung/List.php @@ -20,7 +20,8 @@ $sitesettings = array( ), 'customJSModules' => array('public/js/apps/lehre/Antrag/Leitung.js'), 'customCSSs' => array( - 'public/css/Fhc.css' + 'public/css/Fhc.css', + 'public/css/components/primevue.css', ), 'customJSs' => array( ) diff --git a/application/views/lehre/Antrag/Student/List.php b/application/views/lehre/Antrag/Student/List.php index 55e7ec5df..614af5d79 100644 --- a/application/views/lehre/Antrag/Student/List.php +++ b/application/views/lehre/Antrag/Student/List.php @@ -10,7 +10,8 @@ $sitesettings = array( ), 'customJSModules' => array('public/js/apps/lehre/Antrag/Student.js'), 'customCSSs' => array( - 'public/css/Fhc.css' + 'public/css/Fhc.css', + 'public/css/components/primevue.css', ), 'customJSs' => array( ) diff --git a/application/views/lehre/Antrag/Wiederholung/Student.php b/application/views/lehre/Antrag/Wiederholung/Student.php index 9c2db040e..2171d6928 100644 --- a/application/views/lehre/Antrag/Wiederholung/Student.php +++ b/application/views/lehre/Antrag/Wiederholung/Student.php @@ -14,6 +14,8 @@ $sitesettings = array( ), 'customJSModules' => array('public/js/apps/lehre/Antrag/Lvzuweisung.js'), 'customCSSs' => array( + 'public/css/Fhc.css', + 'public/css/components/primevue.css', ), 'customJSs' => array( ) @@ -30,7 +32,7 @@ $this->load->view(

p->t('studierendenantrag', 'title_lvzuweisen', ['name' => $antrag->name]);?>

- status != Studierendenantragstatus_model::STATUS_CREATED && $antrag->status != Studierendenantragstatus_model::STATUS_LVSASSIGNED) ? ' disabled' : ''; ?>> + status != Studierendenantragstatus_model::STATUS_CREATED && $antrag->status != Studierendenantragstatus_model::STATUS_LVSASSIGNED) ? ' disabled' : ''; ?>>
diff --git a/content/student/studentoverlay.js.php b/content/student/studentoverlay.js.php index 11a4d862f..8be20d32d 100644 --- a/content/student/studentoverlay.js.php +++ b/content/student/studentoverlay.js.php @@ -1658,7 +1658,7 @@ function StudentAuswahl() var antragnotentree = document.getElementById('student-antragnoten-tree'); - url='index.ci.php/components/Antrag/Wiederholung/getLvsAsRdf/'+prestudent_id+"?"+gettimestamp(); + url='index.ci.php/api/frontend/fas/studstatus/Wiederholung/getLvs/'+prestudent_id+"?"+gettimestamp(); try { @@ -4764,7 +4764,7 @@ function StudentNotenMoveFromAntrag() var paramList= ''; var i = 0; - var url = 'index.ci.php/components/Antrag/Wiederholung/moveLvsToZeugnis'; + var url = 'index.ci.php/api/frontend/fas/studstatus/Wiederholung/moveLvsToZeugnis'; var req = new phpRequest(url,'',''); for (var t = 0; t < numRanges; t++) diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js index 08deb26b3..41c89ef50 100644 --- a/public/js/api/fhcapifactory.js +++ b/public/js/api/fhcapifactory.js @@ -19,10 +19,12 @@ import search from "./search.js"; import phrasen from "./phrasen.js"; import navigation from "./navigation.js"; import filter from "./filter.js"; +import studstatus from "./studstatus.js"; export default { search, phrasen, navigation, - filter + filter, + studstatus }; diff --git a/public/js/api/studstatus.js b/public/js/api/studstatus.js new file mode 100644 index 000000000..d0fc4b074 --- /dev/null +++ b/public/js/api/studstatus.js @@ -0,0 +1,220 @@ +/** + * 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 . + */ + +export default { + abmeldung: { + getDetails(antrag_id, prestudent_id) { + const url = '/api/frontend/v1/studstatus/abmeldung/' + + (antrag_id !== undefined ? 'getDetailsForAntrag/' + antrag_id : 'getDetailsForNewAntrag/' + prestudent_id); + return this.$fhcApi.get(url); + }, + create(stdsem, prestudent_id, grund) { + return this.$fhcApi.post('/api/frontend/v1/studstatus/abmeldung/createAntrag', { + studiensemester: stdsem, + prestudent_id, + grund + }, { + errorHandling: 'strict' + }); + }, + cancel(antrag_id) { + if (!Array.isArray(antrag_id)) + return this.$fhcApi.post( + '/api/frontend/v1/studstatus/abmeldung/cancelAntrag', + { antrag_id } + ); + return Promise.allSettled(antrag_id.map(antrag => this.$fhcApi.post( + '/api/frontend/v1/studstatus/abmeldung/cancelAntrag', + { antrag_id: antrag.studierendenantrag_id }, + { errorHeader: '#' + antrag.studierendenantrag_id } + ))); + } + }, + unterbrechung: { + getDetails(antrag_id, prestudent_id) { + const url = '/api/frontend/v1/studstatus/unterbrechung/' + + (antrag_id !== undefined ? 'getDetailsForAntrag/' + antrag_id : 'getDetailsForNewAntrag/' + prestudent_id); + return this.$fhcApi.get(url); + }, + create(studiensemester, prestudent_id, grund, datum_wiedereinstieg, attachment) { + return this.$fhcApi.post('/api/frontend/v1/studstatus/unterbrechung/createAntrag', { + studiensemester, + prestudent_id, + grund, + datum_wiedereinstieg, + attachment + }, { + errorHandling: 'strict' + }); + }, + cancel(antrag_id) { + return this.$fhcApi.post('/api/frontend/v1/studstatus/unterbrechung/cancelAntrag', { + antrag_id + }, { + errorHandling: 'strict' + }); + } + }, + wiederholung: { + getDetails(prestudent_id) { + const url = '/api/frontend/v1/studstatus/wiederholung/getDetailsForNewAntrag/' + prestudent_id; + return this.$fhcApi.get(url) + }, + getLvs(antrag_id) { + const url = '/api/frontend/v1/studstatus/wiederholung/getLvs/' + antrag_id; + return this.$fhcApi.get(url) + }, + create(prestudent_id, studiensemester) { + return this.$fhcApi.post('/api/frontend/v1/studstatus/wiederholung/createAntrag', { + prestudent_id, + studiensemester + }, { + errorHandling: 'strict' + }); + }, + cancel(prestudent_id, studiensemester) { + return this.$fhcApi.post('/api/frontend/v1/studstatus/wiederholung/cancelAntrag', { + prestudent_id, + studiensemester + }, { + errorHandling: 'strict' + }); + }, + saveLvs(forbiddenLvs, mandatoryLvs) { + return this.$fhcApi.post('/api/frontend/v1/studstatus/wiederholung/saveLvs', { + forbiddenLvs, + mandatoryLvs + }); + } + }, + leitung: { + getStgs() { + return this.$fhcApi.get('/api/frontend/v1/studstatus/leitung/getActiveStgs'); + }, + getAntraege(url, config, params) { + return this.$fhcApi + .get('/api/frontend/v1/studstatus/leitung/getAntraege/' + url) + .then(res => res.data); // Return data for tabulator + }, + getHistory(antrag_id) { + return this.$fhcApi.get('/api/frontend/v1/studstatus/leitung/getHistory/' + antrag_id) + }, + getPrestudents(query, signal) { + return this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/getPrestudents', + { query }, + { signal } + ); + }, + approve(antrag) { + if (!Array.isArray(antrag)) + return this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/approveAntrag', + antrag + ); + return Promise.allSettled(antrag.map(a => this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/approveAntrag', + a, + { errorHeader: '#' + a.studierendenantrag_id } + ))); + }, + reject(antrag) { + if (!Array.isArray(antrag)) + return this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/rejectAntrag', + antrag + ); + return Promise.allSettled(antrag.map(a => this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/rejectAntrag', + a, + { errorHeader: '#' + a.studierendenantrag_id } + ))); + }, + reopen(antrag) { + if (!Array.isArray(antrag)) + return this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/reopenAntrag', + antrag + ); + return Promise.allSettled(antrag.map(a => this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/reopenAntrag', + a, + { errorHeader: '#' + a.studierendenantrag_id } + ))); + }, + pause(antrag) { + if (!Array.isArray(antrag)) + return this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/pauseAntrag', + antrag + ); + return Promise.allSettled(antrag.map(a => this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/pauseAntrag', + a, + { errorHeader: '#' + a.studierendenantrag_id } + ))); + }, + unpause(antrag) { + if (!Array.isArray(antrag)) + return this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/unpauseAntrag', + antrag + ); + return Promise.allSettled(antrag.map(a => this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/unpauseAntrag', + a, + { errorHeader: '#' + a.studierendenantrag_id } + ))); + }, + object(antrag) { + if (!Array.isArray(antrag)) + return this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/objectAntrag', + antrag + ); + return Promise.allSettled(antrag.map(a => this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/objectAntrag', + a, + { errorHeader: '#' + a.studierendenantrag_id } + ))); + }, + approveObjection(antrag) { + if (!Array.isArray(antrag)) + return this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/approveObjection', + antrag + ); + return Promise.allSettled(antrag.map(a => this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/approveObjection', + a, + { errorHeader: '#' + a.studierendenantrag_id } + ))); + }, + denyObjection(antrag) { + if (!Array.isArray(antrag)) + return this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/denyObjection', + antrag + ); + return Promise.allSettled(antrag.map(a => this.$fhcApi.post( + '/api/frontend/v1/studstatus/leitung/denyObjection', + a, + { errorHeader: '#' + a.studierendenantrag_id } + ))); + } + } +}; \ No newline at end of file diff --git a/public/js/apps/lehre/Antrag.js b/public/js/apps/lehre/Antrag.js index 00a5877b3..d0c8ab89a 100644 --- a/public/js/apps/lehre/Antrag.js +++ b/public/js/apps/lehre/Antrag.js @@ -1,12 +1,10 @@ import StudierendenantragAntrag from "../../components/Studierendenantrag/Antrag.js"; import StudierendenantragStatus from "../../components/Studierendenantrag/Status.js"; import StudierendenantragInfoblock from "../../components/Studierendenantrag/Infoblock.js"; -import VueDatePicker from "../../components/vueDatepicker.js.php"; import Phrasen from '../../plugin/Phrasen.js'; const app = Vue.createApp({ components: { - VueDatePicker, StudierendenantragAntrag, StudierendenantragStatus, StudierendenantragInfoblock diff --git a/public/js/components/Studierendenantrag/Form/Abmeldung.js b/public/js/components/Studierendenantrag/Form/Abmeldung.js index d72f84265..e6e649e11 100644 --- a/public/js/components/Studierendenantrag/Form/Abmeldung.js +++ b/public/js/components/Studierendenantrag/Form/Abmeldung.js @@ -1,10 +1,16 @@ import {CoreFetchCmpt} from '../../Fetch.js'; +import CoreForm from '../../Form/Form.js'; +import FormValidation from '../../Form/Validation.js'; +import FormInput from '../../Form/Input.js'; var _uuid = 0; export default { components: { - CoreFetchCmpt + CoreFetchCmpt, + CoreForm, + FormValidation, + FormInput }, emits: [ 'setInfos', @@ -18,9 +24,8 @@ export default { return { data: null, saving: false, - errors: { - grund: [], - default: [] + formData: { + grund: '' } } }, @@ -34,24 +39,14 @@ export default { case 'Genehmigt': return 'success'; default: return 'warning'; } - }, - loadUrl() { - if (this.studierendenantragId) - return '/components/Antrag/Abmeldung/getDetailsForAntrag/'+ - this.studierendenantragId; - return '/components/Antrag/Abmeldung/getDetailsForNewAntrag/' + - this.prestudentId; } }, methods: { load() { - return axios.get( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - this.loadUrl - ).then( - result => { - this.data = result.data.retval; + return this.$fhcApi.factory + .studstatus.abmeldung.getDetails(this.studierendenantragId, this.prestudentId) + .then(result => { + this.data = result.data; if (this.data.status) { const msg = (this.data.status == 'Pause' && this.data.status_insertvon == "Studienabbruch") ? Vue.computed(() => { let status = this.$p.t('studierendenantrag/status_stop'); @@ -63,8 +58,7 @@ export default { }); } return result; - } - ); + }); }, createAntrag() { bootstrap.Modal.getOrCreateInstance(this.$refs.modal).hide(); @@ -73,52 +67,39 @@ export default { severity: 'warning' }); this.saving = true; - for(var k in this.errors) - this.errors[k] = []; - axios.post( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - '/components/Antrag/Abmeldung/createAntrag/', { - studiensemester: this.data.studiensemester_kurzbz, - prestudent_id: this.data.prestudent_id, - grund: this.$refs.grund.value - } - ).then( - result => { - if (result.data.error) - { - for (var k in result.data.retval) - { - if (this.errors[k] !== undefined) - this.errors[k].push(result.data.retval[k]); - else - this.errors.default.push(result.data.retval[k]); - } - this.$emit('setStatus', { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), - severity: 'danger' + + this.$refs.form.clearValidation(); + this.$refs.form.factory + .studstatus.abmeldung.create( + this.data.studiensemester_kurzbz, + this.data.prestudent_id, + this.formData.grund + ) + .then(result => { + if (result.data === true) + document.location += ""; + + this.data = result.data; + if (this.data.status) + this.$emit("setStatus", { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), + severity: this.statusSeverity }); - } else - { - if (result.data.retval === true) - document.location += ""; - this.data = result.data.retval; - if (this.data.status) { - this.$emit("setStatus", { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), - severity: this.statusSeverity - }); - } - else - this.$emit('setStatus', { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_open')})), - severity:'success' - }); - } + this.$emit('setStatus', { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_open')})), + severity:'success' + }); this.saving = false; - } - ); + }) + .catch(error => { + this.$emit('setStatus', { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), + severity: 'danger' + }); + this.saving = false; + this.$fhcAlert.handleSystemError(error); + }); }, cancelAntrag() { this.$emit('setStatus', { @@ -126,51 +107,37 @@ export default { severity: 'warning' }); this.saving = true; - for(var k in this.errors) - this.errors[k] = []; - axios.post( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - '/components/Antrag/Abmeldung/cancelAntrag/', { - antrag_id: this.data.studierendenantrag_id - } - ).then( - result => { - if (result.data.error) - { - for (var k in result.data.retval) - { - if (this.errors[k] !== undefined) - this.errors[k].push(result.data.retval[k]); - else - this.errors.default.push(result.data.retval[k]); - } - this.$emit('setStatus', { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), - severity:'danger' + + this.$refs.form.clearValidation(); + this.$refs.form.factory + .studstatus.abmeldung.cancel( + this.data.studierendenantrag_id + ) + .then(result => { + if (Number.isInteger(result.data)) + document.location = document.location.replace(/abmeldung\/([0-9]*)\/[0-9]*[\/]?$/, 'abmeldung/$1') + "/" + result.data; + + this.data = result.data; + if (this.data.status) + this.$emit("setStatus", { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), + severity: this.statusSeverity }); - } else - { - if (Number.isInteger(result.data.retval)) { - document.location = document.location.replace(/abmeldung\/([0-9]*)\/[0-9]*[\/]?$/, 'abmeldung/$1') + "/" + result.data.retval; - } - this.data = result.data.retval; - if (this.data.status) { - this.$emit("setStatus", { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), - severity: this.statusSeverity - }); - } - else - this.$emit('setStatus', { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_cancelled')})), - severity: 'danger' - }); - } + this.$emit('setStatus', { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_cancelled')})), + severity: 'danger' + }); this.saving = false; - } - ); + }) + .catch(error => { + this.$emit('setStatus', { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), + severity: 'danger' + }); + this.saving = false; + this.$fhcAlert.handleSystemError(error); + }); } }, created() { @@ -179,10 +146,9 @@ export default { template: `
-
+
- + @@ -219,19 +185,16 @@ export default {
{{data.grund}}
- - -
- {{errors.grund.join(".")}} -
+ > +
- + + - - ` + ` } diff --git a/public/js/components/Studierendenantrag/Form/AbmeldungStgl.js b/public/js/components/Studierendenantrag/Form/AbmeldungStgl.js index 7e8cd01fc..004f6f4d0 100644 --- a/public/js/components/Studierendenantrag/Form/AbmeldungStgl.js +++ b/public/js/components/Studierendenantrag/Form/AbmeldungStgl.js @@ -1,10 +1,16 @@ import {CoreFetchCmpt} from '../../Fetch.js'; +import CoreForm from '../../Form/Form.js'; +import FormValidation from '../../Form/Validation.js'; +import FormInput from '../../Form/Input.js'; var _uuid = 0; export default { components: { - CoreFetchCmpt + CoreFetchCmpt, + CoreForm, + FormValidation, + FormInput }, emits: [ 'setInfos', @@ -18,9 +24,8 @@ export default { return { data: null, saving: false, - errors: { - grund: [], - default: [] + formData: { + grund: '' } } }, @@ -35,24 +40,14 @@ export default { case 'Abgemeldet': return 'success'; default: return 'warning'; } - }, - loadUrl() { - if (this.studierendenantragId) - return '/components/Antrag/Abmeldung/getDetailsForAntrag/'+ - this.studierendenantragId; - return '/components/Antrag/Abmeldung/getDetailsForNewAntrag/' + - this.prestudentId; } }, methods: { load() { - return axios.get( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - this.loadUrl - ).then( - result => { - this.data = result.data.retval; + return this.$fhcApi.factory + .studstatus.abmeldung.getDetails(this.studierendenantragId, this.prestudentId) + .then(result => { + this.data = result.data; if (this.data.status) { const msg = (this.data.status == 'Pause' && this.data.status_insertvon == "Studienabbruch") ? Vue.computed(() => { let status = this.$p.t('studierendenantrag/status_stop'); @@ -64,8 +59,7 @@ export default { }); } return result; - } - ); + }); }, createAntrag() { bootstrap.Modal.getOrCreateInstance(this.$refs.modal).hide(); @@ -74,63 +68,44 @@ export default { severity: 'warning' }); this.saving = true; - for(var k in this.errors) - this.errors[k] = []; - axios.post( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - '/components/Antrag/Abmeldung/createAntrag/', { - studiensemester: this.data.studiensemester_kurzbz, - prestudent_id: this.data.prestudent_id, - grund: this.$refs.grund.value - } - ).then( - result => { - if (result.data.error) - { - for (var k in result.data.retval) - { - if (this.errors[k] !== undefined) - this.errors[k].push(result.data.retval[k]); - else - this.errors.default.push(result.data.retval[k]); - } - this.$emit('setStatus', { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), - severity: 'danger' - }); - } - else - { - if (result.data.retval === true) - document.location += ""; - this.data = result.data.retval; - if (this.data.status) { - this.$emit("setStatus", { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), - severity: this.statusSeverity - }); - } - else - this.$emit('setStatus', { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_open')})), - severity:'success' - }); - } - this.saving = false; - } - ); - }, - appendDropDownText(event){ - let templateText = this.$refs.grund; - if(event.target.value) - { - let templateT= this.$p.t('studierendenantrag', event.target.value); - templateText.value = templateT; - } - else - templateText.value = ''; + this.$refs.form.clearValidation(); + this.$refs.form.factory + .studstatus.abmeldung.create( + this.data.studiensemester_kurzbz, + this.data.prestudent_id, + this.formData.grund + ) + .then(result => { + if (result.data === true) + document.location += ""; + + this.data = result.data; + if (this.data.status) + this.$emit("setStatus", { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), + severity: this.statusSeverity + }); + else + this.$emit('setStatus', { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_open')})), + severity:'success' + }); + this.saving = false; + }) + .catch(error => { + this.$emit('setStatus', { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), + severity: 'danger' + }); + this.saving = false; + this.$fhcAlert.handleSystemError(error); + }); + }, + appendDropDownText(event) { + this.formData.grund = event.target.value + ? this.$p.t('studierendenantrag', event.target.value) + : ''; }, }, created() { @@ -139,8 +114,9 @@ export default { template: `
-
+
+
{{$p.t('lehre', 'studiengang')}}
@@ -181,8 +157,7 @@ export default {
- @@ -199,19 +174,17 @@ export default { -
- -
- {{errors.grund.join(".")}} -
+ > +
@@ -257,7 +230,7 @@ export default {
- + - - ` + ` } diff --git a/public/js/components/Studierendenantrag/Form/Unterbrechung.js b/public/js/components/Studierendenantrag/Form/Unterbrechung.js index a2058b5bf..a58cf5e77 100644 --- a/public/js/components/Studierendenantrag/Form/Unterbrechung.js +++ b/public/js/components/Studierendenantrag/Form/Unterbrechung.js @@ -1,12 +1,15 @@ import {CoreFetchCmpt} from '../../Fetch.js'; -import VueDatepicker from '../../vueDatepicker.js.php'; +import CoreForm from '../../Form/Form.js'; +import FormValidation from '../../Form/Validation.js'; +import FormInput from '../../Form/Input.js'; -var _uuid = 0; export default { components: { CoreFetchCmpt, - VueDatepicker + CoreForm, + FormValidation, + FormInput }, emits: [ 'setInfos', @@ -20,12 +23,7 @@ export default { return { data: null, saving: false, - errors: { - grund: [], - studiensemester: [], - datum_wiedereinstieg: [], - default: [] - }, + attachment: [], stsem: null, currentWiedereinstieg: '', siteUrl: FHC_JS_DATA_STORAGE_OBJECT.app_root + @@ -45,13 +43,6 @@ export default { default: return 'warning'; } }, - loadUrl() { - if (this.studierendenantragId) - return '/components/Antrag/Unterbrechung/getDetailsForAntrag/'+ - this.studierendenantragId; - return '/components/Antrag/Unterbrechung/getDetailsForNewAntrag/' + - this.prestudentId; - }, datumWsFormatted() { let datumUnformatted = ''; @@ -81,26 +72,24 @@ export default { }, methods: { load() { - return axios.get( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - this.loadUrl - ).then( - result => { - this.data = result.data.retval; - if (this.data.status) { - const msg = (this.data.status == 'Pause' && this.data.status_insertvon == "Studienabbruch") ? Vue.computed(() => { - let status = this.$p.t('studierendenantrag/status_stop'); - return this.$p.t('studierendenantrag', 'status_x', {status}); - }) : Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})); - this.$emit("setStatus", { - msg, - severity: this.statusSeverity - }); + return this.$fhcApi.factory + .studstatus.unterbrechung.getDetails(this.studierendenantragId, this.prestudentId) + .then( + result => { + this.data = result.data; + if (this.data.status) { + const msg = (this.data.status == 'Pause' && this.data.status_insertvon == "Studienabbruch") ? Vue.computed(() => { + let status = this.$p.t('studierendenantrag/status_stop'); + return this.$p.t('studierendenantrag', 'status_x', {status}); + }) : Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})); + this.$emit("setStatus", { + msg, + severity: this.statusSeverity + }); + } + return result; } - return result; - } - ); + ); }, createAntrag() { this.$emit('setStatus', { @@ -108,63 +97,41 @@ export default { severity: 'warning' }); this.saving = true; - for(var k in this.errors) - this.errors[k] = []; - var formData = new FormData(); - var attachment = this.$refs.attachment; - formData.append("attachment", attachment.files[0]); - formData.append("studiensemester", this.stsem !== null && this.data.studiensemester[this.stsem].studiensemester_kurzbz); - formData.append("prestudent_id", this.data.prestudent_id); - formData.append("grund", this.$refs.grund.value); - formData.append("datum_wiedereinstieg", this.stsem !== null && this.currentWiedereinstieg); + this.$refs.form.clearValidation(); + this.$refs.form.factory + .studstatus.unterbrechung.create( + this.stsem !== null && this.data.studiensemester[this.stsem].studiensemester_kurzbz, + this.data.prestudent_id, + this.data.grund, + this.stsem !== null && this.currentWiedereinstieg, + this.attachment + ) + .then(result => { + if (Number.isInteger(result.data)) + document.location += "/" + result.data; - axios.post( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - '/components/Antrag/Unterbrechung/createAntrag/', - formData, - { - headers: { - 'Content-Type': 'multipart/form-data' - } - } - ).then( - result => { - if (result.data.error) - { - for (var k in result.data.retval) - { - if (this.errors[k] !== undefined) - this.errors[k].push(result.data.retval[k]); - else - this.errors.default.push(result.data.retval[k]); - } - this.$emit('setStatus', { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), - severity: 'danger' + this.data = result.data; + if (this.data.status) + this.$emit("setStatus", { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), + severity: this.statusSeverity }); - } else - { - if (Number.isInteger(result.data.retval)) - document.location += "/" + result.data.retval; - this.data = result.data.retval; - if (this.data.status) { - this.$emit("setStatus", { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), - severity: this.statusSeverity - }); - } - else - this.$emit('setStatus', { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_created')})), - severity: 'info' - }); - } + this.$emit('setStatus', { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_created')})), + severity: 'info' + }); this.saving = false; - } - ); + }) + .catch(error => { + this.$emit('setStatus', { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), + severity: 'danger' + }); + this.saving = false; + this.$fhcAlert.handleSystemError(error); + }); }, cancelAntrag() { this.$emit('setStatus', { @@ -172,63 +139,45 @@ export default { severity: 'warning' }); this.saving = true; - for(var k in this.errors) - this.errors[k] = []; - axios.post( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - '/components/Antrag/Unterbrechung/cancelAntrag/', { - antrag_id: this.data.studierendenantrag_id - } - ).then( - result => { - if (result.data.error) - { - for (var k in result.data.retval) - { - if (this.errors[k] !== undefined) - this.errors[k].push(result.data.retval[k]); - else - this.errors.default.push(result.data.retval[k]); - } + + this.$refs.form.clearValidation(); + this.$refs.form.factory + .studstatus.unterbrechung.cancel( + this.data.studierendenantrag_id + ) + .then(result => { + if (Number.isInteger(result.data)) + document.location = document.location.replace(/unterbrechung\/([0-9]*)\/[0-9]*[\/]?$/, 'unterbrechung/$1') + "/" + result.data; + + this.data = result.data; + if (this.data.status) + this.$emit("setStatus", { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), + severity: this.statusSeverity + }); + else this.$emit('setStatus', { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_cancelled')})), severity: 'danger' }); - } - else - { - if (Number.isInteger(result.data.retval)) { - document.location = document.location.replace(/unterbrechung\/([0-9]*)\/[0-9]*[\/]?$/, 'unterbrechung/$1') + "/" + result.data.retval; - } - this.data = result.data.retval; - if (this.data.status) { - this.$emit("setStatus", { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), - severity: this.statusSeverity - }); - } - else - this.$emit('setStatus', { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_cancelled')})), - severity: 'danger' - }); - } this.saving = false; - } - ); + }) + .catch(error => { + this.$emit('setStatus', { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), + severity: 'danger' + }); + this.saving = false; + this.$fhcAlert.handleSystemError(error); + }); } }, - created() { - this.uuid = _uuid++; - }, template: `
-
+
- +
{{$p.t('lehre', 'studiengang')}}
@@ -260,93 +209,99 @@ export default {
-
- {{data.studiensemester_kurzbz}} -
-
- -
- {{errors.studiensemester.join(".")}} + +
+ {{data.studiensemester_kurzbz}}
+ + +
- -
- {{datumWsFormatted}} -
-
- -
-
- -
- -
- {{errors.datum_wiedereinstieg.join(".")}} + +
+ {{datumWsFormatted}} +
+ + + + + +
-
-
{{$p.t('studierendenantrag', 'antrag_grund')}}:
- -
-
- - -
- {{errors.grund.join(".")}} -
+ > +
-
{{$p.t('studierendenantrag', 'antrag_dateianhaenge')}} {{$p.t('studierendenantrag', 'no_attachments')}}
-
- - -
+ +
-
+ - - ` + ` } diff --git a/public/js/components/Studierendenantrag/Form/Wiederholung.js b/public/js/components/Studierendenantrag/Form/Wiederholung.js index eca1dba94..a899d242c 100644 --- a/public/js/components/Studierendenantrag/Form/Wiederholung.js +++ b/public/js/components/Studierendenantrag/Form/Wiederholung.js @@ -1,12 +1,13 @@ import {CoreFetchCmpt} from '../../Fetch.js'; -import VueDatepicker from '../../vueDatepicker.js.php'; +import CoreForm from '../../Form/Form.js'; +import FormValidation from '../../Form/Validation.js'; -var _uuid = 0; export default { components: { CoreFetchCmpt, - VueDatepicker + CoreForm, + FormValidation }, emits: [ 'setInfos', @@ -22,12 +23,6 @@ export default { return { data: null, saving: false, - errors: { - grund: [], - default: [] - }, - siteUrl: FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router, infos: [] } }, @@ -45,10 +40,6 @@ export default { default: return 'warning'; } }, - loadUrl() { - return '/components/Antrag/Wiederholung/getDetailsForNewAntrag/' + - this.prestudentId; - }, datumPruefungFormatted() { if(!this.data.pruefungsdatum) return ''; @@ -58,13 +49,12 @@ export default { }, methods: { load() { - return axios.get( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - this.loadUrl - ).then( - result => { - this.data = result.data.retval; + return this.$fhcApi.factory + .studstatus.wiederholung.getDetails( + this.prestudentId + ) + .then(result => { + this.data = result.data; if (!this.data.status || this.data.status == 'ErsteAufforderungVersandt' || this.data.status == 'ZweiteAufforderungVersandt') { this.data.status = 'Offen'; this.data.statustyp = this.$p.t('studierendenantrag', 'status_open'); @@ -79,8 +69,7 @@ export default { severity: this.statusSeverity }); return result; - } - ); + }); }, createAntrag() { this.createAntragWithStatus(true); @@ -89,7 +78,7 @@ export default { this.createAntragWithStatus(false); }, createAntragWithStatus(repeat) { - let func = repeat ? 'createAntrag' : 'cancelAntrag'; + let func = repeat ? 'create' : 'cancel'; let nextState = repeat ? 'Erstellt' : 'Verzichtet'; this.$emit('setStatus', { @@ -97,54 +86,36 @@ export default { severity: 'warning' }); this.saving = true; - for(var k in this.errors) - this.errors[k] = []; - axios.post( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - '/components/Antrag/Wiederholung/' + func + '/', - { - prestudent_id: this.data.prestudent_id, - studiensemester: this.data.studiensemester_kurzbz - } - ).then( - result => { - if (result.data.error) - { - for (var k in result.data.retval) - { - if (this.errors[k] !== undefined) - this.errors[k].push(result.data.retval[k]); - else - this.errors.default.push(result.data.retval[k]); - } - this.$emit('setStatus', { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), - severity: 'danger' - }); - } - else - { - if (result.data.retval === true) - document.location += ""; - this.data = result.data.retval; - if (!this.data.status) - this.data.status = nextState; - this.$emit('update:status', this.data.status); - this.$emit("setStatus", { - msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), - severity: this.statusSeverity - }); - } + this.$refs.form.factory + .studstatus.wiederholung[func]( + this.data.prestudent_id, + this.data.studiensemester_kurzbz + ) + .then(result => { + if (result.data === true) + document.location += ""; + + this.data = result.data; + if (!this.data.status) + this.data.status = nextState; + this.$emit('update:status', this.data.status); + this.$emit("setStatus", { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.data.statustyp})), + severity: this.statusSeverity + }); this.saving = false; - } - ); + }) + .catch(error => { + this.$emit('setStatus', { + msg: Vue.computed(() => this.$p.t('studierendenantrag', 'status_x', {status: this.$p.t('studierendenantrag', 'status_error')})), + severity: 'danger' + }); + this.saving = false; + this.$fhcAlert.handleSystemError(error); + }); } }, - created() { - this.uuid = _uuid++; - }, mounted() { this.infos = [...Array(5).keys()].map(n => ({ body: Vue.computed(() => this.$p.t('studierendenantrag', 'infotext_Wiederholung_' + n)) @@ -154,10 +125,9 @@ export default { template: `
-
+
- +
{{$p.t('lehre', 'studiengang')}}
@@ -206,7 +176,7 @@ export default { {{$p.t('studierendenantrag/antrag_Wiederholung_button_no')}} --> - +
{{$p.t('lehre', 'studiengang')}}