From 4971d6e9b1c4d96dd0d3ee3aae430c56d1c4e95b Mon Sep 17 00:00:00 2001 From: dorian Date: Mon, 22 Apr 2019 12:38:23 +0200 Subject: [PATCH] - startlists are now supported - displaying errors at the top bar instead of the whole screen --- resources/qml/Components/AppToolBar.qml | 108 +++++++++--------- resources/qml/Components/DataListView.qml | 2 +- resources/qml/Components/RankingView.qml | 6 +- resources/qml/Components/RegistrationView.qml | 18 ++- resources/qml/Components/StartlistView.qml | 70 +++++++++++- .../qml/Pages/CompetitionCalendarPage.qml | 37 ++++-- resources/qml/Pages/RankingPage.qml | 69 +++++++++-- resources/qml/main.qml | 63 +++++++--- resources/qml/qml.qrc | 1 + 9 files changed, 286 insertions(+), 88 deletions(-) diff --git a/resources/qml/Components/AppToolBar.qml b/resources/qml/Components/AppToolBar.qml index 4aeab97..ba9b2d1 100644 --- a/resources/qml/Components/AppToolBar.qml +++ b/resources/qml/Components/AppToolBar.qml @@ -22,73 +22,73 @@ Item { color: "white" anchors.fill: parent - -// anchors { -// top: parent.top -// left: parent.left -// right: parent.right -// topMargin: -60 -// } - Rectangle { id: errorField + + property int errorCode: app.errorCode + + onErrorCodeChanged: { + console.log("new error code: " + errorCode) + if(!([-1, 200, 905].indexOf(app.errorCode) >= 0) && control.showErrorBar){ + animateErrorBar.start() + } + } + width: parent.width - height: 30 - enabled: app.is_error & app.state !== "notLoggedIn" & control.showErrorBar + height: 0 anchors.top: parent.bottom - color: "red" - onEnabledChanged: { - if(enabled){ - toolBar.state = 'moveIn' + color: app.getErrorInfo(errorCode)[0] > 0 ? app.getErrorInfo(errorCode)[0] > 1 ? "red":"grey" : "green" + + SequentialAnimation { + id: animateErrorBar + + NumberAnimation { + target: errorField + property: "height" + duration: 200 + from: 0 + to: 30 + easing.type: Easing.InOutQuad } - else { - toolBar.state = 'moveOut' + + + PauseAnimation { + duration: 1300 + } + + NumberAnimation { + target: errorField + property: "height" + duration: 200 + from: 30 + to: 0 + easing.type: Easing.InOutQuad + } + + onRunningChanged: { + if(!running){ + app.errorCode = -1 + } } } - MouseArea { anchors.fill: parent; onClicked: { - toolBar.state = 'moveOut' - - console.log("clicked") - } - } - - Text { - anchors { - horizontalCenter: parent.horizontalCenter - verticalCenter: parent.verticalCenter - } - + Label { id: errorText - font.family: "Helvetica" + + anchors.fill: parent + color: "White" - font.pointSize: 8 + + font.pixelSize: height * 0.5 + + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + visible: parent.height !== 0 - text: "" + + text: app.getErrorInfo(errorField.errorCode)[1] } } - - states: [ - State { - name: "moveOut" - PropertyChanges { target: errorField; height: 0 } - }, - State { - name: "moveIn" - PropertyChanges { target: errorField; height: 30 } - } - ] - - transitions: [ - Transition { - to: "moveOut" - NumberAnimation { properties: "height"; easing.type: Easing.InOutQuad; duration: 200 } - }, - Transition { - to: "moveIn" - NumberAnimation { properties: "height"; easing.type: Easing.InOutQuad; duration: 200 } - } - ] } } diff --git a/resources/qml/Components/DataListView.qml b/resources/qml/Components/DataListView.qml index 1cfbd45..8fff3a3 100644 --- a/resources/qml/Components/DataListView.qml +++ b/resources/qml/Components/DataListView.qml @@ -12,7 +12,7 @@ ListView { anchors.rightMargin: 14 - enabled: status === 200 + enabled: status === 200 || status === 902 opacity: enabled ? 1:0 diff --git a/resources/qml/Components/RankingView.qml b/resources/qml/Components/RankingView.qml index c563592..aa8020e 100644 --- a/resources/qml/Components/RankingView.qml +++ b/resources/qml/Components/RankingView.qml @@ -77,7 +77,10 @@ DataListView { fontSizeMode: Text.Fit font.bold: false font.pixelSize: Math.abs( partDelSecondRow.height > 0 ? height * 0.4:height * 0.3 ) - minimumPixelSize: 0 + minimumPixelSize: height * 0.3 + + elide: "ElideRight" + verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter @@ -116,6 +119,7 @@ DataListView { if( resultString !== undefined){ resultString = resultString.replace("t", "") resultString = resultString.replace("z", "") + resultString = resultString.replace("b", "") resultList = resultString.split(" ") } diff --git a/resources/qml/Components/RegistrationView.qml b/resources/qml/Components/RegistrationView.qml index b2aab09..e69921f 100644 --- a/resources/qml/Components/RegistrationView.qml +++ b/resources/qml/Components/RegistrationView.qml @@ -13,7 +13,23 @@ DataListView { width: parent.width - text: control.getText(index) + text: "" + + Label { + anchors.fill: parent + anchors.leftMargin: width * 0.05 + + verticalAlignment: Text.AlignVCenter + + fontSizeMode: Text.Fit + font.bold: true + font.pixelSize: Math.abs( height * 0.4 ) + minimumPixelSize: height * 0.3 + + elide: "ElideRight" + + text: control.getText(index) + } } function getText(index){ diff --git a/resources/qml/Components/StartlistView.qml b/resources/qml/Components/StartlistView.qml index 9c36e13..9a7b22b 100644 --- a/resources/qml/Components/StartlistView.qml +++ b/resources/qml/Components/StartlistView.qml @@ -1,5 +1,73 @@ import QtQuick 2.0 +import QtQuick.Controls 2.4 -Item { +DataListView { + id: control + property var listData: ({}) + + model: listData[ root.listKey ] === undefined ? 0:listData[ root.listKey ].length + + delegate: ItemDelegate { + id: partDel + + width: parent.width + + text: "" + + Row { + id: partDelFirstRow + + width: parent.width + height: parent.height + + Label { + height: parent.height + width: parent.width * 0.1 + + fontSizeMode: Text.Fit + font.bold: true + font.pixelSize: Math.abs( height * 0.6 ) + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + + text: listData[ "participants" ][index]["start_order"] + } + + Label { + height: parent.height + width: parent.width * 0.4 + + fontSizeMode: Text.Fit + font.bold: true + font.pixelSize: Math.abs( height * 0.6 ) + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignLeft + + text: listData[ "participants" ][index]["firstname"] + " " + listData[ "participants" ][index]["lastname"] + } + + Label { + height: parent.height + width: parent.width * 0.5 + + fontSizeMode: Text.Fit + font.bold: false + font.pixelSize: Math.abs( height * 0.4 ) + minimumPixelSize: height * 0.3 + + elide: "ElideRight" + + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + + text: "(" + (listData[ "display_athlete" ] === "nation" ? listData[ "participants" ][index]["nation"] : listData[ "participants" ][index]["federation"]) + ")" + + onLinkActivated: { + Qt.openUrlExternally(link) + } + } + } + + } } diff --git a/resources/qml/Pages/CompetitionCalendarPage.qml b/resources/qml/Pages/CompetitionCalendarPage.qml index 6cca235..015a004 100644 --- a/resources/qml/Pages/CompetitionCalendarPage.qml +++ b/resources/qml/Pages/CompetitionCalendarPage.qml @@ -7,15 +7,18 @@ import "../Components" Page { id: root - title: "calendar" + title: (nation === "" ? "IFSC":nation === "GER" ? "DAV":"SAC") + " " + qsTr("competition calendar") + + property bool ready property Component headerComponent: Item { anchors.fill: parent Row { anchors.fill: parent + anchors.rightMargin: parent.width * 0.05 - spacing: width * 0.05 + spacing: anchors.rightMargin Label { anchors.verticalCenter: parent.verticalCenter @@ -25,6 +28,8 @@ Page { fontSizeMode: Text.Fit font.pixelSize: height + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignRight minimumPixelSize: 0 text: root.year @@ -72,13 +77,16 @@ Page { property var calendarData Component.onCompleted: { - loadData(root.nation, root.year) + root.ready = loadData(root.nation, root.year) } function loadData(nation, year) { - root.status = 905 loadingDl.open() + //console.log("loading calendar data and old data is: " + (root.calendarData !== undefined) + " because of: " + root.calendarData + " and: ") + + root.status = 905 + var ret = serverConn.getCalendar(nation, year) if(ret["status"] === 200){ @@ -86,12 +94,25 @@ Page { root.calendarData = ret["data"] calendarList.listData = ret["data"]["competitions"] } + else if (root.calendarData !== undefined ){ + // there is still old data available + root.status = 902 + //console.log("old data") + } else { root.status = parseInt(ret["status"]) - calendarList.listData = {} - root.calendarData = {} + app.errorCode = parseInt(ret["status"]) + root.calendarData = ({}) + calendarList.listData = ({}) + //console.log("error: " + root.status) + loadingDl.close() + app.errorCode = root.status + return false } + loadingDl.close() + app.errorCode = root.status + return true } DataListView { @@ -233,7 +254,7 @@ Page { onClicked: { catSelectPu.close() - app.openResults(calendarList.listData[catSelectPu.index]["WetId"], catSelectPu.catObj[index]["GrpId"], (catSelectPu.catObj[index]["status"] === 4 || catSelectPu.catObj[index]["status"] === undefined)) + app.openResults(calendarList.listData[catSelectPu.index]["WetId"], catSelectPu.catObj[index]["GrpId"], catSelectPu.catObj[index]["status"] ) } } } @@ -262,7 +283,7 @@ Page { width: parent.width height: root.height * 0.6 - model: yearSelectPu.yearList.length + model: yearSelectPu.yearList !== undefined ? yearSelectPu.yearList.length:0 delegate: Button { id: yearBt diff --git a/resources/qml/Pages/RankingPage.qml b/resources/qml/Pages/RankingPage.qml index 110a5b8..88e5c96 100644 --- a/resources/qml/Pages/RankingPage.qml +++ b/resources/qml/Pages/RankingPage.qml @@ -11,14 +11,19 @@ Page { property string subTitle: getSubtitle() property bool titleIsPageTitle: true + property bool ready property int status: -1 property bool debug: true property int comId: -1 property int catId: -1 + property int catStatus: undefined property int routeNumber: -2 - property bool reg: false + + property bool reg: catStatus === 4 || catStatus === undefied // registration data + property bool res: catStatus === 0 || catStatus === 1 // result data + property bool stl: catStatus === 2 || catStatus === 3 // startlist data property var rankingData @@ -30,8 +35,8 @@ Page { } function loadData(comp, cat, reg, route){ - root.status = 905 loadingDl.open() + root.status = 905 console.log("[info][QML] getting ranking data of comp: " + comp + " and cat: " + cat + " reg: " + reg) var ret = serverConn.getRanking(comp, cat, reg, route) @@ -59,17 +64,29 @@ Page { root.routeNumber = root.rankingData["route_order"] === undefined ? -2:root.rankingData["route_order"] } } - else { - root.rankingData = {} + else if(root.rankingData !== undefined){ + root.status = 902 + app.errorCode = 902 } - - if((ret["data"][ root.listKey ] === undefined || ret["data"][ root.listKey ].length < 1) && ( root.status === 200 || root.status === 404 ) ){ + else if((ret["data"][ root.listKey ] === undefined || ret["data"][ root.listKey ].length < 1) && ( root.status === 200 || root.status === 404 ) ){ root.status = 901 + root.ready = false + loadingDl.close() + return false + } + + else { + root.ready = false + root.rankingData = {} + loadingDl.close() + return false } console.log("done! status: " + root.status) + root.ready = true loadingDl.close() + return true } function getSubtitle() { @@ -89,7 +106,19 @@ Page { titleString = root.rankingData["route_name"] } - return titleString + var addition = "" + + if(root.reg) { + addition = "(Registration) " + } + else if(root.res) { + addition = "(Results) " + } + else if(root.stl) { + addition = "(Startlist) " + } + + return addition + titleString } @@ -122,7 +151,7 @@ Page { anchors.fill: parent - visible: !root.reg + visible: root.res RankingView { id: rankViewRv @@ -237,4 +266,28 @@ Page { } } } + + Item { + id: startlItm + // item for startlist data + + anchors.fill: parent + + visible: root.stl + + StartlistView { + id: stlViewRv + + anchors.fill: parent + + status: root.status + + listData: root.stl ? root.rankingData:({}) + + onRefresh: { + root.loadData(root.comId, root.catId, root.reg, root.routeNumber) + } + } + } + } diff --git a/resources/qml/main.qml b/resources/qml/main.qml index d69995a..ba5c306 100644 --- a/resources/qml/main.qml +++ b/resources/qml/main.qml @@ -16,6 +16,8 @@ Window { Page { id: app + property int errorCode: -1 + property var competitionCategoryColors: { "61": "lightgrey", "58": "lightgreen", @@ -49,6 +51,8 @@ Window { StackView { id: mainStack + enabled: !loadingDl.opened + anchors { top: toolBar.bottom left: parent.left @@ -107,11 +111,13 @@ Window { top: parent.top left: parent.left right: parent.right - topMargin: -60 + topMargin: -height } height: 50 + showErrorBar: true + Row { anchors.fill: parent @@ -163,14 +169,17 @@ Window { anchors.verticalCenter: parent.verticalCenter height: childrenRect.height - width: parent.width * 0.7 + width: parent.width - extraComponentLoader.width - toolButton.width - 3 * parent.spacing Label { id: toolBarTitleLa + width: parent.width + elide: "ElideRight" font.bold: true + verticalAlignment: Text.AlignVCenter color: "black" @@ -199,7 +208,8 @@ Window { Label { id: toolBarSubTitleLa - elide: "ElideRight" + width: parent.width + height: text !== "" ? undefined:0 font.bold: false @@ -224,7 +234,7 @@ Window { id: extraComponentLoader height: parent.height - width: parent.width * 0.2 - toolButton.width + width: status === Loader.Ready ? parent.width * 0.35 - toolButton.width - 3 * parent.spacing:0 anchors { top: parent.top @@ -249,7 +259,7 @@ Window { when: mainStack.depth === 1 PropertyChanges { target: toolBar - anchors.topMargin: -60 + anchors.topMargin: -height } }, State { @@ -294,19 +304,39 @@ Window { } function openCalendar(nation){ - loadingDl.open() - mainStack.push(Qt.createComponent("qrc:/Pages/CompetitionCalendarPage.qml").createObject(null, {"nation": nation})) - loadingDl.close() + //loadingDl.open() + + var calComp = Qt.createComponent("qrc:/Pages/CompetitionCalendarPage.qml").createObject(null, {"nation": nation}) + app.errorCode = calComp.status + if(calComp.ready){ + mainStack.push(calComp) + } + else { + delete(calComp) + } + + //loadingDl.close() } - function openResults(comp, cat, reg){ + function openResults(comp, cat, status){ // comp: (int) competiotion ID // cat: (int) category ID - // reg: (bool) false: results; true: registrations + // reg: (int) 0: result imported into ranking; 1: result-service result available; 2: result-service startlist available; 3: old non result-server startlist (no longer used); 4: starters / registration data - //loadingDl.open() - mainStack.push(Qt.createComponent("qrc:/Pages/RankingPage.qml").createObject(null, {"comId": comp, "catId": cat, "reg": reg})) - //loadingDl.close() + loadingDl.open() + + var rankComp = Qt.createComponent("qrc:/Pages/RankingPage.qml").createObject(null, {"comId": comp, "catId": cat, "catStatus": status}) + app.errorCode = rankComp.status + + if(rankComp.ready){ + mainStack.push(rankComp) + } + else { + delete(rankComp) + } + + + loadingDl.close() } function getErrorInfo(errorCode) { @@ -325,6 +355,11 @@ Window { errorString = "No connection to server" errorDescription = "Please check your internet connection and try again." break + case 200: + infoLevel = 0 + errorString = "Success" + errorDescription = "The request was successfull" + break case 401: infoLevel = 2 errorString = "Authentication required" @@ -347,7 +382,7 @@ Window { break case 902: infoLevel = 1 - errorString = "Alte Daten" + errorString = "Cached (old) data" errorDescription = "Es konnte keine Verbindung zum Server hergestellt werden, aber es sind noch alte Daten gespeichert." break case 903: diff --git a/resources/qml/qml.qrc b/resources/qml/qml.qrc index badc274..d6a5861 100644 --- a/resources/qml/qml.qrc +++ b/resources/qml/qml.qrc @@ -11,5 +11,6 @@ Components/DataListView.qml Components/RankingView.qml Components/RegistrationView.qml + Components/StartlistView.qml