Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,269 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* NotificationManagement - Notification Overview Dialog
|
||||
*
|
||||
* Created by Mike Lennart Wille, ESZS, 2025-06-17
|
||||
*/
|
||||
|
||||
#include "nom_dialog.h"
|
||||
#include <ui_nom_dialog.h>
|
||||
|
||||
#include "nom_dialog_model.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QTextBrowser>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <LtsWidgets/lts_events.h>
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
#include <LtsWidgets/lts_base_layout_widget.h>
|
||||
#include <LtsWidgets/lts_events.h>
|
||||
#include <Plugins/NotificationManagement/nom_data_plugin_interface.h>
|
||||
|
||||
namespace NotificationManagement
|
||||
{
|
||||
|
||||
NotificationManagementDialog::NotificationManagementDialog(LtsSession::LtsSession *session, const QString &menuGroup, QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
||||
, m_model(new NotificationManagementDialogModel(this))
|
||||
, m_ui(new Ui::NotificationManagementDialog)
|
||||
, m_session(session)
|
||||
, m_menuGroup(menuGroup)
|
||||
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
||||
, m_logger(getLogger("NotificationManagementDialog"))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->widget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
setOnlineHelpFilename(QStringLiteral("Administrator-Notifications"));
|
||||
|
||||
// Save-Button erzeugen
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Save, this, &NotificationManagementDialog::onAcknowledgeNotification);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Save, false);
|
||||
m_buttonBox->setText(LtsWidgets::DialogButton::Save, tr("Acknowledge"));
|
||||
|
||||
// Delete-Button erzeugen
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &NotificationManagementDialog::onRemoveNotification);
|
||||
|
||||
// Show-Button erzeugen
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Show, this, &NotificationManagementDialog::onShowNotificationContent);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Show, false);
|
||||
|
||||
connect(m_ui->widget, &LtsDataView::LtsDataView::signalDoubleClicked, this, &NotificationManagementDialog::onShowNotificationContent);
|
||||
|
||||
if (!m_session->getDtc<NotificationManagement::DataInterface>(m_dtc))
|
||||
return;
|
||||
if (!m_session->getFtc<NotificationManagement::DataInterface>(m_ftc))
|
||||
return;
|
||||
if (!m_session->getDtc<OperatorManagement::DataInterface>(m_dtcOpm))
|
||||
return;
|
||||
if (!m_session->getDtc<AssetManagement::DataInterface>(m_dtcAsm))
|
||||
return;
|
||||
|
||||
m_dtcAsm->enableAsset();
|
||||
|
||||
m_model->initModel(m_session);
|
||||
auto proxy = new NotificationDialogProxyModel(this);
|
||||
proxy->setSourceModel(m_model);
|
||||
m_ui->widget->setModel(proxy);
|
||||
|
||||
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged, this, &NotificationManagementDialog::enaDisa);
|
||||
enaDisa();
|
||||
}
|
||||
|
||||
NotificationManagementDialog::~NotificationManagementDialog() { delete m_ui; }
|
||||
|
||||
void NotificationManagementDialog::retranslate() { translate(m_ui, tr("Notifications")); }
|
||||
|
||||
void NotificationManagementDialog::tableColumnOrganiserSetting()
|
||||
{
|
||||
// LtsColumnOrganiser
|
||||
m_ui->widget->setColumnsOrganiserEnabled(identifier(), true);
|
||||
}
|
||||
|
||||
void NotificationManagementDialog::onAcknowledgeNotification()
|
||||
{
|
||||
const QModelIndex curIdx = m_ui->widget->currentIndex();
|
||||
const NomNotification ¬i = m_model->getRowData(curIdx.row());
|
||||
|
||||
ReadReceipt request;
|
||||
|
||||
int operatorId = LtsSessionData::LtsSessionData::getInstance()->getOperatorId();
|
||||
int workstationId = LtsSessionData::LtsSessionData::getInstance()->getWorkstationId();
|
||||
|
||||
for (const auto &addr : noti.recipientIds())
|
||||
{
|
||||
if ((addr.addressType() == AddressType_def::Operator && addr.addressId() == operatorId)
|
||||
|| (addr.addressType() == AddressType_def::Workstation && addr.addressId() == workstationId))
|
||||
{
|
||||
request.addressId(addr.id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
request.operatorId(operatorId);
|
||||
request.workstationId(workstationId);
|
||||
|
||||
bool onlyNotYetAcknowledged = true;
|
||||
request.notificationIds(selectedNotificationIds(onlyNotYetAcknowledged));
|
||||
if (request.notificationIds().empty())
|
||||
return;
|
||||
request.processed(true);
|
||||
|
||||
m_requestHelper->setCustomWaitMessage(tr("Marking notification as read"));
|
||||
m_requestHelper->startSingleRequest(
|
||||
[&]()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "m_ftc->readReceipt ";
|
||||
return m_ftc->readReceiptRequest(request, this);
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<int32_t> NotificationManagementDialog::selectedNotificationIds(bool onlyNotYetAcknowledged)
|
||||
{
|
||||
std::vector<int32_t> notificationIds;
|
||||
QModelIndexList selectedRows = m_ui->widget->selectionModel()->selectedRows();
|
||||
notificationIds.reserve(selectedRows.size());
|
||||
for (const QModelIndex &index : selectedRows)
|
||||
{
|
||||
const NomNotification ¬i = m_model->getRowData(index.row());
|
||||
|
||||
// If the notification is already acknowledged
|
||||
// and this acknowledgment has already been processed: Continue.
|
||||
if (onlyNotYetAcknowledged && noti.processed())
|
||||
continue;
|
||||
|
||||
// Add the rest.
|
||||
notificationIds.emplace_back(noti.id());
|
||||
}
|
||||
|
||||
return notificationIds;
|
||||
}
|
||||
|
||||
void NotificationManagementDialog::onRemoveNotification()
|
||||
{
|
||||
const QModelIndex curIdx = m_ui->widget->currentIndex();
|
||||
const NomNotification ¬i = m_model->getRowData(curIdx.row());
|
||||
|
||||
DeleteMessage request;
|
||||
|
||||
const int operatorId = LtsSessionData::LtsSessionData::getInstance()->getOperatorId();
|
||||
const int workstationId = LtsSessionData::LtsSessionData::getInstance()->getWorkstationId();
|
||||
|
||||
for (const auto &addr : noti.recipientIds())
|
||||
{
|
||||
if ((addr.addressType() == AddressType_def::Operator && addr.addressId() == operatorId)
|
||||
|| (addr.addressType() == AddressType_def::Workstation && addr.addressId() == workstationId))
|
||||
{
|
||||
request.addressId(addr.id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
request.operatorId(operatorId);
|
||||
request.workstationId(workstationId);
|
||||
|
||||
bool acknowledge = false;
|
||||
request.notificationIds(selectedNotificationIds(acknowledge));
|
||||
|
||||
m_requestHelper->setCustomWaitMessage(tr("Delete message"));
|
||||
m_requestHelper->startSingleRequest(
|
||||
[&]()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "m_ftc->readReceipt ";
|
||||
return m_ftc->deleteMessageRequest(request, this);
|
||||
});
|
||||
}
|
||||
|
||||
void NotificationManagementDialog::enaDisa()
|
||||
{
|
||||
QModelIndexList selectedRows = m_ui->widget->selectedRows();
|
||||
const int cntSelectedRows = selectedRows.size();
|
||||
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Save, cntSelectedRows >= 1);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, cntSelectedRows >= 1);
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Show, cntSelectedRows == 1);
|
||||
}
|
||||
|
||||
void NotificationManagementDialog::onShowNotificationContent()
|
||||
{
|
||||
LtsWidgets::LtsFramelessDialog *contentPopup = new LtsWidgets::LtsFramelessDialog(this, LtsWidgets::Behaviour::Popup);
|
||||
|
||||
const QModelIndex curIdx = m_ui->widget->currentIndex();
|
||||
const NomNotification ¬i = m_model->getRowData(curIdx.row());
|
||||
|
||||
QString content = QCoreApplication::translate("Notification", noti.content().c_str());
|
||||
|
||||
NomNotification notiDDS = m_dtc->nomNotification(noti.id());
|
||||
DEBUG_LOG(m_logger) << "onShowNotificationContent"
|
||||
<< ", content=" << noti.content()
|
||||
<< ", contentArgs().size()=" << noti.contentArgs().size()
|
||||
<< ", notiDDS.contentArgs().size()=" << notiDDS.contentArgs().size();
|
||||
|
||||
for (const std::string& arg : notiDDS.contentArgs()) {
|
||||
// .arg() ersetzt immer den kleinsten freien Platzhalter (z. B. zuerst %1, dann %2)
|
||||
content = content.arg(QString::fromStdString(arg));
|
||||
DEBUG_LOG(m_logger) << ".arg() ersetzt immer den kleinsten freien Platzhalter"
|
||||
<< ", arg=" << arg
|
||||
<< ", content=" << content;
|
||||
}
|
||||
|
||||
QScrollArea *scrollArea = new QScrollArea(this);
|
||||
scrollArea->setWidgetResizable(true);
|
||||
|
||||
QTextBrowser *wid = new QTextBrowser(this);
|
||||
wid->setOpenExternalLinks(false);
|
||||
wid->setOpenLinks(false);
|
||||
//wid->setTextFormat(Qt::MarkdownText);
|
||||
wid->setWordWrapMode(QTextOption::WordWrap); // Zeilenumbruch bei langem Text
|
||||
wid->setMarkdown(content);
|
||||
connect(wid, &QTextBrowser::anchorClicked, this, [this, contentPopup](QUrl link )
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "LINK CLICKED: " << link.toString();
|
||||
auto *event = new LtsWidgets::LtsLinkEvent(link, m_session->baseLayoutWidget());
|
||||
event->setAccepted(false);
|
||||
QApplication::postEvent(qApp, event); // receive link events by overriding eventFilter of your *parented* QObject class
|
||||
contentPopup->close();
|
||||
});
|
||||
|
||||
scrollArea->setWidget(wid);
|
||||
|
||||
QFont font;
|
||||
font.setBold(true);
|
||||
|
||||
QLabel *lblTitle = new QLabel(QCoreApplication::translate("Notification", noti.title().c_str()), contentPopup);
|
||||
lblTitle->setFont(font);
|
||||
QLabel *lblFrom = new QLabel(tr("From: "));
|
||||
lblFrom->setFont(font);
|
||||
QLabel *lblSender = new QLabel(QString::fromStdString(noti.sender().name()));
|
||||
|
||||
QFrame *line = new QFrame(this);
|
||||
line->setFrameShape(QFrame::HLine);
|
||||
line->setFrameShadow(QFrame::Sunken);
|
||||
QFrame *line2 = new QFrame(this);
|
||||
line2->setFrameShape(QFrame::HLine);
|
||||
line2->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
LtsWidgets::LtsDialogButtonBox *btnBox = new LtsWidgets::LtsDialogButtonBox(contentPopup);
|
||||
connect(btnBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, contentPopup, &LtsWidgets::LtsFramelessDialog::accept); // TODO: undo workaround !
|
||||
btnBox->getButton(LtsWidgets::DialogButton::Ok)->hide();
|
||||
|
||||
// buildUI
|
||||
QHBoxLayout *hLayFrom = new QHBoxLayout();
|
||||
hLayFrom->addWidget(lblFrom);
|
||||
hLayFrom->addWidget(lblSender);
|
||||
hLayFrom->addStretch(1);
|
||||
|
||||
QVBoxLayout *lay = new QVBoxLayout(contentPopup);
|
||||
lay->addWidget(lblTitle);
|
||||
lay->addWidget(line);
|
||||
lay->addLayout(hLayFrom);
|
||||
lay->addWidget(line2);
|
||||
lay->addWidget(scrollArea);
|
||||
lay->addWidget(btnBox);
|
||||
|
||||
contentPopup->setLayout(lay);
|
||||
contentPopup->setMinimumSize(m_session->baseLayoutWidget()->size()/2.0);
|
||||
|
||||
// exec
|
||||
contentPopup->show();
|
||||
}
|
||||
|
||||
} // namespace NotificationManagement
|
||||
Reference in new issue
Block a user