Skip to content

Commit

Permalink
added search bar for client management page
Browse files Browse the repository at this point in the history
  • Loading branch information
Nethius committed Nov 23, 2023
1 parent e8ceeb6 commit 5dc3b64
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 36 deletions.
6 changes: 6 additions & 0 deletions client/images/controls/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions client/images/controls/search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions client/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,7 @@
<file>server_scripts/awg/run_container.sh</file>
<file>server_scripts/awg/Dockerfile</file>
<file>ui/qml/Pages2/PageShareFullAccess.qml</file>
<file>images/controls/close.svg</file>
<file>images/controls/search.svg</file>
</qresource>
</RCC>
8 changes: 8 additions & 0 deletions client/ui/controllers/exportController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ void ExportController::exportConfig(const QString &fileName)
SystemController::saveFile(fileName, m_config);
}

void ExportController::updateClientManagementModel(const DockerContainer container, ServerCredentials credentials)
{
ErrorCode errorCode = m_clientManagementModel->updateModel(container, credentials);
if (errorCode != ErrorCode::NoError) {
emit exportErrorOccurred(errorString(errorCode));
}
}

void ExportController::revokeConfig(const int row, const DockerContainer container, ServerCredentials credentials)
{
ErrorCode errorCode = m_clientManagementModel->revokeClient(row, container, credentials);
Expand Down
1 change: 1 addition & 0 deletions client/ui/controllers/exportController.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public slots:

void exportConfig(const QString &fileName);

void updateClientManagementModel(const DockerContainer container, ServerCredentials credentials);
void revokeConfig(const int row, const DockerContainer container, ServerCredentials credentials);
void renameClient(const int row, const QString &clientName, const DockerContainer container, ServerCredentials credentials);

Expand Down
13 changes: 5 additions & 8 deletions client/ui/models/clientManagementModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ QVariant ClientManagementModel::data(const QModelIndex &index, int role) const

switch (role) {
case ClientNameRole: return userData.value(configKey::clientName).toString();
case ContainerNameRole:
return ContainerProps::containerHumanNames().value(
static_cast<DockerContainer>(userData.value(configKey::container).toInt()));
}

return QVariant();
}

