画廊添加
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "example_descriptors.hpp"
|
||||
#include "gallery.hpp"
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
@@ -25,6 +26,47 @@ const Json* find_named_node(const Json& value, std::string_view name) {
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
void assert_flex_items_renderable(const Json& value) {
|
||||
if(value.is_object()) {
|
||||
if(value.contains("type") && value.at("type") == "flex") {
|
||||
assert(value.contains("items"));
|
||||
for(const auto& item : value.at("items")) {
|
||||
assert(item.is_object());
|
||||
assert(item.contains("type"));
|
||||
}
|
||||
}
|
||||
for(const auto& [key, child] : value.items()) {
|
||||
static_cast<void>(key);
|
||||
assert_flex_items_renderable(child);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(value.is_array()) {
|
||||
for(const auto& child : value) {
|
||||
assert_flex_items_renderable(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
const Json* find_labeled_node(const Json& value, std::string_view label) {
|
||||
if(value.is_object()) {
|
||||
if(value.contains("label") && value.at("label").is_string() && value.at("label").get<std::string>() == label) {
|
||||
return &value;
|
||||
}
|
||||
for(const auto& [key, child] : value.items()) {
|
||||
static_cast<void>(key);
|
||||
if(const Json* result = find_labeled_node(child, label)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} else if(value.is_array()) {
|
||||
for(const auto& child : value) {
|
||||
if(const Json* result = find_labeled_node(child, label)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
const Json* find_titled_node(const Json& value, std::string_view title) {
|
||||
if(value.is_object()) {
|
||||
if(value.contains("title") && value.at("title").is_string() && value.at("title").get<std::string>() == title) {
|
||||
@@ -217,6 +259,41 @@ int main() {
|
||||
assert(resource_form.at("api").at("method") == "post");
|
||||
assert(resource_form.at("api").at("url") == "/admin/config/radio/data");
|
||||
assert(resource_form.at("actions").at(1).at("label") == "确认修改");
|
||||
adminive::example::Component_Gallery gallery;
|
||||
const auto gallery_schema = gallery.amis_schema();
|
||||
assert(gallery_schema.at("type") == "panel");
|
||||
assert_flex_items_renderable(gallery_schema);
|
||||
const Json* automatic_control = find_named_node(gallery_schema, "automatic_text");
|
||||
const Json* text_control = find_named_node(gallery_schema, "text_value");
|
||||
const Json* multiline_control = find_named_node(gallery_schema, "multiline_value");
|
||||
const Json* number_control = find_named_node(gallery_schema, "number_value");
|
||||
const Json* even_control = find_named_node(gallery_schema, "even_number");
|
||||
const Json* boolean_control = find_named_node(gallery_schema, "boolean_value");
|
||||
const Json* select_control = find_named_node(gallery_schema, "select_value");
|
||||
const Json* date_gallery_control = find_named_node(gallery_schema, "date_value");
|
||||
const Json* color_gallery_control = find_named_node(gallery_schema, "color_value");
|
||||
const Json* optional_control = find_named_node(gallery_schema, "optional_text");
|
||||
const Json* readonly_control = find_named_node(gallery_schema, "read_only_text");
|
||||
assert(automatic_control && automatic_control->at("type") == "input-text");
|
||||
assert(text_control && text_control->at("type") == "input-text");
|
||||
assert(multiline_control && multiline_control->at("type") == "textarea");
|
||||
assert(number_control && number_control->at("type") == "input-number");
|
||||
assert(number_control->at("min") == 0 && number_control->at("max") == 100);
|
||||
assert(even_control && even_control->at("type") == "input-number" && even_control->at("step") == 2);
|
||||
assert(boolean_control && boolean_control->at("type") == "switch");
|
||||
assert(select_control && select_control->at("type") == "select");
|
||||
assert(date_gallery_control && date_gallery_control->at("type") == "input-date");
|
||||
assert(color_gallery_control && color_gallery_control->at("type") == "input-color");
|
||||
assert(optional_control && optional_control->at("clearable") == true);
|
||||
assert(readonly_control && readonly_control->at("type") == "static");
|
||||
const Json* save_gallery_button = find_labeled_node(gallery_schema, "保存画廊数据");
|
||||
const Json* create_gallery_button = find_labeled_node(gallery_schema, "新增一行");
|
||||
const Json* edit_gallery_button = find_labeled_node(gallery_schema, "编辑");
|
||||
const Json* delete_gallery_button = find_labeled_node(gallery_schema, "删除");
|
||||
assert(save_gallery_button && save_gallery_button->at("type") == "submit");
|
||||
assert(create_gallery_button && create_gallery_button->at("type") == "button");
|
||||
assert(edit_gallery_button && edit_gallery_button->at("actionType") == "dialog");
|
||||
assert(delete_gallery_button && delete_gallery_button->at("actionType") == "ajax");
|
||||
adminive::example::Server_Status server_status;
|
||||
server_status.server_time = "2026-08-06T00:00:00Z";
|
||||
server_status.poll_sequence = 7;
|
||||
|
||||
@@ -55,6 +55,9 @@ int main() {
|
||||
assert(form_amis.at("body").at(0).at("type") == "fieldset");
|
||||
assert(form_amis.at("body").at(1).at("type") == "grid");
|
||||
assert(form_amis.at("body").at(2).at("type") == "flex");
|
||||
assert(form_amis.at("body").at(2).at("items").at(0).at("type") == "container");
|
||||
assert(form_amis.at("body").at(2).at("items").at(1).at("type") == "container");
|
||||
assert(form_amis.at("body").at(2).at("items").at(0).at("body").at(0).at("type") == "card");
|
||||
assert(form_amis.at("body").at(3).at("type") == "tabs");
|
||||
const auto table_view = adminive::describe_table_view<Config>();
|
||||
adminive::validate_table_view<Config>(table_view);
|
||||
@@ -73,6 +76,11 @@ int main() {
|
||||
const auto composition_amis = adminive::to_amis_composition_schema<Json>(composition, {{"form", form_amis}, {"table", Json{{"type", "tpl"}, {"tpl", "table"}}}});
|
||||
assert(composition_amis.at("body").at(0).at("type") == "tpl");
|
||||
assert(composition_amis.at("body").at(1).at("type") == "grid");
|
||||
const auto flow_composition = adminive::composition_view("flow_page", adminive::compose::flow(adminive::compose::slot("left"), adminive::compose::slot("right")));
|
||||
const auto flow_amis = adminive::to_amis_composition_schema<Json>(flow_composition, {{"left", Json{{"type", "tpl"}, {"tpl", "left"}}}, {"right", Json{{"type", "tpl"}, {"tpl", "right"}}}});
|
||||
assert(flow_amis.at("body").at(0).at("type") == "flex");
|
||||
assert(flow_amis.at("body").at(0).at("items").at(0).at("type") == "container");
|
||||
assert(flow_amis.at("body").at(0).at("items").at(1).at("type") == "container");
|
||||
const auto table_amis = adminive::to_amis_table_schema<Json, Config>("/configs", table_view);
|
||||
assert(table_amis.at("type") == "page");
|
||||
assert(table_amis.at("body").at(0).at("columns").at(1).at("searchable") == true);
|
||||
|
||||
Reference in New Issue
Block a user