diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-08-09 08:33:08 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-08-09 08:33:08 +0200 |
| commit | 5d34aff5888d3f0c624251f15bedb96c347978d6 (patch) | |
| tree | 69a49651271d645ca7eaa114cb1830bf759c0930 /src/views/projects.cpp | |
| parent | b94a7ae06b20d550c727d5192cea8baf3e8fb641 (diff) | |
refactors
Diffstat (limited to 'src/views/projects.cpp')
| -rw-r--r-- | src/views/projects.cpp | 173 |
1 files changed, 0 insertions, 173 deletions
diff --git a/src/views/projects.cpp b/src/views/projects.cpp deleted file mode 100644 index 14f99c9..0000000 --- a/src/views/projects.cpp +++ /dev/null @@ -1,173 +0,0 @@ -#include <stdio.h> - -#include "views.hpp" -#include "imgui.h" -#include "../administration.hpp" -#include "../locales/locales.hpp" - -static view_state current_view_state = LIST; -static project selected_for_cancellation; - -static project active_project; - -static void draw_project_form() -{ - static const char* selected_country = NULL; - - if (ImGui::Button(localize("form.back"))) { - current_view_state = view_state::LIST; - memset(&active_project, 0, sizeof(project)); - selected_country = 0; - return; - } - ImGui::Spacing(); - - bool viewing_only = (current_view_state == view_state::VIEW); - - ImGui::BeginDisabled(); - - float widthAvailable = ImGui::GetContentRegionAvail().x; - - ImGui::SetNextItemWidth(widthAvailable*0.2f); - ImGui::InputText(localize("contact.form.identifier"), active_project.id, IM_ARRAYSIZE(active_project.id)); - if (!viewing_only) ImGui::EndDisabled(); - - ImGui::SetNextItemWidth(widthAvailable*0.5f); - ImGui::InputTextWithHint(localize("project.form.description"), localize("project.form.description"), active_project.description, IM_ARRAYSIZE(active_project.description)); - ImGui::SameLine();view_draw_required_tag(); - - if (viewing_only) ImGui::EndDisabled(); - - if (!viewing_only) { - bool can_save = strlen(active_project.description) > 0; - - if (!can_save) ImGui::BeginDisabled(); - // Save button - ImGui::Spacing(); - if (ImGui::Button(localize("form.save"))) { - if (current_view_state == view_state::CREATE) - administration_create_project(active_project); - - else if (current_view_state == view_state::EDIT) - administration_update_project(active_project); - - memset(&active_project, 0, sizeof(project)); - current_view_state = view_state::LIST; - selected_country = 0; - } - if (!can_save) ImGui::EndDisabled(); - } - else { - // TODO list invoices connected to project. - } -} - -static void draw_project_list() -{ - const u32 items_per_page = 50; - static s32 current_page = 0; - s32 max_page = (administration_get_project_count() + items_per_page - 1) / items_per_page; - if (max_page == 0) max_page = 1; - - if (ImGui::Button(localize("form.create"))) - { - current_view_state = view_state::CREATE; - memset(&active_project, 0, sizeof(project)); - snprintf(active_project.id, IM_ARRAYSIZE(active_project.id), "P/%d", administration_create_id()); - } - - if (current_page >= max_page-1) current_page = max_page-1; - if (current_page < 0) current_page = 0; - - ImGui::SameLine(); - bool enable_prev = current_page > 0; - if (!enable_prev) ImGui::BeginDisabled(); - if (ImGui::Button("<< Prev") && current_page > 0) current_page--; - if (!enable_prev) ImGui::EndDisabled(); - - ImGui::SameLine(); - ImGui::Text("(%d/%d)", current_page+1, max_page); - - ImGui::SameLine(); - bool enable_next = current_page < max_page-1; - if (!enable_next) ImGui::BeginDisabled(); - if (ImGui::Button("Next >>") && current_page < max_page-1) current_page++; - if (!enable_next) ImGui::EndDisabled(); - - ImGui::Spacing(); - - if (ImGui::BeginTable("TableProjects", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { - - ImGui::TableSetupColumn(localize("project.table.identifier"), ImGuiTableColumnFlags_WidthFixed, 80); - ImGui::TableSetupColumn(localize("project.table.status"), ImGuiTableColumnFlags_WidthFixed, 140); - ImGui::TableSetupColumn(localize("project.table.description"), ImGuiTableColumnFlags_WidthStretch); - ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 160); - ImGui::TableHeadersRow(); - - project project_list[items_per_page]; - u32 project_count = administration_get_projects(current_page, items_per_page, project_list); - - for (u32 i = 0; i < project_count; i++) { - project c = project_list[i]; - - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex(0); ImGui::Text(c.id); - ImGui::TableSetColumnIndex(1); ImGui::Text(localize(administration_project_get_status_string(c))); - ImGui::TableSetColumnIndex(2); ImGui::Text(c.description); - - ImGui::TableSetColumnIndex(3); - - char btn_name[20]; - sprintf(btn_name, "%s##%d", localize("form.view"), i); - if (ImGui::Button(btn_name)) { - active_project = c; - current_view_state = view_state::VIEW; - } - - if (c.state == project_state::RUNNING) - { - ImGui::SameLine(); - sprintf(btn_name, "%s##%d", localize("form.change"), i); - if (ImGui::Button(btn_name)) { - active_project = c; - current_view_state = view_state::EDIT; - } - - ImGui::SameLine(); - sprintf(btn_name, "%s##%d", localize("form.cancel"), i); - if (ImGui::Button(btn_name)) { - selected_for_cancellation = c; - ImGui::OpenPopup("ConfirmCancelProject"); - } - } - } - - if (ImGui::BeginPopupModal("ConfirmCancelProject", nullptr, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoTitleBar)) { - ImGui::Text(localize("form.confirmCancelProject")); - ImGui::Separator(); - - if (ImGui::Button(localize("form.yes"), ImVec2(120, 0))) { - administration_cancel_project(selected_for_cancellation); - ImGui::CloseCurrentPopup(); - } - ImGui::SameLine(); - if (ImGui::Button(localize("form.no"), ImVec2(120, 0))) { - ImGui::CloseCurrentPopup(); - } - ImGui::EndPopup(); - } - - ImGui::EndTable(); - } -} - -void views_draw_projects() -{ - switch(current_view_state) - { - case view_state::LIST: draw_project_list(); break; - case view_state::CREATE: draw_project_form(); break; - case view_state::EDIT: draw_project_form(); break; - case view_state::VIEW: draw_project_form(); break; - } -}
\ No newline at end of file |
