Ferienverwaltung: created page with VUE Js, displaying Ferien and adding, deleting

This commit is contained in:
Alexei Karpenko
2026-02-23 18:40:37 +01:00
parent a57df7862c
commit c47a1cb627
8 changed files with 659 additions and 1 deletions
@@ -0,0 +1,192 @@
<?php
/**
* Copyright (C) 2024 fhcomplete.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
if (!defined('BASEPATH')) exit('No direct script access allowed');
//use CI3_Events as Events;
/**
* This controller operates between (interface) the JS (GUI) and the back-end
* This controller works with JSON calls on the HTTP GET or POST and the output is always JSON
*/
class Ferien extends FHCAPI_Controller
{
/**
* Calls the parent's constructor and prepares libraries and phrases
*/
public function __construct()
{
parent::__construct([
'getFerien' => 'basis/ferien:r',
'getStg' => 'basis/ferien:r',
'insert' => 'basis/ferien:w',
'delete' => 'basis/ferien:w'
]);
// Load models
$this->load->model('organisation/Ferien_model', 'FerienModel');
// Load language phrases
$this->loadPhrases([
'ui'
]);
}
//------------------------------------------------------------------------------------------------------------------
// Public methods
/**
* Get Ferien
*
* @return void
*/
public function getFerien()
{
$studiengang_kz = $this->input->get('studiengang_kz');
$this->addMeta('stgkz', $studiengang_kz);
if (!isset($studiengang_kz)) $this->terminateWithSuccess([]);
//~ if (isset($studiengang_kz) && !is_numeric($studiengang_kz))
//~ $this->terminateWithError($this->p->t('ui', 'errorMissingOrInvalidParameters', ['parameter'=> 'Studiengang']), self::ERROR_TYPE_GENERAL);
$this->FerienModel->addSelect('tbl_ferien.*, , UPPER(typ::varchar(1) || kurzbz) AS studiengang_kuerzel');
$this->FerienModel->addJoin('public.tbl_studiengang', 'studiengang_kz');
if (isset($studiengang_kz) && is_numeric($studiengang_kz))
$this->FerienModel->db->where('studiengang_kz', $studiengang_kz);
$this->FerienModel->addOrder('vondatum', 'DESC');
$result = $this->FerienModel->load();
$data = $this->getDataOrTerminateWithError($result);
$this->terminateWithSuccess($data);
}
/**
* Get list of Studiengaenge
*
* @return void
*/
public function getStg()
{
$this->load->model('organisation/Studiengang_model', 'StudiengangModel');
$this->StudiengangModel->addSelect(' tbl_studiengang.*, UPPER(typ::varchar(1) || kurzbz) AS kuerzel');
$this->StudiengangModel->addOrder('typ, kurzbz');
$result = $this->StudiengangModel->load();
$data = $this->getDataOrTerminateWithError($result);
$this->terminateWithSuccess($data);
}
/**
* Save Ferien
*
* @return void
*/
public function insert()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('vondatum', 'Von Datum', 'required|is_valid_date');
$this->form_validation->set_rules('bisdatum', 'Bis Datum', 'required|is_valid_date');
$this->form_validation->set_rules('bezeichnung', 'Bezeichnung', 'required|max_length[128]');
$this->form_validation->set_rules('studiengang_kz', 'Studiengang', 'required|numeric');
//Events::trigger('konto_insert_validation', $this->form_validation);
if (!$this->form_validation->run())
$this->terminateWithValidationErrors($this->form_validation->error_array());
$allowed = [
'vondatum',
'bisdatum',
'bezeichnung',
'studiengang_kz'
];
$data = [];
// TODO add insertaum and updateamum?
//~ $data = [
//~ 'insertamum' => date('c'),
//~ 'insertvon' => getAuthUID()
//~ ];
foreach ($allowed as $field)
{
if ($this->input->post($field) !== null) $data[$field] = $this->input->post($field);
}
$result = [];
$id = $this->getDataOrTerminateWithError($this->FerienModel->insert($data));
$this->terminateWithSuccess(hasData($id) ? getData($id) : null);
}
/**
* Delete Ferien
*
* @return void
*/
public function delete()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('ferien_id', 'Ferien Id', 'required');
if (!$this->form_validation->run())
$this->terminateWithValidationErrors($this->form_validation->error_array());
$ferien_id = $this->input->post('ferien_id');
$this->FerienModel->addSelect('ferien_id');
$result = $this->FerienModel->load($ferien_id);
$this->addMeta('res', $result);
if (!hasData($result))
$this->terminateWithError($this->p->t('ferien', 'error_missing', [
'ferien_id' => $ferien_id
]));
//~ $_POST['studiengang_kz'] = current($result)->studiengang_kz;
//~ $this->form_validation->set_rules('studiengang_kz', 'Studiengang', 'has_permissions_for_stg[admin:rw,assistenz:rw]');
//~ Events::trigger('konto_delete_validation', $this->form_validation);
//~ if (!$this->form_validation->run())
//~ $this->terminateWithValidationErrors($this->form_validation->error_array());
//Events::trigger('konto_delete', $ferien_id);
$result = $this->getDataOrTerminateWithError($this->FerienModel->delete($ferien_id));
//~ if (isError($result)) {
//~ if (getCode($result) != 42)
//~ $this->terminateWithError(getError($result));
//~ $this->terminateWithError($this->p->t('konto', 'error_delete_level'));
//~ }
$this->terminateWithSuccess();
}
}
@@ -0,0 +1,44 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Overview on cronjob logs
*/
class Ferienverwaltung extends Auth_Controller
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct(
array(
'index' => ['admin:r', 'assistenz:r']
)
);
// Loads WidgetLib
//$this->load->library('WidgetLib');
// Loads phrases system
$this->loadPhrases(
array(
'global',
'ui'
//'ferien'
)
);
}
// -----------------------------------------------------------------------------------------------------------------
// Public methods
/**
* Everything has a beginning
*/
public function index()
{
$this->load->view('lehre/ferienverwaltung.php');
}
}
@@ -9,6 +9,6 @@ class Ferien_model extends DB_Model
{
parent::__construct();
$this->dbTable = 'lehre.tbl_ferien';
$this->pk = array('studiengang_kz', 'bezeichnung');
$this->pk = 'ferien_id';
}
}
@@ -0,0 +1,29 @@
<?php
$includesArray = array(
'title' => 'Ferienverwaltung',
'axios027' => true,
'bootstrap5' => true,
'fontawesome6' => true,
'vue3' => true,
'filtercomponent' => true,
'navigationcomponent' => true,
'tabulator6' => true,
'primevue3' => true,
'vuedatepicker11' => true,
'customJSModules' => array('public/js/apps/lehre/Ferienverwaltung/Ferienverwaltung.js'),
);
$this->load->view('templates/FHC-Header', $includesArray);
?>
<div id="main">
<div id="content">
<div>
<ferienverwaltung></ferienverwaltung>
</div>
</div>
</div>
<?php $this->load->view('templates/FHC-Footer', $includesArray); ?>
@@ -0,0 +1,48 @@
/**
* Copyright (C) 2025 fhcomplete.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export default {
getFerien(studiengang_kz) {
return {
method: 'get',
url: 'api/frontend/v1/education/ferien/getFerien',
params: {
studiengang_kz
}
};
},
getStg() {
return {
method: 'get',
url: 'api/frontend/v1/education/ferien/getStg'
};
},
insert(params) {
return {
method: 'post',
url: 'api/frontend/v1/education/ferien/insert',
params
};
},
delete(ferien_id) {
return {
method: 'post',
url: 'api/frontend/v1/education/ferien/delete',
params: { ferien_id }
};
}
};
@@ -0,0 +1,12 @@
import Ferienverwaltung from '../../../components/Ferienverwaltung/Ferienverwaltung.js';
import PluginsPhrasen from '../../../plugins/Phrasen.js';
const app = Vue.createApp({
name: 'FerienverwaltungApp',
components: {
Ferienverwaltung
}
});
app
.use(PluginsPhrasen)
.mount('#main');
@@ -0,0 +1,213 @@
import {CoreFilterCmpt} from "../filter/Filter.js";
import FormInput from "../Form/Input.js";
import FerienNew from "./New.js";
//import KontoEdit from "./Konto/Edit.js";
import ApiFerienverwaltung from '../../api/factory/ferienverwaltung/ferienverwaltung.js';
export default {
name: "Ferienverwaltung",
components: {
CoreFilterCmpt,
FormInput,
FerienNew
//KontoEdit
},
props: {
//modelValue: Object,
//~ config: {
//~ type: Object,
//~ default: {}
//~ }
},
data() {
return {
studiengang_kz_list: [],
studiengang_kz: null,
loading: false,
tabulatorOptions: {
ajaxURL: 'dummy',
ajaxRequestFunc: () => this.$api.call(
ApiFerienverwaltung.getFerien(this.studiengang_kz)
),
ajaxResponse: (url, params, response) => response.data,
columns: [
{title:"Ferien Id", field:"ferien_id", visible: false},
{title:"Studiengang", field:"studiengang_kuerzel"},
{
title:"Datum von",
field:"vondatum",
formatter: function (cell) {
const dateStr = cell.getValue();
if (!dateStr) return "";
const date = new Date(dateStr);
return date.toLocaleString("de-DE", {
day: "2-digit",
month: "2-digit",
year: "numeric",
hour12: false
});
}
},
{
title:"Datum bis",
field:"bisdatum",
formatter: function (cell) {
const dateStr = cell.getValue();
if (!dateStr) return "";
const date = new Date(dateStr);
return date.toLocaleString("de-DE", {
day: "2-digit",
month: "2-digit",
year: "numeric",
hour12: false
});
}
},
{title:"Bezeichnung", field:"bezeichnung"},
{title:"Aktionen", field: "actions",
minWidth: 150, // Ensures Action-buttons will be always fully displayed
formatter: (cell, formatterParams, onRendered) => {
let container = document.createElement('div');
container.className = "d-flex gap-2";
//~ let button = document.createElement('button');
//~ button.className = 'btn btn-outline-secondary btn-action';
//~ button.innerHTML = '<i class="fa fa-edit"></i>';
//~ button.title = this.$p.t('person', 'adresse_edit');
//~ button.addEventListener('click', (event) =>
//~ this.actionEditAdress(cell.getData().adresse_id)
//~ );
//~ container.append(button);
let button = document.createElement('button');
button.className = 'btn btn-outline-secondary';
button.innerHTML = '<i class="fa fa-trash"></i>';
button.addEventListener('click', evt => {
evt.stopPropagation();
this.$fhcAlert
.confirmDelete()
.then(result => result ? cell.getData().ferien_id : Promise.reject({handled:true}))
.then(ferien_id => this.$api.call(ApiFerienverwaltung.delete(ferien_id)))
.then(() => {
//cell.getRow().delete();
this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete'));
this.reload();
})
.catch(this.$fhcAlert.handleSystemError);
});
container.append(button);
return container;
},
frozen: true
}
]
},
tabulatorEvents: [
{
event: 'tableBuilt',
handler: async () => {
//await this.$p.loadCategory(['ferien', 'ui']);
await this.$p.loadCategory(['global', 'ferien']);
let cm = this.$refs.table.tabulator.columnManager;
cm.getColumnByField('ferien_id').component.updateDefinition({
title: this.$p.t('ferien', 'ferien_id'),
});
cm.getColumnByField('studiengang_kuerzel').component.updateDefinition({
title: this.$p.t('ferien', 'studiengang_kuerzel'),
});
cm.getColumnByField('vondatum').component.updateDefinition({
title: this.$p.t('ferien', 'vondatum'),
});
cm.getColumnByField('bisdatum').component.updateDefinition({
title: this.$p.t('ferien', 'bisdatum'),
});
cm.getColumnByField('bezeichnung').component.updateDefinition({
title: this.$p.t('global', 'bezeichnung'),
});
cm.getColumnByField('actions').component.updateDefinition({
title: this.$p.t('global', 'aktionen')
});
}
}
]
}
},
computed: {
},
methods: {
reload() {
this.$refs.table.reloadTable();
},
updateData(data) {
if (!data)
return this.reload();
//this.$refs.table.tabulator.updateOrAddData(data);
},
actionNew() {
this.$refs.new.open();
},
loadByStg() {
this.reload();
}
},
created() {
this.loading = true;
this.$api
.call(ApiFerienverwaltung.getStg())
.then(result => {
this.studiengang_kz_list = result.data;
this.loading = false;
}
)
.catch(error => {
if (error)
this.$fhcAlert.handleSystemError(error);
this.loading = false;
});
},
template: `
<div class="stv-details-konto h-100 d-flex flex-column">
<div class="row justify-content-end">
<div class="col-lg-3">
<div class="input-group w-auto">
<select class="form-select" v-model="studiengang_kz">
<option selected="selected" :value="null">-- {{ $p.t('ferien/keineAuswahl') }} --</option>
<option value="All">-- {{ $p.t('ferien/alleStudiengaenge') }} --</option>
<option v-for="studiengang in studiengang_kz_list" :key="studiengang.studiengang_kz" :value="studiengang.studiengang_kz">
{{ studiengang.kuerzel }}
</option>
</select>
<button
class="btn btn-primary"
@click="loadByStg()"
:disabled="loading"
>
<i v-if="loading" class="fa fa-spinner fa-spin"></i>
{{ $p.t('ui/anzeigen') }}
</button>
</div>
</div>
</div>
<core-filter-cmpt
ref="table"
table-only
:side-menu="false"
:tabulator-options="tabulatorOptions"
:tabulator-events="tabulatorEvents"
reload
:reload-btn-infotext="this.$p.t('table', 'reload')"
new-btn-show
:new-btn-label="$p.t('ui/neu')"
@click:new="actionNew"
>
</core-filter-cmpt>
<ferien-new ref="new" :studiengang_kz_list="studiengang_kz_list" @saved="updateData"></ferien-new>
</div>`
};
@@ -0,0 +1,120 @@
import BsModal from "../Bootstrap/Modal.js";
import BsConfirm from "../Bootstrap/Confirm.js";
import CoreForm from "../Form/Form.js";
import FormValidation from "../Form/Validation.js";
import FormInput from "../Form/Input.js";
import ApiFerien from '../../api/factory/ferienverwaltung/ferienverwaltung.js';
export default {
components: {
BsModal,
CoreForm,
FormValidation,
FormInput
},
props: {
studiengang_kz_list: {
type: Array,
required: true
}
},
data() {
return {
loading: false,
data: {},
};
},
computed: {
},
methods: {
save() {
this.$refs.form.clearValidation();
this.loading = true;
this.$refs.form
.call(ApiFerien.insert(this.data))
.then(result => {
this.$emit('saved', result.data);
this.loading = false;
this.$refs.modal.hide();
this.$fhcAlert.alertSuccess(this.$p.t('ui/gespeichert'));
})
.catch(error => {
if (error)
this.$fhcAlert.handleSystemError(error);
this.loading = false;
});
},
open() {
this.data = {
studiengang_kz: null,
bezeichnung: '',
vondatum: null,
bisdatum: null
};
this.$refs.modal.show();
},
preventCloseOnLoading(ev) {
if (this.loading)
ev.returnValue = false;
}
},
template: `
<core-form ref="form" class="stv-details-ferien-edit" @submit.prevent="save">
<bs-modal ref="modal" @hide-bs-modal="preventCloseOnLoading">
<form-validation></form-validation>
<fieldset :disabled="loading">
<form-input
type="DatePicker"
v-model="data.vondatum"
name="vondatum"
:label="$p.t('ferien/vondatum')"
:enable-time-picker="false"
text-input
format="dd.MM.yyyy"
auto-apply
>
</form-input>
<form-input
type="DatePicker"
v-model="data.bisdatum"
name="bisdatum"
:label="$p.t('ferien/bisdatum')"
:enable-time-picker="false"
text-input
format="dd.MM.yyyy"
auto-apply
>
</form-input>
<form-input
v-model="data.bezeichnung"
name="bezeichnung"
:label="$p.t('global/bezeichnung')"
>
</form-input>
<form-input
type="select"
v-model="data.studiengang_kz"
name="studiengang_kz"
:label="$p.t('lehre/studiengang')"
>
<option v-for="studiengang in studiengang_kz_list" :key="studiengang.studiengang_kz" :value="studiengang.studiengang_kz">
{{ studiengang.kuerzel }}
</option>
</form-input>
</fieldset>
<template #footer>
<button type="submit" class="btn btn-primary" :disabled="loading">
<i v-if="loading" class="fa fa-spinner fa-spin"></i>
{{ $p.t('ui/speichern') }}
</button>
</template>
</bs-modal>
</core-form>`
};