Skip to content

Commit

Permalink
Refs #100. Added support for additional services in session types.
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Dec 10, 2024
1 parent af2df1d commit e478b15
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 24 deletions.
8 changes: 6 additions & 2 deletions client/resources/stylesheet.qss
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ QListView::item:hover {
QComboBox {
background-color: rgba(255,255,255,50%);
selection-background-color: rgba(90,90,90,100%);
selection-color: white;
selection-color: cyan;
border: 1px solid gray;
border-radius: 3px;
padding: 0px 0px 0px 0px;
Expand All @@ -373,11 +373,13 @@ QComboBox::down-arrow:!enabled {

QComboBox QAbstractItemView {
/*background-color: rgba(255,255,255,50%);*/
background-color: rgba(0,0,0,100%);
padding-left: 5px;
border: 1px solid gray;
}

QComboBox QAbstractItemView::item {
/*background-color: rgba(255,255,255,50%);*/
background-color: rgba(0,0,0,100%);
min-height: 25px;
}

Expand All @@ -403,6 +405,7 @@ QPushButton:hover{
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #295d80, stop: 1 #173448);/*qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #173448, stop: 0.2 rgb(200,200,200), stop:1 #173448);*/
border: 2px solid #3286bf /*rgb(186, 186, 186)*/;
border-radius: 5px;
font-weight: bold;
}

QPushButton:!enabled{
Expand Down Expand Up @@ -726,6 +729,7 @@ QPushButton#btnEditUser,QPushButton#btnConfig {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgba(100,100,100,100%), stop: 1 rgba(148,148,148,100%));
border: 1px solid rgba(148,148,148,100%);
min-width: 0px;
color: black;
}

QPushButton#btnEditUser:hover,QPushButton#btnConfig:hover{
Expand Down
69 changes: 68 additions & 1 deletion client/src/editors/SessionTypeWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "SessionTypeWidget.h"
#include "ui_SessionTypeWidget.h"

#include "GlobalMessageBox.h"

SessionTypeWidget::SessionTypeWidget(ComManager *comMan, const TeraData *data, QWidget *parent) :
DataEditorWidget(comMan, data, parent),
ui(new Ui::SessionTypeWidget)
Expand Down Expand Up @@ -232,6 +234,32 @@ void SessionTypeWidget::updateProject(TeraData *project)
item->setText(0, project->getName());
}

void SessionTypeWidget::updateSessionTypeService(TeraData *sts)
{
int id_service = sts->getFieldValue("id_service").toInt();
QListWidgetItem* item;
if (m_lstServices_items.contains(id_service)){
item = m_lstServices_items[id_service];
}else{
item = new QListWidgetItem();
item->setIcon(QIcon(TeraData::getIconFilenameForDataType(TERADATA_SERVICE)));
item->setCheckState(Qt::Unchecked);
ui->lstServices->addItem(item);

m_lstServices_items[id_service] = item;
}

QString service_name = sts->getFieldValue("service_name").toString();
if (!service_name.isEmpty())
item->setText(service_name);
int st_id = sts->getFieldValue("id_session_type").toInt();
if (st_id > 0){
item->setCheckState(Qt::Checked);
}else{
item->setCheckState(Qt::Unchecked);
}
}

void SessionTypeWidget::postSessionTypeSites()
{
QJsonDocument document;
Expand Down Expand Up @@ -371,6 +399,13 @@ void SessionTypeWidget::processProjectsReply(QList<TeraData> projects)
ui->treeProjects->expandAll();
}

void SessionTypeWidget::processSessionTypesServicesReply(QList<TeraData> services)
{
for(TeraData service:services){
updateSessionTypeService(&service);
}
}


void SessionTypeWidget::postResultReply(QString path)
{
Expand All @@ -395,6 +430,8 @@ void SessionTypeWidget::connectSignals()
connect(m_comManager, &ComManager::sitesReceived, this, &SessionTypeWidget::processSitesReply);
connect(m_comManager, &ComManager::projectsReceived, this, &SessionTypeWidget::processProjectsReply);

connect(m_comManager, &ComManager::sessionTypesServicesReceived, this, &SessionTypeWidget::processSessionTypesServicesReply);

connect(ui->btnProjects, & QPushButton::clicked, this, &SessionTypeWidget::btnSaveProjects_clicked);
}

Expand Down Expand Up @@ -445,7 +482,6 @@ void SessionTypeWidget::on_tabNav_currentChanged(int index)
{
QUrlQuery args;
args.addQueryItem(WEB_QUERY_ID_SESSION_TYPE, QString::number(m_data->getId()));

QWidget* current_tab = ui->tabNav->widget(index);

if (current_tab == ui->tabProjects){
Expand All @@ -456,6 +492,13 @@ void SessionTypeWidget::on_tabNav_currentChanged(int index)
}
}

if (current_tab == ui->tabServices){
if (m_lstServices_items.isEmpty()){
args.addQueryItem(WEB_QUERY_WITH_SERVICES, "1");
queryDataRequest(WEB_SESSIONTYPESERVICE_PATH, args);
}
}

}

void SessionTypeWidget::on_btnUpdateConfig_clicked()
Expand All @@ -465,3 +508,27 @@ void SessionTypeWidget::on_btnUpdateConfig_clicked()
ui->wdgSessionType->setFieldValue("session_type_config", config_str);
saveData();
}

