// SPDX-License-Identifier: GPL-3.0-only std::string App::planning_progress(bool second, bool postpone) { const std::array captions = postpone ? std::array{"Spiel wählen", "Termin wählen"} : std::array{"Gegner", "Termin"}; std::string out = "
"; for (int i = 0; i < 2; ++i) out += "" + std::to_string(i + 1) + "" + captions[size_t(i)] + ""; return out + "
"; } std::string App::render_postpone() { if (engine_mode_) return engine_postpone_view(); const auto calendar = planning_calendar(); const auto own = manager(snap()).value("club", ""); const auto *league = world_->find("competitions", calendar.at("league")); const auto fixtures = calendar_fixtures(calendar, *world_, own); const int day = calendar.at("selected"), from = calendar.at("source_day"); const auto selected = std::find_if(fixtures.begin(), fixtures.end(), [&](const auto &f) { return f.day == day; }); const auto source = std::find_if(fixtures.begin(), fixtures.end(), [&](const auto &f) { return f.from == from; }); const bool has_source = source != fixtures.end(); const bool valid = has_source && day >= 7 && !calendar_day_occupied(calendar, *world_, own, day); const auto start = calendar.at("start").get().substr(0, 4); const auto season = start + "/" + std::to_string((std::stoi(start) + 1) % 100); const auto status = !has_source ? "Zuerst ein gelb markiertes Ligaspiel wählen." : day < 7 ? "Bitte einen Termin ab dem 8. Juli wählen." : !valid ? "Dieser Termin ist bereits belegt." : "Freier Termin · Spiel kann verlegt werden."; auto source_calendar = calendar; source_calendar["selected"] = has_source ? source->day : day; const auto source_label = has_source || selected != fixtures.end() ? calendar_day_info(source_calendar) : "Ein gelb markiertes Ligaspiel im Kalender anklicken."; std::string body = "
" "

" + esc(world_->name(*world_->find("clubs", own))) + "

" + esc(league ? world_->name(*league) : "") + " · Saison " + season + "

" + planning_progress(has_source, true) + "
" + calendar_grid(calendar, 132, 1362, 28, 22, false, true) + "

Ausgangsspiel

" + esc(source_label) + "

" + (has_source ? "Das Ausgangsspiel ist im Kalender grün umrahmt." : "Mit „Ausgangsspiel wählen“ bestätigen.") + "" + (has_source ? btn("postpone-cancel", "×", "postpone-cancel", "id=\"postpone-cancel\" aria-label=\"Ausgangsspielauswahl aufheben\"") : "") + "

Neuer Termin

" + esc(calendar_day_info(calendar)) + "

" + status + "
" + render_planning_dialog(); } std::string App::render_friendlies() { if (engine_mode_) return engine_friendlies_view(); const auto calendar = planning_calendar(); const auto own = manager(snap()).value("club", ""); const auto *league = world_->find("competitions", calendar.at("friendly_league")); const auto *opponent = world_->find("clubs", calendar.at("opponent")); const bool booking = calendar.at("friendly_stage") == 1, full = calendar.at("friendlies").size() >= 20; const int day = calendar.at("selected"); const bool available = day >= 7 && !calendar_day_occupied(calendar, *world_, own, day); const auto start = calendar.at("start").get().substr(0, 4); const auto season = start + "/" + std::to_string((std::stoi(start) + 1) % 100); const auto venue = calendar.at("home").get() ? "Heimspiel" : "Auswärtsspiel"; std::string body = "
" "

" + (booking ? label(opponent, 58) : esc(league ? world_->name(*league) : "—")) + "

" + (booking ? std::string(venue) + " · Kostenbeitrag " + cash(calendar_friendly_fee(calendar, *world_)) : "Freundschaftsspiel vereinbaren · Saison " + season) + "

