app/resources/qml/Pages/CalendarPage.qml
2021-03-07 20:42:03 +01:00

371 lines
11 KiB
QML

/*
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
headerComponent: RowLayout {
height: parent.height
//width: 10//childrenRect.width
spacing: 0
ToolButton {
id:yearToolBt
onClicked: control.changeSeason()
icon.name: "year"
}
ToolButton {
id: filterToolBt
onClicked: control.changeLeagues()
icon.name: "filter"
}
ToolButton {
id: cupToolBt
onClicked: control.openCup()
icon.name: "cup"
}
}
onLoadingFinished: {
calendarLv.autoScroll()
}
onSelectionFinished: {
if(data.task === "competition"){
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()
}
else if(data.task === "cup1"){
control.openCup(data)
}
else if(data.task === "cup2"){
app.openWidget({cup: data.cup, cat: data.cat})
}
}
function changeSeason(){
var selectOptions = []
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]}})
}
}
else if(data.task === "cup1"){
// opened for the second time -> select cat
var cup = data.cup
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]}})
}
}
selector.appear(selectOptions, selectTitle)
}
function changeLeagues() {
var leagues = control.data.currentSeason.leagues
var selectOptions = []
for(var i = 0; i < leagues.length; i++) {
selectOptions.push( {text: leagues[i].name, data:{task:"leagues", league: leagues[i]}} )
}
//compCats.push( {"text": qsTr("Pinned"), "data": {"sort_rank":0, "cat_id":[-1]}} )
console.log("leagues: " + leagues)
filterSelectPu.appear(selectOptions, qsTr("Select Filters"), "")
}
DataListView {
id: calendarLv
anchors.fill: parent
model: control.data.currentSeason.competitions
onRefresh: control.data.load()
function autoScroll() {
// function to scroll to the next competition that is not already over
var compList = calendarLv.model
if(control.data.currentSeason.year === new Date().getFullYear()){
console.log("SCROLLING")
for(var i = 0; i < compList.length; i ++){
if(compList[i].endDate.getTime() < new Date().getTime()){
// end date is already over -> move the list view down!
calendarLv.positionViewAtIndex(i, ListView.Top)
}
}
}
}
delegate: ItemDelegate {
id: competitionDel
property var thisData: modelData
width: calendarLv.width
height: compDelCol.height + 10
enabled: thisData.categories.length > 0 || thisData.eventWebsiteUrl.toString() !== "" || thisData.infosheetUrls.length > 0
opacity: 0
scale: 0.9
onThisDataChanged: fadeInPa.start()
Behavior on height {
NumberAnimation {
duration: 400
}
}
onClicked: control.openCompetition(competitionDel.thisData)
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
}
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: competitionDel.thisData.name
Layout.fillWidth: true
}
ToolButton {
id: bookmarkTb
icon.name: competitionDel.thisData.pinned ? "pinFilled":"pin"
onClicked: {
competitionDel.thisData.pinned = !competitionDel.thisData.pinned
}
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: competitionDel.thisData.dateSpan
}
}
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
}
}
SelectorPopup {
id: filterSelectPu
contentItem: ListView {
id: selectorLv
property int delegateHeight: 50
spacing: 10
clip: true
implicitWidth: parent.width
implicitHeight: model === undefined ? 0:(delegateHeight + spacing) * model.length
model: filterSelectPu.dataObj
ScrollIndicator.vertical: ScrollIndicator {
parent: selectorLv.parent
anchors {
top: selectorLv.top
left: selectorLv.right
margins: 10
leftMargin: 3
bottom: selectorLv.bottom
}
}
delegate: CheckDelegate {
id: catBt
property var thisData: modelData
width: parent.width
height: text !== "" ? selectorLv.delegateHeight:0
checked: thisData.data.league.enabled
text: thisData.text
onClicked: {
if(thisData.data.league.state !== BRWidget.Loaded) {
loadingDl.open()
thisData.data.league.load()
loadingDl.close()
}
thisData.data.league.enabled = checked
}
}
}
}
}