-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: added page to revoke active devices
- Loading branch information
Showing
12 changed files
with
322 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "apiDevicesModel.h" | ||
|
||
#include <QJsonObject> | ||
|
||
#include "core/api/apiDefs.h" | ||
#include "logger.h" | ||
|
||
namespace | ||
{ | ||
Logger logger("ApiDevicesModel"); | ||
|
||
constexpr QLatin1String gatewayAccount("gateway_account"); | ||
} | ||
|
||
ApiDevicesModel::ApiDevicesModel(QObject *parent) : QAbstractListModel(parent) | ||
{ | ||
} | ||
|
||
int ApiDevicesModel::rowCount(const QModelIndex &parent) const | ||
{ | ||
Q_UNUSED(parent) | ||
return m_issuedConfigs.size(); | ||
} | ||
|
||
QVariant ApiDevicesModel::data(const QModelIndex &index, int role) const | ||
{ | ||
if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(rowCount())) | ||
return QVariant(); | ||
|
||
IssuedConfigInfo issuedConfigInfo = m_issuedConfigs.at(index.row()); | ||
|
||
switch (role) { | ||
case OsVersionRole: { | ||
return issuedConfigInfo.osVersion; | ||
} | ||
case SupportTagRole: { | ||
return issuedConfigInfo.installationUuid; | ||
} | ||
case CountryCodeRole: { | ||
return issuedConfigInfo.countryCode; | ||
} | ||
} | ||
|
||
return QVariant(); | ||
} | ||
|
||
void ApiDevicesModel::updateModel(const QJsonArray &issuedConfigs) | ||
{ | ||
beginResetModel(); | ||
|
||
m_issuedConfigs.clear(); | ||
for (int i = 0; i < issuedConfigs.size(); i++) { | ||
IssuedConfigInfo issuedConfigInfo; | ||
QJsonObject issuedConfigObject = issuedConfigs.at(i).toObject(); | ||
|
||
if (issuedConfigObject.value(apiDefs::key::sourceType).toString() != gatewayAccount) { | ||
continue; | ||
} | ||
|
||
issuedConfigInfo.installationUuid = issuedConfigObject.value(apiDefs::key::installationUuid).toString(); | ||
issuedConfigInfo.workerLastUpdated = issuedConfigObject.value(apiDefs::key::workerLastUpdated).toString(); | ||
issuedConfigInfo.lastDownloaded = issuedConfigObject.value(apiDefs::key::lastDownloaded).toString(); | ||
issuedConfigInfo.sourceType = issuedConfigObject.value(apiDefs::key::sourceType).toString(); | ||
issuedConfigInfo.osVersion = issuedConfigObject.value(apiDefs::key::osVersion).toString(); | ||
|
||
issuedConfigInfo.countryName = issuedConfigObject.value(apiDefs::key::serverCountryName).toString(); | ||
issuedConfigInfo.countryCode = issuedConfigObject.value(apiDefs::key::serverCountryCode).toString(); | ||
|
||
m_issuedConfigs.push_back(issuedConfigInfo); | ||
} | ||
|
||
endResetModel(); | ||
} | ||
|
||
QHash<int, QByteArray> ApiDevicesModel::roleNames() const | ||
{ | ||
QHash<int, QByteArray> roles; | ||
roles[OsVersionRole] = "osVersion"; | ||
roles[SupportTagRole] = "supportTag"; | ||
roles[CountryCodeRole] = "countryCode"; | ||
return roles; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef APIDEVICESMODEL_H | ||
#define APIDEVICESMODEL_H | ||
|
||
#include <QAbstractListModel> | ||
#include <QJsonArray> | ||
#include <QVector> | ||
|
||
class ApiDevicesModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
enum Roles { | ||
OsVersionRole = Qt::UserRole + 1, | ||
SupportTagRole, | ||
CountryCodeRole | ||
}; | ||
|
||
explicit ApiDevicesModel(QObject *parent = nullptr); | ||
|
||
int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
|
||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
|
||
public slots: | ||
void updateModel(const QJsonArray &issuedConfigs); | ||
|
||
protected: | ||
QHash<int, QByteArray> roleNames() const override; | ||
|
||
private: | ||
struct IssuedConfigInfo | ||
{ | ||
QString installationUuid; | ||
QString workerLastUpdated; | ||
QString lastDownloaded; | ||
QString sourceType; | ||
QString osVersion; | ||
|
||
QString countryName; | ||
QString countryCode; | ||
}; | ||
|
||
QVector<IssuedConfigInfo> m_issuedConfigs; | ||
}; | ||
#endif // APIDEVICESMODEL_H |
Oops, something went wrong.