diff --git a/client/src/CMakeLists.txt b/client/src/CMakeLists.txt index 851e912f..292971e0 100755 --- a/client/src/CMakeLists.txt +++ b/client/src/CMakeLists.txt @@ -84,9 +84,7 @@ set(headers editors/UserGroupWidget.h editors/UserSummaryWidget.h editors/UserWidget.h - # Wizards - wizards/BaseWizard.h - wizards/UserWizard.h + # Services services/BaseServiceWidget.h services/BaseServiceToolsWidget.h @@ -98,6 +96,9 @@ set(headers services/DashboardsService/DashboardsConfigWidget.h services/DashboardsService/DashboardsWebAPI.h services/EmailService/EmailServiceConfigWidget.h + services/EmailService/EmailComManager.h + services/EmailService/EmailServiceWebAPI.h + # Widgets widgets/SessionInviteWidget.h widgets/OnlineManagerWidget.h @@ -216,10 +217,6 @@ set(srcs editors/UserSummaryWidget.cpp editors/UserWidget.cpp - # Wizards - wizards/UserWizard.cpp - wizards/BaseWizard.cpp - # Services services/BaseServiceWidget.cpp services/BaseServiceToolsWidget.cpp @@ -229,6 +226,7 @@ set(srcs services/DashboardsService/DashboardsConfigWidget.cpp services/DashboardsService/DashboardsComManager.cpp services/EmailService/EmailServiceConfigWidget.cpp + services/EmailService/EmailComManager.cpp # Widgets widgets/ProjectNavigator.cpp @@ -263,6 +261,7 @@ if(NOT DEFINED OPENTERA_WEBASSEMBLY) # Widgets widgets/InSessionWidget.cpp + # Services services/VideoRehabService/ScreenController.cpp services/VideoRehabService/VideoRehabWidget.cpp @@ -274,6 +273,7 @@ if(NOT DEFINED OPENTERA_WEBASSEMBLY) services/VideoRehabService/WebSocket/SharedObject.cpp services/VideoRehabService/WebSocket/WebSocketClientWrapper.cpp services/VideoRehabService/WebSocket/WebSocketTransport.cpp + # Kits kit/KitConfigDialog.cpp kit/KitConfigManager.cpp diff --git a/client/src/managers/AssetComManager.cpp b/client/src/managers/AssetComManager.cpp index 46f2ccbe..83423e1d 100644 --- a/client/src/managers/AssetComManager.cpp +++ b/client/src/managers/AssetComManager.cpp @@ -128,7 +128,7 @@ bool AssetComManager::processNetworkReply(QNetworkReply *reply) reply_path = reply_path.append("/infos"); } handled=handleDataReply(reply_path, reply_data, reply_query); - if (handled) emit postResultsOK(reply_path); + if (handled) emit postResultsOK(reply_path, reply_data); } } diff --git a/client/src/managers/BaseComManager.h b/client/src/managers/BaseComManager.h index 568bfa7f..dbca3797 100644 --- a/client/src/managers/BaseComManager.h +++ b/client/src/managers/BaseComManager.h @@ -110,7 +110,7 @@ protected slots: void networkAuthFailed(); void queryResultsOK(QString path, QUrlQuery url_query); - void postResultsOK(QString path); + void postResultsOK(QString reply_path, QString reply_data); void deleteResultsOK(QString path, int id); void posting(QString path, QString data); void querying(QString path); diff --git a/client/src/managers/ComManager.cpp b/client/src/managers/ComManager.cpp index 06bb25ff..022d8360 100644 --- a/client/src/managers/ComManager.cpp +++ b/client/src/managers/ComManager.cpp @@ -133,7 +133,7 @@ bool ComManager::processNetworkReply(QNetworkReply *reply) if (!handled){ handled=handleDataReply(reply_path, reply_data, reply_query); - if (handled) emit postResultsOK(reply_path); + if (handled) emit postResultsOK(reply_path, reply_data); } } diff --git a/client/src/managers/ParticipantComManager.cpp b/client/src/managers/ParticipantComManager.cpp index 36d15e64..38d901b5 100644 --- a/client/src/managers/ParticipantComManager.cpp +++ b/client/src/managers/ParticipantComManager.cpp @@ -79,7 +79,7 @@ bool ParticipantComManager::processNetworkReply(QNetworkReply *reply) if (reply->operation()==QNetworkAccessManager::PostOperation){ if (!handled){ handled=handleDataReply(reply_path, reply_data, reply_query); - if (handled) emit postResultsOK(reply_path); + if (handled) emit postResultsOK(reply_path, reply_data); } } diff --git a/client/src/services/DanceService/DanceComManager.cpp b/client/src/services/DanceService/DanceComManager.cpp index 53075c29..9dbb9b72 100644 --- a/client/src/services/DanceService/DanceComManager.cpp +++ b/client/src/services/DanceService/DanceComManager.cpp @@ -38,7 +38,7 @@ bool DanceComManager::processNetworkReply(QNetworkReply *reply) if (reply->operation()==QNetworkAccessManager::PostOperation){ if (!handled){ handled=handleDataReply(reply_path, reply_data, reply_query); - if (handled) emit postResultsOK(reply_path); + if (handled) emit postResultsOK(reply_path, reply_data); } } diff --git a/client/src/services/DashboardsService/DashboardsComManager.cpp b/client/src/services/DashboardsService/DashboardsComManager.cpp index 70e4bd90..d0b09e48 100644 --- a/client/src/services/DashboardsService/DashboardsComManager.cpp +++ b/client/src/services/DashboardsService/DashboardsComManager.cpp @@ -1,4 +1,5 @@ #include "DashboardsComManager.h" +#include "DashboardsWebAPI.h" DashboardsComManager::DashboardsComManager(ComManager *comManager, QObject *parent) : BaseComManager(comManager->getServerUrl()), diff --git a/client/src/services/DashboardsService/DashboardsComManager.h b/client/src/services/DashboardsService/DashboardsComManager.h index 86c9029e..61e09674 100644 --- a/client/src/services/DashboardsService/DashboardsComManager.h +++ b/client/src/services/DashboardsService/DashboardsComManager.h @@ -4,8 +4,6 @@ #include #include "managers/ComManager.h" #include "managers/BaseComManager.h" -#include "Utils.h" -#include "DashboardsWebAPI.h" class DashboardsComManager : public BaseComManager { @@ -25,7 +23,6 @@ class DashboardsComManager : public BaseComManager ComManager* m_comManager; void connectSignals(); - bool handleDataReply(const QString& reply_path, const QString &reply_data, const QUrlQuery &reply_query); private slots: @@ -35,8 +32,6 @@ private slots: void dataReceived(QList items, QUrlQuery reply_query); void dashboardsReceived(QList dashboards, QUrlQuery reply_query); - void postResultsOK(QString reply_path, QString reply_data); - }; #endif // DASHCOMMANAGER_H diff --git a/client/src/services/DashboardsService/DashboardsConfigWidget.cpp b/client/src/services/DashboardsService/DashboardsConfigWidget.cpp index 979a6085..a7ac72f4 100644 --- a/client/src/services/DashboardsService/DashboardsConfigWidget.cpp +++ b/client/src/services/DashboardsService/DashboardsConfigWidget.cpp @@ -1,5 +1,6 @@ #include "DashboardsConfigWidget.h" #include "ui_DashboardsConfigWidget.h" +#include "DashboardsWebAPI.h" #include "GlobalMessageBox.h" diff --git a/client/src/services/EmailService/EmailComManager.cpp b/client/src/services/EmailService/EmailComManager.cpp new file mode 100644 index 00000000..929d90d1 --- /dev/null +++ b/client/src/services/EmailService/EmailComManager.cpp @@ -0,0 +1,103 @@ +#include "EmailComManager.h" +#include "EmailServiceWebAPI.h" + +EmailComManager::EmailComManager(ComManager *comManager, QObject *parent) + : BaseComManager{comManager->getServerUrl(), parent}, + m_comManager(comManager) +{ + // Set initial user token + setCredentials(m_comManager->getCurrentToken()); + + // Connect signals + connectSignals(); +} + +EmailComManager::~EmailComManager() +{ + +} + +bool EmailComManager::processNetworkReply(QNetworkReply *reply) +{ + QString reply_path = reply->url().path(); + QString reply_data = reply->readAll(); + QUrlQuery reply_query = QUrlQuery(reply->url().query()); + //qDebug() << reply_path << " ---> " << reply_data << ": " << reply->url().query(); + + bool handled = false; + + if (reply->operation()==QNetworkAccessManager::GetOperation){ + if (!handled){ + // General case + handled = handleDataReply(reply_path, reply_data, reply_query); + if (handled) emit queryResultsOK(reply_path, reply_query); + } + } + + if (reply->operation()==QNetworkAccessManager::PostOperation){ + if (!handled){ + handled = handleDataReply(reply_path, reply_data, reply_query); + if (handled) emit postResultsOK(reply_path, reply_data); + } + } + + if (reply->operation()==QNetworkAccessManager::DeleteOperation){ + // Extract id from url + int id = 0; + if (reply_query.hasQueryItem("id")){ + id = reply_query.queryItemValue("id").toInt(); + } + emit deleteResultsOK(reply_path, id); + handled=true; + } + + return handled; +} + +bool EmailComManager::handleDataReply(const QString &reply_path, const QString &reply_data, const QUrlQuery &reply_query) +{ + QJsonParseError json_error; + + // Process reply + QString data_str = filterReplyString(reply_data); + + QJsonDocument data_list = QJsonDocument::fromJson(data_str.toUtf8(), &json_error); + if (json_error.error!= QJsonParseError::NoError){ + LOG_ERROR("Received a JSON string for " + reply_path + " with " + reply_query.toString() + " with error: " + json_error.errorString(), "DashboardsComManager::handleDataReply"); + return false; + } + + // Browse each items received + QList items; + if (data_list.isArray()){ + QJsonArray data_list_array = data_list.array(); + for (const QJsonValue &data:std::as_const(data_list_array)){ + items.append(data.toObject()); + } + }else{ + items.append(data_list.object()); + } + + // Check to emit correct signals for specific data types + if (reply_path.endsWith(EMAIL_TEMPLATE_PATH)){ + if (!items.empty()){ + emit emailTemplateReceived(items.first()); + } + } + + // Always emit generic signal + emit dataReceived(items, reply_query); + + return true; +} + +void EmailComManager::connectSignals() +{ + connect(m_comManager, &ComManager::userTokenUpdated, this, &EmailComManager::handleUserTokenUpdated); +} + +void EmailComManager::handleUserTokenUpdated() +{ + // Update token + setCredentials(m_comManager->getCurrentToken()); +} diff --git a/client/src/services/EmailService/EmailComManager.h b/client/src/services/EmailService/EmailComManager.h new file mode 100644 index 00000000..d422f75f --- /dev/null +++ b/client/src/services/EmailService/EmailComManager.h @@ -0,0 +1,31 @@ +#ifndef EMAILCOMMANAGER_H +#define EMAILCOMMANAGER_H + +#include +#include "managers/BaseComManager.h" +#include "managers/ComManager.h" + +class EmailComManager : public BaseComManager +{ + Q_OBJECT +public: + explicit EmailComManager(ComManager* comManager, QObject *parent = nullptr); + ~EmailComManager(); + +private: + ComManager* m_comManager; + + void connectSignals(); + bool processNetworkReply(QNetworkReply* reply) override; + bool handleDataReply(const QString& reply_path, const QString &reply_data, const QUrlQuery &reply_query); + +private slots: + void handleUserTokenUpdated(); + +signals: + void dataReceived(QList items, QUrlQuery reply_query); + void emailTemplateReceived(QJsonObject email_template); + +}; + +#endif // EMAILCOMMANAGER_H diff --git a/client/src/services/EmailService/EmailServiceConfigWidget.cpp b/client/src/services/EmailService/EmailServiceConfigWidget.cpp index bfc8a2fd..7378a7c0 100644 --- a/client/src/services/EmailService/EmailServiceConfigWidget.cpp +++ b/client/src/services/EmailService/EmailServiceConfigWidget.cpp @@ -1,12 +1,15 @@ #include "EmailServiceConfigWidget.h" #include "ui_EmailServiceConfigWidget.h" +#include "EmailServiceWebAPI.h" + #include EmailServiceConfigWidget::EmailServiceConfigWidget(ComManager *comManager, QWidget *parent) : QWidget(parent) , ui(new Ui::EmailServiceConfigWidget) { - m_comMan = comManager; + m_comManager = comManager; + m_emailComManager = new EmailComManager(comManager); ui->setupUi(this); ui->cmbTemplate->setItemDelegate(new QStyledItemDelegate(ui->cmbTemplate)); @@ -16,12 +19,21 @@ EmailServiceConfigWidget::EmailServiceConfigWidget(ComManager *comManager, QWidg ui->btnUnderline->hide(); initVariablesMenu(); + initTemplates(); + connectSignals(); + + // Only one template for now... query it! + if (ui->cmbTemplate->count() > 0){ + queryTemplate(ui->cmbTemplate->currentData().toString()); + } + } EmailServiceConfigWidget::~EmailServiceConfigWidget() { delete ui; + delete m_emailComManager; } void EmailServiceConfigWidget::insertCurrentVariable() @@ -36,6 +48,23 @@ void EmailServiceConfigWidget::insertCurrentVariable() } } +void EmailServiceConfigWidget::processTemplateReply(const QJsonObject email_template) +{ + if (!email_template.empty()){ + QString template_html = email_template["email_template"].toString(); + ui->txtTemplate->setHtml(template_html); + ui->txtTemplate->setProperty("original", ui->txtTemplate->toHtml()); + ui->frameEditor->show(); + ui->frameSave->show(); + ui->frameSave->setEnabled(false); + } +} + +void EmailServiceConfigWidget::connectSignals() +{ + connect(m_emailComManager, &EmailComManager::emailTemplateReceived, this, &EmailServiceConfigWidget::processTemplateReply); +} + void EmailServiceConfigWidget::initVariablesMenu() { if (!m_variablesMenu){ @@ -60,3 +89,39 @@ void EmailServiceConfigWidget::initVariablesMenu() } } +void EmailServiceConfigWidget::initTemplates() +{ + ui->cmbTemplate->clear(); + ui->cmbTemplate->addItem(tr("Courriel d'invitation"), "INVITE_EMAIL"); +} + +void EmailServiceConfigWidget::queryTemplate(const QString &key) +{ + QUrlQuery args; + args.addQueryItem(WEB_QUERY_KEY, key); + args.addQueryItem(WEB_QUERY_EMAIL_LANG, m_comManager->getCurrentPreferences().getLanguage()); + ui->frameEditor->hide(); + ui->frameSave->hide(); + m_emailComManager->doGet(EMAIL_TEMPLATE_PATH, args); +} + + +void EmailServiceConfigWidget::on_txtTemplate_textChanged() +{ + bool has_changes = ui->txtTemplate->toHtml() != ui->txtTemplate->property("original").toString(); + ui->frameSave->setEnabled(has_changes); +} + + +void EmailServiceConfigWidget::on_btnSave_clicked() +{ + +} + + +void EmailServiceConfigWidget::on_btnUndo_clicked() +{ + ui->txtTemplate->setHtml(ui->txtTemplate->property("original").toString()); + ui->txtTemplate->setProperty("original", ui->txtTemplate->toHtml()); +} + diff --git a/client/src/services/EmailService/EmailServiceConfigWidget.h b/client/src/services/EmailService/EmailServiceConfigWidget.h index e31c458c..f6a35ffb 100644 --- a/client/src/services/EmailService/EmailServiceConfigWidget.h +++ b/client/src/services/EmailService/EmailServiceConfigWidget.h @@ -4,6 +4,7 @@ #include #include #include "managers/ComManager.h" +#include "services/EmailService/EmailComManager.h" namespace Ui { class EmailServiceConfigWidget; @@ -19,14 +20,27 @@ class EmailServiceConfigWidget : public QWidget private slots: void insertCurrentVariable(); + void processTemplateReply(const QJsonObject email_template); -private: - void initVariablesMenu(); + void on_txtTemplate_textChanged(); + + void on_btnSave_clicked(); - Ui::EmailServiceConfigWidget *ui; + void on_btnUndo_clicked(); + +private: + Ui::EmailServiceConfigWidget *ui; + EmailComManager* m_emailComManager; - ComManager* m_comMan; + ComManager* m_comManager; QMenu* m_variablesMenu = nullptr; + + void connectSignals(); + + void initVariablesMenu(); + void initTemplates(); + + void queryTemplate(const QString& key); }; #endif // EMAILSERVICECONFIGWIDGET_H diff --git a/client/src/services/EmailService/EmailServiceConfigWidget.ui b/client/src/services/EmailService/EmailServiceConfigWidget.ui index a0d74666..3f0b4ccc 100644 --- a/client/src/services/EmailService/EmailServiceConfigWidget.ui +++ b/client/src/services/EmailService/EmailServiceConfigWidget.ui @@ -7,7 +7,7 @@ 0 0 400 - 300 + 353 @@ -45,13 +45,7 @@ QToolButton#btnVariables{ - - - - Courriel d'invitation - - - + @@ -208,6 +202,9 @@ QToolButton#btnVariables{ + + false + diff --git a/client/src/services/EmailService/EmailServiceWebAPI.h b/client/src/services/EmailService/EmailServiceWebAPI.h new file mode 100644 index 00000000..766bc4b1 --- /dev/null +++ b/client/src/services/EmailService/EmailServiceWebAPI.h @@ -0,0 +1,9 @@ +#ifndef EMAILWEBAPI_H +#define EMAILWEBAPI_H + +#define EMAIL_SEND_PATH "/email/api/send" +#define EMAIL_TEMPLATE_PATH "/email/api/templates" + +#define WEB_QUERY_EMAIL_LANG "lang" + +#endif // EMAILWEBAPI_H