Skip to content

Commit 8cc964f

Browse files
authored
0.9.0-alpha3 (RedisInsight#3762)
- Add Redis Cluster support - Add Redis Sentinel support - Fix issues with rendering in connections tree - Update translations - Add ability to change language in Settings dialog RedisInsight#3753
1 parent f00eb52 commit 8cc964f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1429
-487
lines changed

src/app/app.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,24 @@ void Application::initUpdater()
206206

207207
void Application::installTranslator()
208208
{
209-
QString locale = QLocale::system().uiLanguages().first().replace( "-", "_" );
209+
QSettings settings;
210+
QString preferredLocale = settings.value("app/locale", "system").toString();
211+
212+
QString locale;
213+
214+
if (preferredLocale == "system") {
215+
settings.setValue("app/locale", "system");
216+
locale = QLocale::system().uiLanguages().first().replace( "-", "_" );
210217

211-
qDebug() << QLocale::system().uiLanguages();
218+
qDebug() << QLocale::system().uiLanguages();
212219

213-
if (locale.isEmpty() || locale == "C")
214-
locale = "en_US";
220+
if (locale.isEmpty() || locale == "C")
221+
locale = "en_US";
215222

216-
qDebug() << "Detected locale:" << locale;
223+
qDebug() << "Detected locale:" << locale;
224+
} else {
225+
locale = preferredLocale;
226+
}
217227

218228
QTranslator* translator = new QTranslator((QObject *)this);
219229
if (translator->load( QString( ":/translations/rdm_" ) + locale ))

src/app/models/treeoperations.cpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,25 @@ void TreeOperations::getDatabases(std::function<void (RedisClient::DatabaseList)
3434

3535
RedisClient::DatabaseList availableDatabeses = m_connection->getKeyspaceInfo();
3636

37-
//detect all databases
38-
RedisClient::Response scanningResp;
39-
int dbIndex = (availableDatabeses.size() == 0)? 0 : availableDatabeses.lastKey() + 1;
40-
41-
while (true) {
42-
try {
43-
scanningResp = m_connection->commandSync("select", QString::number(dbIndex));
44-
} catch (const RedisClient::Connection::Exception& e) {
45-
throw ConnectionsTree::Operations::Exception(QObject::tr("Connection error: ") + QString(e.what()));
37+
if (m_connection->mode() != RedisClient::Connection::Mode::Cluster) {
38+
//detect all databases
39+
RedisClient::Response scanningResp;
40+
int dbIndex = (availableDatabeses.size() == 0)? 0 : availableDatabeses.lastKey() + 1;
41+
42+
while (true) {
43+
try {
44+
scanningResp = m_connection->commandSync("select", QString::number(dbIndex));
45+
} catch (const RedisClient::Connection::Exception& e) {
46+
throw ConnectionsTree::Operations::Exception(QObject::tr("Connection error: ") + QString(e.what()));
47+
}
48+
49+
if (!scanningResp.isOkMessage())
50+
break;
51+
52+
availableDatabeses.insert(dbIndex, 0);
53+
++dbIndex;
4654
}
4755

48-
if (!scanningResp.isOkMessage())
49-
break;
50-
51-
availableDatabeses.insert(dbIndex, 0);
52-
++dbIndex;
5356
}
5457

5558
emit m_manager.openServerStats(m_connection);
@@ -63,7 +66,11 @@ void TreeOperations::getDatabaseKeys(uint dbIndex, QString filter,
6366
QString keyPattern = filter.isEmpty() ? static_cast<ServerConfig>(m_connection->getConfig()).keysPattern() : filter;
6467

6568
try {
66-
m_connection->getDatabaseKeys(callback, keyPattern, dbIndex);
69+
if (m_connection->mode() == RedisClient::Connection::Mode::Cluster) {
70+
m_connection->getClusterKeys(callback, keyPattern);
71+
} else {
72+
m_connection->getDatabaseKeys(callback, keyPattern, dbIndex);
73+
}
6774
} catch (const RedisClient::Connection::Exception& error) {
6875
callback(RedisClient::Connection::RawKeysList(), QString(QObject::tr("Cannot load keys: %1")).arg(error.what()));
6976
}
@@ -153,3 +160,14 @@ void TreeOperations::flushDb(int dbIndex, std::function<void(const QString&)> ca
153160
throw ConnectionsTree::Operations::Exception(QObject::tr("FlushDB error: ") + QString(e.what()));
154161
}
155162
}
163+
164+
QString TreeOperations::mode()
165+
{
166+
if (m_connection->mode() == RedisClient::Connection::Mode::Cluster) {
167+
return QString("cluster");
168+
} else if (m_connection->mode() == RedisClient::Connection::Mode::Sentinel) {
169+
return QString("sentinel");
170+
} else {
171+
return QString("standalone");
172+
}
173+
}

src/app/models/treeoperations.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class TreeOperations : public QObject, public ConnectionsTree::Operations
4040

4141
virtual void flushDb(int dbIndex, std::function<void(const QString&)> callback) override;
4242

43+
virtual QString mode() override;
44+
4345
private:
4446
QSharedPointer<RedisClient::Connection> m_connection;
4547
ConnectionsManager& m_manager;

src/modules/connections-tree/items/abstractnamespaceitem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void AbstractNamespaceItem::renderChilds()
170170
QSharedPointer<TreeItem> self = getSelf().toStrongRef();
171171

172172
if (!self) {
173-
qDebug() << "Cannot render keys: invalid parent item";
173+
qDebug() << "Cannot render keys: invalid parent item";
174174
return;
175175
}
176176

src/modules/connections-tree/items/databaseitem.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class DatabaseItem : public QObject, public AbstractNamespaceItem
2424

2525
QString getIconUrl() const override;
2626

27-
QString getType() const override { return "database"; }
27+
QString getType() const override { return "database"; }
28+
29+
int itemDepth() const override { return 1; }
2830

2931
bool isLocked() const override;
3032

src/modules/connections-tree/items/keyitem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class KeyItem : public TreeItem
2222

2323
QString getType() const override { return "key"; }
2424

25+
int itemDepth() const override { return m_fullPath.count(m_operations->getNamespaceSeparator().toUtf8()) + 2; }
26+
2527
QList<QSharedPointer<TreeItem>> getAllChilds() const override;
2628

2729
bool supportChildItems() const override;

src/modules/connections-tree/items/namespaceitem.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ NamespaceItem::NamespaceItem(const QByteArray &fullPath,
1414
const KeysTreeRenderer::RenderingSettigns& settings)
1515
: AbstractNamespaceItem(model, parent, operations, settings),
1616
m_fullPath(fullPath),
17-
m_removed(false)
17+
m_removed(false),
18+
m_rendering(false)
1819
{
1920
m_displayName = m_fullPath.mid(m_fullPath.lastIndexOf(settings.nsSeparator) + 1);
2021

2122
m_eventHandlers.insert("click", [this]() {
22-
if (m_childItems.size() != 0)
23-
return;
23+
if (m_childItems.size() == 0) {
24+
m_rendering = true;
25+
m_model.itemChanged(getSelf());
2426

25-
renderChilds();
27+
renderChilds();
28+
29+
m_rendering = false;
30+
m_model.itemChanged(getSelf());
31+
}
2632
});
2733

2834
m_eventHandlers.insert("delete", [this]() {
@@ -42,6 +48,7 @@ QByteArray NamespaceItem::getName() const
4248

4349
QString NamespaceItem::getIconUrl() const
4450
{
51+
if (m_rendering) return QString("qrc:/images/wait.svg");
4552
return QString("qrc:/images/namespace.svg");
4653
}
4754

src/modules/connections-tree/items/namespaceitem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class NamespaceItem : public QObject, public AbstractNamespaceItem
2424

2525
QString getType() const override { return "namespace"; }
2626

27+
int itemDepth() const override { return m_fullPath.count(m_renderingSettings.nsSeparator.toUtf8()) + 2; }
28+
2729
bool isLocked() const override;
2830

2931
bool isEnabled() const override;
@@ -36,5 +38,6 @@ class NamespaceItem : public QObject, public AbstractNamespaceItem
3638
QByteArray m_fullPath;
3739
QByteArray m_displayName;
3840
bool m_removed;
41+
bool m_rendering;
3942
};
4043
}

src/modules/connections-tree/items/serveritem.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ServerItem::ServerItem(const QString& name, QSharedPointer<Operations> operation
2626
if (isDatabaseListLoaded())
2727
return;
2828

29-
load();
29+
load();
3030
});
3131

3232
m_eventHandlers.insert("console", [this]() {
@@ -35,25 +35,26 @@ ServerItem::ServerItem(const QString& name, QSharedPointer<Operations> operation
3535

3636
m_eventHandlers.insert("reload", [this]() {
3737
reload();
38+
emit m_model.itemChanged(getSelf());
3839
});
3940

4041
m_eventHandlers.insert("unload", [this]() {
41-
unload();
42+
unload();
4243
});
4344

4445
m_eventHandlers.insert("edit", [this]() {
4546
confirmAction(nullptr, tr("Value and Console tabs related to this "
4647
"connection will be closed. Do you want to continue?"), [this]()
4748
{
48-
unload();
49+
unload();
4950
emit editActionRequested();
5051
});
5152
});
5253

5354
m_eventHandlers.insert("delete", [this]() {
5455
confirmAction(nullptr, tr("Do you really want delete connection?"), [this]()
5556
{
56-
unload();
57+
unload();
5758
emit deleteActionRequested();
5859
});
5960
});
@@ -71,8 +72,16 @@ QString ServerItem::getDisplayName() const
7172
QString ServerItem::getIconUrl() const
7273
{
7374
if (m_locked) return QString("qrc:/images/wait.svg");
74-
if (isDatabaseListLoaded()) return QString("qrc:/images/server.svg");
75-
return QString("qrc:/images/server.svg"); //offline
75+
if (isDatabaseListLoaded()) {
76+
if (m_operations->mode() == "cluster") {
77+
return QString("qrc:/images/cluster.svg");
78+
} else if (m_operations->mode() == "sentinel") {
79+
return QString("qrc:/images/sentinel.svg");
80+
} else {
81+
return QString("qrc:/images/server.svg");
82+
}
83+
}
84+
return QString("qrc:/images/server_offline.svg");
7685
}
7786

7887
QList<QSharedPointer<TreeItem> > ServerItem::getAllChilds() const

src/modules/connections-tree/items/serveritem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class ServerItem : public QObject, public TreeItem
2424

2525
QString getType() const override { return "server"; }
2626

27+
int itemDepth() const override { return 0; }
28+
2729
QList<QSharedPointer<TreeItem>> getAllChilds() const override;
2830

2931
uint childCount(bool recursive = false) const override;

src/modules/connections-tree/items/treeitem.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class TreeItem {
3030

3131
virtual QString getIconUrl() const = 0;
3232

33-
virtual QString getType() const = 0;
33+
virtual QString getType() const = 0;
34+
35+
virtual int itemDepth() const = 0;
3436

3537
virtual QList<QSharedPointer<TreeItem>> getAllChilds() const = 0;
3638

src/modules/connections-tree/model.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ QVariant Model::data(const QModelIndex &index, int role) const
3333
case itemType: return item->getType();
3434
case itemOriginalName: return item->getName();
3535
case itemIsInitiallyExpanded: return item->isExpanded();
36+
case itemDepth: return item->itemDepth();
3637
}
3738

3839
return QVariant();
@@ -44,6 +45,7 @@ QHash<int, QByteArray> Model::roleNames() const
4445
roles[itemName] = "name";
4546
roles[itemType] = "type";
4647
roles[itemIsInitiallyExpanded] = "expanded";
48+
roles[Qt::DecorationRole] = "icon";
4749
return roles;
4850
}
4951

@@ -108,12 +110,25 @@ int Model::rowCount(const QModelIndex &parent) const
108110
if (!parentItem)
109111
return m_treeItems.size();
110112

111-
if (parent.column() > 0)
112-
return 0;
113-
114113
return parentItem->childCount();
115114
}
116115

116+
bool Model::hasChildren(const QModelIndex &parent)
117+
{
118+
const TreeItem* parentItem = getItemFromIndex(parent);
119+
120+
if (!parentItem)
121+
return m_treeItems.size() > 0;
122+
123+
if (parentItem->getType() == "key")
124+
return false;
125+
126+
if (parentItem->getType() == "namespace" || parentItem->getType() == "server")
127+
return true;
128+
129+
return parentItem->childCount() > 0;
130+
}
131+
117132
QModelIndex Model::getIndexFromItem(QWeakPointer<TreeItem> item)
118133
{
119134
if (item && item.toStrongRef()) {
@@ -146,7 +161,7 @@ void Model::onItemChanged(QWeakPointer<TreeItem> item)
146161

147162
auto index = getIndexFromItem(item);
148163

149-
if (!index.isValid() || item.toStrongRef()->childCount() == 0)
164+
if (!index.isValid())
150165
return;
151166

152167
emit dataChanged(index, index);
@@ -167,6 +182,8 @@ void Model::onItemChildsLoaded(QWeakPointer<TreeItem> item)
167182
emit beginInsertRows(index, 0, treeItem->childCount() - 1);
168183
emit endInsertRows();
169184

185+
emit dataChanged(index, index);
186+
170187
if (treeItem->getType() == "database") {
171188
emit expand(index);
172189

@@ -176,7 +193,7 @@ void Model::onItemChildsLoaded(QWeakPointer<TreeItem> item)
176193
} else {
177194
qDebug() << "Namespace reopening is disabled in settings";
178195
m_expanded.clear();
179-
}
196+
}
180197
} else if (treeItem->getType() == "server" || treeItem->getType() == "namespace") {
181198
emit expand(index);
182199
}
@@ -210,9 +227,9 @@ void Model::onExpandItem(QWeakPointer<TreeItem> item)
210227
}
211228

212229

213-
QVariant Model::getItemIcon(const QModelIndex &index)
230+
QVariant Model::getItemDepth(const QModelIndex &index)
214231
{
215-
return data(index, Qt::DecorationRole);
232+
return data(index, itemDepth);
216233
}
217234

218235
QVariant Model::getItemType(const QModelIndex &index)

src/modules/connections-tree/model.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace ConnectionsTree {
2121
itemOriginalName,
2222
itemType,
2323
itemFullPath,
24-
itemIsInitiallyExpanded
24+
itemIsInitiallyExpanded,
25+
itemDepth
2526
};
2627

2728
public:
@@ -39,6 +40,8 @@ namespace ConnectionsTree {
3940

4041
int rowCount(const QModelIndex & parent = QModelIndex()) const;
4142

43+
bool hasChildren(const QModelIndex &parent = QModelIndex());
44+
4245
inline int columnCount(const QModelIndex & parent = QModelIndex()) const
4346
{
4447
Q_UNUSED(parent);
@@ -94,7 +97,7 @@ namespace ConnectionsTree {
9497
void onExpandItem(QWeakPointer<TreeItem> item);
9598

9699
public slots:
97-
QVariant getItemIcon(const QModelIndex &index);
100+
QVariant getItemDepth(const QModelIndex &index);
98101

99102
QVariant getItemType(const QModelIndex &index);
100103

src/modules/connections-tree/operations.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ namespace ConnectionsTree {
6060

6161
virtual void flushDb(int dbIndex, std::function<void(const QString&)> callback) = 0;
6262

63+
virtual QString mode() = 0;
64+
6365
virtual ~Operations() {}
6466

6567
};

0 commit comments

Comments
 (0)