|
|
@@ -1,5 +1,6 @@
|
|
|
#include <cstring>
|
|
|
#include <fmt/format.h>
|
|
|
+#include <memory>
|
|
|
#include <saura/core/app_base/app_base.hpp>
|
|
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
@@ -11,6 +12,8 @@
|
|
|
#include "saura/cmd/sandbox/client/client.hpp"
|
|
|
#include "saura/cmd/sandbox/folder/folder.hpp"
|
|
|
#include "saura/cmd/sandbox/user/user.hpp"
|
|
|
+#include "saura/core/base/types.hpp"
|
|
|
+#include "saura/core/memory/arena.hpp"
|
|
|
#include "server/server.hpp"
|
|
|
|
|
|
namespace saura {
|
|
|
@@ -23,10 +26,15 @@ struct SandboxApp : AppBase {
|
|
|
std::vector<ClientInfo> clients;
|
|
|
std::vector<UserInfo> users;
|
|
|
Folder category_root;
|
|
|
+ std::unique_ptr<MemoryArena> default_memory_arena;
|
|
|
|
|
|
void start() override {
|
|
|
spdlog::info("Sandbox start!");
|
|
|
|
|
|
+ // TODO: FIX FATAL
|
|
|
+ this->default_memory_arena =
|
|
|
+ std::make_unique<MemoryArena>(MemoryArena(Megabytes(256)));
|
|
|
+
|
|
|
this->server_api_ctx = std::make_shared<ServerAPI>();
|
|
|
this->clients = server_api_ctx->fetch_clients(10, 0);
|
|
|
this->users = server_api_ctx->fetch_users(10, 0);
|
|
|
@@ -206,13 +214,60 @@ struct SandboxApp : AppBase {
|
|
|
}
|
|
|
|
|
|
if (ImGui::Button("Создать клиента")) {
|
|
|
- ImGui::OpenPopup("Test");
|
|
|
+ ImGui::OpenPopup("CreateClientPopup");
|
|
|
}
|
|
|
|
|
|
- if (ImGui::BeginPopupModal("Test", NULL,
|
|
|
+ if (ImGui::BeginPopupModal("CreateClientPopup", NULL,
|
|
|
ImGuiWindowFlags_AlwaysAutoResize)) {
|
|
|
- ImGui::Text("This is the modal content!");
|
|
|
- ImGui::Separator();
|
|
|
+ // Тип
|
|
|
+ {
|
|
|
+ static const char *items[] = {"Вариант 1", "Вариант 2",
|
|
|
+ "Вариант 3"};
|
|
|
+ static int current_item = 0;
|
|
|
+
|
|
|
+ if (ImGui::BeginCombo("Тип", items[current_item])) {
|
|
|
+ for (int n = 0; n < IM_ARRAYSIZE(items); n++) {
|
|
|
+ bool is_selected = (current_item == n);
|
|
|
+
|
|
|
+ if (ImGui::Selectable(items[n], is_selected)) {
|
|
|
+ current_item = n;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (is_selected) {
|
|
|
+ ImGui::SetItemDefaultFocus();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ImGui::EndCombo();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Теги
|
|
|
+ {
|
|
|
+ static const char *items[] = {"Вариант 1", "Вариант 2",
|
|
|
+ "Вариант 3"};
|
|
|
+ static int current_item = 0;
|
|
|
+
|
|
|
+ if (ImGui::BeginCombo("Теги", items[current_item])) {
|
|
|
+ for (int n = 0; n < IM_ARRAYSIZE(items); n++) {
|
|
|
+ bool is_selected = (current_item == n);
|
|
|
+
|
|
|
+ if (ImGui::Selectable(items[n], is_selected)) {
|
|
|
+ current_item = n;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (is_selected) {
|
|
|
+ ImGui::SetItemDefaultFocus();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ImGui::EndCombo();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ФИО
|
|
|
+ {
|
|
|
+ uint8_t *buf = this->default_memory_arena->push_zero(1024);
|
|
|
+ ImGui::InputText("ФИО", (char *)buf, sizeof(buf));
|
|
|
+ }
|
|
|
|
|
|
if (ImGui::Button("Close", ImVec2(120, 0))) {
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
@@ -282,7 +337,9 @@ struct SandboxApp : AppBase {
|
|
|
ImGui::TableNextColumn();
|
|
|
ImGui::PushID(fmt::format("{}Delete", idx).c_str());
|
|
|
if (ImGui::Button("Delete")) {
|
|
|
- if (server_api_ctx->send_delete(fmt::format("http://api.localhost:8090/v1/example/client?id={}", client.id))) {
|
|
|
+ if (server_api_ctx->send_delete(fmt::format(
|
|
|
+ "http://api.localhost:8090/v1/example/client?id={}",
|
|
|
+ client.id))) {
|
|
|
if (idx < clients.size()) {
|
|
|
clients.erase(clients.begin() + idx);
|
|
|
}
|
|
|
@@ -295,6 +352,9 @@ struct SandboxApp : AppBase {
|
|
|
}
|
|
|
ImGui::EndTabItem();
|
|
|
}
|
|
|
+ if (ImGui::IsItemActivated()) {
|
|
|
+ this->clients = server_api_ctx->fetch_clients(10, 0);
|
|
|
+ }
|
|
|
|
|
|
if (ImGui::BeginTabItem("Пользователи")) {
|
|
|
ImGuiTableFlags flags =
|
|
|
@@ -377,6 +437,9 @@ struct SandboxApp : AppBase {
|
|
|
}
|
|
|
ImGui::EndTabItem();
|
|
|
}
|
|
|
+ if (ImGui::IsItemActivated()) {
|
|
|
+ this->users = server_api_ctx->fetch_users(10, 0);
|
|
|
+ }
|
|
|
|
|
|
if (ImGui::BeginTabItem("Настройки")) {
|
|
|
ImGui::Text("Hello");
|
|
|
@@ -389,6 +452,8 @@ struct SandboxApp : AppBase {
|
|
|
ImGui::End();
|
|
|
|
|
|
ImGui::ShowDemoWindow();
|
|
|
+
|
|
|
+ this->default_memory_arena->clear();
|
|
|
}
|
|
|
|
|
|
void stop() override { spdlog::info("Sandbox stop!"); }
|