Skip to content

Commit

Permalink
Refs #99. Added test invitations in Participant Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Dec 18, 2024
1 parent cc1cfde commit e81b3b6
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 45 deletions.
47 changes: 47 additions & 0 deletions client/src/dialogs/TestInvitationDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "TestInvitationDialog.h"
#include "services/EmailService/EmailServiceWebAPI.h"
#include "ui_TestInvitationDialog.h"

#include <QStyledItemDelegate>

#include "WebAPI.h"

TestInvitationDialog::TestInvitationDialog(ComManager *comMan, QWidget *parent)
Expand Down Expand Up @@ -34,6 +37,14 @@ void TestInvitationDialog::setTestTypes(const QList<TeraData> &test_types)
}
}

void TestInvitationDialog::setCurrentSession(const TeraData *session)
{
ui->lblSessionName->setText(session->getName());
m_currentSessionId = session->getId();
ui->lblSession->show();
ui->lblSessionName->show();
}

void TestInvitationDialog::setCurrentData(TeraData *data)
{
m_data = data;
Expand Down Expand Up @@ -69,6 +80,17 @@ void TestInvitationDialog::setEnableEmail(const bool &enable_email)
ui->chkInviteEmail->setVisible(m_enableEmails);
}

void TestInvitationDialog::setEnableInviteesList(const bool &enable)
{
if (m_data)
return; // Don't change anything if we already have some invitation data

if (!enable)
ui->stackedPages->removeWidget(ui->pageTargets);
else
ui->stackedPages->addWidget(ui->pageTargets);
}

void TestInvitationDialog::setInvitableDevices(QHash<int, TeraData> *devices)
{
if (devices)
Expand All @@ -93,6 +115,27 @@ void TestInvitationDialog::setInvitableUsers(QHash<int, TeraData> *users)
ui->widgetInvitees->setAvailableUsers(QList<TeraData>());
}

void TestInvitationDialog::addDevicesToInvitation(const QStringList &device_uuids)
{
for(const QString& uuid: device_uuids){
ui->widgetInvitees->addDeviceToSession(uuid);
}
}

void TestInvitationDialog::addParticipantsToInvitation(const QStringList &participant_uuids)
{
for(const QString& uuid: participant_uuids){
ui->widgetInvitees->addParticipantToSession(uuid);
}
}

void TestInvitationDialog::addUsersToInvitation(const QStringList &user_uuids)
{
for(const QString& uuid: user_uuids){
ui->widgetInvitees->addUserToSession(uuid);
}
}

void TestInvitationDialog::processTestInvitationsReply(QList<TeraData> invitations)
{
if (ui->chkInviteEmail->isChecked()){
Expand Down Expand Up @@ -125,9 +168,13 @@ void TestInvitationDialog::emailSentError(QNetworkReply::NetworkError error, QSt

void TestInvitationDialog::initUI()
{
ui->cmbTestType->setItemDelegate(new QStyledItemDelegate(ui->cmbTestType));

ui->stackedPages->setCurrentIndex(0);
ui->lblCount->hide();
ui->numCount->hide();
ui->lblSession->hide();
ui->lblSessionName->hide();
ui->btnPrevious->setEnabled(false);
ui->btnOK->setVisible(false);
ui->btnDone->setVisible(false);
Expand Down
7 changes: 7 additions & 0 deletions client/src/dialogs/TestInvitationDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ class TestInvitationDialog : public QDialog
~TestInvitationDialog();

void setTestTypes(const QList<TeraData>& test_types);
void setCurrentSession(const TeraData* session);
void setCurrentData(TeraData* data);
void setEnableEmail(const bool& enable_email);
void setEnableInviteesList(const bool& enable);

void setInvitableDevices(QHash<int, TeraData>* devices);
void setInvitableParticipants(QHash<int, TeraData>* participants);
void setInvitableUsers(QHash<int, TeraData>* users);

void addDevicesToInvitation(const QStringList &device_uuids);
void addParticipantsToInvitation(const QStringList &participant_uuids);
void addUsersToInvitation(const QStringList &user_uuids);

private slots:
void processTestInvitationsReply(QList<TeraData> invitations);
void emailSentSuccess();
Expand All @@ -47,6 +53,7 @@ private slots:
bool m_enableEmails = false;

QList<TeraData> m_pendingInvitations;
int m_currentSessionId = 0;

void initUI();
void processNextEmail();
Expand Down
47 changes: 36 additions & 11 deletions client/src/dialogs/TestInvitationDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</property>
<widget class="QWidget" name="pageTestType">
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="1">
<item row="6" column="1">
<widget class="QCheckBox" name="chkInviteEmail">
<property name="text">
<string>Envoyer les invitations automatiquement par courriel</string>
Expand All @@ -51,7 +51,10 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="1">
<widget class="QSpinBox" name="numCount"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lblMaxUsage">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
Expand All @@ -75,6 +78,21 @@
<item row="1" column="1">
<widget class="QComboBox" name="cmbTestType"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lblCount">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Usage actuel</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblTestTypes">
<property name="sizePolicy">
Expand All @@ -96,7 +114,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QSpinBox" name="numUsage">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
Expand All @@ -116,9 +134,12 @@
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>1</number>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QDateEdit" name="dateExpiration">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
Expand Down Expand Up @@ -150,7 +171,7 @@
</property>
</spacer>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="lblExpiration">
<property name="font">
<font>
Expand All @@ -165,7 +186,7 @@
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
Expand All @@ -178,23 +199,27 @@
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lblCount">
<item row="2" column="0">
<widget class="QLabel" name="lblSession">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Usage actuel</string>
<string>Séance</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="numCount"/>
<item row="2" column="1">
<widget class="QLabel" name="lblSessionName">
<property name="text">
<string>(Séance)</string>
</property>
</widget>
</item>
</layout>
</widget>
Expand Down
39 changes: 38 additions & 1 deletion client/src/editors/ParticipantWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ ParticipantWidget::ParticipantWidget(ComManager *comMan, const TeraData *data, Q
args.addQueryItem(WEB_QUERY_ID_PROJECT, QString::number(m_data->getFieldValue("id_project").toInt()));
queryDataRequest(WEB_DEVICEPROJECTINFO_PATH, args);

// Query test types if not a new participant
args.clear();
args.addQueryItem(WEB_QUERY_LIST, "1");
args.addQueryItem(WEB_QUERY_ID_PROJECT, m_data->getFieldValue("id_project").toString());
queryDataRequest(WEB_TESTTYPEINFO_PATH, args);

}

// Default display
Expand Down Expand Up @@ -128,6 +134,7 @@ void ParticipantWidget::connectSignals()
connect(m_comManager, &ComManager::deviceParticipantsReceived, this, &ParticipantWidget::processDeviceParticipantsReply);
connect(m_comManager, &ComManager::participantsReceived, this, &ParticipantWidget::processParticipantsReply);
connect(m_comManager, &ComManager::servicesReceived, this, &ParticipantWidget::processServicesReply);
connect(m_comManager, &ComManager::testTypesReceived, this, &ParticipantWidget::processTestTypesReply);
connect(m_comManager, &ComManager::statsReceived, this, &ParticipantWidget::processStatsReply);
connect(m_comManager, &ComManager::deleteResultsOK, this, &ParticipantWidget::deleteDataReply);

Expand Down Expand Up @@ -239,16 +246,20 @@ void ParticipantWidget::initUI()
"participant_username", "participant_password"};
ui->wdgParticipant->hideFields(ignore_fields);

// Hide device & service tabs by default
// Hide device, service and invitation tabs by default
ui->tabNav->setTabVisible(ui->tabNav->indexOf(ui->tabDevices), false);
ui->tabNav->setTabVisible(ui->tabNav->indexOf(ui->tabServices), false);
ui->tabNav->setTabVisible(ui->tabNav->indexOf(ui->tabInvitations), false);
ui->tabServicesDetails->setTabVisible(ui->tabServicesDetails->indexOf(ui->tabServiceParams), false);

// Configure log view
ui->wdgLogins->setComManager(m_comManager);
ui->wdgLogins->setViewMode(LogViewWidget::VIEW_LOGINS_PARTICIPANT, m_data->getUuid());
ui->wdgLogins->setUuidName(m_data->getUuid(), m_data->getName());

// Configure invitation widget
ui->wdgInvitations->setComManager(m_comManager);

}

bool ParticipantWidget::canStartNewSession(const int &id_session_type)
Expand Down Expand Up @@ -536,6 +547,24 @@ void ParticipantWidget::processParticipantsReply(QList<TeraData> participants)
}
}

