app/resources/qml/Widgets/RegistrationWidget.qml

197 lines
5.5 KiB
QML
Raw Normal View History

/*
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
property string title: control.widgetData['name'] === undefined ? "":control.widgetData['name']
property string subTitle: getSubtitle()
property bool titleIsPageTitle: true
property Component headerComponent: ToolButton {
id: moreToolBt
onClicked: {
control.changeCat()
}
text: "\uf142"
font.family: fa5solid.name
}
2019-05-29 20:59:01 +02:00
property var widgetData: currentWidgetData
2021-06-17 15:36:57 +02:00
property var athletes
function getSubtitle() {
var titleString
2019-05-29 20:59:01 +02:00
if(control.widgetData["categorys"] === undefined)
return ""
for(var i = 0; i < control.widgetData["categorys"].length; i ++ ){
//console.log("checking " + i + ": cat: " + parseInt(control.widgetData["categorys"][i]["GrpId"]) + " searched cat: " + params.cat)
if(parseInt(control.widgetData["categorys"][i]["GrpId"]) === parseInt(params.cat)){
titleString = control.widgetData["categorys"][i]["name"]
}
}
2021-06-20 20:11:19 +02:00
//% "(Registration)"
2021-06-20 21:08:59 +02:00
var addition = qsTrId("#registrationHeadline")
2019-05-29 20:59:01 +02:00
if(titleString !== undefined){
return addition + " " + titleString
2019-05-29 20:59:01 +02:00
}
else {
return ""
}
}
function getText(index){
var fedName // federation name
if(widgetData["federations"] !== undefined){
// not an international competition -> get name of federation
for(var i = 0; i < widgetData["federations"].length; i ++ ){
//console.log("checking " + i + ": cat: " + parseInt(widgetData["categorys"][i]["GrpId"]) + " searched cat: " + root.catId)
if(widgetData["federations"][i]["fed_id"] === widgetData[ 'athletes' ][index]["reg_fed_id"]){
fedName = widgetData["federations"][i]["shortcut"]
}
}
}
else {
// an international competition -> get nation
fedName = widgetData[ 'athletes' ][index]["nation"]
}
return widgetData[ "athletes" ][index]["firstname"] + " " + widgetData[ "athletes" ][index]["lastname"] + " (" + fedName + ")"
}
2021-06-17 15:36:57 +02:00
function changeCat() {
var cats = control.widgetData["categorys"]
cats.sort(function(a, b) {
return parseInt(a["GrpId"]) - parseInt(b["GrpId"]);
});
var selectOptions = []
for(var prop in cats){
if (cats.hasOwnProperty(prop) && parseInt(cats[prop]["GrpId"]) !== parseInt(params.cat)) {
// append all cats and ignore the current one
//console.log("found cat: ", cats[prop]['name'])
selectOptions.push({text: cats[prop]['name'], data:{cat: cats[prop]['GrpId']}})
}
}
2021-06-20 21:08:59 +02:00
selector.appear(selectOptions, qsTrId("#selectCategory"))
}
2021-06-17 15:36:57 +02:00
function filterAthletes(athletes) {
var filtered = athletes.filter(function(athlete){
return parseInt(athlete.cat) === parseInt(params.cat)
})
return filtered
}
Connections {
target: selector
function onSelectionFinished(index, data) {
if(data.cat !== undefined){
updateData({cat: data.cat}, true)
}
}
}
2019-05-29 20:59:01 +02:00
Component.onCompleted: {
2021-06-17 15:36:57 +02:00
athletes = filterAthletes(widgetData["athletes"])
if(athletes.length > 0){
2019-05-29 20:59:01 +02:00
control.ready = true
control.status = 200
}
else {
control.ready = false
control.status = 901
}
}
onRefresh: {
updateData({}, false)
2021-06-17 15:36:57 +02:00
athletes = []
athletes = filterAthletes(widgetData["athletes"])
}
2021-06-17 15:36:57 +02:00
model: athletes
delegate: ItemDelegate {
id: partDel
property int thisIndex: index
2021-06-17 15:36:57 +02:00
property var thisData: modelData
2021-06-17 15:36:57 +02:00
width: parseInt(thisData.cat) === parseInt(params.cat) ? control.width:control.width * 0.2
opacity: 0
scale: 0.9
onThisDataChanged: {
fadeInPa.start()
}
onClicked: {
app.openWidget({person:thisData["PerId"]})
}
ParallelAnimation {
id: fadeInPa
NumberAnimation { target: partDel; property: "opacity"; from: 0; to: 1.0; duration: 400 }
NumberAnimation { target: partDel; property: "scale"; from: 0.8; to: 1.0; duration: 400 }
}
text: ""
2021-06-08 19:23:55 +02:00
highlighted: partDel.thisIndex % 2 == 0
Label {
anchors.fill: parent
anchors.leftMargin: parent.width * 0.05
verticalAlignment: Text.AlignVCenter
font.bold: true
font.pixelSize: Math.abs( height * 0.3 )
elide: "ElideRight"
text: control.getText(index)
}
}
}