2019-05-23 23:17:27 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.9
|
|
|
|
import QtQuick.Controls 2.4
|
|
|
|
|
|
|
|
import "../Components"
|
|
|
|
|
|
|
|
DataListView {
|
|
|
|
id: control
|
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
property bool ready
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
property string title: (params.nation === "" ? "IFSC":params.nation === "GER" ? "DAV":"SAC") + " " + qsTr("competition calendar") + " " + control.year
|
|
|
|
property Component headerComponent: Row {
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
anchors {
|
|
|
|
top: parent.top
|
|
|
|
bottom: parent.bottom
|
|
|
|
right: parent.right
|
|
|
|
rightMargin: 5
|
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
width: childrenRect.width
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
spacing: width * 0.1
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
Button {
|
|
|
|
id:yearToolBt
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
anchors {
|
|
|
|
verticalCenter: parent.verticalCenter
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
height: parent.height * 0.5
|
|
|
|
width: height
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
onClicked: {
|
|
|
|
control.changeYear()
|
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
onPressed: yearToolBt.scale = 0.9
|
|
|
|
onReleased: yearToolBt.scale = 1.0
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
background: Image {
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
anchors.centerIn: parent
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
source: "qrc:/icons/calendar.png"
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
height: parent.height > parent.width ? parent.width : parent.height
|
|
|
|
width: height
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
mipmap: true
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
Behavior on scale {
|
|
|
|
PropertyAnimation {
|
|
|
|
duration: 100
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-29 20:59:01 +02:00
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
Button {
|
|
|
|
id: cupToolBt
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
anchors {
|
|
|
|
verticalCenter: parent.verticalCenter
|
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
height: parent.height * 0.5
|
|
|
|
width: height
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
onClicked: {
|
|
|
|
control.openCup()
|
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
onPressed: cupToolBt.scale = 0.9
|
|
|
|
onReleased: cupToolBt.scale = 1.0
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
background: Image {
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
anchors.centerIn: parent
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
source: "qrc:/icons/cup.png"
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
height: parent.height > parent.width ? parent.width : parent.height
|
|
|
|
width: height
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
mipmap: true
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
Behavior on scale {
|
|
|
|
PropertyAnimation {
|
|
|
|
duration: 100
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-29 20:59:01 +02:00
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
Item {
|
|
|
|
id: spacer
|
|
|
|
height: parent.height
|
|
|
|
width: 1
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
2019-05-29 20:59:01 +02:00
|
|
|
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
property var widgetData: currentWidgetData
|
2019-05-23 23:17:27 +02:00
|
|
|
|
|
|
|
property int year: new Date().getFullYear()
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
//boundsBehavior: Flickable.StopAtBounds
|
|
|
|
|
|
|
|
model: widgetData["competitions"].length
|
|
|
|
|
|
|
|
onRefresh: {
|
|
|
|
updateData({}, false)
|
|
|
|
}
|
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
Component.onCompleted: {
|
|
|
|
if(model > 0){
|
|
|
|
control.ready = true
|
|
|
|
control.status = 200
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
control.ready = false
|
|
|
|
control.status = 901
|
|
|
|
}
|
|
|
|
|
2019-05-23 23:17:27 +02:00
|
|
|
autoScroll()
|
|
|
|
|
2019-05-24 14:15:07 +02:00
|
|
|
// if the IFSC Calendar is open -> add the worldranking
|
|
|
|
if(params.nation === ""){
|
|
|
|
control.widgetData['cups'].unshift({"SerId":"","rkey":"","name":"Worldranking","modified":"2018-10-24 16:11:12","modifier":"","year":"","num_comps":"","cats":["ICC-COA","ICC-HD","ICC-MED","ICC_F","ICC_FB","ICC_FS","ICC_M","ICC_MB","ICC_MS"]})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 23:17:27 +02:00
|
|
|
function autoScroll() {
|
2019-05-29 20:59:01 +02:00
|
|
|
// function to scroll to the next competition that is not already over
|
2019-05-23 23:17:27 +02:00
|
|
|
var compList = control.widgetData["competitions"]
|
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
console.log("scrolling")
|
|
|
|
|
2019-05-23 23:17:27 +02:00
|
|
|
if(parseInt(control.year) === new Date().getFullYear()){
|
|
|
|
for(var i = 0; i < compList.length; i ++){
|
|
|
|
// get the start date pf the competition
|
|
|
|
var startDate = Date.fromLocaleString(Qt.locale(), compList[i]["date"], "yyyy-MM-dd")
|
|
|
|
|
|
|
|
// get the duration of the competition
|
|
|
|
var durationString = compList[i]["duration"] === undefined ? "1":compList[i]["duration"]
|
|
|
|
var days = parseInt(durationString.replace(/\D/g,''))
|
|
|
|
// calculate the end date of the competition
|
|
|
|
var endDate = new Date(startDate.valueOf())
|
|
|
|
endDate.setDate(endDate.getDate() + days);
|
|
|
|
|
|
|
|
//console.log(compList[i]["date"] + ": " + startDate + " to " + endDate)
|
|
|
|
|
|
|
|
if(endDate.getTime() < new Date().getTime()){
|
|
|
|
// end date is already over -> move the list view down!
|
|
|
|
control.positionViewAtIndex(i, ListView.Top)
|
|
|
|
//console.log("moving down!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-29 20:59:01 +02:00
|
|
|
else {
|
|
|
|
//console.log("not current year")
|
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getCompCatData(compCatId) {
|
|
|
|
var obj = app.compCats
|
|
|
|
|
|
|
|
for(var prop in obj) {
|
|
|
|
// go through the whole array and search for data keys
|
|
|
|
if (obj.hasOwnProperty(prop) && obj[prop]["cat_id"].indexOf(compCatId) >= 0) {
|
|
|
|
//console.log("found cat: " + obj[prop]['label'])
|
|
|
|
return obj[prop]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function openComp(compIndex){
|
|
|
|
var cats = control.widgetData["competitions"][compIndex]["cats"]
|
|
|
|
|
|
|
|
cats.sort(function(a, b) {
|
|
|
|
return parseInt(a["GrpId"]) - parseInt(b["GrpId"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
var selectOptions = []
|
|
|
|
|
|
|
|
for(var prop in cats){
|
|
|
|
if (cats.hasOwnProperty(prop)) {
|
|
|
|
selectOptions.push({text: cats[prop]["name"], data:{cat: cats[prop]["GrpId"], comp: control.widgetData["competitions"][compIndex]["WetId"], status:cats[prop]["status"]}})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 14:15:07 +02:00
|
|
|
selector.appear(selectOptions, qsTr("select category"))
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function changeYear(){
|
|
|
|
var years = control.widgetData["years"]
|
|
|
|
|
|
|
|
var selectOptions = []
|
|
|
|
|
|
|
|
for(var prop in years){
|
|
|
|
if (years.hasOwnProperty(prop)) {
|
|
|
|
selectOptions.push({text: years[prop], data:{year: years[prop]}})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-24 14:15:07 +02:00
|
|
|
selector.appear(selectOptions, qsTr("select Year"))
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
|
2019-05-24 14:15:07 +02:00
|
|
|
function openCup(state, data) {
|
|
|
|
var cups = control.widgetData["cups"]
|
|
|
|
|
|
|
|
var prop
|
|
|
|
var selectOptions = []
|
|
|
|
var selectTitle = ""
|
|
|
|
|
|
|
|
if(state === undefined){
|
|
|
|
// opened for the first time -> select cup
|
|
|
|
selectTitle = qsTr("select cup")
|
|
|
|
|
|
|
|
cups.sort(function(a, b) {
|
|
|
|
return parseInt(b["SerId"]) - parseInt(a["SerId"]);
|
|
|
|
});
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-05-24 14:15:07 +02:00
|
|
|
for(prop in cups){
|
|
|
|
if (cups.hasOwnProperty(prop)) {
|
|
|
|
selectOptions.push({text: cups[prop]["name"], data:{cup: cups[prop]["SerId"]}})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(state === 1){
|
|
|
|
// opened for the second time -> select cat
|
|
|
|
var cup
|
|
|
|
|
|
|
|
// find the selected cup
|
|
|
|
for(prop in cups){
|
|
|
|
if (cups.hasOwnProperty(prop) && cups[prop]['SerId'] === data.cup) {
|
|
|
|
cup = cups[prop]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cup === undefined){
|
|
|
|
// cup was not found
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
selectTitle = cup['name'] + ": " + qsTr("select category")
|
|
|
|
|
|
|
|
// build a list with all cat in the cup out of the cat keys (rkey) given in the cup.cats
|
|
|
|
for(prop in cup['cats']){
|
|
|
|
if (cup['cats'].hasOwnProperty(prop)) {
|
|
|
|
|
|
|
|
// search the rkey in the cat list
|
|
|
|
for(var i = 0; i < control.widgetData["cats"].length; i ++ ){
|
|
|
|
if(control.widgetData["cats"][i]["rkey"] === cup["cats"][prop] && control.widgetData["cats"][i]["sex"] !== undefined){
|
|
|
|
// found it -> append it to the select list
|
|
|
|
var catName = control.widgetData["cats"][i]["name"] // name of cat
|
|
|
|
var catId = control.widgetData["cats"][i]["GrpId"] // id of cat
|
|
|
|
selectOptions.push({text: catName, data:{cup: data.cup, cat: catId}})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
selector.appear(selectOptions, selectTitle)
|
|
|
|
|
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
|
|
|
|
Connections {
|
2019-05-29 20:59:01 +02:00
|
|
|
target: parent.selector
|
2019-05-23 23:17:27 +02:00
|
|
|
onSelectionFinished: {
|
|
|
|
if(data.comp !== undefined){
|
|
|
|
console.log(data.status)
|
|
|
|
app.openWidget({comp: data.comp, cat: data.cat, type:data.status === 4 ? 'starters':''})
|
|
|
|
}
|
|
|
|
else if(data.year !== undefined){
|
|
|
|
updateData({year: data.year}, true)
|
|
|
|
control.year = data.year
|
|
|
|
}
|
2019-05-24 14:15:07 +02:00
|
|
|
else if(data.cup !== undefined && data.cat === undefined){
|
|
|
|
control.openCup(1,data)
|
|
|
|
}
|
|
|
|
else if(data.cup !== undefined && data.cat !== undefined){
|
|
|
|
app.openWidget({cup: data.cup, cat: data.cat})
|
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate: ItemDelegate {
|
|
|
|
id: competitionDel
|
|
|
|
|
|
|
|
property bool over
|
|
|
|
property var thisData: control.widgetData["competitions"][index]
|
|
|
|
|
|
|
|
property string name: thisData["name"]
|
|
|
|
property string date: thisData["date_span"]
|
|
|
|
property var cats: thisData["cats"]
|
|
|
|
property int catId: thisData["cat_id"] === undefined ? 0:thisData["cat_id"]
|
|
|
|
|
|
|
|
width: parent.width
|
|
|
|
height: compDelCol.height + 10
|
|
|
|
|
|
|
|
enabled: thisData["cats"] !== undefined && thisData["cats"].length > 0
|
|
|
|
|
|
|
|
opacity: 0
|
|
|
|
scale: 0.9
|
|
|
|
|
|
|
|
onThisDataChanged: {
|
|
|
|
fadeInPa.start()
|
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
control.openComp(index)
|
|
|
|
}
|
|
|
|
|
|
|
|
ParallelAnimation {
|
|
|
|
id: fadeInPa
|
|
|
|
NumberAnimation { target: competitionDel; property: "opacity"; from: 0; to: 1.0; duration: 400 }
|
|
|
|
NumberAnimation { target: competitionDel; property: "scale"; from: 0.8; to: 1.0; duration: 400 }
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: delBackroundRect
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
opacity: 0.5
|
|
|
|
|
|
|
|
color: control.getCompCatData(catId) === undefined ? "white":control.getCompCatData(catId)["bgcolor"]
|
|
|
|
}
|
|
|
|
|
|
|
|
Column {
|
|
|
|
id: compDelCol
|
|
|
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
|
|
|
width: parent.width * 0.97
|
|
|
|
|
|
|
|
spacing: 10
|
|
|
|
|
|
|
|
Label {
|
|
|
|
id: nameLa
|
|
|
|
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
font.bold: true
|
|
|
|
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
|
|
|
text: name
|
|
|
|
}
|
2019-05-29 20:59:01 +02:00
|
|
|
|
2019-05-23 23:17:27 +02:00
|
|
|
Label {
|
|
|
|
id: infola
|
|
|
|
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
text: thisData.info
|
2019-05-29 20:59:01 +02:00
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
|
|
|
|
Label {
|
|
|
|
id: dateLa
|
|
|
|
|
|
|
|
color: "grey"
|
|
|
|
|
|
|
|
text: date
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: bottomLineRa
|
|
|
|
|
|
|
|
anchors {
|
|
|
|
bottom: parent.bottom
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
}
|
|
|
|
|
|
|
|
height: 1
|
|
|
|
|
|
|
|
color: "lightgrey"
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|