From 0015a474b7892b6aa53bd15dc0d8f3f38d8cd97e Mon Sep 17 00:00:00 2001 From: dennispelle Date: Wed, 11 Oct 2023 13:40:21 +0200 Subject: [PATCH] vcds has a spinner in create training data hpp --- src/create_training_data.hpp | 51 +++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/create_training_data.hpp b/src/create_training_data.hpp index a9ada978..9eca4d3a 100644 --- a/src/create_training_data.hpp +++ b/src/create_training_data.hpp @@ -113,6 +113,8 @@ static void selected_vcds_data(nlohmann::json const &config, .c_str()); static ImGui::FileBrowser fileBrowser; static bool first_job = true; + static bool flagApiSending = false; + static std::future future; if (first_job) { fileBrowser.SetPwd(load_json(config, "scanfolder")); @@ -143,18 +145,43 @@ static void selected_vcds_data(nlohmann::json const &config, } ImGui::Columns(1); - if (ImGui::Button(load_json(language, "button", "send").c_str(), - ImVec2(load_json(config, "button")))) { - // Api muss angepasst werden und die funktion send to api ebenso - - metadata["kommentar"] = comment; - metadata["laufleistung"] = mileage; - ImGui::Text("Loading %c", "|/-\\"[(int)(ImGui::GetTime() / 0.05f) & 3]); - api_message = send_to_api( - config, path1, inputvin, - load_json(language, "measuretype", "vcds"), metadata); - upload_success = true; - ImGui::CloseCurrentPopup(); + using namespace std::chrono_literals; + if (!flagApiSending) { + if (ImGui::Button( + load_json(language, "button", "send").c_str(), + ImVec2(load_json(config, "button")))) { + metadata["kommentar"] = comment; + metadata["laufleistung"] = mileage; + + future = std::async(std::launch::async, [&] { + std::string result = send_to_api( + config, path1, inputvin, + load_json(language, "measuretype", "vcds"), metadata); + return result; + }); + flagApiSending = true; + } + } + if (flagApiSending) { + ImGui::PushStyleColor( + ImGuiCol_Text, load_json(config, "text", "color", "inactive")); + if (ImGui::Button( + load_json(language, "button", "send").c_str(), + ImVec2(load_json(config, "button")))) { + } + ImGui::PopStyleColor(); + auto status = future.wait_for(10ms); + if (status == std::future_status::ready) { + upload_success = true; + flagApiSending = false; + if (future.valid()) { + api_message = future.get(); + } + ImGui::CloseCurrentPopup(); + } else { + ImGui::SameLine(); + ImGui::Text("senden... %c", "|/-\\"[(int)(ImGui::GetTime() / 0.05f) & 3]); + } } ImGui::EndChild(); }