import QtQuick 2.0 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 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: catStatus === 4 || catStatus === undefined // registration data property bool res: catStatus === 0 || catStatus === 1 // result data property bool stl: catStatus === 2 || catStatus === 3 // startlist data property var rankingData property string listKey: root.reg ? "athletes":"participants" property string compNameKey: root.reg ? "name":"comp_name" Component.onCompleted: { root.loadData(root.comId, root.catId, root.reg, root.routeNumber) } function loadData(comp, cat, reg, route){ 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) root.status = ret["status"] if(parseInt(ret["status"]) === 200){ // request was successfull -> prepare data if(root.reg){ // if the data i sregistration 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 { 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 = {} loadingDl.close() 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 loadingDl.close() return false } console.log("done! status: " + root.status) root.ready = true loadingDl.close() 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) " } 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.routeNumber) } } } Item { id: rankItm // item for ranking data anchors.fill: parent visible: root.res RankingView { 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.reg ? ({}):root.rankingData onRefresh: { root.loadData(root.comId, root.catId, root.reg, 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 !== routeSelectTb.tabs[index][0]){ root.routeNumber = routeSelectTb.tabs[index][0] root.loadData(root.comId, root.catId, root.reg, root.routeNumber) } } } } } } 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) } } } }