Bind season calendar and confirmed fixture rescheduling to engine (by Codex)
This commit is contained in:
1 parent
7e170a00c7
commit
6119d7f21e
17 files changed
+388
-16
No files matched your search
@@ -0,0 +1,101 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
Json App::engine_calendar_view() const {
|
||||
auto view = engine_calendar_projection(engine_data_);
|
||||
view["selected"] = engine_calendar_day_ >= 0 && engine_calendar_day_ < view.at("count").get<int>() ? engine_calendar_day_ : view.at("today").is_number_integer() ? view.at("today").get<int>() : 0;
|
||||
view["source_day"] = -1; view["targets"] = Json::array(); view["moved_days"] = Json::array();
|
||||
try {
|
||||
const auto schedule = engine_scheduling_projection(engine_data_);
|
||||
for (const auto &row : schedule.at("movable")) if (row.at("id") == engine_move_id_) { view["source_day"] = row.at("day"); view["targets"] = row.at("targets"); }
|
||||
for (const auto &row : schedule.at("moved")) view["moved_days"].push_back(row.at("day"));
|
||||
} catch (const std::exception &) {} // a valid calendar also works without scheduling rights
|
||||
return view;
|
||||
}
|
||||
void App::engine_calendar_sync() {
|
||||
try {
|
||||
const auto view = engine_calendar_projection(engine_data_);
|
||||
if (engine_calendar_season_ != view.at("start").get<std::string>() || engine_calendar_day_ < 0 || engine_calendar_day_ >= view.at("count").get<int>()) {
|
||||
engine_calendar_day_ = view.at("today").is_number_integer() ? view.at("today").get<int>() : 0;
|
||||
engine_move_id_.clear(); engine_calendar_season_ = view.at("start");
|
||||
}
|
||||
if (engine_schedule_pending_ && engine_response_.value("messageType", "") == "command_result") engine_move_id_.clear();
|
||||
const auto schedule = engine_scheduling_projection(engine_data_);
|
||||
bool found = false; for (const auto &row : schedule.at("movable")) found |= row.at("id") == engine_move_id_;
|
||||
if (!found) engine_move_id_.clear();
|
||||
} catch (const std::exception &) { engine_move_id_.clear(); }
|
||||
engine_schedule_pending_ = false;
|
||||
}
|
||||
std::string App::engine_calendar_info(const Json &view) const {
|
||||
const int selected = view.at("selected"); const auto days = calendar_days(view.at("start"));
|
||||
std::string out = calendar_date_label(days.at(size_t(selected)).iso); bool own = false;
|
||||
for (const auto &f : view.at("fixtures")) if (f.at("day") == selected) {
|
||||
own = true; out += " · " + std::to_string(f.at("round").get<int>()) + ". Spieltag: " + engine_text(f.at("home").at("name")) + " – " + engine_text(f.at("away").at("name"));
|
||||
if (!f.at("result").is_null()) out += " " + std::to_string(f.at("result")[0].get<int>()) + ":" + std::to_string(f.at("result")[1].get<int>());
|
||||
if (f.at("status") == "rescheduled") out += " · verlegt vom " + calendar_date_label(f.at("originalDate"));
|
||||
else if (f.at("status") == "postponed") out += " · ausgefallen";
|
||||
else if (f.at("status") == "void") out += " · ohne Ergebnis";
|
||||
}
|
||||
if (!own) {
|
||||
const auto event = view.at("events").value(std::to_string(selected), Json{{"kinds",Json::array()}});
|
||||
std::set<std::string> labels;
|
||||
for (const auto &kind : event.at("kinds")) {
|
||||
const auto k = kind.get<std::string>();
|
||||
labels.insert(k == "league" ? "Ligatermin" : k == "friendly" ? "Freundschaftsspiel" : k == "replay" ? "Nachholtermin" : k == "indoor" ? "Hallenturnier" : k == "national" ? "Länderspieltermin" : k.starts_with("cup:") ? "Pokaltermin" : "Weiterer Wettbewerbstermin");
|
||||
}
|
||||
if (labels.empty()) out += " · keine eingetragenen Termine";
|
||||
else for (const auto &label : labels) out += " · " + label;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
std::string App::engine_calendar_footer(const Json &view) {
|
||||
const auto &team = engine_data_.at("desktop").at("data").at("team");
|
||||
const auto *nation = world_->find("nations", team.value("nationId", ""));
|
||||
const auto *league = view.at("league").is_string() ? world_->find("competitions", view.at("league")) : nullptr;
|
||||
return "<nav class=\"report-footer\">" + btn("engine-calendar-filter", esc(nation ? world_->name(*nation) : "Land nicht verfügbar"), "report-reset engine-calendar-label", "id=\"calendar-country\" disabled style=\"" + rect(0,0,1294,94) + "\"") +
|
||||
btn("engine-calendar-filter", esc(league ? world_->name(*league) : "Vereinskalender"), "report-reset engine-calendar-label", "id=\"calendar-league\" disabled style=\"" + rect(1318,0,1294,94) + "\"") + "</nav>";
|
||||
}
|
||||
std::string App::engine_postpone_view() {
|
||||
const auto view = engine_calendar_view(), schedule = engine_scheduling_projection(engine_data_);
|
||||
const Json *source = nullptr, *selected = nullptr; bool undo = false;
|
||||
for (const auto &row : schedule.at("movable")) {
|
||||
if (row.at("id") == engine_move_id_) source = &row;
|
||||
if (row.at("day") == view.at("selected")) selected = &row;
|
||||
}
|
||||
for (const auto &row : schedule.at("moved")) undo |= row.at("day") == view.at("selected");
|
||||
const bool target = source && std::find(source->at("targets").begin(),source->at("targets").end(),view.at("selected")) != source->at("targets").end();
|
||||
std::string title = "Saison " + engine_data_.at("desktop").at("meta").at("season").at("label").get<std::string>();
|
||||
auto source_view = view; if (source) source_view["selected"] = source->at("day");
|
||||
const auto hint = !source ? (schedule.at("movable").empty() ? "Zurzeit ist keine Partie zur Verlegung freigegeben." : "Ein verlegbares Ligaspiel auswählen.") : target ? "Für diese Partie verfügbar." : "Dieser Termin ist für die gewählte Partie nicht verfügbar.";
|
||||
std::string out = "<div id=\"report-underlay\" class=\"report-underlay postpone-layout\"><header class=\"planning-heading\"><h2>Spielverlegung</h2><p>" + esc(title) + "</p>" + planning_progress(source != nullptr,true) + "</header>" + calendar_grid(view,132,1362,28,22,false,true);
|
||||
out += "<section class=\"postpone-summary source " + std::string(source ? "selected-source" : "") + "\"><h3>Ausgangsspiel</h3><p>" + esc(source ? engine_calendar_info(source_view) : selected ? engine_calendar_info(view) : "Zuerst eine verlegbare Partie wählen.") + "</p><small>" + std::string(source ? "Grün markierte Ziele sind für diese Partie verfügbar." : "Mit „Ausgangsspiel wählen“ bestätigen.") + "</small>" + (source ? btn("postpone-cancel","×","postpone-cancel","id=\"postpone-cancel\" aria-label=\"Ausgangsspielauswahl aufheben\"") : "") + "</section>";
|
||||
out += "<section class=\"postpone-summary target\"><h3>Gewählter Termin</h3><p>" + esc(engine_calendar_info(view)) + "</p><small class=\"" + std::string(target ? "valid" : "") + "\">" + hint + "</small></section><nav class=\"planning-footer\">";
|
||||
out += btn("postpone-source","Ausgangsspiel wählen",{},"id=\"postpone-source\" " + std::string(selected ? "" : "disabled")) + btn("postpone-move","Hierhin verlegen",{},"id=\"postpone-move\" " + std::string(target && schedule.at("allowed") == true ? "" : "disabled")) + btn("postpone-undo","Verlegung zurücknehmen",{},"id=\"postpone-undo\" " + std::string(undo && schedule.at("allowed") == true ? "" : "disabled"));
|
||||
return out + "</nav></div>";
|
||||
}
|
||||
bool App::engine_calendar_action(const std::string &action,Rml::Element *target) {
|
||||
if (menu_ != "calendar" && menu_ != "postpone") return false;
|
||||
if (action != "calendar-select" && !action.starts_with("postpone-")) return false;
|
||||
if (engine_busy_ || !engine_fresh_) return true;
|
||||
const auto view = engine_calendar_view();
|
||||
if (action == "calendar-select" && target) {
|
||||
const int day = target->GetAttribute<int>("data-id",-1);
|
||||
if (day >= 0 && day < view.at("count").get<int>()) { engine_calendar_day_ = day; focus_after_render_ = target->GetId(); refresh(); } return true;
|
||||
}
|
||||
if (action == "postpone-cancel") { engine_move_id_.clear(); focus_after_render_ = "postpone-source"; refresh(); return true; }
|
||||
const auto schedule = engine_scheduling_projection(engine_data_);
|
||||
if (action == "postpone-source") {
|
||||
for (const auto &row : schedule.at("movable")) if (row.at("day") == view.at("selected")) { engine_move_id_ = row.at("id"); focus_after_render_ = "calendar-day-" + std::to_string(engine_calendar_day_); refresh(); break; }
|
||||
return true;
|
||||
}
|
||||
const auto days = calendar_days(view.at("start")); const auto date = days.at(size_t(engine_calendar_day_)).iso;
|
||||
Json command; std::string question;
|
||||
if (action == "postpone-move") {
|
||||
command = engine_reschedule_command(engine_data_,engine_move_id_,date,editor::new_id("request:ui-"));
|
||||
const Json *row = nullptr; for (const auto &r : schedule.at("movable")) if (r.at("id") == engine_move_id_) row = &r;
|
||||
if (!row) return true;
|
||||
question = engine_text(row->at("home").at("name")) + " – " + engine_text(row->at("away").at("name")) + " vom " + calendar_date_label(row->at("date")) + " auf " + calendar_date_label(date) + " verlegen?";
|
||||
} else if (action == "postpone-undo") {
|
||||
command = engine_reschedule_undo(engine_data_,date,editor::new_id("request:ui-"));
|
||||
question = "Verlegungen dieses Vereins am " + calendar_date_label(date) + " zurücknehmen und auf ihre ursprünglichen Termine setzen?";
|
||||
} else return true;
|
||||
confirmation(question,[this,command] { engine_schedule_pending_ = true; focus_after_render_ = "calendar-day-" + std::to_string(engine_calendar_day_); engine_finance_submit(command); }); return true;
|
||||
}
|
||||
Reference in new issue
Block a user