75 lines
2.7 KiB
C++
75 lines
2.7 KiB
C++
#include "ListDisplay.hpp"
|
|
#include "Exceptions.hpp"
|
|
#include "Tools.hpp"
|
|
#include <iomanip>
|
|
|
|
ListDisplay::ListDisplay(const List<BaseRecord *> &_allRecordsPtrList)
|
|
: allRecordsPtrList(_allRecordsPtrList), fromDate(), toDate(),
|
|
searchForStu(), recordNumPerPage(20), currentPageIndex(0),
|
|
maxPageIndex(allRecordsPtrList.length() / recordNumPerPage),
|
|
sortOrder(ASCENT), sortByProp(RecordID),
|
|
tableTitleRow(
|
|
"│ " + setMiddle("Record ID", recordDisplayRowSize.recordID) + " │ " +
|
|
setMiddle("Date", recordDisplayRowSize.date) + " │ " +
|
|
setMiddle("Course Name", recordDisplayRowSize.courseName) + " │ " +
|
|
setMiddle("Stud. ID", recordDisplayRowSize.studentID) + " │ " +
|
|
setMiddle("Stud. name", recordDisplayRowSize.studentName) + " │ " +
|
|
setMiddle("Type", recordDisplayRowSize.type) + " │") {
|
|
this->filteredRecordsPtrList =
|
|
allRecordsPtrList.filtered([](BaseRecord *const &) { return true; });
|
|
};
|
|
|
|
bool ListDisplay::hasNext() {
|
|
return currentPageIndex < maxPageIndex;
|
|
}
|
|
|
|
bool ListDisplay::hasPrev() {
|
|
return currentPageIndex > 0;
|
|
}
|
|
|
|
void ListDisplay::displayNext() {
|
|
if (!this->hasNext()) {
|
|
throw(PageIndexError("No next page!"));
|
|
}
|
|
this->currentPageIndex++;
|
|
this->display();
|
|
}
|
|
|
|
void ListDisplay::displayPrev() {
|
|
if (!this->hasPrev()) {
|
|
throw(PageIndexError("No prev page!"));
|
|
}
|
|
this->currentPageIndex--;
|
|
this->display();
|
|
}
|
|
|
|
void ListDisplay::display() {
|
|
bool brightBG = true;
|
|
std::cout << setoutputcolor(ConsoleColorTool::blue) << " Search date: from "
|
|
<< resetOutputColor << this->fromDate.toString()
|
|
<< setoutputcolor(ConsoleColorTool::blue) << " to "
|
|
<< resetOutputColor << this->toDate.toString();
|
|
std::cout << " ";
|
|
std::cout << setoutputcolor(ConsoleColorTool::blue)
|
|
<< "Search for student: ID: " << resetOutputColor
|
|
<< this->searchForStu.getNumberString()
|
|
<< setoutputcolor(ConsoleColorTool::blue)
|
|
<< " Name: " << resetOutputColor << this->searchForStu.getName()
|
|
<< "\n";
|
|
// std::cout << setbgcolor(ConsoleColorTool::cyan);
|
|
std::cout << this->tableTitleRow << std::endl;
|
|
Iterator<BaseRecord *> iter = this->filteredRecordsPtrList.iterate(
|
|
this->currentPageIndex * this->recordNumPerPage);
|
|
int i = recordNumPerPage;
|
|
while (i > 0 && iter) {
|
|
if (brightBG) {
|
|
std::cout << setbgcolor(ConsoleColorTool::lightGray);
|
|
}
|
|
iter.next()->display();
|
|
if (brightBG) {
|
|
std::cout << resetOutputColor;
|
|
}
|
|
brightBG = !brightBG;
|
|
i--;
|
|
}
|
|
} |