From 525158d5b49b3c769bdc0c765f6cc6d8b2c447a4 Mon Sep 17 00:00:00 2001 From: pumpkin Date: Thu, 11 Jul 2024 11:05:07 +0200 Subject: [PATCH 1/9] native: fix typos --- native/Main.qml | 2 +- native/MainPage.qml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/native/Main.qml b/native/Main.qml index cff0dbb..5f878ab 100644 --- a/native/Main.qml +++ b/native/Main.qml @@ -18,7 +18,7 @@ Window { visible: true color: getColors().window - title: qsTr("Alisa - License Managment") + title: qsTr("Alisa - License Management") property string authToken: "" diff --git a/native/MainPage.qml b/native/MainPage.qml index 1d6fba3..399697a 100644 --- a/native/MainPage.qml +++ b/native/MainPage.qml @@ -29,15 +29,15 @@ Rectangle { anchors{ verticalCenter: s1.verticalCenter rightMargin: 5 - right: logginB.left + right: loginB.left } - placeholderText: qsTr("Seach") + placeholderText: qsTr("Search") } Button{ - id: logginB + id: loginB anchors{ verticalCenter: s1.verticalCenter rightMargin: 10 From dabf39fa9a31aa49116275d95df54b7bf68cc737 Mon Sep 17 00:00:00 2001 From: jopejoe1 Date: Thu, 11 Jul 2024 11:12:45 +0200 Subject: [PATCH 2/9] native: make login page part of window --- native/LoginScreen.qml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/native/LoginScreen.qml b/native/LoginScreen.qml index d3a509c..01d9da0 100644 --- a/native/LoginScreen.qml +++ b/native/LoginScreen.qml @@ -4,7 +4,7 @@ import QtQuick.Controls.Basic -Window { +Rectangle { SystemPalette { id: activeColors; colorGroup: SystemPalette.Active } SystemPalette { id: inactiveColors; colorGroup: SystemPalette.Inactive } @@ -14,9 +14,6 @@ Window { return root.active ? activeColors : inactiveColors; } - - width: 400 - height: 400 visible: true signal loginSuccess(string token) From 0b76f3472d64befb7235df48d79029316ec34582 Mon Sep 17 00:00:00 2001 From: jopejoe1 Date: Thu, 11 Jul 2024 11:25:08 +0200 Subject: [PATCH 3/9] native: fix logout button --- native/Main.qml | 3 +++ native/MainPage.qml | 12 +++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/native/Main.qml b/native/Main.qml index 5f878ab..ca58216 100644 --- a/native/Main.qml +++ b/native/Main.qml @@ -42,6 +42,9 @@ Window { id: mainPageComponent MainPage { authToken: authToken + onLogout: { + stackView.push(loginPageComponent) + } } } } diff --git a/native/MainPage.qml b/native/MainPage.qml index 399697a..e42c572 100644 --- a/native/MainPage.qml +++ b/native/MainPage.qml @@ -14,6 +14,8 @@ Rectangle { property string authToken: "" + signal logout() + Rectangle { id: s1 anchors { @@ -43,12 +45,10 @@ Rectangle { rightMargin: 10 right: s1.right } - text: qsTr("Login") + text: qsTr("Logout") onClicked: { - var component = Qt.createComponent("LoginScreen.qml") - var window = component.createObject(root) - window.show() + logout(); } } } @@ -122,9 +122,7 @@ Rectangle { } text: qsTr("Login Screen") onClicked: { - var component = Qt.createComponent("LoginScreen.qml") - var window = component.createObject(root) - window.show() + logout(); } } } From 1b413df4339f83df8409a74099aa99e59b50a721 Mon Sep 17 00:00:00 2001 From: Mika Date: Thu, 11 Jul 2024 11:26:19 +0200 Subject: [PATCH 4/9] web: implement dropdown for select group --- web/src/components/HeaderBar.vue | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/web/src/components/HeaderBar.vue b/web/src/components/HeaderBar.vue index 1ff12cd..7a25461 100644 --- a/web/src/components/HeaderBar.vue +++ b/web/src/components/HeaderBar.vue @@ -112,6 +112,19 @@ variant="outlined" clearable > + all fields marked with * are required From ffae1c2ed7aecfd8ba838296e6f961c592b34a1f Mon Sep 17 00:00:00 2001 From: Schnitzel Date: Thu, 11 Jul 2024 11:37:44 +0200 Subject: [PATCH 5/9] native: mainPage.qml del button loginPage --- native/MainPage.qml | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/native/MainPage.qml b/native/MainPage.qml index e42c572..797ce35 100644 --- a/native/MainPage.qml +++ b/native/MainPage.qml @@ -23,7 +23,6 @@ Rectangle { left: parent.left right: parent.right } - radius: 0 height: 50 color: getColors().midlight @@ -97,26 +96,11 @@ Rectangle { } } - - Button { - id: testB - anchors { - bottom: parent.bottom - left: parent.left - } - text: qsTr("Test Window") - - onClicked: { - var component = Qt.createComponent("Test.qml") - var window = component.createObject(root) - window.show() - } - } Button { id: loginScreenB anchors { - left: testB.right bottom: parent.bottom + left: parent.left } From a6118791b10519e472f9315d93452f05faa63f89 Mon Sep 17 00:00:00 2001 From: jopejoe1 Date: Thu, 11 Jul 2024 11:41:24 +0200 Subject: [PATCH 6/9] native: fix login button fixes #20 --- native/LoginScreen.qml | 36 +++++++++++++++++++----------------- native/Main.qml | 6 +++--- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/native/LoginScreen.qml b/native/LoginScreen.qml index 01d9da0..b3d7e28 100644 --- a/native/LoginScreen.qml +++ b/native/LoginScreen.qml @@ -71,25 +71,27 @@ Rectangle { text: qsTr("Submit") - onClicked: { - var xhr = new XMLHttpRequest(); - xhr.open("POST", "https://api.clan-war.net/api/v1/auth/login"); - xhr.setRequestHeader("Content-Type", "application/json"); - xhr.onreadystatechange = function() { - if (xhr.readyState === XMLHttpRequest.DONE) { - if (xhr.status === 200) { - var token = xhr.responseText.trim(); // Trim to remove any leading/trailing whitespace - loginSuccess(token); - } else { - console.log("Login failed: " + xhr.status); - } + onClicked: login + } + + function login() { + var xhr = new XMLHttpRequest(); + xhr.open("POST", "https://api.clan-war.net/api/v1/auth/login"); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + var token = xhr.responseText.trim(); // Trim to remove any leading/trailing whitespace + loginSuccess(token); + } else { + console.log("Login failed: " + xhr.status); } } - var data = JSON.stringify({ - email: nameT.text, - password: passwordT.text - }); - xhr.send(data); } + var data = JSON.stringify({ + email: nameT.text, + password: passwordT.text + }); + xhr.send(data); } } diff --git a/native/Main.qml b/native/Main.qml index ca58216..cc4bd1d 100644 --- a/native/Main.qml +++ b/native/Main.qml @@ -31,9 +31,9 @@ Window { Component { id: loginPageComponent LoginScreen { - onLoginSuccess: { - authToken = token - stackView.push(mainPageComponent) + onLoginSuccess: function(token) { + authToken = token; + stackView.push(mainPageComponent); } } } From 067402a0fd4126389c0054c7edd49b1528707ea1 Mon Sep 17 00:00:00 2001 From: jopejoe1 Date: Thu, 11 Jul 2024 11:42:50 +0200 Subject: [PATCH 7/9] native: fix submit button --- native/LoginScreen.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/LoginScreen.qml b/native/LoginScreen.qml index b3d7e28..a4ec54d 100644 --- a/native/LoginScreen.qml +++ b/native/LoginScreen.qml @@ -71,7 +71,7 @@ Rectangle { text: qsTr("Submit") - onClicked: login + onClicked: login() } function login() { From b1f2f6507e87e6de265abf0f7d0a104d8d296890 Mon Sep 17 00:00:00 2001 From: jopejoe1 Date: Thu, 11 Jul 2024 11:47:46 +0200 Subject: [PATCH 8/9] native: login screen make enter work --- native/LoginScreen.qml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/native/LoginScreen.qml b/native/LoginScreen.qml index a4ec54d..ab326ad 100644 --- a/native/LoginScreen.qml +++ b/native/LoginScreen.qml @@ -39,25 +39,29 @@ Rectangle { id: nameT anchors{ - horizontalCenter: parent.horizontalCenter - topMargin: 5 - top: loginL.bottom + horizontalCenter: parent.horizontalCenter + topMargin: 5 + top: loginL.bottom } placeholderText: qsTr("Name") + Keys.onReturnPressed: passwordField.focus = true + } TextField { id: passwordT anchors{ - horizontalCenter: parent.horizontalCenter - topMargin: 5 - top: nameT.bottom + horizontalCenter: parent.horizontalCenter + topMargin: 5 + top: nameT.bottom } placeholderText: qsTr("Password") + Keys.onReturnPressed: login() + echoMode: TextInput.Password } From ad7b0f07329a487f20316da3d0801775edc3a1eb Mon Sep 17 00:00:00 2001 From: Mika Date: Thu, 11 Jul 2024 12:19:35 +0200 Subject: [PATCH 9/9] web: refactor add license Co-authored-by: Schmackofatz --- web/src/components/HeaderBar.vue | 104 ++++++++++++++++++++++++++----- web/src/components/MainPage.vue | 43 ++++++------- web/src/types.ts | 14 +++++ 3 files changed, 120 insertions(+), 41 deletions(-) create mode 100644 web/src/types.ts diff --git a/web/src/components/HeaderBar.vue b/web/src/components/HeaderBar.vue index 7a25461..2751807 100644 --- a/web/src/components/HeaderBar.vue +++ b/web/src/components/HeaderBar.vue @@ -76,8 +76,31 @@ :rules="licenseNameRules" class="mb-3" > + + + +
-
+
-
+
@@ -112,19 +137,6 @@ variant="outlined" clearable > - all fields marked with * are required @@ -210,6 +222,32 @@ import { store } from "@/store"; import { SubmitEventPromise } from "vuetify"; import { ref } from "vue"; import { Plus, LogOut, Pencil, FolderPlus } from "lucide-vue-next"; +import { useQuery } from "@tanstack/vue-query"; +import axios from "axios"; +import { LicenseGroup } from "@/types"; + +const { data } = useQuery({ + queryKey: ["licenses"], + queryFn: async () => { + const res = await axios.get( + import.meta.env.VITE_BACKEND_URL + "/licenses", + { + headers: { + Authorization: `Bearer ${store.token}`, + }, + } + ); + return res.data; + }, + select: (data) => { + return data.map((group) => { + return { + title: group.name, + value: group.id, + }; + }); + }, +}); function handlelogout() { store.setToken(null); @@ -217,8 +255,21 @@ function handlelogout() { async function submit(event: SubmitEventPromise) { const result = await event; - console.log(result); + if (result.valid) { + console.log({ + name: addLicenseName.value, + group_id: addLicenseGroup.value, + amount: addAmount.value, + key: addLicenseKey.value, + start: addStartDate.value, + stop: addStopDate.value, + notes: addNotes.value, + }); + } else { + console.log("Invalid"); + } } + // // GROUP SECTION // @@ -226,6 +277,7 @@ async function submit(event: SubmitEventPromise) { const group = ref(false); // Dialog for Group const groupLicenseName = ref(""); +// Rules for Group Dialog const licenseGroupRules = [ (value: string) => { if (value) return true; @@ -239,6 +291,10 @@ const licenseGroupRules = [ const add = ref(false); // References for Add License Dialog const addLicenseName = ref(""); +const addLicenseKey = ref(""); +const addLicenseGroup = ref(); + +// Rules for Add License Dialog const licenseNameRules = [ (value: string) => { if (value) return true; @@ -246,6 +302,22 @@ const licenseNameRules = [ return "YOU MUST ENTER (A LICENSE NAME)"; }, ]; +const selectGroupRules = [ + (value: string) => { + if (value) return true; + + return "YOU MUST SELECT (A LICENSE GROUP)"; + }, +]; + +const licenseKeyRules = [ + (value: string) => { + if (value) return true; + + return "YOU MUST ENTER (A LICENSE KEY)"; + }, +]; +// Optional Fields const addAmount = ref(); const addNotes = ref(""); diff --git a/web/src/components/MainPage.vue b/web/src/components/MainPage.vue index dce2feb..ac102b8 100644 --- a/web/src/components/MainPage.vue +++ b/web/src/components/MainPage.vue @@ -6,7 +6,10 @@
Error: {{ error?.message }}
  • - +
@@ -19,37 +22,27 @@ import CategoryContainer from "./CategoryContainer.vue"; import { useQuery } from "@tanstack/vue-query"; import axios from "axios"; import { store } from "@/store"; +import { LicenseGroup } from "@/types"; -interface LicenseGroup { - id: string, - name: string, - licenses: License[] -} - -interface License { - name: string; - id: string; - start?: Date, - end?: Date, - key: string, - amount?: number, -} - -const {isPending, isError, data, error} = useQuery({ +const { isPending, isError, data, error } = useQuery({ queryKey: ["licenses"], queryFn: async () => { - const res = await axios.get(import.meta.env.VITE_BACKEND_URL + "/licenses", { - headers: { - Authorization: `Bearer ${store.token}` + const res = await axios.get( + import.meta.env.VITE_BACKEND_URL + "/licenses", + { + headers: { + Authorization: `Bearer ${store.token}`, + }, } - }) - return res.data - } -}) + ); + return res.data; + }, +}); diff --git a/web/src/types.ts b/web/src/types.ts new file mode 100644 index 0000000..2454aaf --- /dev/null +++ b/web/src/types.ts @@ -0,0 +1,14 @@ +export interface LicenseGroup { + id: string; + name: string; + licenses: License[]; +} + +export interface License { + name: string; + id: string; + start?: Date; + end?: Date; + key: string; + amount?: number; +}