Skip to content

Commit

Permalink
Refs #99. Added test invitation editing
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Dec 17, 2024
1 parent 3c8199d commit 374ef18
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 95 deletions.
88 changes: 61 additions & 27 deletions client/src/dialogs/TestInvitationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ void TestInvitationDialog::setTestTypes(const QList<TeraData> &test_types)
}
}

void TestInvitationDialog::setCurrentData(TeraData *data)
{
m_data = data;
ui->lblCount->setVisible(m_data);
ui->numCount->setVisible(m_data);
ui->cmbTestType->setEnabled(!m_data);
ui->btnNext->setVisible(!m_data);
ui->btnPrevious->setVisible(!m_data);
ui->btnOK->setText(m_data ? tr("OK") : tr("Inviter"));
ui->btnOK->setVisible(m_data);

if (m_data){
int test_index = ui->cmbTestType->findData(m_data->getFieldValue("id_test_type").toInt());
ui->cmbTestType->setCurrentIndex(test_index);
ui->numUsage->setValue(m_data->getFieldValue("test_invitation_max_count").toInt());
ui->numCount->setValue(m_data->getFieldValue("test_invitation_count").toInt());
}

}

void TestInvitationDialog::setInvitableDevices(QHash<int, TeraData> *devices)
{
if (devices)
Expand Down Expand Up @@ -54,6 +74,8 @@ void TestInvitationDialog::setInvitableUsers(QHash<int, TeraData> *users)
void TestInvitationDialog::initUI()
{
ui->stackedPages->setCurrentIndex(0);
ui->lblCount->hide();
ui->numCount->hide();
ui->btnPrevious->setEnabled(false);
ui->btnOK->setVisible(false);

Expand Down Expand Up @@ -107,37 +129,49 @@ void TestInvitationDialog::on_btnOK_clicked()
QJsonObject base_obj;
QJsonArray invitations;

QList<int> ids = ui->widgetInvitees->getParticipantsIdsInSession();
for(int id: ids){
QJsonObject invitation;
invitation["id_test_invitation"] = 0;
invitation["id_participant"] = id;
invitation["id_test_type"] = ui->cmbTestType->currentData().toInt();
invitation["test_invitation_count"] = ui->numUsage->value();
invitation["test_invitation_expiration_date"] = QJsonValue::fromVariant(ui->dateExpiration->date());
invitations.append(invitation);
}

ids = ui->widgetInvitees->getDevicesIdsInSession();
for(int id: ids){
if (!m_data){
// New
QList<int> ids = ui->widgetInvitees->getParticipantsIdsInSession();
for(int id: ids){
QJsonObject invitation;
invitation["id_test_invitation"] = 0;
invitation["id_participant"] = id;
invitation["id_test_type"] = ui->cmbTestType->currentData().toInt();
invitation["test_invitation_max_count"] = ui->numUsage->value();
invitation["test_invitation_expiration_date"] = QJsonValue::fromVariant(ui->dateExpiration->date());
invitations.append(invitation);
}

ids = ui->widgetInvitees->getDevicesIdsInSession();
for(int id: ids){
QJsonObject invitation;
invitation["id_test_invitation"] = 0;
invitation["id_device"] = id;
invitation["id_test_type"] = ui->cmbTestType->currentData().toInt();
invitation["test_invitation_max_count"] = ui->numUsage->value();
invitation["test_invitation_expiration_date"] = QJsonValue::fromVariant(ui->dateExpiration->date());
invitations.append(invitation);
}

ids = ui->widgetInvitees->getUsersIdsInSession();
for(int id: ids){
QJsonObject invitation;
invitation["id_test_invitation"] = 0;
invitation["id_user"] = id;
invitation["id_test_type"] = ui->cmbTestType->currentData().toInt();
invitation["test_invitation_max_count"] = ui->numUsage->value();
invitation["test_invitation_expiration_date"] = QJsonValue::fromVariant(ui->dateExpiration->date());
invitations.append(invitation);
}
}else{
// Update
QJsonObject invitation;
invitation["id_test_invitation"] = 0;
invitation["id_device"] = id;
invitation["id_test_type"] = ui->cmbTestType->currentData().toInt();
invitation["test_invitation_count"] = ui->numUsage->value();
invitation["id_test_invitation"] = m_data->getId();
invitation["test_invitation_max_count"] = ui->numUsage->value();
invitation["test_invitation_count"] = ui->numCount->value();
invitation["test_invitation_expiration_date"] = QJsonValue::fromVariant(ui->dateExpiration->date());
invitations.append(invitation);
}

ids = ui->widgetInvitees->getUsersIdsInSession();
for(int id: ids){
QJsonObject invitation;
invitation["id_test_invitation"] = 0;
invitation["id_user"] = id;
invitation["id_test_type"] = ui->cmbTestType->currentData().toInt();
invitation["test_invitation_count"] = ui->numUsage->value();
invitation["test_invitation_expiration_date"] = QJsonValue::fromVariant(ui->dateExpiration->date());
invitations.append(invitation);
}
base_obj["tests_invitations"] = invitations;
doc.setObject(base_obj);
Expand Down
3 changes: 3 additions & 0 deletions client/src/dialogs/TestInvitationDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class TestInvitationDialog : public QDialog
~TestInvitationDialog();

void setTestTypes(const QList<TeraData>& test_types);
void setCurrentData(TeraData* data);

void setInvitableDevices(QHash<int, TeraData>* devices);
void setInvitableParticipants(QHash<int, TeraData>* participants);
void setInvitableUsers(QHash<int, TeraData>* users);
Expand All @@ -34,6 +36,7 @@ private slots:
private:
Ui::TestInvitationDialog *ui;
ComManager* m_comManager;
TeraData* m_data = nullptr;

void initUI();
};
Expand Down
132 changes: 75 additions & 57 deletions client/src/dialogs/TestInvitationDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,21 @@
</property>
<widget class="QWidget" name="pageTestType">
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QLabel" name="lblExpiration">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Date d'expiration</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
<widget class="QCheckBox" name="chkInviteEmail">
<property name="text">
<string>Envoyer les invitations automatiquement par courriel</string>
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="QDateEdit" name="dateExpiration">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<property name="icon">
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/email.png</normaloff>:/icons/email.png</iconset>
</property>
<property name="minimumSize">
<property name="iconSize">
<size>
<width>0</width>
<height>0</height>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::ButtonSymbols::UpDownArrows</enum>
</property>
</widget>
</item>
<item row="2" column="0">
Expand All @@ -105,20 +75,24 @@
<item row="1" column="1">
<widget class="QComboBox" name="cmbTestType"/>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="chkInviteEmail">
<property name="text">
<string>Envoyer les invitations automatiquement par courriel</string>
<item row="1" column="0">
<widget class="QLabel" name="lblTestTypes">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="icon">
<iconset resource="../../resources/TeraClient.qrc">
<normaloff>:/icons/email.png</normaloff>:/icons/email.png</iconset>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
<property name="text">
<string>Test</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
Expand All @@ -144,29 +118,55 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblTestTypes">
<item row="4" column="1">
<widget class="QDateEdit" name="dateExpiration">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::ButtonSymbols::UpDownArrows</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lblExpiration">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Test</string>
<string>Date d'expiration</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer_2">
<item row="6" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
Expand All @@ -178,6 +178,24 @@
</property>
</spacer>
</item>
<item row="3" 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="3" column="1">
<widget class="QSpinBox" name="numCount"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="pageTargets">
Expand Down
13 changes: 12 additions & 1 deletion client/src/dialogs/WebLoginDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ WebLoginDialog::WebLoginDialog(ConfigManagerClient *config, QWidget *parent)
connect(m_webPage, &QWebEnginePage::certificateError, this, &WebLoginDialog::onCertificateError);
connect(m_webPage, &QWebEnginePage::loadingChanged, this, &WebLoginDialog::onLoginPageLoadingChanged);

connect(myObject, &WebLoginSharedObject::loginSuccess, this, &WebLoginDialog::loginSuccess);
connect(myObject, &WebLoginSharedObject::loginSuccess, this, &WebLoginDialog::onLoginSuccess);
connect(myObject, &WebLoginSharedObject::loginFailure, this, &WebLoginDialog::onLoginFailed);
connect(myObject, &WebLoginSharedObject::mfaCheckInProgress, this, &WebLoginDialog::onMfaCheckInProgress);
connect(myObject, &WebLoginSharedObject::mfaSetupInProgress, this, &WebLoginDialog::onMfaSetupInProgress);
Expand Down Expand Up @@ -174,6 +174,17 @@ void WebLoginDialog::onLoginPageLoadingChanged(const QWebEngineLoadingInfo &load
}
}

void WebLoginDialog::onLoginSuccess(const QString &token, const QString &websocket_url, const QString &user_uuid)
{
ui->lblLoading->show();
ui->btnRetry->hide();
ui->lblLoading->setText(tr("Bienvenue!"));
ui->lblError->hide();
ui->frameLoginMessages->show();
ui->stackedLogins->hide();
emit loginSuccess(token, websocket_url, user_uuid);
}

void WebLoginDialog::onMfaSetupInProgress()
{
showLargeView(true);
Expand Down
1 change: 1 addition & 0 deletions client/src/dialogs/WebLoginDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private slots:
void onCertificateError(const QWebEngineCertificateError &certificateError);
void onServerSelected(int index);
void onLoginPageLoadingChanged(const QWebEngineLoadingInfo &loadingInfo);
void onLoginSuccess(const QString &token, const QString &websocket_url, const QString &user_uuid);

void onMfaSetupInProgress();
void onMfaCheckInProgress();
Expand Down
11 changes: 8 additions & 3 deletions client/src/widgets/SessionsListWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,16 @@ void SessionsListWidget::updateSession(const TeraData *session, const bool &auto

// Resume session
if (btnResume){
btnResume->hide();
if (session->hasFieldName("session_start_datetime")){
QDateTime session_date = session->getFieldValue("session_start_datetime").toDateTime().toLocalTime();
btnResume->setVisible(session_date.date() == QDate::currentDate());
}else{
btnResume->hide();
// Check if session type can be resumed
int id_session_type = session->getFieldValue("id_session_type").toInt();
TeraData* session_type = m_ids_session_types[id_session_type];
if (session_type){
if (session_type->getFieldValue("session_type_online").toBool() == true)
btnResume->setVisible(session_date.date() == QDate::currentDate());
}
}
}

Expand Down
Loading

0 comments on commit 374ef18

Please sign in to comment.