|
|
@@ -1,20 +1,25 @@
|
|
|
+#include <fmt/format.h>
|
|
|
#include <saura/core/app_base/app_base.hpp>
|
|
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
|
|
#include <imgui.h>
|
|
|
#include <imgui_internal.h>
|
|
|
+#include <vector>
|
|
|
|
|
|
+#include "saura/cmd/sandbox/client/client.hpp"
|
|
|
#include "server/server.hpp"
|
|
|
|
|
|
namespace saura {
|
|
|
struct SandboxApp : AppBase {
|
|
|
std::shared_ptr<ServerAPI> server_api_ctx;
|
|
|
+ std::vector<ClientInfo> clients;
|
|
|
|
|
|
void start() override {
|
|
|
spdlog::info("Sandbox start!");
|
|
|
|
|
|
- server_api_ctx = std::make_shared<ServerAPI>();
|
|
|
+ this->server_api_ctx = std::make_shared<ServerAPI>();
|
|
|
+ this->clients = server_api_ctx->fetch_clients(10, 0);
|
|
|
}
|
|
|
|
|
|
void update(double dt) override {
|
|
|
@@ -41,37 +46,105 @@ struct SandboxApp : AppBase {
|
|
|
ImGuiTableFlags_Resizable | ImGuiTableFlags_Borders |
|
|
|
ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_ScrollY;
|
|
|
|
|
|
- if (ImGui::BeginTable("MyDataTable", 5, flags))
|
|
|
{
|
|
|
+ int64_t total = 0;
|
|
|
+ for (auto &client : this->clients) {
|
|
|
+ total += client.income.amount;
|
|
|
+ }
|
|
|
+
|
|
|
+ int64_t rubles = total / 100;
|
|
|
+ int64_t kopecks = total % 100;
|
|
|
+
|
|
|
+ auto text = fmt::format("Общий доход: {}.{} RUB,", rubles, kopecks);
|
|
|
+ ImGui::Text("%s", text.c_str());
|
|
|
+ ImGui::SameLine();
|
|
|
+ }
|
|
|
+ {
|
|
|
+ auto text = fmt::format("Всего клиентов: {}", this->clients.size());
|
|
|
+ ImGui::Text("%s", text.c_str());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ImGui::Button("Создать клиента")) {
|
|
|
+ ImGui::OpenPopup("Test");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ImGui::BeginPopupModal("Test", NULL,
|
|
|
+ ImGuiWindowFlags_AlwaysAutoResize)) {
|
|
|
+ ImGui::Text("This is the modal content!");
|
|
|
+ ImGui::Separator();
|
|
|
+
|
|
|
+ if (ImGui::Button("Close", ImVec2(120, 0))) {
|
|
|
+ ImGui::CloseCurrentPopup(); // Function to close the currently
|
|
|
+ // open popup
|
|
|
+ }
|
|
|
+
|
|
|
+ ImGui::EndPopup(); // Must be called if BeginPopupModal returned
|
|
|
+ // true
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ImGui::BeginTable("MyDataTable", 9, flags)) {
|
|
|
ImGui::TableSetupColumn("#");
|
|
|
+ ImGui::TableSetupColumn("Тип");
|
|
|
+ ImGui::TableSetupColumn("Теги");
|
|
|
ImGui::TableSetupColumn("ФИО");
|
|
|
ImGui::TableSetupColumn("Телефон");
|
|
|
ImGui::TableSetupColumn("Эл. почта");
|
|
|
ImGui::TableSetupColumn("Дата регистрации");
|
|
|
+ ImGui::TableSetupColumn(""); // Edit
|
|
|
+ ImGui::TableSetupColumn(""); // Delete
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
- for (int row = 0; row < 5; row++) {
|
|
|
+ int32_t selected_row_idx = -1;
|
|
|
+ for (size_t idx = 0; idx < clients.size(); idx++) {
|
|
|
+ auto &client = clients[idx];
|
|
|
+
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
|
// #
|
|
|
ImGui::TableNextColumn();
|
|
|
- ImGui::Text("0");
|
|
|
+ ImGui::Text("%03d", (int)idx + 1);
|
|
|
+
|
|
|
+ // Тип
|
|
|
+ ImGui::TableNextColumn();
|
|
|
+ ImGui::Text("%s", client.type.c_str());
|
|
|
+
|
|
|
+ // Теги
|
|
|
+ ImGui::TableNextColumn();
|
|
|
+ if (client.tags.size() > 1) {
|
|
|
+ ImGui::Text("%s...", client.tags[0].c_str());
|
|
|
+ } else {
|
|
|
+ ImGui::Text("%s", client.tags[0].c_str());
|
|
|
+ }
|
|
|
|
|
|
// ФИО
|
|
|
ImGui::TableNextColumn();
|
|
|
- ImGui::Text("Воробьёв Варлам Филиппович");
|
|
|
+ ImGui::Text("%s", client.full_name.c_str());
|
|
|
|
|
|
// Телефон
|
|
|
ImGui::TableNextColumn();
|
|
|
- ImGui::Text("+7 (999) 999-9999");
|
|
|
+ if (client.phones.size() > 1) {
|
|
|
+ ImGui::Text("%s...", client.phones[0].c_str());
|
|
|
+ } else {
|
|
|
+ ImGui::Text("%s", client.phones[0].c_str());
|
|
|
+ }
|
|
|
|
|
|
// Эл. почта
|
|
|
ImGui::TableNextColumn();
|
|
|
- ImGui::Text("test@gmail.com");
|
|
|
+ ImGui::Text("%s", client.email.c_str());
|
|
|
|
|
|
// Дата регистрации
|
|
|
ImGui::TableNextColumn();
|
|
|
- ImGui::Text("15.12.2025");
|
|
|
+ ImGui::Text("%s", client.reg_date.c_str());
|
|
|
+
|
|
|
+ ImGui::TableNextColumn();
|
|
|
+ ImGui::PushID(fmt::format("{}Edit", idx).c_str());
|
|
|
+ ImGui::Button("Edit");
|
|
|
+ ImGui::PopID();
|
|
|
+
|
|
|
+ ImGui::TableNextColumn();
|
|
|
+ ImGui::PushID(fmt::format("{}Delete", idx).c_str());
|
|
|
+ ImGui::Button("Delete");
|
|
|
+ ImGui::PopID();
|
|
|
}
|
|
|
|
|
|
ImGui::EndTable();
|