From a0ce635c7eb60460cd8075c7f208d9f721979e3d Mon Sep 17 00:00:00 2001 From: ma0068 Date: Wed, 12 Mar 2025 15:04:37 +0100 Subject: [PATCH] Refactor and Cleanup - adapt tabulator and queries for remote pagination - use formatterParams for messageStati to enable phrase logic - adapt logic for mitarbeiter_uid - refactor logic to use new Page, new Tab and newDiv with one child component - add phrases --- .../api/frontend/v1/messages/Messages.php | 59 +++++-- application/models/system/Message_model.php | 62 ++++++-- public/js/api/messages/person.js | 14 +- .../{NewMessage.js => Depr_NewMessage.js} | 0 .../Messages/Details/NewMessage/Modal.js | 148 +++++++++++++----- .../Messages/Details/NewMessage/NewDiv.js | 116 +++++++------- .../Messages/Details/TableMessages.js | 108 ++++--------- public/js/components/Messages/Messages.js | 140 +++++++---------- .../Studentenverwaltung/Details/Messages.js | 31 +++- system/phrasesupdate.php | 80 ++++++++++ 10 files changed, 459 insertions(+), 299 deletions(-) rename public/js/components/Messages/Details/{NewMessage.js => Depr_NewMessage.js} (100%) diff --git a/application/controllers/api/frontend/v1/messages/Messages.php b/application/controllers/api/frontend/v1/messages/Messages.php index 65c354c4f..7834ba5f7 100644 --- a/application/controllers/api/frontend/v1/messages/Messages.php +++ b/application/controllers/api/frontend/v1/messages/Messages.php @@ -41,17 +41,27 @@ class Messages extends FHCAPI_Controller ]); } - public function getMessages($id, $type_id) + public function getMessages($id, $type_id, $size, $page) { if($type_id != 'person_id'){ $id = $this->_getPersonId($id, $type_id); } - $result = $this->MessageModel->getMessagesForTable($id); + $offset = $size * ($page - 1); + $limit = $size; + + $result = $this->MessageModel->getMessagesForTable($id, $offset, $limit); $data = $this->getDataOrTerminateWithError($result); - $this->terminateWithSuccess($data); + //return null if count == 0 + if($data['count'] == 0){ + $this->terminateWithSuccess([]); + } + + $this->addMeta('count', $data['count']); + + $this->terminateWithSuccess($data['data']); } public function getVorlagen() @@ -107,9 +117,10 @@ class Messages extends FHCAPI_Controller $this->terminateWithSuccess($vorlage->text); } - public function getMessageVarsPerson() + public function getMessageVarsPerson($id, $typeId) { - $result = $this->MessageModel->getMessageVarsPerson(); + $person_id = ($typeId == 'mitarbeiter_uid') ? $this->_getPersonId($id, $typeId) : $id; + $result = $this->MessageModel->getMessageVarsPerson($person_id); $data = $this->getDataOrTerminateWithError($result); @@ -119,7 +130,7 @@ class Messages extends FHCAPI_Controller public function getMsgVarsPrestudent($id, $typeId) { - $prestudent_id = ($typeId == 'prestudent_id') ? $id : $this->_getPrestudentIdFromUid($id); + $prestudent_id = ($typeId == 'uid') ? $this->_getPrestudentIdFromUid($id) : $id; $result = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id); @@ -138,7 +149,7 @@ class Messages extends FHCAPI_Controller public function getNameOfDefaultRecipient($id, $type_id) { - $id = $type_id!='person_id)' ? $this->_getPersonId($id, $type_id) : $id; + $id = ($type_id != 'person_id') ? $this->_getPersonId($id, $type_id) : $id; $this->load->model('person/Person_model', 'PersonModel'); @@ -151,8 +162,8 @@ class Messages extends FHCAPI_Controller public function sendMessage($recipient_id) { - //is always uid in FAS - //TODO(Manu) make dynamic for other ids + //has to be uid + // $this->terminateWithError("uid", $recipient_id, self::ERROR_TYPE_GENERAL); //default setting $receiversPersonId = $this->_getPersonId($recipient_id, 'uid'); @@ -205,10 +216,17 @@ class Messages extends FHCAPI_Controller $result = $this->MessagesModel->parseMessageTextPrestudent($prestudent_id, $body); $bodyParsed = $this->getDataOrTerminateWithError($result); } + if($typeId == 'mitarbeiter_uid') + { + $person_id = $this->_getPersonId($id, $typeId); + + $result = $this->MessagesModel->parseMessageTextPerson($person_id, $body); + $bodyParsed = $this->getDataOrTerminateWithError($result); + $this->terminateWithError($bodyParsed, self::ERROR_TYPE_GENERAL); + + } elseif($typeId == 'person_id') { - $this->terminateWithError("person_id ", self::ERROR_TYPE_GENERAL); - $result = $this->MessagesModel->parseMessageTextPerson($id, $body); $bodyParsed = $this->getDataOrTerminateWithError($result); } @@ -235,7 +253,6 @@ class Messages extends FHCAPI_Controller { $data = json_decode($_POST['data']); unset($_POST['data']); - } else $this->terminateWithError("Textbody missing ", self::ERROR_TYPE_GENERAL); @@ -249,6 +266,15 @@ class Messages extends FHCAPI_Controller case 'prestudent_id': $result = $this->MessagesModel->parseMessageTextPrestudent($id, $data); break; + case 'person_id': + $result = $this->MessagesModel->parseMessageTextPerson($id, $data); + break; + case 'mitarbeiter_uid': + { + $person_id = $this->_getPersonId($id, $type_id); + $result = $this->MessagesModel->parseMessageTextPerson($person_id, $data); + } + break; default: $this->terminateWithError("MESSAGES::getPreviewText logic for type_id " . $type_id . " not defined yet", self::ERROR_TYPE_GENERAL); break; @@ -318,7 +344,7 @@ class Messages extends FHCAPI_Controller public function getPersonId($id, $typeId) { - if ($typeId == 'uid') + if ($typeId == 'uid' || $typeId == 'mitarbeiter_uid') { $this->load->model('person/Benutzer_model', 'BenutzerModel'); $result = $this->BenutzerModel->loadWhere( @@ -368,7 +394,7 @@ class Messages extends FHCAPI_Controller ['person_id' => $person_id] ); } - elseif($typeId == 'uid') + elseif($typeId == 'uid' || $typeId == 'mitarbeiter_uid') { $this->terminateWithSuccess($id); } @@ -385,7 +411,7 @@ class Messages extends FHCAPI_Controller private function _getPersonId($id, $typeId) { - if ($typeId == 'uid') + if ($typeId == 'uid' || $typeId == 'mitarbeiter_uid') { $this->load->model('person/Benutzer_model', 'BenutzerModel'); $result = $this->BenutzerModel->loadWhere( @@ -408,6 +434,7 @@ 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] @@ -415,7 +442,7 @@ class Messages extends FHCAPI_Controller $data = $this->getDataOrTerminateWithError($result); $student = current($data); - + // $this->terminateWithError($student->prestudent_id, self::ERROR_TYPE_GENERAL); return $student->prestudent_id; } diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 38defa383..acbe3a44c 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -234,12 +234,15 @@ class Message_model extends DB_Model /** * Gets messages for a person for tableMessages. * @param $person_id - * @param null $status message status. by default, latest status is returned + * paginationInitialPage: 1, + * @param $offset number to skip, calculated by tabulatorParam paginationInitialPage and paginationSize, refers to specified numer of skipped items + * and page + * @param $limit refers to tabulatorParam paginationSize * @return array|null */ - public function getMessagesForTable($person_id, $status = null) + public function getMessagesForTable($person_id, $offset, $limit) { - $sql = " + $sql_base = " SELECT m.message_id AS message_id, m.subject AS subject, @@ -275,20 +278,45 @@ class Message_model extends DB_Model JOIN public.tbl_msg_message m USING(message_id) WHERE r.person_id = ? GROUP BY m.message_id, m.subject, m.body, m.insertamum, m.relationmessage_id, sender, recipient, sender_id, recipient_id - ORDER BY insertamum DESC + "; + $sql = " + SELECT COUNT(*) AS count FROM ( + " . $sql_base . " + ) a "; $parametersArray = array($person_id, $person_id); - return $this->execQuery($sql, $parametersArray); + $count = $this->execQuery($sql, $parametersArray); + + if (isError($count)) + return $count; + + $count = floor(current(getData($count))->count/$limit); + $sql = " + SELECT * FROM ( + " . $sql_base . " + ) a + ORDER BY insertamum DESC + LIMIT ? + OFFSET ? + "; + + $parametersArray = array($person_id, $person_id, $limit, $offset); + + $data = $this->execQuery($sql, $parametersArray); + + if (isError($data)) + return $data; + + $data = getData($data); + + return success(['data' => $data, 'count' => $count]); } /** - * Deletes a messages from tableMessages and tbl_msg_recipient - * TODO(MANU) CHECK IF NECESSARY - * dependency with other tables - * in case of reply... more messages?? delete all dependent ones? - * maybe anonimize it + * Deletes entry in dependency table tbl_msg_recipient + * * @param $message_id * @return boolean success */ @@ -302,7 +330,12 @@ class Message_model extends DB_Model return $this->execQuery($sql, array($message_id)); } - + /** + * Deletes entry in dependency table tbl_msg_status + * + * @param $message_id + * @return boolean success + */ public function deleteMessageStatus($message_id) { $sql = " @@ -312,7 +345,12 @@ class Message_model extends DB_Model return $this->execQuery($sql, array($message_id)); } - + /** + * Deletes entry in dependency table tbl_msg_message + * + * @param $message_id + * @return boolean success + */ public function deleteMessage($message_id) { $sql = " diff --git a/public/js/api/messages/person.js b/public/js/api/messages/person.js index e53f23f6a..6fa39c6ba 100644 --- a/public/js/api/messages/person.js +++ b/public/js/api/messages/person.js @@ -1,6 +1,7 @@ export default { - getMessages(url, config, params){ - return this.$fhcApi.get('api/frontend/v1/messages/messages/getMessages/' + params.id + '/' + params.type); + getMessages(url, config, params) { + console.log('page ' + params.page + ' size ' + params.size); + return this.$fhcApi.get('api/frontend/v1/messages/messages/getMessages/' + params.id + '/' + params.type + '/' + params.size + '/' + params.page); }, getVorlagen(){ return this.$fhcApi.get('api/frontend/v1/messages/messages/getVorlagen/'); @@ -8,8 +9,8 @@ export default { getMsgVarsLoggedInUser(){ return this.$fhcApi.get('api/frontend/v1/messages/messages/getMsgVarsLoggedInUser/'); }, - getMessageVarsPerson(){ - return this.$fhcApi.get('api/frontend/v1/messages/messages/getMessageVarsPerson/'); + getMessageVarsPerson(params){ + return this.$fhcApi.get('api/frontend/v1/messages/messages/getMessageVarsPerson/' + params.id + '/' + params.type_id); }, getMsgVarsPrestudent(params){ return this.$fhcApi.get('api/frontend/v1/messages/messages/getMsgVarsPrestudent/' + params.id + '/' + params.type_id); @@ -34,9 +35,14 @@ export default { return this.$fhcApi.get('api/frontend/v1/messages/messages/getReplyData/' + messageId); }, sendMessage(form, id, data) { + console.log("id" + id); return this.$fhcApi.post(form,'api/frontend/v1/messages/messages/sendMessage/' + id, data); }, +/* sendMessage(id, data) { + return this.$fhcApi.post('api/frontend/v1/messages/messages/sendMessage/' + id, + data); + },*/ deleteMessage(messageId){ return this.$fhcApi.post('api/frontend/v1/messages/messages/deleteMessage/' + messageId); } diff --git a/public/js/components/Messages/Details/NewMessage.js b/public/js/components/Messages/Details/Depr_NewMessage.js similarity index 100% rename from public/js/components/Messages/Details/NewMessage.js rename to public/js/components/Messages/Details/Depr_NewMessage.js diff --git a/public/js/components/Messages/Details/NewMessage/Modal.js b/public/js/components/Messages/Details/NewMessage/Modal.js index 9bfe49929..c6d3e1210 100644 --- a/public/js/components/Messages/Details/NewMessage/Modal.js +++ b/public/js/components/Messages/Details/NewMessage/Modal.js @@ -22,19 +22,25 @@ export default { type: [Number, String], required: true }, + messageId: { + type: Number, + required: false, + }, openMode: String, }, data(){ return { formData: { - recipient: this.id, + recipient: null, subject: null, body: null, vorlage_kurzbz: null, selectedValue: '', + relationmessage_id: null }, statusNew: true, vorlagen: [], + recipientsArray: [], defaultRecipient: null, editor: null, fieldsUser: [], @@ -47,7 +53,9 @@ export default { itemsPerson: [], itemsUser: [], previewText: null, - previewBody: "" + previewBody: "", + replyData: null, + uid: null, } }, methods: { @@ -98,12 +106,14 @@ export default { return this.$fhcApi.factory.messages.person.sendMessage( this.$refs.formMessage, - this.id, + this.uid, data) +/* return this.$fhcApi.factory.messages.person.sendMessage( + this.uid, + data)*/ .then(response => { this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent')); - //this.hideModal('messageModal'); - this.hideTemplate(); + this.hideModal('modalNewMessage'); this.resetForm(); }).catch(this.$fhcAlert.handleSystemError) .finally(() => { @@ -119,7 +129,7 @@ export default { return this.$fhcApi.factory.messages.person.getVorlagentext(vorlage_kurzbz) .then(response => { //this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successSent')); - //this.hideModal('messageModal'); + //this.hideModal('modalNewMessage'); //this.resetForm(); //TODO(Manu) CHECK this.formData.body = response.data; @@ -165,20 +175,22 @@ export default { console.error("Editor instance is not available."); } }, - replyMessage(message_id){ - console.log("auf message " + message_id + " antworten"); - }, resetForm(){ this.formData = { vorlage_kurzbz: null, body: null, subject: null, }; + this.$emit('resetMessageId'); + if (this.editor) { this.editor.setContent(""); } + this.$refs.dropdownComp.setValue(null); + this.previewBody = null; + }, handleSelectedVorlage(vorlage_kurzbz) { if (typeof vorlage_kurzbz === "string") { @@ -186,22 +198,28 @@ export default { this.formData.subject = vorlage_kurzbz; } }, - hideTemplate(){ - if (this.openMode == "showDiv") - this.isVisible = false; - }, - showTemplate(){ - if (this.openMode == "showDiv") - this.isVisible = true; - }, showPreview(){ this.getPreviewText().then(() => { this.previewBody = this.previewText; }); }, + getUid(id, typeId){ + const params = { + id: id, + type_id: typeId + }; + this.$fhcApi.factory.messages.person.getUid(params) + .then(result => { + this.uid = result.data; + }) + .catch(this.$fhcAlert.handleSystemError); + }, show(){ this.$refs.modalNewMessage.show(); - } + }, + hideModal(modalRef){ + this.$refs[modalRef].hide(); + }, }, watch: { 'formData.body': { @@ -223,11 +241,37 @@ export default { return this.getVorlagentext(newVal); } } + }, + messageId: { + immediate: true, + handler: async function (newMessageId) { + if (!newMessageId) return; + + try { + const result = await this.$fhcApi.factory.messages.person.getReplyData(newMessageId); + this.replyData = result.data; + console.log(this.replyData); + + if (this.replyData.length > 0) { + this.formData.subject = this.replyData[0].replySubject; + this.formData.body = this.replyData[0].replyBody; + this.formData.relationmessage_id = newMessageId; + } + } catch (error) { + this.$fhcAlert.handleSystemError(error); + } + } } }, created(){ - if(this.typeId == 'person_id'){ - this.$fhcApi.factory.messages.person.getMessageVarsPerson() + this.getUid(this.id, this.typeId); + + if(this.typeId == 'person_id' || this.typeId == 'mitarbeiter_uid'){ + const params = { + id: this.id, + type_id: this.typeId + }; + this.$fhcApi.factory.messages.person.getMessageVarsPerson(params) .then(result => { this.fieldsPerson = result.data; this.itemsPerson = Object.entries(this.fieldsPerson).map(([key, value]) => ({ @@ -237,16 +281,16 @@ export default { }) .catch(this.$fhcAlert.handleSystemError); } - if(this.typeId == 'uid') { - this.$fhcApi.factory.messages.person.getMsgVarsPrestudent(this.id) + + if(this.typeId == 'prestudent_id' || this.typeId == 'uid'){ + const params = { + id: this.id, + type_id: this.typeId + }; + this.$fhcApi.factory.messages.person.getMsgVarsPrestudent(params) .then(result => { this.fieldsPrestudent = result.data; const prestudent = this.fieldsPrestudent[0]; - //Just for testing with inserting values - /* this.itemsPrestudent = Object.entries(prestudent).map(([key, value]) => ({ - label: key, - value: value - }));*/ this.itemsPrestudent = Object.entries(prestudent).map(([key, value]) => ({ label: key.toLowerCase(), value: '{' + key.toLowerCase() + '}' @@ -271,8 +315,25 @@ export default { type_id: this.typeId}) .then(result => { this.defaultRecipient = result.data; + // console.log("check " + this.uid + "|" + this.defaultRecipient); + this.recipientsArray.push({ + 'uid': this.uid, + 'details': this.defaultRecipient}); + // console.log(JSON.stringify(this.recipientsArray)); }) .catch(this.$fhcAlert.handleSystemError); + + //case of reply + if(this.messageId) { + this.$fhcApi.factory.messages.person.getReplyData(this.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 = this.messageId; + }) + .catch(this.$fhcAlert.handleSystemError); + } }, async mounted() { this.initTinyMCE(); @@ -281,10 +342,15 @@ export default { this.editor.destroy(); }, template: ` - + @@ -296,7 +362,6 @@ export default {
-
- Felder Prestudent + {{$p.t('ui', 'felder')}} {{$p.t('lehre', 'prestudent')}}
- -

{{selectedFieldPrestudent}}

-
@@ -387,12 +449,10 @@ export default {
- -

{{selectedFieldPerson}}

- Meine Felder + {{$p.t('messages', 'meineFelder')}}
-
@@ -417,7 +476,7 @@ export default {
-

Vorschau:

+

{{ $p.t('global', 'vorschau') }}:

@@ -428,12 +487,19 @@ export default { :label="$p.t('messages/recipient')" v-model="defaultRecipient" > + +

- +
@@ -454,7 +520,7 @@ export default {