mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-02 19:39:27 +00:00
Reply functionality and Pagination
This commit is contained in:
@@ -23,7 +23,7 @@ class NeueNachricht extends Auth_Controller
|
||||
//now working
|
||||
$this->load->view('Nachrichten', [
|
||||
'permissions' => [
|
||||
'vertragsverwaltung_schreibrechte' => $this->permissionlib->isBerechtigt('vertrag/mitarbeiter', 'suid')
|
||||
'assistenz_schreibrechte' => $this->permissionlib->isBerechtigt('assistenz','suid'),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ class Messages extends FHCAPI_Controller
|
||||
'deleteMessage' => ['admin:r', 'assistenz:r'],
|
||||
'getVorlagentext' => ['admin:r', 'assistenz:r'],
|
||||
'getPreviewText' => ['admin:r', 'assistenz:r'],
|
||||
'getReplyData' => ['admin:r', 'assistenz:r'],
|
||||
'getPersonIdFromUid' => ['admin:r', 'assistenz:r'],
|
||||
]);
|
||||
|
||||
//Load Models
|
||||
@@ -70,8 +72,6 @@ class Messages extends FHCAPI_Controller
|
||||
$data = $this->getDataOrTerminateWithError($result);
|
||||
$oe_kurzbz = current($data);
|
||||
|
||||
// $this->terminateWithError("oe: ". $oe_kurzbz->oe_kurzbz, self::ERROR_TYPE_GENERAL);
|
||||
|
||||
$this->load->model('system/Vorlage_model', 'VorlageModel');
|
||||
|
||||
//39 Stück Variante OE
|
||||
@@ -129,11 +129,8 @@ class Messages extends FHCAPI_Controller
|
||||
|
||||
public function getMsgVarsPrestudent($uid)
|
||||
{
|
||||
//$this->terminateWithError($uid, self::ERROR_TYPE_GENERAL);
|
||||
$prestudent_id = $this-> _getPrestudentIdFromUid($uid);
|
||||
|
||||
// $this->terminateWithError("prestudent_id " . $prestudent_id, self::ERROR_TYPE_GENERAL);
|
||||
|
||||
$result = $this->MessageModel->getMsgVarsDataByPrestudentId($prestudent_id);
|
||||
|
||||
$data = $this->getDataOrTerminateWithError($result);
|
||||
@@ -290,6 +287,46 @@ class Messages extends FHCAPI_Controller
|
||||
$this->terminateWithSuccess($bodyParsed);
|
||||
}
|
||||
|
||||
public function getReplyData($messageId)
|
||||
{
|
||||
// return $this->terminateWithError("in get ReplyBody" . $messageId, self::ERROR_TYPE_GENERAL);
|
||||
//TODO(Manu) validation of messageId: if number
|
||||
|
||||
|
||||
$this->MessageModel->addSelect('public.tbl_msg_message.*');
|
||||
$this->MessageModel->addSelect('r.*');
|
||||
$this->MessageModel->addSelect('p.nachname');
|
||||
$this->MessageModel->addSelect('p.vorname');
|
||||
$this->MessageModel->addJoin('public.tbl_msg_recipient r', 'ON (r.message_id = public.tbl_msg_message.message_id)');
|
||||
$this->MessageModel->addJoin('public.tbl_person p', 'ON (p.person_id = public.tbl_msg_message.person_id)');
|
||||
|
||||
$result = $this->MessageModel->loadWhere(
|
||||
array('r.message_id' => $messageId)
|
||||
);
|
||||
|
||||
// $this->terminateWithSuccess((getData($result) ?: []));
|
||||
$dataMessage = $this->getDataOrTerminateWithError($result);
|
||||
|
||||
$prefix = "Re: "; // reply subject prefix
|
||||
|
||||
/* $body = current($dataMessage->body);
|
||||
$subject = $dataMessage->subject;*/
|
||||
|
||||
$subject = $dataMessage[0]->subject;
|
||||
$body = $dataMessage[0]->body;
|
||||
|
||||
|
||||
$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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function deleteMessage($messageId)
|
||||
{
|
||||
// Start DB transaction
|
||||
@@ -298,7 +335,7 @@ class Messages extends FHCAPI_Controller
|
||||
$result = $this->MessageModel->deleteMessageRecipient($messageId);
|
||||
if (isError($result)) {
|
||||
return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
|
||||
return $this->terminateWithError($result, self::ERROR_TYPE_GENERAL);
|
||||
|
||||
}
|
||||
|
||||
$result = $this->MessageModel->deleteMessageStatus($messageId);
|
||||
@@ -316,6 +353,19 @@ class Messages extends FHCAPI_Controller
|
||||
$this->terminateWithSuccess($result);
|
||||
}
|
||||
|
||||
public function getPersonIdFromUid($uid)
|
||||
{
|
||||
$this->load->model('person/Benutzer_model', 'BenutzerModel');
|
||||
$result = $this->BenutzerModel->loadWhere(
|
||||
['uid' => $uid]
|
||||
);
|
||||
|
||||
$data = $this->getDataOrTerminateWithError($result);
|
||||
$benutzer = current($data);
|
||||
|
||||
$this->terminateWithSuccess($benutzer->person_id);
|
||||
}
|
||||
|
||||
private function _getPersonIdFromUid($uid)
|
||||
{
|
||||
$this->load->model('person/Benutzer_model', 'BenutzerModel');
|
||||
@@ -326,7 +376,6 @@ class Messages extends FHCAPI_Controller
|
||||
$data = $this->getDataOrTerminateWithError($result);
|
||||
$benutzer = current($data);
|
||||
|
||||
//return $data->person_id;
|
||||
return $benutzer->person_id;
|
||||
}
|
||||
|
||||
@@ -342,4 +391,23 @@ class Messages extends FHCAPI_Controller
|
||||
|
||||
return $student->prestudent_id;
|
||||
}
|
||||
|
||||
private function _getReplyBody($body, $receiverName, $receiverSurname, $sentDate)
|
||||
{
|
||||
// To quote a reply body message
|
||||
$bodyFormat = "<br>
|
||||
<br>
|
||||
<blockquote>
|
||||
<i>
|
||||
On %s %s %s wrote:
|
||||
</i>
|
||||
</blockquote>
|
||||
<blockquote style='border-left:2px solid; padding-left: 8px'>
|
||||
%s
|
||||
</blockquote>";
|
||||
return sprintf(
|
||||
$bodyFormat,
|
||||
date_format(date_create($sentDate), 'd.m.Y H:i'), $receiverName, $receiverSurname, $body
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -275,7 +275,7 @@ 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
|
||||
ORDER BY insertamum DESC
|
||||
";
|
||||
|
||||
$parametersArray = array($person_id, $person_id);
|
||||
@@ -287,7 +287,7 @@ class Message_model extends DB_Model
|
||||
* Deletes a messages from tableMessages and tbl_msg_recipient
|
||||
* TODO(MANU) CHECK IF NECESSARY
|
||||
* dependency with other tables
|
||||
* in case of reply... more messages
|
||||
* in case of reply... more messages?? delete all dependent ones?
|
||||
* maybe anonimize it
|
||||
* @param $message_id
|
||||
* @return boolean success
|
||||
|
||||
@@ -14,6 +14,9 @@ export default {
|
||||
getMsgVarsPrestudent(uid){
|
||||
return this.$fhcApi.get('api/frontend/v1/messages/messages/getMsgVarsPrestudent/' + uid);
|
||||
},
|
||||
getPersonIdFromUid(uid){
|
||||
return this.$fhcApi.get('api/frontend/v1/messages/messages/getPersonIdFromUid/' + uid);
|
||||
},
|
||||
getVorlagentext(vorlage_kurzbz){
|
||||
return this.$fhcApi.get('api/frontend/v1/messages/messages/getVorlagentext/' + vorlage_kurzbz);
|
||||
},
|
||||
@@ -24,6 +27,10 @@ export default {
|
||||
return this.$fhcApi.post('api/frontend/v1/messages/messages/getPreviewText/' + params.id + '/' + params.type_id,
|
||||
data);
|
||||
},
|
||||
getReplyData(messageId){
|
||||
return this.$fhcApi.get('api/frontend/v1/messages/messages/getReplyData/' + messageId);
|
||||
|
||||
},
|
||||
sendMessage(form, id, data) {
|
||||
return this.$fhcApi.post(form,'api/frontend/v1/messages/messages/sendMessage/' + id,
|
||||
data);
|
||||
|
||||
@@ -8,6 +8,7 @@ const router = VueRouter.createRouter({
|
||||
history: VueRouter.createWebHistory(),
|
||||
routes: [
|
||||
{ path: `/${ciPath}/NeueNachricht/:id/:typeId`, component: NewMessage },
|
||||
{ path: `/${ciPath}/NeueNachricht/:id/:typeId/:messageId`, component: NewMessage },
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@ export default {
|
||||
},
|
||||
typeId(){
|
||||
return this.$route.params.typeId || this.$props.id;
|
||||
},
|
||||
messageId(){
|
||||
return this.$route.params.messageId;
|
||||
}
|
||||
},
|
||||
data(){
|
||||
@@ -62,7 +65,8 @@ export default {
|
||||
itemsPerson: [],
|
||||
itemsUser: [],
|
||||
previewText: null,
|
||||
previewBody: ""
|
||||
previewBody: "",
|
||||
replyData: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -179,9 +183,9 @@ export default {
|
||||
console.error("Editor instance is not available.");
|
||||
}
|
||||
},
|
||||
replyMessage(message_id){
|
||||
/* replyMessage(message_id){
|
||||
console.log("auf message " + message_id + " antworten");
|
||||
},
|
||||
},*/
|
||||
resetForm(){
|
||||
this.formData = {
|
||||
vorlage_kurzbz: null,
|
||||
@@ -293,6 +297,19 @@ export default {
|
||||
})
|
||||
.catch(this.$fhcAlert.handleSystemError);
|
||||
|
||||
if(this.messageId != null) {
|
||||
|
||||
//get replayBody.. body receivername, receiverSurname, sentDate of message
|
||||
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;
|
||||
})
|
||||
.catch(this.$fhcAlert.handleSystemError);
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
async mounted() {
|
||||
this.initTinyMCE();
|
||||
@@ -309,13 +326,7 @@ export default {
|
||||
|
||||
<!--new page-->
|
||||
<div class="overflow-auto m-3">
|
||||
|
||||
{{id}} || {{typeId}}
|
||||
|
||||
<h4>New Message</h4>
|
||||
<!-- {{formData.body}}
|
||||
||
|
||||
{{previewText}}-->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-8">
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {CoreFilterCmpt} from "../../filter/Filter.js";
|
||||
import FormForm from '../../Form/Form.js';
|
||||
import NewMessage from "../Details/NewMessage.js";
|
||||
//import NewMessage from "../Details/NewMessage.js";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
CoreFilterCmpt,
|
||||
FormForm,
|
||||
NewMessage,
|
||||
// NewMessage,
|
||||
},
|
||||
inject: {
|
||||
cisRoot: {
|
||||
@@ -110,13 +110,15 @@ export default {
|
||||
container.className = "d-flex gap-2";
|
||||
|
||||
let button = document.createElement('button');
|
||||
if (this.personId != cell.getData().recipient_id)
|
||||
button.disabled = true;
|
||||
button.className = 'btn btn-outline-secondary btn-action';
|
||||
button.title = this.$p.t('global', 'reply');
|
||||
button.innerHTML = '<i class="fa fa-reply"></i>';
|
||||
button.addEventListener(
|
||||
'click',
|
||||
(event) =>
|
||||
this.reply(cell.getData().message_id)
|
||||
this.actionReplyToMessage(cell.getData().message_id)
|
||||
);
|
||||
container.append(button);
|
||||
|
||||
@@ -141,6 +143,8 @@ export default {
|
||||
height: '400',
|
||||
selectable: true,
|
||||
selectableRangeMode: 'click',
|
||||
pagination: true,
|
||||
// paginationSize: 5,
|
||||
/* layoutColumnsOnNewData: false,
|
||||
|
||||
selectableRangeMode: 'click',
|
||||
@@ -208,13 +212,11 @@ export default {
|
||||
],
|
||||
tabulatorData: [],
|
||||
previewBody: "",
|
||||
open: false
|
||||
open: false,
|
||||
personId: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
reply(message_id){
|
||||
console.log("in reply " + message_id);
|
||||
},
|
||||
actionDeleteMessage(message_id){
|
||||
this.$fhcAlert
|
||||
.confirmDelete()
|
||||
@@ -225,7 +227,6 @@ export default {
|
||||
.catch(this.$fhcAlert.handleSystemError);
|
||||
},
|
||||
deleteMessage(message_id){
|
||||
// console.log("deleteMessage " + message_id);
|
||||
return this.$fhcApi.factory.messages.person.deleteMessage(message_id)
|
||||
.then(response => {
|
||||
this.$fhcAlert.alertSuccess(this.$p.t('ui', 'successDelete'));
|
||||
@@ -240,6 +241,9 @@ export default {
|
||||
//console.log("action new message");
|
||||
|
||||
},
|
||||
actionReplyToMessage(message_id){
|
||||
this.$emit('replyToMessage', this.id, this.typeId, message_id);
|
||||
},
|
||||
reload() {
|
||||
this.$refs.table.reloadTable();
|
||||
},
|
||||
@@ -264,6 +268,15 @@ export default {
|
||||
});
|
||||
});*/
|
||||
},
|
||||
created(){
|
||||
if(this.typeId == 'uid') {
|
||||
this.$fhcApi.factory.messages.person.getPersonIdFromUid(this.id)
|
||||
.then(result => {
|
||||
this.personId = result.data;
|
||||
})
|
||||
.catch(this.$fhcAlert.handleSystemError);
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<div class="messages-detail-table">
|
||||
|
||||
|
||||
@@ -76,6 +76,23 @@ export default {
|
||||
else
|
||||
console.log("no valid openMode");
|
||||
},
|
||||
handleMessage(id, typeId, messageId){
|
||||
console.log("in handleMessage " + messageId);
|
||||
if (this.openMode == "window") {
|
||||
this.openInNewWindow(id, typeId, messageId);
|
||||
}
|
||||
else if (this.openMode == "newTab"){
|
||||
this.openInNewTab(id, typeId, messageId);
|
||||
}
|
||||
else if (this.openMode == "modal"){
|
||||
this.openInModal(id, typeId, messageId);
|
||||
}
|
||||
else if (this.openMode == "showDiv"){
|
||||
this.$refs.templateNewMessage.showTemplate(id, typeId, messageId);
|
||||
}
|
||||
else
|
||||
console.log("no valid openMode");
|
||||
},
|
||||
openInDiv(id, typeId){
|
||||
this.$refs.templateNewMessage.showTemplate(id, typeId);
|
||||
//this.showDiv = true; //local variante
|
||||
@@ -85,15 +102,26 @@ export default {
|
||||
//TODO(manu) define bs-modal in this component
|
||||
this.$refs.templateNewMessage.$refs.modalMsg.show();
|
||||
},
|
||||
openInNewTab(id, typeId){
|
||||
/* openInNewTab(id, typeId){
|
||||
//TODO(MANU) check if array of ids...
|
||||
/* let path = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router;
|
||||
path += "/NeueNachricht/" + this.id + "/" + this.typeId;*/
|
||||
|
||||
//als param
|
||||
let path = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router;
|
||||
path += "/NeueNachricht/" + id + "/" + typeId;
|
||||
|
||||
const newTab = window.open(path, "_blank");
|
||||
},*/
|
||||
openInNewTab(id, typeId, messageId=null){
|
||||
//TODO(MANU) check if array of ids...
|
||||
let path = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router;
|
||||
|
||||
if (messageId){
|
||||
path += "/NeueNachricht/" + id + "/" + typeId + "/" + messageId;
|
||||
}
|
||||
|
||||
else {
|
||||
path += "/NeueNachricht/" + id + "/" + typeId;
|
||||
}
|
||||
|
||||
|
||||
const newTab = window.open(path, "_blank");
|
||||
},
|
||||
openInNewWindow(id, typeId){
|
||||
@@ -152,7 +180,8 @@ export default {
|
||||
:endpoint="endpoint"
|
||||
:messageLayout="messageLayout"
|
||||
:openMode="openMode"
|
||||
@newMessage="newMessage"
|
||||
@newMessage="newMessage"
|
||||
@replyToMessage="handleMessage"
|
||||
>
|
||||
|
||||
</table-messages>
|
||||
|
||||
Reference in New Issue
Block a user