Skip to content

Commit

Permalink
Refs #99. Added SurveyJS answers view button in service config widget
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Dec 19, 2024
1 parent 8c0800b commit 79f1596
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 2 deletions.
31 changes: 30 additions & 1 deletion client/src/services/SurveyService/SurveyEditorDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "ui_SurveyEditorDialog.h"

#include <QWebEngineProfile>
#include <QFileDialog>
#include <QStandardPaths>

SurveyEditorDialog::SurveyEditorDialog(SurveyComManager *surveyComManager, const QString& test_type_uuid, QWidget *parent)
: QDialog(parent)
Expand Down Expand Up @@ -38,6 +40,8 @@ SurveyEditorDialog::SurveyEditorDialog(SurveyComManager *surveyComManager, const
connect(m_webPage, &QWebEnginePage::loadProgress, this, &SurveyEditorDialog::onPageLoadingProcess);
m_webView->setPage(m_webPage);

connect(m_webPage->profile(), &QWebEngineProfile::downloadRequested, this, &SurveyEditorDialog::onFileDownloadRequested);

connect(m_surveyComManager, &SurveyComManager::userTokenUpdated, this, &SurveyEditorDialog::onUserTokenUpdated);

}
Expand Down Expand Up @@ -65,6 +69,20 @@ void SurveyEditorDialog::loadEditor()
m_webPage->load(editor_url);
}

void SurveyEditorDialog::loadManager(const int &id_project)
{
ui->wdgWebView->hide();
QUrl manager_url = m_surveyComManager->getServerUrl();
manager_url.setPath(m_surveyComManager->getServiceEndpoint("manager"));
QUrlQuery args;
//TODO: Enable arguments when supported by service
//args.addQueryItem("token", m_surveyComManager->getCurrentToken());
args.addQueryItem("test_type_uuid", m_testTypeUuid);
//args.addQueryItem("id_project", QString::number(id_project));
manager_url.setQuery(args);
m_webPage->load(manager_url);
}

void SurveyEditorDialog::on_btnClose_clicked()
{
reject();
Expand Down Expand Up @@ -99,9 +117,20 @@ void SurveyEditorDialog::onPageLoadingProcess(int progress)
ui->progressLoading->setValue(progress);
}

void SurveyEditorDialog::onFileDownloadRequested(QWebEngineDownloadRequest *download)
{
QString filename = QFileDialog::getSaveFileName(this, tr("Enregistrer sous"), QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first() + "/" + download->suggestedFileName());
if (!filename.isEmpty()){
download->setDownloadFileName(filename);
download->accept();
}else{
download->cancel();
}
}

void SurveyEditorDialog::onUserTokenUpdated()
{
qDebug() << "Changing user token in Survey Editor";
//qDebug() << "Changing user token in Survey Editor";
m_webPage->runJavaScript("set_user_token(\"" + m_surveyComManager->getCurrentToken() + "\");");
}

3 changes: 3 additions & 0 deletions client/src/services/SurveyService/SurveyEditorDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QWebEngineView>
#include <QWebEngineCertificateError>
#include <QWebEngineLoadingInfo>
#include <QWebEngineDownloadRequest>

#include "SurveyComManager.h"
#include "libs/WebPageRequestInterceptor.h"
Expand All @@ -24,13 +25,15 @@ class SurveyEditorDialog : public QDialog

void setCurrentTestTypeUuid(const QString& test_type_uuid);
void loadEditor();
void loadManager(const int& id_project);

private slots:
void on_btnClose_clicked();

void onCertificateError(const QWebEngineCertificateError &certificateError);
void onPageLoadingChanged(const QWebEngineLoadingInfo &loadingInfo);
void onPageLoadingProcess(int progress);
void onFileDownloadRequested(QWebEngineDownloadRequest *download);

void onUserTokenUpdated();

Expand Down
26 changes: 26 additions & 0 deletions client/src/services/SurveyService/SurveyServiceConfigWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void SurveyServiceConfigWidget::setEditMode(const bool &editing)
ui->frameSave->setVisible(editing);

ui->btnEditSurvey->setVisible(m_id_survey > 0 && !editing);
ui->btnAnswers->setVisible(m_id_survey > 0 && !editing);
ui->frameEditor->setEnabled(editing);
ui->frameItemEditor->setVisible(editing || m_id_survey > 0);
ui->frameItems->setEnabled(!editing);
Expand Down Expand Up @@ -100,6 +101,25 @@ void SurveyServiceConfigWidget::showSurveyEditor()

}

void SurveyServiceConfigWidget::showSurveyManager()
{
if (!m_data)
return;

if (m_data->isNew())
return;

if (!m_surveyEditor){
m_surveyEditor = new SurveyEditorDialog(m_surveyComManager, m_data->getUuid(), this);
connect(m_surveyEditor, &SurveyEditorDialog::finished, this, &SurveyServiceConfigWidget::surveyEditorFinished);
}else{
m_surveyEditor->setCurrentTestTypeUuid(m_data->getUuid());
}
m_surveyEditor->loadManager(m_id_project);

m_surveyEditor->showMaximized();
}

void SurveyServiceConfigWidget::processTestTypesReply(QList<TeraData> ttp_list, QUrlQuery reply_query)
{
for(const TeraData &data:ttp_list){
Expand Down Expand Up @@ -335,3 +355,9 @@ void SurveyServiceConfigWidget::on_btnDelete_clicked()
}
}


void SurveyServiceConfigWidget::on_btnAnswers_clicked()
{
showSurveyManager();
}

2 changes: 2 additions & 0 deletions client/src/services/SurveyService/SurveyServiceConfigWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private slots:
void on_btnEditSurvey_clicked();
void on_btnEdit_clicked();
void on_btnDelete_clicked();
void on_btnAnswers_clicked();

private:
Ui::SurveyServiceConfigWidget *ui;
Expand All @@ -66,6 +67,7 @@ private slots:
void queryTestTypes();
void setEditMode(const bool& editing);
void showSurveyEditor();
void showSurveyManager();


};
Expand Down
40 changes: 39 additions & 1 deletion client/src/services/SurveyService/SurveyServiceConfigWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>673</width>
<height>484</height>
<height>490</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -470,12 +470,24 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>32</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
Expand All @@ -494,6 +506,32 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnAnswers">
<property name="minimumSize">
<size>
<width>0</width>
<height>32</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Voir les réponses pour ce projet</string>
</property>
<property name="icon">
<iconset resource="../../../resources/TeraClient.qrc">
<normaloff>:/icons/search.png</normaloff>:/icons/search.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit 79f1596

Please sign in to comment.