Start Component Notiz und Tab Notizen

This commit is contained in:
ma0068
2023-12-14 16:01:18 +01:00
parent 0b97a92ae9
commit 798469dfcc
7 changed files with 568 additions and 3 deletions
@@ -0,0 +1,177 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
class Notiz extends FHC_Controller
{
public function __construct()
{
parent::__construct();
// Load Libraries
$this->load->library('AuthLib');
$this->load->library('VariableLib', ['uid' => getAuthUID()]);
// Load language phrases
$this->loadPhrases([
'ui'
]);
}
public function getNotizen($person_id)
{
$this->load->model('person/Notiz_model', 'NotizModel');
$result = $this->NotizModel->getNotiz($person_id, true);
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$this->outputJson(getError($result));
} else {
$this->outputJson(getData($result) ?: []);
}
}
public function loadNotiz($notiz_id)
{
$this->load->model('person/Notiz_model', 'NotizModel');
$this->NotizModel->addJoin('public.tbl_notiz_dokument', 'notiz_id', 'LEFT');
$this->NotizModel->addSelect('*');
$this->NotizModel->addLimit(1);
$result = $this->NotizModel->loadWhere(
array('notiz_id' => $notiz_id)
);
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$this->outputJson($result);
}
elseif (!hasData($result)) {
$this->outputJson($result); //success mit Wert null
// $this->outputJson(getData($result) ?: []);
}
else
{
$this->outputJsonSuccess(current(getData($result)));
}
}
public function addNewNotiz($person_id)
{
$_POST = json_decode($this->input->raw_input_stream, true);
$this->load->library('form_validation');
$this->form_validation->set_rules('titel', 'titel', 'required');
$this->form_validation->set_rules('text', 'Text', 'required');
if ($this->form_validation->run() == false)
{
return $this->outputJsonError($this->form_validation->error_array());
}
$this->load->model('person/Notiz_model', 'NotizModel');
$uid = getAuthUID();
$titel = isset($_POST['titel']) ? $_POST['titel'] : null;
$text = isset($_POST['text']) ? $_POST['text'] : null;
//$verfasser_uid = isset($_POST['verfasser_uid']) ? $_POST['verfasser_uid'] : null;
$verfasser_uid = $uid;
$start = isset($_POST['von']) ? $_POST['von'] : null;
$ende = isset($_POST['bis']) ? $_POST['bis'] : null;
$erledigt = $_POST['erledigt'];
/* $dms_id = isset($_POST['dms_id']) ? $_POST['dms_id'] : null;
$bearbeiter_uid = isset($_POST['bearbeiter_uid']) ? $_POST['bearbeiter_uid'] : null;
*/
$result = $this->NotizModel->addNotizForPersonWithDoc($person_id, $titel, $text, $erledigt, $verfasser_uid, $start, $ende);
// var_dump($result);
/* $result = $this->NotizModel->insert(
[
'titel' => $titel,
'text' => $text,
'insertvon' => $uid,
'insertamum' => date('c'),
'verfasser_uid' => $verfasser_uid,
'bearbeiter_uid' => $bearbeiter_uid,
'start' => $start,
'ende' => $ende,
'erledigt' => $_POST['erledigt'],
//'dms_id' => $dms_id
]
);*/
if (isError($result))
{
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
return $this->outputJson($result);
}
return $this->outputJsonSuccess(true);
}
public function updateNotiz($notiz_id)
{
$uid = getAuthUID();
$this->load->library('form_validation');
$_POST = json_decode($this->input->raw_input_stream, true);
$this->form_validation->set_rules('titel', 'titel', 'required');
$this->form_validation->set_rules('text', 'Text', 'required');
if ($this->form_validation->run() == false)
{
return $this->outputJsonError($this->form_validation->error_array());
}
$this->load->model('person/Notiz_model', 'NotizModel');
if(!$notiz_id)
{
return $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
}
// $person_id = isset($_POST['person_id']) ? $_POST['person_id'] : null;
$uid = getAuthUID();
$titel = isset($_POST['titel']) ? $_POST['titel'] : null;
$text = isset($_POST['text']) ? $_POST['text'] : null;
$verfasser_uid = isset($_POST['verfasser_uid']) ? $_POST['verfasser_uid'] : null;
$bearbeiter_uid = $uid;
$start = isset($_POST['von']) ? $_POST['von'] : null;
$ende = isset($_POST['bis']) ? $_POST['bis'] : null;
$erledigt = $_POST['erledigt'];
$result = $this->NotizModel->update(
[
'notiz_id' => $notiz_id
],
[
'titel' => $titel,
'updatevon' => $uid,
'updateamum' => date('c'),
'text' => $text,
'verfasser_uid' => $verfasser_uid,
'bearbeiter_uid' => $bearbeiter_uid,
'start' => $start,
'ende' => $ende,
'erledigt' => $erledigt
]
);
if (isError($result))
{
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
return $this->outputJson(getError($result));
}
return $this->outputJsonSuccess(true);
}
}
+42 -1
View File
@@ -133,15 +133,56 @@ class Notiz_model extends DB_Model
return $result;
}
/**
* Add a Notiz for a given person
*/
public function addNotizForPersonWithDoc($person_id, $titel, $text, $erledigt, $verfasser_uid, $von, $bis)
{
// Loads model Notizzuordnung_model
$this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel');
// Start DB transaction
$this->db->trans_start(false);
$result = $this->insert(array('titel' => $titel, 'text' => $text, 'erledigt' => $erledigt, 'verfasser_uid' => $verfasser_uid,
"insertvon" => $verfasser_uid, 'start' => $von, 'ende' => $bis));
if (isSuccess($result))
{
$notiz_id = $result->retval;
$result = $this->NotizzuordnungModel->insert(array('notiz_id' => $notiz_id, 'person_id' => $person_id));
}
// Transaction complete!
$this->db->trans_complete();
// Check if everything went ok during the transaction
if ($this->db->trans_status() === false || isError($result))
{
$this->db->trans_rollback();
$result = error($result->msg, EXIT_ERROR);
}
else
{
$this->db->trans_commit();
$result = success($notiz_id);
}
return $result;
}
/**
* gets all Notizen for a person
* @param $person_id
*/
public function getNotiz($person_id)
public function getNotiz($person_id, $withDoc=false)
{
// Join with the table public.tbl_notizzuordnung using notiz_id
$this->addJoin('public.tbl_notizzuordnung', 'notiz_id');
if($withDoc)
$this->addJoin('public.tbl_notiz_dokument', 'notiz_id', 'LEFT');
return $this->loadWhere(array('person_id' => $person_id));
}
+1
View File
@@ -1,5 +1,6 @@
@import './components/searchbar.css';
@import './components/verticalsplit.css';
@import './components/Notiz.css';
html {
font-size: .875em;
+6
View File
@@ -0,0 +1,6 @@
.notizTitle {
color: darkred;
}
.notizText {
color: darkblue;
}
+138
View File
@@ -0,0 +1,138 @@
export default {
props: ['titel', 'text', 'von', 'bis', 'action', 'document', 'erledigt', 'verfasser', 'bearbeiter'],
computed: {
intTitel: {
get() {
return this.titel;
},
set(value) {
this.$emit('update:titel', value);
}
},
intText: {
get() {
return this.text;
},
set(value) {
this.$emit('update:text', value);
}
},
intVon: {
get() {
return this.von;
},
set(value) {
this.$emit('update:von', value);
}
},
intBis: {
get() {
return this.bis;
},
set(value) {
this.$emit('update:bis', value);
}
},
intDocument: {
get() {
return this.document;
},
set(value) {
this.$emit('update:document', value);
}
},
intErledigt: {
get() {
return this.erledigt;
},
set(value) {
this.$emit('update:erledigt', value);
}
},
intVerfasser: {
get() {
return this.verfasser;
},
set(value) {
this.$emit('update:verfasser', value);
}
},
intBearbeiter: {
get() {
return this.bearbeiter;
},
set(value) {
this.$emit('update:bearbeiter', value);
}
},
},
methods: {
},
template: `
<div>
{{intTitel}} {{intText}} {{intVon}}| {{titel}} {{text}} {{action}} {{von}} {{bis}} {{document}} {{erledigt}} {{verfasser}} {{bearbeiter}}
<form class="row">
<div class="notizAction row mb-3">
<b>{{action}}</b>
</div>
<div class="notizTitle row mb-3">
<label for="titel" class="form-label col-sm-2">Titel</label>
<div class="col-sm-6">
<input type="text" v-model="intTitel" class="form-control">
</div>
</div>
<div class="notizText row mb-3">
<label for="text" class="form-label col-sm-2">Text</label>
<div class="col-sm-6">
<textarea rows="5" cols="75" v-model="intText" class="form-control"></textarea>
</div>
</div>
<div class="notizDoc row mb-3">
<label for="text" class="form-label col-sm-2">Dokument</label>
<div class="col-sm-6">
<input type="text" v-model="intDocument" class="form-control">
</div>
</div>
<div class="notizVon row mb-3">
<label for="von" class="form-label col-sm-2">von</label>
<div class="col-sm-6" >
<input type="text" v-model="intVon" class="form-control">
</div>
</div>
<div class="notizBis row mb-3">
<label for="bis" class="form-label col-sm-2">bis</label>
<div class="col-sm-6">
<input type="text" v-model="intBis" class="form-control">
</div>
</div>
<div class="notizErledigt row mb-3">
<label for="bis" class="form-label col-sm-2">erledigt</label>
<div class="col-sm-6">
<input type="checkbox" v-model="intErledigt">
</div>
</div>
<div class="notizVerfasser row mb-3">
<label for="bis" class="form-label col-sm-2">VerfasserIn</label>
<div class="col-sm-6">
<input type="text" v-model="intVerfasser" class="form-control">
{{uid}}
</div>
</div>
<div class="notizBearbeiter row mb-3">
<label for="bis" class="form-label col-sm-2">BearbeiterIn</label>
<div class="col-sm-6">
<input type="text" v-model="intBearbeiter" class="form-control">
</div>
</div>
</form>
</div>`
}
@@ -1,9 +1,211 @@
//import NotizList from "./Notizen/Notizen.js";
import {CoreRESTClient} from "../../../../RESTClient.js";
import {CoreFilterCmpt} from "../../../filter/Filter.js";
import Notiz from "../../../Notiz/Notiz.js";
var editIcon = function (cell, formatterParams) {
return "<i class='fa fa-edit'></i>";
};
var deleteIcon = function (cell, formatterParams){
return "<i class='fa fa-remove'></i>";
};
export default {
components: {
CoreRESTClient,
CoreFilterCmpt,
Notiz
},
props: {
modelValue: Object
},
data() {
return {
tabulatorOptions: {
ajaxURL: CoreRESTClient._generateRouterURI('components/stv/Notiz/getNotizen/' + this.modelValue.person_id),
columns: [
{title: "Titel", field: "titel"},
{title: "Text", field: "text", width: 350},
{title: "VerfasserIn", field: "verfasser_uid"},
{title: "BearbeiterIn", field: "bearbeiter_uid", visible: false},
{title: "Start", field: "start"},
{title: "Ende", field: "ende"},
{title: "Dokumente", field: "dms_id"},
{title: "Erledigt", field: "erledigt"},
{title: "Notiz_id", field: "notiz_id", visible: false},
{title: "Notizzuordnung_id", field: "notizzuordnung_id", visible: false},
{
formatter: editIcon, cellClick: (e, cell) => {
this.actionEditNotiz(cell.getData().notiz_id);
//console.log(cell.getRow().getIndex(), cell.getData(), this);
}, width: 50, headerSort: false, headerVisible: false
},
{
formatter: deleteIcon, cellClick: (e, cell) => {
this.actionDeleteNotiz(cell.getData().notiz_id);
}, width: 50, headerSort: false, headerVisible: false
},
],
layout: 'fitDataFill',
layoutColumnsOnNewData: false,
height: '150',
selectable: true,
index: 'notiz_id'
},
tabulatorEvents: [],
notizen: [],
formData: {
titel: null,
action: 'Neue Notiz',
text: null,
von: null,
bis: null,
dms_id: null,
erledigt: false,
verfasser: null,
bearbeiter: null
},
}
},
methods:{
actionEditNotiz(notiz_id){
this.loadNotiz(notiz_id).then(() => {
if(this.notizen.notiz_id) {
this.formData.titel = this.notizen.titel;
this.formData.action = 'Notiz bearbeiten';
this.formData.text = this.notizen.text;
this.formData.von = this.notizen.start;
this.formData.bis = this.notizen.ende;
this.formData.doc = this.notizen.dms_id;
this.formData.erledigt = this.notizen.erledigt;
this.formData.verfasser = this.notizen.verfasser_uid;
this.formData.bearbeiter = this.notizen.bearbeiter_uid;
}
});
},
actionNewNotiz(){
this.formData.titel = '';
this.formData.action = 'Neue Notiz';
this.formData.text = null;
this.formData.von = null;
this.formData.bis = null;
this.formData.dms_id = null;
this.formData.erledigt = false;
this.formData.verfasser = null;
this.formData.bearbeiter = null;
},
addNewNotiz(notizData) {
CoreRESTClient.post('components/stv/Notiz/addNewNotiz/' + this.modelValue.person_id,
this.formData
).then(response => {
if (!response.data.error) {
this.$fhcAlert.alertSuccess('Anlegen von neuer Notiz erfolgreich');
this.resetFormData();
this.reload();
} else {
const errorData = response.data.retval;
Object.entries(errorData).forEach(entry => {
const [key, value] = entry;
this.$fhcAlert.alertError(value);
});
}
}).catch(error => {
this.$fhcAlert.alertError('Fehler bei Speicherroutine aufgetreten');
}).finally(() => {
window.scrollTo(0, 0);
});
},
loadNotiz(notiz_id){
return CoreRESTClient.get('components/stv/Notiz/loadNotiz/' + notiz_id)
.then(
result => {
if(result.data.retval)
this.notizen = result.data.retval;
else
{
this.notizen = {};
this.$fhcAlert.alertError('Keine Notiz mit Id ' + notiz_id + ' gefunden');
}
return result;
}
);
},
reload(){
this.$refs.table.reloadTable();
},
resetFormData(){
this.formData.titel = null;
this.formData.text = null;
this.formData.von = null;
this.formData.bis = null;
this.formData.dms_id = null;
this.formData.erledigt = false;
this.formData.verfasser = null;
this.formData.bearbeiter = null;
},
updateNotiz(notiz_id){
CoreRESTClient.post('components/stv/Notiz/updateNotiz/' + notiz_id,
this.formData
).then(response => {
if (!response.data.error) {
this.$fhcAlert.alertSuccess('Update erfolgreich');
this.resetFormData();
this.reload();
} else {
const errorData = response.data.retval;
Object.entries(errorData).forEach(entry => {
const [key, value] = entry;
this.$fhcAlert.alertError(value);
});
}
}).catch(error => {
this.statusMsg = 'Error in Catch';
this.$fhcAlert.alertError('Fehler bei Updateroutine aufgetreten');
}).finally(() => {
window.scrollTo(0, 0);
//this.reload();
});
}
},
template: `
<div class="stv-details-details h-100 pb-3">
NOT YET IMPLEMENTED
</div>`
<core-filter-cmpt
ref="table"
:tabulator-options="tabulatorOptions"
:tabulator-events="tabulatorEvents"
table-only
:side-menu="false"
reload
new-btn-show
new-btn-label="Neu"
@click:new="actionNewNotiz"
>
</core-filter-cmpt>
<br>
<Notiz
v-model:titel="formData.titel"
v-model:text="formData.text"
v-model:action="formData.action"
v-model:von="formData.von"
v-model:bis="formData.bis"
v-model:document="formData.dms_id"
v-model:erledigt="formData.erledigt"
v-model:verfasser="formData.verfasser"
v-model:bearbeiter="formData.bearbeiter"
></Notiz>
<hr>
Parent: {{titel}} {{text}}| {{notizTitel}} {{notizText}}
<br> {{modelValue}}
<br> {{formData}}
<hr>
<button v-if="formData.action === 'Neue Notiz'" type="button" class="btn btn-primary" @click="addNewNotiz()"> Neu anlegen </button>
<button v-else type="button" class="btn btn-warning" @click="updateNotiz(notizen.notiz_id)"> Speichern </button>
</div>
`
};