creating, deleting and selecting athletes is now supported

This commit is contained in:
Dorian Zedler 2019-05-02 22:39:22 +02:00
parent 271e98f8ec
commit 6b819d3298
5 changed files with 135 additions and 68 deletions

View file

@ -95,7 +95,12 @@ public slots:
Q_INVOKABLE void disconnectBaseStation(); Q_INVOKABLE void disconnectBaseStation();
Q_INVOKABLE QString getBaseStationState(); Q_INVOKABLE QString getBaseStationState();
Q_INVOKABLE QVariant getBaseStationConnections(); Q_INVOKABLE QVariant getBaseStationConnections();
// athlete management
Q_INVOKABLE QVariant getAthletes(); Q_INVOKABLE QVariant getAthletes();
Q_INVOKABLE bool createAthlete( QString userName, QString fullName );
Q_INVOKABLE bool deleteAthlete( QString userName );
Q_INVOKABLE bool selectAthlete( QString userName );
Q_INVOKABLE bool reloadBaseStationIpAdress(); Q_INVOKABLE bool reloadBaseStationIpAdress();
}; };

View file

@ -77,7 +77,7 @@ Popup {
leftMargin: ( parent.width - headlineUnderline.width ) / 2 leftMargin: ( parent.width - headlineUnderline.width ) / 2
//topMargin: headlineUnderline.anchors.topMargin * 1.2 //topMargin: headlineUnderline.anchors.topMargin * 1.2
bottom: parent.bottom bottom: parent.bottom
bottomMargin: headlineUnderline.anchors.topMargin bottomMargin: topContainerItm.height
} }
Behavior on opacity { Behavior on opacity {
@ -96,12 +96,18 @@ Popup {
property string secondButt: "add" property string secondButt: "add"
property var listData: speedBackend.getAthletes() property var listData: speedBackend.getAthletes()
function loadData() {
profileList.enabled = false
listData = speedBackend.getAthletes()
profileList.enabled = true
}
model: listData.length model: listData.length
Connections { Connections {
target: root target: root
onOpened: { onOpened: {
listData = speedBackend.getAthletes() profileList.loadData()
} }
} }
@ -120,8 +126,13 @@ Popup {
delegate: SwipeDelegate { delegate: SwipeDelegate {
id: swipeDelegate id: swipeDelegate
property bool active: profileList.listData[index]["active"]
text: profileList.listData[index]["fullName"] text: profileList.listData[index]["fullName"]
width: profileList.width width: profileList.width - (swipeDelegate.x)
font.pixelSize: profiles_stack.text_pixelSize font.pixelSize: profiles_stack.text_pixelSize
@ -129,8 +140,14 @@ Popup {
removeAnim.start() removeAnim.start()
} }
onClicked: {
if(speedBackend.selectAthlete(profileList.listData[index]["userName"])){
profileList.loadData()
}
}
background: Rectangle { background: Rectangle {
color: pressed ? Qt.darker("white", 1.1):"white" color: Qt.darker( pressed ? Qt.darker("white", 1.1):"white", swipeDelegate.active ? 1.1:0 )
} }
@ -154,32 +171,6 @@ Popup {
onStopped: profileModel.model.remove(index) onStopped: profileModel.model.remove(index)
} }
Component {
id: component
Rectangle {
color: mouseAr.pressed ? "#333" : "#444"
width: parent.width
height: parent.height
clip: true
Label {
text: qsTr("Press me!")
color: "#21be2b"
anchors.centerIn: parent
}
MouseArea {
id: mouseAr
anchors.fill: parent
onClicked: {
swipeDelegate.remove()
}
}
}
}
swipe.transition: Transition { swipe.transition: Transition {
SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic }
} }
@ -188,20 +179,6 @@ Popup {
anchors.left: parent.left anchors.left: parent.left
height: parent.height height: parent.height
Label {
id: moveLabel
text: qsTr("Move")
color: "white"
verticalAlignment: Label.AlignVCenter
padding: 12
height: parent.height
SwipeDelegate.onClicked: console.log("Moving...")
background: Rectangle {
color: moveLabel.SwipeDelegate.pressed ? Qt.darker("#ffbf47", 1.1) : "#ffbf47"
}
}
Label { Label {
id: deleteLabel id: deleteLabel
text: qsTr("Delete") text: qsTr("Delete")
@ -210,7 +187,11 @@ Popup {
padding: 12 padding: 12
height: parent.height height: parent.height
SwipeDelegate.onClicked: console.log("Deleting...") SwipeDelegate.onClicked: {
if(speedBackend.deleteAthlete(profileList.listData[index]["userName"])){
profileList.loadData()
}
}
background: Rectangle { background: Rectangle {
color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato" color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato"
@ -218,6 +199,7 @@ Popup {
} }
} }
} }
ScrollIndicator.vertical: ScrollIndicator { } ScrollIndicator.vertical: ScrollIndicator { }
} }
@ -230,16 +212,37 @@ Popup {
property string title: "add profile" property string title: "add profile"
property string secondButt: "ok" property string secondButt: "ok"
property string newProfileName: "" property string newProfileName: ""
Connections {
target: head_add
enabled: true
onClicked: {
if(speedBackend.createAthlete(userNameTf.text, fullNameTf.text)){
profiles_stack.pop()
}
}
}
TextField { TextField {
id: fullNameTf
width: parent.width width: parent.width
placeholderText: "name" placeholderText: "full name"
onTextChanged: {
parent.newProfileName = text
}
Keys.onReturnPressed: {
}
}
TextField {
id: userNameTf
width: parent.width
placeholderText: "username"
onTextChanged: { onTextChanged: {
parent.newProfileName = text parent.newProfileName = text
} }
Keys.onReturnPressed: { Keys.onReturnPressed: {
if(profileModel.model.append(text)){
profiles_stack.pop()
}
} }
} }
} }
@ -430,9 +433,7 @@ Popup {
profiles_stack.push(addProfileComp) profiles_stack.push(addProfileComp)
break break
case "ok": case "ok":
if(profileModel.model.append(profiles_stack.currentItem.newProfileName)){ //speedBackend.createAthlete(fullNameTf.text, userNameTf.text)
profiles_stack.pop()
}
} }
} }

