升级
This commit is contained in:
+12
-4
@@ -58,12 +58,18 @@ function grouped(items) {
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
function adminiveFieldVisible(expression, data) {
|
||||
if (!expression) return true;
|
||||
const equality = expression.match(/^\$\{\$self\.([A-Za-z_][A-Za-z0-9_]*) == '([^']*)'\}$/);
|
||||
return equality ? String(data?.[equality[1]]) === equality[2] : true;
|
||||
}
|
||||
function adminiveControls(resource) {
|
||||
const resources = resource?.resources || (resource ? [resource] : []);
|
||||
const controls = [];
|
||||
const visit = (fields, data, target, group, path = [], labels = []) => {
|
||||
for (const field of fields || []) {
|
||||
const presentation = field.presentation || {};
|
||||
if (!adminiveFieldVisible(presentation.visible_on, data)) continue;
|
||||
const fieldPath = [...path, field.name];
|
||||
const fieldLabels = [...labels, presentation.label || field.name];
|
||||
if (field.children?.length) {
|
||||
@@ -76,7 +82,7 @@ function adminiveControls(resource) {
|
||||
target,
|
||||
path: fieldPath,
|
||||
label: fieldLabels.join(" / "),
|
||||
api: presentation.description || fieldPath.join("."),
|
||||
api: fieldPath.join("."),
|
||||
description: presentation.description || "",
|
||||
group,
|
||||
input: presentation.control === "automatic" ? "text" : presentation.control || "text",
|
||||
@@ -637,7 +643,7 @@ function renderControl(item) {
|
||||
const row = document.createElement("div"); row.className = "control-row";
|
||||
const copy = document.createElement("div"); copy.className = "control-copy";
|
||||
const label = document.createElement("label"); label.textContent = item.label;
|
||||
const api = document.createElement("code"); api.textContent = item.api; api.title = item.api; copy.append(label, api);
|
||||
copy.append(label);
|
||||
let input;
|
||||
if (item.input === "select") {
|
||||
input = document.createElement("select");
|
||||
@@ -648,10 +654,12 @@ function renderControl(item) {
|
||||
if (item.input === "boolean") input.checked = Boolean(item.value); else input.value = item.value;
|
||||
if (item.input === "number") { input.min = item.minimum; input.max = item.maximum; input.step = item.step || "any"; }
|
||||
}
|
||||
input.className = "control-input"; input.title = item.description || item.api;
|
||||
input.className = "control-input";
|
||||
input.setAttribute("aria-label", item.label);
|
||||
input.title = item.description || item.label;
|
||||
const submit = value => {
|
||||
card.send("gallery_patch", {target: item.target, patch: nestedPatch(item.path, value)});
|
||||
elements.menuStatus.textContent = `提交 ${item.api} · 等待后端回读`;
|
||||
elements.menuStatus.textContent = `提交“${item.label}”并等待后端回读`;
|
||||
};
|
||||
if (item.input === "number") {
|
||||
let committedValue = input.value;
|
||||
|
||||
Reference in New Issue
Block a user