分层重构
This commit is contained in:
@@ -395,7 +395,6 @@ requires Described_Type<Model>
|
||||
Json model_descriptor_json(const Model* defaults = nullptr) {
|
||||
const auto descriptor = describe<Model>();
|
||||
Json fields = json_array<Json>();
|
||||
int field_index{};
|
||||
std::apply([&](const auto&... item) {
|
||||
([&] {
|
||||
using Field = std::remove_cvref_t<decltype(item)>;
|
||||
@@ -403,70 +402,46 @@ Json model_descriptor_json(const Model* defaults = nullptr) {
|
||||
using Value = Adapted_Value_Type<Member, Json>;
|
||||
using Descriptor_Value = Optional_Unwrapped_Type<Value>;
|
||||
Json field_json = json_object<Json>();
|
||||
const int order = item.order() < 0 ? field_index : item.order();
|
||||
++field_index;
|
||||
json_set(field_json, "name", item.name());
|
||||
json_set(field_json, "label", item.label());
|
||||
json_set(field_json, "list_label", item.list_label());
|
||||
json_set(field_json, "value_type", value_type_name<Json, Member>());
|
||||
json_set(field_json, "nullable", Optional_Type<Value>);
|
||||
json_set(field_json, "readable", item.is_readable());
|
||||
json_set(field_json, "sensitive", item.is_sensitive());
|
||||
json_set(field_json, "editable", item.is_editable());
|
||||
using Field = std::remove_cvref_t<decltype(item)>;
|
||||
json_set(field_json, "writable", Field::managed_writable);
|
||||
json_set(field_json, "synchronized", Field::managed_writable && Field::synchronized);
|
||||
json_set(field_json, "creatable", item.is_creatable());
|
||||
json_set(field_json, "visible", item.is_visible());
|
||||
json_set(field_json, "required", item.is_required());
|
||||
json_set(field_json, "list_visible", item.is_list_visible());
|
||||
json_set(field_json, "order", order);
|
||||
json_set(field_json, "sortable", item.is_sortable());
|
||||
if(defaults && item.is_readable() && !item.is_sensitive() && item.includes_default()) {
|
||||
json_set(field_json, "default", encode_json_value<Json>(item.get(*defaults)));
|
||||
}
|
||||
Json presentation = json_object<Json>();
|
||||
json_set(presentation, "label", item.label());
|
||||
json_set(presentation, "control", std::string(field_control_name(item.control())));
|
||||
if(!item.description().empty()) {
|
||||
json_set(field_json, "description", item.description());
|
||||
}
|
||||
if(!item.widget().empty()) {
|
||||
json_set(field_json, "widget", item.widget());
|
||||
json_set(presentation, "description", item.description());
|
||||
}
|
||||
if(!item.visible_on().empty()) {
|
||||
json_set(field_json, "visible_on", item.visible_on());
|
||||
json_set(presentation, "visible_on", item.visible_on());
|
||||
}
|
||||
auto options = enum_options<Json, Member>(item.enum_labels());
|
||||
if(Json_Adapter<Json>::size(options) != 0) {
|
||||
json_set(presentation, "options", std::move(options));
|
||||
}
|
||||
json_set(field_json, "presentation", std::move(presentation));
|
||||
if constexpr(Described_Type<Descriptor_Value> || Snapshot_Adapted_Object<Descriptor_Value>) {
|
||||
json_set(field_json, "children", Json_Adapter<Json>::at(to_descriptor_json<Json, Descriptor_Value>(), "fields"));
|
||||
}
|
||||
append_constraints<Json, Member>(field_json);
|
||||
auto options = enum_options<Json, Member>(item.enum_labels());
|
||||
if(Json_Adapter<Json>::size(options) != 0) {
|
||||
json_set(field_json, "options", std::move(options));
|
||||
}
|
||||
json_append(fields, std::move(field_json));
|
||||
}(), ...);
|
||||
}, descriptor.fields());
|
||||
const auto& options = descriptor.list_options();
|
||||
Json list = json_object<Json>();
|
||||
json_set(list, "id_label", options.id_label);
|
||||
json_set(list, "create_label", options.create_label);
|
||||
json_set(list, "edit_label", options.edit_label);
|
||||
json_set(list, "delete_label", options.delete_label);
|
||||
json_set(list, "actions_label", options.actions_label);
|
||||
json_set(list, "confirm_label", options.confirm_label);
|
||||
json_set(list, "delete_confirm", options.delete_confirm);
|
||||
json_set(list, "view_status_label", options.view_status_label);
|
||||
json_set(list, "management_label", options.management_label.empty() ? descriptor.label() + " Management" : options.management_label);
|
||||
json_set(list, "default_order_by", options.default_order_by);
|
||||
json_set(list, "default_order_dir", options.default_order_dir);
|
||||
json_set(list, "user_reorderable", options.user_reorderable_);
|
||||
json_set(list, "column_reorderable", options.column_reorderable_);
|
||||
Json result = json_object<Json>();
|
||||
json_set(result, "protocol", "adminive.resource");
|
||||
json_set(result, "protocol_version", 4);
|
||||
json_set(result, "protocol_version", 5);
|
||||
json_set(result, "name", descriptor.name());
|
||||
json_set(result, "label", descriptor.label());
|
||||
json_set(result, "value_type", "object");
|
||||
json_set(result, "list", std::move(list));
|
||||
json_set(result, "fields", std::move(fields));
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user