app/resources/qml/Pages/CalendarPage.qml

670 lines
21 KiB
QML
Raw Normal View History

2020-10-31 15:16:06 +01: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 QtQuick.Layouts 1.3
import de.itsblue.blueRock 2.0
import "../Components"
BRWidgetPage {
id: control
title: control.data.title
2020-10-31 15:16:06 +01:00
headerComponent: RowLayout {
height: parent.height
//width: 10//childrenRect.width
spacing: 0
ToolButton {
id:yearToolBt
onClicked: control.changeSeason()
2020-10-31 15:16:06 +01:00
icon.name: "year"
}
ToolButton {
id: filterToolBt
onClicked: control.changeLeagues()
2020-10-31 15:16:06 +01:00
icon.name: "filter"
}
2020-10-31 15:16:06 +01:00
ToolButton {
id: cupToolBt
2020-10-31 15:16:06 +01:00
onClicked: control.openCup()
2020-10-31 15:16:06 +01:00
icon.name: "cup"
}
}
2020-10-31 15:16:06 +01:00
onLoadingFinished: {
calendarLv.autoScroll()
}
2020-10-31 15:16:06 +01:00
onSelectionFinished: {
if(data.task === "competition"){
console.log("OPENING COMP 1")
loadingDl.open()
data.competition.currentCategory = data.category
app.openResults(data.competition)
loadingDl.close()
//app.openWidget({comp: data.comp, cat: data.cat, type:data.status === 4 ? 'starters':''})
}
else if(data.task === "season"){
loadingDl.open()
control.data.currentSeason = data.season
loadingDl.close()
2020-10-31 15:16:06 +01:00
}
else if(data.task === "cup1"){
control.openCup(data)
}
else if(data.task === "cup2"){
app.openWidget({cup: data.cup, cat: data.cat})
}
}
2020-10-31 15:16:06 +01:00
function changeSeason(){
var selectOptions = []
2020-10-31 15:16:06 +01:00
for(var i = 0; i < control.data.seasons.length; i++){
selectOptions.push({text: control.data.seasons[i].name, data:{task: "season", season: control.data.seasons[i]}})
}
selector.appear(selectOptions, qsTr("select season"))
}
function openCompetition(competition){
var selectOptions = []
var categories = competition.categories
for(var i = 0; i < categories.length; i++){
selectOptions.push({text: categories[i].name, data:{task: "competition", category: categories[i], competition: competition, /*TODO*/ status:categories.status}})
}
var infoUrls = competition.infosheetUrls
var infosheet = "";
if(infoUrls.length >= 1)
infosheet += ("<a href='" + infoUrls[0] + "'>" + qsTr('infosheet') + "</a>")
if(infoUrls.length === 2)
infosheet += (", <a href='" + infoUrls[1] + "'>" + qsTr('further infos') + "</a>")
var eventWebsite = competition.eventWebsiteUrl.toString() !== "" ? ("<a href='" + competition.eventWebsiteUrl + "'>" + qsTr('Event Website') + "</a>"):""
selector.appear(selectOptions, competition.name, eventWebsite + ((eventWebsite !== "" && infosheet !== "") ? ", ":"") + infosheet )
}
function openCup(data) {
var cups = control.data.currentSeason.cups
var prop
var selectOptions = []
var selectTitle = ""
if(data === undefined){
// opened for the first time -> select cup
selectTitle = qsTr("select cup")
for(var i = 0; i < cups.length; i++){
selectOptions.push({text: cups[i].name, data:{task: "cup1", cup: cups[i]}})
2020-10-31 15:16:06 +01:00
}
}
else if(data.task === "cup1"){
// opened for the second time -> select cat
var cup = data.cup
2020-10-31 15:16:06 +01:00
selectTitle = cup['name'] + ": " + qsTr("select category")
for(var c = 0; c < cup.categories.length; c++){
selectOptions.push({text: cup.categories[c].name, data:{task: "cup2", cup: data.cup, cat: cup.categories[c]}})
}
2020-10-31 15:16:06 +01:00
}
selector.appear(selectOptions, selectTitle)
}
function changeLeagues() {
var leagues = control.data.currentSeason.leagues
var selectOptions = []
for(var i = 0; i < leagues.length; i++) {
//console.log("found cat: " + obj[prop]['label'])
selectOptions.push( {text: leagues[i].name, data:{task:"leagues", league: selectOptions}} )
}
//compCats.push( {"text": qsTr("Pinned"), "data": {"sort_rank":0, "cat_id":[-1]}} )
console.log("leagues: " + leagues)
filterSelectPu.appear(selectOptions, qsTr("Select Filters"), "")
2020-10-31 15:16:06 +01:00
}
DataListView {
id: calendarLv
2020-10-31 15:16:06 +01:00
anchors.fill: parent
//boundsBehavior: Flickable.StopAtBounds
model: control.data.currentSeason.competitions
2020-10-31 15:16:06 +01:00
//listData: widgetData['competitions']
onRefresh: {
control.data.load()
2020-10-31 15:16:06 +01:00
}
Component.onCompleted: {
//initFilters()
//initFavorites()
/*if(model){
2020-10-31 15:16:06 +01:00
control.status = 200
control.ready = true
}
else {
control.ready = false
control.status = 901
return
}*/
2020-10-31 15:16:06 +01:00
}
/*
onWidgetDataChanged: {
// if the IFSC Calendar is open -> add the worldranking
if(params.nation === "ICC"){
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"]})
}
}
*/
function autoScroll() {
// function to scroll to the next competition that is not already over
var compList = calendarLv.model
2020-10-31 15:16:06 +01:00
if(control.data.currentSeason.year === new Date().getFullYear()){
console.log("SCROLLING")
2020-10-31 15:16:06 +01:00
for(var i = 0; i < compList.length; i ++){
if(compList[i].endDate.getTime() < new Date().getTime()){
2020-10-31 15:16:06 +01:00
// end date is already over -> move the list view down!
calendarLv.positionViewAtIndex(i, ListView.Top)
2020-10-31 15:16:06 +01: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 filterCats(display, cats) {
//console.log("filtering cats: " + cats + " displaying: " + display)
for(var i = 0; i < cats.length; i ++){
if(control.displayedCompCats.indexOf(cats[i]) >= 0 && !display){
control.displayedCompCats.splice(control.displayedCompCats.indexOf(cats[i]), 1)
}
else if(control.displayedCompCats.indexOf(cats[i]) == -1 && display){
control.displayedCompCats.push(cats[i])
}
}
// trigger 'changed' signal
control.displayedCompCats = control.displayedCompCats
appSettings.write("displayedCompCats"+params.nation, JSON.stringify(displayedCompCats))
//console.log("new JSON string is: " + JSON.stringify(displayedCompCats))
//console.log("displayed cats is now: " + control.displayedCompCats)
}
function initFilters() {
if(appSettings.read("displayedCompCats"+params.nation) !== "false"){
//console.log(appSettings.read("displayedCompCats"+params.nation))
control.displayedCompCats = JSON.parse(appSettings.read("displayedCompCats"+params.nation))
}
if(control.displayedCompCats.length === 0){
var obj = app.compCats
var compCats = new Array
for(var prop in obj) {
// go through the whole array and search for data keys
if (obj.hasOwnProperty(prop) && obj[prop]["nation"] === params.nation) {
//console.log("found cat: " + obj[prop]['label'])
filterCats(true, obj[prop]['cat_id'])
}
}
}
// trigger 'changed' signal
control.displayedCompCats = control.displayedCompCats
//console.log(control.displayedCompCats)
}
function editFavorites(favorite, compId) {
if(control.compFavorites.indexOf(compId) >= 0 && !favorite) {
control.compFavorites.splice( control.compFavorites.indexOf(compId), 1)
}
else if(control.compFavorites.indexOf(compId) < 0 && favorite) {
control.compFavorites.push(compId)
}
appSettings.write("compFavorites", JSON.stringify(control.compFavorites))
// trigger 'changed' signal
control.compFavorites = control.compFavorites
}
function initFavorites() {
if(appSettings.read("compFavorites") !== "false"){
//console.log(appSettings.read("displayedCompCats"+params.nation))
control.compFavorites = JSON.parse(appSettings.read("compFavorites"))
}
else {
control.compFavorites = []
appSettings.write("compFavorites", JSON.stringify(control.compFavorites))
}
// trigger 'changed' signal
control.compFavorites = control.compFavorites
console.log(control.compFavorites)
}
header: Item {
id: topSpacerItm
width: parent.width
height: 10
}
footer: Item {
id: bottomSpacerItm
width: parent.width
height: 10
}
delegate: ItemDelegate {
id: competitionDel
property bool over
property var thisData: modelData
2020-10-31 15:16:06 +01:00
property string name: thisData.name
property string date: thisData.dateSpan //"test" // TODO thisData["date_span"]
2020-10-31 15:16:06 +01:00
property var cats: thisData["cats"]
property int catId: thisData["cat_id"] === undefined ? 0:thisData["cat_id"]
property bool thisIsFavored: true //control.compFavorites.indexOf(parseInt(thisData['WetId'])) >= 0
property bool includedByFavorites: true //control.displayedCompCats.indexOf(-1) >= 0 && thisIsFavored
property bool includedByFilter: true//control.displayedCompCats.indexOf(parseInt(thisData['cat_id'])) >= 0
2020-10-31 15:16:06 +01:00
property bool thisIsVisible: includedByFavorites || includedByFilter
function updateVisibility() {
competitionDel.includedByFilter = control.displayedCompCats.indexOf(parseInt(competitionDel.thisData['cat_id'])) >= 0
competitionDel.thisIsFavored = control.compFavorites.indexOf(parseInt(thisData['WetId'])) >= 0
competitionDel.includedByFavorites = control.displayedCompCats.indexOf(-1) >= 0 && thisIsFavored
}
width: parent.width
height: thisIsVisible ? compDelCol.height + 10 : 0
enabled: true//((thisData["cats"] !== undefined && thisData["cats"].length > 0) || competitionDel.thisData["homepage"] !== undefined || getCompInfoUrls(index).length > 0) && height > 0
2020-10-31 15:16:06 +01:00
//visible: includedByFilter
opacity: 0
scale: 0.9
/*Connections {
target: control
onDisplayedCompCatsChanged: {
competitionDel.updateVisibility()
}
onCompFavoritesChanged: {
competitionDel.updateVisibility()
}
}*/
onThisDataChanged: {
if(thisIsVisible){
fadeInPa.start()
}
}
onThisIsVisibleChanged: {
if(thisIsVisible){
fadeInPa.start()
}
else {
fadeOutPa.start()
}
}
Behavior on height {
NumberAnimation {
duration: 400
}
}
onClicked: {
control.openCompetition(competitionDel.thisData)
2020-10-31 15:16:06 +01:00
}
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 }
}
ParallelAnimation {
id: fadeOutPa
NumberAnimation { target: competitionDel; property: "opacity"; from: 1; to: 0; duration: 400 }
NumberAnimation { target: competitionDel; property: "scale"; from: 1; to: 0.8; duration: 400 }
}
Rectangle {
id: delBackroundRect
anchors.fill: parent
opacity: 0.5
color: competitionDel.thisData.league.color
2020-10-31 15:16:06 +01:00
}
Column {
id: compDelCol
anchors.centerIn: parent
width: parent.width * 0.97
spacing: 10
RowLayout {
width: parent.width
Label {
id: nameLa
width: parent.width
font.bold: true
wrapMode: Text.WordWrap
text: name
Layout.fillWidth: true
}
ToolButton {
id: bookmarkTb
icon.name: competitionDel.thisIsFavored ? "pinFilled":"pin"
onClicked: {
control.editFavorites(!competitionDel.thisIsFavored, parseInt(thisData['WetId']))
}
Layout.alignment: Layout.Right
Behavior on icon.name {
SequentialAnimation {
NumberAnimation {
property: "scale"
target: bookmarkTb
duration: 75
to: 0.8
}
NumberAnimation {
property: "scale"
target: bookmarkTb
duration: 75
to: 1
}
}
}
}
}
Label {
id: dateLa
color: "grey"
text: date
}
}
Rectangle {
id: bottomLineRa
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
height: 1
color: "lightgrey"
}
}
section.property: "month"
section.delegate: ItemDelegate {
id: name
background: Rectangle {
color: "red"
}
width: parent.width
text: section
}
}
2020-10-31 15:16:06 +01:00
Dialog {
id: filterSelectPu
2020-10-31 15:16:06 +01:00
property var dataObj
property string subTitle: ""
2020-10-31 15:16:06 +01:00
signal selectionFinished(int index, var data)
2020-10-31 15:16:06 +01:00
x: 0 - control.anchors.leftMargin //root.width / 2 - width / 2
y: control.height - filterSelectPu.height * 0.7//root.height - height //root.height / 2 - height / 2
2020-10-31 15:16:06 +01:00
opacity: 0
2020-10-31 15:16:06 +01:00
width: control.width + control.anchors.leftMargin + control.anchors.rightMargin
height: selectorLv.implicitHeight
2020-10-31 15:16:06 +01:00
modal: true
focus: true
2020-10-31 15:16:06 +01:00
title: ""
2020-10-31 15:16:06 +01:00
function appear(dataObj, title, subTitle) {
if(dataObj.length > 0){
filterSelectPu.dataObj = dataObj
filterSelectPu.title = title
filterSelectPu.subTitle = subTitle === undefined ? "":subTitle
filterSelectPu.open()
2020-10-31 15:16:06 +01:00
}
}
2020-10-31 15:16:06 +01:00
header: Column {
id: filterSelectPuHeaderCol
2020-10-31 15:16:06 +01:00
width: parent.width
2020-10-31 15:16:06 +01:00
Label {
id: headerLa
2020-10-31 15:16:06 +01:00
visible: filterSelectPu.title
2020-10-31 15:16:06 +01:00
width: parent.width
2020-10-31 15:16:06 +01:00
elide: "ElideRight"
padding: 24
bottomPadding: 0
font.bold: true
font.pixelSize: 16
background: Rectangle {
radius: 2
//color: filterSelectPu.Material.dialogColor
clip: true
}
2020-10-31 15:16:06 +01:00
text: filterSelectPu.title
2020-10-31 15:16:06 +01:00
onLinkActivated: {
Qt.openUrlExternally(link)
2020-10-31 15:16:06 +01:00
}
}
Label {
id: headerSubLa
2020-10-31 15:16:06 +01:00
visible: filterSelectPu.subTitle
2020-10-31 15:16:06 +01:00
width: parent.width
2020-10-31 15:16:06 +01:00
elide: "ElideRight"
padding: 24
topPadding: 5
bottomPadding: 0
font.bold: true
font.pixelSize: 16
background: Rectangle {
radius: 2
//color: filterSelectPu.Material.dialogColor
clip: true
}
2020-10-31 15:16:06 +01:00
text: filterSelectPu.subTitle
2020-10-31 15:16:06 +01:00
onLinkActivated: {
Qt.openUrlExternally(link)
2020-10-31 15:16:06 +01:00
}
}
}
2020-10-31 15:16:06 +01:00
ListView {
id: selectorLv
2020-10-31 15:16:06 +01:00
property int delegateHeight: 50
2020-10-31 15:16:06 +01:00
anchors.fill: parent
2020-10-31 15:16:06 +01:00
implicitWidth: parent.width
implicitHeight: control.height * 0.7 < ( (delegateHeight + spacing) * model ) ? root.height * 0.7 : (delegateHeight + spacing) * model + 100
2020-10-31 15:16:06 +01:00
model: filterSelectPu.dataObj !== undefined ? filterSelectPu.dataObj.length:0
2020-10-31 15:16:06 +01:00
ScrollIndicator.vertical: ScrollIndicator {
parent: selectorLv.parent
anchors {
top: selectorLv.top
left: selectorLv.right
margins: 10
leftMargin: 3
bottom: selectorLv.bottom
2020-10-31 15:16:06 +01:00
}
}
2020-10-31 15:16:06 +01:00
delegate: CheckDelegate {
id: catBt
2020-10-31 15:16:06 +01:00
width: parent.width
height: text !== "" ? selectorLv.delegateHeight:0
2020-10-31 15:16:06 +01:00
//flat: true
2020-10-31 15:16:06 +01:00
text: filterSelectPu.dataObj[index].text
2020-10-31 15:16:06 +01:00
Component.onCompleted: {
checked = getCheckedState()
}
Connections {
target: control
onDisplayedCompCatsChanged: {
//console.log("filters changed")
//competitionDel.visible = control.displayedCompCats.indexOf(parseInt(competitionDel.thisData['cat_id'])) >= 0
checked = getCheckedState()
2020-10-31 15:16:06 +01:00
}
}
2020-10-31 15:16:06 +01:00
function getCheckedState() {
for(var i = 0; i < filterSelectPu.dataObj[index].data.cat_id.length; i ++){
2020-10-31 15:16:06 +01:00
//console.log("checking cat " + filterSelectPu.dataObj[index].data.label )
if(control.displayedCompCats.indexOf(filterSelectPu.dataObj[index].data.cat_id[i] ) >= 0){
return true
2020-10-31 15:16:06 +01:00
}
}
return false
}
2020-10-31 15:16:06 +01:00
onClicked: {
control.filterCats(checked, filterSelectPu.dataObj[index].data.cat_id)
if(control.displayedCompCats.length === 0){
control.filterCats(true, filterSelectPu.dataObj[index].data.cat_id)
checked = true
2020-10-31 15:16:06 +01:00
}
}
}
}
2020-10-31 15:16:06 +01:00
enter: Transition {
NumberAnimation {
property: "opacity";
//from: 0.0;
to: 1.0
}
NumberAnimation {
property: "y"
//from: root.height - filterSelectPu.height * 0.7
to: control.height - filterSelectPu.height
2020-10-31 15:16:06 +01:00
}
}
2020-10-31 15:16:06 +01:00
exit: Transition {
NumberAnimation {
property: "opacity";
//from: 1.0;
to: 0.0
}
NumberAnimation {
property: "y"
//from: root.height - filterSelectPu.height
to: control.height - filterSelectPu.height * 0.7
2020-10-31 15:16:06 +01:00
}
}
}
2020-10-31 15:16:06 +01:00
}