add a group table
This commit is contained in:
parent
f40cda49d5
commit
51f05b349b
|
@ -19,18 +19,58 @@
|
|||
<source>...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="dedicatedservergroupwidget.ui" line="69"/>
|
||||
<source>Name</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="dedicatedservergroupwidget.ui" line="74"/>
|
||||
<source>IP</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="dedicatedservergroupwidget.ui" line="79"/>
|
||||
<source>Monitoring</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="dedicatedservergroupwidget.ui" line="84"/>
|
||||
<source>Hardware</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="dedicatedservergroupwidget.ui" line="89"/>
|
||||
<source>Price</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="dedicatedservergroupwidget.cpp" line="26"/>
|
||||
<source>Enabled with intervention</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="dedicatedservergroupwidget.cpp" line="27"/>
|
||||
<source>Enabled without intervention</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="dedicatedservergroupwidget.cpp" line="28"/>
|
||||
<source>Disabled</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="dedicatedservergroupwidget.cpp" line="39"/>
|
||||
<source>Group %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="dedicatedservergroupwidget.cpp" line="55"/>
|
||||
<location filename="dedicatedservergroupwidget.cpp" line="102"/>
|
||||
<source>(incomplete!) %1 %2</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="dedicatedservergroupwidget.cpp" line="56"/>
|
||||
<location filename="dedicatedservergroupwidget.cpp" line="103"/>
|
||||
<source>For no good reason, OVH sometimes doesn't provide pricing information, sorry about that</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
#include <QJsonObject>
|
||||
#include "ovhapi.h"
|
||||
|
||||
|
||||
// TODO : unify
|
||||
QString _monitoringWithIntervention, _monitoringWithoutIntervention, _noMonitoring;
|
||||
|
||||
DedicatedServerGroupWidget::DedicatedServerGroupWidget(OvhApi *api, const QString &groupName, const QStringList &servers, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::DedicatedServerGroupWidget),
|
||||
|
@ -14,7 +18,15 @@ DedicatedServerGroupWidget::DedicatedServerGroupWidget(OvhApi *api, const QStrin
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->serverTable->hideColumn(0);
|
||||
ui->serverTable->setRowCount(servers.count());
|
||||
QTimer::singleShot(0, this, &DedicatedServerGroupWidget::fetchOvhData);
|
||||
|
||||
if (_monitoringWithIntervention.isEmpty()) {
|
||||
_monitoringWithIntervention = tr("Enabled with intervention");
|
||||
_monitoringWithoutIntervention = tr("Enabled without intervention");
|
||||
_noMonitoring = tr("Disabled");
|
||||
}
|
||||
}
|
||||
|
||||
DedicatedServerGroupWidget::~DedicatedServerGroupWidget()
|
||||
|
@ -28,9 +40,39 @@ QCoro::Task<> DedicatedServerGroupWidget::fetchOvhData()
|
|||
double totalMonthlyCost = 0;
|
||||
bool incompletePricing = false;
|
||||
QString currency;
|
||||
int i = 0;
|
||||
for (auto &&server: _servers) {
|
||||
int c = 0;
|
||||
qDebug() << server;
|
||||
|
||||
auto serverInfo = (co_await api->get("/dedicated/server/" + server, 1h)).object();
|
||||
|
||||
auto tableItem = new QTableWidgetItem(server);
|
||||
ui->serverTable->setItem(i, c++, tableItem);
|
||||
tableItem = new QTableWidgetItem(serverInfo["reverse"].toString());
|
||||
ui->serverTable->setItem(i, c++, tableItem);
|
||||
|
||||
auto networkInfo = (co_await api->get(QString("/dedicated/server/%1/specifications/network").arg(server), 240h)).object();
|
||||
auto routingInfo = networkInfo["routing"].toObject();
|
||||
auto v4Info = routingInfo["ipv4"].toObject();
|
||||
tableItem = new QTableWidgetItem(v4Info["ip"].toString());
|
||||
ui->serverTable->setItem(i, c++, tableItem);
|
||||
|
||||
|
||||
if (serverInfo["monitoring"].toBool()) {
|
||||
if (serverInfo["noIntervention"].toBool())
|
||||
tableItem = new QTableWidgetItem(_monitoringWithoutIntervention);
|
||||
else
|
||||
tableItem = new QTableWidgetItem(_monitoringWithIntervention);
|
||||
} else {
|
||||
tableItem = new QTableWidgetItem(_noMonitoring);
|
||||
}
|
||||
ui->serverTable->setItem(i, c++, tableItem);
|
||||
|
||||
auto hardwareInfo = (co_await api->get(QString("/dedicated/server/%1/specifications/hardware").arg(server), 240h)).object();
|
||||
tableItem = new QTableWidgetItem(hardwareInfo["description"].toString());
|
||||
ui->serverTable->setItem(i, c++, tableItem);
|
||||
|
||||
// Calculate monthly cost, using the /services API
|
||||
auto serviceInfo = (co_await api->get(QString("/dedicated/server/%1/serviceInfos").arg(server), 1h)).object();
|
||||
auto serviceId = serviceInfo["serviceId"].toInt();
|
||||
|
@ -41,6 +83,9 @@ QCoro::Task<> DedicatedServerGroupWidget::fetchOvhData()
|
|||
double totalCost = pricingData["price"].toObject()["value"].toDouble();
|
||||
totalCost = totalCost / pricingData["interval"].toInt();
|
||||
|
||||
tableItem = new QTableWidgetItem(QString::number(totalCost));
|
||||
ui->serverTable->setItem(i, c++, tableItem);
|
||||
|
||||
if (billingData["pricing"].isNull()) {
|
||||
incompletePricing = true;
|
||||
} else {
|
||||
|
@ -50,6 +95,8 @@ QCoro::Task<> DedicatedServerGroupWidget::fetchOvhData()
|
|||
// TODO: else ??
|
||||
totalMonthlyCost += totalCost;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
if (incompletePricing) {
|
||||
ui->monthlyCost->setText(tr("(incomplete!) %1 %2").arg(totalMonthlyCost).arg(currency));
|
||||
|
|
|
@ -6,15 +6,15 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>688</width>
|
||||
<height>442</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
|
@ -57,18 +57,39 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<item row="1" column="0">
|
||||
<widget class="QTableWidget" name="serverTable">
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">OVH Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>IP</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Monitoring</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Hardware</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Price</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
|
|
@ -111,7 +111,7 @@ QCoro::Task<> MainWindow::login(const QString &ck) {
|
|||
}
|
||||
}
|
||||
|
||||
QCoro::Task<> MainWindow::loadServerInfo(const QString &server) {
|
||||
QCoro::Task<> MainWindow::loadServerInfo(QString server) {
|
||||
qDebug() << "Loading for " << server;
|
||||
auto serverInfo = (co_await api->get(QString("/dedicated/server/") + server, 1h)).object();
|
||||
auto displayName = serverInfo["reverse"].toString();
|
||||
|
|
|
@ -31,7 +31,8 @@ private slots:
|
|||
|
||||
void on_tabWidget_tabCloseRequested(int index);
|
||||
|
||||
QCoro::Task<> loadServerInfo(const QString &serverName);
|
||||
// This is a copy and not a const pointer on purpose
|
||||
QCoro::Task<> loadServerInfo(QString serverName);
|
||||
|
||||
void loadKvm(const QString &name, const QString &kvmType, const QString &data);
|
||||
|
||||
|
|
Loading…
Reference in New Issue