0xc3 пре 1 месец
родитељ
комит
e730fc33ca
1 измењених фајлова са 56 додато и 24 уклоњено
  1. 56 24
      src/saura/cmd/sandbox/sandbox.cpp

+ 56 - 24
src/saura/cmd/sandbox/sandbox.cpp

@@ -1,3 +1,4 @@
+#include <cpr/api.h>
 #include <cstring>
 #include <fmt/format.h>
 #include <memory>
@@ -225,30 +226,40 @@ struct SandboxApp : AppBase {
         if (ImGui::BeginPopupModal("CreateClientPopup", NULL,
                                    ImGuiWindowFlags_AlwaysAutoResize)) {
           ClientInfo tmp_client;
+          uint64_t def_str_size = 65;
+
+          this->mem_arena_temp->begin(this->def_mem_arena.get());
+
           // Тип
           {
+            // TODO: get form server (DB)
             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();
+              if (ImGui::IsWindowAppearing()) {
+                auto res = cpr::Get(
+                    cpr::Url(
+                        "http://api.localhost:8090/v1/example/client/tags"),
+                    cpr::Timeout(1000));
+                if (res.status_code == 200) {
+                  auto res_json = nlohmann::json::parse(res.text);
+                  if (!res_json.is_array()) {
+                    throw std::runtime_error("Expected JSON array but got " +
+                                             std::string(res_json.type_name()));
+                  }
+                  spdlog::info("Response: {}", res_json.dump(2));
                 }
               }
+
               ImGui::EndCombo();
             }
           }
 
           // Теги
           {
+            // TODO: get form server (DB)
             static const char *items[] = {"Вариант 1", "Вариант 2",
                                           "Вариант 3"};
             static int current_item = 0;
@@ -269,28 +280,49 @@ struct SandboxApp : AppBase {
             }
           }
 
-          this->mem_arena_temp->begin(this->def_mem_arena.get());
+          // Контрагент
+          bool *contractor = (bool *)this->mem_arena_temp->push(def_str_size);
+          ImGui::Checkbox("Контрагент", contractor);
 
           // ФИО
-          {
-            uint64_t default_size = 65;
+          uint8_t *full_name = this->mem_arena_temp->push(def_str_size);
+          ImGui::InputText("ФИО", (char *)full_name, def_str_size);
 
-            uint8_t *full_name = this->mem_arena_temp->push(default_size);
-            ImGui::InputText("ФИО", (char *)full_name, default_size);
-            tmp_client.full_name = (char *)full_name;
-          }
+          // Эл. почта
+          uint8_t *email = this->mem_arena_temp->push(def_str_size);
+          ImGui::InputText("Эл. почта", (char *)email, def_str_size);
 
-          // Телефон
-          {
-            uint64_t default_size = 65;
+          // legal_address
+          uint8_t *legal_address = this->mem_arena_temp->push(def_str_size);
+          ImGui::InputText("legal_address", (char *)legal_address,
+                           def_str_size);
 
-            uint8_t *email = this->mem_arena_temp->push(default_size);
-            ImGui::InputText("Эл. почта", (char *)email, default_size);
-            tmp_client.email = (char*)email;
-          }
+          // physical_address
+          uint8_t *physical_address = this->mem_arena_temp->push(def_str_size);
+          ImGui::InputText("physical_address", (char *)physical_address,
+                           def_str_size);
+
+          // Заметки
+          uint8_t *note = this->mem_arena_temp->push(def_str_size);
+          ImGui::InputTextMultiline("Заметки", (char *)note, def_str_size);
 
           if (ImGui::Button("Close", ImVec2(120, 0))) {
-            spdlog::info("{}, {}", tmp_client.full_name, tmp_client.email);
+            tmp_client.contractor = *contractor;
+            tmp_client.full_name = (char *)full_name;
+            tmp_client.email = (char *)email;
+            tmp_client.legal_address = (char *)legal_address;
+            tmp_client.physical_address = (char *)physical_address;
+            tmp_client.note = (char *)note;
+
+            spdlog::info("{}", tmp_client.contractor);
+            spdlog::info("{}", tmp_client.full_name);
+            // spdlog::info("{}", tmp_client.type);
+            spdlog::info("{}", tmp_client.email);
+            spdlog::info("{}", tmp_client.legal_address);
+            spdlog::info("{}", tmp_client.physical_address);
+            spdlog::info("{}", tmp_client.note);
+            // spdlog::info("{}", tmp_client.reg_date);
+
             this->mem_arena_temp->pop_zero_all();
             ImGui::CloseCurrentPopup();
           }