Compare commits
4 Commits
0.6
..
17e850e6d7
| Author | SHA1 | Date | |
|---|---|---|---|
| 17e850e6d7 | |||
| 01cf082351 | |||
| 5088b273b6 | |||
| 17f4316947 |
@@ -5,4 +5,9 @@
|
|||||||
> [nlohmann-json](https://github.com/nlohmann/json)
|
> [nlohmann-json](https://github.com/nlohmann/json)
|
||||||
|
|
||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
> Only marks work right now
|
> Only folowing works:
|
||||||
|
> - [x] Login
|
||||||
|
> - [x] Marks
|
||||||
|
> - [-] Timetable
|
||||||
|
> - [ ] Komens
|
||||||
|
> - [ ] Absence
|
||||||
|
|||||||
+236
-109
@@ -13,6 +13,7 @@
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <panel.h>
|
#include <panel.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
@@ -23,8 +24,11 @@ using nlohmann::json;
|
|||||||
const wchar_t *day_abriviations[] = {nullptr, L"Mo", L"Tu", L"We",
|
const wchar_t *day_abriviations[] = {nullptr, L"Mo", L"Tu", L"We",
|
||||||
L"Th", L"Fr", L"Sa", L"Su"};
|
L"Th", L"Fr", L"Sa", L"Su"};
|
||||||
|
|
||||||
void draw_grid(const uint8_t num_of_columns, const uint8_t num_of_rows,
|
void refresh_cells(uint8_t num_of_columns, uint8_t num_of_days,
|
||||||
const uint16_t cell_width, const uint16_t cell_height);
|
uint16_t cell_width, uint16_t cell_height,
|
||||||
|
std::vector<std::vector<WINDOW *>> &cells,
|
||||||
|
std::vector<uint8_t> &HourIdLookupTable,
|
||||||
|
json &resp_from_api);
|
||||||
|
|
||||||
uint8_t hour_id_to_index(const std::vector<uint8_t> &HourIdLookupTable,
|
uint8_t hour_id_to_index(const std::vector<uint8_t> &HourIdLookupTable,
|
||||||
uint8_t id) {
|
uint8_t id) {
|
||||||
@@ -57,6 +61,19 @@ std::wstring get_data_for_atom(json &resp_from_api, json *atom,
|
|||||||
.get<std::string>());
|
.get<std::string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json *find_atom_by_indexes(json &resp_from_api, uint8_t day_index,
|
||||||
|
uint8_t hour_index,
|
||||||
|
const std::vector<uint8_t> &HourIdLookupTable) {
|
||||||
|
for (uint8_t k = 0; k < resp_from_api["Days"][day_index]["Atoms"].size();
|
||||||
|
k++) {
|
||||||
|
if (resp_from_api["Days"][day_index]["Atoms"][k]["HourId"].get<uint8_t>() ==
|
||||||
|
HourIdLookupTable[hour_index]) {
|
||||||
|
return &resp_from_api["Days"][day_index]["Atoms"][k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr; // No matching atom found
|
||||||
|
}
|
||||||
|
|
||||||
void timetable_page() {
|
void timetable_page() {
|
||||||
// DONT FORGET TO UNCOMMENT
|
// DONT FORGET TO UNCOMMENT
|
||||||
// json resp_from_api =
|
// json resp_from_api =
|
||||||
@@ -226,17 +243,227 @@ void timetable_page() {
|
|||||||
cells[i][j] =
|
cells[i][j] =
|
||||||
newwin(cell_height, cell_width, i * cell_height + DEFAULT_OFFSET,
|
newwin(cell_height, cell_width, i * cell_height + DEFAULT_OFFSET,
|
||||||
j * cell_width + DEFAULT_OFFSET);
|
j * cell_width + DEFAULT_OFFSET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
refresh_cells(num_of_columns, num_of_days, cell_width, cell_height, cells,
|
||||||
|
HourIdLookupTable, resp_from_api);
|
||||||
|
|
||||||
json *atom;
|
refresh();
|
||||||
for (uint8_t k = 0; k < resp_from_api["Days"][i]["Atoms"].size(); k++) {
|
|
||||||
if (resp_from_api["Days"][i]["Atoms"][k]["HourId"].get<uint8_t>() ==
|
SelectorType selected_cell(0, 0, 0, num_of_columns - 1, 0, num_of_days - 1);
|
||||||
HourIdLookupTable[j]) {
|
std::array<WINDOW *, 4> selector_windows;
|
||||||
atom = &resp_from_api["Days"][i]["Atoms"][k];
|
std::array<PANEL *, 4> selector_panels;
|
||||||
goto correct_atom_found;
|
|
||||||
|
{
|
||||||
|
const chtype corners[] = {
|
||||||
|
ACS_ULCORNER, /* Upper left corner */
|
||||||
|
ACS_URCORNER, /* Upper right corner */
|
||||||
|
ACS_LLCORNER, /* Lower left corner */
|
||||||
|
ACS_LRCORNER /* Lower right corner */
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned short x_offset, y_offset;
|
||||||
|
for (uint8_t i = 0; i < selector_windows.size(); i++) {
|
||||||
|
|
||||||
|
if (!(i % 2 == 0)) {
|
||||||
|
x_offset = cell_width - 1;
|
||||||
|
} else {
|
||||||
|
x_offset = 0;
|
||||||
|
}
|
||||||
|
if (!(i < 2)) {
|
||||||
|
y_offset = cell_height - 1;
|
||||||
|
} else {
|
||||||
|
y_offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
selector_windows[i] =
|
||||||
|
newwin(1, 1, DEFAULT_OFFSET + y_offset, DEFAULT_OFFSET + x_offset);
|
||||||
|
selector_panels[i] = new_panel(selector_windows[i]);
|
||||||
|
wattron(selector_windows[i], COLOR_PAIR(COLOR_RED));
|
||||||
|
mvwaddch(selector_windows[i], 0, 0, corners[i]);
|
||||||
|
wattroff(selector_windows[i], COLOR_PAIR(COLOR_RED));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
update_panels();
|
||||||
|
doupdate();
|
||||||
|
|
||||||
|
WINDOW *infobox_window;
|
||||||
|
PANEL *infobox_panel;
|
||||||
|
|
||||||
|
bool is_info_box_open = false;
|
||||||
|
int ch;
|
||||||
|
while ((ch = getch()) != KEY_F(1)) {
|
||||||
|
if (is_info_box_open) {
|
||||||
|
werase(infobox_window);
|
||||||
|
wrefresh(infobox_window);
|
||||||
|
hide_panel(infobox_panel);
|
||||||
|
del_panel(infobox_panel);
|
||||||
|
delwin(infobox_window);
|
||||||
|
wclear(infobox_window);
|
||||||
|
touchwin(stdscr);
|
||||||
|
refresh();
|
||||||
|
refresh_cells(num_of_columns, num_of_days, cell_width, cell_height, cells,
|
||||||
|
HourIdLookupTable, resp_from_api);
|
||||||
|
for (uint8_t i = 0; i < selector_panels.size(); i++) {
|
||||||
|
top_panel(selector_panels[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
update_panels();
|
||||||
|
doupdate();
|
||||||
|
refresh();
|
||||||
|
is_info_box_open = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
run_loop_again:
|
||||||
|
switch (ch) {
|
||||||
|
case KEY_UP:
|
||||||
|
case 'k':
|
||||||
|
selected_cell.y--;
|
||||||
|
break;
|
||||||
|
case KEY_DOWN:
|
||||||
|
case 'j':
|
||||||
|
selected_cell.y++;
|
||||||
|
break;
|
||||||
|
case KEY_LEFT:
|
||||||
|
case 'h':
|
||||||
|
selected_cell.x--;
|
||||||
|
break;
|
||||||
|
case KEY_RIGHT:
|
||||||
|
case 'l':
|
||||||
|
selected_cell.x++;
|
||||||
|
break;
|
||||||
|
case 10: // ENTER
|
||||||
|
json *atom = find_atom_by_indexes(resp_from_api, selected_cell.y,
|
||||||
|
selected_cell.x, HourIdLookupTable);
|
||||||
|
if (atom == nullptr) {
|
||||||
|
std::cerr << RED "[ERROR]" << RESET " Selector at invalid position\n";
|
||||||
|
safe_exit(129);
|
||||||
|
}
|
||||||
|
|
||||||
|
infobox_window = newwin(LINES * 0.6, COLS * 0.6, LINES * 0.2, COLS * 0.2);
|
||||||
|
infobox_panel = new_panel(infobox_window);
|
||||||
|
|
||||||
|
wattron(infobox_window, COLOR_PAIR(COLOR_MAGENTA));
|
||||||
|
box(infobox_window, 0, 0);
|
||||||
|
mvwaddch(infobox_window, 2, 0, ACS_LTEE);
|
||||||
|
mvwhline(infobox_window, 2, 1, ACS_HLINE, COLS * 0.6 - 2);
|
||||||
|
mvwaddch(infobox_window, 2, COLS * 0.6 - 1, ACS_RTEE);
|
||||||
|
wattroff(infobox_window, COLOR_PAIR(COLOR_MAGENTA));
|
||||||
|
|
||||||
|
std::wstring Caption;
|
||||||
|
if (atom->contains("Change") && !atom->at("Change").is_null()) {
|
||||||
|
if (!atom->at("Change")["TypeName"].is_null()) {
|
||||||
|
Caption = string_to_wstring(
|
||||||
|
atom->at("Change")["TypeName"].get<std::string>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Caption.empty()) {
|
||||||
|
try {
|
||||||
|
Caption = get_data_for_atom(resp_from_api, atom, "Subjects",
|
||||||
|
"SubjectId", "Name");
|
||||||
|
} catch (...) {
|
||||||
|
__asm__("nop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring Teacher = get_data_for_atom(resp_from_api, atom, "Teachers",
|
||||||
|
"TeacherId", "Name");
|
||||||
|
|
||||||
|
std::wstring groups = L"";
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (uint8_t i = 0; i < atom->at("GroupsIds").size(); i++) {
|
||||||
|
for (uint8_t j = 0; j < resp_from_api["Groups"].size(); j++) {
|
||||||
|
if (resp_from_api["Groups"][j]["GroupId"].get<std::string>() ==
|
||||||
|
atom->at("GroupsIds")[i].get<std::string>()) {
|
||||||
|
groups.append(string_to_wstring(
|
||||||
|
resp_from_api["Groups"][j]["Name"].get<std::string>()));
|
||||||
|
if (i + 1 < atom->at("GroupsIds").size()) {
|
||||||
|
groups.append(L", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
__asm__("nop");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring Room =
|
||||||
|
get_data_for_atom(resp_from_api, atom, "Rooms", "RoomId", "Name");
|
||||||
|
|
||||||
|
wprint_in_middle(
|
||||||
|
infobox_window, 1,
|
||||||
|
// COLS * 0.6 - wcslen(Caption.c_str()) / 2,
|
||||||
|
1, wcslen(Caption.c_str()), Caption.c_str(),
|
||||||
|
COLOR_PAIR(COLOR_PAIR(COLOR_CYAN)));
|
||||||
|
|
||||||
|
wprint_in_middle(infobox_window, 3, 1, wcslen(Teacher.c_str()),
|
||||||
|
Teacher.c_str(), COLOR_PAIR(COLOR_YELLOW));
|
||||||
|
|
||||||
|
wprint_in_middle(infobox_window, 4, 1, wcslen(groups.c_str()),
|
||||||
|
groups.c_str(), COLOR_PAIR(COLOR_CYAN));
|
||||||
|
|
||||||
|
wprint_in_middle(infobox_window, 5, 1, wcslen(Room.c_str()), Room.c_str(),
|
||||||
|
COLOR_PAIR(COLOR_YELLOW));
|
||||||
|
|
||||||
|
top_panel(infobox_panel);
|
||||||
|
update_panels();
|
||||||
|
doupdate();
|
||||||
continue;
|
continue;
|
||||||
correct_atom_found:
|
break;
|
||||||
|
}
|
||||||
|
{ // print selected indicator
|
||||||
|
chtype top_left_corner =
|
||||||
|
mvwinch(cells[selected_cell.y][selected_cell.x], 0, 0);
|
||||||
|
|
||||||
|
if (!((top_left_corner & A_CHARTEXT) == 32)) {
|
||||||
|
for (uint8_t i = 0; i < selector_panels.size(); i++) {
|
||||||
|
unsigned short x_offset, y_offset;
|
||||||
|
if (!(i % 2 == 0)) {
|
||||||
|
x_offset = cell_width - 1;
|
||||||
|
} else {
|
||||||
|
x_offset = 0;
|
||||||
|
}
|
||||||
|
if (!(i < 2)) {
|
||||||
|
y_offset = cell_height - 1;
|
||||||
|
} else {
|
||||||
|
y_offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
move_panel(selector_panels[i],
|
||||||
|
DEFAULT_OFFSET + y_offset + selected_cell.y * cell_height,
|
||||||
|
DEFAULT_OFFSET + x_offset + selected_cell.x * cell_width);
|
||||||
|
}
|
||||||
|
refresh_cells(num_of_columns, num_of_days, cell_width, cell_height,
|
||||||
|
cells, HourIdLookupTable, resp_from_api);
|
||||||
|
update_panels();
|
||||||
|
doupdate();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// skip if the cell is empty
|
||||||
|
goto run_loop_again;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete[] day_windows;
|
||||||
|
delete[] lesson_windows;
|
||||||
|
endwin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void refresh_cells(uint8_t num_of_columns, uint8_t num_of_days,
|
||||||
|
uint16_t cell_width, uint16_t cell_height,
|
||||||
|
std::vector<std::vector<WINDOW *>> &cells,
|
||||||
|
std::vector<uint8_t> &HourIdLookupTable,
|
||||||
|
json &resp_from_api) {
|
||||||
|
for (uint8_t i = 0; i < num_of_days; i++) {
|
||||||
|
for (uint8_t j = 0; j < num_of_columns; j++) {
|
||||||
|
|
||||||
|
json *atom = find_atom_by_indexes(resp_from_api, i, j, HourIdLookupTable);
|
||||||
|
if (atom == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
std::wstring Subject_Abbrev;
|
std::wstring Subject_Abbrev;
|
||||||
std::wstring Room_Abbrev;
|
std::wstring Room_Abbrev;
|
||||||
std::wstring Teacher_Abbrev;
|
std::wstring Teacher_Abbrev;
|
||||||
@@ -316,104 +543,4 @@ void timetable_page() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
refresh();
|
|
||||||
|
|
||||||
SelectorType selected_cell(0, 0, 0, num_of_columns - 1, 0, num_of_days - 1);
|
|
||||||
std::array<WINDOW *, 4> selector_windows;
|
|
||||||
std::array<PANEL *, 4> selector_panels;
|
|
||||||
|
|
||||||
{
|
|
||||||
const chtype corners[] = {
|
|
||||||
ACS_ULCORNER, /* Upper left corner */
|
|
||||||
ACS_URCORNER, /* Upper right corner */
|
|
||||||
ACS_LLCORNER, /* Lower left corner */
|
|
||||||
ACS_LRCORNER /* Lower right corner */
|
|
||||||
};
|
|
||||||
|
|
||||||
unsigned short x_offset, y_offset;
|
|
||||||
for (uint8_t i = 0; i < selector_windows.size(); i++) {
|
|
||||||
|
|
||||||
if (!(i % 2 == 0)) {
|
|
||||||
x_offset = cell_width - 1;
|
|
||||||
} else {
|
|
||||||
x_offset = 0;
|
|
||||||
}
|
|
||||||
if (!(i < 2)) {
|
|
||||||
y_offset = cell_height - 1;
|
|
||||||
} else {
|
|
||||||
y_offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
selector_windows[i] =
|
|
||||||
newwin(1, 1, DEFAULT_OFFSET + y_offset, DEFAULT_OFFSET + x_offset);
|
|
||||||
selector_panels[i] = new_panel(selector_windows[i]);
|
|
||||||
wattron(selector_windows[i], COLOR_PAIR(COLOR_RED));
|
|
||||||
mvwaddch(selector_windows[i], 0, 0, corners[i]);
|
|
||||||
wattroff(selector_windows[i], COLOR_PAIR(COLOR_RED));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
update_panels();
|
|
||||||
doupdate();
|
|
||||||
|
|
||||||
int ch;
|
|
||||||
while ((ch = getch()) != KEY_F(1)) {
|
|
||||||
run_loop_again:
|
|
||||||
switch (ch) {
|
|
||||||
case KEY_UP:
|
|
||||||
case 'k':
|
|
||||||
selected_cell.y--;
|
|
||||||
break;
|
|
||||||
case KEY_DOWN:
|
|
||||||
case 'j':
|
|
||||||
selected_cell.y++;
|
|
||||||
break;
|
|
||||||
case KEY_LEFT:
|
|
||||||
case 'h':
|
|
||||||
selected_cell.x--;
|
|
||||||
break;
|
|
||||||
case KEY_RIGHT:
|
|
||||||
case 'l':
|
|
||||||
selected_cell.x++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
{ // print selected indicator
|
|
||||||
chtype top_left_corner =
|
|
||||||
mvwinch(cells[selected_cell.y][selected_cell.x], 0, 0);
|
|
||||||
|
|
||||||
if (!((top_left_corner & A_CHARTEXT) == 32)) {
|
|
||||||
for (uint8_t i = 0; i < selector_panels.size(); i++) {
|
|
||||||
unsigned short x_offset, y_offset;
|
|
||||||
if (!(i % 2 == 0)) {
|
|
||||||
x_offset = cell_width - 1;
|
|
||||||
} else {
|
|
||||||
x_offset = 0;
|
|
||||||
}
|
|
||||||
if (!(i < 2)) {
|
|
||||||
y_offset = cell_height - 1;
|
|
||||||
} else {
|
|
||||||
y_offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
move_panel(selector_panels[i],
|
|
||||||
DEFAULT_OFFSET + y_offset + selected_cell.y * cell_height,
|
|
||||||
DEFAULT_OFFSET + x_offset + selected_cell.x * cell_width);
|
|
||||||
}
|
|
||||||
for (uint8_t i = 0; i < num_of_days; i++) {
|
|
||||||
for (uint8_t j = 0; j < num_of_columns; j++) {
|
|
||||||
wrefresh(cells[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
update_panels();
|
|
||||||
doupdate();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// skip if the cell is empty
|
|
||||||
goto run_loop_again;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete[] day_windows;
|
|
||||||
delete[] lesson_windows;
|
|
||||||
endwin();
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user