Skip to content

Commit

Permalink
Refs #94. Work in progress on the Dashboards config widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Mar 12, 2024
1 parent 973304f commit e4704b0
Show file tree
Hide file tree
Showing 7 changed files with 493 additions and 107 deletions.
2 changes: 1 addition & 1 deletion client/src/editors/ProjectWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ void ProjectWidget::addServiceTab(const TeraData &service_project)
// Dashboards Service
if (service_key == "DashboardsService"){
if (is_project_admin){
DashboardsConfigWidget* wdg = new DashboardsConfigWidget(m_comManager, m_data->getFieldValue("id_site").toInt(), m_data->getId());
DashboardsConfigWidget* wdg = new DashboardsConfigWidget(m_comManager, 0, m_data->getId());
QString service_name = service_key;
if (m_listServices_items.contains(id_service)){
service_name = m_listServices_items[id_service]->text();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,20 @@ void DashboardsComManager::handleUserTokenUpdated()
setCredentials(m_comManager->getCurrentToken());
}

void DashboardsComManager::doGet(const QString &path, const QUrlQuery &query_args)
void DashboardsComManager::doGet(const QString &path, const QUrlQuery &query_args, const bool &use_token)
{
Q_UNUSED(use_token)
BaseComManager::doGet(path, query_args, true);
}

void DashboardsComManager::doPost(const QString &path, const QString &post_data)
void DashboardsComManager::doPost(const QString &path, const QString &post_data, const bool &use_token)
{
Q_UNUSED(use_token)
BaseComManager::doPost(path, post_data, true);
}

void DashboardsComManager::doDelete(const QString &path, const int &id)
void DashboardsComManager::doDelete(const QString &path, const int &id, const bool &use_token)
{
Q_UNUSED(use_token)
BaseComManager::doDelete(path, id, true);
}
8 changes: 4 additions & 4 deletions client/src/services/DashboardsService/DashboardsComManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class DashboardsComManager : public BaseComManager

bool processNetworkReply(QNetworkReply* reply);

void doGet(const QString &path, const QUrlQuery &query_args = QUrlQuery());
void doPost(const QString &path, const QString &post_data);
void doDelete(const QString &path, const int& id);
void doGet(const QString &path, const QUrlQuery &query_args = QUrlQuery(), const bool &use_token=true);
void doPost(const QString &path, const QString &post_data, const bool &use_token=true);
void doDelete(const QString &path, const int& id, const bool &use_token=true);


private:
Expand All @@ -33,7 +33,7 @@ private slots:

signals:
void dataReceived(QList<QJsonObject> items, QUrlQuery reply_query);
void dashboardsReceived(QList<QJsonObject> videos, QUrlQuery reply_query);
void dashboardsReceived(QList<QJsonObject> dashboards, QUrlQuery reply_query);

};

Expand Down
140 changes: 139 additions & 1 deletion client/src/services/DashboardsService/DashboardsConfigWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ DashboardsConfigWidget::DashboardsConfigWidget(ComManager *comManager, const int
m_idSite = id_site;
m_idProject = id_project;

connectSignals();

// Init ui
ui->frameEditor->hide();

// Query dashboards
QUrlQuery args;
args.addQueryItem(WEB_QUERY_LIST, "1");
//args.addQueryItem(WEB_QUERY_LIST, "1");
m_dashComManager->doGet(DASHBOARDS_USER_PATH, args);
}

Expand All @@ -23,3 +28,136 @@ DashboardsConfigWidget::~DashboardsConfigWidget()
delete ui;
delete m_dashComManager;
}

void DashboardsConfigWidget::connectSignals()
{
connect(m_dashComManager, &DashboardsComManager::dashboardsReceived, this, &DashboardsConfigWidget::processDashboardsReply);
}

