some cleanup
This commit is contained in:
@@ -76,8 +76,8 @@ DTree data_format_value(DTree value, DTree row, DTree column)
|
||||
|
||||
COMPONENT:SUMMARY_METRICS(Request& context)
|
||||
{
|
||||
String title = context.call["title"].to_string();
|
||||
String subtitle = context.call["subtitle"].to_string();
|
||||
String title = context.props["title"].to_string();
|
||||
String subtitle = context.props["subtitle"].to_string();
|
||||
|
||||
<>
|
||||
<div class="dashboard-panel">
|
||||
@@ -88,7 +88,7 @@ COMPONENT:SUMMARY_METRICS(Request& context)
|
||||
</div>
|
||||
<? } ?>
|
||||
<div class="dashboard-stat-grid">
|
||||
<? context.call["items"].each([&](DTree item, String key) {
|
||||
<? context.props["items"].each([&](DTree item, String key) {
|
||||
String tone = first(item["tone"].to_string(), "info");
|
||||
String href = item["href"].to_string();
|
||||
String tag = href != "" ? "a" : "div";
|
||||
@@ -108,16 +108,16 @@ COMPONENT:TIMESERIES_CHART(Request& context)
|
||||
starter_register_js("js/u-format.js", context);
|
||||
starter_register_js("js/u-timeseries-chart.js", context);
|
||||
|
||||
String chart_id = first(context.call["id"].to_string(), "ts-chart-" + std::to_string((u64)time()));
|
||||
String chart_id = first(context.props["id"].to_string(), "ts-chart-" + std::to_string((u64)time()));
|
||||
String canvas_id = chart_id + "-canvas";
|
||||
String title = context.call["title"].to_string();
|
||||
String subtitle = context.call["subtitle"].to_string();
|
||||
s32 height = std::max(180, (s32)int_val(first(context.call["height"].to_string(), "320")));
|
||||
String x_axis_label = first(context.call["x_axis_label"].to_string(), "Time");
|
||||
String y_axis_left_label = first(context.call["y_axis_left_label"].to_string(), "Value");
|
||||
String y_axis_right_label = context.call["y_axis_right_label"].to_string();
|
||||
String y_axis_left_format = first(context.call["y_axis_left_format"].to_string(), "number");
|
||||
String y_axis_right_format = first(context.call["y_axis_right_format"].to_string(), "number");
|
||||
String title = context.props["title"].to_string();
|
||||
String subtitle = context.props["subtitle"].to_string();
|
||||
s32 height = std::max(180, (s32)int_val(first(context.props["height"].to_string(), "320")));
|
||||
String x_axis_label = first(context.props["x_axis_label"].to_string(), "Time");
|
||||
String y_axis_left_label = first(context.props["y_axis_left_label"].to_string(), "Value");
|
||||
String y_axis_right_label = context.props["y_axis_right_label"].to_string();
|
||||
String y_axis_left_format = first(context.props["y_axis_left_format"].to_string(), "number");
|
||||
String y_axis_right_format = first(context.props["y_axis_right_format"].to_string(), "number");
|
||||
|
||||
<>
|
||||
<div class="dashboard-panel">
|
||||
@@ -139,7 +139,7 @@ COMPONENT:TIMESERIES_CHART(Request& context)
|
||||
yAxisLeftFormat: <?: json_encode(y_axis_left_format) ?>,
|
||||
yAxisRightFormat: <?: json_encode(y_axis_right_format) ?>
|
||||
});
|
||||
chart.setData(<?: json_encode(context.call["series"]) ?>, <?: json_encode(context.call["x_labels"]) ?>);
|
||||
chart.setData(<?: json_encode(context.props["series"]) ?>, <?: json_encode(context.props["x_labels"]) ?>);
|
||||
window[<?: json_encode("chart_" + chart_id) ?>] = chart;
|
||||
}());
|
||||
</script>
|
||||
@@ -151,17 +151,17 @@ COMPONENT:SORTABLE_TABLE(Request& context)
|
||||
starter_register_js("js/u-format.js", context);
|
||||
starter_register_js("js/u-sortable-table.js", context);
|
||||
|
||||
String table_id = first(context.call["id"].to_string(), "sortable-table-" + std::to_string((u64)time()));
|
||||
String title = context.call["title"].to_string();
|
||||
String subtitle = context.call["subtitle"].to_string();
|
||||
String empty_label = first(context.call["empty_label"].to_string(), "No data available");
|
||||
String table_id = first(context.props["id"].to_string(), "sortable-table-" + std::to_string((u64)time()));
|
||||
String title = context.props["title"].to_string();
|
||||
String subtitle = context.props["subtitle"].to_string();
|
||||
String empty_label = first(context.props["empty_label"].to_string(), "No data available");
|
||||
|
||||
DTree init_options;
|
||||
init_options["storageKey"] = first(context.call["storage_key"].to_string(), "starter.sort." + table_id);
|
||||
if(context.call["sort"]["column"].to_string() != "")
|
||||
init_options["storageKey"] = first(context.props["storage_key"].to_string(), "starter.sort." + table_id);
|
||||
if(context.props["sort"]["column"].to_string() != "")
|
||||
{
|
||||
init_options["initialSort"]["column"] = context.call["sort"]["column"];
|
||||
init_options["initialSort"]["direction"] = first(context.call["sort"]["direction"].to_string(), "asc");
|
||||
init_options["initialSort"]["column"] = context.props["sort"]["column"];
|
||||
init_options["initialSort"]["direction"] = first(context.props["sort"]["direction"].to_string(), "asc");
|
||||
}
|
||||
|
||||
<>
|
||||
@@ -176,7 +176,7 @@ COMPONENT:SORTABLE_TABLE(Request& context)
|
||||
<table id="<?= table_id ?>" class="u-sortable-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<? context.call["columns"].each([&](DTree column, String key) {
|
||||
<? context.props["columns"].each([&](DTree column, String key) {
|
||||
String align = first(column["align"].to_string(), "left");
|
||||
bool sortable = column["sortable"].to_string() == "" || column["sortable"].to_string() == "1";
|
||||
?><th scope="col" class="align-<?= align ?>"<?= sortable ? "" : " data-sortable=\"false\"" ?>><?= first(column["label"].to_string(), column["key"].to_string(), "Column") ?></th><?
|
||||
@@ -184,14 +184,14 @@ COMPONENT:SORTABLE_TABLE(Request& context)
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<? if(context.call["rows"].get_type_name() != "array" || context.call["rows"]["0"].get_type_name() != "array") { ?>
|
||||
<tr data-empty-row="1"><td colspan="<?= context.call["columns"]._map.size() == 0 ? "1" : std::to_string(context.call["columns"]._map.size()) ?>" class="muted"><?= empty_label ?></td></tr>
|
||||
<? if(context.props["rows"].get_type_name() != "array" || context.props["rows"]["0"].get_type_name() != "array") { ?>
|
||||
<tr data-empty-row="1"><td colspan="<?= context.props["columns"]._map.size() == 0 ? "1" : std::to_string(context.props["columns"]._map.size()) ?>" class="muted"><?= empty_label ?></td></tr>
|
||||
<? } ?>
|
||||
<? context.call["rows"].each([&](DTree row, String key) {
|
||||
<? context.props["rows"].each([&](DTree row, String key) {
|
||||
if(row.get_type_name() != "array")
|
||||
return;
|
||||
?><tr><?
|
||||
context.call["columns"].each([&](DTree column, String ckey) {
|
||||
context.props["columns"].each([&](DTree column, String ckey) {
|
||||
String col_key = column["key"].to_string();
|
||||
DTree formatted = data_format_value(row[col_key], row, column);
|
||||
?><td class="align-<?= first(column["align"].to_string(), "left") ?>" data-sort-value="<?= formatted["sort"].to_string() ?>"><?= formatted["display"].to_string() ?></td><?
|
||||
@@ -213,21 +213,21 @@ COMPONENT:SORTABLE_TABLE(Request& context)
|
||||
|
||||
COMPONENT:DATA_TABLE(Request& context)
|
||||
{
|
||||
String table_id = first(context.call["id"].to_string(), "data-grid-" + std::to_string((u64)time()));
|
||||
String table_id = first(context.props["id"].to_string(), "data-grid-" + std::to_string((u64)time()));
|
||||
starter_register_js("js/ag-grid/ag-grid-community.min.js", context);
|
||||
starter_register_css("js/ag-grid/ag-grid.css", context);
|
||||
starter_register_css("js/ag-grid/ag-theme-alpine.css", context);
|
||||
|
||||
DTree columns = context.call["columns"];
|
||||
DTree columns = context.props["columns"];
|
||||
if(columns.get_type_name() != "array")
|
||||
columns.set_array();
|
||||
bool has_explicit_columns = columns.is_list() &&
|
||||
columns._map.size() > 0 &&
|
||||
columns._map.find("0") != columns._map.end() &&
|
||||
columns["0"]["field"].to_string() != "";
|
||||
if(!has_explicit_columns && context.call["items"]["0"].get_type_name() == "array")
|
||||
if(!has_explicit_columns && context.props["items"]["0"].get_type_name() == "array")
|
||||
{
|
||||
context.call["items"]["0"].each([&](DTree value, String key) {
|
||||
context.props["items"]["0"].each([&](DTree value, String key) {
|
||||
DTree col;
|
||||
col["field"] = key;
|
||||
col["headerName"] = key;
|
||||
@@ -248,7 +248,7 @@ COMPONENT:DATA_TABLE(Request& context)
|
||||
columns = normalized_columns;
|
||||
}
|
||||
|
||||
DTree row_data = context.call["items"];
|
||||
DTree row_data = context.props["items"];
|
||||
if(row_data.get_type_name() != "array")
|
||||
row_data.set_array();
|
||||
if(!row_data.is_list())
|
||||
@@ -264,7 +264,7 @@ COMPONENT:DATA_TABLE(Request& context)
|
||||
|
||||
DTree grid_options;
|
||||
grid_options["pagination"].set_bool(true);
|
||||
grid_options["paginationPageSize"] = first(context.call["options"]["paginationPageSize"].to_string(), "20");
|
||||
grid_options["paginationPageSize"] = first(context.props["options"]["paginationPageSize"].to_string(), "20");
|
||||
grid_options["paginationPageSizeSelector"].set_bool(false);
|
||||
grid_options["suppressMenuHide"].set_bool(true);
|
||||
grid_options["animateRows"].set_bool(true);
|
||||
@@ -275,7 +275,7 @@ COMPONENT:DATA_TABLE(Request& context)
|
||||
<div class="ag-grid-container" style="margin: 1rem 0;">
|
||||
<div class="ag-grid-toolbar" style="display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem;padding:0.75rem;background:var(--surface-elevated);border:1px solid var(--border);border-radius:0.5rem 0.5rem 0 0;border-bottom:none;">
|
||||
<div style="display:flex;gap:1rem;align-items:center;flex:1;">
|
||||
<span style="color: var(--text-secondary); font-size: 0.875rem; font-weight: 500;"><?= std::to_string(context.call["items"]._map.size()) ?> rows</span>
|
||||
<span style="color: var(--text-secondary); font-size: 0.875rem; font-weight: 500;"><?= std::to_string(context.props["items"]._map.size()) ?> rows</span>
|
||||
<input type="text" id="<?= table_id ?>-search" placeholder="Search all columns..." style="padding:0.5rem 0.75rem;border:1px solid var(--border);border-radius:0.375rem;background:var(--surface);color:var(--text-primary);font-size:0.875rem;width:250px;" />
|
||||
</div>
|
||||
<div style="display:flex;gap:0.5rem;">
|
||||
@@ -283,7 +283,7 @@ COMPONENT:DATA_TABLE(Request& context)
|
||||
<button id="<?= table_id ?>-clear-filters" class="btn btn-outline">Clear Filters</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="<?= table_id ?>" class="ag-theme-alpine-dark" style="height: <?= first(context.call["height"].to_string(), "400px") ?>; width: 100%; border: 1px solid var(--border); border-radius: 0 0 0.5rem 0.5rem; overflow: hidden;"></div>
|
||||
<div id="<?= table_id ?>" class="ag-theme-alpine-dark" style="height: <?= first(context.props["height"].to_string(), "400px") ?>; width: 100%; border: 1px solid var(--border); border-radius: 0 0 0.5rem 0.5rem; overflow: hidden;"></div>
|
||||
</div>
|
||||
<script>
|
||||
(function () {
|
||||
|
||||
Reference in New Issue
Block a user