void SessionTypeWidget::on_btnServices_clicked()
{
QJsonDocument document;
QJsonObject base_obj;
QJsonArray services;

for(QListWidgetItem* item: std::as_const(m_lstServices_items)){
int service_id = m_lstServices_items.key(item);
if (item->checkState() == Qt::Checked){
QJsonObject data_obj;
data_obj.insert("id_service", service_id);
services.append(data_obj);
}
}

QJsonObject service_obj;
service_obj.insert("id_session_type", m_data->getId());
service_obj.insert("services", services);
base_obj.insert("session_type", service_obj);
document.setObject(base_obj);
postDataRequest(WEB_SESSIONTYPESERVICE_PATH, document.toJson());
}

6 changes: 5 additions & 1 deletion client/src/editors/SessionTypeWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include <QWidget>
#include <QTreeWidgetItem>
#include <QListWidgetItem>

#include "DataEditorWidget.h"
#include "GlobalMessageBox.h"

namespace Ui {
class SessionTypeWidget;
Expand All @@ -28,6 +28,7 @@ class SessionTypeWidget : public DataEditorWidget

QMap<int, QTreeWidgetItem*> m_treeSites_items;
QMap<int, QTreeWidgetItem*> m_treeProjects_items;
QMap<int, QListWidgetItem*> m_lstServices_items;

void updateControlsState();
void updateFieldsValue();
Expand All @@ -36,6 +37,7 @@ class SessionTypeWidget : public DataEditorWidget
void updateSessionTypeProject(TeraData* stp);
void updateSite(TeraData *site);
void updateProject(TeraData *project);
void updateSessionTypeService(TeraData *sts);

void postSessionTypeSites();
void postSessionTypeProjects();
Expand All @@ -49,13 +51,15 @@ private slots:
void processSessionTypesSitesReply(QList<TeraData> sts_list);
void processSitesReply(QList<TeraData> sites);
void processProjectsReply(QList<TeraData> projects);
void processSessionTypesServicesReply(QList<TeraData> services);
void postResultReply(QString path);

void btnSaveProjects_clicked();

void on_treeProjects_itemChanged(QTreeWidgetItem *item, int column);
void on_tabNav_currentChanged(int index);
void on_btnUpdateConfig_clicked();
void on_btnServices_clicked();
};

