Funktionserweiterungen um idType

This commit is contained in:
ma0068
2024-01-16 14:34:13 +01:00
parent 09c02b0906
commit 28fe3ef839
5 changed files with 163 additions and 111 deletions
@@ -29,18 +29,30 @@ class Notiz extends FHC_Controller
$this->outputJsonError($result);
}
public function getNotizen($person_id)
public function getNotizen($id, $type)
{
$this->load->model('person/Notiz_model', 'NotizModel');
$type = 'person';
$this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel');
$result = $this->NotizModel->getNotizWithDocEntries($person_id);
//check if valid type
$isValidType = $this->NotizzuordnungModel->isValidType($type);
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
if($isValidType)
{
$result = $this->NotizModel->getNotizWithDocEntries($id, $type);
if (isError($result)) {
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$this->outputJson(getError($result));
} else {
$this->outputJson(getData($result) ?: []);
}
}
else
{
//Todo manu (correct return to ajax)
$result = "datatype not yet implemented for notes";
$this->outputJson(getError($result));
} else {
$this->outputJson(getData($result) ?: []);
}
}
@@ -60,8 +72,7 @@ class Notiz extends FHC_Controller
}
elseif (!hasData($result)) {
$this->outputJson($result); //success mit Wert null
// $this->outputJson(getData($result) ?: []);
$this->outputJson($result);
}
else
{
@@ -69,7 +80,7 @@ class Notiz extends FHC_Controller
}
}
public function addNewNotiz($id)
public function addNewNotiz($id, $paramTyp = null)
{
$this->load->model('person/Notiz_model', 'NotizModel');
@@ -87,6 +98,18 @@ class Notiz extends FHC_Controller
}
}
//Überprüfung ob type übergeben wurde (entweder Funktions- oder Postparameter)
if ($paramTyp)
$type = $paramTyp;
if(isset($_POST['typeId']))
$type = $this->input->post('typeId');
if(!$type)
{
//Todo(manu) return error
var_dump("ERROR no type");
}
//Form Validation
$this->form_validation->set_rules('titel', 'titel', 'required');
$this->form_validation->set_rules('text', 'Text', 'required');
@@ -101,11 +124,11 @@ class Notiz extends FHC_Controller
$erledigt = $this->input->post('erledigt');
$verfasser_uid = isset($_POST['verfasser_uid']) ? $_POST['verfasser_uid'] : $uid;
$bearbeiter_uid = isset($_POST['bearbeiter']) ? $_POST['bearbeiter'] : null;
$type = $this->input->post('typeId');
//$type = $this->input->post('typeId');
$start = $this->input->post('von');
$ende = $this->input->post('bis');
//Speichern der Notiz und Notizzuordnung
//Speichern der Notiz und Notizzuordnung inkl Prüfung ob valid type
$result = $this->NotizModel->addNotizForType($type, $id, $titel, $text, $uid, $start, $ende, $erledigt, $verfasser_uid, $bearbeiter_uid);
if (isError($result))
{
@@ -219,7 +242,10 @@ class Notiz extends FHC_Controller
return $this->outputJson(getError($result));
}
//Todo(manu) update von Notizzuordnung?? typeId?
//neue Files speichern
//Todo(manu) update files
foreach ($_FILES as $k => $file)
{
$dms = array(
@@ -291,7 +317,6 @@ class Notiz extends FHC_Controller
}
}
//Todo(manu) rollback?
//delete Notiz und Notizzuordnung
$this->load->model('person/Notiz_model', 'NotizModel');
+29 -19
View File
@@ -140,11 +140,31 @@ class Notiz_model extends DB_Model
* @param id for Dokumentzuordnung (person_id, prestudent_id, uid, projekt_id...)
* @param titel, text, start, ende, erledigt, verfasser_uid, bearbeiter_uid, insertvon Parameter for notiz
*/
public function addNotizForType($type, $id, $titel, $text, $insertvon, $start=null, $ende=null, $erledigt=false, $verfasser_uid=null, $bearbeiter_uid=null)
{
public function addNotizForType(
$type,
$id,
$titel,
$text,
$insertvon,
$start = null,
$ende = null,
$erledigt = false,
$verfasser_uid = null,
$bearbeiter_uid = null
) {
// Loads model Notizzuordnung_model
$this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel');
//check if valid type
$isValidType = $this->NotizzuordnungModel->isValidType($type);
if(!$isValidType)
{
//Todo manu (correct return to controller)
$msg = "datatype " . $type . " not implemented for notes";
return error($msg, EXIT_ERROR);
}
// Start DB transaction
$this->db->trans_start(false);
@@ -180,13 +200,10 @@ class Notiz_model extends DB_Model
return $result;
}
/**
* Add a Notiz for a given person with DMS_id
*/
//TODO(manu) add type for Notizzuordnung
public function addNotizForPersonWithDoc($person_id, $titel, $text, $erledigt, $verfasser_uid, $von, $bis, $dms_id=null)
public function addNotizForPersonWithDoc($person_id, $titel, $text, $erledigt, $verfasser_uid, $von, $bis, $dms_id = null)
{
// Loads model Notizzuordnung_model
$this->load->model('person/Notizzuordnung_model', 'NotizzuordnungModel');
@@ -243,16 +260,12 @@ class Notiz_model extends DB_Model
/**
* gets all Notizen with Documententries for a certain type and type_id
* @param $person_id
* @param String type of id eg. person_id, prestudent_id, mitarbeiter_uid, projekt_kurzbz, projektphase_id, projekttask_id,
* bestellung_id, lehreinheit_id, anrechnung_id, uid)
* @param $id the corresponding id, part of public.tbl_notizzuordnung
*/
//Todo(Manu) rewrite in CI-Style
//Todo(Manu) auf andere types erweitern
public function getNotizWithDocEntries($id)
public function getNotizWithDocEntries($id, $type)
{
$type = 'writeFunction';
//$type_id = 'z.person_id';
$qry = "
SELECT
n.*, count(dms_id) as countDoc, z.notizzuordnung_id
@@ -265,16 +278,15 @@ class Notiz_model extends DB_Model
LEFT JOIN
campus.tbl_dms_version USING (dms_id)
WHERE
z.person_id = ?
z.$type = ?
GROUP BY
notiz_id, z.notizzuordnung_id
";
return $this->execQuery($qry, array($id));
}
/**
* gets all Notizen for a person with a specific title
* @param $person_id
@@ -361,6 +373,4 @@ class Notiz_model extends DB_Model
return $this->loadWhere(array('anrechnung_id' => $anrechnung_id));
}
// ------------------------------------------------------------------------------------------------------
}
@@ -11,4 +11,35 @@ class Notizzuordnung_model extends DB_Model
$this->dbTable = 'public.tbl_notizzuordnung';
$this->pk = 'notizzuordnung_id';
}
public function isValidType($type)
{
//var_dump($type);
$validTypes = [];
$qry = "
SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'tbl_notizzuordnung'
";
$type_arr = $this->execQuery($qry);
$type_arr = $type_arr->retval;
foreach ($type_arr as $t) {
$validTypes[] = $t->column_name;
}
if (in_array($type, $validTypes))
{
// var_dump($type . " is IN ARRAY");
return true;
}
else
{
//var_dump($type . " is NOT IN ARRAY");
return false;
}
}
}
+31 -40
View File
@@ -29,7 +29,7 @@ export default {
multiupload: true,
mitarbeiter: [],
filteredMitarbeiter: [],
filteredFirmen: []
/* filteredFirmen: []*/
}
},
computed: {
@@ -138,17 +138,16 @@ export default {
<form ref="form" @submit.prevent class="row">
<div>
<div class="row mb-3">
<b>{{action}}</b>
<div class="col-sm-7">
<span class="small">[{{this.typeId}}]</span>
</div>
</div>
</div>
<div class="notizTitle row mb-3">
<label for="titel" class="form-label col-sm-2">Titel</label>
<div class="col-sm-7">
<input type="text" v-model="intTitel" class="form-control">
</div>
</div>
</div>
<div class="row mb-3">
@@ -159,25 +158,21 @@ export default {
</div>
</div>
<div v-if="showDocument">
<slot name="document">
<!-- show Documentupload-->
<div v-if="showDocument">
<div class="row mb-3">
<label for="text" class="form-label col-sm-2">Dokument</label>
<!-- Component File-->
<div class="col-sm-7">
<!-- File component-->
<div class="col-sm-7">
<File ref="upload" id="file" :multiupload="multiupload" v-model:dateien="intAnhang" ></File>
</div>
<hr>
</slot>
</div>
<div v-if="showErweitert">
<!-- <slot name="erweitert"> -->
</div>
<!-- show Details-->
<div v-if="showErweitert">
<div class="row mb-3">
<label for="bis" class="form-label col-sm-2">VerfasserIn</label>
<div class="col-sm-3">
@@ -186,15 +181,15 @@ export default {
<label for="von" class="form-label col-sm-1">von</label>
<div class="col-sm-3">
<vue-date-picker
id="von"
v-model="intVon"
clearable="false"
<vue-date-picker
id="von"
v-model="intVon"
clearable="false"
auto-apply
:enable-time-picker="false"
format="dd.MM.yyyy"
format="dd.MM.yyyy"
preview-format="dd.MM.yyyy"></vue-date-picker>
</div>
</div>
</div>
<div class="row mb-3">
@@ -205,32 +200,28 @@ export default {
<label for="bis" class="form-label col-sm-1">bis</label>
<div class="col-sm-3">
<vue-date-picker
id="bis"
v-model="intBis"
clearable="false"
auto-apply
<vue-date-picker
id="bis"
v-model="intBis"
clearable="false"
auto-apply
:enable-time-picker="false"
format="dd.MM.yyyy"
format="dd.MM.yyyy"
preview-format="dd.MM.yyyy"></vue-date-picker>
</div>
</div>
<div class="row mb-3">
<label for="bis" class="form-label col-sm-2">erledigt</label>
<div class="col-sm-1">
<input type="checkbox" v-model="intErledigt">
<div class="col-sm-1">
<input type="checkbox" v-model="intErledigt">
</div>
</div>
<!-- </slot>-->
</div>
</form>
</div>`
</div>
</form>
</div>`
}
@@ -6,7 +6,7 @@ import BsModal from "../../../Bootstrap/Modal";
var editIcon = function (cell, formatterParams) {
return "<i class='fa fa-edit'></i>";
};
var deleteIcon = function (cell, formatterParams){
var deleteIcon = function (cell, formatterParams) {
return "<i class='fa fa-remove text-danger'></i>";
};
@@ -20,11 +20,11 @@ export default {
props: {
modelValue: Object
},
data() {
data(){
return {
tabulatorOptions: {
ajaxURL: CoreRESTClient._generateRouterURI('components/stv/Notiz/getNotizen/' + this.modelValue.person_id),
// + this.modelValue.person_id, 'person'),
ajaxURL: CoreRESTClient._generateRouterURI('components/stv/Notiz/getNotizen/' + this.modelValue.person_id + '/person_id'),
//ajaxURL: CoreRESTClient._generateRouterURI('components/stv/Notiz/getNotizen/' + this.modelValue.person_id + '/' + this.typeId),
columns: [
{title: "Titel", field: "titel"},
{title: "Text", field: "text", width: 350},
@@ -52,7 +52,7 @@ export default {
],
layout: 'fitDataFill',
layoutColumnsOnNewData: false,
height: '200',
height: '150',
selectable: true,
index: 'notiz_id'
},
@@ -74,10 +74,10 @@ export default {
bearbeiter: null,
anhang: []
},
showErweitert: true,
showDocument: true
showErweitert: true, //show details verfasser, bearbeiter, von, bis, erledigt
showDocument: true //show upload documents
}
};
},
methods:{
actionDeleteNotiz(notiz_id){
@@ -107,8 +107,7 @@ export default {
this.loadDocEntries(this.notizen.notiz_id);
//console.log(this.formData.anhang);
}
})
;
});
},
actionNewNotiz(){
this.resetFormData();
@@ -125,13 +124,13 @@ export default {
this.formData.anhang = [];
},
addNewNotiz(notizData) {
const formData = new FormData();
formData.append('data', JSON.stringify(this.formData));
Object.entries(this.formData.anhang).forEach(([k, v]) => formData.append(k, v));
CoreRESTClient.post('components/stv/Notiz/addNewNotiz/' + this.modelValue.person_id,
CoreRESTClient.post(
'components/stv/Notiz/addNewNotiz/' + this.modelValue.person_id,
formData,
{ Headers: { "Content-Type": "multipart/form-data" } }
).then(response => {
@@ -163,16 +162,15 @@ export default {
this.$fhcAlert.alertError('Keine Notiz mit Id ' + notiz_id + ' gefunden');
}
}).catch(error => {
this.$fhcAlert.alertError('Fehler bei Löschroutine aufgetreten');
}).finally(()=> {
window.scrollTo(0, 0);
});
this.$fhcAlert.alertError('Fehler bei Löschroutine aufgetreten');
}).finally(()=> {
window.scrollTo(0, 0);
});
},
loadDocEntries(notiz_id){
return CoreRESTClient.get('components/stv/Notiz/loadDokumente/' + notiz_id)
.then(
result => {
//console.log(result.data);
if(result.data.retval) {
this.formData.anhang = result.data.retval;
console.log(this.formData.anhang);
@@ -187,15 +185,15 @@ export default {
);
},
loadNotiz(notiz_id){
return CoreRESTClient.get('components/stv/Notiz/loadNotiz/' + notiz_id)
return CoreRESTClient.get(
'components/stv/Notiz/loadNotiz/' + notiz_id)
.then(
result => {
if(result.data.retval) {
this.notizen = result.data.retval;
console.log(this.notizen);
//console.log(this.notizen);
}
else
{
else {
this.notizen = {};
this.$fhcAlert.alertError('Keine Notiz mit Id ' + notiz_id + ' gefunden');
}
@@ -230,7 +228,8 @@ export default {
Object.entries(this.formData.anhang).forEach(([k, v]) => formData.append(k, v));
//console.log(this.formData);
CoreRESTClient.post('components/stv/Notiz/updateNotiz/' + notiz_id,
CoreRESTClient.post(
'components/stv/Notiz/updateNotiz/' + notiz_id,
formData,
{ Headers: { "Content-Type": "multipart/form-data" } }
).then(response => {
@@ -256,9 +255,9 @@ export default {
CoreRESTClient
.get('components/stv/Notiz/getUid')
.then(result => {
if(result.data.retval) {
this.formData.verfasser = result.data.retval;
}
if(result.data.retval) {
this.formData.verfasser = result.data.retval;
}
})
.catch(this.$fhcAlert.handleSystemError);
},
@@ -277,7 +276,7 @@ export default {
<button ref="Close" type="button" class="btn btn-primary" @click="deleteNotiz(notizen.notiz_id)">OK</button>
</template>
</BsModal>
<core-filter-cmpt
ref="table"
:tabulator-options="tabulatorOptions"
@@ -291,18 +290,18 @@ export default {
>
</core-filter-cmpt>
<br>
<br>
<hr>
<Notiz
<Notiz
ref="form"
:showErweitert="showErweitert"
:showDocument="showDocument"
v-model:typeId="formData.typeId"
v-model:titel="formData.titel"
v-model:text="formData.text"
v-model:statusNew="formData.statusNew"
v-model:von="formData.von"
v-model:bis="formData.bis"
v-model:titel="formData.titel"
v-model:text="formData.text"
v-model:statusNew="formData.statusNew"
v-model:von="formData.von"
v-model:bis="formData.bis"
v-model:document="formData.document"
v-model:erledigt="formData.erledigt"
v-model:verfasser="formData.verfasser"
@@ -314,10 +313,6 @@ export default {
<button v-if="formData.statusNew" type="button" class="btn btn-primary" @click="addNewNotiz()"> Neu anlegen </button>
<button v-else type="button" class="btn btn-primary" @click="updateNotiz(notizen.notiz_id)"> Speichern </button>
<div>
<!-- parent: -->
</div>
</div>
`
};
`
};