Skip to content

Commit

Permalink
Refs #94. Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Mar 13, 2024
1 parent 97bf26c commit cbe805d
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 151 deletions.
2 changes: 1 addition & 1 deletion client/resources/stylesheet.qss
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ QToolButton#btnVideo:!checked, QToolButton#btnLog:!checked, QToolButton#btnFilte
border-radius: 5px;
}

QToolButton#btnLog:!checked, QToolButton#btnInSessionInfos:!checked, QToolButton#btnPause:!checked{
QToolButton#btnLog:!checked, QToolButton#btnInSessionInfos:!checked, QToolButton#btnPause:!checked, QToolButton#btnEdit:!checked{
color:white;
background-color: transparent;
border: 0px;
Expand Down
2 changes: 1 addition & 1 deletion client/src/editors/ProjectWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ void ProjectWidget::addServiceTab(const TeraData &service_project)

// Dashboards Service
if (service_key == "DashboardsService"){
if (is_project_admin){
if (isSiteAdmin()){
DashboardsConfigWidget* wdg = new DashboardsConfigWidget(m_comManager, 0, m_data->getId());
QString service_name = service_key;
if (m_listServices_items.contains(id_service)){
Expand Down
16 changes: 8 additions & 8 deletions client/src/editors/ProjectWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
</sizepolicy>
</property>
<property name="currentIndex">
<number>3</number>
<number>0</number>
</property>
<property name="iconSize">
<size>
Expand Down Expand Up @@ -1284,7 +1284,7 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
</widget>
</item>
</layout>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
Expand All @@ -1297,6 +1297,12 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
</widget>
</widget>
<customwidgets>
<customwidget>
<class>TeraForm</class>
<extends>QWidget</extends>
<header>TeraForm.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ClickableLabel</class>
<extends>QLabel</extends>
Expand All @@ -1306,12 +1312,6 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
<slot>clicked()</slot>
</slots>
</customwidget>
<customwidget>
<class>TeraForm</class>
<extends>QWidget</extends>
<header>TeraForm.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../resources/TeraClient.qrc"/>
Expand Down
94 changes: 79 additions & 15 deletions client/src/services/DashboardsService/DashboardsConfigWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@ DashboardsConfigWidget::DashboardsConfigWidget(ComManager *comManager, const int
connectSignals();

// Init ui
bool is_super = m_comManager->isCurrentUserSuperAdmin();
ui->frameEditor->hide();
ui->wdgMessages->hide();
ui->frameDashboardButtons->setVisible(is_super);
ui->frameButtons->hide();
ui->frameVersionsInfos->setVisible(is_super);
ui->frameVersionsButtons->hide();

// Query dashboards
QUrlQuery args;
//args.addQueryItem(WEB_QUERY_LIST, "1");
args.addQueryItem(WEB_QUERY_ENABLED, "0"); // Include dashboards that are not enabled
if (!m_comManager->isCurrentUserSuperAdmin()){
// Only query dashboards associated with that item
if (m_idSite > 0)
args.addQueryItem(WEB_QUERY_ID_SITE, QString::number(m_idSite));
if (m_idProject > 0)
args.addQueryItem(WEB_QUERY_ID_PROJECT, QString::number(m_idProject));
}
m_dashComManager->doGet(DASHBOARDS_USER_PATH, args);
}

Expand All @@ -36,6 +49,8 @@ void DashboardsConfigWidget::connectSignals()
connect(m_dashComManager, &DashboardsComManager::networkError, this, &DashboardsConfigWidget::handleNetworkError);
connect(m_dashComManager, &DashboardsComManager::deleteResultsOK, this, &DashboardsConfigWidget::dashComDeleteOK);
connect(m_dashComManager, &DashboardsComManager::postResultsOK, this, &DashboardsConfigWidget::dashComPostOK);

connect(ui->wdgMessages, &ResultMessageWidget::nextMessageShown, this, &DashboardsConfigWidget::nextMessageWasShown);
}

void DashboardsConfigWidget::processDashboardsReply(QList<QJsonObject> dashboards, QUrlQuery reply_query)
Expand Down Expand Up @@ -82,28 +97,38 @@ void DashboardsConfigWidget::processDashboardsReply(QList<QJsonObject> dashboard
}
}

if (ui->lstDashboards->currentItem())
ui->frameSpecific->setVisible(ui->lstDashboards->currentItem()->checkState() == Qt::Checked);
if (ui->lstDashboards->currentItem()){
ui->frameSpecific->setVisible(ui->lstDashboards->currentItem()->checkState() == Qt::Checked ||
!ui->lstDashboards->currentItem()->flags().testFlags(Qt::ItemIsUserCheckable));
}

ui->frameEditor->show();

}else{
}else{/*
ui->lstDashboards->clear();
m_listDashboards_items.clear();
m_listDashboards_projects.clear();
m_listDashboards_sites.clear();
m_listDashboards_sites.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);
QListWidgetItem* item;
if (m_listDashboards_items.contains(id_dashboard)){
item = m_listDashboards_items[id_dashboard];
}else{
item = new QListWidgetItem();

item->setIcon(QIcon("://icons/history.png"));
item->setData(Qt::UserRole, id_dashboard);
m_listDashboards_items.insert(id_dashboard, item);
}
item->setText(dash["dashboard_name"].toString());

bool checked = false;/*dash["dashboard_sites"].toArray().contains(m_idSite) ||
dash["dashboard_projects"].toArray().contains(m_idProject);*/
bool checked = false;
bool checkable = false;
if (m_idSite>0){
QJsonArray sites = dash["dashboard_sites"].toArray();
m_listDashboards_sites.clear();
for(QJsonValueRef site:sites){
QJsonObject site_obj = site.toObject();
int id_site = site_obj["id_site"].toInt();
Expand All @@ -115,10 +140,12 @@ void DashboardsConfigWidget::processDashboardsReply(QList<QJsonObject> dashboard
m_listDashboards_sites[id_dashboard] = QList<int>() << id_site;
}
}
checkable = sites.count() > 1 || m_comManager->isCurrentUserSuperAdmin();
}

if (m_idProject>0){
QJsonArray projects = dash["dashboard_projects"].toArray();
m_listDashboards_projects.clear();
for(QJsonValueRef project:projects){
QJsonObject proj_obj = project.toObject();
int id_project = proj_obj["id_project"].toInt();
Expand All @@ -130,15 +157,21 @@ void DashboardsConfigWidget::processDashboardsReply(QList<QJsonObject> dashboard
m_listDashboards_projects[id_dashboard] = QList<int>() << id_project;
}
}
checkable = projects.count() > 1 || m_comManager->isCurrentUserSuperAdmin();
}

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

}
}
}
Expand Down Expand Up @@ -180,6 +213,15 @@ void DashboardsConfigWidget::dashComPostOK(QString path)
ui->wdgMessages->addMessage(Message(Message::MESSAGE_OK, tr("Données sauvegardées")));
}

