mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-18 07:22:17 +00:00
Replace CoreRESTClient calls with $api calls in stv Studiensemester component and add logic to accept lowercase input (because it could come from the url)
This commit is contained in:
@@ -26,7 +26,9 @@ class Studiensemester extends FHCAPI_Controller
|
||||
'getAll' => self::PERM_LOGGED,
|
||||
'getAktNext' => self::PERM_LOGGED,
|
||||
'getStudienjahrByStudiensemester' => self::PERM_LOGGED,
|
||||
'getAllStudiensemesterAndAktOrNext' => self::PERM_LOGGED
|
||||
'getAllStudiensemesterAndAktOrNext' => self::PERM_LOGGED,
|
||||
'current' => self::PERM_LOGGED,
|
||||
'set' => self::PERM_LOGGED
|
||||
)
|
||||
);
|
||||
// Load model StudiensemesterModel
|
||||
@@ -166,4 +168,39 @@ class Studiensemester extends FHCAPI_Controller
|
||||
|
||||
$this->terminateWithSuccess(array($studiensemester, $aktuell));
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
$result = $this->StudiensemesterModel->getNearest();
|
||||
|
||||
$data = $this->getDataOrTerminateWithError($result);
|
||||
|
||||
if (!$data)
|
||||
$this->terminateWithError('Kein Studiensemester aktiv');
|
||||
if (count($data) > 1)
|
||||
$this->terminateWithError('Mehrere Studiensemester aktiv');
|
||||
|
||||
$this->terminateWithSuccess(current($data)->studiensemester_kurzbz);
|
||||
}
|
||||
|
||||
public function set()
|
||||
{
|
||||
$this->load->library('AuthLib');
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$this->form_validation->set_rules('studiensemester_kurzbz', 'Studiensemester', 'required');
|
||||
|
||||
if (!$this->form_validation->run())
|
||||
$this->terminateWithValidationErrors($this->form_validation->error_array());
|
||||
|
||||
$stdsem = $this->input->post('studiensemester_kurzbz');
|
||||
|
||||
$this->load->model('system/Variable_model', 'VariableModel');
|
||||
|
||||
$result = $this->VariableModel->setVariable(getAuthUID(), 'semester_aktuell', $stdsem);
|
||||
|
||||
$this->getDataOrTerminateWithError($result);
|
||||
|
||||
$this->terminateWithSuccess(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Studiensemester extends Auth_Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// TODO(chris): access!
|
||||
parent::__construct([
|
||||
'index' => self::PERM_LOGGED,
|
||||
'now' => self::PERM_LOGGED,
|
||||
'set' => self::PERM_LOGGED
|
||||
]);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel');
|
||||
|
||||
$this->StudiensemesterModel->addOrder('start');
|
||||
|
||||
$result = $this->StudiensemesterModel->load();
|
||||
|
||||
if (isError($result)) {
|
||||
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
$this->outputJson($result);
|
||||
}
|
||||
|
||||
public function now()
|
||||
{
|
||||
$this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel');
|
||||
|
||||
$result = $this->StudiensemesterModel->getNearest();
|
||||
|
||||
if (isError($result)) {
|
||||
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
|
||||
$this->outputJson(getError($result));
|
||||
}
|
||||
$result = getData($result) ?: [];
|
||||
|
||||
if (count($result) != 1) {
|
||||
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
|
||||
$this->outputJsonError(count($result) ? 'Mehrere Studiensemester aktiv' : 'Kein Studiensemester aktiv');
|
||||
} else {
|
||||
$this->outputJsonSuccess(current($result)->studiensemester_kurzbz);
|
||||
}
|
||||
}
|
||||
|
||||
public function set()
|
||||
{
|
||||
$this->load->library('AuthLib');
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$_POST = json_decode(utf8_encode($this->input->raw_input_stream), true);
|
||||
|
||||
$this->form_validation->set_rules('studiensemester', 'Studiensemester', 'required');
|
||||
|
||||
if ($this->form_validation->run() == false) {
|
||||
$this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST);
|
||||
return $this->outputJsonError($this->form_validation->error_array());
|
||||
}
|
||||
|
||||
$stdsem = $this->input->post('studiensemester');
|
||||
|
||||
$this->load->model('system/Variable_model', 'VariableModel');
|
||||
|
||||
$result = $this->VariableModel->setVariable(getAuthUID(), 'semester_aktuell', $stdsem);
|
||||
|
||||
if (isError($result)) {
|
||||
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
|
||||
return $this->outputJson($result);
|
||||
}
|
||||
|
||||
$this->outputJsonSuccess(true);
|
||||
}
|
||||
}
|
||||
@@ -29,5 +29,20 @@ export default {
|
||||
url: 'api/frontend/v1/organisation/studiensemester/getAll',
|
||||
params: { order, start }
|
||||
};
|
||||
},
|
||||
current() {
|
||||
return {
|
||||
method: 'get',
|
||||
url: 'api/frontend/v1/organisation/studiensemester/current'
|
||||
};
|
||||
},
|
||||
set(studiensemester_kurzbz) {
|
||||
return {
|
||||
method: 'post',
|
||||
url: 'api/frontend/v1/organisation/studiensemester/set',
|
||||
params: {
|
||||
studiensemester_kurzbz
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
import {CoreRESTClient} from '../../../RESTClient.js';
|
||||
import ApiStudiensemester from '../../../api/factory/studiensemester.js';
|
||||
|
||||
export default {
|
||||
emits: [
|
||||
@@ -18,6 +18,11 @@ export default {
|
||||
today: -1
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
lowerCaseList() {
|
||||
return this.list.map(i => i.toLowerCase());
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
set(n) {
|
||||
this.loading = true;
|
||||
@@ -47,25 +52,18 @@ export default {
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
CoreRESTClient
|
||||
.get('components/stv/studiensemester/now')
|
||||
.then(result => CoreRESTClient.getData(result.data))
|
||||
this.$api
|
||||
.call(ApiStudiensemester.current())
|
||||
.then(result => {
|
||||
this.today = this.list.indexOf(result);
|
||||
if (this.today >= 0) {
|
||||
if (this.today != this.current)
|
||||
this.set(this.today);
|
||||
} else {
|
||||
// TODO(chris): handle error (list might not be loaded yet)
|
||||
}
|
||||
this.today = this.list.indexOf(result.data);
|
||||
if (this.today >= 0 && this.today != this.current)
|
||||
this.set(this.today);
|
||||
})
|
||||
.catch(this.$fhcAlert.handleSystemError);
|
||||
},
|
||||
save(fallback) {
|
||||
CoreRESTClient
|
||||
.post('components/stv/studiensemester/set', {
|
||||
studiensemester: this.list[this.current]
|
||||
})
|
||||
this.$api
|
||||
.call(ApiStudiensemester.set(this.list[this.current]))
|
||||
.then(() => {
|
||||
this.loading = false;
|
||||
this.$emit('update:studiensemesterKurzbz', this.list[this.current]);
|
||||
@@ -73,27 +71,42 @@ export default {
|
||||
.catch(error => {
|
||||
this.current = fallback;
|
||||
this.loading = false;
|
||||
this.$fhcAlert.handleFormValidation(error);
|
||||
this.$fhcAlert.handleSystemError(error);
|
||||
});
|
||||
},
|
||||
index() {
|
||||
let index = this.list.indexOf(this.studiensemesterKurzbz);
|
||||
if (index >= 0)
|
||||
return index;
|
||||
|
||||
// check if input is lower cases (because it came from an url)
|
||||
index = this.lowerCaseList.indexOf(this.studiensemesterKurzbz);
|
||||
if (index >= 0) {
|
||||
this.$emit('update:studiensemesterKurzbz', this.list[index]);
|
||||
return index;
|
||||
}
|
||||
|
||||
this.$emit('update:studiensemesterKurzbz', null);
|
||||
return -1;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'studiensemesterKurzbz': function () {
|
||||
this.current = this.list.indexOf(this.studiensemesterKurzbz);
|
||||
studiensemesterKurzbz() {
|
||||
if (!this.loading)
|
||||
this.current = this.index(this.studiensemesterKurzbz);
|
||||
}
|
||||
},
|
||||
created() {
|
||||
CoreRESTClient
|
||||
.get('components/stv/studiensemester')
|
||||
.then(result => CoreRESTClient.getData(result.data) || [])
|
||||
this.$api
|
||||
.call(ApiStudiensemester.getAll())
|
||||
.then(result => {
|
||||
this.list = result.map(el => el.studiensemester_kurzbz);
|
||||
this.list = result.data.map(el => el.studiensemester_kurzbz);
|
||||
this.loading = false;
|
||||
this.current = this.list.indexOf(this.studiensemesterKurzbz);
|
||||
this.current = this.index(this.studiensemesterKurzbz);
|
||||
})
|
||||
.catch(this.$fhcAlert.handleSystemError);
|
||||
},
|
||||
template: `
|
||||
template: /* html */`
|
||||
<div class="stv-studiensemester">
|
||||
<div class="btn-toolbar w-100 dropup" role="toolbar" aria-label="Studiensemester">
|
||||
<div class="btn-group flex-grow-1 position-static" role="group" aria-label="Studiensemester einstellen">
|
||||
|
||||
Reference in New Issue
Block a user