refactor Messages

- endpoint: using apiMessages instead of prop
- add Phrases
- openMode Modal: resetModal if no messageId
- openMode inSamePage: loadReplyData
- function getNameOfDefaulRecipients: add missing check, if id[]
This commit is contained in:
ma0068
2025-12-02 16:08:13 +01:00
parent 4dabc642ed
commit d75939a8f8
7 changed files with 186 additions and 126 deletions
@@ -1,6 +1,5 @@
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Messages extends FHCAPI_Controller
@@ -39,7 +38,7 @@ class Messages extends FHCAPI_Controller
// Load language phrases
$this->loadPhrases([
'ui'
'ui', 'messages'
]);
}
@@ -156,19 +155,6 @@ class Messages extends FHCAPI_Controller
$this->terminateWithSuccess($data);
}
/* public function getNameOfDefaultRecipient($id, $type_id)
{
$id = ($type_id != 'person_id') ? $this->_getPersonId($id, $type_id) : $id;
$this->load->model('person/Person_model', 'PersonModel');
$result = $this->PersonModel->load($id);
$data = $this->getDataOrTerminateWithError($result);
$name = current($data);
$this->terminateWithSuccess($name->vorname . " " . $name->nachname );
}*/
public function getNameOfDefaultRecipients($type_id)
{
$ids = $this->input->post('ids');
@@ -178,7 +164,8 @@ class Messages extends FHCAPI_Controller
$recipients = [];
if (empty($ids)) {
throw new InvalidArgumentException("Keine ID(s) übergeben.");
throw new InvalidArgumentException($this->p->t('ui', 'errorMissingOrInvalidParameters', ['parameter'=> 'Id(s)']), self::ERROR_TYPE_GENERAL);
}
$this->load->model('person/Person_model', 'PersonModel');
@@ -253,6 +240,10 @@ class Messages extends FHCAPI_Controller
}
}
if (!is_array($ids)) {
$ids = [$ids];
}
foreach ($ids as $id)
{
$receiversPersonId = $typeId == "person_id" ? $id : $this->_getPersonId($id, $typeId);
@@ -283,7 +274,7 @@ class Messages extends FHCAPI_Controller
}
else
{
$this->terminateWithError("type_id " . $typeId . " not valid", self::ERROR_TYPE_GENERAL);
$this->terminateWithError($this->p->t('messages', 'error_missingLogic', ['type'=> $typeId]), self::ERROR_TYPE_GENERAL);
}
$result =$this->messagelib->sendMessageUser($receiversPersonId, $subject, $bodyParsed, $benutzer->person_id, null, $relationmessage_id);
@@ -302,7 +293,7 @@ class Messages extends FHCAPI_Controller
unset($_POST['data']);
}
else
$this->terminateWithError("Textbody missing ", self::ERROR_TYPE_GENERAL);
$this->terminateWithError($this->p->t('messages', 'errorMissingOrInvalidParameters', ['parameter'=> "Textbody"]), self::ERROR_TYPE_GENERAL);
if (isset($_POST['ids']))
{
@@ -314,7 +305,7 @@ class Messages extends FHCAPI_Controller
unset($_POST['ids']);
}
else
$this->terminateWithError("IDs missing ", self::ERROR_TYPE_GENERAL);
$this->terminateWithError($this->p->t('ui', 'errorMissingOrInvalidParameters', ['parameter'=> 'Id(s)']), self::ERROR_TYPE_GENERAL);
$bodyParsed = [];
@@ -343,7 +334,7 @@ class Messages extends FHCAPI_Controller
}
break;
default:
$this->terminateWithError("MESSAGES::getPreviewText logic for type_id " . $type_id . " not defined yet", self::ERROR_TYPE_GENERAL);
$this->terminateWithError($this->p->t('messages', 'error_missingLogic', ['type'=> $type_id]), self::ERROR_TYPE_GENERAL);
break;
}
}
@@ -353,7 +344,9 @@ class Messages extends FHCAPI_Controller
public function getReplyData($messageId)
{
//TODO(Manu) validation of messageId: if number
if (!is_numeric($messageId)) {
$this->terminateWithError($this->p->t('ui', 'error_valueNotNumeric', ['value'=> 'Message ID']), self::ERROR_TYPE_GENERAL);
}
$this->MessageModel->addSelect('public.tbl_msg_message.*');
$this->MessageModel->addSelect('r.*');
@@ -376,7 +369,6 @@ class Messages extends FHCAPI_Controller
$replyBody = $this->_getReplyBody($body, $dataMessage[0]->nachname, $dataMessage[0]->vorname, $dataMessage[0]->insertamum);
$dataMessage[0]->replyBody = $replyBody;
$dataMessage[0]->rest = "Help Manu";
$dataMessage[0]->replySubject = $prefix . $subject;
$this->terminateWithSuccess($dataMessage);
@@ -424,6 +416,11 @@ class Messages extends FHCAPI_Controller
['prestudent_id' => $id]
);
}
else
{
$this->terminateWithError($this->p->t('messages', 'error_missingLogic', ['type'=> $typeId]), self::ERROR_TYPE_GENERAL);
}
$data = $this->getDataOrTerminateWithError($result);
$person = current($data);
@@ -431,50 +428,6 @@ class Messages extends FHCAPI_Controller
$this->terminateWithSuccess($person->person_id);
}
public function getUid($typeId)
{
if (!$typeId)
{
$this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Type ID']), self::ERROR_TYPE_GENERAL);
}
elseif ($typeId == 'person_id')
{
$this->load->model('person/Benutzer_model', 'BenutzerModel');
$result = $this->BenutzerModel->loadWhere(
['person_id' => $id]
);
}
elseif($typeId == 'prestudent_id')
{
$this->load->model('crm/Prestudent_model', 'PrestudentModel');
$result = $this->PrestudentModel->loadWhere(
['prestudent_id' => $id]
);
$data = $this->getDataOrTerminateWithError($result);
$person = current($data);
$person_id = $person->person_id;
$this->load->model('person/Benutzer_model', 'BenutzerModel');
$result = $this->BenutzerModel->loadWhere(
['person_id' => $person_id]
);
}
elseif($typeId == 'uid' || $typeId == 'mitarbeiter_uid')
{
$this->terminateWithSuccess($id);
}
else
{
$this->terminateWithError("MESSAGES::getUID logic for type_id " . $typeId . " not defined yet", self::ERROR_TYPE_GENERAL);
}
$data = $this->getDataOrTerminateWithError($result);
$benutzer = current($data);
$this->terminateWithSuccess($benutzer->uid);
}
public function getUids($typeId)
{
$ids = $this->input->post('ids');
@@ -527,13 +480,9 @@ class Messages extends FHCAPI_Controller
}
else
{
$this->terminateWithError("MESSAGES::getUID logic for type_id " . $typeId . " not defined yet", self::ERROR_TYPE_GENERAL);
$this->terminateWithError($this->p->t('messages', 'error_missingLogic', ['type'=> $typeId]), self::ERROR_TYPE_GENERAL);
}
//$data = $this->getDataOrTerminateWithError($resultBenutzer);
//$benutzer = current($data);
$this->terminateWithSuccess($benutzerIds);
}
@@ -553,11 +502,16 @@ class Messages extends FHCAPI_Controller
['prestudent_id' => $id]
);
}
else
{
$this->terminateWithError($this->p->t('messages', 'error_missingLogic', ['type'=> $typeId]), self::ERROR_TYPE_GENERAL);
}
$data = $this->getDataOrTerminateWithError($result);
if (count($data) < 1)
{
$this->terminateWithError('Error: Messages API no person_id found.');
$this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Person ID']), self::ERROR_TYPE_GENERAL);
}
$person = current($data);
@@ -566,7 +520,6 @@ class Messages extends FHCAPI_Controller
private function _getPrestudentIdFromUid($uid)
{
// $this->terminateWithError($uid, self::ERROR_TYPE_GENERAL);
$this->load->model('crm/Student_model', 'StudentModel');
$result = $this->StudentModel->loadWhere(
['student_uid' => $uid]
@@ -575,7 +528,7 @@ class Messages extends FHCAPI_Controller
$data = $this->getDataOrTerminateWithError($result);
if (count($data) < 1)
{
$this->terminateWithError('Error: Messages API no prestudent_id found.');
$this->terminateWithError($this->p->t('ui', 'error_missingId', ['id'=> 'Prestudent ID']), self::ERROR_TYPE_GENERAL);
}
$student = current($data);
@@ -4,6 +4,8 @@ import FormInput from '../../../Form/Input.js';
import ListBox from "../../../../../../index.ci.php/public/js/components/primevue/listbox/listbox.esm.min.js";
import DropdownComponent from "../../../VorlagenDropdown/VorlagenDropdown.js";
import ApiMessages from '../../../../api/factory/messages/messages.js';
export default {
name: "ModalNewMessages",
components: {
@@ -14,10 +16,6 @@ export default {
ListBox
},
props: {
endpoint: {
type: Object,
required: true
},
typeId: String,
id: {
type: Array,
@@ -117,7 +115,7 @@ export default {
data.append('ids', JSON.stringify(this.id));
return this.$refs.formMessage
.call(this.endpoint.sendMessageFromModalContext(this.typeId, data))
.call(ApiMessages.sendMessageFromModalContext(this.typeId, data))
.then(response => {
this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent'));
this.hideModal('modalNewMessage');
@@ -134,7 +132,7 @@ export default {
},
getDataVorlage(vorlage_kurzbz){
return this.$api
.call(this.endpoint.getDataVorlage(vorlage_kurzbz))
.call(ApiMessages.getDataVorlage(vorlage_kurzbz))
.then(response => {
this.formData.body = response.data.text;
this.formData.subject = response.data.subject;
@@ -146,14 +144,14 @@ export default {
data.append('ids', JSON.stringify(this.id));
return this.$api
.call(this.endpoint.getPreviewText(
.call(ApiMessages.getPreviewText(
this.typeId, data))
.then(response => {
const previews = response.data;
this.previewText = previews[this.defaultRecipient];
}).catch(this.$fhcAlert.handleSystemError)
.finally(() => {
//this.resetForm();
this.resetForm();
//closeModal
//closewindwo
});
@@ -177,6 +175,7 @@ export default {
body: null,
subject: null,
};
this.$emit('resetMessageId');
if (this.editor) {
@@ -230,7 +229,7 @@ export default {
if (!newMessageId) return;
try {
const result = await this.$api.call(this.endpoint.getReplyData(newMessageId));
const result = await this.$api.call(ApiMessages.getReplyData(newMessageId));
this.replyData = result.data;
if (this.replyData.length > 0) {
@@ -247,7 +246,7 @@ export default {
created(){
if(this.typeId == 'person_id' || this.typeId == 'mitarbeiter_uid'){
this.$api
.call(this.endpoint.getMessageVarsPerson(this.id, this.typeId))
.call(ApiMessages.getMessageVarsPerson(this.id, this.typeId))
.then(result => {
this.fieldsPerson = result.data;
const person = this.fieldsPerson[0];
@@ -261,7 +260,7 @@ export default {
if(this.typeId == 'prestudent_id' || this.typeId == 'uid'){
this.$api
.call(this.endpoint.getMsgVarsPrestudent(this.id, this.typeId))
.call(ApiMessages.getMsgVarsPrestudent(this.id, this.typeId))
.then(result => {
this.fieldsPrestudent = result.data;
const prestudent = this.fieldsPrestudent[0];
@@ -274,7 +273,7 @@ export default {
}
this.$api
.call(this.endpoint.getMsgVarsLoggedInUser())
.call(ApiMessages.getMsgVarsLoggedInUser())
.then(result => {
this.fieldsUser = result.data;
const user = this.fieldsUser;
@@ -286,7 +285,7 @@ export default {
.catch(this.$fhcAlert.handleSystemError);
this.$api
.call(this.endpoint.getNameOfDefaultRecipients(this.id, this.typeId))
.call(ApiMessages.getNameOfDefaultRecipients(this.id, this.typeId))
.then(result => {
this.defaultRecipients = result.data;
this.defaultRecipientString = Object.values(this.defaultRecipients).join("; ");
@@ -297,7 +296,7 @@ export default {
//case of reply
if(this.messageId) {
this.$api
.call(this.endpoint.getReplyData(this.messageId))
.call(ApiMessages.getReplyData(this.messageId))
.then(result => {
this.replyData = result.data;
this.formData.subject = this.replyData[0].replySubject;
@@ -13,12 +13,6 @@ export default {
DropdownComponent,
},
props: {
/*
endpoint: {
type: Object,
required: true
},
*/
openMode: String,
typeId: String,
id: {
@@ -113,7 +107,6 @@ export default {
if(this.openMode == "inSamePage" && this.id.length == 1 ){
this.$emit('reloadTable');
}
this.resetForm();
}
);
},
@@ -126,10 +119,14 @@ export default {
}).catch(this.$fhcAlert.handleSystemError);
},
getPreviewText(){
console.log("subj" + this.formData.subject);
const data = new FormData();
data.append('data', JSON.stringify(this.formData.body));
data.append('ids', JSON.stringify(this.id));
console.log("subj" + this.formData.subject);
return this.$api
.call(ApiMessages.getPreviewText(
this.typeId, data))
@@ -150,7 +147,7 @@ export default {
this.editor.save();
} else {
console.error("Editor instance is not available.");
console.error(this.$p.t('messages', 'errorEditorNotAvailable'));
}
},
resetForm(){
@@ -182,14 +179,28 @@ export default {
this.isVisible = false;
},
showTemplate(){
if (this.openMode == "inSamePage")
if (this.openMode == "inSamePage") {
this.isVisible = true;
//to enable send newMessage after sentMessage
this.messageSent = false;
}
},
showPreview(){
this.getPreviewText().then(() => {
this.previewBody = this.previewText;
});
},
loadReplyData(messageId){
this.$api
.call(ApiMessages.getReplyData(messageId))
.then(result => {
this.replyData = result.data;
this.formData.subject = this.replyData[0].replySubject;
this.formData.body = this.replyData[0].replyBody;
this.formData.relationmessage_id = messageId;
})
.catch(this.$fhcAlert.handleSystemError);
}
},
watch: {
'formData.body': {
@@ -216,14 +227,12 @@ export default {
const missingparamsmsgs = [];
if(!this.typeId)
{
// TODO(bh) Phrase
missingparamsmsgs.push('Fehlender oder ungültiger Parameter Empfänger-Id-Typ.');
missingparamsmsgs.push(this.$p.t('messages', 'errorMissingOrInvalidParameterRecipientTypeId'));
}
if(!this.id || this.id.length < 1)
{
// TODO(bh) Phrase
missingparamsmsgs.push('Fehlender oder ungültiger Parameter Empfänger-Id(s).');
missingparamsmsgs.push(this.$p.t('messages', 'errorMissingOrInvalidParameterRecipientIds'));
}
if(missingparamsmsgs.length > 0)
@@ -283,7 +292,8 @@ export default {
//case of reply
if(this.messageId != null) {
this.$api
this.loadReplyData(this.messageId);
/* this.$api
.call(ApiMessages.getReplyData(this.messageId))
.then(result => {
this.replyData = result.data;
@@ -291,7 +301,7 @@ export default {
this.formData.body = this.replyData[0].replyBody;
this.formData.relationmessage_id = this.messageId;
})
.catch(this.$fhcAlert.handleSystemError);
.catch(this.$fhcAlert.handleSystemError);*/
}
},
@@ -305,7 +315,7 @@ export default {
<div class="messages-detail-newmessage-newdiv">
<!--new page-->
<div v-if="!messageSent" class="overflow-auto m-3">
<div v-if="!messageSent" ref="divNewMessage" class="overflow-auto m-3">
<h4>{{ $p.t('messages', 'neueNachricht') }}</h4>
<div class="row">
@@ -1,6 +1,8 @@
import {CoreFilterCmpt} from "../../filter/Filter.js";
import FormForm from '../../Form/Form.js';
import ApiMessages from "../../../api/factory/messages/messages.js"
export default {
name: "TableMessages",
components: {
@@ -13,10 +15,6 @@ export default {
},
},
props: {
endpoint: {
type: Object,
required: true
},
typeId: String,
id: {
type: Array,
@@ -281,7 +279,7 @@ export default {
},
deleteMessage(message_id){
return this.$api
.call(this.endpoint.deleteMessage(message_id))
.call(ApiMessages.deleteMessage(message_id))
.then(response => {
this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete'));
}).catch(this.$fhcAlert.handleSystemError)
@@ -347,7 +345,7 @@ export default {
},
loadAjaxCall(url, config, params){
return this.$api.call(
this.endpoint.getMessages(params)
ApiMessages.getMessages(params)
);
}
},
@@ -378,7 +376,7 @@ export default {
type_id: this.typeId
};
this.$api
.call(this.endpoint.getPersonId(params))
.call(ApiMessages.getPersonId(params))
.then(result => {
this.personId = result.data;
})
+11 -11
View File
@@ -14,10 +14,6 @@ export default {
}
},
props: {
endpoint: {
type: Object,
required: true
},
typeId: {
type: String,
required: true,
@@ -74,18 +70,25 @@ export default {
handleMessage(id, typeId, messageId){
this.messageId = messageId;
if (this.openMode == "window") {
//this.$refs['newMsgForm'].submit();
this.openInNewWindow(id, typeId, messageId);
}
else if (this.openMode == "newTab"){
//this.$refs['newMsgForm'].submit();
this.openInNewTab(id, typeId, messageId);
}
else if (this.openMode == "modal"){
if(!messageId)
this.$refs.modalMsg.resetForm();
this.$refs.modalMsg.show();
}
else if (this.openMode == "inSamePage"){
console.log("in same Page");
this.isVisibleDiv = true;
if(messageId)
this.$refs.templateNewDivMessage.loadReplyData(messageId);
else
this.$refs.templateNewDivMessage.resetForm();
this.$refs.templateNewDivMessage.showTemplate();
}
else
console.log("no valid openMode");
@@ -156,7 +159,6 @@ export default {
:type-id="typeId"
:id="id"
:message-id="messageId"
:endpoint="endpoint"
:openMode="openMode"
@reloadTable="reloadTable"
@resetMessageId="resetMessageId"
@@ -164,13 +166,12 @@ export default {
</message-modal>
<!--in same page-->
<div v-if="isVisibleDiv" class="overflow-auto m-3" style="max-height: 500px; border: 1px solid #ccc;">
<div v-show="isVisibleDiv" class="overflow-auto m-3" style="max-height: 500px; border: 1px solid #ccc;">
<form-only
ref="templateNewMessage"
ref="templateNewDivMessage"
:type-id="typeId"
:id="id"
:message-id="messageId"
:endpoint="endpoint"
:openMode="openMode"
@reloadTable="reloadTable"
>
@@ -182,7 +183,6 @@ export default {
ref="templateTableMessage"
:type-id="typeId"
:id="id"
:endpoint="endpoint"
:messageLayout="messageLayout"
:openMode="openMode"
@newMessage="handleMessage"
@@ -1,5 +1,5 @@
import CoreMessages from "../../../Messages/Messages.js";
import ApiMessages from "../../../../api/factory/messages/messages.js";
//import ApiMessages from "../../../../api/factory/messages/messages.js";
export default {
name: "TabMessages",
@@ -11,7 +11,7 @@ export default {
},
data(){
return {
endpoint: ApiMessages
//endpoint: ApiMessages
};
},
computed: {
@@ -36,7 +36,6 @@ export default {
<template v-if="prestudent_ids">
<core-messages
ref="formc"
:endpoint="endpoint"
type-id="prestudent_id"
:id="prestudent_ids"
messageLayout="twoColumnsTableLeft"
@@ -48,7 +47,6 @@ export default {
<template v-else >
<core-messages
ref="formc"
:endpoint="endpoint"
type-id="person_id"
:id="person_ids"
messageLayout="twoColumnsTableLeft"
+102
View File
@@ -52330,6 +52330,108 @@ I have been informed that I am under no obligation to consent to the transmissio
)
),
// ### Personen zusammenlegen Phrasen END
// ### Refactor Messages START
array(
'app' => 'core',
'category' => 'ui',
'phrase' => 'errorMissingOrInvalidParameterRecipientTypeId',
'insertvon' => 'system',
'phrases' => array(
array(
'sprache' => 'German',
'text' => 'Fehlender oder ungültiger Parameter Type_ID Empfänger',
'description' => '',
'insertvon' => 'system'
),
array(
'sprache' => 'English',
'text' => 'Missing or invalid parameter type ID Recipient',
'description' => '',
'insertvon' => 'system'
)
)
),
array(
'app' => 'core',
'category' => 'ui',
'phrase' => 'errorMissingOrInvalidParameterRecipientIds',
'insertvon' => 'system',
'phrases' => array(
array(
'sprache' => 'German',
'text' => 'Fehlende(r) oder ungültige(r) Parameter Empfänger-Id(s)',
'description' => '',
'insertvon' => 'system'
),
array(
'sprache' => 'English',
'text' => 'Missing or invalid parameter(s) Recipient ID(s)',
'description' => '',
'insertvon' => 'system'
)
)
),
array(
'app' => 'core',
'category' => 'ui',
'phrase' => 'errorMissingOrInvalidParameters',
'insertvon' => 'system',
'phrases' => array(
array(
'sprache' => 'German',
'text' => 'Fehlende(r) oder ungültige(r) Parameter {parameter}',
'description' => '',
'insertvon' => 'system'
),
array(
'sprache' => 'English',
'text' => 'Missing or invalid parameter(s) {parameter}',
'description' => '',
'insertvon' => 'system'
)
)
),
array(
'app' => 'core',
'category' => 'messages',
'phrase' => 'errorEditorNotAvailable',
'insertvon' => 'system',
'phrases' => array(
array(
'sprache' => 'German',
'text' => 'Editor-Instanz nicht verfügbar.',
'description' => '',
'insertvon' => 'system'
),
array(
'sprache' => 'English',
'text' => 'Editor instance is not available.',
'description' => '',
'insertvon' => 'system'
)
)
),
array(
'app' => 'core',
'category' => 'messages',
'phrase' => 'error_missingLogic',
'insertvon' => 'system',
'phrases' => array(
array(
'sprache' => 'German',
'text' => 'Logik für Type ID {type} nicht implementiert.',
'description' => '',
'insertvon' => 'system'
),
array(
'sprache' => 'English',
'text' => 'logic for type ID {type} not implemented.',
'description' => '',
'insertvon' => 'system'
)
)
),
// ### Refactor Messages END
);