Fix some status issue in b_manage

This commit is contained in:
2024-03-15 12:45:08 +01:00
parent 1912d17498
commit 175e0eb591
2 changed files with 49 additions and 34 deletions

View File

@@ -43,7 +43,7 @@ namespace platform {
} }
std::cout << Colors::RESET() << "Done!" << std::endl; std::cout << Colors::RESET() << "Done!" << std::endl;
} }
void ManageResults::list(const std::string& status_message, const std::string& status_color, int index_A, int index_B) void ManageResults::list(const std::string& status_message_init, const std::string& status_color, int index_A, int index_B)
{ {
// //
// Page info // Page info
@@ -102,6 +102,7 @@ namespace platform {
oss << " A: " << (index_A == -1 ? "<notset>" : std::to_string(index_A)) << oss << " A: " << (index_A == -1 ? "<notset>" : std::to_string(index_A)) <<
" B: " << (index_B == -1 ? "<notset>" : std::to_string(index_B)) << " "; " B: " << (index_B == -1 ? "<notset>" : std::to_string(index_B)) << " ";
int status_length = std::max(oss.str().size(), maxLine - oss.str().size()); int status_length = std::max(oss.str().size(), maxLine - oss.str().size());
auto status_message = status_message_init.substr(0, status_length - 1);
std::string status = status_message + std::string(std::max(size_t(0), status_length - status_message.size()), ' '); std::string status = status_message + std::string(std::max(size_t(0), status_length - status_message.size()), ' ');
auto color = (index_A != -1 && index_B != -1) ? Colors::IGREEN() : Colors::IYELLOW(); auto color = (index_A != -1 && index_B != -1) ? Colors::IGREEN() : Colors::IYELLOW();
std::cout << color << Colors::REVERSE() << oss.str() << Colors::RESET() << Colors::WHITE() std::cout << color << Colors::REVERSE() << oss.str() << Colors::RESET() << Colors::WHITE()
@@ -129,27 +130,27 @@ namespace platform {
std::cout << "Not done!" << std::endl; std::cout << "Not done!" << std::endl;
return false; return false;
} }
void ManageResults::report_compared(const int index_A, const int index_B) std::string ManageResults::report_compared(const int index_A, const int index_B)
{ {
std::cout << "Comparing " << results.at(index_A).getFilename() << " with " << results.at(index_B).getFilename() << std::endl;
auto data_A = results.at(index_A).getJson(); auto data_A = results.at(index_A).getJson();
auto data_B = results.at(index_B).getJson(); auto data_B = results.at(index_B).getJson();
ReportExcelCompared reporter(data_A, data_B); ReportExcelCompared reporter(data_A, data_B);
reporter.report(); reporter.report();
return results.at(index_A).getFilename() + " Vs " + results.at(index_B).getFilename();
} }
void ManageResults::report(const int index, const bool excelReport) std::string ManageResults::report(const int index, const bool excelReport)
{ {
std::cout << Colors::YELLOW() << "Reporting " << results.at(index).getFilename() << std::endl;
auto data = results.at(index).getJson(); auto data = results.at(index).getJson();
if (excelReport) { if (excelReport) {
ReportExcel reporter(data, compare, workbook); ReportExcel reporter(data, compare, workbook);
reporter.show(); reporter.show();
openExcel = true; openExcel = true;
workbook = reporter.getWorkbook(); workbook = reporter.getWorkbook();
std::cout << "Adding sheet to " << Paths::excel() + Paths::excelResults() << std::endl; return results.at(index).getFilename() + "->" + Paths::excel() + Paths::excelResults();
} else { } else {
ReportConsole reporter(data, compare); ReportConsole reporter(data, compare);
reporter.show(); reporter.show();
return "Reporting " + results.at(index).getFilename();
} }
} }
void ManageResults::showIndex(const int index, const int idx) void ManageResults::showIndex(const int index, const int idx)
@@ -229,7 +230,7 @@ namespace platform {
} else { } else {
std::tie(option, subIndex) = parser.parse(Colors::IBLUE(), listOptions, 'r', 0, results.at(index).getJson()["results"].size() - 1); std::tie(option, subIndex) = parser.parse(Colors::IBLUE(), listOptions, 'r', 0, results.at(index).getJson()["results"].size() - 1);
} }
std::string status_message, status_color;
switch (option) { switch (option) {
case 'p': case 'p':
if (paginator.valid(index)) { if (paginator.valid(index)) {
@@ -284,7 +285,7 @@ namespace platform {
list("Need to set A and B first!", Colors::RED(), index_A, index_B); list("Need to set A and B first!", Colors::RED(), index_A, index_B);
break; break;
} }
report_compared(index_A, index_B); list(report_compared(index_A, index_B), Colors::GREEN(), index_A, index_B);
break; break;
case 'l': case 'l':
list(STATUS_OK, STATUS_COLOR, index_A, index_B); list(STATUS_OK, STATUS_COLOR, index_A, index_B);
@@ -292,25 +293,35 @@ namespace platform {
break; break;
case 'd': case 'd':
filename = results.at(index).getFilename(); filename = results.at(index).getFilename();
if (!confirmAction("delete", filename)) if (!confirmAction("delete", filename)) {
list("File: " + filename + " not deleted!", Colors::YELLOW(), index_A, index_B); list(filename + " not deleted!", Colors::YELLOW(), index_A, index_B);
break;
}
std::cout << "Deleting " << filename << std::endl; std::cout << "Deleting " << filename << std::endl;
results.deleteResult(index); results.deleteResult(index);
list("File: " + filename + " deleted!", Colors::RED(), index_A, index_B); list(filename + " deleted!", Colors::RED(), index_A, index_B);
break; break;
case 'h': case 'h':
filename = results.at(index).getFilename(); {
if (!confirmAction("hide", filename)) std::string status_message;
list("File: " + filename + " not hidden!", Colors::YELLOW(), index_A, index_B); filename = results.at(index).getFilename();
filename = results.at(index).getFilename(); if (!confirmAction("hide", filename)) {
std::cout << "Hiding " << filename << std::endl; list(filename + " not hidden!", Colors::YELLOW(), index_A, index_B);
results.hideResult(index, Paths::hiddenResults()); break;
status_message = "File: " + filename + " hidden! (moved to " + Paths::hiddenResults() + ")"; }
list(status_message, Colors::YELLOW(), index_A, index_B); filename = results.at(index).getFilename();
std::cout << "Hiding " << filename << std::endl;
results.hideResult(index, Paths::hiddenResults());
status_message = filename + " hidden! (moved to " + Paths::hiddenResults() + ")";
list(status_message, Colors::YELLOW(), index_A, index_B);
}
break; break;
case 's': case 's':
tie(status_color, status_message) = sortList(); {
list(status_message, status_color, index_A, index_B); std::string status_message, status_color;
tie(status_color, status_message) = sortList();
list(status_message, status_color, index_A, index_B);
}
break; break;
case 'r': case 'r':
if (indexList) { if (indexList) {
@@ -321,20 +332,24 @@ namespace platform {
} }
break; break;
case 'e': case 'e':
report(index, true); list(report(index, true), Colors::GREEN(), index_A, index_B);
break; break;
case 't': case 't':
std::cout << "Title: " << results.at(index).getTitle() << std::endl; {
std::cout << "New title: "; std::string status_message;
std::string newTitle; std::cout << "Title: " << results.at(index).getTitle() << std::endl;
getline(std::cin, newTitle); std::cout << "New title: ";
if (!newTitle.empty()) { std::string newTitle;
results.at(index).setTitle(newTitle); getline(std::cin, newTitle);
results.at(index).save(); if (!newTitle.empty()) {
status_message = "Title changed to " + newTitle; results.at(index).setTitle(newTitle);
list(status_message, Colors::GREEN(), index_A, index_B); results.at(index).save();
status_message = "Title changed to " + newTitle;
list(status_message, Colors::GREEN(), index_A, index_B);
break;
}
list("No title change!", Colors::YELLOW(), index_A, index_B);
} }
list("No title change!", Colors::YELLOW(), index_A, index_B);
break; break;
} }
} }

View File

@@ -13,8 +13,8 @@ namespace platform {
private: private:
void list(const std::string& status, const std::string& color, int index_A, int index_B); void list(const std::string& status, const std::string& color, int index_A, int index_B);
bool confirmAction(const std::string& intent, const std::string& fileName) const; bool confirmAction(const std::string& intent, const std::string& fileName) const;
void report(const int index, const bool excelReport); std::string report(const int index, const bool excelReport);
void report_compared(const int index_A, const int index_B); std::string report_compared(const int index_A, const int index_B);
void showIndex(const int index, const int idx); void showIndex(const int index, const int idx);
std::pair<std::string, std::string> sortList(); std::pair<std::string, std::string> sortList();
void menu(); void menu();