Implemented basic export functionality
This commit is contained in:
@@ -1,17 +1,113 @@
|
|||||||
#include "exportdialog.h"
|
#include "exportdialog.h"
|
||||||
#include "ui_exportdialog.h"
|
#include "ui_exportdialog.h"
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
// zeiterfassungcorelib includes
|
||||||
|
#include "utils/timeutils.h"
|
||||||
|
|
||||||
|
// zeiterfassungguilib includes
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
// zeiterfassungnetworklib includes
|
||||||
|
#include "zeiterfassungapi.h"
|
||||||
|
#include "replies/getbookingsreply.h"
|
||||||
|
|
||||||
ExportDialog::ExportDialog(MainWindow &mainWindow, QWidget *parent) :
|
ExportDialog::ExportDialog(MainWindow &mainWindow, QWidget *parent) :
|
||||||
ZeiterfassungDialog(parent),
|
ZeiterfassungDialog(parent),
|
||||||
ui(new Ui::ExportDialog),
|
ui(new Ui::ExportDialog),
|
||||||
m_mainWindow(mainWindow)
|
m_mainWindow(mainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(ui->dateEditFrom, &QDateEdit::dateChanged, ui->dateEditTo, &QDateEdit::setMinimumDate);
|
||||||
|
connect(ui->pushButton, &QAbstractButton::pressed, this, &ExportDialog::start);
|
||||||
|
|
||||||
|
ui->dateEditFrom->setDate(beginOfMonth(QDate::currentDate().addMonths(-1)));
|
||||||
|
ui->dateEditTo->setDate(endOfMonth(QDate::currentDate().addMonths(-1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ExportDialog::~ExportDialog()
|
ExportDialog::~ExportDialog()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExportDialog::start()
|
||||||
|
{
|
||||||
|
if(ui->dateEditFrom->date() > ui->dateEditTo->date())
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Invalid date selection!"), tr("Invalid date selection!\n\n%0").arg(tr("From date cannot be after to date!")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto filename = QFileDialog::getSaveFileName(this, tr("Save Export as"), QString(), QString("%0 (*.csv)").arg(tr("CSV-File")));
|
||||||
|
|
||||||
|
auto file = std::make_unique<QFile>(filename);
|
||||||
|
if(!file->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Could not open export file!"), tr("Could not open export file!\n\n%0").arg(file->errorString()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_file = std::move(file);
|
||||||
|
|
||||||
|
m_textStream.setDevice(file.get());
|
||||||
|
|
||||||
|
m_date = ui->dateEditFrom->date();
|
||||||
|
m_toDate = ui->dateEditTo->date();
|
||||||
|
|
||||||
|
ui->pushButton->setEnabled(false);
|
||||||
|
|
||||||
|
ui->progressBar->setMaximum(m_date.daysTo(m_toDate) + 1);
|
||||||
|
ui->progressBar->setValue(0);
|
||||||
|
ui->progressBar->setEnabled(true);
|
||||||
|
|
||||||
|
ui->plainTextEdit->clear();
|
||||||
|
|
||||||
|
nextDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportDialog::requestFinished()
|
||||||
|
{
|
||||||
|
ui->progressBar->setValue(ui->progressBar->maximum() - m_date.daysTo(m_toDate));
|
||||||
|
|
||||||
|
if(m_reply->success())
|
||||||
|
{
|
||||||
|
for(const auto &booking : m_reply->bookings())
|
||||||
|
{
|
||||||
|
ui->plainTextEdit->appendHtml(QStringLiteral("<b>%0</b> booking %1 %2<br/>")
|
||||||
|
.arg(QLocale().toString(m_date, QLocale::ShortFormat), QLocale().toString(booking.time), booking.type));
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->plainTextEdit->appendHtml(QStringLiteral("<b>%0</b> <span style=\"color: darkgreen;\">succeeded</span>!<br/>")
|
||||||
|
.arg(QLocale().toString(m_date, QLocale::ShortFormat)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui->plainTextEdit->appendHtml(QStringLiteral("<b>%0</b> <span style=\"color: red;\">failed to load</span>: %1<br/>")
|
||||||
|
.arg(QLocale().toString(m_date, QLocale::ShortFormat), m_reply->message()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_date < m_toDate)
|
||||||
|
{
|
||||||
|
m_date = m_date.addDays(1);
|
||||||
|
nextDate();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_file = nullptr;
|
||||||
|
m_textStream.setDevice(nullptr);
|
||||||
|
m_reply = nullptr;
|
||||||
|
QMessageBox::information(this, tr("Export finished!"), tr("Export finished!"));
|
||||||
|
ui->pushButton->setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportDialog::nextDate()
|
||||||
|
{
|
||||||
|
m_reply = m_mainWindow.erfassung().doGetBookings(m_mainWindow.userInfo().userId, m_date, m_date);
|
||||||
|
connect(m_reply.get(), &ZeiterfassungReply::finished, this, &ExportDialog::requestFinished);
|
||||||
|
}
|
||||||
|
@@ -2,8 +2,19 @@
|
|||||||
|
|
||||||
#include "zeiterfassungdialog.h"
|
#include "zeiterfassungdialog.h"
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QDate>
|
||||||
|
|
||||||
|
// system includes
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
// forward declarations
|
||||||
|
class QFile;
|
||||||
|
|
||||||
namespace Ui { class ExportDialog; }
|
namespace Ui { class ExportDialog; }
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
class GetBookingsReply;
|
||||||
|
|
||||||
class ExportDialog : public ZeiterfassungDialog
|
class ExportDialog : public ZeiterfassungDialog
|
||||||
{
|
{
|
||||||
@@ -13,8 +24,21 @@ public:
|
|||||||
explicit ExportDialog(MainWindow &mainWindow, QWidget *parent = Q_NULLPTR);
|
explicit ExportDialog(MainWindow &mainWindow, QWidget *parent = Q_NULLPTR);
|
||||||
~ExportDialog();
|
~ExportDialog();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void start();
|
||||||
|
void requestFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void nextDate();
|
||||||
|
|
||||||
Ui::ExportDialog *ui;
|
Ui::ExportDialog *ui;
|
||||||
|
|
||||||
MainWindow &m_mainWindow;
|
MainWindow &m_mainWindow;
|
||||||
|
|
||||||
|
std::unique_ptr<QFile> m_file;
|
||||||
|
QTextStream m_textStream;
|
||||||
|
QDate m_date;
|
||||||
|
QDate m_toDate;
|
||||||
|
|
||||||
|
std::unique_ptr<GetBookingsReply> m_reply;
|
||||||
};
|
};
|
||||||
|
@@ -6,17 +6,64 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1024</width>
|
<width>586</width>
|
||||||
<height>480</height>
|
<height>349</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Export</string>
|
<string>Export</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelFrom">
|
||||||
|
<property name="text">
|
||||||
|
<string>From:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDateEdit" name="dateEditFrom"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>To:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDateEdit" name="dateEditTo"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Start</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QProgressBar" name="progressBar">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPlainTextEdit" name="plainTextEdit">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections/>
|
||||||
</connections>
|
|
||||||
</ui>
|
</ui>
|
||||||
|
@@ -7,6 +7,54 @@
|
|||||||
<source>Export</source>
|
<source>Export</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>From:</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>To:</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Start</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Invalid date selection!</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Invalid date selection!
|
||||||
|
|
||||||
|
%0</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>From date cannot be after to date!</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Export finished!</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Save Export as</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>CSV-File</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Could not open export file!</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Could not open export file!
|
||||||
|
|
||||||
|
%0</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ExportPlugin</name>
|
<name>ExportPlugin</name>
|
||||||
|
@@ -7,6 +7,54 @@
|
|||||||
<source>Export</source>
|
<source>Export</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>From:</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>To:</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Start</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Invalid date selection!</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Invalid date selection!
|
||||||
|
|
||||||
|
%0</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>From date cannot be after to date!</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Export finished!</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Save Export as</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>CSV-File</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Could not open export file!</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Could not open export file!
|
||||||
|
|
||||||
|
%0</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ExportPlugin</name>
|
<name>ExportPlugin</name>
|
||||||
|
Reference in New Issue
Block a user