View file

@ -58,6 +58,7 @@ Window {
onStateChanged: { onStateChanged: {
var stateString var stateString
console.log("race state changed to: " + state)
switch (state){ switch (state){
case 0: case 0:
stateString = "IDLE" stateString = "IDLE"
@ -147,7 +148,7 @@ Window {
Behavior on text { Behavior on text {
FadeAnimation{ FadeAnimation{
target: topLa target: topLa
fadeDuration: 200 fadeDuration: 100
} }
} }
} }
@ -729,6 +730,11 @@ Window {
from: "STARTING" from: "STARTING"
to: "RUNNING" to: "RUNNING"
//disable transitions for the RUNNING state //disable transitions for the RUNNING state
},
Transition {
from: "RUNNING"
to: "WAITING"
//disable transitions for the RUNNING state
} }
] ]

View file

@ -445,6 +445,74 @@ bool ClimbingRace::refreshRemoteTimers() {
} }
} }
// - athlete management -
QVariant ClimbingRace::getAthletes() {
QVariantMap reply = this->baseConn->sendCommand(4003);
if(reply["status"] != 200){
//handle Error!!
qDebug() << "+ --- error getting athletes: " << reply["status"];
return false;
}
QVariantList tmpAthletes = reply["data"].toList();
qDebug() << tmpAthletes;
return tmpAthletes;
}
bool ClimbingRace::createAthlete(QString userName, QString fullName) {
QVariant requestData = QVariantMap({{"fullName", fullName}, {"userName", userName}});
QVariantMap reply = this->baseConn->sendCommand(4001, requestData.toJsonValue());
if(reply["status"] != 200){
//handle Error!!
qDebug() << "+ --- error creating athlete: " << reply["status"];
return false;
}
return true;
}
bool ClimbingRace::deleteAthlete( QString userName ){
QVariant requestData = QVariantMap({{"userName", userName}});
QVariantMap reply = this->baseConn->sendCommand(4002, requestData.toJsonValue());
if(reply["status"] != 200){
//handle Error!!
qDebug() << "+ --- error deleting athlete: " << reply["status"];
return false;
}
return true;
}
bool ClimbingRace::selectAthlete( QString userName){
QVariant requestData = QVariantMap({{"userName", userName}});
QVariantMap reply = this->baseConn->sendCommand(4000, requestData.toJsonValue());
if(reply["status"] != 200){
//handle Error!!
qDebug() << "+ --- error deleting athlete: " << reply["status"];
return false;
}
return true;
}
// ------------------------- // -------------------------
// --- functions for qml --- // --- functions for qml ---
// ------------------------- // -------------------------
@ -515,21 +583,6 @@ QVariant ClimbingRace::getBaseStationConnections() {
return baseConn->getConnections(); return baseConn->getConnections();
} }
QVariant ClimbingRace::getAthletes() {
QVariantMap reply = this->baseConn->sendCommand(4003);
if(reply["status"] != 200){
//handle Error!!
qDebug() << "+ --- error getting athletes: " << reply["status"];
return false;
}
QVariantList tmpAthletes = reply["data"].toList();
qDebug() << tmpAthletes;
return tmpAthletes;
}
bool ClimbingRace::reloadBaseStationIpAdress() { bool ClimbingRace::reloadBaseStationIpAdress() {
if(this->baseConn->state == "disconnected"){ if(this->baseConn->state == "disconnected"){

View file

@ -99,6 +99,8 @@ QString SpeedTimer::getState(){
return("IDLE"); return("IDLE");
case STARTING: case STARTING:
return("STARTING"); return("STARTING");
case WAITING:
return ("WAITING");
case RUNNING: case RUNNING:
return("RUNNING"); return("RUNNING");
case STOPPED: case STOPPED: