Compare commits

...

3 commits

Author SHA1 Message Date
4306f561a6 native: add search support 2024-07-11 22:08:06 +02:00
8a6ba829c0 native: add table header 2024-07-11 22:08:06 +02:00
e2ca009d35 native: make table nice 2024-07-11 22:08:06 +02:00
2 changed files with 103 additions and 75 deletions

View file

@ -96,7 +96,7 @@ Window {
name: nameT.text, name: nameT.text,
key: keyT.text, key: keyT.text,
amount: parseInt(amountT.text), amount: parseInt(amountT.text),
group_id: "f7604976-1e3c-49b7-841b-6a4025257c70", group_id: "ff664d29-68c9-45c2-a6bc-8f378876c90d",
}); });
xhr.send(data); xhr.send(data);

View file

@ -4,6 +4,8 @@ import QtQuick.Layouts 2.15
import QtQuick.Controls 2.15 import QtQuick.Controls 2.15
Rectangle { Rectangle {
visible: true
SystemPalette { id: activeColors; colorGroup: SystemPalette.Active } SystemPalette { id: activeColors; colorGroup: SystemPalette.Active }
SystemPalette { id: inactiveColors; colorGroup: SystemPalette.Inactive } SystemPalette { id: inactiveColors; colorGroup: SystemPalette.Inactive }
SystemPalette { id: disabledColors; colorGroup: SystemPalette.Disabled } SystemPalette { id: disabledColors; colorGroup: SystemPalette.Disabled }
@ -13,6 +15,7 @@ Rectangle {
} }
property string authToken: "" property string authToken: ""
property string searchText: "" // Property to hold the search text
signal logout() signal logout()
@ -26,44 +29,42 @@ Rectangle {
height: 50 height: 50
color: getColors().midlight color: getColors().midlight
TextField { RowLayout {
anchors { anchors.fill: parent
verticalCenter: s1.verticalCenter spacing: 10
rightMargin: 5 anchors.margins: 5
right: loginB.left
TextField {
id: searchField
placeholderText: qsTr("Search")
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
onTextChanged: {
searchText = text
filterModel() // Filter model based on search text
}
} }
placeholderText: qsTr("Search") Button {
} text: qsTr("Add License")
Layout.alignment: Qt.AlignVCenter
Button { onClicked: {
id: loginB // Create and show a new window
anchors { var newWindow = newWindowComponent.createObject(null, { authToken: authToken });
verticalCenter: s1.verticalCenter if (newWindow !== null) {
rightMargin: 10 newWindow.show();
right: s1.right } else {
console.log("Failed to create new window");
}
}
} }
text: qsTr("Logout")
onClicked: { Button {
logout(); id: loginB
} text: qsTr("Logout")
} Layout.alignment: Qt.AlignVCenter
onClicked: {
Button { logout();
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");
} }
} }
} }
@ -79,54 +80,65 @@ Rectangle {
} }
color: getColors().window color: getColors().window
ListModel { ColumnLayout {
id: apiDataModel anchors.fill: parent
} spacing: 0
ListView { Rectangle {
anchors { id: header
topMargin: 5 color: getColors().midlight
fill: s2 height: 40
} Layout.fillWidth: true
clip: true
boundsBehavior: Flickable.StopAtBounds
model: apiDataModel RowLayout {
anchors.fill: parent
delegate: Item {
width: parent.width
height: 50
Row {
spacing: 10 spacing: 10
anchors.margins: 5
Text { Text { text: qsTr("Name"); color: getColors().text; Layout.fillWidth: true }
text: model.name Text { text: qsTr("Key"); color: getColors().text; Layout.fillWidth: true }
color: getColors().text Text { text: qsTr("Amount"); color: getColors().text; Layout.fillWidth: true }
} Text { text: qsTr("Start"); color: getColors().text; Layout.fillWidth: true }
Text { text: qsTr("End"); color: getColors().text; Layout.fillWidth: true }
Text { text: qsTr("Group"); color: getColors().text; Layout.fillWidth: true }
}
}
Text { ListView {
text: model.key id: listView
color: getColors().text Layout.fillWidth: true
} Layout.fillHeight: true
Text { clip: true
text: model.amount boundsBehavior: Flickable.StopAtBounds
color: getColors().text model: filteredApiDataModel // Use the filtered model
}
Text { delegate: Rectangle {
text: model.start width: listView.width
color: getColors().text height: 50
} color: getColors().button
Text {
text: model.end RowLayout {
color: getColors().text anchors.fill: parent
} spacing: 10
Text { anchors.margins: 5
text: model.group
color: getColors().text Text { text: model.name; color: getColors().text; Layout.fillWidth: true }
Text { text: model.key; color: getColors().text; Layout.fillWidth: true }
Text { text: model.amount; color: getColors().text; Layout.fillWidth: true }
Text { text: model.start; color: getColors().text; Layout.fillWidth: true }
Text { text: model.end; color: getColors().text; Layout.fillWidth: true }
Text { text: model.group; color: getColors().text; Layout.fillWidth: true }
} }
} }
} }
ListModel {
id: apiDataModel
}
ListModel {
id: filteredApiDataModel
}
} }
} }
@ -160,6 +172,7 @@ Rectangle {
}); });
} }
} }
filterModel() // Filter the model after loading data
} else { } else {
console.log("Error: " + xhr.status); console.log("Error: " + xhr.status);
} }
@ -167,4 +180,19 @@ Rectangle {
} }
xhr.send(); xhr.send();
} }
function filterModel() {
filteredApiDataModel.clear()
for (var i = 0; i < apiDataModel.count; ++i) {
var item = apiDataModel.get(i)
if (item.name.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 ||
item.key.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 ||
item.amount.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 ||
item.start.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 ||
item.end.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 ||
item.group.toLowerCase().indexOf(searchText.toLowerCase()) !== -1) {
filteredApiDataModel.append(item)
}
}
}
} }