/* blueROCK - for digital rock Copyright (C) 2019 Dorian Zedler This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.9 import QtQuick.Controls 2.4 import QtGraphicalEffects 1.0 import "../Components" Page { id: root title: root.rankingData[compNameKey] property string subTitle: getSubtitle() property bool titleIsPageTitle: true property Component headerComponent: Item { anchors.fill: parent Button { id: cupToolBt anchors { verticalCenter: parent.verticalCenter right: parent.right rightMargin: parent.width * 0.1 } height: parent.height * 0.5 width: height onClicked: { catSelectPu.appear() } onPressed: cupToolBt.scale = 0.9 onReleased: cupToolBt.scale = 1.0 background: Image { anchors.centerIn: parent source: "qrc:/icons/more_black.png" height: parent.height > parent.width ? parent.width : parent.height width: height mipmap: true fillMode: Image.PreserveAspectFit Behavior on scale { PropertyAnimation { duration: 100 } } } } } 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 rak: catStatus === -1 // ranking (cup) data property bool reg: catStatus === 4 || catStatus === undefined // registration data property bool res: catStatus === 0 || catStatus === 1 // result data property bool stl: catStatus === 2 || catStatus === 3 // startlist data /* enum DataType { RankingData, RegistrationData, ResultData, StartlistData }*/ property var rankingData property string listKey: root.reg ? "athletes":"participants" property string compNameKey: root.reg ? "name":"comp_name" Component.onCompleted: { loadingDl.open() root.loadData(root.comId, root.catId, root.reg, root.rak, root.routeNumber) loadingDl.close() } function loadData(comp, cat, reg, rak, route){ root.status = 905 console.log("[info][QML] getting ranking data of comp: " + comp + " , cat: " + cat + " and status: " + root.catStatus) if(route === -1){ route = -2 } var ret = serverConn.getRanking(comp, cat, reg, rak, route) root.status = ret["status"] console.log(root.status) if(parseInt(ret["status"]) === 200){ // request was successfull -> prepare data if(root.reg){ // if the data is registration data, athletes of other cats need to be removed /* var validAthletes = [] for(var i = 0; i < ret["data"]["athletes"].length; i++){ if(parseInt(ret["data"]["athletes"][i]["cat"]) === cat){ //console.log("found matching athlete at " + i) validAthletes.push(ret["data"]["athletes"][i]) } } ret["data"]["athletes"] = validAthletes*/ root.rankingData = ret["data"] } else if(root.rak){ root.rankingData = ret["data"] root.routeNumber = root.rankingData["route_order"] === undefined ? -2:root.rankingData["route_order"] } else { root.rankingData = ret["data"] root.routeNumber = root.rankingData["route_order"] === undefined ? -2:root.rankingData["route_order"] } } else if(root.rankingData !== undefined){ root.status = 902 app.errorCode = 902 } else if(root.status !== 200) { root.ready = false root.rankingData = {} return false } if((ret["data"][ root.listKey ] === undefined || ret["data"][ root.listKey ].length < 1) && ( root.status === 200 || root.status === 404 ) ){ root.status = 901 root.ready = false return false } console.log("done! status: " + root.status) root.ready = true return true } function getSubtitle() { var titleString //console.log("getting title, reg: " + root.reg) if(reg){ for(var i = 0; i < root.rankingData["categorys"].length; i ++ ){ //console.log("checking " + i + ": cat: " + parseInt(root.rankingData["categorys"][i]["GrpId"]) + " searched cat: " + root.catId) if(parseInt(root.rankingData["categorys"][i]["GrpId"]) === root.catId){ titleString = root.rankingData["categorys"][i]["name"] } } } else { titleString = root.rankingData["route_name"] } var addition = "" if(root.reg) { addition = "(Registration) " } else if(root.res) { addition = "(Results) " } else if(root.stl) { addition = "(Startlist) " } else if(root.rak) { addition = "(Ranking) " } return addition + titleString } Item { id: regItm // item for registration view anchors.fill: parent visible: root.reg RegistrationView { id: regViewRv anchors.fill: parent status: root.status listData: root.reg ? root.rankingData:({}) onRefresh: { root.loadData(root.comId, root.catId, root.reg, root.rak, root.routeNumber) } } } Item { id: rankItm // item for ranking data anchors.fill: parent visible: root.res ResultView { id: rankViewRv anchors { left: parent.left right: parent.right top: parent.top bottom: routeSelectTb.top } height: root.height - routeSelectTb.height status: root.status listData: root.res ? root.rankingData:({}) onRefresh: { root.loadData(root.comId, root.catId, root.reg, root.rak, root.routeNumber) } } RectangularGlow { id: toolBarEffect glowRadius: 3 spread: 0.2 color: "black" opacity: 0.3 anchors.fill: routeSelectTb } TabBar { id: routeSelectTb property var tabs: getTabs() property var tabIndexes: [] anchors { left: parent.left right: parent.right bottom: parent.bottom } height: tabs.length > 0 ? 50:0 position: TabBar.Footer Component.onCompleted: { //currentIndex = getIndex(root.routeNumber) setCurrentIndex(getIndex(root.routeNumber)) } function getTabs() { var obj = root.rankingData["route_names"] var buttonData = [] for(var prop in obj) { // go through the whole array and search for data keys if (obj.hasOwnProperty(prop)) { buttonData.push([prop, obj[prop]]) console.log("found " + obj[prop] + " at index " + prop) } } buttonData.sort(function(a, b) { return a[0] - b[0]; }); return buttonData } function getIndex(routeNumber) { console.log("getting index for route number: " + routeNumber) for(var i = 0; i < tabs.length; i++){ //console.log(tabs[i]) if(parseInt(tabs[i][0]) === routeNumber){ console.log("found index: " + i) return i } } return 0 } Repeater { id: routeSelectButtonRep model: routeSelectTb.tabs.length onModelChanged: { routeSelectTb.setCurrentIndex(routeSelectTb.getIndex(root.routeNumber)) } delegate: TabButton { text: routeSelectTb.tabs[index][1] width: Math.max(150, routeSelectTb.width / routeSelectButtonRep.model) //text.length * font.pixelSize onClicked: { console.log("changing to index: " + index + " (" + routeSelectTb.tabs[index][0] + ", " + routeSelectTb.tabs[index][1] + ")") if(root.routeNumber !== parseInt(routeSelectTb.tabs[index][0])){ loadingDl.open() if(root.loadData(root.comId, root.catId, root.reg, root.rak, routeSelectTb.tabs[index][0]) && root.status === 200){ root.routeNumber = routeSelectTb.tabs[index][0] } else { routeSelectTb.setCurrentIndex(routeSelectTb.getIndex(root.routeNumber)) } loadingDl.close() } } } } } } 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.rak, root.routeNumber) } } } Item { id: rankinglItm // item for startlist data anchors.fill: parent visible: root.rak RankingView { id: rankingRv anchors.fill: parent status: root.status listData: root.rak ? root.rankingData:({}) onRefresh: { root.loadData(root.comId, root.catId, root.reg, root.rak, root.routeNumber) } } } Dialog { id: catSelectPu property var catObj: undefined x: 0 //root.width / 2 - width / 2 y: root.height - height //root.height / 2 - height / 2 width: root.width height: catsLv.implicitHeight modal: true focus: true title: qsTr("select category") function appear() { var tmpCatObj tmpCatObj = root.rankingData["categorys"] tmpCatObj.sort(function(a, b) { return parseInt(a["GrpId"]) - parseInt(b["GrpId"]); }); catSelectPu.catObj = tmpCatObj catSelectPu.open() } function getText(index){ // ---------------------------- // get the text // returns list with [catId, catName] return [catSelectPu.catObj[index]["GrpId"], catSelectPu.catObj[index]["name"]] } ListView { id: catsLv property int delegateHeight: 50 anchors.fill: parent implicitWidth: parent.width implicitHeight: root.height * 0.6 < ( (delegateHeight + spacing) * model ) ? root.height * 0.6 : (delegateHeight + spacing) * model + 75 model: catSelectPu.catObj !== undefined ? catSelectPu.catObj.length:0 ScrollIndicator.vertical: ScrollIndicator { parent: catsLv.parent anchors { top: catsLv.top left: catsLv.right margins: 10 leftMargin: 3 bottom: catsLv.bottom } } delegate: Button { id: catBt property var catData: catSelectPu.getText(index) width: parent.width height: text !== "" ? catsLv.delegateHeight:0 flat: true text: catData[1] onClicked: { catSelectPu.close() root.catId = catData[0] root.loadData(root.comId, root.catId, root.reg, root.rak, root.routeNumber) } } } enter: Transition { NumberAnimation { property: "opacity"; from: 0.0; to: 1.0 } NumberAnimation { property: "y" from: root.height - catSelectPu.height * 0.7 to: root.height - catSelectPu.height } } exit: Transition { NumberAnimation { property: "opacity"; from: 1.0; to: 0.0 } NumberAnimation { property: "y" from: root.height - catSelectPu.height to: root.height - catSelectPu.height * 0.7 } } } }