habarico 7.2.0.pre.beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +82 -0
- data/Rakefile +15 -0
- data/VERSION +1 -0
- data/app/controllers/habarico/action_schema_controller.rb +41 -0
- data/app/controllers/habarico/application_controller.rb +15 -0
- data/app/controllers/habarico/contrib/preferences/user_preferences_controller.rb +105 -0
- data/app/controllers/habarico/global_schema_controller.rb +11 -0
- data/app/controllers/habarico/local_schema_controller.rb +35 -0
- data/app/helpers/habarico/application_helper.rb +4 -0
- data/app/models/habarico/application_record.rb +5 -0
- data/app/views/layouts/habarico/application.html.erb +17 -0
- data/config/locales/cs.yml +39 -0
- data/config/locales/de.yml +39 -0
- data/config/locales/en.yml +39 -0
- data/config/locales/es.yml +39 -0
- data/config/locales/fr.yml +39 -0
- data/config/locales/it.yml +39 -0
- data/config/locales/ja.yml +39 -0
- data/config/locales/nl.yml +39 -0
- data/config/locales/pl.yml +39 -0
- data/config/locales/pt.yml +39 -0
- data/config/locales/ro.yml +39 -0
- data/config/locales/sk.yml +39 -0
- data/config/locales/uk.yml +39 -0
- data/config/routes.rb +1 -0
- data/lib/generators/habarico/preferences/install_generator.rb +27 -0
- data/lib/generators/habarico/preferences/templates/create_habarico_user_preferences.rb.tt +15 -0
- data/lib/habarico/active_model/references.rb +68 -0
- data/lib/habarico/authenticatable.rb +31 -0
- data/lib/habarico/config.rb +71 -0
- data/lib/habarico/context.rb +126 -0
- data/lib/habarico/contrib/preferences/base_preferences.rb +40 -0
- data/lib/habarico/contrib/preferences/config.rb +31 -0
- data/lib/habarico/contrib/preferences/errors.rb +79 -0
- data/lib/habarico/contrib/preferences/locales/cs.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/de.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/en.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/es.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/fr.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/it.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/ja.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/nl.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/pl.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/pt.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/ro.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/sk.yml +8 -0
- data/lib/habarico/contrib/preferences/locales/uk.yml +8 -0
- data/lib/habarico/contrib/preferences/registry.rb +293 -0
- data/lib/habarico/contrib/preferences/routes.rb +17 -0
- data/lib/habarico/contrib/preferences/schemas.rb +129 -0
- data/lib/habarico/contrib/preferences/serializer.rb +19 -0
- data/lib/habarico/contrib/preferences/user_preference.rb +16 -0
- data/lib/habarico/contrib/preferences.rb +32 -0
- data/lib/habarico/controller.rb +584 -0
- data/lib/habarico/definition/action_reference.rb +18 -0
- data/lib/habarico/definition/actions/action.rb +14 -0
- data/lib/habarico/definition/actions/create_action.rb +18 -0
- data/lib/habarico/definition/actions/delete_action.rb +20 -0
- data/lib/habarico/definition/actions/edit_action.rb +18 -0
- data/lib/habarico/definition/actions/link_action.rb +11 -0
- data/lib/habarico/definition/actions/resource_action.rb +12 -0
- data/lib/habarico/definition/actions/save_action.rb +14 -0
- data/lib/habarico/definition/actions/show_action.rb +18 -0
- data/lib/habarico/definition/actions/upload_images_action.rb +11 -0
- data/lib/habarico/definition/actions/view_action.rb +11 -0
- data/lib/habarico/definition/boxes/array_box.rb +10 -0
- data/lib/habarico/definition/boxes/box.rb +32 -0
- data/lib/habarico/definition/boxes/gallery_box.rb +10 -0
- data/lib/habarico/definition/boxes/grid_box.rb +10 -0
- data/lib/habarico/definition/boxes/grid_item_box.rb +10 -0
- data/lib/habarico/definition/boxes/list_box.rb +10 -0
- data/lib/habarico/definition/boxes/object_box.rb +10 -0
- data/lib/habarico/definition/boxes/tab_box.rb +10 -0
- data/lib/habarico/definition/boxes/tab_item_box.rb +10 -0
- data/lib/habarico/definition/boxes/wizard_box.rb +10 -0
- data/lib/habarico/definition/concerns/definition_model.rb +38 -0
- data/lib/habarico/definition/definition.rb +206 -0
- data/lib/habarico/definition/field_reference.rb +9 -0
- data/lib/habarico/definition/filter_reference.rb +7 -0
- data/lib/habarico/definition/menu/link_menu_item.rb +12 -0
- data/lib/habarico/definition/menu/menu_item.rb +9 -0
- data/lib/habarico/definition/menu/text_menu_item.rb +12 -0
- data/lib/habarico/definition/menu/view_menu_item.rb +13 -0
- data/lib/habarico/definition/response.rb +13 -0
- data/lib/habarico/definition/views/action_view.rb +11 -0
- data/lib/habarico/definition/views/create_view.rb +15 -0
- data/lib/habarico/definition/views/edit_view.rb +15 -0
- data/lib/habarico/definition/views/list_view.rb +17 -0
- data/lib/habarico/definition/views/show_view.rb +15 -0
- data/lib/habarico/definition/views/view.rb +10 -0
- data/lib/habarico/engine.rb +6 -0
- data/lib/habarico/file_validations.rb +119 -0
- data/lib/habarico/generators/abstract_generator.rb +21 -0
- data/lib/habarico/generators/action/action_schema_generator.rb +111 -0
- data/lib/habarico/generators/action/confirm_dialog_properties_generator.rb +30 -0
- data/lib/habarico/generators/action/global_resource_action_schema_generator.rb +46 -0
- data/lib/habarico/generators/action/link_action_parameters_generator.rb +31 -0
- data/lib/habarico/generators/action/resource_action_endpoint_parameters_generator.rb +70 -0
- data/lib/habarico/generators/action/resource_action_parameters_generator.rb +40 -0
- data/lib/habarico/generators/action/resource_action_schema_generator.rb +51 -0
- data/lib/habarico/generators/action/save_action_parameters_generator.rb +26 -0
- data/lib/habarico/generators/action/upload_images_action_parameters_generator.rb +41 -0
- data/lib/habarico/generators/action/view_action_endpoint_parameters_generator.rb +37 -0
- data/lib/habarico/generators/action/view_action_parameters_generator.rb +56 -0
- data/lib/habarico/generators/endpoint/dynamic_render_options_generator.rb +26 -0
- data/lib/habarico/generators/endpoint/endpoints_schema_generator.rb +61 -0
- data/lib/habarico/generators/endpoint/enum_type_generator.rb +45 -0
- data/lib/habarico/generators/endpoint/field_options_generator.rb +179 -0
- data/lib/habarico/generators/endpoint/field_schema_generator.rb +381 -0
- data/lib/habarico/generators/endpoint/fields_schema_generator.rb +35 -0
- data/lib/habarico/generators/endpoint/filter_schema_generator.rb +201 -0
- data/lib/habarico/generators/endpoint/filters_schema_generator.rb +25 -0
- data/lib/habarico/generators/endpoint/method_schema_generator.rb +34 -0
- data/lib/habarico/generators/endpoint/number_field_options_generator.rb +45 -0
- data/lib/habarico/generators/endpoint/phone_field_options_generator.rb +29 -0
- data/lib/habarico/generators/endpoint/relation_field_options_generator.rb +90 -0
- data/lib/habarico/generators/endpoint/search_filter_schema_generator.rb +44 -0
- data/lib/habarico/generators/menu/menu_group_schema_generator.rb +63 -0
- data/lib/habarico/generators/menu/menu_link_parameters_generator.rb +31 -0
- data/lib/habarico/generators/menu/menu_schema_generator.rb +105 -0
- data/lib/habarico/generators/menu/menu_view_endpoint_parameters_generator.rb +44 -0
- data/lib/habarico/generators/menu/menu_view_parameters_generator.rb +50 -0
- data/lib/habarico/generators/resource/action_resource_schema_generator.rb +84 -0
- data/lib/habarico/generators/resource/global_resource_schema_generator.rb +70 -0
- data/lib/habarico/generators/resource/local_resource_schema_generator.rb +111 -0
- data/lib/habarico/generators/resource/object_resource_schema_generator.rb +49 -0
- data/lib/habarico/generators/resource/resource_schema_generator.rb +31 -0
- data/lib/habarico/generators/view/action_descriptor_generator.rb +88 -0
- data/lib/habarico/generators/view/array_box_parameters_generator.rb +34 -0
- data/lib/habarico/generators/view/box_options_generator.rb +23 -0
- data/lib/habarico/generators/view/box_schema_generator.rb +194 -0
- data/lib/habarico/generators/view/detail_view_parameters_generator.rb +57 -0
- data/lib/habarico/generators/view/field_descriptor_generator.rb +107 -0
- data/lib/habarico/generators/view/filter_descriptor_generator.rb +75 -0
- data/lib/habarico/generators/view/gallery_box_parameters_generator.rb +71 -0
- data/lib/habarico/generators/view/global_view_schema_generator.rb +59 -0
- data/lib/habarico/generators/view/grid_item_box_parameters_generator.rb +44 -0
- data/lib/habarico/generators/view/list_box_parameters_generator.rb +124 -0
- data/lib/habarico/generators/view/list_view_parameters_generator.rb +120 -0
- data/lib/habarico/generators/view/object_box_parameters_generator.rb +26 -0
- data/lib/habarico/generators/view/sort_descriptor_generator.rb +30 -0
- data/lib/habarico/generators/view/tab_box_parameters_generator.rb +26 -0
- data/lib/habarico/generators/view/view_endpoint_parameters_generator.rb +71 -0
- data/lib/habarico/generators/view/view_schema_generator.rb +87 -0
- data/lib/habarico/generators/view/wizard_box_parameters_generator.rb +32 -0
- data/lib/habarico/helpers/action_helper.rb +9 -0
- data/lib/habarico/helpers/attributes_helper.rb +67 -0
- data/lib/habarico/helpers/box_helper.rb +19 -0
- data/lib/habarico/helpers/callable_helper.rb +15 -0
- data/lib/habarico/helpers/filter_params_helper.rb +49 -0
- data/lib/habarico/helpers/order_by_helper.rb +56 -0
- data/lib/habarico/helpers/reflection_helper.rb +61 -0
- data/lib/habarico/helpers/sorting_helper.rb +136 -0
- data/lib/habarico/schema/action/action_schema.rb +46 -0
- data/lib/habarico/schema/action/confirm_dialog_properties.rb +13 -0
- data/lib/habarico/schema/action/global_resource_action_schema.rb +29 -0
- data/lib/habarico/schema/action/link_action_parameters.rb +15 -0
- data/lib/habarico/schema/action/resource_action_endpoint_parameters.rb +24 -0
- data/lib/habarico/schema/action/resource_action_parameters.rb +17 -0
- data/lib/habarico/schema/action/resource_action_schema.rb +14 -0
- data/lib/habarico/schema/action/save_action_parameters.rb +10 -0
- data/lib/habarico/schema/action/upload_images_action_parameters.rb +23 -0
- data/lib/habarico/schema/action/view_action_endpoint_parameters.rb +16 -0
- data/lib/habarico/schema/action/view_action_parameters.rb +27 -0
- data/lib/habarico/schema/endpoint/ai_field_options.rb +10 -0
- data/lib/habarico/schema/endpoint/box_options.rb +10 -0
- data/lib/habarico/schema/endpoint/choices_field_options.rb +10 -0
- data/lib/habarico/schema/endpoint/dynamic_render_options.rb +14 -0
- data/lib/habarico/schema/endpoint/endpoints_schema.rb +22 -0
- data/lib/habarico/schema/endpoint/enum_type.rb +21 -0
- data/lib/habarico/schema/endpoint/field_options.rb +56 -0
- data/lib/habarico/schema/endpoint/field_schema.rb +65 -0
- data/lib/habarico/schema/endpoint/filter_schema.rb +44 -0
- data/lib/habarico/schema/endpoint/image_field_options.rb +13 -0
- data/lib/habarico/schema/endpoint/key_value.rb +13 -0
- data/lib/habarico/schema/endpoint/method_schema.rb +13 -0
- data/lib/habarico/schema/endpoint/number_field_options.rb +24 -0
- data/lib/habarico/schema/endpoint/phone_field_options.rb +13 -0
- data/lib/habarico/schema/endpoint/relation_field_options.rb +39 -0
- data/lib/habarico/schema/extensible_enum.rb +20 -0
- data/lib/habarico/schema/menu/action_view_choice.rb +13 -0
- data/lib/habarico/schema/menu/menu_group_schema.rb +26 -0
- data/lib/habarico/schema/menu/menu_schema.rb +36 -0
- data/lib/habarico/schema/resource/global_resource_schema.rb +14 -0
- data/lib/habarico/schema/resource/local_resource_schema.rb +14 -0
- data/lib/habarico/schema/resource/object_resource_schema.rb +8 -0
- data/lib/habarico/schema/resource/resource_schema.rb +16 -0
- data/lib/habarico/schema/types.rb +102 -0
- data/lib/habarico/schema/view/action_descriptor.rb +30 -0
- data/lib/habarico/schema/view/array_box_parameters.rb +13 -0
- data/lib/habarico/schema/view/box_schema.rb +67 -0
- data/lib/habarico/schema/view/detail_view_parameters.rb +16 -0
- data/lib/habarico/schema/view/field_descriptor.rb +50 -0
- data/lib/habarico/schema/view/field_wrapper_properties.rb +13 -0
- data/lib/habarico/schema/view/filter_descriptor.rb +24 -0
- data/lib/habarico/schema/view/gallery_box_parameters.rb +31 -0
- data/lib/habarico/schema/view/global_view_schema.rb +25 -0
- data/lib/habarico/schema/view/grid_item_box_parameters.rb +13 -0
- data/lib/habarico/schema/view/list_box_parameters.rb +44 -0
- data/lib/habarico/schema/view/list_view_parameters.rb +31 -0
- data/lib/habarico/schema/view/object_box_parameters.rb +10 -0
- data/lib/habarico/schema/view/sort_descriptor.rb +15 -0
- data/lib/habarico/schema/view/sortable_parameters.rb +13 -0
- data/lib/habarico/schema/view/tab_box_parameters.rb +10 -0
- data/lib/habarico/schema/view/view_action_descriptor_parameters.rb +21 -0
- data/lib/habarico/schema/view/view_endpoint_parameters.rb +22 -0
- data/lib/habarico/schema/view/view_schema.rb +33 -0
- data/lib/habarico/schema/view/wizard_box_parameters.rb +13 -0
- data/lib/habarico/search/field_resolver.rb +138 -0
- data/lib/habarico/search/search_matcher.rb +152 -0
- data/lib/habarico/serializers/meta_serializer.rb +42 -0
- data/lib/habarico/serializers/record_serializer.rb +33 -0
- data/lib/habarico/serializers/serializer.rb +61 -0
- data/lib/habarico/services/resource_service.rb +69 -0
- data/lib/habarico/services/routing_service.rb +160 -0
- data/lib/habarico/services/schema_service.rb +72 -0
- data/lib/habarico/version.rb +5 -0
- data/lib/habarico.rb +262 -0
- metadata +324 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class LocalResourceSchemaGenerator < ResourceSchemaGenerator
|
|
3
|
+
|
|
4
|
+
def generate(context)
|
|
5
|
+
actions, actions_endpoint_parameters = generate_actions(context)
|
|
6
|
+
views, views_endpoint_parameters = generate_views(context)
|
|
7
|
+
Habarico::LocalResourceSchema.new(
|
|
8
|
+
name: generate_name,
|
|
9
|
+
label: generate_label,
|
|
10
|
+
pk_field_name: generate_pk_field_name,
|
|
11
|
+
actions: actions,
|
|
12
|
+
views: views,
|
|
13
|
+
endpoints: generate_endpoints(context, actions_endpoint_parameters + views_endpoint_parameters)
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def resource_action_schema_generator
|
|
20
|
+
@resource_action_schema_generator ||= definition.resource_action_schema_generator.new(definition, resource_path)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def view_schema_generator
|
|
24
|
+
@view_schema_generator ||= definition.view_schema_generator.new(definition, resource_path)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def endpoints_schema_generator
|
|
28
|
+
@endpoints_schema_generator ||= definition.endpoints_schema_generator.new(definition, resource_path)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# ***********************************************************************
|
|
32
|
+
# Attribute generators
|
|
33
|
+
# ***********************************************************************
|
|
34
|
+
|
|
35
|
+
def generate_actions(context)
|
|
36
|
+
is_detail = !context.record_pk.blank?
|
|
37
|
+
|
|
38
|
+
# Generate and filter actions based on permissions and whether we are generating for detail or list
|
|
39
|
+
action_schemas = definition.normalized_actions.select do |action|
|
|
40
|
+
|
|
41
|
+
# Action must be allowed by permissions
|
|
42
|
+
context.can?(action.permission)
|
|
43
|
+
|
|
44
|
+
end.map do |action|
|
|
45
|
+
|
|
46
|
+
# Generate action schema
|
|
47
|
+
resource_action_schema_generator.generate(action, context)
|
|
48
|
+
|
|
49
|
+
end.select do |action_schema|
|
|
50
|
+
|
|
51
|
+
# Plausibility check, only actions that are shown in the current context should be included here
|
|
52
|
+
(is_detail && action_schema.show_in_detail) || # we generate record/detail schema and action should be shown in detail
|
|
53
|
+
(!is_detail && action_schema.show_in_list && !action_schema.is_detail) # we generate resource/list schema and action should be shown in list and does not require record PK
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Extract endpoint parameters from actions
|
|
58
|
+
endpoint_parameters = action_schemas.map { |action_schema| action_schema&.resource&.endpoint }.compact
|
|
59
|
+
|
|
60
|
+
[action_schemas, endpoint_parameters]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def generate_views(context)
|
|
64
|
+
is_detail = !context.record_pk.blank?
|
|
65
|
+
|
|
66
|
+
# Generate and filter views based on permissions and whether we are generating for detail or list
|
|
67
|
+
view_schemas = definition.normalized_views.select do |view|
|
|
68
|
+
|
|
69
|
+
# View must be allowed by permissions, only exception is the show view in order to support references across
|
|
70
|
+
# multiple services.
|
|
71
|
+
(view.name.to_s == 'show' && is_detail) || context.can?(view.permission)
|
|
72
|
+
|
|
73
|
+
end.map do |view|
|
|
74
|
+
|
|
75
|
+
# Generate view schema
|
|
76
|
+
view_schema_generator.generate(view, context)
|
|
77
|
+
|
|
78
|
+
end.select do |view_schema|
|
|
79
|
+
|
|
80
|
+
# Plausibility check, only views that are shown in the current context should be included here
|
|
81
|
+
view_schema.is_detail == is_detail
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Extract endpoint parameters from views
|
|
86
|
+
endpoint_parameters = view_schemas.map { |view_schema| view_schema&.endpoint }.compact
|
|
87
|
+
|
|
88
|
+
[view_schemas, endpoint_parameters]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def generate_endpoints(_context, endpoint_parameters)
|
|
92
|
+
# Determine endpoint methods to be included, base for the selection ale endpoint parameters collected from the
|
|
93
|
+
# actions and views without action name and without reference. Additionally, always include GET.
|
|
94
|
+
methods = endpoint_parameters.select { |e| e.action_name.blank? && e.reference.blank? }.map { |e| e.method.to_sym }
|
|
95
|
+
methods << :get # Ensure GET is always present
|
|
96
|
+
methods = methods.uniq
|
|
97
|
+
|
|
98
|
+
# Determine read and write fields
|
|
99
|
+
read_fields = (definition.fields + definition.read_only_fields).uniq
|
|
100
|
+
write_fields = (definition.fields + definition.write_only_fields).uniq
|
|
101
|
+
|
|
102
|
+
# Generate endpoint schema
|
|
103
|
+
endpoints_schema_generator.generate(definition.model,
|
|
104
|
+
read_fields,
|
|
105
|
+
write_fields,
|
|
106
|
+
definition.filters,
|
|
107
|
+
methods)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class ObjectResourceSchemaGenerator < ResourceSchemaGenerator
|
|
3
|
+
|
|
4
|
+
def generate(view_type, context)
|
|
5
|
+
Habarico::ObjectResourceSchema.new(
|
|
6
|
+
name: generate_name,
|
|
7
|
+
label: generate_label,
|
|
8
|
+
pk_field_name: generate_pk_field_name,
|
|
9
|
+
actions: generate_actions(view_type, context),
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
protected
|
|
14
|
+
|
|
15
|
+
# ***********************************************************************
|
|
16
|
+
# Attribute generators
|
|
17
|
+
# ***********************************************************************
|
|
18
|
+
|
|
19
|
+
def generate_actions(_view_type, context)
|
|
20
|
+
action_schemas = definition.normalized_actions.select do |action|
|
|
21
|
+
|
|
22
|
+
# Action must be allowed by permissions
|
|
23
|
+
context.can?(action.permission)
|
|
24
|
+
|
|
25
|
+
end.select do |action|
|
|
26
|
+
|
|
27
|
+
# Conditional display check
|
|
28
|
+
if action.if.respond_to?(:call)
|
|
29
|
+
action.if.call(context)
|
|
30
|
+
else
|
|
31
|
+
true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end.map do |action|
|
|
35
|
+
|
|
36
|
+
# Generate action schema
|
|
37
|
+
resource_action_schema_generator.generate(action, context)
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Object-level meta always represents detail semantics, regardless of which endpoint
|
|
42
|
+
# (list or detail) is rendering it, so that a record's action list is identical no
|
|
43
|
+
# matter which response it came from. Only record-bound actions belong here; actions
|
|
44
|
+
# that aren't tied to a specific record (e.g. create) are excluded via is_detail.
|
|
45
|
+
action_schemas.select(&:is_detail)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class ResourceSchemaGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate
|
|
5
|
+
raise NotImplementedError('Subclasses must implement the generate method.')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
protected
|
|
9
|
+
|
|
10
|
+
def resource_action_schema_generator
|
|
11
|
+
@resource_action_schema_generator ||= definition.resource_action_schema_generator.new(definition, resource_path)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# ***********************************************************************
|
|
15
|
+
# Attribute generators
|
|
16
|
+
# ***********************************************************************
|
|
17
|
+
|
|
18
|
+
def generate_name
|
|
19
|
+
resource_path.last
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def generate_label
|
|
23
|
+
definition.label || I18n.t("resources.#{resource_path.join('.')}", default: generate_name.to_s.humanize)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def generate_pk_field_name
|
|
27
|
+
definition.model.primary_key
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class ActionDescriptorGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(action_reference, context)
|
|
5
|
+
# Fallback to a simple ActionReference object if a string or symbol is provided
|
|
6
|
+
action_reference = Habarico::ActionReference.new(name: action_reference.to_s) if action_reference.is_a?(String) || action_reference.is_a?(Symbol)
|
|
7
|
+
|
|
8
|
+
# Validate arguments
|
|
9
|
+
raise Eluvia::Errors::StandardError.new('Argument `action_reference` must be a Habarico::ActionReference') unless action_reference.is_a?(Habarico::ActionReference)
|
|
10
|
+
|
|
11
|
+
# Check permission
|
|
12
|
+
if action_reference.permission.present?
|
|
13
|
+
return nil unless context.can?(action_reference.permission)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Check "if" condition
|
|
17
|
+
if action_reference.if.present?
|
|
18
|
+
return nil unless Habarico::CallableHelper.resolve(action_reference.if, context)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Create model
|
|
22
|
+
Habarico::ActionDescriptor.new(
|
|
23
|
+
name: generate_name(action_reference, context),
|
|
24
|
+
label: generate_label(action_reference, context),
|
|
25
|
+
icon: generate_icon(action_reference, context),
|
|
26
|
+
color: generate_color(action_reference, context),
|
|
27
|
+
action: generate_action(action_reference, context),
|
|
28
|
+
view: generate_view(action_reference, context),
|
|
29
|
+
menu_items: generate_menu_items(action_reference, context),
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
protected
|
|
34
|
+
|
|
35
|
+
def action_schema_generator
|
|
36
|
+
@action_schema_generator ||= definition.action_schema_generator.new(definition, resource_path)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# ***********************************************************************
|
|
40
|
+
# Attribute generators
|
|
41
|
+
# ***********************************************************************
|
|
42
|
+
|
|
43
|
+
def generate_name(action_reference, _context)
|
|
44
|
+
action_reference.name
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def generate_label(action_reference, _context)
|
|
48
|
+
action_reference.label
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def generate_icon(action_reference, _context)
|
|
52
|
+
action_reference.icon
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def generate_color(action_reference, _context)
|
|
56
|
+
action_reference.color
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def generate_action(action_reference, context)
|
|
60
|
+
if action_reference.action.present?
|
|
61
|
+
return action_schema_generator.generate(action_reference.action, context)
|
|
62
|
+
end
|
|
63
|
+
nil
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def generate_view(action_reference, _context)
|
|
67
|
+
has_view_params = action_reference.view_mode.present? ||
|
|
68
|
+
action_reference.view_choices.present? ||
|
|
69
|
+
action_reference.view_parameters.present? ||
|
|
70
|
+
!action_reference.view_keep_linked_parent.nil?
|
|
71
|
+
return nil unless has_view_params
|
|
72
|
+
Habarico::ViewActionDescriptorParameters.new(
|
|
73
|
+
mode: action_reference.view_mode,
|
|
74
|
+
choices: action_reference.view_choices,
|
|
75
|
+
parameters: action_reference.view_parameters,
|
|
76
|
+
keep_linked_parent: action_reference.view_keep_linked_parent,
|
|
77
|
+
)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def generate_menu_items(action_reference, context)
|
|
81
|
+
return nil unless action_reference.menu_items.present?
|
|
82
|
+
action_reference.menu_items.map do |item|
|
|
83
|
+
generate(item, context)
|
|
84
|
+
end.compact
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class ArrayBoxParametersGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(box, context)
|
|
5
|
+
# Validate arguments
|
|
6
|
+
raise Eluvia::Errors::StandardError.new('Argument `box` must be a Habarico::ArrayBox') unless box.is_a?(Habarico::ArrayBox)
|
|
7
|
+
|
|
8
|
+
# Create model
|
|
9
|
+
Habarico::ArrayBoxParameters.new(
|
|
10
|
+
target: generate_target(box, context),
|
|
11
|
+
inline: generate_inline(box, context)
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
|
|
17
|
+
# ***********************************************************************
|
|
18
|
+
# Attribute generators
|
|
19
|
+
# ***********************************************************************
|
|
20
|
+
|
|
21
|
+
def generate_target(box, _context)
|
|
22
|
+
box.target
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Defaults to true unless the box contains nested boxes (then the items are rendered as separate blocks).
|
|
26
|
+
# An explicit `inline` value on the box always wins.
|
|
27
|
+
def generate_inline(box, _context)
|
|
28
|
+
return !!box.inline unless box.inline.nil?
|
|
29
|
+
boxes = box.boxes || []
|
|
30
|
+
boxes.none? { |item| item.is_a?(Habarico::Box) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class BoxOptionsGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(box)
|
|
5
|
+
Habarico::BoxOptions.new(
|
|
6
|
+
dynamic_render: generate_dynamic_render(box)
|
|
7
|
+
)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
protected
|
|
11
|
+
|
|
12
|
+
def generate_dynamic_render(box)
|
|
13
|
+
dynamic_render_options_generator.generate(definition.model, box)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def dynamic_render_options_generator
|
|
19
|
+
@dynamic_render_options_generator ||= definition.dynamic_render_options_generator.new(definition, resource_path)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class BoxSchemaGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(view, box, index, context)
|
|
5
|
+
# Fallback to an empty box if none is provided
|
|
6
|
+
box = Habarico::Box.new if box.nil?
|
|
7
|
+
|
|
8
|
+
# Validate arguments
|
|
9
|
+
raise Eluvia::Errors::StandardError.new('Argument `view` must be a Habarico::View') unless view.is_a?(Habarico::View)
|
|
10
|
+
raise Eluvia::Errors::StandardError.new('Argument `box` must be a Habarico::Box') unless box.is_a?(Habarico::Box)
|
|
11
|
+
|
|
12
|
+
# Deduce reference and target for has_many associations for list boxes
|
|
13
|
+
if box.type == 'list' && !box.reference
|
|
14
|
+
if box.name && Habarico::ReflectionHelper.is_has_many_association?(definition.model, box.name)
|
|
15
|
+
reflection = definition.model.reflect_on_association(box.name.to_sym)
|
|
16
|
+
if reflection
|
|
17
|
+
reference = Habarico::ResourceService.instance.find_resource_name_by_model_class(reflection.klass)
|
|
18
|
+
if reference
|
|
19
|
+
box.reference = reference
|
|
20
|
+
box.target = reflection.foreign_key
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Create model
|
|
27
|
+
Habarico::BoxSchema.new(
|
|
28
|
+
type: generate_type(view, box, index, context),
|
|
29
|
+
name: generate_name(view, box, index, context),
|
|
30
|
+
label: generate_label(view, box, index, context),
|
|
31
|
+
read_only: generate_read_only(view, box, index, context),
|
|
32
|
+
card: generate_card(view, box, index, context),
|
|
33
|
+
collapsible: generate_collapsible(view, box, index, context),
|
|
34
|
+
toolbar_actions: generate_toolbar_actions(view, box, index, context),
|
|
35
|
+
bottom_actions: generate_bottom_actions(view, box, index, context),
|
|
36
|
+
boxes: generate_boxes(view, box, index, context),
|
|
37
|
+
grid_item: generate_grid_item(view, box, index, context),
|
|
38
|
+
list: generate_list(view, box, index, context),
|
|
39
|
+
tab: generate_tab(view, box, index, context),
|
|
40
|
+
wizard: generate_wizard(view, box, index, context),
|
|
41
|
+
array: generate_array(view, box, index, context),
|
|
42
|
+
object: generate_object(view, box, index, context),
|
|
43
|
+
gallery: generate_gallery(view, box, index, context),
|
|
44
|
+
options: generate_options(view, box, index, context)
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
protected
|
|
49
|
+
|
|
50
|
+
def field_descriptor_generator
|
|
51
|
+
@field_descriptor_generator ||= definition.field_descriptor_generator.new(definition, resource_path)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def box_schema_generator
|
|
55
|
+
@box_schema_generator ||= definition.box_schema_generator.new(definition, resource_path)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def array_box_parameters_generator
|
|
59
|
+
@array_box_parameters_generator ||= definition.array_box_parameters_generator.new(definition, resource_path)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def object_box_parameters_generator
|
|
63
|
+
@object_box_parameters_generator ||= definition.object_box_parameters_generator.new(definition, resource_path)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def grid_item_box_parameters_generator
|
|
67
|
+
@grid_item_box_parameters_generator ||= definition.grid_item_box_parameters_generator.new(definition, resource_path)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def list_box_parameters_generator
|
|
71
|
+
@list_box_parameters_generator ||= definition.list_box_parameters_generator.new(definition, resource_path)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def tab_box_parameters_generator
|
|
75
|
+
@tab_box_parameters_generator ||= definition.tab_box_parameters_generator.new(definition, resource_path)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def wizard_box_parameters_generator
|
|
79
|
+
@wizard_box_parameters_generator ||= definition.wizard_box_parameters_generator.new(definition, resource_path)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def gallery_box_parameters_generator
|
|
83
|
+
@gallery_box_parameters_generator ||= definition.gallery_box_parameters_generator.new(definition, resource_path)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def action_descriptor_generator
|
|
87
|
+
@action_descriptor_generator ||= definition.action_descriptor_generator.new(definition, resource_path)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def box_options_generator
|
|
91
|
+
@box_options_generator ||= definition.box_options_generator.new(definition, resource_path)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# ***********************************************************************
|
|
95
|
+
# Attribute generators
|
|
96
|
+
# ***********************************************************************
|
|
97
|
+
|
|
98
|
+
def generate_type(_view, box, _index, _context)
|
|
99
|
+
box.type
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def generate_name(_view, box, index, _context)
|
|
103
|
+
box.name || index.to_s
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def generate_label(_view, box, _index, _context)
|
|
107
|
+
box.label
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def generate_read_only(_view, box, _index, _context)
|
|
111
|
+
!!box.read_only
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Three-state on purpose: true (always a card), false (never a card, not even with a label)
|
|
115
|
+
# and nil (unset - the frontend decides from the label, the toolbar actions and the surface).
|
|
116
|
+
# Coercing nil to false here would strip the card off every labelled box.
|
|
117
|
+
def generate_card(_view, box, _index, _context)
|
|
118
|
+
box.card
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def generate_collapsible(_view, box, _index, _context)
|
|
122
|
+
box.collapsible&.to_s
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Box-level toolbar (box header / card header area), relative to the box root. Emitted for all box types
|
|
126
|
+
# including 'list' - for a list box the table's own toolbar is carried separately by 'list.toolbar_actions'.
|
|
127
|
+
def generate_toolbar_actions(_view, box, _index, context)
|
|
128
|
+
return nil if box.toolbar_actions.nil?
|
|
129
|
+
box.toolbar_actions.map do |action|
|
|
130
|
+
action_descriptor_generator.generate(action, context)
|
|
131
|
+
end.compact
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Box-level bottom actions (rendered below the box fields), relative to the box root.
|
|
135
|
+
def generate_bottom_actions(_view, box, _index, context)
|
|
136
|
+
return nil if box.bottom_actions.nil?
|
|
137
|
+
box.bottom_actions.map do |action|
|
|
138
|
+
action_descriptor_generator.generate(action, context)
|
|
139
|
+
end.compact
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def generate_boxes(view, box, _index, context)
|
|
143
|
+
referenced_model = Habarico::BoxHelper.get_referenced_model(box) || definition.model
|
|
144
|
+
boxes = box.boxes || view.boxes
|
|
145
|
+
return nil if boxes.nil? || boxes.empty?
|
|
146
|
+
boxes.enum_for(:each_with_index).map do |item, i|
|
|
147
|
+
if item.is_a?(Habarico::Box)
|
|
148
|
+
box_schema_generator.generate(view, item, i, context)
|
|
149
|
+
else
|
|
150
|
+
field_descriptor_generator.generate(referenced_model, item, context)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def generate_grid_item(_view, box, _index, context)
|
|
156
|
+
return nil unless box.type == 'grid-item'
|
|
157
|
+
grid_item_box_parameters_generator.generate(box, context)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def generate_list(_view, box, _index, context)
|
|
161
|
+
return nil unless box.type == 'list'
|
|
162
|
+
list_box_parameters_generator.generate(box, context)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def generate_tab(_view, box, _index, context)
|
|
166
|
+
return nil unless box.type == 'tab'
|
|
167
|
+
tab_box_parameters_generator.generate(box, context)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def generate_wizard(_view, box, _index, context)
|
|
171
|
+
return nil unless box.type == 'wizard'
|
|
172
|
+
wizard_box_parameters_generator.generate(box, context)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def generate_array(_view, box, _index, context)
|
|
176
|
+
return nil unless box.type == 'array'
|
|
177
|
+
array_box_parameters_generator.generate(box, context)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def generate_object(_view, box, _index, context)
|
|
181
|
+
return nil unless box.type == 'object'
|
|
182
|
+
object_box_parameters_generator.generate(box, context)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def generate_gallery(_view, box, _index, context)
|
|
186
|
+
return nil unless box.type == 'gallery'
|
|
187
|
+
gallery_box_parameters_generator.generate(box, context)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def generate_options(_view, box, _index, _context)
|
|
191
|
+
box_options_generator.generate(box)
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class DetailViewParametersGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(view, context)
|
|
5
|
+
# Validate arguments
|
|
6
|
+
raise Eluvia::Errors::StandardError.new('Argument `view` must be a Habarico::View') unless view.is_a?(Habarico::View)
|
|
7
|
+
|
|
8
|
+
# Create model
|
|
9
|
+
Habarico::DetailViewParameters.new(
|
|
10
|
+
box: generate_box(view, context),
|
|
11
|
+
toolbar_actions: generate_toolbar_actions(view, context),
|
|
12
|
+
bottom_actions: generate_bottom_actions(view, context),
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
BOTTOM_ACTION_VIEW_TYPES = %i[create edit action].freeze
|
|
17
|
+
|
|
18
|
+
protected
|
|
19
|
+
|
|
20
|
+
def box_schema_generator
|
|
21
|
+
@box_schema_generator ||= definition.box_schema_generator.new(definition, resource_path)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def action_descriptor_generator
|
|
25
|
+
@action_descriptor_generator ||= definition.action_descriptor_generator.new(definition, resource_path)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# ***********************************************************************
|
|
29
|
+
# Attribute generators
|
|
30
|
+
# ***********************************************************************
|
|
31
|
+
|
|
32
|
+
def generate_box(view, context)
|
|
33
|
+
box_schema_generator.generate(view, view.box, 0, context)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def generate_toolbar_actions(view, context)
|
|
37
|
+
unless view.toolbar_actions.nil?
|
|
38
|
+
return view.toolbar_actions.map do |action|
|
|
39
|
+
action_descriptor_generator.generate(action, context)
|
|
40
|
+
end.compact
|
|
41
|
+
end
|
|
42
|
+
nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def generate_bottom_actions(view, context)
|
|
46
|
+
if BOTTOM_ACTION_VIEW_TYPES.include?(view.type.to_sym)
|
|
47
|
+
save_reference = Habarico::ActionReference.new(
|
|
48
|
+
name: 'save',
|
|
49
|
+
permission: nil,
|
|
50
|
+
action: Habarico::SaveAction.new
|
|
51
|
+
)
|
|
52
|
+
[action_descriptor_generator.generate(save_reference, context)].compact
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|