#endif // SESSIONTYPEWIDGET_H
82 changes: 67 additions & 15 deletions client/src/editors/SessionTypeWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="icoTitle">
<property name="sizePolicy">
Expand All @@ -135,7 +138,7 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
<string/>
</property>
<property name="pixmap">
<pixmap>:/icons/session_type.png</pixmap>
<pixmap resource="../../resources/TeraClient.qrc">:/icons/session_type.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
Expand All @@ -159,11 +162,11 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
<item>
<widget class="QTabWidget" name="tabNav">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tabDashboard">
<attribute name="icon">
<iconset>
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/info.png</normaloff>:/icons/info.png</iconset>
</attribute>
<attribute name="title">
Expand Down Expand Up @@ -202,7 +205,7 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
Expand All @@ -227,7 +230,7 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
<string>Éditer</string>
</property>
<property name="icon">
<iconset>
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/edit.png</normaloff>:/icons/edit.png</iconset>
</property>
<property name="iconSize">
Expand Down Expand Up @@ -272,7 +275,7 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
<string>Sauvegarder</string>
</property>
<property name="icon">
<iconset>
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/save.png</normaloff>:/icons/save.png</iconset>
</property>
<property name="iconSize">
Expand All @@ -298,7 +301,7 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
<string>Annuler</string>
</property>
<property name="icon">
<iconset>
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/undo.png</normaloff>:/icons/undo.png</iconset>
</property>
<property name="iconSize">
Expand All @@ -316,7 +319,7 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
</widget>
<widget class="QWidget" name="tabProjects">
<attribute name="icon">
<iconset>
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/site-icon.png</normaloff>:/icons/site-icon.png</iconset>
</attribute>
<attribute name="title">
Expand All @@ -332,13 +335,13 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
<enum>Qt::FocusPolicy::NoFocus</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::EditTrigger::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
<enum>QAbstractItemView::SelectionMode::NoSelection</enum>
</property>
<property name="iconSize">
<size>
Expand Down Expand Up @@ -371,7 +374,54 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
<string>Mettre à jour les sites / projets associés</string>
</property>
<property name="icon">
<iconset>
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/save.png</normaloff>:/icons/save.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabServices">
<attribute name="icon">
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/service.png</normaloff>:/icons/service.png</iconset>
</attribute>
<attribute name="title">
<string>Services additionnels</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QListWidget" name="lstServices">
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnServices">
<property name="minimumSize">
<size>
<width>0</width>
<height>32</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Mettre à jour les services associés</string>
</property>
<property name="icon">
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/save.png</normaloff>:/icons/save.png</iconset>
</property>
<property name="iconSize">
Expand All @@ -386,7 +436,7 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
</widget>
<widget class="QWidget" name="tabConfig">
<attribute name="icon">
<iconset>
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/config.png</normaloff>:/icons/config.png</iconset>
</attribute>
<attribute name="title">
Expand Down Expand Up @@ -421,7 +471,7 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
<string>Mettre à jour la configuration</string>
</property>
<property name="icon">
<iconset>
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/save.png</normaloff>:/icons/save.png</iconset>
</property>
<property name="iconSize">
Expand All @@ -446,6 +496,8 @@ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../../resources/TeraClient.qrc"/>
</resources>
<connections/>
</ui>
7 changes: 4 additions & 3 deletions client/src/editors/TeraForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,11 +1300,12 @@ bool TeraForm::validateWidget(QWidget *widget, bool include_hidden)
if (!dynamic_cast<QPushButton*>(widget)) // Ignore push button in validation
widget->setStyleSheet("");
}else{
if (!dynamic_cast<QComboBox*>(widget)){
widget->setStyleSheet("background-color: #ffaaaa;");
/*if (!dynamic_cast<QComboBox*>(widget)){
widget->setStyleSheet("background-color: #ffaaaa;");
}else{
widget->setStyleSheet("background-color: #ffaaaa; color:black;");
}
widget->setStyleSheet("background-color: #ffaaaa; color:white;");
}*/
}
return rval;
}
Expand Down
Loading

0 comments on commit e478b15

Please sign in to comment.