native: add license screen

This commit is contained in:
Johannes Jöns 2024-07-11 18:34:40 +02:00
parent 8d90d84733
commit d4744976e2
3 changed files with 138 additions and 10 deletions

104
native/AddData.qml Normal file
View file

@ -0,0 +1,104 @@
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Layouts 2.15
import QtQuick.Controls 2.15
Window {
SystemPalette { id: activeColors; colorGroup: SystemPalette.Active }
SystemPalette { id: inactiveColors; colorGroup: SystemPalette.Inactive }
SystemPalette { id: disabledColors; colorGroup: SystemPalette.Disabled }
function getColors() {
return dataScreen.active ? activeColors : inactiveColors;
}
id: dataScreen
width: 640
height: 480
visible: true
color: getColors().window
title: qsTr("Alisa - Add License")
property string authToken: ""
TextField {
id: nameT
anchors {
horizontalCenter: parent.horizontalCenter
topMargin: 5
top: parent.top // Assuming there's no loginL defined in your code
}
placeholderText: qsTr("Name")
Keys.onReturnPressed: keyT.focus = true
}
TextField {
id: keyT
anchors {
horizontalCenter: parent.horizontalCenter
topMargin: 5
top: nameT.bottom
}
placeholderText: qsTr("Key")
Keys.onReturnPressed: amountT.focus = true
}
TextField {
id: amountT
anchors {
horizontalCenter: parent.horizontalCenter
topMargin: 5
top: keyT.bottom
}
placeholderText: qsTr("Amount")
inputMethodHints: Qt.ImhDigitsOnly
validator: DoubleValidator {
bottom: 0
top: 1000000
}
onTextChanged: {
text = text.replace(/[^0-9]/g, "")
}
Keys.onReturnPressed: submitB.focus = true
}
Button {
id: submitB
anchors {
horizontalCenter: parent.horizontalCenter
topMargin: 5
top: amountT.bottom
}
text: qsTr("Submit")
onClicked: submit()
Keys.onReturnPressed: submit()
}
function submit() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://api.clan-war.net/api/v1/licenses");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "Bearer " + authToken);
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status != 200) {
console.log("Submission failed: " + xhr.status);
}
}
}
var data = JSON.stringify({
name: nameT.text,
key: keyT.text,
amount: parseInt(amountT.text),
group_id: "f7604976-1e3c-49b7-841b-6a4025257c70",
});
xhr.send(data);
}
}

View file

@ -20,11 +20,10 @@ qt_add_qml_module(alisa
Test.qml Test.qml
MainPage.qml MainPage.qml
LoginScreen.qml LoginScreen.qml
AddData.qml
RESOURCES RESOURCES
Assets/Icons/turbo.svg Assets/Icons/turbo.svg
) )
set_target_properties(alisa PROPERTIES set_target_properties(alisa PROPERTIES

View file

@ -27,19 +27,18 @@ Rectangle {
color: getColors().midlight color: getColors().midlight
TextField { TextField {
anchors{ anchors {
verticalCenter: s1.verticalCenter verticalCenter: s1.verticalCenter
rightMargin: 5 rightMargin: 5
right: loginB.left right: loginB.left
} }
placeholderText: qsTr("Search") placeholderText: qsTr("Search")
} }
Button{ Button {
id: loginB id: loginB
anchors{ anchors {
verticalCenter: s1.verticalCenter verticalCenter: s1.verticalCenter
rightMargin: 10 rightMargin: 10
right: s1.right right: s1.right
@ -50,9 +49,27 @@ Rectangle {
logout(); logout();
} }
} }
Button {
text: qsTr("Add License")
anchors {
verticalCenter: s1.verticalCenter
rightMargin: 10
right: loginB.left
}
onClicked: {
// Create and show a new window
var newWindow = newWindowComponent.createObject(null, { authToken: authToken });
if (newWindow !== null) {
newWindow.show();
} else {
console.log("Failed to create new window");
}
}
}
} }
Rectangle{ Rectangle {
id: s2 id: s2
anchors { anchors {
top: s1.bottom top: s1.bottom
@ -113,6 +130,14 @@ Rectangle {
} }
} }
Component {
id: newWindowComponent
AddData {
id: dataWindow
authToken: authToken
}
}
Component.onCompleted: { Component.onCompleted: {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.clan-war.net/api/v1/licenses"); xhr.open("GET", "https://api.clan-war.net/api/v1/licenses");