This commit is contained in:
parent
6985b21d37
commit
05d3819d56
1
src/const.h
Normal file
1
src/const.h
Normal file
@ -0,0 +1 @@
|
||||
#define VERSION "0.5"
|
@ -16,7 +16,7 @@ char *choices[] = {
|
||||
"Homework", "Absence", "Exit", (char *)NULL,
|
||||
};
|
||||
void (*choicesFuncs[])() = {
|
||||
NULL, marks_page, NULL, NULL, NULL, NULL, NULL, NULL
|
||||
nullptr, marks_page, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr
|
||||
};
|
||||
|
||||
void main_menu() {
|
||||
@ -90,9 +90,11 @@ void main_menu() {
|
||||
menu_driver(my_menu, REQ_UP_ITEM);
|
||||
break;
|
||||
case 10: // ENTER
|
||||
endwin();
|
||||
clear();
|
||||
choicesFuncs[item_index(current_item(my_menu))]();
|
||||
pos_menu_cursor(my_menu);
|
||||
refresh();
|
||||
wrefresh(my_menu_win);
|
||||
break;
|
||||
}
|
||||
wrefresh(my_menu_win);
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
#include "net.h"
|
||||
#include "color.h"
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
@ -145,6 +146,7 @@ void marks_page() {
|
||||
|
||||
// Cleanup
|
||||
endwin();
|
||||
clear();
|
||||
delete[] my_wins;
|
||||
delete[] my_panels;
|
||||
delete[] original_y;
|
||||
@ -161,10 +163,13 @@ void init_wins(WINDOW **wins, int n, json marks_json) {
|
||||
uint8_t curent_color = 0;
|
||||
|
||||
int MaxHight = 0;
|
||||
// this loop true subjects
|
||||
for (i = 0; i < n; ++i) {
|
||||
|
||||
// Calculate label and max_text_length to determine window width
|
||||
std::string sub_name = marks_json["Subjects"][i]["Subject"]["Name"];
|
||||
// DEBUG
|
||||
// std::clog << BLUE"[LOG]" << RESET" procesing subject: " << sub_name << "\n";
|
||||
std::string sub_avg_s = marks_json["Subjects"][i]["AverageText"];
|
||||
sprintf(label, "%s - avg: %s", sub_name.c_str(), sub_avg_s.c_str());
|
||||
|
||||
@ -228,14 +233,9 @@ void win_show(WINDOW *win, char *label, int label_color, int width, int height,
|
||||
i++) {
|
||||
Caption = marks_json["Subjects"][SubjectIndex]["Marks"][i]["Caption"];
|
||||
Caption = rm_tr_le_whitespace(Caption);
|
||||
Caption.append(std::format(
|
||||
" - {{{}}} [{}]",
|
||||
marks_json["Subjects"][SubjectIndex]["Marks"][i]["MarkText"]
|
||||
.get<std::string>(),
|
||||
marks_json["Subjects"][SubjectIndex]["Marks"][i]["Weight"].get<int>()));
|
||||
Caption.append(std::format(" - {{{}}} [{}]",marks_json["Subjects"][SubjectIndex]["Marks"][i]["MarkText"].get<std::string>(),marks_json["Subjects"][SubjectIndex]["Marks"][i]["Weight"].get<int>()));
|
||||
strncpy(CaptionBuf, Caption.c_str(), sizeof(CaptionBuf)-1);
|
||||
print_in_middle(win, 3 + i + AdditionalOffset, 0, width, CaptionBuf,
|
||||
COLOR_PAIR(label_color));
|
||||
print_in_middle(win, 3 + i + AdditionalOffset, 0, width, CaptionBuf,COLOR_PAIR(label_color));
|
||||
|
||||
strncpy(ThemeBuf,
|
||||
rm_tr_le_whitespace(marks_json["Subjects"][SubjectIndex]["Marks"][i]["Theme"]
|
||||
|
15
src/net.cpp
15
src/net.cpp
@ -16,6 +16,7 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include <string>
|
||||
#include "const.h"
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
@ -42,8 +43,13 @@ std::tuple<std::string, int> send_curl_request(std::string endpoint,
|
||||
std::string req_data) {
|
||||
std::string response;
|
||||
std::string url = baka_api_url + endpoint;
|
||||
if (type == GET) {
|
||||
url.append("?" + req_data);
|
||||
}
|
||||
|
||||
if (curl) {
|
||||
// DEBUG
|
||||
// std::clog << BLUE"[LOG]" << RESET" sending to endpoint: " << url << "\n";
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
|
||||
@ -52,11 +58,11 @@ std::tuple<std::string, int> send_curl_request(std::string endpoint,
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req_data.c_str());
|
||||
|
||||
|
||||
struct curl_slist *headers = NULL;
|
||||
headers = curl_slist_append(
|
||||
headers, "Content-Type: application/x-www-form-urlencoded");
|
||||
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
|
||||
headers = curl_slist_append(headers, std::format("User-Agent: bakatui/{}", VERSION).c_str());
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
|
||||
switch (type) {
|
||||
@ -64,6 +70,7 @@ std::tuple<std::string, int> send_curl_request(std::string endpoint,
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
|
||||
break;
|
||||
case POST:
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req_data.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
||||
break;
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user