2017-12-02 10:50:30 +01:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
2017-12-02 18:46:46 +01:00
|
|
|
#include <QUrl>
|
2017-12-02 10:50:30 +01:00
|
|
|
#include <QLineEdit>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QStandardItem>
|
|
|
|
|
#include <QStringBuilder>
|
|
|
|
|
#include <QMenu>
|
2017-12-10 21:08:19 +01:00
|
|
|
#include <QEventLoop>
|
2017-12-02 12:41:49 +01:00
|
|
|
#include <QLabel>
|
2017-12-02 18:46:46 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
|
#include <QDesktopServices>
|
2017-12-02 19:03:43 +01:00
|
|
|
#include <QRegularExpression>
|
2017-12-02 10:50:30 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
2017-12-09 01:48:18 +01:00
|
|
|
#include "timeutils.h"
|
2017-12-03 22:22:07 +01:00
|
|
|
#include "zeiterfassungsettings.h"
|
2017-12-09 04:33:52 +01:00
|
|
|
#include "stripfactory.h"
|
2017-12-09 01:48:18 +01:00
|
|
|
#include "stripswidget.h"
|
2017-12-02 10:50:30 +01:00
|
|
|
#include "dialogs/aboutmedialog.h"
|
2017-12-05 21:36:47 +01:00
|
|
|
#include "dialogs/bookingdialog.h"
|
2017-12-05 21:03:03 +01:00
|
|
|
#include "dialogs/timeassignmentdialog.h"
|
2017-12-04 20:11:11 +01:00
|
|
|
#include "dialogs/settingsdialog.h"
|
2017-12-07 00:27:39 +01:00
|
|
|
#include "dialogs/updatedialog.h"
|
2017-12-05 21:36:47 +01:00
|
|
|
#include "models/bookingsmodel.h"
|
2017-12-05 21:03:03 +01:00
|
|
|
#include "models/timeassignmentsmodel.h"
|
2017-12-10 21:08:19 +01:00
|
|
|
#include "replies/getprojectsreply.h"
|
|
|
|
|
#include "replies/getauswertungreply.h"
|
|
|
|
|
#include "replies/updatebookingreply.h"
|
|
|
|
|
#include "replies/deletebookingreply.h"
|
|
|
|
|
#include "replies/createbookingreply.h"
|
|
|
|
|
#include "replies/updatetimeassignmentreply.h"
|
|
|
|
|
#include "replies/deletetimeassignmentreply.h"
|
|
|
|
|
#include "replies/createtimeassignmentreply.h"
|
|
|
|
|
#include "replies/createbookingreply.h"
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 23:29:12 +01:00
|
|
|
MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfassung, const ZeiterfassungApi::UserInfo &userInfo,
|
|
|
|
|
StripFactory &stripFactory, QWidget *parent) :
|
2017-12-02 10:50:30 +01:00
|
|
|
QMainWindow(parent),
|
|
|
|
|
ui(new Ui::MainWindow),
|
|
|
|
|
m_settings(settings),
|
|
|
|
|
m_erfassung(erfassung),
|
|
|
|
|
m_userInfo(userInfo),
|
2017-12-10 23:29:12 +01:00
|
|
|
m_stripFactory(stripFactory),
|
2017-12-11 00:23:48 +01:00
|
|
|
m_getProjectsReply(Q_NULLPTR),
|
|
|
|
|
m_getAuswertungReply(Q_NULLPTR),
|
|
|
|
|
m_bookingsModel(new BookingsModel(this)),
|
|
|
|
|
m_timeAssignmentsModel(new TimeAssignmentsModel(this)),
|
2017-12-10 23:10:27 +01:00
|
|
|
m_currentStripWidget(Q_NULLPTR)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
2017-12-10 23:59:13 +01:00
|
|
|
for(quint8 i = 0; i < 7; i++)
|
2017-12-09 01:48:18 +01:00
|
|
|
{
|
2017-12-10 23:59:13 +01:00
|
|
|
m_stripsWidgets[i] = new StripsWidget(m_erfassung, m_userInfo.userId, m_stripFactory, m_projects, ui->widgetWeek);
|
2017-12-10 23:44:44 +01:00
|
|
|
connect(m_stripsWidgets[i], &StripsWidget::refreshingChanged, this, &MainWindow::refreshingChanged);
|
2017-12-13 23:14:37 +01:00
|
|
|
ui->layoutWeek->addWidget(m_stripsWidgets[i]);
|
2017-12-09 01:48:18 +01:00
|
|
|
}
|
2017-12-08 08:28:22 +01:00
|
|
|
|
2017-12-02 19:26:40 +01:00
|
|
|
setWindowTitle(tr("Zeiterfassung - %0 (%1)").arg(m_userInfo.text).arg(m_userInfo.email));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
ui->actionQuit->setShortcut(QKeySequence::Quit);
|
|
|
|
|
|
|
|
|
|
connect(ui->actionToday, &QAction::triggered, [=](){ ui->dateEditDate->setDate(QDate::currentDate()); });
|
|
|
|
|
|
|
|
|
|
ui->actionRefresh->setShortcut(QKeySequence::Refresh);
|
2017-12-10 23:23:00 +01:00
|
|
|
connect(ui->actionRefresh, &QAction::triggered, this, [=](){ dateChanged(true); });
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 23:10:27 +01:00
|
|
|
connect(ui->actionAuswertung, &QAction::triggered, this, &MainWindow::openAuswertung);
|
2017-12-02 18:46:46 +01:00
|
|
|
|
2017-12-02 10:50:30 +01:00
|
|
|
connect(ui->actionAboutMe, &QAction::triggered, [=](){ AboutMeDialog(userInfo, this).exec(); });
|
2017-12-04 20:11:11 +01:00
|
|
|
connect(ui->actionSettings, &QAction::triggered, [=](){ SettingsDialog(m_settings, this).exec(); });
|
|
|
|
|
|
2017-12-02 10:50:30 +01:00
|
|
|
connect(ui->actionAboutQt, &QAction::triggered, [=](){ QMessageBox::aboutQt(this); });
|
|
|
|
|
|
|
|
|
|
ui->dateEditDate->setDate(QDate::currentDate());
|
2017-12-10 23:23:00 +01:00
|
|
|
connect(ui->dateEditDate, &QDateTimeEdit::dateChanged, this, [=](){ dateChanged(false); });
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-04 20:11:11 +01:00
|
|
|
connect(ui->pushButtonPrev, &QAbstractButton::pressed, [=](){ ui->dateEditDate->setDate(ui->dateEditDate->date().addDays(-1)); });
|
|
|
|
|
connect(ui->pushButtonNext, &QAbstractButton::pressed, [=](){ ui->dateEditDate->setDate(ui->dateEditDate->date().addDays(1)); });
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
ui->timeEditTime->setTime(timeNormalise(QTime::currentTime()));
|
|
|
|
|
|
2017-12-13 23:14:37 +01:00
|
|
|
connect(ui->pushButtonNow, &QAbstractButton::pressed, [=](){ ui->timeEditTime->setTime(QTime::currentTime()); });
|
|
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
m_getProjectsReply = erfassung.doGetProjects(userInfo.userId, QDate::currentDate());
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(m_getProjectsReply.get(), &ZeiterfassungReply::finished, this, &MainWindow::getProjectsFinished);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->setMaxVisibleItems(10);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxSubproject->lineEdit()->setPlaceholderText(tr("Subproject"));
|
2017-12-02 10:50:30 +01:00
|
|
|
ui->comboBoxWorkpackage->lineEdit()->setPlaceholderText(tr("Workpackage"));
|
|
|
|
|
ui->comboBoxText->lineEdit()->setPlaceholderText(tr("Text"));
|
|
|
|
|
|
|
|
|
|
updateComboboxes();
|
|
|
|
|
|
|
|
|
|
connect(ui->pushButtonStart, &QAbstractButton::pressed, this, &MainWindow::pushButtonStartPressed);
|
|
|
|
|
connect(ui->pushButtonEnd, &QAbstractButton::pressed, this, &MainWindow::pushButtonEndPressed);
|
|
|
|
|
|
2017-12-11 00:23:48 +01:00
|
|
|
ui->treeViewBookings->setModel(m_bookingsModel);
|
|
|
|
|
connect(m_bookingsModel, &BookingsModel::enabledChanged, ui->treeViewBookings, &QWidget::setEnabled);
|
|
|
|
|
connect(ui->treeViewBookings, &QWidget::customContextMenuRequested, this, &MainWindow::contextMenuBooking);
|
|
|
|
|
|
|
|
|
|
ui->treeViewTimeAssignments->setModel(m_timeAssignmentsModel);
|
|
|
|
|
connect(m_timeAssignmentsModel, &TimeAssignmentsModel::enabledChanged, ui->treeViewTimeAssignments, &QWidget::setEnabled);
|
|
|
|
|
connect(ui->treeViewTimeAssignments, &QWidget::customContextMenuRequested, this, &MainWindow::contextMenuTimeAssignment);
|
2017-12-02 18:25:32 +01:00
|
|
|
|
2017-12-05 20:46:41 +01:00
|
|
|
ui->statusbar->addPermanentWidget(m_balanceLabel = new QLabel(ui->statusbar));
|
|
|
|
|
m_balanceLabel->setFrameShape(QFrame::Panel);
|
|
|
|
|
m_balanceLabel->setFrameShadow(QFrame::Sunken);
|
|
|
|
|
ui->statusbar->addPermanentWidget(m_holidaysLabel = new QLabel(ui->statusbar));
|
|
|
|
|
m_holidaysLabel->setFrameShape(QFrame::Panel);
|
|
|
|
|
m_holidaysLabel->setFrameShadow(QFrame::Sunken);
|
2017-12-02 19:03:43 +01:00
|
|
|
|
2017-12-10 23:10:27 +01:00
|
|
|
dateChanged();
|
2017-12-07 00:27:39 +01:00
|
|
|
|
|
|
|
|
if(settings.lastUpdateCheck().isNull() || settings.lastUpdateCheck() < QDate::currentDate())
|
|
|
|
|
new UpdateDialog(settings, erfassung.manager(), this);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
void MainWindow::getProjectsFinished()
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
if(m_getProjectsReply->success())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
m_projects.clear();
|
|
|
|
|
|
|
|
|
|
for(const auto &project : m_getProjectsReply->projects())
|
|
|
|
|
m_projects.insert(project.value, project.label);
|
|
|
|
|
|
|
|
|
|
updateComboboxes();
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
2017-12-10 21:08:19 +01:00
|
|
|
else
|
|
|
|
|
QMessageBox::warning(this, tr("Could not load bookings!"),
|
|
|
|
|
tr("Could not load bookings!") % "\n\n" % m_getProjectsReply->message());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
m_getProjectsReply = Q_NULLPTR;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
void MainWindow::getAuswertungFinished()
|
2017-12-02 18:46:46 +01:00
|
|
|
{
|
2017-12-10 23:44:44 +01:00
|
|
|
if(std::none_of(std::begin(m_stripsWidgets), std::end(m_stripsWidgets), [](StripsWidget *stripsWidget){
|
|
|
|
|
return stripsWidget->refreshing();
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(true);
|
|
|
|
|
ui->actionRefresh->setEnabled(true);
|
2017-12-10 23:59:13 +01:00
|
|
|
ui->dateEditDate->setReadOnly(false);
|
2017-12-10 23:44:44 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(true);
|
|
|
|
|
ui->pushButtonNext->setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
if(!m_getAuswertungReply->success())
|
2017-12-02 18:46:46 +01:00
|
|
|
{
|
2017-12-04 20:25:33 +01:00
|
|
|
m_auswertungDate = QDate();
|
2017-12-10 21:08:19 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not load Auswertung!"), tr("Could not load Auswertung!") % "\n\n" % m_getAuswertungReply->message());
|
2017-12-10 23:44:44 +01:00
|
|
|
m_getAuswertungReply = Q_NULLPTR;
|
2017-12-02 18:46:46 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->actionAuswertung->setEnabled(true);
|
2017-12-10 21:08:19 +01:00
|
|
|
m_auswertung = m_getAuswertungReply->auswertung();
|
2017-12-02 18:46:46 +01:00
|
|
|
|
2017-12-12 21:29:20 +01:00
|
|
|
auto urlaubsAnspruch = tr("n/a");
|
2017-12-02 19:03:43 +01:00
|
|
|
|
|
|
|
|
{
|
2017-12-05 20:46:41 +01:00
|
|
|
static QRegularExpression regex(QStringLiteral("Urlaubsanspruch +([0-9]+\\.[0-9]+\\-?) +([0-9]+\\.[0-9]+\\-?)"));
|
2017-12-10 21:08:19 +01:00
|
|
|
auto match = regex.match(m_auswertung);
|
2017-12-02 19:03:43 +01:00
|
|
|
if(match.hasMatch())
|
|
|
|
|
urlaubsAnspruch = match.captured(2);
|
|
|
|
|
else
|
|
|
|
|
qWarning() << "Urlaubsanspruch not found";
|
|
|
|
|
}
|
2017-12-12 21:29:20 +01:00
|
|
|
|
|
|
|
|
auto gleitzeit = tr("n/a");
|
|
|
|
|
|
2017-12-02 19:03:43 +01:00
|
|
|
{
|
2017-12-05 20:46:41 +01:00
|
|
|
static QRegularExpression regex(QStringLiteral("Gleitzeit +([0-9]+\\:[0-9]+\\-?) +([0-9]+\\:[0-9]+\\-?)"));
|
2017-12-10 21:08:19 +01:00
|
|
|
auto match = regex.match(m_auswertung);
|
2017-12-02 19:03:43 +01:00
|
|
|
if(match.hasMatch())
|
2017-12-05 21:03:03 +01:00
|
|
|
{
|
2017-12-02 19:03:43 +01:00
|
|
|
gleitzeit = match.captured(2);
|
2017-12-05 21:03:03 +01:00
|
|
|
if(gleitzeit.endsWith(QChar('-')))
|
|
|
|
|
{
|
|
|
|
|
gleitzeit.chop(1);
|
|
|
|
|
gleitzeit = QChar('-') % gleitzeit;
|
|
|
|
|
}
|
|
|
|
|
gleitzeit = tr("%0h").arg(gleitzeit);
|
|
|
|
|
}
|
2017-12-02 19:03:43 +01:00
|
|
|
else
|
|
|
|
|
qWarning() << "Gleitzeit not found";
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
m_balanceLabel->setText(tr("%0: %1").arg(tr("Balance")).arg(gleitzeit));
|
|
|
|
|
m_holidaysLabel->setText(tr("%0: %1").arg(tr("Holidays")).arg(urlaubsAnspruch));
|
2017-12-10 23:44:44 +01:00
|
|
|
|
|
|
|
|
m_getAuswertungReply = Q_NULLPTR;
|
2017-12-02 18:46:46 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:36:47 +01:00
|
|
|
void MainWindow::contextMenuBooking(const QPoint &pos)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
auto index = ui->treeViewBookings->indexAt(pos);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-11 00:23:48 +01:00
|
|
|
if(!index.isValid())
|
2017-12-10 21:08:19 +01:00
|
|
|
{
|
|
|
|
|
QMenu menu;
|
|
|
|
|
auto createAction = menu.addAction(tr("Create booking"));
|
2017-12-11 00:23:48 +01:00
|
|
|
auto refreshAction = menu.addAction(QIcon(QPixmap(QStringLiteral(":/zeiterfassung/images/refresh.png"))), tr("Refresh bookings"));
|
2017-12-10 21:08:19 +01:00
|
|
|
auto selectedAction = menu.exec(ui->treeViewBookings->viewport()->mapToGlobal(pos));
|
|
|
|
|
if(selectedAction == createAction)
|
|
|
|
|
{
|
|
|
|
|
BookingDialog dialog(this);
|
|
|
|
|
dialog.setTime(timeNormalise(QTime::currentTime()));
|
|
|
|
|
again2:
|
|
|
|
|
if(dialog.exec() == QDialog::Accepted)
|
|
|
|
|
{
|
|
|
|
|
auto reply = m_erfassung.doCreateBooking(m_userInfo.userId, ui->dateEditDate->date(),
|
|
|
|
|
dialog.getTime(), dialog.getTimespan(),
|
|
|
|
|
dialog.getType(), dialog.getText());
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QEventLoop eventLoop;
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit);
|
2017-12-10 21:08:19 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(reply->success())
|
|
|
|
|
{
|
2017-12-10 23:10:27 +01:00
|
|
|
m_currentStripWidget->refreshBookings();
|
2017-12-10 21:08:19 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not create booking!"), tr("Could not create booking!") % "\n\n" % reply->message());
|
|
|
|
|
goto again2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-11 00:23:48 +01:00
|
|
|
else if(selectedAction == refreshAction)
|
|
|
|
|
{
|
|
|
|
|
m_currentStripWidget->refreshBookings();
|
|
|
|
|
}
|
2017-12-10 21:08:19 +01:00
|
|
|
}
|
|
|
|
|
else
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-10 23:10:27 +01:00
|
|
|
auto booking = m_currentStripWidget->bookings().at(index.row());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
QMenu menu;
|
2017-12-05 21:36:47 +01:00
|
|
|
auto editAction = menu.addAction(tr("Edit booking"));
|
|
|
|
|
auto deleteAction = menu.addAction(tr("Delete booking"));
|
|
|
|
|
auto selectedAction = menu.exec(ui->treeViewBookings->viewport()->mapToGlobal(pos));
|
2017-12-02 10:50:30 +01:00
|
|
|
if(selectedAction == editAction)
|
|
|
|
|
{
|
2017-12-05 21:36:47 +01:00
|
|
|
BookingDialog dialog(this);
|
|
|
|
|
dialog.setTime(booking.time);
|
|
|
|
|
dialog.setTimespan(booking.timespan);
|
|
|
|
|
dialog.setType(booking.type);
|
|
|
|
|
dialog.setText(booking.text);
|
2017-12-02 10:50:30 +01:00
|
|
|
again1:
|
|
|
|
|
if(dialog.exec() == QDialog::Accepted)
|
|
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
auto reply = m_erfassung.doUpdateBooking(booking.id, m_userInfo.userId, ui->dateEditDate->date(),
|
|
|
|
|
dialog.getTime(), dialog.getTimespan(),
|
|
|
|
|
dialog.getType(), dialog.getText());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
{
|
|
|
|
|
QEventLoop eventLoop;
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit);
|
2017-12-10 21:08:19 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
}
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
if(reply->success())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-10 23:10:27 +01:00
|
|
|
m_currentStripWidget->refreshBookings();
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not edit booking!"), tr("Could not edit booking!") % "\n\n" % reply->message());
|
2017-12-02 10:50:30 +01:00
|
|
|
goto again1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(selectedAction == deleteAction)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox msgBox;
|
2017-12-12 20:17:32 +01:00
|
|
|
msgBox.setText(tr("Do you really want to delete the booking?"));
|
2017-12-02 10:50:30 +01:00
|
|
|
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
|
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
|
if(msgBox.exec() == QMessageBox::Yes)
|
|
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
auto reply = m_erfassung.doDeleteBooking(booking.id);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
{
|
|
|
|
|
QEventLoop eventLoop;
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit);
|
2017-12-10 21:08:19 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
}
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
if(reply->success())
|
2017-12-10 23:10:27 +01:00
|
|
|
m_currentStripWidget->refreshBookings();
|
2017-12-02 10:50:30 +01:00
|
|
|
else
|
2017-12-10 21:08:19 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not delete booking!"), tr("Could not delete booking!") % "\n\n" % reply->message());
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:03:03 +01:00
|
|
|
void MainWindow::contextMenuTimeAssignment(const QPoint &pos)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:03:03 +01:00
|
|
|
auto index = ui->treeViewTimeAssignments->indexAt(pos);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
if(!index.isValid())
|
|
|
|
|
{
|
|
|
|
|
QMenu menu;
|
|
|
|
|
auto createAction = menu.addAction(tr("Create time assignment"));
|
2017-12-11 00:23:48 +01:00
|
|
|
auto refreshAction = menu.addAction(QIcon(QPixmap(QStringLiteral(":/zeiterfassung/images/refresh.png"))), tr("Refresh time assignments"));
|
2017-12-10 21:08:19 +01:00
|
|
|
auto selectedAction = menu.exec(ui->treeViewTimeAssignments->viewport()->mapToGlobal(pos));
|
|
|
|
|
if(selectedAction == createAction)
|
|
|
|
|
{
|
|
|
|
|
TimeAssignmentDialog dialog(m_projects, m_settings, this);
|
|
|
|
|
again2:
|
|
|
|
|
if(dialog.exec() == QDialog::Accepted)
|
|
|
|
|
{
|
|
|
|
|
auto reply = m_erfassung.doCreateTimeAssignment(m_userInfo.userId, ui->dateEditDate->date(),
|
|
|
|
|
dialog.getTime(), dialog.getTimespan(),
|
|
|
|
|
dialog.getProject(), dialog.getSubproject(),
|
|
|
|
|
dialog.getWorkpackage(), dialog.getText());
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QEventLoop eventLoop;
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit);
|
2017-12-10 21:08:19 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(reply->success())
|
|
|
|
|
{
|
2017-12-10 23:10:27 +01:00
|
|
|
m_currentStripWidget->refreshTimeAssignments();
|
2017-12-10 21:08:19 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not create time assignment!"), tr("Could not create time assignment!") % "\n\n" % reply->message());
|
|
|
|
|
goto again2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-11 00:23:48 +01:00
|
|
|
else if(selectedAction == refreshAction)
|
|
|
|
|
{
|
|
|
|
|
m_currentStripWidget->refreshTimeAssignments();
|
|
|
|
|
}
|
2017-12-10 21:08:19 +01:00
|
|
|
}
|
|
|
|
|
else
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-10 23:10:27 +01:00
|
|
|
auto timeAssignment = m_currentStripWidget->timeAssignments().at(index.row());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
QMenu menu;
|
2017-12-05 21:36:47 +01:00
|
|
|
auto editAction = menu.addAction(tr("Edit time assignment"));
|
|
|
|
|
auto deleteAction = menu.addAction(tr("Delete time assignment"));
|
2017-12-05 21:03:03 +01:00
|
|
|
auto selectedAction = menu.exec(ui->treeViewTimeAssignments->viewport()->mapToGlobal(pos));
|
2017-12-02 10:50:30 +01:00
|
|
|
if(selectedAction == editAction)
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
TimeAssignmentDialog dialog(m_projects, m_settings, this);
|
2017-12-05 21:03:03 +01:00
|
|
|
dialog.setTime(timeAssignment.time);
|
|
|
|
|
dialog.setTimespan(timeAssignment.timespan);
|
2017-12-05 21:16:46 +01:00
|
|
|
dialog.setProject(timeAssignment.project);
|
|
|
|
|
dialog.setSubproject(timeAssignment.subproject);
|
2017-12-05 21:03:03 +01:00
|
|
|
dialog.setWorkpackage(timeAssignment.workpackage);
|
|
|
|
|
dialog.setText(timeAssignment.text);
|
2017-12-02 10:50:30 +01:00
|
|
|
again1:
|
|
|
|
|
if(dialog.exec() == QDialog::Accepted)
|
|
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
auto reply = m_erfassung.doUpdateTimeAssignment(timeAssignment.id, m_userInfo.userId, ui->dateEditDate->date(),
|
|
|
|
|
dialog.getTime(), dialog.getTimespan(),
|
|
|
|
|
dialog.getProject(), dialog.getSubproject(),
|
|
|
|
|
dialog.getWorkpackage(), dialog.getText());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
{
|
|
|
|
|
QEventLoop eventLoop;
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit);
|
2017-12-10 21:08:19 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
}
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
if(reply->success())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-10 23:10:27 +01:00
|
|
|
m_currentStripWidget->refreshTimeAssignments();
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not edit time assignment!"), tr("Could not edit time assignment!") % "\n\n" % reply->message());
|
2017-12-02 10:50:30 +01:00
|
|
|
goto again1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(selectedAction == deleteAction)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox msgBox;
|
2017-12-12 20:17:32 +01:00
|
|
|
msgBox.setText(tr("Do you really want to delete the time assignment?"));
|
2017-12-02 10:50:30 +01:00
|
|
|
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
|
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
|
if(msgBox.exec() == QMessageBox::Yes)
|
|
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
auto reply = m_erfassung.doDeleteTimeAssignment(timeAssignment.id);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
{
|
|
|
|
|
QEventLoop eventLoop;
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit);
|
2017-12-10 21:08:19 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
}
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
if(reply->success())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-10 23:10:27 +01:00
|
|
|
m_currentStripWidget->refreshTimeAssignments();
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
else
|
2017-12-10 21:08:19 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not delete time assignment!"), tr("Could not delete time assignment!") % "\n\n" % reply->message());
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonStartPressed()
|
|
|
|
|
{
|
2017-12-12 21:29:20 +01:00
|
|
|
auto bookingsChanged = false;
|
|
|
|
|
|
2017-12-10 23:10:27 +01:00
|
|
|
if(m_currentStripWidget->bookings().rbegin() == m_currentStripWidget->bookings().rend() ||
|
|
|
|
|
m_currentStripWidget->bookings().rbegin()->type == QStringLiteral("G"))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
auto reply = m_erfassung.doCreateBooking(m_userInfo.userId, ui->dateEditDate->date(),
|
|
|
|
|
timeNormalise(ui->timeEditTime->time()), QTime(0, 0),
|
|
|
|
|
QStringLiteral("K"), QStringLiteral(""));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
QEventLoop eventLoop;
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit);
|
2017-12-10 21:08:19 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!reply->success())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not create booking!"), tr("Could not create booking!") % "\n\n" % reply->message());
|
2017-12-10 23:23:00 +01:00
|
|
|
m_currentStripWidget->refresh();
|
2017-12-02 10:50:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2017-12-10 21:08:19 +01:00
|
|
|
|
2017-12-12 21:29:20 +01:00
|
|
|
bookingsChanged = true;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-11 00:23:48 +01:00
|
|
|
auto timeAssignmentTime = m_currentStripWidget->timeAssignmentTime();
|
2017-12-09 01:48:18 +01:00
|
|
|
|
2017-12-10 23:10:27 +01:00
|
|
|
if(m_currentStripWidget->timeAssignments().rbegin() != m_currentStripWidget->timeAssignments().rend())
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-10 23:10:27 +01:00
|
|
|
auto timeAssignment = *m_currentStripWidget->timeAssignments().rbegin();
|
2017-12-05 21:03:03 +01:00
|
|
|
if(timeAssignment.timespan == QTime(0, 0))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-11 00:23:48 +01:00
|
|
|
auto timespan = timeBetween(m_currentStripWidget->lastTimeAssignmentStart(), ui->timeEditTime->time());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
auto reply = m_erfassung.doUpdateTimeAssignment(timeAssignment.id, m_userInfo.userId, timeAssignment.date,
|
|
|
|
|
timeAssignment.time, timespan,
|
|
|
|
|
timeAssignment.project, timeAssignment.subproject,
|
|
|
|
|
timeAssignment.workpackage, timeAssignment.text);
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
{
|
|
|
|
|
QEventLoop eventLoop;
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit);
|
2017-12-10 21:08:19 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(reply->success())
|
2017-12-09 01:48:18 +01:00
|
|
|
timeAssignmentTime = timeAdd(timeAssignmentTime, timespan);
|
2017-12-02 10:50:30 +01:00
|
|
|
else
|
|
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
QMessageBox::warning(this, tr("Could not edit time assignment!"), tr("Could not edit time assignment!") % "\n\n" % reply->message());
|
2017-12-10 23:23:00 +01:00
|
|
|
m_currentStripWidget->refresh();
|
2017-12-02 10:50:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2017-12-13 23:59:14 +01:00
|
|
|
auto reply = m_erfassung.doCreateTimeAssignment(m_userInfo.userId, ui->dateEditDate->date(),
|
|
|
|
|
timeAssignmentTime, QTime(0, 0),
|
|
|
|
|
ui->comboBoxProject->currentData().toString(), ui->comboBoxSubproject->currentText(),
|
|
|
|
|
ui->comboBoxWorkpackage->currentText(), ui->comboBoxText->currentText());
|
2017-12-10 21:08:19 +01:00
|
|
|
|
2017-12-13 23:59:14 +01:00
|
|
|
{
|
|
|
|
|
QEventLoop eventLoop;
|
|
|
|
|
connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit);
|
|
|
|
|
eventLoop.exec();
|
|
|
|
|
}
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-13 23:59:14 +01:00
|
|
|
if(!reply->success())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not create time assignment!"), tr("Could not create time assignment!") % "\n\n" % reply->message());
|
|
|
|
|
m_currentStripWidget->refresh();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-10 21:08:19 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
m_settings.prependProject(ui->comboBoxProject->currentData().toString());
|
|
|
|
|
m_settings.prependSubproject(ui->comboBoxSubproject->currentText());
|
2017-12-03 22:22:07 +01:00
|
|
|
m_settings.prependWorkpackage(ui->comboBoxWorkpackage->currentText());
|
|
|
|
|
m_settings.prependText(ui->comboBoxText->currentText());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
updateComboboxes();
|
|
|
|
|
|
2017-12-12 21:29:20 +01:00
|
|
|
if(bookingsChanged)
|
|
|
|
|
{
|
|
|
|
|
m_currentStripWidget->refresh();
|
|
|
|
|
|
|
|
|
|
refreshAuswertung();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
m_currentStripWidget->refreshTimeAssignments();
|
|
|
|
|
|
|
|
|
|
ui->actionToday->setEnabled(false);
|
|
|
|
|
ui->actionRefresh->setEnabled(false);
|
|
|
|
|
ui->dateEditDate->setReadOnly(true);
|
|
|
|
|
ui->pushButtonPrev->setEnabled(false);
|
|
|
|
|
ui->pushButtonNext->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::pushButtonEndPressed()
|
|
|
|
|
{
|
2017-12-09 01:48:18 +01:00
|
|
|
{
|
2017-12-10 23:10:27 +01:00
|
|
|
auto timeAssignment = *m_currentStripWidget->timeAssignments().rbegin();
|
2017-12-09 01:48:18 +01:00
|
|
|
Q_ASSERT(timeAssignment.timespan == QTime(0, 0));
|
|
|
|
|
|
2017-12-11 00:23:48 +01:00
|
|
|
auto timespan = timeBetween(m_currentStripWidget->lastTimeAssignmentStart(), ui->timeEditTime->time());
|
2017-12-09 01:48:18 +01:00
|
|
|
|
2017-12-10 21:08:19 +01:00
|
|
|
auto reply = m_erfassung.doUpdateTimeAssignment(timeAssignment.id, m_userInfo.userId, timeAssignment.date,
|
|
|
|
|
timeAssignment.time, timespan,
|
|
|
|
|
timeAssignment.project, timeAssignment.subproject,
|
|
|
|
|
timeAssignment.workpackage, timeAssignment.text);
|
2017-12-09 01:48:18 +01:00
|
|
|
|
|
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
QEventLoop eventLoop;
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(reply.get(), SIGNAL(finished()), &eventLoop, SLOT(quit()));
|
2017-12-10 21:08:19 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!reply->success())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not edit time assignment!"), tr("Could not edit time assignment!") % "\n\n" % reply->message());
|
2017-12-10 23:23:00 +01:00
|
|
|
m_currentStripWidget->refresh();
|
2017-12-09 01:48:18 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
auto reply = m_erfassung.doCreateBooking(m_userInfo.userId, ui->dateEditDate->date(),
|
|
|
|
|
timeNormalise(ui->timeEditTime->time()), QTime(0, 0),
|
|
|
|
|
QStringLiteral("G"), QStringLiteral(""));
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
{
|
2017-12-10 21:08:19 +01:00
|
|
|
QEventLoop eventLoop;
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit);
|
2017-12-10 21:08:19 +01:00
|
|
|
eventLoop.exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!reply->success())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not create booking!"), tr("Could not create booking!") % "\n\n" % reply->message());
|
2017-12-10 23:23:00 +01:00
|
|
|
m_currentStripWidget->refresh();
|
2017-12-02 10:50:30 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-10 23:23:00 +01:00
|
|
|
m_currentStripWidget->refresh();
|
2017-12-12 21:29:20 +01:00
|
|
|
refreshAuswertung();
|
|
|
|
|
|
|
|
|
|
ui->actionToday->setEnabled(false);
|
|
|
|
|
ui->actionRefresh->setEnabled(false);
|
|
|
|
|
ui->dateEditDate->setReadOnly(true);
|
|
|
|
|
ui->pushButtonPrev->setEnabled(false);
|
|
|
|
|
ui->pushButtonNext->setEnabled(false);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-10 23:23:00 +01:00
|
|
|
void MainWindow::dateChanged(bool force)
|
2017-12-10 23:10:27 +01:00
|
|
|
{
|
2017-12-10 23:23:00 +01:00
|
|
|
auto firstDayOfWeek = ui->dateEditDate->date().addDays(-(ui->dateEditDate->date().dayOfWeek() - 1));
|
2017-12-10 23:10:27 +01:00
|
|
|
|
|
|
|
|
for(quint8 i = 0; i < 7; i++)
|
|
|
|
|
{
|
|
|
|
|
auto date = firstDayOfWeek.addDays(i);
|
2017-12-10 23:23:00 +01:00
|
|
|
|
|
|
|
|
if(force || m_stripsWidgets[i]->date() != date)
|
|
|
|
|
m_stripsWidgets[i]->setDate(date);
|
|
|
|
|
|
|
|
|
|
if(date == ui->dateEditDate->date() && (force || m_currentStripWidget != m_stripsWidgets[i]))
|
2017-12-10 23:10:27 +01:00
|
|
|
{
|
|
|
|
|
if(m_currentStripWidget)
|
|
|
|
|
{
|
|
|
|
|
disconnect(m_currentStripWidget, &StripsWidget::minimumTimeChanged, this, &MainWindow::minimumTimeChanged);
|
|
|
|
|
disconnect(m_currentStripWidget, &StripsWidget::startEnabledChanged, this, &MainWindow::startEnabledChanged);
|
|
|
|
|
disconnect(m_currentStripWidget, &StripsWidget::endEnabledChanged, this, &MainWindow::endEnabledChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_currentStripWidget = m_stripsWidgets[i];
|
|
|
|
|
|
2017-12-11 00:23:48 +01:00
|
|
|
m_bookingsModel->setStripsWidget(m_currentStripWidget);
|
|
|
|
|
m_timeAssignmentsModel->setStripsWidget(m_currentStripWidget);
|
2017-12-10 23:10:27 +01:00
|
|
|
|
|
|
|
|
minimumTimeChanged();
|
|
|
|
|
startEnabledChanged();
|
|
|
|
|
endEnabledChanged();
|
|
|
|
|
|
|
|
|
|
connect(m_currentStripWidget, &StripsWidget::minimumTimeChanged, this, &MainWindow::minimumTimeChanged);
|
|
|
|
|
connect(m_currentStripWidget, &StripsWidget::startEnabledChanged, this, &MainWindow::startEnabledChanged);
|
|
|
|
|
connect(m_currentStripWidget, &StripsWidget::endEnabledChanged, this, &MainWindow::endEnabledChanged);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-10 23:23:00 +01:00
|
|
|
|
2017-12-12 21:29:20 +01:00
|
|
|
if(force || m_auswertungDate != QDate(ui->dateEditDate->date().year(), ui->dateEditDate->date().month(), 1))
|
|
|
|
|
refreshAuswertung();
|
2017-12-10 23:44:44 +01:00
|
|
|
|
|
|
|
|
if(std::any_of(std::begin(m_stripsWidgets), std::end(m_stripsWidgets), [](StripsWidget *stripsWidget) {
|
|
|
|
|
return stripsWidget->refreshing();
|
|
|
|
|
}) || m_getAuswertungReply)
|
|
|
|
|
{
|
|
|
|
|
ui->actionToday->setEnabled(false);
|
|
|
|
|
ui->actionRefresh->setEnabled(false);
|
2017-12-10 23:59:13 +01:00
|
|
|
ui->dateEditDate->setReadOnly(true);
|
2017-12-10 23:44:44 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(false);
|
|
|
|
|
ui->pushButtonNext->setEnabled(false);
|
|
|
|
|
}
|
2017-12-10 23:10:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::openAuswertung()
|
|
|
|
|
{
|
2017-12-12 20:43:43 +01:00
|
|
|
QTemporaryFile file(QDir::temp().absoluteFilePath(QStringLiteral("auswertungXXXXXX.pdf")));
|
2017-12-10 23:10:27 +01:00
|
|
|
file.setAutoRemove(false);
|
|
|
|
|
if(!file.open())
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not open auswertung!"), tr("Could not open auswertung!") % "\n\n" % file.errorString());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file.write(m_auswertung);
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
|
if(!QDesktopServices::openUrl(QUrl::fromLocalFile(file.fileName())))
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Could not open auswertung!"), tr("Could not open default PDF viewer!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::minimumTimeChanged()
|
|
|
|
|
{
|
|
|
|
|
ui->timeEditTime->setMinimumTime(m_currentStripWidget->minimumTime());
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-10 23:44:44 +01:00
|
|
|
void MainWindow::refreshingChanged()
|
|
|
|
|
{
|
|
|
|
|
if(m_getAuswertungReply)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto allFinished = std::none_of(std::begin(m_stripsWidgets), std::end(m_stripsWidgets), [](StripsWidget *stripsWidget){
|
|
|
|
|
return stripsWidget->refreshing();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ui->actionToday->setEnabled(allFinished);
|
|
|
|
|
ui->actionRefresh->setEnabled(allFinished);
|
2017-12-10 23:59:13 +01:00
|
|
|
ui->dateEditDate->setReadOnly(!allFinished);
|
2017-12-10 23:44:44 +01:00
|
|
|
ui->pushButtonPrev->setEnabled(allFinished);
|
|
|
|
|
ui->pushButtonNext->setEnabled(allFinished);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-10 23:10:27 +01:00
|
|
|
void MainWindow::startEnabledChanged()
|
|
|
|
|
{
|
|
|
|
|
auto startEnabled = m_currentStripWidget->startEnabled();
|
2017-12-10 23:59:13 +01:00
|
|
|
auto endEnabled = m_currentStripWidget->endEnabled();
|
|
|
|
|
|
2017-12-13 23:14:37 +01:00
|
|
|
ui->timeEditTime->setEnabled(startEnabled || endEnabled);
|
|
|
|
|
ui->pushButtonNow->setEnabled(startEnabled || endEnabled);
|
2017-12-10 23:10:27 +01:00
|
|
|
|
|
|
|
|
ui->comboBoxProject->setEnabled(startEnabled);
|
|
|
|
|
ui->comboBoxSubproject->setEnabled(startEnabled);
|
|
|
|
|
ui->comboBoxWorkpackage->setEnabled(startEnabled);
|
|
|
|
|
ui->comboBoxText->setEnabled(startEnabled);
|
|
|
|
|
|
|
|
|
|
ui->pushButtonStart->setEnabled(startEnabled);
|
2017-12-10 23:59:13 +01:00
|
|
|
ui->pushButtonStart->setText(endEnabled ? tr("Switch") : tr("Start"));
|
2017-12-10 23:10:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::endEnabledChanged()
|
|
|
|
|
{
|
2017-12-10 23:59:13 +01:00
|
|
|
auto startEnabled = m_currentStripWidget->startEnabled();
|
|
|
|
|
auto endEnabled = m_currentStripWidget->endEnabled();
|
|
|
|
|
|
2017-12-12 21:29:20 +01:00
|
|
|
ui->timeEditTime->setEnabled(startEnabled || endEnabled);
|
2017-12-13 23:14:37 +01:00
|
|
|
ui->pushButtonNow->setEnabled(startEnabled || endEnabled);
|
2017-12-10 23:59:13 +01:00
|
|
|
|
|
|
|
|
ui->pushButtonStart->setText(endEnabled ? tr("Switch") : tr("Start"));
|
|
|
|
|
ui->pushButtonEnd->setEnabled(endEnabled);
|
2017-12-10 23:10:27 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-12 21:29:20 +01:00
|
|
|
void MainWindow::refreshAuswertung()
|
|
|
|
|
{
|
|
|
|
|
m_balanceLabel->setText(tr("%0: %1").arg(tr("Balance")).arg(tr("???")));
|
|
|
|
|
m_holidaysLabel->setText(tr("%0: %1").arg(tr("Holidays")).arg(tr("???")));
|
|
|
|
|
|
|
|
|
|
ui->actionAuswertung->setEnabled(false);
|
|
|
|
|
m_auswertung.clear();
|
|
|
|
|
|
|
|
|
|
m_auswertungDate = QDate(ui->dateEditDate->date().year(), ui->dateEditDate->date().month(), 1);
|
|
|
|
|
m_getAuswertungReply = m_erfassung.doGetAuswertung(m_userInfo.userId, m_auswertungDate);
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(m_getAuswertungReply.get(), &ZeiterfassungReply::finished, this, &MainWindow::getAuswertungFinished);
|
2017-12-12 21:29:20 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-02 10:50:30 +01:00
|
|
|
void MainWindow::updateComboboxes()
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxProject->clear();
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
auto preferedProjects = m_settings.projects();
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
for(const auto &preferedProject : preferedProjects)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
if(!m_projects.contains(preferedProject))
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
qWarning() << "cannot find project" << preferedProject;
|
2017-12-02 19:11:49 +01:00
|
|
|
continue;
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
2017-12-02 19:11:49 +01:00
|
|
|
|
2017-12-12 20:43:43 +01:00
|
|
|
ui->comboBoxProject->addItem(tr("%0 (%1)").arg(m_projects.value(preferedProject)).arg(preferedProject), preferedProject);
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
if(preferedProjects.count())
|
|
|
|
|
ui->comboBoxProject->insertSeparator(ui->comboBoxProject->count());
|
2017-12-02 10:50:30 +01:00
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
for(auto iter = m_projects.constBegin(); iter != m_projects.constEnd(); iter++)
|
2017-12-02 10:50:30 +01:00
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
if(!preferedProjects.contains(iter.key()))
|
2017-12-12 20:43:43 +01:00
|
|
|
ui->comboBoxProject->addItem(tr("%0 (%1)").arg(iter.value()).arg(iter.key()), iter.key());
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-05 21:16:46 +01:00
|
|
|
ui->comboBoxSubproject->clear();
|
2017-12-02 10:50:30 +01:00
|
|
|
|
|
|
|
|
{
|
2017-12-05 21:16:46 +01:00
|
|
|
auto subprojects = m_settings.subprojects();
|
|
|
|
|
for(const auto &subproject : subprojects)
|
|
|
|
|
ui->comboBoxSubproject->addItem(subproject);
|
|
|
|
|
if(subprojects.count())
|
|
|
|
|
ui->comboBoxSubproject->setCurrentText(QString());
|
2017-12-02 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->comboBoxWorkpackage->clear();
|
|
|
|
|
|
|
|
|
|
{
|
2017-12-03 22:22:07 +01:00
|
|
|
auto workpackages = m_settings.workpackages();
|
2017-12-02 10:50:30 +01:00
|
|
|
for(const auto &workpackage : workpackages)
|
|
|
|
|
ui->comboBoxWorkpackage->addItem(workpackage);
|
|
|
|
|
if(workpackages.count())
|
|
|
|
|
ui->comboBoxWorkpackage->setCurrentText(QString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->comboBoxText->clear();
|
|
|
|
|
|
|
|
|
|
{
|
2017-12-03 22:22:07 +01:00
|
|
|
auto texte = m_settings.texte();
|
2017-12-02 10:50:30 +01:00
|
|
|
for(const auto &text : texte)
|
|
|
|
|
ui->comboBoxText->addItem(text);
|
|
|
|
|
if(texte.count())
|
|
|
|
|
ui->comboBoxText->setCurrentText(QString());
|
|
|
|
|
}
|
|
|
|
|
}
|