" + planning_progress(booking, false) + "
"; const auto count_label = "Vorgemerkte Spiele · " + std::to_string(calendar.at("friendlies").size()); if (!booking) { const auto clubs = world_->clubs(calendar.at("friendly_league")); auto reports = snap().state.at("reports"); reports["league"] = calendar.at("friendly_league"); reports["round"] = 0; const auto strengths = report_strength_rows(*world_, reports); body += "
"; for (const auto &heading : {"Gegner", "Stärke", "Platz", "Spiele"}) body += "
" + std::string(heading) + "
"; body += "
"; size_t visible = 0; for (size_t i = 0; i < clubs.size(); ++i) { const auto *c = clubs[i]; const auto id = c->value("id", ""); if (id == own) continue; const auto value = std::find_if(strengths.begin(), strengths.end(), [&](const auto &r) { return r.at("club") == id; }); const auto strength = value == strengths.end() ? "—" : report_number(value->at("strength")); body += "
" + btn("friendly-opponent", label(c, 42), "friendly-opponent", "id=\"friendly-opponent-" + esc(id) + "\" data-id=\"" + esc(id) + "\" aria-pressed=\"" + (calendar.at("opponent") == id ? "true" : "false") + "\"") + "
" + strength + "
" + std::to_string(i + 1) + "
26
"; } body += "
" + render_planning_dialog(); } std::string App::render_planning_dialog() { if (engine_mode_) return engine_friendly_dialog(); if (planning_dialog_.empty()) return {}; const auto calendar = planning_calendar(); const auto *opponent = world_->find("clubs", calendar.at("opponent")); std::string heading, body, actions; double height = planning_dialog_ == "undo-blocked" ? 332 : 341; const auto close = [&](const std::string &caption) { return btn("planning-close", caption, {}, "id=\"planning-close\""); }; if (planning_dialog_ == "venue" || planning_dialog_ == "quote") { const bool quote = planning_dialog_ == "quote"; heading = quote ? "Freundschaftsspiel · Kosten" : "Austragungsort"; height = quote ? 720.5 : 496; body = "
" + crest(opponent, 72) + "" + esc(opponent ? world_->name(*opponent) : "—") + "" + (quote ? std::string(calendar.at("home").get() ? "Heimspiel" : "Auswärtsspiel") : "Heimspiel oder Auswärtsspiel?") + "
"; if (quote) { body += "
Fiktiver Kostenbeitrag" + cash(calendar_friendly_fee(calendar, *world_)) + "

Anschließend einen freien Termin im Kalender wählen.

"; actions = close("Abbrechen") + btn("friendly-quote-accept", "Termin wählen", {}, "id=\"friendly-quote-accept\""); } else actions = btn("friendly-venue", "Heim", {}, "id=\"friendly-home\" data-id=\"home\"") + btn("friendly-venue", "Auswärts", {}, "id=\"friendly-away\" data-id=\"away\"") + close("Abbrechen"); } else if (planning_dialog_ == "list") { heading = "Vorgemerkte Freundschaftsspiele"; auto bookings = calendar.at("friendlies"); std::sort(bookings.begin(), bookings.end(), [](const auto &a, const auto &b) { return a.at("day") < b.at("day"); }); const auto days = calendar_days(calendar.at("start")); height = bookings.empty() ? 330.5 : 287 + std::min(1020., 80. * (bookings.size() + 1)); body = "
"; if (bookings.empty()) body += "

Noch keine Freundschaftsspiele vorgemerkt.

"; else { body += "
DatumGegnerOrt
"; for (const auto &f : bookings) body += "
" + calendar_date_label(days.at(f.at("day").get()).iso) + "" + label(world_->find("clubs", f.at("opponent")), 42) + "" + (f.at("home").get() ? "Heim" : "Auswärts") + "
"; } body += "
"; actions = close("Zurück"); } else { heading = planning_dialog_ == "booked" ? "Spiel vorgemerkt" : "Rücknahme nicht möglich"; body = "

" + esc(planning_notice_) + "

"; actions = close("Verstanden"); } return "

" + heading + "

" + body + "
"; }