diff --git a/fannyapp.pro b/fannyapp.pro index 01ef4d5..e0f63df 100644 --- a/fannyapp.pro +++ b/fannyapp.pro @@ -22,12 +22,12 @@ SOURCES += \ sources/serverconn.cpp \ sources/main.cpp \ sources/appsettings.cpp \ - sources/eventform.cpp + sources/foodplanmodel.cpp HEADERS += \ headers/serverconn.h \ headers/appsettings.h \ - headers/eventform.h + headers/foodplanmodel.h RESOURCES += \ qml/qml.qrc \ diff --git a/headers/eventform.h b/headers/eventform.h deleted file mode 100644 index 74d418c..0000000 --- a/headers/eventform.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef EVENTFORM_H -#define EVENTFORM_H - -#include - -class EventForm : public QObject -{ - Q_OBJECT -public: - explicit EventForm(QObject *parent = nullptr); - -signals: - -public slots: -}; - -#endif // EVENTFORM_H \ No newline at end of file diff --git a/headers/foodplanmodel.h b/headers/foodplanmodel.h new file mode 100644 index 0000000..4179b88 --- /dev/null +++ b/headers/foodplanmodel.h @@ -0,0 +1,45 @@ +#ifndef FOODPLANMODEL_H +#define FOODPLANMODEL_H + +#include +#include +#include "serverconn.h" + +class FoodPlanModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit FoodPlanModel(QObject *parent = nullptr); + ~FoodPlanModel(); + enum DishRole { + CookteamRole = Qt::DisplayRole, + DateRole, + MainDishRole, + MainDishVegRole, + GarnishRole, + DessertRole + }; + Q_ENUM(DishRole) + + int rowCount(const QModelIndex & = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QHash roleNames() const; + + Q_INVOKABLE QVariantMap get(int row) const; + +private: + struct Dish { + QString cookteam; + QString date; + QString mainDish; + QString mainDishVeg; + QString garnish; + QString dessert; + }; + + QList m_foodPlan; + +public slots: +}; + +#endif // FOODPLANMODEL_H diff --git a/headers/serverconn.h b/headers/serverconn.h index e5ded92..cb268bc 100644 --- a/headers/serverconn.h +++ b/headers/serverconn.h @@ -48,6 +48,8 @@ public: Q_INVOKABLE int getEventCount(); ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData); + QList> m_weekplan; + signals: public slots: @@ -55,19 +57,9 @@ public slots: private: -struct Day -{ - QString Cookteam; - QString Date; - QString Main; - QString Main_veg; - QString Salad; - QString Dessert; -}; - -QList> m_weekplan; QList m_eventlist; }; +extern ServerConn * pGlobalServConn; #endif // SERVERCONN_H diff --git a/qml/Components/EventDisplay.qml b/qml/Components/EventDisplay.qml index f484901..8e183ea 100644 --- a/qml/Components/EventDisplay.qml +++ b/qml/Components/EventDisplay.qml @@ -4,7 +4,6 @@ import QtQuick.Controls 2.4 Item { id: control - ScrollView { id:scroll anchors.fill: parent @@ -94,30 +93,5 @@ Item { } } - Rectangle { - id: errorRect - - anchors { - left: parent.left - right: parent.right - verticalCenter: parent.verticalCenter - margins: parent.width * 0.15 - } - - radius: height * 0.5 - height: width - - color: "transparent" - border.width: 5 - border.color: "red" - - visible: _cppServerConn.getEventCount() === 0 - - Label { - anchors.centerIn: parent - text: "keine Daten..." - } - } - } diff --git a/qml/Components/FoodPlanDisplay.qml b/qml/Components/FoodPlanDisplay.qml index 7840d46..a206d7d 100644 --- a/qml/Components/FoodPlanDisplay.qml +++ b/qml/Components/FoodPlanDisplay.qml @@ -1,211 +1,154 @@ import QtQuick 2.9 import QtQuick.Controls 2.4 +import QtQuick.Layouts 1.3 +import Backend 1.0 Item { id: control - ScrollView { - id:scroll + ListView { + id: foodList + anchors.fill: parent - visible: _cppServerConn.getFoodPlanData(0).cookteam !== "" + anchors.margins: 10 - ListView { - id: listView - //width: 514 - model: 8 - spacing: 0 - property var today: new Date - anchors { - right: parent.right - left: parent.left - top: parent.top - bottom: parent.bottom - leftMargin: 5 - rightMargin: 5 - topMargin: 3 - } - - delegate: Button { - - width: listView.width - id: delegate - height: visible ? cookteam.height + date.height + main_dish.height + main_dish_veg.height + garnish.height + dessert.height + spacer.height + cust_spacing*9 + 5:0 - visible: listView.isDayVisible(index) - - property int cust_spacing: 5 - - Label { - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.top: parent.top - anchors.topMargin: 10 - font.bold: true - id: cookteam - text: _cppServerConn.getFoodPlanData(index).cookteam - width: parent.width - 10 - wrapMode: Label.Wrap - height: text!=""? undefined:0 - } - Label { - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.top: cookteam.bottom - font.bold: true - id: date - text: listView.getDateString(index) - width: parent.width - 10 - wrapMode: Label.Wrap - } - Rectangle { - anchors.top: date.bottom - anchors.topMargin: cust_spacing - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.right: parent.right - anchors.rightMargin: 10 - height: 2 - color: "grey" - - } - - Label { - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.top: date.bottom - anchors.topMargin: cust_spacing * 2 - width: parent.width - 10 - wrapMode: Label.Wrap - id: main_dish - text: _cppServerConn.getFoodPlanData(index).main_dish - height: text!=""? undefined:0 - } - - Rectangle { - anchors.top: main_dish.bottom - anchors.topMargin: cust_spacing - anchors.left: parent.left - anchors.leftMargin: 10 - width: parent.width / 10 - height: main_dish_veg.text!=""? 1:0 - color: "grey" - - } - - Label { - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.top: main_dish.bottom - anchors.topMargin: cust_spacing * 2 - id: main_dish_veg - text: _cppServerConn.getFoodPlanData(index).main_dish_veg - width: parent.width - 10 - wrapMode: Label.Wrap - height: text!=""? undefined:0 - } - - Rectangle { - anchors.top: main_dish_veg.bottom - anchors.topMargin: cust_spacing - anchors.left: parent.left - anchors.leftMargin: 10 - width: parent.width / 10 - height: garnish.text!=""? 1:0 - color: "grey" - } - - Label { - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.top: main_dish_veg.bottom - anchors.topMargin: cust_spacing * 2 - id: garnish - text: _cppServerConn.getFoodPlanData(index).garnish - width: parent.width - 10 - wrapMode: Label.Wrap - height: text!=""? undefined:0 - } - - Rectangle { - anchors.top: garnish.bottom - anchors.topMargin: cust_spacing - anchors.left: parent.left - anchors.leftMargin: 10 - width: parent.width / 10 - height: dessert.text!=""? 1:0 - color: "grey" - - } - - Label { - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.top: garnish.bottom - anchors.topMargin: cust_spacing * 2 - id: dessert - text: _cppServerConn.getFoodPlanData(index).dessert - width: parent.width - 10 - wrapMode: Label.Wrap - height: text!=""? undefined:0 - } - - Label { - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.top: dessert.bottom - anchors.topMargin: cust_spacing - id: spacer - text: "" - } - } - - function getDateString(index){ - var date = _cppServerConn.getFoodPlanData(index).date - console.log(date.getTime()) - console.log(today.getTime()) - if(date.getDate() === today.getDate()){ - return("Heute") - } - else if(date.getTime() < (today.getTime() + (24 * 60 * 60 * 1000) )/*date.getDate() === today.getDate() + 1 || (date.getDate() === 1 && date.getMonth() === today.getMonth() + 1)*/){ - return("Morgen") - } - else { - return(Qt.formatDateTime(_cppServerConn.getFoodPlanData(index).date, "dddd, d.M.yy")) - } - - } - function isDayVisible(index){ - var date = _cppServerConn.getFoodPlanData(index).date - // console.warn(date.getTime()) - // console.warn(today.getTime()) - // console.log("") - return( date.getTime() > today.getTime() || date.getDate() === today.getDate()/*(date.getDate() >= today.getDate() && date.getMonth() >= today.getMonth()) || (date.getDate() < today.getDate() && date.getMonth() >= today.getMonth())*/) - } - } - } - - Rectangle { - id: errorRect - - anchors { - left: parent.left - right: parent.right - verticalCenter: parent.verticalCenter - margins: parent.width * 0.15 + model: FoodPlanModel { + id: foodPlanModel } - radius: height * 0.5 - height: width + delegate: Button { - color: "transparent" - border.width: 5 - border.color: "red" + width: foodList.width + id: delegate + height: visible ? cookteamLa.height + dateLa.height + mainDishLa.height + mainDishVegLa.height + garnishLa.height + dessertLa.height + spacer.height + cust_spacing*9 + 5:0 + visible: true//listView.isDayVisible(index) - visible: _cppServerConn.getFoodPlanData(0).cookteam === "" + property int cust_spacing: 5 - Label { - anchors.centerIn: parent - text: "keine Daten..." + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: parent.top + anchors.topMargin: 10 + font.bold: true + id: cookteamLa + text: cookteam + width: parent.width - 10 + wrapMode: Label.Wrap + height: text!=""? undefined:0 + } + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: cookteamLa.bottom + font.bold: true + id: dateLa + text: date + width: parent.width - 10 + wrapMode: Label.Wrap + } + Rectangle { + anchors.top: dateLa.bottom + anchors.topMargin: cust_spacing + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.right: parent.right + anchors.rightMargin: 10 + height: 2 + color: "grey" + + } + + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: dateLa.bottom + anchors.topMargin: cust_spacing * 2 + width: parent.width - 10 + wrapMode: Label.Wrap + id: mainDishLa + text: mainDish + height: text!=""? undefined:0 + } + + Rectangle { + anchors.top: mainDishLa.bottom + anchors.topMargin: cust_spacing + anchors.left: parent.left + anchors.leftMargin: 10 + width: parent.width / 10 + height: mainDishVegLa.text!=""? 1:0 + color: "grey" + + } + + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: mainDishLa.bottom + anchors.topMargin: cust_spacing * 2 + id: mainDishVegLa + text: mainDishVeg + width: parent.width - 10 + wrapMode: Label.Wrap + height: text!=""? undefined:0 + } + + Rectangle { + anchors.top: mainDishVegLa.bottom + anchors.topMargin: cust_spacing + anchors.left: parent.left + anchors.leftMargin: 10 + width: parent.width / 10 + height: garnishLa.text!=""? 1:0 + color: "grey" + } + + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: mainDishVegLa.bottom + anchors.topMargin: cust_spacing * 2 + id: garnishLa + text: garnish + width: parent.width - 10 + wrapMode: Label.Wrap + height: text!=""? undefined:0 + } + + Rectangle { + anchors.top: garnishLa.bottom + anchors.topMargin: cust_spacing + anchors.left: parent.left + anchors.leftMargin: 10 + width: parent.width / 10 + height: dessertLa.text!=""? 1:0 + color: "grey" + + } + + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: garnishLa.bottom + anchors.topMargin: cust_spacing * 2 + id: dessertLa + text: dessert + width: parent.width - 10 + wrapMode: Label.Wrap + height: text!=""? undefined:0 + } + + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: dessertLa.bottom + anchors.topMargin: cust_spacing + id: spacer + text: "" + } } + } } diff --git a/qml/Components/InfoArea.qml b/qml/Components/InfoArea.qml new file mode 100644 index 0000000..01898cc --- /dev/null +++ b/qml/Components/InfoArea.qml @@ -0,0 +1,71 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.4 + +Item { + id: infoArea + + property int alertLevel: app.getErrorInfo(infoArea.errorCode)[0] + property int errorCode: -1 + + height: childrenRect.height + + Rectangle { + + // 0 - ok + // 1 - info + // 2 - error + + radius: height * 0.5 + width: parent.width + height: width + + color: "transparent" + border.width: 5 + border.color: infoArea.alertLevel > 0 ? infoArea.alertLevel > 1 ? "red":"grey" : "green" + + opacity: infoArea.errorCode !== 200 && infoArea.errorCode !== (-1) ? 1:0 + + Behavior on opacity { + NumberAnimation { + duration: 500 + } + } + + Label { + anchors.centerIn: parent + font.pixelSize: parent.height * 0.8 + text: infoArea.alertLevel > 1 ? "!":"i" + color: infoArea.alertLevel > 0 ? infoArea.alertLevel > 1 ? "red":"grey" : "green" + } + + Label { + id: errorShortDescription + anchors { + horizontalCenter: parent.horizontalCenter + top: parent.bottom + margins: parent.height * 0.1 + } + font.pixelSize: errorLongDescription.font.pixelSize * 2 + text: app.getErrorInfo(infoArea.errorCode)[1] + } + + Label { + id: errorLongDescription + anchors { + horizontalCenter: parent.horizontalCenter + top: errorShortDescription.bottom + margins: parent.height * 0.1 + } + + width: parent.width + + wrapMode: Label.Wrap + + horizontalAlignment: Label.AlignHCenter + + text: app.getErrorInfo(infoArea.errorCode)[2] + } + } + +} + diff --git a/qml/Forms/EventForm.qml b/qml/Forms/EventForm.qml index 9b0144c..75bea67 100644 --- a/qml/Forms/EventForm.qml +++ b/qml/Forms/EventForm.qml @@ -1,6 +1,7 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 import QtGraphicalEffects 1.0 +import "../Components" Page { id: root @@ -9,6 +10,7 @@ Page { title: qsTr("Vertretungsplan") property string icon: "qrc:/graphics/FannyLogo_small.png" property string link: "http://www.fanny-leicht.de/j34" + property int status: -1 signal opened() @@ -56,8 +58,22 @@ Page { running: true repeat: false onTriggered: { - _cppServerConn.getEvents(day); + status = _cppServerConn.getEvents(day); pageLoader.source = "../Components/EventDisplay.qml" } } + + InfoArea { + id: infoArea + + anchors { + left: parent.left + right: parent.right + top: parent.top + margins: app.landscape() ? parent.width * 0.4:parent.width * 0.3 + topMargin: parent.height/2 - height * 0.8 + } + + errorCode: status + } } diff --git a/qml/Forms/FoodPlanForm.qml b/qml/Forms/FoodPlanForm.qml index bd77fe0..41231c8 100644 --- a/qml/Forms/FoodPlanForm.qml +++ b/qml/Forms/FoodPlanForm.qml @@ -1,6 +1,7 @@ import QtQuick 2.9 import QtQuick.Controls 2.4 import QtGraphicalEffects 1.0 +import "../Components" Page { id:root @@ -9,6 +10,7 @@ Page { title: qsTr("Speiseplan") property string icon: "qrc:/graphics/images/TreffpunktFannyLogo.png" property string link: "http://www.treffpunkt-fanny.de" + property int status: -1 signal opened() @@ -57,10 +59,22 @@ Page { running: true repeat: false onTriggered: { - _cppServerConn.getFoodPlan() + root.status = _cppServerConn.getFoodPlan() pageLoader.source = "../Components/FoodPlanDisplay.qml" } } + InfoArea { + id: infoArea + anchors { + left: parent.left + right: parent.right + top: parent.top + margins: app.landscape() ? parent.width * 0.4:parent.width * 0.3 + topMargin: parent.height/2 - height * 0.8 + } + + errorCode: status + } } diff --git a/qml/Forms/HomeForm[old].qml b/qml/Forms/HomeForm[old].qml deleted file mode 100644 index 49721a1..0000000 --- a/qml/Forms/HomeForm[old].qml +++ /dev/null @@ -1,210 +0,0 @@ -import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtGraphicalEffects 1.0 - -import "../Components" - -Page { - //anchors.fill: parent - - title: qsTr("Vertretungsplan") - property string icon: "qrc:/graphics/images/FannyLogo_small.png" - property string link: "http://www.fanny-leicht.de/j34" - -// Image{ -// source: "qrc:/graphics/chat_background.jpg"; -// height: parent.height -// width: parent.width -// fillMode: Image.Tile -// horizontalAlignment: Image.AlignLeft -// verticalAlignment: Image.AlignTop -// } - - -// LinearGradient { -// anchors.fill: parent -// start: Qt.point(0, 0) -// end: Qt.point(0, parent.height) -// gradient: Gradient { -// GradientStop { position: 0.0; color: "#4db2b3" } -// GradientStop { position: 1.0; color: "#8f4dae" } -// } -// } - - Label { - id: laWelcome - text: "Hier kannst du dir den Vertretungsplan des Fannys anschauen" - font.pixelSize: 20 - wrapMode: Label.Wrap - width: window.width / 1.2 - color: app.text_color - anchors { - top: parent.top - topMargin: window.height / 8 - laWelcome.height / 2 - horizontalCenter: parent.horizontalCenter - } - } - - Button { - id:buttToday - enabled: window.is_error === false - anchors { - left: parent.left - leftMargin: (window.width / 4) - (buttToday.width / 2) - verticalCenter: parent.verticalCenter - } - - onClicked: { - verificationDialog.day = "sheute" - verificationDialog.open() - } - - onPressed: sheuteImage.scale = 0.9 - onReleased: sheuteImage.scale = 1.0 - - background: Image { - id: sheuteImage - source: "qrc:/graphics/sheute.png" - - Behavior on scale { - PropertyAnimation { - duration: 100 - } - } - } - } - - Button { - id: buttTomorrow - enabled: window.is_error === false - anchors { - right: parent.right - rightMargin: (window.width / 4) - (buttTomorrow.width / 2) - verticalCenter: parent.verticalCenter - } - - onClicked: { - verificationDialog.day = "smorgen" - verificationDialog.open() - } - - onPressed: smorgenImage.scale = 0.9 - onReleased: smorgenImage.scale = 1.0 - - background: Image { - id: smorgenImage - source: "qrc:/graphics/smorgen.png" - - Behavior on scale { - PropertyAnimation { - duration: 100 - } - } - } - - } - - Rectangle { - id: buttonsDisabled - anchors.left: buttToday.left - anchors.right: buttTomorrow.right - anchors.top: buttToday.top - anchors.bottom: buttToday.bottom - color: "white" - opacity: 0.7 - visible: app.is_error - } - - Dialog { - property string day - id: verificationDialog - modal: true - focus: true - title: "Bedingung" - x: (window.width - width) / 2 - y: window.height / 6 - width: Math.min(window.width, window.height) / 3 * 2 - contentHeight: aboutColumn.height - standardButtons: Dialog.Ok | Dialog.Cancel - onAccepted: { - _cppServerConn.updateProgress(0,100) - busyDialog.open() - text.visible = false - var ret = _cppServerConn.getDay(day) - progressCircle.arcEnd = 36000 - progress.text = "100%" - busyDialog.close() - text.visible = true - if(ret.startsWith("OK")){ - var path = ret.replace("OK_", ""); - Qt.openUrlExternally(path); - return - } - else if(ret === "Ungültige Benutzerdaten."){ - root.StackView.view.pop() - } - else { - error.text = ret - window.is_error = true - window.error = ret - error.visible = true - } - } - - Column { - id: aboutColumn - spacing: 20 - Label { - id: text - visible: true - width: verificationDialog.availableWidth - wrapMode: Label.Wrap - text: "Vertretungsplan, vertraulich, nur zum persönlichen Gebrauch, keine Speicherung!" - } - } - } - - Dialog { - id: busyDialog - modal: true - closePolicy: "NoAutoClose" - focus: true - //title: "Please wait..." - x: (window.width - width) / 2 - y: window.height / 6 - //width: Math.min(window.width, window.height) / 3 * 2 - height: contentHeight * 1.5 - width: contentWidth * 1.5 - contentHeight: progressCircle.height - contentWidth: progressCircle.width - - ProgressCircle { - id: progressCircle - size: 50 - lineWidth: 5 - anchors.centerIn: parent - colorCircle: "#FF3333" - colorBackground: "#E6E6E6" - showBackground: true - arcBegin: 0 - arcEnd: 0 - Label { - id: progress - anchors.centerIn: parent - text: "0%" - } - Timer { - id: refreshTimer - interval: 1; - running: busyDialog.visible - repeat: true - onTriggered: { - var ret = _cppServerConn.getProgress() - - progressCircle.arcEnd = 360 * ret * 1.2 - progress.text = Math.round( ret * 100 ) + "%" - } - } - } - } -} diff --git a/qml/Forms/WebsiteForm.qml b/qml/Forms/WebsiteForm.qml deleted file mode 100644 index 90e2fb8..0000000 --- a/qml/Forms/WebsiteForm.qml +++ /dev/null @@ -1,46 +0,0 @@ -import QtQuick 2.2 -import QtWebView 1.1 -import QtQuick.Controls 2.2 - -import QtQuick.Controls.Styles 1.2 - -Page { - id:root - - objectName: "WebsitePage"; - - title: qsTr("Fanny Webseite") - //property string icon: "qrc:/graphics/FannyLogo_small.png" - - property string link: "http://www.fanny-leicht.de/j34" - - ProgressBar { - id: progress - width: parent.width - anchors { - top: parent.top - } - //z: Qt.platform.os === "android" ? -1 : 1 - visible: webView.loadProgress < 100 - value: webView.loadProgress === 100 ? 0 : webView.loadProgress / 100 - } - - WebView { - id: webView - Keys.onBackPressed: webView.goBack() - z: 0 - anchors { - top: webView.loadProgress < 100 ? progress.bottom:parent.top - bottom: parent.bottom - left: parent.left - right: parent.right - } - - url: link - onLoadingChanged: { - console.log(url) - if (loadRequest.errorString) - console.error(loadRequest.errorString); - } - } -} diff --git a/qml/Pages/MainPage.qml b/qml/Pages/MainPage.qml index 082d831..2d6d285 100644 --- a/qml/Pages/MainPage.qml +++ b/qml/Pages/MainPage.qml @@ -1,8 +1,7 @@ import QtQuick 2.9 -import QtQuick.Controls 2.2 +import QtQuick.Controls 2.4 +import QtGraphicalEffects 1.0 -import QtQuick.Layouts 1.1 -import QtQuick.Controls.Styles 1.2 import "../Components" import "../Forms" @@ -12,18 +11,103 @@ Page { Shortcut { sequences: ["Esc", "Back"] - enabled: stackView.depth > 1 + enabled: formStack.depth > 1 onActivated: { - stackView.pop() + formStack.pop() } } - header: AppToolBar { + StackView { + id: formStack + property var currPage + property string eventDay: "" + anchors { + top: toolBar.bottom + left: parent.left + right: parent.right + bottom: parent.bottom + } + + onCurrPageChanged: { + mainStack.replace(currPage) + } + + onCurrentItemChanged: { + formStack.currentItem.opened() + } + + initialItem: homeForm + + Component { + id: homeForm + HomeForm {} + } + + Component { + id: foodPlanForm + FoodPlanForm {} + } + + Component { + id: eventForm + EventForm { + day: formStack.eventDay + } + } + + popEnter: Transition { + XAnimator { + from: (formStack.mirrored ? -1 : 1) * -formStack.width + to: 0 + duration: 500 + easing.type: Easing.OutCubic + } + } + + popExit: Transition { + XAnimator { + from: 0 + to: (formStack.mirrored ? -1 : 1) * formStack.width + duration: 500 + easing.type: Easing.OutCubic + } + } + + pushEnter: Transition { + XAnimator { + from: (formStack.mirrored ? -1 : 1) * formStack.width + to: 0 + duration: 500 + easing.type: Easing.OutCubic + } + } + + pushExit: Transition { + XAnimator { + from: 0 + to: (formStack.mirrored ? -1 : 1) * -formStack.width + duration: 500 + easing.type: Easing.OutCubic + } + } + } + + AppToolBar { + id: toolBar + + anchors { + top: parent.top + left: parent.left + right: parent.right + topMargin: -60 + } + + height: 50 Button { id:toolButton - enabled: window.is_error === false + enabled: true anchors { left: parent.left verticalCenter: parent.verticalCenter @@ -33,8 +117,8 @@ Page { width: height onClicked: { - if (stackView.depth > 1) { - stackView.pop() + if (formStack.depth > 1) { + formStack.pop() } else { drawer.open() } @@ -44,7 +128,7 @@ Page { onReleased: toolButton.scale = 1.0 background: Image { - source: stackView.depth > 1 ? "qrc:/graphics/icons/back.png" : "qrc:/graphics/icons/drawer.png" + source: formStack.depth > 1 ? "qrc:/graphics/icons/backDark.png" : "qrc:/graphics/icons/drawer.png" height: parent.height width: parent.width Behavior on scale { @@ -56,205 +140,40 @@ Page { } Label { - text: stackView.currentItem.title + text: formStack.currentItem.title anchors { verticalCenter: parent.verticalCenter left: toolButton.right leftMargin: parent.width * 0.02 } font.bold: true - color: "white" + color: "black" } - Image { - id: logo - source: stackView.currentItem.icon - anchors.right: parent.right - anchors.rightMargin: parent.width * 0.02 - anchors.top: parent.top - height: parent.height - fillMode: Image.PreserveAspectFit - mipmap: true - Behavior on scale { - PropertyAnimation { - duration: 100 - } - } - MouseArea { - enabled: stackView.currentItem.link !== undefined && stackView.currentItem.objectName !== "WebsitePage" - anchors.fill: parent - onPressed: logo.scale = 0.9 - onReleased: logo.scale = 1.0 - onClicked: { - stackView.push("qrc:/WebsitePage.qml",{title: "Web", link: stackView.currentItem.link, icon: stackView.currentItem.icon}) - } + Behavior on anchors.topMargin { + NumberAnimation { + duration: 500 + easing.type: Easing.OutCubic } } - } - Drawer { - id: drawer - width: window.width * 0.66 - height: window.height - AppToolBar { - id: header - showErrorBar: false - anchors { - top: parent.top - left: parent.left - right: parent.right - } - - Label { - text: "Menü" - anchors { - verticalCenter: parent.verticalCenter - left: parent.left - leftMargin: 17 + states: [ + State { + name: "closed" + when: formStack.depth === 1 + PropertyChanges { + target: toolBar + anchors.topMargin: -60 } - - font.bold: true - } - } - Column { - anchors { - top: header.bottom - bottom: parent.bottom - left: parent.left - right: parent.right - } - - - ItemDelegate { - text: qsTr("Fanny Webseite") - width: parent.width - onClicked: { - stackView.push("qrc:/WebsitePage.qml",{title: "Fanny Webseite", link: "http://www.fanny-leicht.de/j34", icon: stackView.currentItem.icon}) - drawer.close() + }, + State { + name: "open" + when: formStack.depth > 1 + PropertyChanges { + target: toolBar + anchors.topMargin: 0 } } - - ItemDelegate { - text: qsTr("Vertretungsplan") - width: parent.width - onClicked: { - busyDialog.open() - var ret = _cppServerConn.getEvents(); - drawer.close() - busyDialog.close() - if(ret === 200 || _cppServerConn.getEventData(0).grade !== ""){ - stackView.push("qrc:/Forms/EventForm.qml") - } - } - } - - ItemDelegate { - text: qsTr("Speiseplan") - width: parent.width - onClicked: { - busyDialog.open() - var ret = _cppServerConn.getFoodPlan(); - drawer.close() - busyDialog.close() - if(ret === 200 || _cppServerConn.getFoodPlanData(1).cookteam !== ""){ - stackView.push("qrc:/FoodPlanForm.qml") - } - } - } - - ItemDelegate { - Label { - text: "abmelden" - color: "red" - anchors { - verticalCenter: parent.verticalCenter - left: parent.left - leftMargin: 17 - } - - font.bold: true - } - width: parent.width - - onClicked: { - confirmationDialog.open() - } - - Dialog { - id: confirmationDialog - - x: (window.width - width) / 2 - y: (window.height - height) / 2 - parent: ApplicationWindow.overlay - - - modal: true - standardButtons: Dialog.Cancel | Dialog.Ok - Column { - spacing: 20 - anchors.fill: parent - Label { - text: "Möchtest du dich wirklich abmelden?" - } - } - onAccepted: { - _cppServerConn.logout() - drawer.close() - root.StackView.view.push("qrc:/LoginPage.qml") - } - } - } - } - } - - StackView { - id: stackView - initialItem: "qrc:/Forms/HomeForm.qml" - anchors.fill: parent - } - - Dialog { - id: busyDialog - modal: true - focus: true - //title: "Please wait..." - x: (window.width - width) / 2 - y: window.height / 6 - //width: Math.min(window.width, window.height) / 3 * 2 - height: contentHeight * 1.5 - width: contentWidth * 1.5 - contentHeight: progressCircle.height - contentWidth: progressCircle.width - ProgressCircle { - id: progressCircle - size: 50 - lineWidth: 5 - anchors.centerIn: parent - colorCircle: "#FF3333" - colorBackground: "#E6E6E6" - showBackground: true - arcBegin: 0 - arcEnd: 0 - Label { - id: progress - anchors.centerIn: parent - text: "0%" - } - Timer { - id: refreshTimer - interval: 1; - running: busyDialog.visible - repeat: true - onTriggered: { - var ret = _cppServerConn.getProgress() - if(ret > 100 || ret < 0){ - ret = 0 - } - - progress.text = Math.round( ret * 100 ) + "%" - progressCircle.arcEnd = 360 * ret - } - } - } + ] } } diff --git a/qml/Pages/StartPage.qml b/qml/Pages/StartPage.qml deleted file mode 100644 index 2d6d285..0000000 --- a/qml/Pages/StartPage.qml +++ /dev/null @@ -1,179 +0,0 @@ -import QtQuick 2.9 -import QtQuick.Controls 2.4 -import QtGraphicalEffects 1.0 - -import "../Components" -import "../Forms" - -Page { - id: root - objectName: "MainPage" - - Shortcut { - sequences: ["Esc", "Back"] - enabled: formStack.depth > 1 - onActivated: { - formStack.pop() - } - } - - StackView { - id: formStack - property var currPage - property string eventDay: "" - - anchors { - top: toolBar.bottom - left: parent.left - right: parent.right - bottom: parent.bottom - } - - onCurrPageChanged: { - mainStack.replace(currPage) - } - - onCurrentItemChanged: { - formStack.currentItem.opened() - } - - initialItem: homeForm - - Component { - id: homeForm - HomeForm {} - } - - Component { - id: foodPlanForm - FoodPlanForm {} - } - - Component { - id: eventForm - EventForm { - day: formStack.eventDay - } - } - - popEnter: Transition { - XAnimator { - from: (formStack.mirrored ? -1 : 1) * -formStack.width - to: 0 - duration: 500 - easing.type: Easing.OutCubic - } - } - - popExit: Transition { - XAnimator { - from: 0 - to: (formStack.mirrored ? -1 : 1) * formStack.width - duration: 500 - easing.type: Easing.OutCubic - } - } - - pushEnter: Transition { - XAnimator { - from: (formStack.mirrored ? -1 : 1) * formStack.width - to: 0 - duration: 500 - easing.type: Easing.OutCubic - } - } - - pushExit: Transition { - XAnimator { - from: 0 - to: (formStack.mirrored ? -1 : 1) * -formStack.width - duration: 500 - easing.type: Easing.OutCubic - } - } - } - - AppToolBar { - id: toolBar - - anchors { - top: parent.top - left: parent.left - right: parent.right - topMargin: -60 - } - - height: 50 - - Button { - id:toolButton - enabled: true - anchors { - left: parent.left - verticalCenter: parent.verticalCenter - leftMargin: parent.width *0.02 - } - height: parent.height - parent.height * 0.5 - width: height - - onClicked: { - if (formStack.depth > 1) { - formStack.pop() - } else { - drawer.open() - } - } - - onPressed: toolButton.scale = 0.9 - onReleased: toolButton.scale = 1.0 - - background: Image { - source: formStack.depth > 1 ? "qrc:/graphics/icons/backDark.png" : "qrc:/graphics/icons/drawer.png" - height: parent.height - width: parent.width - Behavior on scale { - PropertyAnimation { - duration: 100 - } - } - } - } - - Label { - text: formStack.currentItem.title - anchors { - verticalCenter: parent.verticalCenter - left: toolButton.right - leftMargin: parent.width * 0.02 - } - font.bold: true - color: "black" - } - - Behavior on anchors.topMargin { - NumberAnimation { - duration: 500 - easing.type: Easing.OutCubic - } - } - - states: [ - State { - name: "closed" - when: formStack.depth === 1 - PropertyChanges { - target: toolBar - anchors.topMargin: -60 - } - }, - State { - name: "open" - when: formStack.depth > 1 - PropertyChanges { - target: toolBar - anchors.topMargin: 0 - } - } - ] - } -} diff --git a/qml/main.qml b/qml/main.qml index 0ba2149..dee4499 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -40,7 +40,7 @@ ApplicationWindow { name: "loggedIn" PropertyChanges { target: mainStack - currPage: startPage + currPage: mainPage } } ] @@ -131,8 +131,8 @@ ApplicationWindow { } Component { - id: startPage - StartPage {} + id: mainPage + MainPage {} } } @@ -175,6 +175,42 @@ ApplicationWindow { } } + function getErrorInfo(errorCode) { + + var infoLevel + var errorString + var errorDescription + + switch(errorCode) { + case 0: + infoLevel = 2 + errorString = "Keine Verbindung zum Server" + errorDescription = "Bitte überprüfe deine Internetverbindung und versuche es erneut." + break + case 500: + infoLevel = 2 + errorString = "Interner Server Fehler" + errorDescription = "Scheinbar kann der Server die Anfrage im Moment nicht verarbeiten, bitte versuche es später erneut." + break + case 900: + infoLevel = 2 + errorString = "Interner Verarbeitungsfehler" + errorDescription = "Die Daten, die vom Server übertragen wurden, konnten nicht richtig verarbeitet werden, bitte versuche es später erneut." + break + case 901: + infoLevel = 1 + errorString = "Keine Daten" + errorDescription = "Es liegen keine aktuellen Daten vor." + break + default: + infoLevel = 2 + errorString = "Unerwarteter Fehler ("+errorCode+")" + errorDescription = "Unbekannter Fehler bei der Verbindung mit dem Server." + } + + return([infoLevel, errorString, errorDescription]) + } + function landscape(){ return(app.width > app.height) } diff --git a/qml/qml.qrc b/qml/qml.qrc index 0066fb6..5a12ddc 100644 --- a/qml/qml.qrc +++ b/qml/qml.qrc @@ -1,19 +1,17 @@ main.qml - Forms/HomeForm[old].qml Pages/LoginPage.qml - Pages/MainPage.qml Components/AppToolBar.qml - Forms/WebsiteForm.qml Forms/FoodPlanForm.qml Components/ProgressCircle.qml Forms/EventForm.qml - Pages/StartPage.qml + Pages/MainPage.qml Components/FancyButton.qml Forms/HomeForm.qml Components/FoodPlanDisplay.qml Forms/LoadingForm.qml Components/EventDisplay.qml + Components/InfoArea.qml diff --git a/sources/eventform.cpp b/sources/eventform.cpp deleted file mode 100644 index 820703a..0000000 --- a/sources/eventform.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "headers/eventform.h" - -EventForm::EventForm(QObject *parent) : QObject(parent) -{ - -} diff --git a/sources/foodplanmodel.cpp b/sources/foodplanmodel.cpp new file mode 100644 index 0000000..ed30932 --- /dev/null +++ b/sources/foodplanmodel.cpp @@ -0,0 +1,59 @@ +#include "headers/foodplanmodel.h" + +FoodPlanModel::FoodPlanModel(QObject *parent) : QAbstractListModel(parent) +{ + //m_foodPlan.append({ "Angel Hogan", "Chapel St. 368 ", "Clearwater" , "0311 1823993", "uhj", "iuij" }); + qDebug() << "foodplan Konstructor"; + + m_foodPlan.clear(); + foreach(QListday, pGlobalServConn->m_weekplan){ + m_foodPlan.append({day[0], day[1], day[2], day[3], day[4], day[5]}); + } + + qDebug() << "end1"; + //qDebug() << pGlobalServConn->m_weekplan; +} + +int FoodPlanModel::rowCount(const QModelIndex &) const +{ + return m_foodPlan.count(); +} + +QVariant FoodPlanModel::data(const QModelIndex &index, int role) const +{ + if (index.row() < rowCount()) + switch (role) { + case CookteamRole: return m_foodPlan.at(index.row()).cookteam; + case DateRole: return m_foodPlan.at(index.row()).date; + case MainDishRole: return m_foodPlan.at(index.row()).mainDish; + case MainDishVegRole: return m_foodPlan.at(index.row()).mainDishVeg; + case GarnishRole: return m_foodPlan.at(index.row()).garnish; + case DessertRole: return m_foodPlan.at(index.row()).dessert; + default: return QVariant(); + } + return QVariant(); +} + +QHash FoodPlanModel::roleNames() const +{ + static const QHash roles { + { CookteamRole, "cookteam" }, + { DateRole, "date" }, + { MainDishRole, "mainDish" }, + { MainDishVegRole, "mainDishVeg" }, + { GarnishRole, "garnish" }, + { DessertRole, "dessert" } + }; + return roles; +} + +QVariantMap FoodPlanModel::get(int row) const +{ + const Dish foodPlan = m_foodPlan.value(row); + return { {"cookteam", foodPlan.cookteam}, {"date", foodPlan.date}, {"mainDish", foodPlan.mainDish}, {"mainDishVeg", foodPlan.mainDishVeg}, {"garnish", foodPlan.garnish}, {"dessert", foodPlan.dessert} }; +} + +FoodPlanModel::~FoodPlanModel(){ + +} + diff --git a/sources/main.cpp b/sources/main.cpp index cefdea6..6fe72c8 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -13,24 +13,23 @@ #include #include #include -#include #include "headers/serverconn.h" #include "headers/appsettings.h" +#include "headers/foodplanmodel.h" int main(int argc, char *argv[]) { - ServerConn * pServerConn = new ServerConn; AppSettings * pAppSettings = new AppSettings(); pGlobalAppSettings = pAppSettings; + ServerConn * pServerConn = new ServerConn(); + //pGlobalServConn = pServerConn; QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); - //! [0] - QGuiApplication app(argc, argv); - QtWebView::initialize(); - //! [0] + qmlRegisterType("Backend", 1, 0, "FoodPlanModel"); QQuickStyle::setStyle("Material"); QQmlApplicationEngine engine; diff --git a/sources/serverconn.cpp b/sources/serverconn.cpp index 3485168..8b92e97 100644 --- a/sources/serverconn.cpp +++ b/sources/serverconn.cpp @@ -1,11 +1,13 @@ #include "headers/serverconn.h" +ServerConn * pGlobalServConn = nullptr; ServerConn::ServerConn(QObject *parent) : QObject(parent) { qDebug("serverconn konstruktor"); this->networkManager = new QNetworkAccessManager(); this->refreshNetworkManager = new QNetworkAccessManager(); + pGlobalServConn = this; } ServerConn::~ServerConn() @@ -285,14 +287,13 @@ int ServerConn::getFoodPlan() { this->progress = 0; ReturnData_t ret; //this is a custom type to store the returned data - // Call the webservice + // Call the webservice QNetworkRequest request(QUrl("http://www.treffpunkt-fanny.de/fuer-schueler-und-lehrer/speiseplan.html")); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); - //set ssl configuration - //send a POST request with the given url and data to the server + // send a POST request with the given url and data to the server QNetworkReply* reply; QUrlQuery pdata; @@ -300,93 +301,224 @@ int ServerConn::getFoodPlan() connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateProgress(qint64, qint64))); - //wait until the request has finished + + // wait until the request has finished QEventLoop loop; + QTimer timer; + + timer.setSingleShot(true); + // quit the loop when the timer times out + loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit())); + timer.start(2000); loop.exec(); - //get the status code + // get the status code QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); this->progress = 1; if(status_code != 200){ return(status_code.toInt()); } - //initialize the weekplan to store information to it - //m_weekplan.empty(); //empty the weekplan + // initialize the weekplan to store information to it QList> temp_weekplan; - //m_weekplan is a list, that contains a list for each day, which contains: cookteam, date, main dish, vagi main dish, garnish(Beilage) and Dessert. + // m_weekplan is a list, that contains a list for each day, which contains: cookteam, date, main dish, vagi main dish, garnish(Beilage) and Dessert. - ret.text = QString::fromUtf8(reply->readAll()); //read the whole website - ret.text.replace("\n",""); //remove unnecessary stuff + // read the whole website + ret.text = QString::fromUtf8(reply->readAll()); + + // remove unnecessary stuff + ret.text.replace("\n",""); ret.text.replace("\r",""); ret.text.replace("\t",""); - ret.text.replace("style=\"width: 25%;\"", "width=\"25%\""); - QStringList stringlist_0 = ret.text.split( "" ); //split the + // workaround for changing html syntax + ret.text.replace("width=\"25%\"", "style=\"width: 25%;\""); - //prepare the table of the first week - QString table1 = stringlist_0[1]; + // split the string at the beginning of the tables + QStringList documentList = ret.text.split( "
" ); - QStringList stringlist_1 = table1.split( "
" ); //remove everything after "" - table1 = stringlist_1[0]; - table1.remove(0,71); //remove "" at the beginning - table1 = table1.left(table1.length() - 13); //remove "" at the end + // enshure that the data is valid + if(documentList.length() < 2){ + return(900); + } - QStringList table1list = table1.split(""); //split at the days to get a list of all days - table1list.takeFirst(); //remove the first item, as it is empty + //---------- prepare the table of the first week ---------- + QString table1 = documentList[1]; - //prepare the table of the second week - QString table2 = stringlist_0[2]; + // enshure that the data is valid + if(table1.split( "" ).length() < 1){ + return(900); + } - QStringList stringlist_2 = table2.split( "" ); //remove everything after "" - table2 = stringlist_2[0]; - table2.remove(0,39); //remove "" at the beginning - table2.remove(table2.length() - 13, table2.length()); //remove "" at the end + // remove everything after "" + table1 = table1.split( "" )[0]; + // remove "" at the beginning + table1.remove(0,71); + //remove "" at the end + table1 = table1.left(table1.length() - 13); - QStringList table2list = table2.split(""); //split at the days to get a list of all days - table2list.takeFirst(); //remove the first item, as it is empty + //split at the days to get a list of all days + QStringList table1list = table1.split(""); + // enshure that the data is valid + if(table1list.length() < 5){ + return(900); + } - QStringList weeklist = table1list + table2list; //put both weeks into one big list + //remove the first item, as it is empty + table1list.takeFirst(); + + //---------- prepare the table of the second week ---------- + QString table2 = documentList[2]; + + // enshure that the data is valid + if(table2.split( "" ).length() < 1){ + return(900); + } + + //remove everything after "" + table2 = table2.split( "" )[0]; + //remove "" at the beginning + table2.remove(0,39); + //remove "" at the end + table2.remove(table2.length() - 13, table2.length()); + + //split at the days to get a list of all days + QStringList table2list = table2.split(""); + + // enshure that the data is valid + if(table2list.length() < 5){ + return(900); + } + + //remove the first item, as it is empty + table2list.takeFirst(); + + //---------- put both weeks into one big list ---------- + QStringList weeklist = table1list + table2list; + + //---------- go through all days and split the day-string into the different types of information ---------- for (int i = 0; i <=7; i ++){ - QString temp = weeklist[i]; //store item temporarly to edit it - weeklist[i] = temp.left(temp.length()-5); //remove "" at the and of the Item - temp = weeklist[i]; - //table list[i] looks now like: - //Red Hot Chili Peppers - //
- //26.06.2018 - //
Gulasch mit Kartoffeln - //
Pellkartoffeln mit Quark - //
Gemischter Salat - //
Eaton Mess ( Erdbeer-Nachtisch ) - - QStringList templist = temp.split(""); //split item at strong, to get the cookteam and the date - //qDebug() << templist << "\n"; - temp = ""; - for (int i = 0; i <=2; i ++){ - temp += templist[i]; //convert the list to a big string + if(i > weeklist.length()){ + // if the loop exceeds the length of the wweklist some kind of eror occured + return 900; } - temp.replace("
",""); - templist = temp.split("
"); - temp_weekplan.append({templist[0], templist[1]}); //store cookteam and date - temp = templist[2]; //store information in temp (looks like: "
Gulasch mit Kartoffeln
Pellkartoffeln mit Quark
Gemischter Salat
Eaton Mess ( Erdbeer-Nachtisch )") - templist = temp.split("
"); //seperate the information - templist.takeFirst(); //remove first item + // store item temporarly to edit it + QString day = weeklist[i]; + // remove "" at the and of the Item + day = day.left(day.length()-5); - temp_weekplan[i].append(templist); + // table list[i] looks now like: | clould be: + // cookteam | Red Hot Chili Peppers + //
|
+ // date | 26.06.2018 + //
mainDish |
Gulasch mit Kartoffeln + //
mainDishVeg |
Pellkartoffeln mit Quark + //
garnish |
Gemischter Salat + //
dessert |
Eaton Mess ( Erdbeer-Nachtisch ) + // split item at strong, to get the cookteam and the date + QStringList daylist = day.split(""); + day = ""; + + // convert the list to a big string + for (int i = 0; i <= 2; i ++){ + if(i <= daylist.length()){ + day += daylist[i]; + } + } + + day.replace("
",""); + daylist = day.split("
"); + + // store cookteam and date in the temp_weekplan + //temp_weekplan.append({daylist[0], daylist[1]}); + + // store information in day + // (looks like: "
MainDish
MainDishVeg
Garnish
Dessert") + // (could be: "
Gulasch mit Kartoffeln
Pellkartoffeln mit Quark
Gemischter Salat
Eaton Mess ( Erdbeer-Nachtisch )") + day = daylist.takeLast(); + // seperate the information + daylist.append(day.split("
")); + // remove the item that is emplty from the list + daylist.removeAt(2); + + //---------- check if the day is aleady over ---------- + + // get the datestring + QString dateString = daylist[1]; + // convert it to a valid QDate + QDateTime date = QDateTime::fromString(dateString,"dd.MM.yyyy"); + + // get the current date and time + QDateTime currentDateTime = QDateTime::currentDateTimeUtc(); + + // check if the given day is still in the future or today (then it is valid) + if(date.toTime_t() > currentDateTime.toTime_t() || date.date() == currentDateTime.date()){ + // add the rest of the information to the temp_weekplan + qDebug() << "day valid:" << daylist; + + //---------- convert the date to a readable string ---------- + QString readableDateString; + + if(date.date() == currentDateTime.date()){ + // the given day is today + readableDateString = "Heute"; + } + else if (date.toTime_t() < ( currentDateTime.toTime_t() + ( 24 * 60 * 60 ))) { + // the given day is tomorrow + readableDateString = "Morgen"; + } + else { + readableDateString = date.toString("dddd, d.M.yy"); + } + + qDebug() << readableDateString; + + // insert the redable tring into the daylist + daylist[1] = readableDateString; + + // append the day to the weeklist + temp_weekplan.append({daylist[0], daylist[1], daylist[2], daylist[3], daylist[4], daylist[5]}); + } + /* + function getDateString(index){ + var date = _cppServerConn.getFoodPlanData(index).date + console.log(date.getTime()) + console.log(today.getTime()) + if(date.getDate() === today.getDate()){ + return("Heute") + } + else if(date.getTime() < (today.getTime() + (24 * 60 * 60 * 1000) )){ + return("Morgen") + } + else { + return(Qt.formatDateTime(_cppServerConn.getFoodPlanData(index).date, "dddd, d.M.yy")) + } + + } + function isDayVisible(index){ + var date = _cppServerConn.getFoodPlanData(index).date + // console.warn(date.getTime()) + // console.warn(today.getTime()) + // console.log("") + return( date.getTime() > today.getTime() || date.getDate() === today.getDate()) + } + } + } + */ } //qDebug() << temp_weekplan; - - this->m_weekplan = temp_weekplan; //write changes to global foodplan - qDebug() << temp_weekplan; + + if(this->m_weekplan.isEmpty()){ + return(901); + } return(200); } @@ -395,30 +527,29 @@ QVariantMap ServerConn::getFoodPlanData(int index) { //cookteam, date, main dish, vagi main dish, garnish(Beilage) and Dessert. - QStringList ret; //list to return - //qDebug() << index; - for(int i=0;i<=5;i++){ +// QStringList ret; //list to return +// //qDebug() << index; +// for(int i=0;i<=5;i++){ + +// if(m_weekplan.size() > index){ +// //qDebug() << i << m_weekplan[index].size(); +// if(m_weekplan[index].size() > i){ +// ret.append(m_weekplan[index][i]); +// //qDebug() << i << m_weekplan[index][i]; +// } +// else { +// ret.append(nullptr); +// } +// } +// else { +// ret.append(nullptr); +// } +// } - if(m_weekplan.size() > index){ - //qDebug() << i << m_weekplan[index].size(); - if(m_weekplan[index].size() > i){ - ret.append(m_weekplan[index][i]); - //qDebug() << i << m_weekplan[index][i]; - } - else { - ret.append(nullptr); - } - } - else { - ret.append(nullptr); - } - } - QString date_string_on_db = ret[1]; - QDate Date = QDate::fromString(date_string_on_db,"dd.MM.yyyy"); //date_string_on_db - qDebug() << Date; - qDebug() << ret; - return { {"cookteam", ret[0]}, {"date", Date}, {"main_dish", ret[2]}, {"main_dish_veg", ret[3]}, {"garnish", ret[4]}, {"dessert", ret[5]} }; + //qDebug() << Date; + //qDebug() << ret; + //return { {"cookteam", ret[0]}, {"date", Date}, {"main_dish", ret[2]}, {"main_dish_veg", ret[3]}, {"bgarnish", ret[4]}, {"dessert", ret[5]} }; }