From bcfc802932ae847db54f7b37630ad191237ca602 Mon Sep 17 00:00:00 2001 From: dorian Date: Sun, 23 Dec 2018 21:12:33 +0100 Subject: [PATCH] cleaned up code of foodplan --- headers/serverconn.h | 1 - sources/serverconn.cpp | 76 ++++++------------------------------------ 2 files changed, 11 insertions(+), 66 deletions(-) diff --git a/headers/serverconn.h b/headers/serverconn.h index cb268bc..b8028a0 100644 --- a/headers/serverconn.h +++ b/headers/serverconn.h @@ -42,7 +42,6 @@ public: Q_INVOKABLE int checkConn(); Q_INVOKABLE float getProgress(); Q_INVOKABLE int getFoodPlan(); - Q_INVOKABLE QVariantMap getFoodPlanData(int index); Q_INVOKABLE QVariantMap getEventData(int index); Q_INVOKABLE int getEvents(QString day); Q_INVOKABLE int getEventCount(); diff --git a/sources/serverconn.cpp b/sources/serverconn.cpp index 8b92e97..dc4c2b4 100644 --- a/sources/serverconn.cpp +++ b/sources/serverconn.cpp @@ -286,7 +286,6 @@ int ServerConn::getEvents(QString day){ int ServerConn::getFoodPlan() { this->progress = 0; - ReturnData_t ret; //this is a custom type to store the returned data // Call the webservice QNetworkRequest request(QUrl("http://www.treffpunkt-fanny.de/fuer-schueler-und-lehrer/speiseplan.html")); @@ -326,18 +325,18 @@ int ServerConn::getFoodPlan() // 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. // read the whole website - ret.text = QString::fromUtf8(reply->readAll()); + QString returnedData = QString::fromUtf8(reply->readAll()); // remove unnecessary stuff - ret.text.replace("\n",""); - ret.text.replace("\r",""); - ret.text.replace("\t",""); + returnedData.replace("\n",""); + returnedData.replace("\r",""); + returnedData.replace("\t",""); // workaround for changing html syntax - ret.text.replace("width=\"25%\"", "style=\"width: 25%;\""); + returnedData.replace("style=\"width: 25%;\"", "width=\"25%\""); // split the string at the beginning of the tables - QStringList documentList = ret.text.split( "" ); + QStringList documentList = returnedData.split( "
" ); // enshure that the data is valid if(documentList.length() < 2){ @@ -485,74 +484,21 @@ int ServerConn::getFoodPlan() // 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 + // write data to global foodplan + this->m_weekplan = temp_weekplan; + // check if there is any valid data if(this->m_weekplan.isEmpty()){ + // no data return(901); } + // success return(200); } -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++){ - -// 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); -// } -// } - - //date_string_on_db - //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]} }; - -} - QVariantMap ServerConn::getEventData(int index) { //cookteam, date, main dish, vagi main dish, garnish(Beilage) and Dessert.