From 5f1c56bf8a793f4ae9a9ff94ac4f9934d6500fed Mon Sep 17 00:00:00 2001 From: dorian Date: Sun, 24 Jun 2018 21:56:40 +0200 Subject: [PATCH] =?UTF-8?q?Vollst=C3=A4ndiger=20Vertretungsplan=20support?= =?UTF-8?q?=20wurde=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android-sources/AndroidManifest.xml | 2 +- qml/FoodPlanForm.qml | 123 ++++++++++++++++++++++++---- qml/MainPage.qml | 10 +-- source/serverconn.cpp | 39 +++++---- 4 files changed, 133 insertions(+), 41 deletions(-) diff --git a/android-sources/AndroidManifest.xml b/android-sources/AndroidManifest.xml index e4fdc54..71ea905 100644 --- a/android-sources/AndroidManifest.xml +++ b/android-sources/AndroidManifest.xml @@ -1,5 +1,5 @@ - + diff --git a/qml/FoodPlanForm.qml b/qml/FoodPlanForm.qml index a9f3d07..276fb16 100644 --- a/qml/FoodPlanForm.qml +++ b/qml/FoodPlanForm.qml @@ -2,19 +2,21 @@ import QtQuick 2.9 import QtQuick.Controls 2.2 Page { + id:root anchors.fill: parent - + property bool cookplanChanged title: qsTr("Speiseplanplan") - property bool loaded: false + Timer { id: firstLoadTimer interval: 1; running: true repeat: false + onTriggered: { _cppServerConn.getFoodPlan() - loaded = true + cookplanChanged = true } } @@ -22,33 +24,124 @@ Page { anchors.fill: parent ListView { - enabled: loaded + id: listView width: parent.width model: 8 - delegate: ItemDelegate { + spacing: 5 + property var today: new Date + anchors { + right: parent.right + left: parent.left + top: parent.top + bottom: parent.bottom + leftMargin: 5 + rightMargin: 5 + } + + delegate: Button { //text: getText(index, "cookteam") width: parent.width + id: delegate + height: listView.isDayVisible(index) ? childrenRect.height + 10:0 + visible: listView.isDayVisible(index) + + //height: 150 + 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 } Label { anchors.left: parent.left - anchors.bottom: parent.bottom + anchors.leftMargin: 10 + anchors.top: cookteam.bottom + font.bold: true id: date - text: _cppServerConn.getFoodPlanData(index).date + text: listView.getDateString(index) + } + Rectangle { + anchors.top: date.bottom + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.right: parent.right + anchors.rightMargin: 10 + height: 1 + color: "grey" + } + + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: date.bottom + id: main_dish + text: _cppServerConn.getFoodPlanData(index).main_dish + } + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: main_dish.bottom + id: main_dish_veg + text: _cppServerConn.getFoodPlanData(index).main_dish_veg + } + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: main_dish_veg.bottom + id: garnish + text: _cppServerConn.getFoodPlanData(index).garnish + } + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: garnish.bottom + id: dessert + text: _cppServerConn.getFoodPlanData(index).dessert + } + +// Timer { +// id: reloadTimer +// interval: 10; +// running: cookplanChanged +// repeat: true +// onTriggered: { +// //var today = new Date + +// cookteam.text = _cppServerConn.getFoodPlanData(index).cookteam +// date.text = listView.getDateString(index) +// //_cppServerConn.getFoodPlanData(index).date +// main_dish.text = _cppServerConn.getFoodPlanData(index).main_dish +// main_dish_veg.text = _cppServerConn.getFoodPlanData(index).main_dish_veg +// garnish.text = _cppServerConn.getFoodPlanData(index).garnish +// dessert.text = _cppServerConn.getFoodPlanData(index).dessert +// if(index === 7) { +// cookplanChanged = false +// } +// } +// } + } + + function getDateString(index){ + var date = _cppServerConn.getFoodPlanData(index).date + //console.log(date) + if(date.getDate() === today.getDate()){ + return("Heute") + } + else if(date.getDate() === today.getDate() + 1 || (date.getDay() === 1 && today.getMonth() === date.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 + return( date.getDate() >= today.getDate() || date.getMonth() > today.getMonth()) + } } - - } - function getText(indexvar, type){ - if(!loaded){ - _cppServerConn.getFoodPlan() - loaded = true - } - //console.log(_cppServerConn.getFoodPlanData(indexvar)) } } diff --git a/qml/MainPage.qml b/qml/MainPage.qml index 8f3e874..2449c2c 100644 --- a/qml/MainPage.qml +++ b/qml/MainPage.qml @@ -26,15 +26,6 @@ Page { text: stackView.currentItem.title anchors.centerIn: parent } - Button { - id: butt - text: "load" - anchors.right: parent.right - visible: stackView.currentItem.title === "Speiseplanplan" - onClicked: { - var ret = _cppServerConn.getFoodPlan(); - } - } } Drawer { @@ -57,6 +48,7 @@ Page { text: qsTr("Speiseplan") width: parent.width onClicked: { + _cppServerConn.getFoodPlan(); stackView.push("FoodPlanForm.qml") drawer.close() } diff --git a/source/serverconn.cpp b/source/serverconn.cpp index 41ff037..16191d5 100644 --- a/source/serverconn.cpp +++ b/source/serverconn.cpp @@ -212,7 +212,9 @@ QString ServerConn::getFoodPlan() } //initialize the weekplan to store information to it - m_weekplan.empty(); //empty the weekplan + //m_weekplan.empty(); //empty the weekplan + 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. ret.text = QString::fromUtf8(reply->readAll()); //read the whole website @@ -224,11 +226,13 @@ QString ServerConn::getFoodPlan() //prepare the table of the first week QString table1 = stringlist_0[1]; + 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 - QStringList table1list = table1.split(""); //split at the days to get a list of all days + + 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 second week @@ -237,7 +241,7 @@ QString ServerConn::getFoodPlan() table2 = stringlist_2[0]; table2.remove(0,39); //remove "" at the beginning table2.remove(table2.length() - 13, table2.length()); //remove "" at the end - QStringList table2list = table2.split(""); //split at the days to get a list of all days + 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 @@ -267,37 +271,36 @@ QString ServerConn::getFoodPlan() temp.replace("
",""); templist = temp.split(""); - m_weekplan.append({templist[0], templist[1]}); //store cookteam and date + 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 - m_weekplan[i].append(templist); + temp_weekplan[i].append(templist); } - qDebug() << m_weekplan; + qDebug() << temp_weekplan; + this->m_weekplan = temp_weekplan; + + return(""); } QVariantMap ServerConn::getFoodPlanData(int index) { //cookteam, date, main dish, vagi main dish, garnish(Beilage) and Dessert. - QString cookteam; - QString date; - QString main_dish; - QString main_dish_veg; - QString garnish; - QString Dessert; QStringList ret; //list to return - qDebug() << index; + //qDebug() << index; for(int i=0;i<=5;i++){ - qDebug() << i << m_weekplan.size(); + if(m_weekplan.size() > index){ - if(m_weekplan.at(index).size() > i){ + //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(NULL); @@ -307,7 +310,11 @@ QVariantMap ServerConn::getFoodPlanData(int index) ret.append(NULL); } } - return { {"cookteam", ret[0]}, {"date", ret[1]}, {"main", ret[2]}, {"main_veg", ret[3]}, {"garnish", ret[4]}, {"dessert", ret[5]} }; + QString date_string_on_db = ret[1]; + QDate Date = QDate::fromString(date_string_on_db," dd.MM.yyyy"); +//date_string_on_db + //qDebug() << Date; + return { {"cookteam", ret[0]}, {"date", Date}, {"main_dish", ret[2]}, {"main_dish_veg", ret[3]}, {"garnish", ret[4]}, {"dessert", ret[5]} }; }