void DashboardsConfigWidget::nextMessageWasShown(Message current_message)
{
if (current_message.getMessageType()==Message::MESSAGE_NONE){
ui->wdgMessages->hide();
}else{
ui->wdgMessages->show();
}
}

void DashboardsConfigWidget::on_lstDashboards_itemChanged(QListWidgetItem *item)
{
ui->frameSpecific->setVisible(item->checkState() == Qt::Checked);
Expand Down Expand Up @@ -207,7 +249,7 @@ void DashboardsConfigWidget::on_lstDashboards_itemChanged(QListWidgetItem *item)
}else{
if (!m_listDashboards_projects[id_dashboard].contains(m_idProject))
return; // No need to update - all set!
m_listDashboards_projects[id_dashboard].remove(m_idProject);
m_listDashboards_projects[id_dashboard].removeAll(m_idProject);
}
for(int item_id: m_listDashboards_projects[id_dashboard]){
QJsonObject item;
Expand All @@ -223,7 +265,7 @@ void DashboardsConfigWidget::on_lstDashboards_itemChanged(QListWidgetItem *item)
}else{
if (!m_listDashboards_sites[id_dashboard].contains(m_idSite))
return; // No need to update - all set!
m_listDashboards_sites[id_dashboard].remove(m_idSite);
m_listDashboards_sites[id_dashboard].removeAll(m_idSite);
}
for(int item_id: m_listDashboards_sites[id_dashboard]){
QJsonObject item;
Expand Down Expand Up @@ -255,3 +297,25 @@ void DashboardsConfigWidget::on_cmbVersion_currentIndexChanged(int index)
ui->txtDefinition->setText(ui->cmbVersion->currentData().toString());
}


void DashboardsConfigWidget::on_btnEdit_toggled(bool checked)
{
ui->frameDashboards->setDisabled(checked);
if (m_comManager->isCurrentUserSuperAdmin()){
ui->frameDashboardDetails->setEnabled(checked);
ui->frameVersionsButtons->setVisible(checked);
ui->txtDefinition->setEnabled(checked);
}
ui->frameSpecific->setEnabled(checked);
ui->frameButtons->setVisible(checked);
ui->btnEdit->setVisible(!checked);
}


void DashboardsConfigWidget::on_btnCancel_clicked()
{
// Refresh data
ui->btnEdit->setChecked(false);
//on_btnEdit_toggled(false);
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QListWidgetItem>

#include "DashboardsComManager.h"
#include "data/Message.h"

namespace Ui {
class DashboardsConfigWidget;
Expand Down Expand Up @@ -39,10 +40,13 @@ private slots:
void dashComDeleteOK(QString path, int id);
void dashComPostOK(QString path);

void on_lstDashboards_itemChanged(QListWidgetItem *item);
void nextMessageWasShown(Message current_message);

void on_lstDashboards_itemChanged(QListWidgetItem *item);
void on_lstDashboards_itemClicked(QListWidgetItem *item);
void on_cmbVersion_currentIndexChanged(int index);
void on_btnEdit_toggled(bool checked);
void on_btnCancel_clicked();
};

#endif // DASHBOARDSCONFIGWIDGET_H
Loading

0 comments on commit cbe805d

Please sign in to comment.