server-admin-panel/src/htmx/HtmxTableRow.cpp

35 lines
907 B
C++

//
// Created by lukas on 5/11/25.
//
#include <format>
#include "HtmxTableRow.h"
using namespace std;
void HtmxTableRow::add_button(string_view endpoint, string_view name, string_view text) {
html += format("<td>\
<button\
hx-post=\"{}\"\
hx-vals='{{\"name\":\"{}\"}}'\
hx-target=\"closest tr\"\
hx-swap=\"outerHTML\">\
{} \
</button> \
</td>", endpoint, name, text);
}
static string_view get_button_class(bool is_active) {
return is_active ? "active-button" : "inactive-button";
}
void HtmxTableRow::add_status_box(std::string_view name, bool is_active) {
html += format("<td class='{}'>{}</td>", get_button_class(is_active), name);
}
void HtmxTableRow::add(string_view text) {
html += format("<td>{}</td>", text);
}
void HtmxTableRow::complete() {
html += "</tr>";
}