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
|
2019-06-23 10:55:08 +02:00
|
|
|
//import QtGraphicalEffects 1.0
|
|
|
|
//import QtQuick.Templates 2.04 as T
|
|
|
|
//import QtQuick.Controls.impl 2.04
|
|
|
|
import QtQuick.Controls.Material 2.3
|
2019-05-23 23:17:27 +02:00
|
|
|
|
|
|
|
import "../Components"
|
|
|
|
|
|
|
|
Page {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
enum WidgetType {
|
|
|
|
Competitions,
|
|
|
|
|
|
|
|
Profile,
|
|
|
|
|
|
|
|
Registration,
|
|
|
|
Startlist,
|
|
|
|
Result,
|
|
|
|
|
|
|
|
Ranking,
|
|
|
|
Aggregated // not yet implemented
|
|
|
|
}
|
|
|
|
|
2019-05-24 14:15:07 +02:00
|
|
|
title: widgetLd.item !== null && widgetLd.item.hasOwnProperty('title') ? widgetLd.item['title']:""
|
|
|
|
property string subTitle: widgetLd.item !== null && widgetLd.item.hasOwnProperty('subTitle') ? widgetLd.item['subTitle']:""
|
|
|
|
property bool titleIsPageTitle: widgetLd.item !== null && widgetLd.item.hasOwnProperty('titleIsPageTitle') ? widgetLd.item['titleIsPageTitle']:false
|
|
|
|
property Component headerComponent: widgetLd.item !== null && widgetLd.item.hasOwnProperty('headerComponent') ? widgetLd.item['headerComponent']:null
|
2019-05-23 23:17:27 +02:00
|
|
|
|
|
|
|
property var params
|
|
|
|
|
|
|
|
property int status: -1
|
|
|
|
property bool ready: false
|
|
|
|
|
|
|
|
property var widgetData
|
|
|
|
|
|
|
|
property int widgetType
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
loadData(params)
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadData(params) {
|
|
|
|
// params is an object and can contain: {
|
|
|
|
// comp: competitionId,
|
|
|
|
// person: personId,
|
|
|
|
// cat: categoryId,
|
|
|
|
// nation: nationString ('', 'GER', 'SUI')
|
2019-09-08 23:37:01 +02:00
|
|
|
// route: (int) round
|
2019-05-23 23:17:27 +02:00
|
|
|
// type: ('','starters', 'nat_team_ranking', 'sektionenwertung', 'regionalzentren'),
|
|
|
|
//}
|
|
|
|
|
|
|
|
var ret = serverConn.getWidgetData(params)
|
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
root.status = ret["status"]
|
|
|
|
|
2019-05-23 23:17:27 +02:00
|
|
|
if(ret["status"] === 200){
|
|
|
|
root.widgetData = ret["data"]
|
|
|
|
root.widgetType = checkWidgetType(params, root.widgetData)
|
2019-05-29 20:59:01 +02:00
|
|
|
if(widgetLd.load()){
|
|
|
|
root.ready = true
|
|
|
|
}
|
|
|
|
else {
|
2019-05-31 12:18:35 +02:00
|
|
|
//root.status = 901
|
2019-05-29 20:59:01 +02:00
|
|
|
root.ready = false
|
|
|
|
}
|
|
|
|
}
|
2019-09-08 23:37:01 +02:00
|
|
|
else if(ret["status"] === 404 && [WidgetPage.WidgetType.Registration, WidgetPage.WidgetType.Startlist, WidgetPage.WidgetType.Result].includes(root.widgetType) && root.params["route"] !== "") {
|
|
|
|
// if we get a 404 and have startlist, results or registration, the route was not found -> remove round and try again
|
|
|
|
root.params["route"] = ""
|
|
|
|
loadData(root.params)
|
|
|
|
return
|
|
|
|
}
|
2019-05-29 20:59:01 +02:00
|
|
|
else {
|
|
|
|
root.ready = false
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
app.errorCode = root.status
|
2019-05-23 23:17:27 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateData(params, openLoadingDl) {
|
|
|
|
if(openLoadingDl)
|
|
|
|
loadingDl.open()
|
|
|
|
|
2019-05-29 20:59:01 +02:00
|
|
|
// update all the given values
|
2019-09-08 23:37:01 +02:00
|
|
|
Object.assign(root.params, params)
|
2019-05-23 23:17:27 +02:00
|
|
|
|
|
|
|
loadData(root.params)
|
|
|
|
|
2019-05-31 12:18:35 +02:00
|
|
|
console.log("ready: " + root.ready + ": " + root.status)
|
|
|
|
|
2019-05-23 23:17:27 +02:00
|
|
|
if(openLoadingDl)
|
|
|
|
loadingDl.close()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkWidgetType(params, widgetData){
|
|
|
|
var widgetType
|
|
|
|
|
|
|
|
function hasParam(object, key, value){
|
|
|
|
if(object[key] !== undefined){
|
|
|
|
if(value !== undefined){
|
|
|
|
return object[key] === value
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the type of the requested widget
|
|
|
|
|
2019-05-24 14:15:07 +02:00
|
|
|
if(hasParam(params, 'person')){
|
2019-05-23 23:17:27 +02:00
|
|
|
// person profile
|
|
|
|
widgetType = WidgetPage.WidgetType.Profile
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(hasParam(params, 'nation')){
|
|
|
|
// competition calendar
|
|
|
|
widgetType = WidgetPage.WidgetType.Competitions
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(hasParam(params, 'comp') && hasParam(params, 'type', 'starters')){
|
|
|
|
// registration
|
|
|
|
widgetType = WidgetPage.WidgetType.Registration
|
|
|
|
}
|
|
|
|
else if(hasParam(params, 'type', 'startlist') || (widgetData.participants !== undefined && widgetData.participants[0] && !widgetData.participants[0].result_rank && widgetData.discipline !== 'ranking')){
|
|
|
|
// startlist
|
|
|
|
widgetType = WidgetPage.WidgetType.Startlist
|
|
|
|
}
|
|
|
|
else if(hasParam(params, 'comp') && hasParam(params, 'cat')){
|
|
|
|
// results
|
|
|
|
widgetType = WidgetPage.WidgetType.Result
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( hasParam(params, 'cat') && hasParam(params, 'cup') && !hasParam(params, 'comp')){
|
|
|
|
// ranking data
|
|
|
|
widgetType = WidgetPage.WidgetType.Ranking
|
|
|
|
}
|
|
|
|
else if(hasParam(params, 'type', 'nat_team_ranking') || hasParam(params, 'type', 'sektionenwertung') || hasParam(params, 'type', 'regionalzentren')){
|
|
|
|
// aggregated
|
|
|
|
widgetType = WidgetPage.WidgetType.Aggregated
|
|
|
|
}
|
|
|
|
|
|
|
|
return widgetType
|
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: widgetLd
|
|
|
|
|
|
|
|
property alias selector: selectorPu
|
|
|
|
property var updateData: root.updateData
|
|
|
|
property alias params: root.params
|
2019-05-29 20:59:01 +02:00
|
|
|
property alias currentWidgetData: root.widgetData
|
2019-06-23 13:45:29 +02:00
|
|
|
property bool isTopElement: mainStack.currentItem === root
|
2019-05-29 20:59:01 +02:00
|
|
|
|
|
|
|
property var oldWidgetType: NaN
|
2019-05-23 23:17:27 +02:00
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
source: ""
|
|
|
|
|
|
|
|
function load() {
|
2019-05-29 20:59:01 +02:00
|
|
|
if(root.widgetType !== oldWidgetType){
|
|
|
|
oldWidgetType = root.widgetType
|
|
|
|
var calComp = Qt.createComponent(getFile(root.widgetType))//.createObject(null, {widgetData: root.widgetData, parent: widgetLd})
|
|
|
|
|
|
|
|
widgetLd.sourceComponent = calComp
|
|
|
|
//widgetLd.item.widgetData = root.widgetData
|
|
|
|
}
|
2019-05-31 12:18:35 +02:00
|
|
|
root.status = widgetLd.item.status
|
2019-05-29 20:59:01 +02:00
|
|
|
|
2019-05-31 12:18:35 +02:00
|
|
|
if(widgetLd.item.ready){
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
root.status = widgetLd.item.status === undefined ? 900:widgetLd.item.status
|
|
|
|
delete(widgetLd.sourceComponent)
|
|
|
|
return false
|
|
|
|
}
|
2019-05-29 20:59:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
//
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getFile(widgetType) {
|
|
|
|
var path = "qrc:/Widgets/"
|
|
|
|
switch(widgetType){
|
|
|
|
case WidgetPage.WidgetType.Competitions:
|
|
|
|
path += "CalendarWidget"
|
|
|
|
break
|
|
|
|
case WidgetPage.WidgetType.Profile:
|
|
|
|
path += "ProfileWidget"
|
|
|
|
break
|
|
|
|
case WidgetPage.WidgetType.Registration:
|
|
|
|
path += "RegistrationWidget"
|
|
|
|
break
|
2019-05-24 14:15:07 +02:00
|
|
|
case WidgetPage.WidgetType.Startlist:
|
|
|
|
path += "StartlistWidget"
|
|
|
|
break
|
|
|
|
case WidgetPage.WidgetType.Result:
|
|
|
|
path += "ResultWidget"
|
|
|
|
break
|
|
|
|
case WidgetPage.WidgetType.Ranking:
|
|
|
|
path += "RankingWidget"
|
|
|
|
break
|
|
|
|
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
path += ".qml"
|
|
|
|
return path
|
|
|
|
}
|
2019-05-24 14:15:07 +02:00
|
|
|
|
|
|
|
function getItemProperty(key, defaultValue) {
|
|
|
|
if(widgetLd.item !== null && widgetLd.item.hasOwnProperty(key)) {
|
|
|
|
return key
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return defaultValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Dialog {
|
|
|
|
id: selectorPu
|
|
|
|
|
|
|
|
property var dataObj
|
2019-06-23 10:55:08 +02:00
|
|
|
property string subTitle: ""
|
2019-05-23 23:17:27 +02:00
|
|
|
|
|
|
|
signal selectionFinished(int index, var data)
|
|
|
|
|
|
|
|
x: 0 //root.width / 2 - width / 2
|
2019-06-23 10:55:08 +02:00
|
|
|
y: root.height - selectorPu.height * 0.7//root.height - height //root.height / 2 - height / 2
|
|
|
|
|
|
|
|
opacity: 0
|
2019-05-23 23:17:27 +02:00
|
|
|
|
|
|
|
width: root.width
|
|
|
|
height: selectorLv.implicitHeight
|
|
|
|
|
|
|
|
modal: true
|
|
|
|
focus: true
|
|
|
|
|
2019-05-24 14:15:07 +02:00
|
|
|
title: ""
|
2019-05-23 23:17:27 +02:00
|
|
|
|
2019-06-23 10:55:08 +02:00
|
|
|
header: Column {
|
|
|
|
id: selectorPuHeaderCol
|
|
|
|
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
Label {
|
|
|
|
id: headerLa
|
|
|
|
|
|
|
|
visible: selectorPu.title
|
|
|
|
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
elide: "ElideRight"
|
|
|
|
padding: 24
|
|
|
|
bottomPadding: 0
|
|
|
|
font.bold: true
|
|
|
|
font.pixelSize: 16
|
|
|
|
background: Rectangle {
|
|
|
|
radius: 2
|
|
|
|
color: selectorPu.Material.dialogColor
|
|
|
|
clip: true
|
|
|
|
}
|
|
|
|
|
|
|
|
text: selectorPu.title
|
|
|
|
|
|
|
|
onLinkActivated: {
|
|
|
|
Qt.openUrlExternally(link)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
Label {
|
|
|
|
id: headerSubLa
|
|
|
|
|
|
|
|
visible: selectorPu.subTitle
|
|
|
|
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
elide: "ElideRight"
|
|
|
|
padding: 24
|
|
|
|
topPadding: 5
|
|
|
|
bottomPadding: 0
|
|
|
|
font.bold: true
|
|
|
|
font.pixelSize: 16
|
|
|
|
background: Rectangle {
|
|
|
|
radius: 2
|
|
|
|
color: selectorPu.Material.dialogColor
|
|
|
|
clip: true
|
|
|
|
}
|
|
|
|
|
|
|
|
text: selectorPu.subTitle
|
|
|
|
|
|
|
|
onLinkActivated: {
|
|
|
|
Qt.openUrlExternally(link)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function appear(dataObj, title, subTitle) {
|
2019-05-29 20:59:01 +02:00
|
|
|
if(dataObj.length > 0){
|
|
|
|
selectorPu.dataObj = dataObj
|
2019-06-23 13:45:29 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
selectorPu.dataObj = undefined
|
|
|
|
}
|
2019-05-29 20:59:01 +02:00
|
|
|
selectorPu.title = title
|
2019-06-23 10:55:08 +02:00
|
|
|
selectorPu.subTitle = subTitle === undefined ? "":subTitle
|
2019-05-29 20:59:01 +02:00
|
|
|
selectorPu.open()
|
2019-06-23 13:45:29 +02:00
|
|
|
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: selectorLv
|
|
|
|
|
|
|
|
property int delegateHeight: 50
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
implicitWidth: parent.width
|
2019-06-23 10:55:08 +02:00
|
|
|
implicitHeight: root.height * 0.7 < ( (delegateHeight + spacing) * model ) ? root.height * 0.7 : (delegateHeight + spacing) * model + 100
|
2019-05-23 23:17:27 +02:00
|
|
|
|
|
|
|
model: selectorPu.dataObj !== undefined ? selectorPu.dataObj.length:0
|
|
|
|
|
|
|
|
ScrollIndicator.vertical: ScrollIndicator {
|
|
|
|
parent: selectorLv.parent
|
|
|
|
anchors {
|
|
|
|
top: selectorLv.top
|
|
|
|
left: selectorLv.right
|
|
|
|
margins: 10
|
|
|
|
leftMargin: 3
|
|
|
|
bottom: selectorLv.bottom
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate: Button {
|
|
|
|
id: catBt
|
|
|
|
|
|
|
|
width: parent.width
|
|
|
|
height: text !== "" ? selectorLv.delegateHeight:0
|
|
|
|
|
|
|
|
flat: true
|
|
|
|
|
|
|
|
text: selectorPu.dataObj[index].text
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
selectorPu.close()
|
|
|
|
selectorPu.selectionFinished(index, selectorPu.dataObj[index].data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enter: Transition {
|
2019-06-23 10:55:08 +02:00
|
|
|
NumberAnimation {
|
|
|
|
property: "opacity";
|
|
|
|
//from: 0.0;
|
|
|
|
to: 1.0
|
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
NumberAnimation {
|
|
|
|
property: "y"
|
2019-06-23 10:55:08 +02:00
|
|
|
//from: root.height - selectorPu.height * 0.7
|
2019-05-23 23:17:27 +02:00
|
|
|
to: root.height - selectorPu.height
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit: Transition {
|
2019-06-23 10:55:08 +02:00
|
|
|
NumberAnimation {
|
|
|
|
property: "opacity";
|
|
|
|
//from: 1.0;
|
|
|
|
to: 0.0
|
|
|
|
}
|
2019-05-23 23:17:27 +02:00
|
|
|
NumberAnimation {
|
|
|
|
property: "y"
|
2019-06-23 10:55:08 +02:00
|
|
|
//from: root.height - selectorPu.height
|
2019-05-23 23:17:27 +02:00
|
|
|
to: root.height - selectorPu.height * 0.7
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-23 10:55:08 +02:00
|
|
|
|
2019-05-23 23:17:27 +02:00
|
|
|
}
|