From 6a7ccbe06f69a5a2e5ecb8105ff27777f063615b Mon Sep 17 00:00:00 2001 From: jopejoe1 Date: Thu, 11 Jul 2024 23:19:24 +0200 Subject: [PATCH] native: add license goup adder --- native/AddGroup.qml | 67 +++++++++++++++++++++++++++++++++++++++++++ native/CMakeLists.txt | 1 + native/MainPage.qml | 26 +++++++++++++++-- 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 native/AddGroup.qml diff --git a/native/AddGroup.qml b/native/AddGroup.qml new file mode 100644 index 0000000..e5dbda2 --- /dev/null +++ b/native/AddGroup.qml @@ -0,0 +1,67 @@ + +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 + visible: true + color: getColors().window + + title: qsTr("Alisa - Add License Group") + + 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: submit() + } + + Button { + id: submitB + anchors { + horizontalCenter: parent.horizontalCenter + topMargin: 5 + top: nameT.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/groups"); + 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, + }); + + xhr.send(data); + } +} diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 1037eb8..6b503ec 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -19,6 +19,7 @@ qt_add_qml_module(alisa MainPage.qml LoginScreen.qml AddData.qml + AddGroup.qml RESOURCES Assets/Icons/turbo.svg diff --git a/native/MainPage.qml b/native/MainPage.qml index 1a159bd..2ee8e7e 100644 --- a/native/MainPage.qml +++ b/native/MainPage.qml @@ -50,7 +50,21 @@ Rectangle { Layout.alignment: Qt.AlignVCenter onClicked: { // Create and show a new window - var newWindow = newWindowComponent.createObject(null, { authToken: authToken }); + var newWindow = addLicenseWindow.createObject(null, { authToken: authToken }); + if (newWindow !== null) { + newWindow.show(); + } else { + console.log("Failed to create new window"); + } + } + } + + Button { + text: qsTr("Add License Group") + Layout.alignment: Qt.AlignVCenter + onClicked: { + // Create and show a new window + var newWindow = addLicenseGroupWindow.createObject(null, { authToken: authToken }); if (newWindow !== null) { newWindow.show(); } else { @@ -148,13 +162,21 @@ Rectangle { } Component { - id: newWindowComponent + id: addLicenseWindow AddData { id: dataWindow authToken: authToken } } + Component { + id: addLicenseGroupWindow + AddGroup { + id: dataWindow + authToken: authToken + } + } + Component.onCompleted: { var xhr = new XMLHttpRequest(); xhr.open("GET", "https://api.clan-war.net/api/v1/licenses");