app/resources/qml/Pages/BRWidgetPage.qml

142 lines
4.1 KiB
QML
Raw Permalink 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 QtGraphicalEffects 1.0
//import QtQuick.Templates 2.04 as T
//import QtQuick.Controls.impl 2.04
import QtQuick.Controls.Material 2.3
import de.itsblue.blueRock 2.0
import "../Components"
Page {
id: root
property BRWidget data
property Component headerComponent
property alias selector: selectorPopup
2020-10-31 15:16:06 +01:00
property string subTitle
property bool titleIsPageTitle: true
property int status: -1
property bool ready: false
signal loadingFinished()
signal selectionFinished(int index, var data)
2020-10-31 15:16:06 +01:00
Component.onCompleted: {
console.log("TRYING TO LOAD")
var status = data.load()
console.log(data)
if(status !== BRWidget.Success)
ready = false
else
ready = true
loadingFinished()
2020-10-31 15:16:06 +01:00
}
function loadData(params) {
// params is an object and can contain: {
// comp: competitionId,
// person: personId,
// cat: categoryId,
// nation: nationString ('', 'GER', 'SUI')
// route: (int) round
// type: ('','starters', 'nat_team_ranking', 'sektionenwertung', 'regionalzentren'),
//}
var ret = serverConn.getWidgetData(params)
root.status = ret["status"]
if(ret["status"] === 200){
root.widgetData = ret["data"]
root.widgetType = checkWidgetType(params, root.widgetData)
if(widgetLd.load()){
root.ready = true
}
else {
//root.status = 901
root.ready = false
}
}
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 route and try again
root.params["route"] = ""
loadData(root.params)
return
}
else {
root.ready = false
}
app.errorCode = root.status
}
SelectorPopup {
id: selectorPopup
2020-10-31 15:16:06 +01:00
contentItem: ListView {
2020-10-31 15:16:06 +01:00
id: selectorLv
property int delegateHeight: 50
spacing: 10
2020-10-31 15:16:06 +01:00
clip: true
2020-10-31 15:16:06 +01:00
implicitWidth: selectorPopup.width
implicitHeight: model === undefined ? 0:(delegateHeight + spacing) * model.length
2020-10-31 15:16:06 +01:00
model: selectorPopup.dataObj !== undefined ? selectorPopup.dataObj:undefined
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
}
}
delegate: Button {
id: catBt
2021-03-07 20:39:07 +01:00
width: selectorLv.width
2020-10-31 15:16:06 +01:00
height: text !== "" ? selectorLv.delegateHeight:0
flat: true
text: selectorPopup.dataObj[index].text
2020-10-31 15:16:06 +01:00
onClicked: {
selectorPopup.close()
control.selectionFinished(index, selectorPopup.dataObj[index].data)
2020-10-31 15:16:06 +01:00
}
}
}
}
}