mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 12:19:28 +00:00
Studiensemester now
This commit is contained in:
@@ -29,6 +29,26 @@ class Studiensemester extends FHC_Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function now()
|
||||
{
|
||||
$this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel');
|
||||
|
||||
$result = $this->StudiensemesterModel->getAkt();
|
||||
|
||||
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->outputJson(count($result) ? 'Mehrere Studiensemester aktiv' : 'Kein Studiensemester aktiv');
|
||||
} else {
|
||||
$this->outputJson(current($result)->studiensemester_kurzbz);
|
||||
}
|
||||
}
|
||||
|
||||
public function set()
|
||||
{
|
||||
$this->load->library('AuthLib');
|
||||
@@ -39,7 +59,7 @@ class Studiensemester extends FHC_Controller
|
||||
$this->form_validation->set_rules('studiensemester', 'Studiensemester', 'required');
|
||||
|
||||
if ($this->form_validation->run() == false) {
|
||||
$this->output->set_status_header(HTTP_BAD_REQUEST);
|
||||
$this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST);
|
||||
return $this->outputJson($this->form_validation->error_array());
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ export default {
|
||||
return {
|
||||
current: 0,
|
||||
loading: true,
|
||||
list: []
|
||||
list: [],
|
||||
today: -1
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
@@ -38,6 +39,31 @@ export default {
|
||||
this.current = 0;
|
||||
this.save(fallback);
|
||||
},
|
||||
setToToday() {
|
||||
if (this.today > 0) {
|
||||
if (this.today == this.current)
|
||||
return;
|
||||
return this.set(this.today);
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
CoreRESTClient
|
||||
.get('components/stv/studiensemester/now')
|
||||
.then(result => result.data)
|
||||
.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)
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
// TODO(chris): emit error
|
||||
console.error(error);
|
||||
});
|
||||
},
|
||||
save(fallback) {
|
||||
CoreRESTClient
|
||||
.post('components/stv/studiensemester/set', {
|
||||
@@ -47,9 +73,10 @@ export default {
|
||||
this.loading = false;
|
||||
this.$emit('changed');
|
||||
})
|
||||
.catch(() => {
|
||||
.catch(error => {
|
||||
this.current = fallback;
|
||||
// TODO(chris): emit error
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -68,18 +95,23 @@ export default {
|
||||
},
|
||||
template: `
|
||||
<div class="stv-studiensemester">
|
||||
<div class="btn-group w-100 dropup" role="group" aria-label="Basic example">
|
||||
<button type="button" class="btn btn-outline-secondary flex-grow-0" @click="prev"><i class="fa-solid fa-caret-left"></i></button>
|
||||
<button type="button" class="btn btn-outline-secondary" data-bs-toggle="dropdown" data-bs-display="static" data-bs-offset="0,0" aria-expanded="false">
|
||||
{{list[current]}}
|
||||
<i v-if="loading" class="fa-solid fa-spinner fa-spin"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-dark overflow-auto w-100" style="max-height:60vh">
|
||||
<li v-for="(item, index) in list" :key="index">
|
||||
<a class="dropdown-item" :class="{active: index == current}" :aria-current="index == current ? 'true' : 'false'" href="#" @click="set(index)">{{item}}</a>
|
||||
</li>
|
||||
</ul>
|
||||
<button type="button" class="btn btn-outline-secondary flex-grow-0" @click="next"><i class="fa-solid fa-caret-right"></i></button>
|
||||
<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">
|
||||
<button type="button" class="btn btn-outline-secondary flex-grow-0" @click="prev"><i class="fa-solid fa-caret-left"></i></button>
|
||||
<button type="button" class="btn btn-outline-secondary" data-bs-toggle="dropdown" data-bs-display="static" data-bs-offset="0,0" aria-expanded="false">
|
||||
{{list[current]}}
|
||||
<i v-if="loading" class="fa-solid fa-spinner fa-spin"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-dark overflow-auto w-100" style="max-height:60vh">
|
||||
<li v-for="(item, index) in list" :key="index">
|
||||
<a class="dropdown-item" :class="{active: index == current}" :aria-current="index == current ? 'true' : 'false'" href="#" @click="set(index)">{{item}}</a>
|
||||
</li>
|
||||
</ul>
|
||||
<button type="button" class="btn btn-outline-secondary flex-grow-0" @click="next"><i class="fa-solid fa-caret-right"></i></button>
|
||||
</div>
|
||||
<div class="btn-group flex-grow-0" role="group" aria-label="aktuelles Studiensemester">
|
||||
<button type="button" class="btn btn-outline-secondary" @click="setToToday"><i class="fa-solid fa-bullseye"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user