/* 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 . */ import QtQuick 2.9 import QtQuick.Controls 2.4 import QtGraphicalEffects 1.0 import "../Components" Page { id: root enum WidgetType { Competitions, Profile, Registration, Startlist, Result, Ranking, Aggregated // not yet implemented } 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 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') // type: ('','starters', 'nat_team_ranking', 'sektionenwertung', 'regionalzentren'), //} var ret = serverConn.getWidgetData(params) if(ret["status"] === 200){ root.widgetData = ret["data"] root.widgetType = checkWidgetType(params, root.widgetData) console.log(widgetType) widgetLd.load() root.ready = true } root.status = ret["status"] } function updateData(params, openLoadingDl) { if(openLoadingDl) loadingDl.open() for(var prop in params){ if(params.hasOwnProperty(prop)){ root.params[prop] = params[prop] } } loadData(root.params) 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 if(hasParam(params, 'person')){ // 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 anchors.fill: parent source: "" function load() { widgetLd.source = getFile(root.widgetType) widgetLd.item.widgetData = root.widgetData } 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 case WidgetPage.WidgetType.Startlist: path += "StartlistWidget" break case WidgetPage.WidgetType.Result: path += "ResultWidget" break case WidgetPage.WidgetType.Ranking: path += "RankingWidget" break } path += ".qml" return path } function getItemProperty(key, defaultValue) { if(widgetLd.item !== null && widgetLd.item.hasOwnProperty(key)) { return key } else { return defaultValue } } } Dialog { id: selectorPu property var dataObj signal selectionFinished(int index, var data) x: 0 //root.width / 2 - width / 2 y: root.height - height //root.height / 2 - height / 2 width: root.width height: selectorLv.implicitHeight modal: true focus: true title: "" function appear(dataObj, title) { selectorPu.dataObj = dataObj selectorPu.title = title selectorPu.open() } ListView { id: selectorLv property int delegateHeight: 50 anchors.fill: parent implicitWidth: parent.width implicitHeight: root.height * 0.6 < ( (delegateHeight + spacing) * model ) ? root.height * 0.6 : (delegateHeight + spacing) * model + 75 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 { NumberAnimation { property: "opacity"; from: 0.0; to: 1.0 } NumberAnimation { property: "y" from: root.height - selectorPu.height * 0.7 to: root.height - selectorPu.height } } exit: Transition { NumberAnimation { property: "opacity"; from: 1.0; to: 0.0 } NumberAnimation { property: "y" from: root.height - selectorPu.height to: root.height - selectorPu.height * 0.7 } } } }