89 lines
9.5 KiB
C++
89 lines
9.5 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
std::string App::files_standard_preview() {
|
|
// Root captures the immutable template without publishing a live layout.
|
|
return picture(files_default_thumbnail(), 1678, 943.875);
|
|
}
|
|
|
|
std::string App::files_details(bool layouts, bool save) {
|
|
const bool standard = layouts && files_selected_ == "standard";
|
|
const bool fresh = save && files_selected_.empty();
|
|
if (files_entry_ && !files_entry_->valid())
|
|
return "<div class=\"files-empty-details\"><h2>" + esc(files_entry_->name) + "</h2><p>Diese Datei kann nicht geöffnet werden.</p><p class=\"files-error\">" + esc(files_entry_->error) + "</p></div>";
|
|
if (!fresh && !standard && !files_entry_)
|
|
return "<div class=\"files-empty-details\">" + glyph("folder",144) + "<h2>" + std::string(layouts ? "Keine Ansicht" : "Kein Spielstand") + " ausgewählt</h2><p>Wähle links einen Eintrag aus.</p></div>";
|
|
std::string out;
|
|
const auto input = [&]() {
|
|
return "<label class=\"files-name-label\"><span>Bezeichnung</span><input id=\"files-name\" data-change=\"files-name\" maxlength=\"64\" value=\"" + esc(files_name_) + "\"/></label>";
|
|
};
|
|
if (layouts) {
|
|
const auto heading = standard ? "Standard" : fresh ? "Neue Ansicht" : files_entry_->name;
|
|
out = "<h2 class=\"files-heading\">" + esc(heading) + "</h2><p class=\"files-intro\">" +
|
|
(standard ? "Unveränderliche Vorlage nach dem ursprünglichen BMH-Desktop." : "Dein Look und deine gesamte Anordnung.") + "</p>";
|
|
if (fresh) return out + input() + "<div class=\"files-save-illustration\">" + glyph("save", 140) + "<p>Eine Desktop-Vorschau wird beim Speichern automatisch aufgenommen.</p></div>";
|
|
const auto payload = standard ? Json{{"layout", default_desktop()}, {"theme", theme_}} : files_entry_->data;
|
|
if (standard) out += "<div class=\"files-thumbnail\">" + files_standard_preview() + "</div>";
|
|
else if (!files_entry_->preview_png.empty()) {
|
|
const auto preview = files_store().preview_file(*files_entry_);
|
|
out += "<div class=\"files-thumbnail\">" + picture(renderer_.local_image(preview, 1920), 1678, 943.875) + "</div>";
|
|
} else out += "<p class=\"files-no-preview\">Für diese ältere Ansicht ist keine Vorschau vorhanden.</p>";
|
|
int widgets = 0, apps = 0;
|
|
for (const auto &[id, object] : payload.at("layout").at("objects").items())
|
|
if (object.value("visible", false)) { if (object.value("widget", false)) ++widgets; else ++apps; }
|
|
const auto look = payload.at("theme").get<std::string>();
|
|
const std::vector<std::pair<std::string, std::string>> meta = {{"Gestaltung", look == "silver" ? "Silver Glass" : look == "matchday" ? "Matchday" : "Midnight Glass"}, {"Widgets", std::to_string(widgets)}, {"Buttons", std::to_string(apps)}, {"Hintergrund", "Stadion bei Nacht"}};
|
|
out += "<div class=\"files-metadata\">";
|
|
for (const auto &[label, value] : meta) out += "<div class=\"files-metadata-cell\"><span>" + esc(label) + "</span><strong>" + esc(value) + "</strong></div>";
|
|
return out + "</div>";
|
|
}
|
|
const auto data = fresh ? snap().state : files_entry_->data;
|
|
const auto meta = DemoFiles::career_metadata(data);
|
|
const auto &managers = meta.at("managers");
|
|
const Json *own = managers.empty() ? nullptr : world_->find("clubs", meta.at("current_manager").value("club", ""));
|
|
out = "<div class=\"files-detail-heading\"><div class=\"files-crest\">" + (meta.at("role")=="national"?img("career.national-de",108,108,false,false,256):crest(own,108)) + "</div><div><p>" + std::string(fresh ? "Aktuelles Spiel" : "Gespeicherter Spielstand") + "</p><h2>" + esc(fresh ? "Neuer Speicherstand" : files_entry_->name) + "</h2><span>" + esc(meta.at("role")=="national"?"Deutschland":own ? world_->name(*own) : "") + "</span></div></div>";
|
|
if (fresh) out += input();
|
|
out += "<div class=\"files-metadata\">";
|
|
const auto iso_date = meta.at("date").get<std::string>();
|
|
const auto display_date = iso_date.substr(8, 2) + "." + iso_date.substr(5, 2) + "." + iso_date.substr(0, 4);
|
|
const std::vector<std::pair<std::string, std::string>> cells = {{"Saison", meta.at("season")}, {"Spieltag", meta.at("matchday")}, {"Spieldatum", display_date}, {"Spieler", std::to_string(meta.at("human_count").get<size_t>())}};
|
|
for (const auto &[label, value] : cells) out += "<div class=\"files-metadata-cell\"><span>" + esc(label) + "</span><strong>" + esc(value) + "</strong></div>";
|
|
out += "</div><section class=\"files-managers\"><h3>Mitspieler</h3>";
|
|
for (const auto &manager : managers) {
|
|
const auto *managed = world_->find("clubs", manager.value("club", ""));
|
|
out += "<div><strong>" + esc(manager.value("name", "")) + "</strong><span>" + esc(meta.at("role")=="national"&&manager.value("portrait",0)==meta.at("current_manager").value("portrait",0)?"Deutschland":managed ? world_->name(*managed) : "") + "</span></div>";
|
|
}
|
|
return out + "</section><p class=\"files-timestamp\">" + (fresh ? "Diese Angaben werden mit dem Spielstand gespeichert." : "Gespeichert am " + esc(files_entry_->created) + "<br/>Geändert am " + esc(files_entry_->modified) + " · " + std::to_string(files_entry_->bytes) + " Bytes") + "</p>";
|
|
}
|
|
std::string App::render_files(bool layouts, bool save) {
|
|
if (files_mode_ != menu_) files_begin(menu_);
|
|
std::string entries;
|
|
const auto row = [&](const std::string &action, const std::string &id, const std::string &label, const std::string &subtitle, bool selected, const std::string &identity, bool fresh = false) {
|
|
const auto icon = fresh ? "plus" : id == "standard" ? "grid" : layouts ? "image" : "save";
|
|
return btn(action, "<span class=\"files-entry-icon\">" + glyph(icon, 40) + "</span><span class=\"files-entry-copy\"><strong>" + esc(label) + "</strong><span>" + esc(subtitle) + "</span></span>" + (id == "standard" ? "<span class=\"files-standard-badge\">Standard</span>" : ""), std::string("files-entry ") + (selected ? "selected" : ""), "id=\"" + identity + "\" role=\"option\" data-id=\"" + esc(id) + "\" data-file-row=\"true\" aria-selected=\"" + (selected ? "true" : "false") + "\"");
|
|
};
|
|
if (save) entries += row("files-new", "", layouts ? "Neue Ansicht" : "Neuer Speicherstand", layouts ? "Aktuellen Desktop mit Vorschau sichern" : "Aktuellen Spielstand neu speichern", files_selected_.empty(), "files-new", true);
|
|
if (layouts && !save) entries += row("files-standard", "standard", "Standard", "Nach dem Original von BMH · immer verfügbar", files_selected_ == "standard", "files-standard");
|
|
for (size_t i = 0; i < files_rows_.size(); ++i) {
|
|
const auto &entry = files_rows_[i];
|
|
entries += row("files-select", entry.id, entry.name, entry.valid() ? "Gespeichert am " + entry.created : "Datei kann nicht geöffnet werden", files_selected_ == entry.id, "files-entry-" + std::to_string(i));
|
|
}
|
|
if (entries.empty()) entries = "<p class=\"files-empty-list\">Noch keine Spielstände vorhanden.</p>";
|
|
std::string details;
|
|
try { details = files_details(layouts, save); }
|
|
catch (const std::exception &e) { details = "<div class=\"files-empty-details\"><h2>Datei nicht verfügbar</h2><p>" + esc(e.what()) + "</p></div>"; }
|
|
const bool selected = files_entry_ && files_entry_->valid();
|
|
bool can_save = save && (!files_entry_ || selected);
|
|
if (save && !selected) try { DemoFiles::clean_name(files_name_); } catch (...) { can_save = false; }
|
|
const auto disabled = selected ? "" : "disabled";
|
|
std::string footer = "<div class=\"files-file-actions\">";
|
|
if (!layouts) footer += btn("files-import", "Importieren") + btn("files-export", "Exportieren", {}, disabled);
|
|
footer += "</div><div class=\"files-record-actions\">" + btn("files-rename", "Umbenennen", {}, disabled) + btn("files-delete", "Löschen", {}, files_entry_ && !files_entry_->token.empty() ? "" : "disabled") + "</div><div class=\"files-confirm-actions\">" + btn("files-close", "Abbrechen") + btn(save ? "files-save" : "files-load", save ? "Speichern" : "Laden", "primary", "id=\"files-confirm\" " + std::string((save ? can_save : selected || (layouts && files_selected_ == "standard")) ? "" : "disabled")) + "</div>";
|
|
const auto content = "<div class=\"files-layout" + std::string(layouts ? " files-views" : "") + "\"><section class=\"files-browser panel\"><div class=\"files-browser-header\"><h2>" + std::string(layouts ? "Ansichten" : "Spielstände") + "</h2><span>" + std::to_string(files_rows_.size()) + "</span></div><div id=\"files-list\" class=\"files-list\" role=\"listbox\" aria-label=\"" + (layouts ? "Ansicht" : "Spielstand") + " auswählen\">" + entries + "</div></section><section class=\"files-details panel\">" + details + "</section></div>";
|
|
if (layouts) {
|
|
const auto feedback = files_feedback_.empty() ? (save ? "Look, Widgets, Größen und Fixierungen werden gemeinsam gespeichert." : "Die Standardansicht ist fixiert und bleibt immer verfügbar.") : files_feedback_;
|
|
const auto view_actions = "<p id=\"files-feedback\" role=\"status\">" + esc(feedback) + "</p><div class=\"files-view-record-actions\">" + btn("files-rename", "Umbenennen", {}, disabled) + btn("files-delete", "Löschen", {}, files_entry_ && !files_entry_->token.empty() ? "" : "disabled") + "</div>" + btn("files-close", "Abbrechen") + btn(save ? "files-save" : "files-load", save ? "Speichern" : "Laden", "primary", "id=\"files-confirm\" " + std::string((save ? can_save : selected || files_selected_ == "standard") ? "" : "disabled"));
|
|
return desktop_dialog(save ? "Ansicht speichern" : "Ansicht laden", content, view_actions);
|
|
}
|
|
const auto actions = "<footer class=\"files-actions\">" + footer + "</footer>";
|
|
return content + "<p id=\"files-feedback\" class=\"files-feedback\" role=\"status\">" + esc(files_feedback_) + "</p>" + actions;
|
|
}
|