2019-05-11 15:21:43 +02:00
|
|
|
/*
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-04-27 22:48:06 +02:00
|
|
|
import QtQuick 2.9
|
2019-04-20 22:57:40 +02:00
|
|
|
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
|
|
|
|
|
2019-04-22 12:38:23 +02:00
|
|
|
property bool ready
|
2019-04-20 22:57:40 +02:00
|
|
|
property int status: -1
|
|
|
|
|
|
|
|
property bool debug: true
|
|
|
|
|
|
|
|
property int comId: -1
|
|
|
|
property int catId: -1
|
2019-04-22 12:38:23 +02:00
|
|
|
property int catStatus: undefined
|
2019-04-20 22:57:40 +02:00
|
|
|
property int routeNumber: -2
|
2019-04-22 12:38:23 +02:00
|
|
|
|
2019-04-27 22:48:06 +02:00
|
|
|
property bool rak: catStatus === -1 // ranking (cup) data
|
2019-04-24 14:24:38 +02:00
|
|
|
property bool reg: catStatus === 4 || catStatus === undefined // registration data
|
2019-04-22 12:38:23 +02:00
|
|
|
property bool res: catStatus === 0 || catStatus === 1 // result data
|
|
|
|
property bool stl: catStatus === 2 || catStatus === 3 // startlist data
|
2019-04-20 22:57:40 +02:00
|
|
|
|
|
|
|
property var rankingData
|
|
|
|
|
|
|
|
property string listKey: root.reg ? "athletes":"participants"
|
|
|
|
property string compNameKey: root.reg ? "name":"comp_name"
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
2019-05-11 15:16:23 +02:00
|
|
|
loadingDl.open()
|
2019-04-27 22:48:06 +02:00
|
|
|
root.loadData(root.comId, root.catId, root.reg, root.rak, root.routeNumber)
|
2019-05-11 15:16:23 +02:00
|
|
|
loadingDl.close()
|
2019-04-20 22:57:40 +02:00
|
|
|
}
|
|
|
|
|
2019-04-27 22:48:06 +02:00
|
|
|
function loadData(comp, cat, reg, rak, route){
|
2019-04-22 12:38:23 +02:00
|
|
|
root.status = 905
|
2019-04-27 22:48:06 +02:00
|
|
|
console.log("[info][QML] getting ranking data of comp: " + comp + " , cat: " + cat + " and status: " + root.catStatus)
|
2019-05-11 15:16:23 +02:00
|
|
|
if(route === -1){
|
|
|
|
route = -2
|
|
|
|
}
|
|
|
|
|
2019-04-27 22:48:06 +02:00
|
|
|
var ret = serverConn.getRanking(comp, cat, reg, rak, route)
|
2019-04-20 22:57:40 +02:00
|
|
|
|
|
|
|
root.status = ret["status"]
|
|
|
|
|
|
|
|
if(parseInt(ret["status"]) === 200){
|
|
|
|
// request was successfull -> prepare data
|
|
|
|
if(root.reg){
|
2019-04-27 22:48:06 +02:00
|
|
|
// if the data is registration data, athletes of other cats need to be removed
|
2019-04-20 22:57:40 +02:00
|
|
|
|
|
|
|
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"]
|
|
|
|
}
|
2019-04-27 22:48:06 +02:00
|
|
|
else if(root.rak){
|
|
|
|
root.rankingData = ret["data"]
|
|
|
|
root.routeNumber = root.rankingData["route_order"] === undefined ? -2:root.rankingData["route_order"]
|
|
|
|
}
|
2019-04-20 22:57:40 +02:00
|
|
|
else {
|
|
|
|
root.rankingData = ret["data"]
|
|
|
|
root.routeNumber = root.rankingData["route_order"] === undefined ? -2:root.rankingData["route_order"]
|
|
|
|
}
|
|
|
|
}
|
2019-04-22 12:38:23 +02:00
|
|
|
else if(root.rankingData !== undefined){
|
|
|
|
root.status = 902
|
|
|
|
app.errorCode = 902
|
2019-04-20 22:57:40 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 14:24:38 +02:00
|
|
|
else if(root.status !== 200) {
|
2019-04-22 12:38:23 +02:00
|
|
|
root.ready = false
|
|
|
|
root.rankingData = {}
|
|
|
|
return false
|
2019-04-20 22:57:40 +02:00
|
|
|
}
|
|
|
|
|
2019-04-24 14:24:38 +02:00
|
|
|
if((ret["data"][ root.listKey ] === undefined || ret["data"][ root.listKey ].length < 1) && ( root.status === 200 || root.status === 404 ) ){
|
2019-04-27 22:48:06 +02:00
|
|
|
root.status = 901
|
|
|
|
root.ready = false
|
|
|
|
return false
|
|
|
|
}
|
2019-04-24 14:24:38 +02:00
|
|
|
|
2019-04-20 22:57:40 +02:00
|
|
|
console.log("done! status: " + root.status)
|
2019-04-22 12:38:23 +02:00
|
|
|
root.ready = true
|
|
|
|
return true
|
2019-04-20 22:57:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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"]
|
|
|
|
}
|
|
|
|
|
2019-04-22 12:38:23 +02:00
|
|
|
var addition = ""
|
|
|
|
|
|
|
|
if(root.reg) {
|
|
|
|
addition = "(Registration) "
|
|
|
|
}
|
|
|
|
else if(root.res) {
|
|
|
|
addition = "(Results) "
|
|
|
|
}
|
|
|
|
else if(root.stl) {
|
|
|
|
addition = "(Startlist) "
|
|
|
|
}
|
2019-04-27 22:48:06 +02:00
|
|
|
else if(root.rak) {
|
|
|
|
addition = "(Ranking) "
|
|
|
|
}
|
2019-04-22 12:38:23 +02:00
|
|
|
|
|
|
|
return addition + titleString
|
2019-04-20 22:57:40 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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:({})
|
|
|
|
|
2019-04-21 12:35:11 +02:00
|
|
|
onRefresh: {
|
2019-04-27 22:48:06 +02:00
|
|
|
root.loadData(root.comId, root.catId, root.reg, root.rak, root.routeNumber)
|
2019-04-21 12:35:11 +02:00
|
|
|
}
|
2019-04-20 22:57:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: rankItm
|
|
|
|
// item for ranking data
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
2019-04-22 12:38:23 +02:00
|
|
|
visible: root.res
|
2019-04-20 22:57:40 +02:00
|
|
|
|
2019-04-27 22:48:06 +02:00
|
|
|
ResultView {
|
2019-04-20 22:57:40 +02:00
|
|
|
id: rankViewRv
|
|
|
|
|
|
|
|
anchors {
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
top: parent.top
|
|
|
|
bottom: routeSelectTb.top
|
|
|
|
}
|
|
|
|
|
|
|
|
height: root.height - routeSelectTb.height
|
|
|
|
|
|
|
|
status: root.status
|
|
|
|
|
2019-04-27 22:48:06 +02:00
|
|
|
listData: root.res ? root.rankingData:({})
|
2019-04-20 22:57:40 +02:00
|
|
|
|
2019-04-21 12:35:11 +02:00
|
|
|
onRefresh: {
|
2019-04-27 22:48:06 +02:00
|
|
|
root.loadData(root.comId, root.catId, root.reg, root.rak, root.routeNumber)
|
2019-04-20 22:57:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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] + ")")
|
2019-05-11 15:16:23 +02:00
|
|
|
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()
|
|
|
|
|
2019-04-20 22:57:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-22 12:38:23 +02:00
|
|
|
|
|
|
|
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: {
|
2019-04-27 22:48:06 +02:00
|
|
|
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)
|
2019-04-22 12:38:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-20 22:57:40 +02:00
|
|
|
}
|