ORE Studio 0.0.4
Loading...
Searching...
No Matches
ClientTenantModel.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2026 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_CLIENT_TENANT_MODEL_HPP
21#define ORES_QT_CLIENT_TENANT_MODEL_HPP
22
23#include <vector>
24#include <QSize>
25#include <QFutureWatcher>
26#include <QAbstractTableModel>
27#include "ores.qt/AbstractClientModel.hpp"
28#include "ores.qt/ClientManager.hpp"
29#include "ores.qt/RecencyPulseManager.hpp"
30#include "ores.qt/RecencyTracker.hpp"
31#include "ores.qt/ColumnMetadata.hpp"
32#include "ores.logging/make_logger.hpp"
33#include "ores.iam.api/domain/tenant.hpp"
34
35namespace ores::qt {
36
44 Q_OBJECT
45
46private:
47 inline static std::string_view logger_name =
48 "ores.qt.client_tenant_model";
49
50 [[nodiscard]] static auto& lg() {
51 using namespace ores::logging;
52 static auto instance = make_logger(logger_name);
53 return instance;
54 }
55
56public:
60 enum Column {
61 Code,
62 Name,
63 Type,
64 Hostname,
65 Status,
66 Version,
67 ModifiedBy,
68 RecordedAt,
69 ColumnCount
70 };
71
77 static constexpr std::size_t kColumnCount = std::size_t(ColumnCount);
78 static constexpr std::array<ColumnMetadata, kColumnCount> kColumns = {{
79 {
80 .column = Code,
81 .header = std::string_view("Code"),
83 .hidden_by_default = false,
84 .default_width = kColumnWidthAuto
85 },
86 {
87 .column = Name,
88 .header = std::string_view("Name"),
90 .hidden_by_default = false,
91 .default_width = kColumnWidthAuto
92 },
93 {
94 .column = Type,
95 .header = std::string_view("Type"),
97 .hidden_by_default = false,
98 .default_width = kColumnWidthAuto
99 },
100 {
101 .column = Hostname,
102 .header = std::string_view("Hostname"),
104 .hidden_by_default = false,
105 .default_width = kColumnWidthAuto
106 },
107 {
108 .column = Status,
109 .header = std::string_view("Status"),
111 .hidden_by_default = false,
112 .default_width = kColumnWidthAuto
113 },
114 {
115 .column = Version,
116 .header = std::string_view("Version"),
118 .hidden_by_default = false,
119 .default_width = 70
120 },
121 {
122 .column = ModifiedBy,
123 .header = std::string_view("Modified By"),
125 .hidden_by_default = false,
126 .default_width = kColumnWidthAuto
127 },
128 {
129 .column = RecordedAt,
130 .header = std::string_view("Recorded At"),
132 .hidden_by_default = false,
133 .default_width = kColumnWidthAuto
134 },
135 }};
136
140 inline static const QSize kDefaultWindowSize = {900, 400};
141
145 static constexpr std::string_view kSettingsGroup = "TenantListWindow";
146
150 static std::vector<column_style> const& columnStyles() {
151 static std::vector<column_style> const kStylesVector = []() {
152 std::vector<column_style> result;
153 result.reserve(kColumnCount);
154 for (std::size_t i = 0; i < kColumnCount; ++i)
155 result.push_back(kColumns[i].style);
156 return result;
157 }();
158 return kStylesVector;
159 }
160
164 static QVector<int> defaultHiddenColumns() {
165 static QVector<int> const result =
166 ::ores::qt::defaultHiddenColumns<kColumnCount>(kColumns);
167 return result;
168 }
169
170 explicit ClientTenantModel(ClientManager* clientManager,
171 QObject* parent = nullptr);
172 ~ClientTenantModel() override = default;
173
174 // QAbstractTableModel interface
175 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
176 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
177 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
178 QVariant headerData(int section, Qt::Orientation orientation,
179 int role = Qt::DisplayRole) const override;
180
184 void refresh();
185
192 const iam::domain::tenant* getTenant(int row) const;
193
194signals:
203private slots:
204 void onTenantsLoaded();
205 void onPulseStateChanged(bool isOn);
206 void onPulsingComplete();
207
208private:
209 QVariant recency_foreground_color(const std::string& code) const;
210
211 struct FetchResult {
212 bool success;
213 std::vector<iam::domain::tenant> tenants;
214 QString error_message;
215 QString error_details;
216 };
217
218 ClientManager* clientManager_;
219 std::vector<iam::domain::tenant> tenants_;
220 QFutureWatcher<FetchResult>* watcher_;
221 bool is_fetching_{false};
222
223 using TenantKeyExtractor = std::string(*)(const iam::domain::tenant&);
224 RecencyTracker<iam::domain::tenant, TenantKeyExtractor> recencyTracker_;
225 RecencyPulseManager* pulseManager_;
226};
227
228}
229
230#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
constexpr int kColumnWidthAuto
Sentinel value for column default width meaning "auto-size to contents".
Definition ColumnMetadata.hpp:37
@ mono_center
Monospace, centered.
@ text_left
Proportional font, left-aligned (default).
@ mono_left
Monospace, left-aligned.
A tenant representing an isolated organisation or the system platform.
Definition tenant.hpp:43
Base class for all client-side entity models.
Definition AbstractClientModel.hpp:36
Manages the lifecycle of the NATS client and login state.
Definition ClientManager.hpp:109
Model for displaying tenants fetched from the server.
Definition ClientTenantModel.hpp:43
static constexpr std::string_view kSettingsGroup
Settings group name for persisting window and column state.
Definition ClientTenantModel.hpp:145
const iam::domain::tenant * getTenant(int row) const
Get tenant at the specified row.
Definition ClientTenantModel.cpp:206
static constexpr std::size_t kColumnCount
Column metadata: header text, style, visibility, and width.
Definition ClientTenantModel.hpp:77
static const QSize kDefaultWindowSize
Default window size for the tenant list window.
Definition ClientTenantModel.hpp:140
static std::vector< column_style > const & columnStyles()
Returns a static vector of column styles (built once per process).
Definition ClientTenantModel.hpp:150
void refresh()
Refresh tenant data from server asynchronously.
Definition ClientTenantModel.cpp:135
static QVector< int > defaultHiddenColumns()
Returns a static QVector of hidden column indices (built once per process).
Definition ClientTenantModel.hpp:164
Column
Enumeration of table columns for type-safe column access.
Definition ClientTenantModel.hpp:60