refactor: rename DTree to DValue

This commit is contained in:
udo
2026-06-12 11:05:52 +00:00
parent 941f5aea08
commit 7066da3cde
157 changed files with 1203 additions and 1074 deletions
@@ -34,9 +34,9 @@ String data_format_bytes(String raw, bool disk = false)
return(String(buf) + " " + units[unit_index]);
}
DTree data_format_value(DTree value, DTree row, DTree column)
DValue data_format_value(DValue value, DValue row, DValue column)
{
DTree result;
DValue result;
String format = column["format"].to_string();
String raw = value.to_string();
String sort_value = raw;
@@ -98,7 +98,7 @@ COMPONENT:SUMMARY_METRICS(Request& context)
</div>
<? } ?>
<div class="dashboard-stat-grid">
<? context.props["items"].each([&](DTree item, String key) {
<? context.props["items"].each([&](DValue item, String key) {
String tone = first(item["tone"].to_string(), "info");
String href = item["href"].to_string();
String tag = href != "" ? "a" : "div";
@@ -162,7 +162,7 @@ COMPONENT:SORTABLE_TABLE(Request& context)
String subtitle = context.props["subtitle"].to_string();
String empty_label = first(context.props["empty_label"].to_string(), "No data available");
DTree init_options;
DValue init_options;
init_options["storageKey"] = first(context.props["storage_key"].to_string(), "starter.sort." + table_id);
if(context.props["sort"]["column"].to_string() != "")
{
@@ -182,7 +182,7 @@ COMPONENT:SORTABLE_TABLE(Request& context)
<table id="<?= table_id ?>" class="u-sortable-table">
<thead>
<tr>
<? context.props["columns"].each([&](DTree column, String key) {
<? context.props["columns"].each([&](DValue 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><?
@@ -193,13 +193,13 @@ COMPONENT:SORTABLE_TABLE(Request& context)
<? 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.props["rows"].each([&](DTree row, String key) {
<? context.props["rows"].each([&](DValue row, String key) {
if(row.get_type_name() != "array")
return;
?><tr><?
context.props["columns"].each([&](DTree column, String ckey) {
context.props["columns"].each([&](DValue column, String ckey) {
String col_key = column["key"].to_string();
DTree formatted = data_format_value(row[col_key], row, column);
DValue 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><?
});
?></tr><?
@@ -221,7 +221,7 @@ COMPONENT:DATA_TABLE(Request& context)
{
String table_id = first(context.props["id"].to_string(), "data-grid-" + std::to_string((u64)time()));
DTree columns = context.props["columns"];
DValue columns = context.props["columns"];
if(columns.get_type_name() != "array")
columns.set_array();
bool has_explicit_columns = columns.is_list() &&
@@ -230,8 +230,8 @@ COMPONENT:DATA_TABLE(Request& context)
columns["0"]["field"].to_string() != "";
if(!has_explicit_columns && context.props["items"]["0"].get_type_name() == "array")
{
context.props["items"]["0"].each([&](DTree value, String key) {
DTree col;
context.props["items"]["0"].each([&](DValue value, String key) {
DValue col;
col["field"] = key;
col["headerName"] = key;
col["sortable"].set_bool(true);
@@ -242,30 +242,30 @@ COMPONENT:DATA_TABLE(Request& context)
}
if(!columns.is_list())
{
DTree normalized_columns;
DValue normalized_columns;
normalized_columns.set_array();
columns.each([&](DTree column, String key) {
columns.each([&](DValue column, String key) {
if(column.get_type_name() == "array")
normalized_columns.push(column);
});
columns = normalized_columns;
}
DTree row_data = context.props["items"];
DValue row_data = context.props["items"];
if(row_data.get_type_name() != "array")
row_data.set_array();
if(!row_data.is_list())
{
DTree normalized_rows;
DValue normalized_rows;
normalized_rows.set_array();
row_data.each([&](DTree row, String key) {
row_data.each([&](DValue row, String key) {
if(row.get_type_name() == "array")
normalized_rows.push(row);
});
row_data = normalized_rows;
}
DTree grid_options;
DValue grid_options;
grid_options["pagination"].set_bool(true);
grid_options["paginationPageSize"] = first(context.props["options"]["paginationPageSize"].to_string(), "20");
grid_options["paginationPageSizeSelector"].set_bool(false);