-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #98. Email template editor work in progress.
- Loading branch information
Showing
15 changed files
with
246 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
client/src/services/DashboardsService/DashboardsConfigWidget.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.