ErrorCode ClientManagementModel::updateModel(DockerContainer container, ServerCredentials credentials)
{
beginResetModel();
m_clientsTable = QJsonArray();

ServerController serverController(m_settings);

ErrorCode error = ErrorCode::NoError;
Expand All @@ -60,10 +60,10 @@ ErrorCode ClientManagementModel::updateModel(DockerContainer container, ServerCr
serverController.getTextFileFromContainer(container, credentials, clientsTableFile, &error);
if (error != ErrorCode::NoError) {
logger.error() << "Failed to get the clientsTable file from the server";
endResetModel();
return error;
}

beginResetModel();
m_clientsTable = QJsonDocument::fromJson(clientsTableString).array();

if (m_clientsTable.isEmpty()) {
Expand All @@ -76,6 +76,7 @@ ErrorCode ClientManagementModel::updateModel(DockerContainer container, ServerCr
error = getWireGuardClients(serverController, container, credentials, count);
}
if (error != ErrorCode::NoError) {
endResetModel();
return error;
}

Expand Down Expand Up @@ -124,7 +125,6 @@ ErrorCode ClientManagementModel::getOpenVpnClients(ServerController &serverContr

QJsonObject userData;
userData[configKey::clientName] = QString("Client %1").arg(count);
userData[configKey::container] = container;
client[configKey::userData] = userData;

m_clientsTable.push_back(client);
Expand Down Expand Up @@ -165,7 +165,6 @@ ErrorCode ClientManagementModel::getWireGuardClients(ServerController &serverCon

QJsonObject userData;
userData[configKey::clientName] = QString("Client %1").arg(count);
userData[configKey::container] = container;
client[configKey::userData] = userData;

m_clientsTable.push_back(client);
Expand Down Expand Up @@ -211,7 +210,6 @@ ErrorCode ClientManagementModel::appendClient(const QString &clientId, const QSt

QJsonObject userData;
userData[configKey::clientName] = clientName;
userData[configKey::container] = container;
client[configKey::userData] = userData;
m_clientsTable.push_back(client);
endResetModel();
Expand Down Expand Up @@ -371,6 +369,5 @@ QHash<int, QByteArray> ClientManagementModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[ClientNameRole] = "clientName";
roles[ContainerNameRole] = "containerName";
return roles;
}
17 changes: 0 additions & 17 deletions client/ui/models/clientManagementModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,9 @@ class ClientManagementModel : public QAbstractListModel
{
Q_OBJECT

struct ClientManagementData
{
QString userId;
QJsonObject userData;

bool operator==(const ClientManagementData &r) const
{
return userId == r.userId;
}

bool operator==(const QString &otherUserId) const
{
return userId == otherUserId;
}
};

public:
enum Roles {
ClientNameRole = Qt::UserRole + 1,
ContainerNameRole,
};

ClientManagementModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
Expand Down
1 change: 1 addition & 0 deletions client/ui/qml/Controls2/SwitcherType.qml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Switch {
id: content

anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left

ListItemTitleType {
Layout.fillWidth: true
Expand Down
64 changes: 53 additions & 11 deletions client/ui/qml/Pages2/PageShare.qml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ PageType {
}
}

property bool isSearchBarVisible: false
property bool showContent: false
property bool shareButtonEnabled: true
property list<QtObject> connectionTypesModel: [
Expand Down Expand Up @@ -205,8 +206,8 @@ PageType {
onClicked: {
accessTypeSelector.currentIndex = 1
PageController.showBusyIndicator(true)
ClientManagementModel.updateModel(ContainersModel.getCurrentlyProcessedContainerIndex(),
ServersModel.getCurrentlyProcessedServerCredentials())
ExportController.updateClientManagementModel(ContainersModel.getCurrentlyProcessedContainerIndex(),
ServersModel.getCurrentlyProcessedServerCredentials())
PageController.showBusyIndicator(false)
}
}
Expand Down Expand Up @@ -354,12 +355,12 @@ PageType {

ContainersModel.setCurrentlyProcessedContainerIndex(proxyContainersModel.mapToSource(currentIndex))

if (accessTypeSelector.currentIndex === 0) {
fillConnectionTypeModel()
} else {
fillConnectionTypeModel()

if (accessTypeSelector.currentIndex === 1) {
PageController.showBusyIndicator(true)
ClientManagementModel.updateModel(ContainersModel.getCurrentlyProcessedContainerIndex(),
ServersModel.getCurrentlyProcessedServerCredentials())
ExportController.updateClientManagementModel(ContainersModel.getCurrentlyProcessedContainerIndex(),
ServersModel.getCurrentlyProcessedServerCredentials())
PageController.showBusyIndicator(false)
}
}
Expand Down Expand Up @@ -444,9 +445,36 @@ PageType {
Layout.topMargin: 24
Layout.bottomMargin: 16

visible: accessTypeSelector.currentIndex === 1
visible: accessTypeSelector.currentIndex === 1 && !root.isSearchBarVisible

headerText: qsTr("Users")
actionButtonImage: "qrc:/images/controls/search.svg"
actionButtonFunction: function() {
root.isSearchBarVisible = true
}
}

RowLayout {
Layout.topMargin: 24
Layout.bottomMargin: 16
visible: accessTypeSelector.currentIndex === 1 && root.isSearchBarVisible

TextFieldWithHeaderType {
id: searchTextField
Layout.fillWidth: true

textFieldPlaceholderText: qsTr("Search")
}

ImageButtonType {
image: "qrc:/images/controls/close.svg"
imageColor: "#D7D8DB"

onClicked: function() {
root.isSearchBarVisible = false
searchTextField.textFieldText = ""
}
}
}

ListView {
Expand All @@ -456,7 +484,15 @@ PageType {

visible: accessTypeSelector.currentIndex === 1

model: ClientManagementModel
model: SortFilterProxyModel {
id: proxyClientManagementModel
sourceModel: ClientManagementModel
filters: RegExpFilter {
roleName: "clientName"
pattern: ".*" + searchTextField.textFieldText + ".*"
caseSensitivity: Qt.CaseInsensitive
}
}

clip: true
interactive: false
Expand All @@ -479,7 +515,6 @@ PageType {
Layout.fillWidth: true

text: clientName
descriptionText: containerName
rightImageSource: "qrc:/images/controls/chevron-right.svg"

clickedFunction: function() {
Expand Down Expand Up @@ -510,7 +545,7 @@ PageType {
Layout.bottomMargin: 24

headerText: clientName
descriptionText: serverSelector.text + ", " + containerName
descriptionText: serverSelector.text
}

BasicButtonType {
Expand Down Expand Up @@ -620,4 +655,11 @@ PageType {
}
}
}
MouseArea {
anchors.fill: parent
onPressed: function(mouse) {
forceActiveFocus()
mouse.accepted = false
}
}
}

0 comments on commit 5dc3b64

Please sign in to comment.