diff --git a/zeiterfassungcorelib/replies/getabsencesreply.cpp b/zeiterfassungcorelib/replies/getabsencesreply.cpp index 107adc6..84c8ea5 100644 --- a/zeiterfassungcorelib/replies/getabsencesreply.cpp +++ b/zeiterfassungcorelib/replies/getabsencesreply.cpp @@ -59,12 +59,12 @@ void GetAbsencesReply::requestFinished() m_absences.append({ obj.value(QStringLiteral("altRepresentative")).toInt(), obj.value(QStringLiteral("compositeId")).toString(), - QDate::fromString(QString::number(obj.value(QStringLiteral("end")).toInt()), QStringLiteral("yyyyMMdd")), + parseDate(obj.value(QStringLiteral("end"))), obj.value(QStringLiteral("hourCategory")).toString(), obj.value(QStringLiteral("openMarking")).toString(), obj.value(QStringLiteral("persNr")).toInt(), obj.value(QStringLiteral("representative")).toInt(), - QDate::fromString(QString::number(obj.value(QStringLiteral("start")).toInt()), QStringLiteral("yyyyMMdd")), + parseDate(obj.value(QStringLiteral("start"))), obj.value(QStringLiteral("text")).toString() }); } diff --git a/zeiterfassungcorelib/replies/getbookingsreply.cpp b/zeiterfassungcorelib/replies/getbookingsreply.cpp index b286cae..5d7d95e 100644 --- a/zeiterfassungcorelib/replies/getbookingsreply.cpp +++ b/zeiterfassungcorelib/replies/getbookingsreply.cpp @@ -57,9 +57,9 @@ void GetBookingsReply::requestFinished() m_bookings.append({ obj.value(QStringLiteral("bookingNr")).toInt(), - QDate::fromString(QString::number(obj.value(QStringLiteral("bookingDate")).toInt()), QStringLiteral("yyyyMMdd")), - QTime::fromString(QStringLiteral("%0").arg(obj.value(QStringLiteral("bookingTime")).toInt(), 6, 10, QChar('0')), QStringLiteral("HHmmss")), - QTime::fromString(QStringLiteral("%0").arg(obj.value(QStringLiteral("bookingTimespan")).toInt(), 6, 10, QChar('0')), QStringLiteral("HHmmss")), + parseDate(obj.value(QStringLiteral("bookingDate"))), + parseTime(obj.value(QStringLiteral("bookingTime"))), + parseTime(obj.value(QStringLiteral("bookingTimespan"))), obj.value(QStringLiteral("bookingType")).toString(), obj.value(QStringLiteral("text")).toString() }); diff --git a/zeiterfassungcorelib/replies/getdayinforeply.cpp b/zeiterfassungcorelib/replies/getdayinforeply.cpp new file mode 100644 index 0000000..2b20a01 --- /dev/null +++ b/zeiterfassungcorelib/replies/getdayinforeply.cpp @@ -0,0 +1,74 @@ +#include "getdayinforeply.h" + +#include +#include +#include +#include +#include +#include + +#include "zeiterfassungapi.h" + +GetDayinfoReply::GetDayinfoReply(std::unique_ptr &&reply, ZeiterfassungApi *zeiterfassung) : + ZeiterfassungReply(zeiterfassung), + m_reply(std::move(reply)) +{ + connect(m_reply.get(), &QNetworkReply::finished, this, &GetDayinfoReply::requestFinished); +} + +const QVector &GetDayinfoReply::dayinfos() const +{ + return m_dayinfos; +} + +void GetDayinfoReply::requestFinished() +{ + if(m_reply->error() != QNetworkReply::NoError) + { + setSuccess(false); + setMessage(tr("Request error occured: %0").arg(m_reply->errorString())); + goto end; + } + + { + QJsonParseError error; + QJsonDocument document = QJsonDocument::fromJson(m_reply->readAll(), &error); + if(error.error != QJsonParseError::NoError) + { + setSuccess(false); + setMessage(tr("Parsing JSON failed: %0").arg(error.errorString())); + goto end; + } + + if(!document.isArray()) + { + setSuccess(false); + setMessage(tr("JSON document is not an array!")); + goto end; + } + + auto arr = document.array(); + + setSuccess(true); + m_dayinfos.clear(); + m_dayinfos.reserve(arr.count()); + for(const auto &val : arr) + { + auto obj = val.toObject(); + + m_dayinfos.append({ + obj.value(QStringLiteral("className")).toString(), + obj.value(QStringLiteral("persNr")).toInt(), + parseDate(obj.value(QStringLiteral("date"))), + parseTime(obj.value(QStringLiteral("ist"))), + parseTime(obj.value(QStringLiteral("soll"))), + obj.value(QStringLiteral("compositeId")).toString() + }); + } + } + + end: + m_reply = Q_NULLPTR; + + Q_EMIT finished(); +} diff --git a/zeiterfassungcorelib/replies/getdayinforeply.h b/zeiterfassungcorelib/replies/getdayinforeply.h new file mode 100644 index 0000000..6bdf816 --- /dev/null +++ b/zeiterfassungcorelib/replies/getdayinforeply.h @@ -0,0 +1,40 @@ +#pragma once + +#include + +#include +#include +#include +#include + +#include "zeiterfassungcorelib_global.h" +#include "zeiterfassungreply.h" + +class ZeiterfassungApi; + +class ZEITERFASSUNGCORELIBSHARED_EXPORT GetDayinfoReply : public ZeiterfassungReply +{ + Q_OBJECT + +public: + explicit GetDayinfoReply(std::unique_ptr &&reply, ZeiterfassungApi *zeiterfassung); + + struct Dayinfo + { + QString className; + int userId; + QDate date; + QTime ist; + QTime soll; + QString compositeId; + }; + + const QVector &dayinfos() const; + +private Q_SLOTS: + void requestFinished(); + +private: + std::unique_ptr m_reply; + QVector m_dayinfos; +}; diff --git a/zeiterfassungcorelib/replies/gettimeassignmentsreply.cpp b/zeiterfassungcorelib/replies/gettimeassignmentsreply.cpp index 2f13cd1..57b272c 100644 --- a/zeiterfassungcorelib/replies/gettimeassignmentsreply.cpp +++ b/zeiterfassungcorelib/replies/gettimeassignmentsreply.cpp @@ -60,9 +60,9 @@ void GetTimeAssignmentsReply::requestFinished() m_timeAssignments.append({ obj.value(QStringLiteral("bookingNr")).toInt(), - QDate::fromString(QString::number(obj.value(QStringLiteral("bookingDate")).toInt()), QStringLiteral("yyyyMMdd")), - QTime::fromString(QStringLiteral("%0").arg(obj.value(QStringLiteral("bookingTime")).toInt(), 6, 10, QChar('0')), QStringLiteral("HHmmss")), - QTime::fromString(QStringLiteral("%0").arg(obj.value(QStringLiteral("bookingTimespan")).toInt(), 6, 10, QChar('0')), QStringLiteral("HHmmss")), + parseDate(obj.value(QStringLiteral("bookingDate"))), + parseTime(obj.value(QStringLiteral("bookingTime"))), + parseTime(obj.value(QStringLiteral("bookingTimespan"))), obj.value(QStringLiteral("text")).toString(), koWertList.at(0).toObject().value(QStringLiteral("value")).toString(), koWertList.at(1).toObject().value(QStringLiteral("value")).toString(), diff --git a/zeiterfassungcorelib/replies/getuserinforeply.cpp b/zeiterfassungcorelib/replies/getuserinforeply.cpp index e07dc18..640f165 100644 --- a/zeiterfassungcorelib/replies/getuserinforeply.cpp +++ b/zeiterfassungcorelib/replies/getuserinforeply.cpp @@ -150,8 +150,8 @@ void GetUserInfoReply::request1Finished() m_userInfo.street = obj.value(QStringLiteral("gemeinde")).toString(); m_userInfo.city = obj.value(QStringLiteral("ort")).toString(); - m_userInfo.employedSince = QDate::fromString(QString::number(obj.value(QStringLiteral("angFrom")).toInt()), QStringLiteral("yyyyMMdd")); - m_userInfo.employedTill = QDate::fromString(QString::number(obj.value(QStringLiteral("angTill")).toInt()), QStringLiteral("yyyyMMdd")); + m_userInfo.employedSince = parseDate(obj.value(QStringLiteral("angFrom"))); + m_userInfo.employedTill = parseDate(obj.value(QStringLiteral("angTill"))); m_userInfo.placeOfBirth = obj.value(QStringLiteral("gebOrt")).toString(); m_userInfo.zipcode = obj.value(QStringLiteral("plz")).toString(); m_userInfo.religion = obj.value(QStringLiteral("religion")).toString(); diff --git a/zeiterfassungcorelib/replies/zeiterfassungreply.cpp b/zeiterfassungcorelib/replies/zeiterfassungreply.cpp index 6784956..2270dc1 100644 --- a/zeiterfassungcorelib/replies/zeiterfassungreply.cpp +++ b/zeiterfassungcorelib/replies/zeiterfassungreply.cpp @@ -1,6 +1,7 @@ #include "zeiterfassungreply.h" #include +#include #include "zeiterfassungapi.h" @@ -29,6 +30,22 @@ void ZeiterfassungReply::waitForFinished() eventLoop.exec(); } +QDate ZeiterfassungReply::parseDate(const QJsonValue &value) +{ + if(value.isNull()) + return QDate(); + + return QDate::fromString(QString::number(value.toInt()), QStringLiteral("yyyyMMdd")); +} + +QTime ZeiterfassungReply::parseTime(const QJsonValue &value) +{ + if(value.isNull()) + return QTime(); + + return QTime::fromString(QStringLiteral("%0").arg(value.toInt(), 6, 10, QChar('0')), QStringLiteral("HHmmss")); +} + ZeiterfassungApi *ZeiterfassungReply::zeiterfassung() const { return m_zeiterfassung; diff --git a/zeiterfassungcorelib/replies/zeiterfassungreply.h b/zeiterfassungcorelib/replies/zeiterfassungreply.h index 11b535d..88c21a0 100644 --- a/zeiterfassungcorelib/replies/zeiterfassungreply.h +++ b/zeiterfassungcorelib/replies/zeiterfassungreply.h @@ -4,6 +4,8 @@ #include "zeiterfassungcorelib_global.h" +class QJsonValue; + class ZeiterfassungApi; class ZEITERFASSUNGCORELIBSHARED_EXPORT ZeiterfassungReply : public QObject @@ -18,6 +20,9 @@ public: void waitForFinished(); + static QDate parseDate(const QJsonValue &value); + static QTime parseTime(const QJsonValue &value); + Q_SIGNALS: void finished(); diff --git a/zeiterfassungcorelib/zeiterfassungapi.cpp b/zeiterfassungcorelib/zeiterfassungapi.cpp index a125acc..78f2803 100644 --- a/zeiterfassungcorelib/zeiterfassungapi.cpp +++ b/zeiterfassungcorelib/zeiterfassungapi.cpp @@ -24,6 +24,7 @@ #include "replies/getreportreply.h" #include "replies/getpresencestatusreply.h" #include "replies/getabsencesreply.h" +#include "replies/getdayinforeply.h" //add support for pre cpp14 compilers #include "cpp14polyfills.h" @@ -84,8 +85,8 @@ std::unique_ptr ZeiterfassungApi::doGetBookings(int userId, co { QNetworkRequest request(QUrl(QStringLiteral("%0json/bookings?start=%1&end=%2&pnrLst=%3") .arg(m_url.toString()) - .arg(start.toString(QStringLiteral("yyyyMMdd"))) - .arg(end.toString(QStringLiteral("yyyyMMdd"))) + .arg(formatDate(start)) + .arg(formatDate(end)) .arg(userId))); request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar")); @@ -101,9 +102,9 @@ std::unique_ptr ZeiterfassungApi::doCreateBooking(int userId QJsonObject obj; obj[QStringLiteral("persNr")] = userId; - obj[QStringLiteral("bookingDate")] = date.toString(QStringLiteral("yyyyMMdd")).toInt(); - obj[QStringLiteral("bookingTime")] = time.toString(QStringLiteral("Hmmss")).toInt(); - obj[QStringLiteral("bookingTimespan")] = timespan.toString(QStringLiteral("Hmmss")).toInt(); + obj[QStringLiteral("bookingDate")] = formatDate(date).toInt(); + obj[QStringLiteral("bookingTime")] = formatTime(time).toInt(); + obj[QStringLiteral("bookingTimespan")] = formatTime(timespan).toInt(); obj[QStringLiteral("bookingType")] = type; obj[QStringLiteral("hourCategory")] = QStringLiteral(""); obj[QStringLiteral("empfEinh")] = QStringLiteral(""); @@ -125,9 +126,9 @@ std::unique_ptr ZeiterfassungApi::doUpdateBooking(int bookin QJsonObject obj; obj[QStringLiteral("bookingNr")] = bookingId; obj[QStringLiteral("persNr")] = userId; - obj[QStringLiteral("bookingDate")] = date.toString(QStringLiteral("yyyyMMdd")).toInt(); - obj[QStringLiteral("bookingTime")] = time.toString(QStringLiteral("Hmmss")).toInt(); - obj[QStringLiteral("bookingTimespan")] = timespan.toString(QStringLiteral("Hmmss")).toInt(); + obj[QStringLiteral("bookingDate")] = formatDate(date).toInt(); + obj[QStringLiteral("bookingTime")] = formatTime(time).toInt(); + obj[QStringLiteral("bookingTimespan")] = formatTime(timespan).toInt(); obj[QStringLiteral("bookingType")] = type; obj[QStringLiteral("hourCategory")] = QStringLiteral(""); obj[QStringLiteral("empfEinh")] = QStringLiteral(""); @@ -153,8 +154,8 @@ std::unique_ptr ZeiterfassungApi::doGetTimeAssignments( { QNetworkRequest request(QUrl(QStringLiteral("%0json/azebooking?start=%1&end=%2&pnrLst=%3") .arg(m_url.toString()) - .arg(start.toString(QStringLiteral("yyyyMMdd"))) - .arg(end.toString(QStringLiteral("yyyyMMdd"))) + .arg(formatDate(start)) + .arg(formatDate(end)) .arg(userId))); request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar")); @@ -173,9 +174,9 @@ std::unique_ptr ZeiterfassungApi::doCreateTimeAssignm QJsonObject obj; obj[QStringLiteral("bookingNr")] = QJsonValue::Null; obj[QStringLiteral("persNr")] = userId; - obj[QStringLiteral("bookingDate")] = date.toString(QStringLiteral("yyyyMMdd")).toInt(); - obj[QStringLiteral("bookingTime")] = time.toString(QStringLiteral("Hmmss")).toInt(); - obj[QStringLiteral("bookingTimespan")] = timespan.toString(QStringLiteral("Hmmss")).toInt(); + obj[QStringLiteral("bookingDate")] = formatDate(date).toInt(); + obj[QStringLiteral("bookingTime")] = formatTime(time).toInt(); + obj[QStringLiteral("bookingTimespan")] = formatTime(timespan).toInt(); obj[QStringLiteral("text")] = text; { QJsonArray koWertList; @@ -214,9 +215,9 @@ std::unique_ptr ZeiterfassungApi::doUpdateTimeAssignm QJsonObject obj; obj[QStringLiteral("bookingNr")] = timeAssignmentId; obj[QStringLiteral("persNr")] = userId; - obj[QStringLiteral("bookingDate")] = date.toString(QStringLiteral("yyyyMMdd")).toInt(); - obj[QStringLiteral("bookingTime")] = time.toString(QStringLiteral("Hmmss")).toInt(); - obj[QStringLiteral("bookingTimespan")] = timespan.toString(QStringLiteral("Hmmss")).toInt(); + obj[QStringLiteral("bookingDate")] = formatDate(date).toInt(); + obj[QStringLiteral("bookingTime")] = formatTime(time).toInt(); + obj[QStringLiteral("bookingTimespan")] = formatTime(timespan).toInt(); obj[QStringLiteral("bookingType")] = QJsonValue::Null; obj[QStringLiteral("hourCategory")] = QJsonValue::Null; obj[QStringLiteral("bewEinh")] = QJsonValue::Null; @@ -263,7 +264,7 @@ std::unique_ptr ZeiterfassungApi::doGetProjects(int userId, co QNetworkRequest request(QUrl(QStringLiteral("%0json/combobox?persnr=%1&date=%2&dqkey=KOST&kowert0=&kowert1=&kowert2=&term=") .arg(m_url.toString()) .arg(userId) - .arg(date.toString(QStringLiteral("yyyyMMdd"))))); + .arg(formatDate(date)))); request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar")); return std::make_unique(std::unique_ptr(m_manager->get(request)), this); @@ -274,7 +275,7 @@ std::unique_ptr ZeiterfassungApi::doGetReport(int userId, const QNetworkRequest request(QUrl(QStringLiteral("%0json/auswertung/month?persNr=%1&date=%2") .arg(m_url.toString()) .arg(userId) - .arg(date.toString(QStringLiteral("yyyyMMdd"))))); + .arg(formatDate(date)))); request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar")); return std::make_unique(std::unique_ptr(m_manager->get(request)), this); @@ -292,10 +293,32 @@ std::unique_ptr ZeiterfassungApi::doGetAbsences(int userId, co { QNetworkRequest request(QUrl(QStringLiteral("%0json/fulldayAbsences?start=%1&end=%2&pnrLst=%3") .arg(m_url.toString()) - .arg(start.toString(QStringLiteral("yyyyMMdd"))) - .arg(end.toString(QStringLiteral("yyyyMMdd"))) + .arg(formatDate(start)) + .arg(formatDate(end)) .arg(userId))); request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar")); return std::make_unique(std::unique_ptr(m_manager->get(request)), this); } + +std::unique_ptr ZeiterfassungApi::doGetDayinfo(int userId, const QDate &start, const QDate &end) +{ + QNetworkRequest request(QUrl(QStringLiteral("%0json/dayinfo?start=%1&end=%2&pnrLst=%3") + .arg(m_url.toString()) + .arg(formatDate(start)) + .arg(formatDate(end)) + .arg(userId))); + request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar")); + + return std::make_unique(std::unique_ptr(m_manager->get(request)), this); +} + +QString ZeiterfassungApi::formatDate(const QDate &date) +{ + return date.toString(QStringLiteral("yyyyMMdd")); +} + +QString ZeiterfassungApi::formatTime(const QTime &time) +{ + return time.toString(QStringLiteral("Hmmss")); +} diff --git a/zeiterfassungcorelib/zeiterfassungapi.h b/zeiterfassungcorelib/zeiterfassungapi.h index a3f3107..17602ba 100644 --- a/zeiterfassungcorelib/zeiterfassungapi.h +++ b/zeiterfassungcorelib/zeiterfassungapi.h @@ -27,6 +27,7 @@ class GetProjectsReply; class GetReportReply; class GetPresenceStatusReply; class GetAbsencesReply; +class GetDayinfoReply; class ZEITERFASSUNGCORELIBSHARED_EXPORT ZeiterfassungApi : public QObject { @@ -66,8 +67,12 @@ public: std::unique_ptr doGetReport(int userId, const QDate &date); std::unique_ptr doGetPresenceStatus(); std::unique_ptr doGetAbsences(int userId, const QDate &start, const QDate &end); + std::unique_ptr doGetDayinfo(int userId, const QDate &start, const QDate &end); private: + static QString formatDate(const QDate &date); + static QString formatTime(const QTime &time); + QUrl m_url; QNetworkAccessManager *m_manager; }; diff --git a/zeiterfassungcorelib/zeiterfassungcorelib.pro b/zeiterfassungcorelib/zeiterfassungcorelib.pro index f64770b..80c924d 100644 --- a/zeiterfassungcorelib/zeiterfassungcorelib.pro +++ b/zeiterfassungcorelib/zeiterfassungcorelib.pro @@ -17,6 +17,7 @@ SOURCES += timeutils.cpp \ replies/deletetimeassignmentreply.cpp \ replies/getabsencesreply.cpp \ replies/getbookingsreply.cpp \ + replies/getdayinforeply.cpp \ replies/getpresencestatusreply.cpp \ replies/getprojectsreply.cpp \ replies/getreportreply.cpp \ @@ -39,6 +40,7 @@ HEADERS += cpp14polyfills.h \ replies/deletetimeassignmentreply.h \ replies/getabsencesreply.h \ replies/getbookingsreply.h \ + replies/getdayinforeply.h \ replies/getpresencestatusreply.h \ replies/getprojectsreply.h \ replies/getreportreply.h \ diff --git a/zeiterfassungguilib/stripswidget.cpp b/zeiterfassungguilib/stripswidget.cpp index 131efba..f4c74df 100644 --- a/zeiterfassungguilib/stripswidget.cpp +++ b/zeiterfassungguilib/stripswidget.cpp @@ -12,10 +12,14 @@ #include "timeutils.h" #include "stripfactory.h" +const QStringList StripsWidget::m_weekDays { tr("Monday"), tr("Tuesday"), + tr("Wednesday"), tr("Thursday"), tr("Friday"), tr("Saturday"), tr("Sunday") }; + StripsWidget::StripsWidget(MainWindow &mainWindow, QWidget *parent) : QFrame(parent), m_mainWindow(mainWindow), m_refreshing(false), + m_refreshingDayinfo(false), m_refreshingBookings(false), m_refreshingTimeAssignments(false), m_startEnabled(false), @@ -24,15 +28,20 @@ StripsWidget::StripsWidget(MainWindow &mainWindow, QWidget *parent) : auto layout = new QVBoxLayout(this); m_headerLayout = new QHBoxLayout; - m_label = new QLabel; + + m_label[0] = new QLabel; { - auto font = m_label->font(); + auto font = m_label[0]->font(); font.setBold(true); - m_label->setFont(font); + m_label[0]->setFont(font); } - m_headerLayout->addWidget(m_label, 1); + m_headerLayout->addWidget(m_label[0], 1); + layout->addLayout(m_headerLayout); + m_label[1] = new QLabel; + layout->addWidget(m_label[1]); + m_stripsLayout = new QVBoxLayout; layout->addLayout(m_stripsLayout); @@ -56,9 +65,14 @@ QBoxLayout *StripsWidget::stripsLayout() const return m_stripsLayout; } -QLabel *StripsWidget::label() const +QLabel *StripsWidget::label0() const { - return m_label; + return m_label[0]; +} + +QLabel *StripsWidget::label1() const +{ + return m_label[1]; } const QDate &StripsWidget::date() const @@ -73,12 +87,11 @@ void StripsWidget::setDate(const QDate &date) Q_EMIT dateChanged(m_date = date); if(m_date.isValid()) - m_label->setText(tr("%0 (%1)") - .arg(std::array { tr("Monday"), tr("Tuesday"), tr("Wednesday"), tr("Thursday"), - tr("Friday"), tr("Saturday"), tr("Sunday") }[m_date.dayOfWeek() - 1]) + m_label[0]->setText(tr("%0 (%1)") + .arg(m_weekDays.at(m_date.dayOfWeek() - 1)) .arg(m_date.toString(tr("dd.MM.yyyy")))); else - m_label->setText(tr("Invalid")); + m_label[0]->setText(tr("Invalid")); refresh(); } @@ -98,6 +111,11 @@ void StripsWidget::setHighlighted(bool highlighted) } } +const GetDayinfoReply::Dayinfo &StripsWidget::dayinfo() const +{ + return m_dayinfo; +} + const QVector &StripsWidget::bookings() const { return m_bookings; @@ -128,6 +146,11 @@ bool StripsWidget::refreshing() const return m_refreshing; } +bool StripsWidget::refreshingDayinfo() const +{ + return m_refreshingDayinfo; +} + bool StripsWidget::refreshingBookings() const { return m_refreshingBookings; @@ -152,12 +175,34 @@ void StripsWidget::refresh() { clearStrips(); + m_label[1]->setText(QString()); m_stripsLayout->addWidget(new QLabel(tr("Loading..."), this)); + refreshDayinfo(); refreshBookings(false); refreshTimeAssignments(false); } +void StripsWidget::refreshDayinfo() +{ + if(!m_date.isValid()) + { + qWarning() << "invalid date"; + return; + } + + if(!m_refreshing) + Q_EMIT refreshingChanged(m_refreshing = true); + + if(!m_refreshingDayinfo) + Q_EMIT refreshingDayinfoChanged(m_refreshingDayinfo = true); + + invalidateValues(); + + m_getDayinfoReply = m_mainWindow.erfassung().doGetDayinfo(m_mainWindow.userInfo().userId, m_date, m_date); + connect(m_getDayinfoReply.get(), &ZeiterfassungReply::finished, this, &StripsWidget::getDayinfoFinished); +} + void StripsWidget::refreshBookings(bool createLabel) { if(!m_date.isValid()) @@ -483,6 +528,13 @@ void StripsWidget::clearStrips() } } +void StripsWidget::getDayinfoFinished() +{ + Q_EMIT dayinfoChanged(m_dayinfo = m_getDayinfoReply->dayinfos().first()); + + m_label[1]->setText(QString("%0 - %1").arg(m_dayinfo.soll.toString("HH:mm")).arg(m_dayinfo.ist.toString("HH:mm"))); +} + void StripsWidget::getBookingsFinished() { Q_EMIT bookingsChanged(m_bookings = m_getBookingsReply->bookings()); @@ -490,13 +542,11 @@ void StripsWidget::getBookingsFinished() if(m_refreshingBookings) Q_EMIT refreshingBookingsChanged(m_refreshingBookings = false); - if(!m_getTimeAssignmentsReply) - { - if(m_refreshing) - Q_EMIT refreshingChanged(m_refreshing = false); + if(m_refreshing && !m_getDayinfoReply && !m_getTimeAssignmentsReply) + Q_EMIT refreshingChanged(m_refreshing = false); + if(!m_getTimeAssignmentsReply) createStrips(); - } m_getBookingsReply = Q_NULLPTR; } @@ -508,13 +558,11 @@ void StripsWidget::getTimeAssignmentsFinished() if(m_refreshingTimeAssignments) Q_EMIT refreshingTimeAssignmentsChanged(m_refreshingTimeAssignments = false); - if(!m_getBookingsReply) - { - if(m_refreshing) - Q_EMIT refreshingChanged(m_refreshing = false); + if(m_refreshing && !m_getDayinfoReply && !m_getBookingsReply) + Q_EMIT refreshingChanged(m_refreshing = false); + if(!m_getBookingsReply) createStrips(); - } m_getTimeAssignmentsReply = Q_NULLPTR; } diff --git a/zeiterfassungguilib/stripswidget.h b/zeiterfassungguilib/stripswidget.h index f9a9cbe..ebeb961 100644 --- a/zeiterfassungguilib/stripswidget.h +++ b/zeiterfassungguilib/stripswidget.h @@ -6,6 +6,7 @@ #include #include "zeiterfassungguilib_global.h" +#include "replies/getdayinforeply.h" #include "replies/getbookingsreply.h" #include "replies/gettimeassignmentsreply.h" @@ -27,7 +28,8 @@ public: QBoxLayout *headerLayout() const; QBoxLayout *stripsLayout() const; - QLabel *label() const; + QLabel *label0() const; + QLabel *label1() const; const QDate &date() const; void setDate(const QDate &date); @@ -35,6 +37,7 @@ public: bool highlighted() const; void setHighlighted(bool highlighted); + const GetDayinfoReply::Dayinfo &dayinfo() const; const QVector &bookings() const; const QVector &timeAssignments() const; @@ -42,12 +45,14 @@ public: const QTime &lastTimeAssignmentStart() const; const QTime &minimumTime() const; bool refreshing() const; + bool refreshingDayinfo() const; bool refreshingBookings() const; bool refreshingTimeAssignments() const; bool startEnabled() const; bool endEnabled() const; void refresh(); + void refreshDayinfo(); void refreshBookings(bool createLabel = true); void refreshTimeAssignments(bool createLabel = true); bool createStrips(); @@ -57,6 +62,7 @@ Q_SIGNALS: void dateChanged(const QDate &date); void highlightedChanged(bool highlighted); + void dayinfoChanged(const GetDayinfoReply::Dayinfo &dayinfo); void bookingsChanged(const QVector &bookings); void timeAssignmentsChanged(const QVector &timeAssignments); @@ -64,12 +70,14 @@ Q_SIGNALS: void lastTimeAssignmentStartChanged(const QTime &lastTimeAssignmentStart); void minimumTimeChanged(const QTime &minimumTime); void refreshingChanged(bool refreshing); + void refreshingDayinfoChanged(bool refreshingDayinfo); void refreshingBookingsChanged(bool refreshingBookings); void refreshingTimeAssignmentsChanged(bool refreshingTimeAssignments); void startEnabledChanged(bool startEnabled); void endEnabledChanged(bool endEnabled); private Q_SLOTS: + void getDayinfoFinished(); void getBookingsFinished(); void getTimeAssignmentsFinished(); @@ -87,11 +95,12 @@ private: QBoxLayout *m_headerLayout; QBoxLayout *m_stripsLayout; - QLabel *m_label; + QLabel *m_label[2]; QDate m_date; bool m_highlighted; + GetDayinfoReply::Dayinfo m_dayinfo; QVector m_bookings; QVector m_timeAssignments; @@ -99,11 +108,15 @@ private: QTime m_lastTimeAssignmentStart; QTime m_minimumTime; bool m_refreshing; + bool m_refreshingDayinfo; bool m_refreshingBookings; bool m_refreshingTimeAssignments; bool m_startEnabled; bool m_endEnabled; + std::unique_ptr m_getDayinfoReply; std::unique_ptr m_getBookingsReply; std::unique_ptr m_getTimeAssignmentsReply; + + static const QStringList m_weekDays; };