Skip to content

Commit

Permalink
Refs #98. Email template editor work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Nov 15, 2024
1 parent 8a993b5 commit 0b2190d
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 30 deletions.
14 changes: 7 additions & 7 deletions client/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -263,6 +261,7 @@ if(NOT DEFINED OPENTERA_WEBASSEMBLY)

# Widgets
widgets/InSessionWidget.cpp

# Services
services/VideoRehabService/ScreenController.cpp
services/VideoRehabService/VideoRehabWidget.cpp
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/src/managers/AssetComManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/managers/BaseComManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion client/src/managers/ComManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/managers/ParticipantComManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/services/DanceService/DanceComManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "DashboardsComManager.h"
#include "DashboardsWebAPI.h"

DashboardsComManager::DashboardsComManager(ComManager *comManager, QObject *parent)
: BaseComManager(comManager->getServerUrl()),
Expand Down
5 changes: 0 additions & 5 deletions client/src/services/DashboardsService/DashboardsComManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <QObject>
#include "managers/ComManager.h"
#include "managers/BaseComManager.h"
#include "Utils.h"
#include "DashboardsWebAPI.h"

class DashboardsComManager : public BaseComManager
{
Expand All @@ -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:
Expand All @@ -35,8 +32,6 @@ private slots:
void dataReceived(QList<QJsonObject> items, QUrlQuery reply_query);
void dashboardsReceived(QList<QJsonObject> dashboards, QUrlQuery reply_query);

void postResultsOK(QString reply_path, QString reply_data);

};

#endif // DASHCOMMANAGER_H
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "DashboardsConfigWidget.h"
#include "ui_DashboardsConfigWidget.h"
#include "DashboardsWebAPI.h"

#include "GlobalMessageBox.h"

Expand Down
103 changes: 103 additions & 0 deletions client/src/services/EmailService/EmailComManager.cpp
Original file line number Diff line number Diff line change
@@ -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<QJsonObject> 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());
}
31 changes: 31 additions & 0 deletions client/src/services/EmailService/EmailComManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef EMAILCOMMANAGER_H
#define EMAILCOMMANAGER_H

#include <QObject>
#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<QJsonObject> items, QUrlQuery reply_query);
void emailTemplateReceived(QJsonObject email_template);

};

#endif // EMAILCOMMANAGER_H
67 changes: 66 additions & 1 deletion client/src/services/EmailService/EmailServiceConfigWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#include "EmailServiceConfigWidget.h"
#include "ui_EmailServiceConfigWidget.h"
#include "EmailServiceWebAPI.h"

#include <QStyledItemDelegate>

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));
Expand All @@ -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()
Expand All @@ -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){
Expand All @@ -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());
}

Loading

0 comments on commit 0b2190d

Please sign in to comment.