void ParticipantWidget::processTestTypesReply(QList<TeraData> test_types, QUrlQuery reply_query)
{
if (dataIsNew())
return;

if (!reply_query.hasQueryItem(WEB_QUERY_ID_PROJECT))
return;

if (reply_query.queryItemValue(WEB_QUERY_ID_PROJECT) == m_data->getFieldValue("id_project").toString()){
// For us!
m_testTypes.clear();
m_testTypes = test_types;
ui->wdgInvitations->setCurrentTestTypes(m_testTypes);
ui->tabNav->setTabVisible(ui->tabNav->indexOf(ui->tabInvitations), !m_testTypes.isEmpty());
}

}

void ParticipantWidget::processServicesReply(QList<TeraData> services, QUrlQuery reply_query)
{
if (!reply_query.hasQueryItem(WEB_QUERY_ID_PROJECT))
Expand Down Expand Up @@ -576,6 +605,7 @@ void ParticipantWidget::processServicesReply(QList<TeraData> services, QUrlQuery
}

ui->btnEmailWeb->setVisible(has_email_service);
ui->wdgInvitations->setEnableEmail(has_email_service);

// Find and select VideoRehab by default in the combobox
int default_index = ui->cmbServices->findData("VideoRehabService");
Expand Down Expand Up @@ -1151,6 +1181,13 @@ void ParticipantWidget::on_tabNav_currentChanged(int index)
ui->wdgServiceConfig->layout()->addWidget(service_config_widget);
}
}

// Test invitations
if (current_tab == ui->tabInvitations){
if (m_data){
ui->wdgInvitations->loadForParticipant(m_data);
}
}
}


Expand Down
3 changes: 3 additions & 0 deletions client/src/editors/ParticipantWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class ParticipantWidget : public DataEditorWidget
QMap<int, QWidget*> m_services_tabs;
bool m_allowFileTransfers; // Allow to attach files to a session?

QList<TeraData> m_testTypes;

QRCodeDialog* m_diag_qr = nullptr;
#ifndef OPENTERA_WEBASSEMBLY
SessionLobbyDialog* m_sessionLobby;
Expand Down Expand Up @@ -90,6 +92,7 @@ private slots:
void processDeviceProjectsReply(QList<TeraData> device_projects);
void processDeviceParticipantsReply(QList<TeraData> device_participants);
void processParticipantsReply(QList<TeraData> participants);
void processTestTypesReply(QList<TeraData> test_types, QUrlQuery reply_query);
void processServicesReply(QList<TeraData> services, QUrlQuery reply_query);
void processStatsReply(TeraData stats, QUrlQuery reply_query);

Expand Down
Loading

0 comments on commit e81b3b6

Please sign in to comment.