Skip to content

Commit

Permalink
Refs #99. Allowed selection of survey item in SurveyServiceConfigWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Nov 28, 2024
1 parent 1dad8a9 commit d3974fa
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 64 deletions.
6 changes: 3 additions & 3 deletions client/resources/stylesheet.qss
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ QTreeWidget::branch:open:has-children:has-siblings {
QLineEdit
*/
QLineEdit, QSpinBox, QTextEdit, QDateTimeEdit, QTimeEdit{
background-color: rgba(255,255,255,50%);
background-color: rgba(255,255,255,70%);
color:black;
min-height: 25px;
padding-left: 5px;
Expand All @@ -309,8 +309,8 @@ QDateTimeEdit::down-arrow:!enabled, QDateTimeEdit::up-arrow:!enabled {
QPlainTextEdit
*/
QPlainTextEdit {
background-color: rgba(255,255,255,50%);
color: white;
background-color: rgba(255,255,255,70%);
color: black;
}

/*
Expand Down
74 changes: 59 additions & 15 deletions client/src/services/SurveyService/SurveyServiceConfigWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SurveyServiceConfigWidget::SurveyServiceConfigWidget(ComManager *comManager, int

ui->setupUi(this);

ui->frameEditor->hide();
ui->frameItemEditor->hide();
ui->btnDelete->setEnabled(false);
ui->wdgMessages->hide();

Expand All @@ -24,10 +24,17 @@ SurveyServiceConfigWidget::SurveyServiceConfigWidget(ComManager *comManager, int
SurveyServiceConfigWidget::~SurveyServiceConfigWidget()
{
delete ui;
if (m_data){
delete m_data;
}
}

void SurveyServiceConfigWidget::refresh()
{
if (!m_surveyComManager->isReady()){
m_refreshRequested = true;
return;
}
queryTestTypes();
}

Expand All @@ -53,12 +60,12 @@ void SurveyServiceConfigWidget::queryTestTypes()

void SurveyServiceConfigWidget::setEditMode(const bool &editing)
{
ui->frameEditButton->setVisible(!editing && m_current_id > 0);
ui->frameEditButton->setVisible(!editing && m_id_survey > 0);
ui->frameSave->setVisible(editing);

ui->btnEditSurvey->setVisible(m_current_id > 0);
ui->btnEditSurvey->setVisible(m_id_survey > 0);
ui->frameEditor->setEnabled(editing);
ui->frameEditor->setVisible(editing || m_current_id > 0);
ui->frameItemEditor->setVisible(editing || m_id_survey > 0);
ui->frameItems->setEnabled(!editing);
ui->btnSave->setDisabled(ui->txtName->text().isEmpty());
ui->txtName->setFocus();
Expand All @@ -74,11 +81,12 @@ void SurveyServiceConfigWidget::processTestTypesReply(QList<TeraData> ttp_list,
continue;

QListWidgetItem* item = nullptr;
int id_testtype = data.getId();
//int id_testtype = data.getId();
QString testtype_uuid = data.getUuid();

// Check if we already have that item
if (m_listTestTypes_items.contains(id_testtype))
item = m_listTestTypes_items[id_testtype];
if (m_listTestTypes_items.contains(testtype_uuid))
item = m_listTestTypes_items[testtype_uuid];

QString tt_name = data.getName();

Expand All @@ -87,27 +95,36 @@ void SurveyServiceConfigWidget::processTestTypesReply(QList<TeraData> ttp_list,
// Check if we have a new item that we could match
item = new QListWidgetItem(tt_name, ui->lstData);
item->setIcon(QIcon(TeraData::getIconFilenameForDataType(TERADATA_TESTTYPE)));
m_listTestTypes_items[id_testtype] = item;
m_listTestTypes_items[testtype_uuid] = item;

}else{
// Update name if needed
m_listTestTypes_items[id_testtype]->setText(tt_name);
m_listTestTypes_items[testtype_uuid]->setText(tt_name);

// Refresh infos if we are looking for it
if (m_data){
if (m_data->getUuid() == testtype_uuid){
*m_data = data;
ui->txtDescription->setPlainText(m_data->getFieldValue("test_type_description").toString());
ui->txtName->setText(m_data->getName());
}
}
}
}
}

void SurveyServiceConfigWidget::processActiveSurveyReply(const QJsonObject survey)
{
if (m_current_id == 0){
// New servey
m_current_id = survey.value("id_active_survey").toInt();
if (m_id_survey == 0){
// New survey
m_id_survey = survey.value("id_active_survey").toInt();
}else{
// Updated survey

}
// Update related test type
QUrlQuery args;
args.addQueryItem(WEB_QUERY_UUID, survey.value("active_survey_test_type_uuid").toString());
args.addQueryItem(WEB_QUERY_UUID_TESTTYPE, survey.value("active_survey_test_type_uuid").toString());
m_comManager->doGet(WEB_TESTTYPEINFO_PATH, args);

setEditMode(false);
Expand Down Expand Up @@ -136,6 +153,16 @@ void SurveyServiceConfigWidget::handleNetworkError(QNetworkReply::NetworkError e
ui->wdgMessages->addMessage(Message(Message::MESSAGE_ERROR, error_str));
}

void SurveyServiceConfigWidget::surveyComManagerReady(bool ready)
{
if (ready){
if (m_refreshRequested){
m_refreshRequested = false;
refresh();
}
}
}

void SurveyServiceConfigWidget::nextMessageWasShown(Message current_message)
{
if (current_message.getMessageType()==Message::MESSAGE_NONE){
Expand All @@ -149,7 +176,7 @@ void SurveyServiceConfigWidget::on_btnNew_clicked()
{
ui->txtName->clear();
ui->txtDescription->clear();
m_current_id = 0;
m_id_survey = 0;

setEditMode(true);

Expand All @@ -169,7 +196,7 @@ void SurveyServiceConfigWidget::on_btnSave_clicked()
QJsonObject data_obj;
QJsonDocument doc;

data_obj["id_active_survey"] = m_current_id;
data_obj["id_active_survey"] = m_id_survey;
data_obj["active_survey_name"] = ui->txtName->text();
data_obj["active_survey_description"] = ui->txtDescription->toPlainText();

Expand All @@ -188,3 +215,20 @@ void SurveyServiceConfigWidget::on_txtName_textChanged(const QString &new_text)
ui->btnSave->setDisabled(new_text.isEmpty());
}


void SurveyServiceConfigWidget::on_lstData_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
ui->btnDelete->setEnabled(current);

if (m_data)
delete m_data;

m_data = new TeraData(TeraDataTypes::TERADATA_TESTTYPE);
m_data->setUuid(m_listTestTypes_items.key(current));

QUrlQuery args;
args.addQueryItem(SURVEY_QUERY_ACTIVE_TEST_TYPE_UUID, m_data->getUuid());
m_surveyComManager->doGet(SURVEY_ACTIVE_PATH, args);

}

13 changes: 10 additions & 3 deletions client/src/services/SurveyService/SurveyServiceConfigWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,27 @@ private slots:

void processActiveSurveyReply(const QJsonObject survey);
void handleNetworkError(QNetworkReply::NetworkError error, QString error_msg, QNetworkAccessManager::Operation op, int status_code);
void surveyComManagerReady(bool ready);

void nextMessageWasShown(Message current_message);

void on_txtName_textChanged(const QString &arg1);

void on_lstData_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);

private:
Ui::SurveyServiceConfigWidget *ui;

ComManager* m_comManager;
SurveyComManager* m_surveyComManager;

int m_id_project;
int m_current_id = 0;
int m_id_project;
int m_id_survey = 0;
TeraData* m_data = nullptr;

bool m_refreshRequested = false;

QHash<int, QListWidgetItem*> m_listTestTypes_items;
QHash<QString, QListWidgetItem*> m_listTestTypes_items; // Test type UUID mapping

void connectSignals();
void queryTestTypes();
Expand Down
88 changes: 45 additions & 43 deletions client/src/services/SurveyService/SurveyServiceConfigWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
<number>0</number>
</property>
<item>
<widget class="QFrame" name="frameEditor">
<widget class="QFrame" name="frameItemEditor">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
Expand Down Expand Up @@ -340,48 +340,50 @@
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="lblName">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Nom</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtName"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblDescription">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Description</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPlainTextEdit" name="txtDescription">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
<widget class="QFrame" name="frameEditor">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="lblName">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Nom</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="txtName"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblDescription">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Description</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPlainTextEdit" name="txtDescription">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frameSave">
Expand Down
2 changes: 2 additions & 0 deletions client/src/services/SurveyService/SurveyServiceWebAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
#define SURVEY_ACTIVE_PATH "api/surveys/active"
#define SURVEY_RESULTS_PATH "api/surveys/results"

#define SURVEY_QUERY_ACTIVE_TEST_TYPE_UUID "active_survey_test_type_uuid"


#endif // SURVEYWEBAPI_H
1 change: 1 addition & 0 deletions shared/src/WebAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
#define WEB_QUERY_UUID_ASSET "asset_uuid"
#define WEB_QUERY_UUID_USER "user_uuid"
#define WEB_QUERY_UUID_DEVICE "device_uuid"
#define WEB_QUERY_UUID_TESTTYPE "test_type_uuid"

#define WEB_QUERY_UUID "uuid"
#define WEB_QUERY_APPTAG "app_tag"
Expand Down

0 comments on commit d3974fa

Please sign in to comment.