|
|
|
@@ -1,10 +1,12 @@
|
|
|
|
|
#include "marks.h"
|
|
|
|
|
#include "helper_funcs.h"
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <curses.h>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <menu.h>
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
#include <panel.h>
|
|
|
|
@@ -40,11 +42,13 @@ SOFTWARE.
|
|
|
|
|
#define NLINES 10
|
|
|
|
|
#define NCOLS 40
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_X_OFFSET 10
|
|
|
|
|
#define DEFAULT_Y_OFFSET 2
|
|
|
|
|
|
|
|
|
|
void init_wins(WINDOW **wins, int n, json marks_json);
|
|
|
|
|
void win_show(WINDOW *win, char *label, int label_color);
|
|
|
|
|
void win_show(WINDOW *win, char *label, int label_color, int width);
|
|
|
|
|
|
|
|
|
|
void marks_page() {
|
|
|
|
|
|
|
|
|
|
// DONT FORGET TO UNCOMMENT
|
|
|
|
|
// json resp_from_api = bakaapi::get_grades();
|
|
|
|
|
std::ifstream f("test-data/marks2.json");
|
|
|
|
@@ -69,8 +73,10 @@ void marks_page() {
|
|
|
|
|
noecho();
|
|
|
|
|
keypad(stdscr, TRUE);
|
|
|
|
|
|
|
|
|
|
std::clog << COLS << " " << LINES << std::endl;
|
|
|
|
|
|
|
|
|
|
/* Initialize all the colors */
|
|
|
|
|
for (size_t i = 0; i < 8; i++) {
|
|
|
|
|
for (uint8_t i = 0; i < 8; i++) {
|
|
|
|
|
init_pair(i, i, COLOR_BLACK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -97,7 +103,7 @@ void marks_page() {
|
|
|
|
|
attroff(COLOR_PAIR(4));
|
|
|
|
|
doupdate();
|
|
|
|
|
|
|
|
|
|
top = my_panels[2];
|
|
|
|
|
top = my_panels[resp_from_api["Subjects"].size() - 1];
|
|
|
|
|
while ((ch = getch()) != KEY_F(1)) {
|
|
|
|
|
switch (ch) {
|
|
|
|
|
case 9:
|
|
|
|
@@ -109,6 +115,8 @@ void marks_page() {
|
|
|
|
|
doupdate();
|
|
|
|
|
}
|
|
|
|
|
endwin();
|
|
|
|
|
delete[] my_wins;
|
|
|
|
|
delete[] my_panels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Put all the windows */
|
|
|
|
@@ -116,32 +124,48 @@ void init_wins(WINDOW **wins, int n, json marks_json) {
|
|
|
|
|
int x, y, i;
|
|
|
|
|
char label[1500];
|
|
|
|
|
|
|
|
|
|
y = 2;
|
|
|
|
|
x = 10;
|
|
|
|
|
y = DEFAULT_Y_OFFSET;
|
|
|
|
|
x = DEFAULT_X_OFFSET;
|
|
|
|
|
uint8_t curent_color = 0;
|
|
|
|
|
for (i = 0; i < n; ++i) {
|
|
|
|
|
wins[i] = newwin(NLINES, NCOLS, y, x);
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Calculate label and max_text_length to determine window width
|
|
|
|
|
std::string sub_name = marks_json["Subjects"][i]["Subject"]["Name"];
|
|
|
|
|
std::string sub_avg_s = marks_json["Subjects"][i]["AverageText"];
|
|
|
|
|
|
|
|
|
|
sprintf(label, "%s - avg: %s", sub_name.c_str(), sub_avg_s.c_str());
|
|
|
|
|
|
|
|
|
|
size_t max_text_length = strlen(label);
|
|
|
|
|
for (int j = 0; j < marks_json["Subjects"][i]["Marks"].size(); j++) {
|
|
|
|
|
std::string caption = marks_json["Subjects"][i]["Marks"][j]["Caption"];
|
|
|
|
|
std::string theme = marks_json["Subjects"][i]["Marks"][j]["Theme"];
|
|
|
|
|
caption = rm_tr_le_whitespace(caption);
|
|
|
|
|
theme = rm_tr_le_whitespace(theme);
|
|
|
|
|
max_text_length =
|
|
|
|
|
std::max({max_text_length, caption.length(), theme.length()});
|
|
|
|
|
}
|
|
|
|
|
curent_color++;
|
|
|
|
|
if (curent_color >= 7) {
|
|
|
|
|
curent_color = 1;
|
|
|
|
|
|
|
|
|
|
int width = max_text_length + 4;
|
|
|
|
|
|
|
|
|
|
// hanndle windows overflowing off screen
|
|
|
|
|
if (x + width > COLS) {
|
|
|
|
|
x = DEFAULT_X_OFFSET;
|
|
|
|
|
y += NLINES + 10;
|
|
|
|
|
}
|
|
|
|
|
win_show(wins[i], label, curent_color);
|
|
|
|
|
x += 40;
|
|
|
|
|
|
|
|
|
|
wins[i] = newwin(NLINES, NCOLS, y, x);
|
|
|
|
|
win_show(wins[i], label, curent_color + 1, width);
|
|
|
|
|
|
|
|
|
|
curent_color = (curent_color + 1) % 7;
|
|
|
|
|
x += width + 5;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Show the window with a border and a label */
|
|
|
|
|
void win_show(WINDOW *win, char *label, int label_color) {
|
|
|
|
|
int startx, starty, height, width;
|
|
|
|
|
void win_show(WINDOW *win, char *label, int label_color, int width) {
|
|
|
|
|
int startx, starty, height;
|
|
|
|
|
height = 20;
|
|
|
|
|
|
|
|
|
|
wresize(win, height, strlen(label) + 4);
|
|
|
|
|
wresize(win, height, width);
|
|
|
|
|
|
|
|
|
|
getbegyx(win, starty, startx);
|
|
|
|
|
getmaxyx(win, height, width);
|
|
|
|
@@ -152,4 +176,5 @@ void win_show(WINDOW *win, char *label, int label_color) {
|
|
|
|
|
mvwaddch(win, 2, width - 1, ACS_RTEE);
|
|
|
|
|
|
|
|
|
|
print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color));
|
|
|
|
|
print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color));
|
|
|
|
|
}
|