void DashboardsConfigWidget::processDashboardsReply(QList<QJsonObject> dashboards, QUrlQuery reply_query)
{
if (reply_query.hasQueryItem(WEB_QUERY_ID_DASHBOARD)){
// Querying specific dashboard
if (dashboards.count() != 1){
qWarning() << "DashboardsConfigWidget::processDashboardsReply - Was expecting one dashboard - got more!";
return;
}
ui->txtName->setText(dashboards.first()["dashboard_name"].toString());
ui->txtDescription->setPlainText(dashboards.first()["dashboard_description"].toString());
ui->cmbVersion->clear();
ui->cmbFixedVersion->clear();
ui->cmbFixedVersion->addItem(tr("Aucune"));
QJsonArray versions = dashboards.first()["versions"].toArray();
for (const QJsonValueRef &version:versions){
QJsonObject version_obj = version.toObject();
QString version_str = QString::number(version_obj["dashboard_version"].toInt());
ui->cmbVersion->addItem(version_str, version_obj["dashboard_definition"].toString());
ui->cmbFixedVersion->addItem(version_str);
}

ui->chkEnabled->setChecked(false);
QJsonArray projects = dashboards.first()["dashboard_projects"].toArray();
for (const QJsonValueRef &project:projects){
QJsonObject proj_obj = project.toObject();
if (proj_obj["id_project"] == m_idProject){
ui->chkEnabled->setChecked(proj_obj["dashboard_enabled"].toBool());
int required_version = proj_obj["dashboard_required_version"].toInt();
ui->cmbFixedVersion->setCurrentIndex(required_version);
break;
}
}

QJsonArray sites = dashboards.first()["dashboard_sites"].toArray();
for (const QJsonValueRef &site:sites){
QJsonObject site_obj = site.toObject();
if (site_obj["id_site"] == m_idSite){
ui->chkEnabled->setChecked(site_obj["dashboard_enabled"].toBool());
int required_version = site_obj["dashboard_required_version"].toInt();
ui->cmbFixedVersion->setCurrentIndex(required_version);
break;
}
}

if (ui->lstDashboards->currentItem())
ui->frameSpecific->setVisible(ui->lstDashboards->currentItem()->checkState() == Qt::Checked);

ui->frameEditor->show();

}else{
ui->lstDashboards->clear();
m_listDashboards_items.clear();

for (const QJsonObject &dash:std::as_const(dashboards)){
QListWidgetItem* item = new QListWidgetItem();
int id_dashboard = dash["id_dashboard"].toInt();
item->setIcon(QIcon("://icons/history.png"));
item->setData(Qt::UserRole, id_dashboard);
item->setText(dash["dashboard_name"].toString());

bool checked = false;/*dash["dashboard_sites"].toArray().contains(m_idSite) ||
dash["dashboard_projects"].toArray().contains(m_idProject);*/
if (m_idSite>0){
QJsonArray sites = dash["dashboard_sites"].toArray();
for(QJsonValueRef site:sites){
QJsonObject site_obj = site.toObject();
checked = site_obj["id_site"].toInt() == m_idSite;
if (checked)
break;
}
}

if (m_idProject>0){
QJsonArray projects = dash["dashboard_projects"].toArray();
for(QJsonValueRef project:projects){
QJsonObject proj_obj = project.toObject();
checked = proj_obj["id_project"].toInt() == m_idProject;
if (checked)
break;
}
}

if (checked){
item->setCheckState(Qt::Checked);
}else{
item->setCheckState(Qt::Unchecked);
}
ui->lstDashboards->addItem(item);
m_listDashboards_items.insert(id_dashboard, item);
}
}
}

/*void DashboardsConfigWidget::on_lstDashboards_itemChanged(QListWidgetItem *item)
{
bool has_changes = false;
if (m_listDashboards_items.key(item) > 0 && item->checkState() == Qt::Unchecked){
// Item deselected
has_changes = true;
}else{
if (m_listDashboards_items.key(item, -1) <= 0 && item->checkState() == Qt::Checked){
// Item selected
has_changes = true;
}
}
ui->btnUpdateDashboards->setEnabled(has_changes);
}*/

void DashboardsConfigWidget::on_lstDashboards_itemClicked(QListWidgetItem *item)
{
// Query informations for that dashboard
QUrlQuery args;
int id_dashboard = m_listDashboards_items.key(item);
args.addQueryItem(WEB_QUERY_ID_DASHBOARD, QString::number(id_dashboard));
args.addQueryItem(WEB_QUERY_ALL_VERSIONS, "1");
ui->frameSpecific->setVisible(item->checkState() == Qt::Checked);
ui->frameEditor->hide();
m_dashComManager->doGet(DASHBOARDS_USER_PATH, args);
}


void DashboardsConfigWidget::on_cmbVersion_currentIndexChanged(int index)
{
ui->txtDefinition->setText(ui->cmbVersion->currentData().toString());
}

13 changes: 13 additions & 0 deletions client/src/services/DashboardsService/DashboardsConfigWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define DASHBOARDSCONFIGWIDGET_H

#include <QWidget>
#include <QListWidgetItem>

#include "DashboardsComManager.h"

namespace Ui {
Expand All @@ -22,9 +24,20 @@ class DashboardsConfigWidget : public QWidget
ComManager* m_comManager;
DashboardsComManager* m_dashComManager;

QHash<int, QListWidgetItem*> m_listDashboards_items;

int m_idProject;
int m_idSite;

void connectSignals();

private slots:
void processDashboardsReply(QList<QJsonObject> dashboards, QUrlQuery reply_query);

/*void on_lstDashboards_itemChanged(QListWidgetItem *item);
void on_btnUpdateDashboards_clicked();*/
void on_lstDashboards_itemClicked(QListWidgetItem *item);
void on_cmbVersion_currentIndexChanged(int index);
};

#endif // DASHBOARDSCONFIGWIDGET_H
Loading

0 comments on commit e4704b0

Please sign in to comment.