Skip to content

Commit

Permalink
Create Report: Pivotable and FeatureDB button to use FilePickerHandler (
Browse files Browse the repository at this point in the history
  • Loading branch information
bertrandboudaud authored Oct 4, 2021
1 parent f3e7f30 commit 7c2b414
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 22 deletions.
21 changes: 20 additions & 1 deletion src/smartpeak/include/SmartPeak/ui/Report.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

#pragma once

#include <SmartPeak/ui/Widget.h>
#include <SmartPeak/core/ApplicationHandler.h>
#include <SmartPeak/core/FeatureMetadata.h>
#include <SmartPeak/core/SampleType.h>
#include <SmartPeak/ui/Widget.h>
#include <SmartPeak/ui/FilePicker.h>
#include <array>
#include <set>
#include <string>
Expand Down Expand Up @@ -61,5 +62,23 @@ namespace SmartPeak
Report(ApplicationHandler& application_handler);

void draw() override;

protected:
struct ReportFilePickerHandler : IFilePickerHandler
{
ReportFilePickerHandler(const Report& report, const std::string title) :
report_(report), title_(title) { };
/**
IFilePickerHandler
*/
bool onFilePicked(const std::filesystem::path& filename, ApplicationHandler* application_handler) override;
protected:
const Report& report_;
const std::string title_;
};

std::shared_ptr<ReportFilePickerHandler> feature_db_file_picker_handler_;
std::shared_ptr<ReportFilePickerHandler> pivot_table_file_picker_handler_;
FilePicker report_file_picker_;
};
}
8 changes: 7 additions & 1 deletion src/smartpeak/source/ui/FilePicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ namespace SmartPeak

void FilePicker::drawConfirmationPopup()
{
bool do_open_file = false;
if (ImGui::BeginPopupModal("Overwrite confirmation", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("Overwrite file:");
Expand All @@ -297,8 +298,8 @@ namespace SmartPeak
LOGE << e.what();
// let's continue ...
}
doOpenFile();
ImGui::CloseCurrentPopup();
do_open_file = true;
}
ImGui::SameLine();
if (ImGui::Button("Cancel"))
Expand All @@ -307,6 +308,11 @@ namespace SmartPeak
}
ImGui::EndPopup();
}

if (do_open_file)
{
doOpenFile();
}
}

std::string FilePicker::getPickedPathname() const
Expand Down
52 changes: 32 additions & 20 deletions src/smartpeak/source/ui/Report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@

namespace SmartPeak
{

bool Report::ReportFilePickerHandler::onFilePicked(const std::filesystem::path& filename, ApplicationHandler* application_handler)
{
report_.run_and_join(
SequenceParser::writeDataTableFromMetaValue,
title_,
application_handler->sequenceHandler_,
filename,
report_.summaryMetaData_,
report_.summarySampleTypes_
);
return true;
}

Report::Report(ApplicationHandler& application_handler) :
Widget("Create Report"),
application_handler_(application_handler)
Expand All @@ -42,6 +56,8 @@ namespace SmartPeak
std::fill(md_checks_.begin(), md_checks_.end(), false);
all_st_checks_ = false; all_st_deactivated_ = true;
all_md_checks_ = false; all_md_deactivated_ = true;
feature_db_file_picker_handler_ = std::make_shared<ReportFilePickerHandler>(*this, "Feature DB report");
pivot_table_file_picker_handler_ = std::make_shared<ReportFilePickerHandler>(*this, "Pivot Table");
}

void Report::draw()
Expand All @@ -50,6 +66,8 @@ namespace SmartPeak
return;
}

report_file_picker_.draw();

ImGui::BeginChild("ReportContent", ImVec2(600, 400));

ImGui::Text("Select the information to export in the reports.");
Expand Down Expand Up @@ -110,20 +128,17 @@ namespace SmartPeak

ImGui::Separator();

if (ImGui::Button("Create FeatureDB.csv"))
if (ImGui::Button("Create Feature DB"))
{
const bool checkboxes_check = initializeMetadataAndSampleTypes();
if (checkboxes_check)
{
const auto pathname = application_handler_.main_dir_ / "FeatureDB.csv";
run_and_join(
SequenceParser::writeDataTableFromMetaValue,
"FeatureDB.csv",
application_handler_.sequenceHandler_,
pathname,
summaryMetaData_,
summarySampleTypes_
);
report_file_picker_.open(
"Create Feature DB",
feature_db_file_picker_handler_,
FilePicker::Mode::EFileCreate,
application_handler_,
"FeatureDB.csv");
}
else
{
Expand All @@ -133,20 +148,17 @@ namespace SmartPeak

ImGui::SameLine();

if (ImGui::Button("Create PivotTable.csv"))
if (ImGui::Button("Create Pivot Table"))
{
const bool checkboxes_check = initializeMetadataAndSampleTypes();
if (checkboxes_check)
{
const auto pathname = application_handler_.main_dir_ / "PivotTable.csv";
run_and_join(
SequenceParser::writeDataMatrixFromMetaValue,
"PivotTable.csv",
application_handler_.sequenceHandler_,
pathname,
summaryMetaData_,
summarySampleTypes_
);
report_file_picker_.open(
"Create Pivot Table",
pivot_table_file_picker_handler_,
FilePicker::Mode::EFileCreate,
application_handler_,
"PivotTable.csv");
}
else
{
Expand Down

0 comments on commit 7c2b414

Please sign in to comment.