192 lines
5.5 KiB
C++
Executable File
192 lines
5.5 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* ResourceManangement - Plan Edit Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*
|
|
* Created by Mike Wille, SLSE, 2017-04-21
|
|
*/
|
|
|
|
#include "ism_plan_edit_dialog.h"
|
|
#include "ui_ism_plan_edit_dialog.h"
|
|
#include "ism_plan_dialog_model.h"
|
|
|
|
#include <Services/InfrastructureManagement/ism_dtc.h>
|
|
#include <Services/InfrastructureManagement/ism_ftc.h>
|
|
#include <LtsUtilsGuiDds/request_helper.h>
|
|
|
|
namespace InfrastructureManagement
|
|
{
|
|
|
|
PlanEditDialog::PlanEditDialog(QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
|
, m_session(nullptr)
|
|
, m_ui(new Ui::PlanEditDialog)
|
|
, m_dtc(nullptr)
|
|
, m_ftc(nullptr)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_logger(getLogger("PlanEditDialog"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
m_uiRequirements->addRequirement( { m_ui->lblName, [this]()
|
|
{
|
|
return (!m_ui->leName->text().isEmpty()); }
|
|
});
|
|
|
|
setOnlineHelpFilename(QStringLiteral("Ressourcen-Plans"));
|
|
}
|
|
|
|
PlanEditDialog::~PlanEditDialog()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
bool PlanEditDialog::init(LtsSession::LtsSession *session,
|
|
const int scheduleId,
|
|
const std::shared_ptr<Interface::Dtc> &dtc,
|
|
const std::shared_ptr<Interface::Ftc> &ftc,
|
|
const std::shared_ptr<ForeignGuiComboboxInterface> &ismCbx)
|
|
{
|
|
m_scheduleId = scheduleId;
|
|
m_dtc = dtc;
|
|
m_ftc = ftc;
|
|
m_ismGuiCbxIfc = ismCbx;
|
|
m_session = session;
|
|
|
|
m_ui->dteBegin->setRetrieveCurrentTimeCallback([this]() { return m_session->partitionTime(); });
|
|
m_ui->dteEnd->setRetrieveCurrentTimeCallback([this]() { return m_session->partitionTime(); });
|
|
|
|
m_ismGuiCbxIfc->fillScheduleStatusComboBox(m_ui->cbStatus);
|
|
|
|
if (m_scheduleId > 0) // edit plan
|
|
{
|
|
MainSchedule data = dtc->mainSchedule(m_scheduleId);
|
|
|
|
m_currentState = data.statusId();
|
|
m_ui->cbStatus->setCurrentIndex(m_ui->cbStatus->findData(data.statusId().underlying()));
|
|
|
|
m_ui->leName->setText(QString::fromStdString(data.name()));
|
|
if (data.timeStart().is_set())
|
|
m_ui->dteBegin->setMsecsSinceEpoch(data.timeStart().get());
|
|
if (data.timeEnd().is_set())
|
|
m_ui->dteEnd->setMsecsSinceEpoch(data.timeEnd().get());
|
|
|
|
}
|
|
else // add plan
|
|
{
|
|
m_currentState = ScheduleStatus::Active;
|
|
m_ui->cbStatus->setCurrentIndex(m_ui->cbStatus->findData(ScheduleStatus::Inactive));
|
|
m_ui->cbStatus->setEnabled(true);
|
|
}
|
|
|
|
enaDisa();
|
|
|
|
return true;
|
|
}
|
|
|
|
bool PlanEditDialog::apply()
|
|
{
|
|
|
|
|
|
|
|
if (!m_ui->dteBegin->isEmpty() && !m_ui->dteEnd->isEmpty() && m_ui->dteBegin->msecsSinceEpoch() > m_ui->dteEnd->msecsSinceEpoch())
|
|
{
|
|
QString msg = tr("Begin time must be before end time.");
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Cannot save instrumentation plan '%1':\n%2").arg(m_ui->leName->text(), msg));
|
|
return false;
|
|
}
|
|
|
|
|
|
for(auto schedule : m_dtc->mainSchedules())
|
|
{
|
|
if(schedule.name() == m_ui->leName->text().toStdString())
|
|
{
|
|
if(m_scheduleId <= 0)
|
|
{
|
|
QString msg = tr("The name is already in use.");
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Cannot save instrumentation plan '%1':\n%2").arg(m_ui->leName->text(), msg));
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if(m_scheduleId != schedule.id() && schedule.name() == m_ui->leName->text().toStdString())
|
|
{
|
|
|
|
QString msg = tr("The name is already in use.");
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Cannot save instrumentation plan '%1':\n%2").arg(m_ui->leName->text(), msg));
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
MainScheduleModifyRequest data;
|
|
data.name((m_ui->leName->text().toStdString()));
|
|
|
|
ScheduleStatus newStatus = static_cast<ScheduleStatus::type>(m_ui->cbStatus->currentData().toInt());
|
|
|
|
if (newStatus != m_currentState)
|
|
{
|
|
switch (newStatus.underlying())
|
|
{
|
|
case ScheduleStatus::Active:
|
|
//m_ui->dteBegin->setMsecsSinceEpoch(QDateTime::currentMSecsSinceEpoch());
|
|
// data.statusId(ScheduleStatus::Active);
|
|
break;
|
|
case ScheduleStatus::Inactive:
|
|
//m_ui->dteEnd->setMsecsSinceEpoch(QDateTime::currentMSecsSinceEpoch());
|
|
// data.statusId(ScheduleStatus::Inactive);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (m_scheduleId > 0) // edit schedule
|
|
{
|
|
MainSchedule ms = m_dtc->mainSchedule(m_scheduleId);
|
|
data.id(ms.id());
|
|
data.exerciseId(ms.exerciseId()); //not used
|
|
data.description(ms.description()); // not used
|
|
data.timeCreated(ms.timeCreated());
|
|
}
|
|
else // add schedule
|
|
{
|
|
data.id(0);
|
|
data.timeCreated(QDateTime::currentMSecsSinceEpoch());
|
|
}
|
|
|
|
if (!m_ui->dteBegin->isEmpty() && m_ui->dteBegin->isValidDate())
|
|
data.timeStart(m_ui->dteBegin->msecsSinceEpoch());
|
|
else
|
|
data.timeStart();
|
|
if (!m_ui->dteEnd->isEmpty() && m_ui->dteEnd->isValidDate())
|
|
data.timeEnd(m_ui->dteEnd->msecsSinceEpoch());
|
|
else
|
|
data.timeEnd();
|
|
|
|
data.statusId(static_cast<ScheduleStatus::type>(m_ui->cbStatus->currentData().toInt()));
|
|
|
|
m_requestHelper->addRequest([data,this](){
|
|
return m_ftc->mainScheduleModifyRequest(data, this);
|
|
});
|
|
return m_requestHelper->startRequests();
|
|
}
|
|
|
|
void PlanEditDialog::enaDisa()
|
|
{
|
|
m_ui->dteBegin->setEnabled(true);
|
|
m_ui->dteEnd->setEnabled(true);
|
|
}
|
|
|
|
void PlanEditDialog::retranslate()
|
|
{
|
|
translate(m_ui, m_dtc->mainSchedule(m_scheduleId), tr("Instrumentation Plan"));
|
|
}
|
|
|
|
} // namespace InfrastructureManagement
|
|
|