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,10 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class View
|
|
3
|
+
include DefinitionModel
|
|
4
|
+
|
|
5
|
+
attr_accessor :type, :name, :label, :is_detail, :view_mode, :boxes, :filters, :toolbar_filters, :box, :endpoint_action_name,
|
|
6
|
+
:endpoint_method, :endpoint_reference, :model, :default_sorting, :row_actions, :toolbar_actions, :list_actions,
|
|
7
|
+
:single_click_action, :double_click_action, :permission
|
|
8
|
+
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
require 'marcel'
|
|
2
|
+
|
|
3
|
+
module Habarico
|
|
4
|
+
# Per-field file validations, read from the host's `active_storage_validations` declarations on
|
|
5
|
+
# a `file_attr`'s `underlying_attachment` (HAB-966). Mirrors the Python package's
|
|
6
|
+
# `habarico.validators.content_types` / `habarico.validators.files`.
|
|
7
|
+
#
|
|
8
|
+
# `active_storage_validations` is deliberately NOT a dependency of this gem: a host that does not
|
|
9
|
+
# use it simply declares no such validators, and `for_model` resolves to `NONE`. Not upload-
|
|
10
|
+
# specific either - `habarico_enterprise.uploads` folds in its own project-wide size ceiling and
|
|
11
|
+
# content-type blocklist on top of this for a field a chunked-upload provider actually serves,
|
|
12
|
+
# but this module alone is what fills `max_size` / `accept` for every `file_attr`, enterprise or
|
|
13
|
+
# not.
|
|
14
|
+
module FileValidations
|
|
15
|
+
|
|
16
|
+
# What one field's declarations amount to - the *rules* a value is measured against, never a
|
|
17
|
+
# value's own claimed properties. `allowed_content_types` is nil when the field declares no
|
|
18
|
+
# content-type restriction; `max_size` is nil when it declares no upper bound.
|
|
19
|
+
Rules = Struct.new(:allowed_content_types, :max_size, keyword_init: true)
|
|
20
|
+
|
|
21
|
+
# No declarations at all - what an unknown model, a non-`file_attr` attribute, or a host
|
|
22
|
+
# without `active_storage_validations` resolves to.
|
|
23
|
+
NONE = Rules.new(allowed_content_types: nil, max_size: nil).freeze
|
|
24
|
+
|
|
25
|
+
# ***********************************************************************
|
|
26
|
+
# Derivation
|
|
27
|
+
# ***********************************************************************
|
|
28
|
+
|
|
29
|
+
# The `Rules` for one `file_attr`, derived from the model class schema generation already has
|
|
30
|
+
# in hand. Returns `NONE` when there is nothing to derive: no model, the attribute is not a
|
|
31
|
+
# `file_attr` or has no `underlying_attachment`, or `active_storage_validations` is not
|
|
32
|
+
# installed.
|
|
33
|
+
def self.for_model(model, attr_name)
|
|
34
|
+
return NONE if model.nil? || attr_name.blank?
|
|
35
|
+
return NONE unless model.respond_to?(:has_file_attr?) && model.has_file_attr?(attr_name)
|
|
36
|
+
return NONE unless model.respond_to?(:validators_on)
|
|
37
|
+
|
|
38
|
+
attachment = model.find_file_attr(attr_name)&.fetch(:underlying_attachment, nil)
|
|
39
|
+
return NONE if attachment.blank?
|
|
40
|
+
|
|
41
|
+
validators = model.validators_on(attachment)
|
|
42
|
+
Rules.new(allowed_content_types: content_types_from(validators), max_size: max_size_from(validators))
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# The `accept` field-schema option for a field's `allowed_content_types`, or nil when they have
|
|
46
|
+
# no client-checkable form.
|
|
47
|
+
#
|
|
48
|
+
# The frontend matches an entry as a filename extension, a concrete media type or a `type/*`
|
|
49
|
+
# wildcard (`isFileAccepted`), so concrete Marcel-normalized types map over directly. A
|
|
50
|
+
# `Regexp` entry has no such form, and dropping just the regex entries would leave a list
|
|
51
|
+
# *stricter* than the server's - refusing client-side what would otherwise be accepted - so a
|
|
52
|
+
# field declaring one advertises nothing and lets the server alone decide.
|
|
53
|
+
def self.accept_for(content_types)
|
|
54
|
+
return nil if content_types.blank?
|
|
55
|
+
return nil if content_types.any? { |type| type.is_a?(::Regexp) }
|
|
56
|
+
|
|
57
|
+
content_types.map(&:to_s)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# The allowed content types of an `ActiveStorageValidations::ContentTypeValidator`, normalized
|
|
61
|
+
# through Marcel exactly as the validator itself does at save time (`:png` and `'png'` both
|
|
62
|
+
# become `'image/png'`), or nil when the field declares none.
|
|
63
|
+
#
|
|
64
|
+
# A `Proc` option is resolved by the gem per-record (`ASVOptionable#set_flat_options`); there
|
|
65
|
+
# is no record yet at schema-generation time, so a field declaring one yields nil - the
|
|
66
|
+
# validator itself still runs on save.
|
|
67
|
+
def self.content_types_from(validators)
|
|
68
|
+
validator = find_validator(validators, 'ContentTypeValidator')
|
|
69
|
+
return nil if validator.nil?
|
|
70
|
+
|
|
71
|
+
declared = Array(validator.options[:with]) + Array(validator.options[:in])
|
|
72
|
+
return nil if declared.empty? || declared.any? { |type| type.is_a?(::Proc) }
|
|
73
|
+
|
|
74
|
+
declared.filter_map do |type|
|
|
75
|
+
case type
|
|
76
|
+
when ::String, ::Symbol then ::Marcel::MimeType.for(declared_type: type.to_s, extension: type.to_s)
|
|
77
|
+
when ::Regexp then type
|
|
78
|
+
end
|
|
79
|
+
end.presence
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# The inclusive upper bound of an `ActiveStorageValidations::SizeValidator`, or nil when the
|
|
83
|
+
# field declares no upper bound (a `greater_than*`-only validator, a `Proc`, or a non-integer
|
|
84
|
+
# range). `less_than: n` becomes `n - 1` so the ceiling here is exactly the one the validator
|
|
85
|
+
# itself would enforce on save.
|
|
86
|
+
#
|
|
87
|
+
# The gem's `check_validity!` guarantees exactly one of these options is present.
|
|
88
|
+
def self.max_size_from(validators)
|
|
89
|
+
validator = find_validator(validators, 'SizeValidator')
|
|
90
|
+
return nil if validator.nil?
|
|
91
|
+
|
|
92
|
+
options = validator.options
|
|
93
|
+
return nil if options.values.any? { |value| value.is_a?(::Proc) }
|
|
94
|
+
|
|
95
|
+
range = options[:between]
|
|
96
|
+
return integer_bound(range.max) if range.is_a?(::Range) && range.first.is_a?(::Integer)
|
|
97
|
+
return integer_bound(options[:less_than])&.pred if options[:less_than]
|
|
98
|
+
|
|
99
|
+
integer_bound(options[:less_than_or_equal_to] || options[:equal_to])
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def self.integer_bound(value)
|
|
103
|
+
value.is_a?(::Integer) ? value : nil
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# nil unless `active_storage_validations` is installed - the gem requires every validator
|
|
107
|
+
# eagerly from its entry point, so the constant is defined as soon as it is loaded at all.
|
|
108
|
+
def self.find_validator(validators, class_name)
|
|
109
|
+
full_name = "ActiveStorageValidations::#{class_name}"
|
|
110
|
+
return nil unless ::Object.const_defined?(full_name)
|
|
111
|
+
|
|
112
|
+
klass = full_name.constantize
|
|
113
|
+
validators.find { |validator| validator.is_a?(klass) }
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
private_class_method :content_types_from, :max_size_from, :integer_bound, :find_validator
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def initialize(definition, resource_path)
|
|
5
|
+
@definition = definition
|
|
6
|
+
@resource_path = resource_path
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
protected
|
|
10
|
+
|
|
11
|
+
attr_reader :definition
|
|
12
|
+
|
|
13
|
+
attr_reader :resource_path
|
|
14
|
+
|
|
15
|
+
def resource_name
|
|
16
|
+
@resource_path.last
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class ActionSchemaGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(action, context)
|
|
5
|
+
# Validate arguments
|
|
6
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be a Habarico::Action') unless action.is_a?(Habarico::Action)
|
|
7
|
+
|
|
8
|
+
# Create model
|
|
9
|
+
Habarico::ActionSchema.new(
|
|
10
|
+
type: generate_type(action, context),
|
|
11
|
+
is_detail: generate_is_detail(action, context),
|
|
12
|
+
label: generate_label(action, context),
|
|
13
|
+
icon: generate_icon(action, context),
|
|
14
|
+
color: generate_color(action, context),
|
|
15
|
+
confirm_dialog: generate_confirm_dialog(action, context),
|
|
16
|
+
view: generate_view(action, context),
|
|
17
|
+
resource: generate_resource(action, context),
|
|
18
|
+
link: generate_link(action, context),
|
|
19
|
+
save: generate_save(action, context),
|
|
20
|
+
upload_images: generate_upload_images(action, context)
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
protected
|
|
25
|
+
|
|
26
|
+
def view_action_parameters_generator
|
|
27
|
+
@view_action_parameters_generator ||= definition.view_action_parameters_generator.new(definition, resource_path)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def save_action_parameters_generator
|
|
31
|
+
@save_action_parameters_generator ||= definition.save_action_parameters_generator.new(definition, resource_path)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def resource_action_parameters_generator
|
|
35
|
+
@resource_action_parameters_generator ||= definition.resource_action_parameters_generator.new(definition, resource_path)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def link_action_parameters_generator
|
|
39
|
+
@link_action_parameters_generator ||= definition.link_action_parameters_generator.new(definition, resource_path)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def upload_images_action_parameters_generator
|
|
43
|
+
@upload_images_action_parameters_generator ||= definition.upload_images_action_parameters_generator.new(definition, resource_path)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def confirm_dialog_properties_generator
|
|
47
|
+
@confirm_dialog_properties_generator ||= definition.confirm_dialog_properties_generator.new(definition, resource_path)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# ***********************************************************************
|
|
51
|
+
# Attribute generators
|
|
52
|
+
# ***********************************************************************
|
|
53
|
+
|
|
54
|
+
def generate_type(action, _context)
|
|
55
|
+
action.type
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def generate_is_detail(action, _context)
|
|
59
|
+
action.is_detail
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def generate_label(action, _context)
|
|
63
|
+
action.label
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def generate_icon(action, _context)
|
|
67
|
+
action.icon
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def generate_color(action, _context)
|
|
71
|
+
action.color
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def generate_confirm_dialog(action, context)
|
|
75
|
+
if !action.confirm_dialog_title.blank? || !action.confirm_dialog_message.blank?
|
|
76
|
+
confirm_dialog_properties_generator.generate(action, context)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def generate_view(action, context)
|
|
81
|
+
if action.type.to_sym == :view
|
|
82
|
+
view_action_parameters_generator.generate(action, context)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def generate_resource(action, context)
|
|
87
|
+
if action.type.to_sym == :resource
|
|
88
|
+
resource_action_parameters_generator.generate(action, context)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def generate_link(action, context)
|
|
93
|
+
if action.type.to_sym == :link
|
|
94
|
+
link_action_parameters_generator.generate(action, context)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def generate_save(action, context)
|
|
99
|
+
if action.type.to_sym == :save
|
|
100
|
+
data = Habarico::CallableHelper.resolve(action.data, context)
|
|
101
|
+
save_action_parameters_generator.generate(action, context) unless data.nil?
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def generate_upload_images(action, context)
|
|
106
|
+
if action.type.to_sym == :'upload-images'
|
|
107
|
+
upload_images_action_parameters_generator.generate(action, context)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class ConfirmDialogPropertiesGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(action, context)
|
|
5
|
+
# Validate arguments
|
|
6
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be a Habarico::Action') unless action.is_a?(Habarico::Action)
|
|
7
|
+
|
|
8
|
+
# Create model
|
|
9
|
+
Habarico::ConfirmDialogProperties.new(
|
|
10
|
+
title: generate_title(action, context),
|
|
11
|
+
message: generate_message(action, context),
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
|
|
17
|
+
# ***********************************************************************
|
|
18
|
+
# Attribute generators
|
|
19
|
+
# ***********************************************************************
|
|
20
|
+
|
|
21
|
+
def generate_title(action, _context)
|
|
22
|
+
action.confirm_dialog_title
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def generate_message(action, _context)
|
|
26
|
+
action.confirm_dialog_message
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class GlobalResourceActionSchemaGenerator < ActionSchemaGenerator
|
|
3
|
+
|
|
4
|
+
def generate(action)
|
|
5
|
+
# Fallback to a simple Action object if a string or symbol is provided
|
|
6
|
+
if action.is_a?(String) || action.is_a?(Symbol)
|
|
7
|
+
action = case action.to_sym
|
|
8
|
+
when :show then Habarico::ShowAction.new
|
|
9
|
+
when :edit then Habarico::EditAction.new
|
|
10
|
+
when :create then Habarico::CreateAction.new
|
|
11
|
+
when :delete then Habarico::DeleteAction.new
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Validate arguments
|
|
16
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be a Habarico::Action') unless action.is_a?(Habarico::Action)
|
|
17
|
+
|
|
18
|
+
# Create model
|
|
19
|
+
Habarico::GlobalResourceActionSchema.new(
|
|
20
|
+
type: generate_type(action, Habarico::Context.new),
|
|
21
|
+
is_detail: generate_is_detail(action, Habarico::Context.new),
|
|
22
|
+
name: generate_name(action),
|
|
23
|
+
show_in_detail: generate_show_in_detail(action),
|
|
24
|
+
show_in_list: generate_show_in_list(action),
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
protected
|
|
29
|
+
|
|
30
|
+
# ***********************************************************************
|
|
31
|
+
# Attribute generators
|
|
32
|
+
# ***********************************************************************
|
|
33
|
+
|
|
34
|
+
def generate_name(action)
|
|
35
|
+
action.name
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def generate_show_in_detail(action)
|
|
39
|
+
action.show_in_detail
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def generate_show_in_list(action)
|
|
43
|
+
action.show_in_list
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class LinkActionParametersGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(action, context)
|
|
5
|
+
# Validate arguments
|
|
6
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be a Habarico::Action') unless action.is_a?(Habarico::Action)
|
|
7
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be of :link type') unless action.type.to_sym == :link
|
|
8
|
+
|
|
9
|
+
# Create model
|
|
10
|
+
Habarico::LinkActionParameters.new(
|
|
11
|
+
url: generate_url(action, context),
|
|
12
|
+
target: generate_target(action, context)
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
protected
|
|
17
|
+
|
|
18
|
+
# ***********************************************************************
|
|
19
|
+
# Attribute generators
|
|
20
|
+
# ***********************************************************************
|
|
21
|
+
|
|
22
|
+
def generate_url(action, context)
|
|
23
|
+
Habarico::CallableHelper.resolve(action.link_url, context)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def generate_target(action, _context)
|
|
27
|
+
action.link_target
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class ResourceActionEndpointParametersGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(action, context)
|
|
5
|
+
# Validate arguments
|
|
6
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be a Habarico::Action') unless action.is_a?(Habarico::Action)
|
|
7
|
+
|
|
8
|
+
# Create model
|
|
9
|
+
Habarico::ResourceActionEndpointParameters.new(
|
|
10
|
+
path: generate_path(action, context),
|
|
11
|
+
method: generate_method(action, context),
|
|
12
|
+
reference: generate_reference(action, context),
|
|
13
|
+
action_name: generate_action_name(action, context),
|
|
14
|
+
record_pk: generate_record_pk(action, context)
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
protected
|
|
19
|
+
|
|
20
|
+
# ***********************************************************************
|
|
21
|
+
# Attribute generators
|
|
22
|
+
# ***********************************************************************
|
|
23
|
+
|
|
24
|
+
def generate_path(action, context)
|
|
25
|
+
return nil if Habarico::ActionHelper.is_standard_action?(action)
|
|
26
|
+
url_prefix = Habarico::Config.routing_url_prefix.trim('/')
|
|
27
|
+
result = !url_prefix.blank? ? "/#{url_prefix}" : ''
|
|
28
|
+
|
|
29
|
+
# Add resource path
|
|
30
|
+
reference = generate_reference(action, context)
|
|
31
|
+
if reference.present?
|
|
32
|
+
resource_path_2 = ResourceService.instance.get_resource_path(reference)
|
|
33
|
+
result += "/#{resource_path_2.join('/')}"
|
|
34
|
+
else
|
|
35
|
+
result += "/#{resource_path.join('/')}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Add record PK
|
|
39
|
+
record_pk = generate_record_pk(action, context)
|
|
40
|
+
result += "/#{record_pk}" if record_pk
|
|
41
|
+
|
|
42
|
+
# Add action name
|
|
43
|
+
action_name = generate_action_name(action, context)
|
|
44
|
+
result += "/#{action_name}" if action_name
|
|
45
|
+
|
|
46
|
+
# Return result
|
|
47
|
+
"#{result}/"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def generate_method(action, _context)
|
|
51
|
+
action.endpoint_method
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def generate_reference(action, _context)
|
|
55
|
+
action.endpoint_reference
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def generate_action_name(action, _context)
|
|
59
|
+
return nil if Habarico::ActionHelper.is_standard_action?(action)
|
|
60
|
+
action.endpoint_action_name || action.name
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def generate_record_pk(action, context)
|
|
64
|
+
if action&.is_detail
|
|
65
|
+
context.record_pk
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class ResourceActionParametersGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(action, context)
|
|
5
|
+
# Validate arguments
|
|
6
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be a Habarico::Action') unless action.is_a?(Habarico::Action)
|
|
7
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be of :resource type') unless action.type.to_sym == :resource
|
|
8
|
+
|
|
9
|
+
# Create model
|
|
10
|
+
Habarico::ResourceActionParameters.new(
|
|
11
|
+
is_background: generate_is_background(action, context),
|
|
12
|
+
data: generate_data(action, context),
|
|
13
|
+
endpoint: generate_endpoint(action, context)
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def resource_action_endpoint_parameters_generator
|
|
20
|
+
@resource_action_endpoint_parameters_generator ||= definition.resource_action_endpoint_parameters_generator.new(definition, resource_path)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# ***********************************************************************
|
|
24
|
+
# Attribute generators
|
|
25
|
+
# ***********************************************************************
|
|
26
|
+
|
|
27
|
+
def generate_is_background(action, _context)
|
|
28
|
+
action.is_background
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def generate_data(action, context)
|
|
32
|
+
Habarico::CallableHelper.resolve(action.data, context)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def generate_endpoint(action, context)
|
|
36
|
+
resource_action_endpoint_parameters_generator.generate(action, context)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class ResourceActionSchemaGenerator < ActionSchemaGenerator
|
|
3
|
+
|
|
4
|
+
def generate(action, context)
|
|
5
|
+
# Validate arguments
|
|
6
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be a Habarico::Action') unless action.is_a?(Habarico::Action)
|
|
7
|
+
|
|
8
|
+
# Create model
|
|
9
|
+
Habarico::ResourceActionSchema.new(
|
|
10
|
+
type: generate_type(action, context),
|
|
11
|
+
is_detail: generate_is_detail(action, context),
|
|
12
|
+
label: generate_label(action, context),
|
|
13
|
+
icon: generate_icon(action, context),
|
|
14
|
+
color: generate_color(action, context),
|
|
15
|
+
confirm_dialog: generate_confirm_dialog(action, context),
|
|
16
|
+
view: generate_view(action, context),
|
|
17
|
+
resource: generate_resource(action, context),
|
|
18
|
+
link: generate_link(action, context),
|
|
19
|
+
name: generate_name(action, context),
|
|
20
|
+
show_in_detail: generate_show_in_detail(action, context),
|
|
21
|
+
show_in_list: generate_show_in_list(action, context),
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
protected
|
|
26
|
+
|
|
27
|
+
# ***********************************************************************
|
|
28
|
+
# Attribute generators
|
|
29
|
+
# ***********************************************************************
|
|
30
|
+
|
|
31
|
+
def generate_label(action, context)
|
|
32
|
+
action_name = generate_name(action, context).to_s
|
|
33
|
+
action.label ||
|
|
34
|
+
I18n.t("actions.#{resource_path.join('.')}.#{action.name}", default: nil) ||
|
|
35
|
+
I18n.t("actions.common.#{action_name}", default: nil) ||
|
|
36
|
+
action_name.to_s.humanize
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def generate_name(action, _context)
|
|
40
|
+
action.name
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def generate_show_in_detail(action, _context)
|
|
44
|
+
action.show_in_detail
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def generate_show_in_list(action, _context)
|
|
48
|
+
action.show_in_list
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class SaveActionParametersGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(action, context)
|
|
5
|
+
# Validate arguments
|
|
6
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be a Habarico::Action') unless action.is_a?(Habarico::Action)
|
|
7
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be of :save type') unless action.type.to_sym == :save
|
|
8
|
+
|
|
9
|
+
# Create model
|
|
10
|
+
Habarico::SaveActionParameters.new(
|
|
11
|
+
data: generate_data(action, context)
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
|
|
17
|
+
# ***********************************************************************
|
|
18
|
+
# Attribute generators
|
|
19
|
+
# ***********************************************************************
|
|
20
|
+
|
|
21
|
+
def generate_data(action, context)
|
|
22
|
+
Habarico::CallableHelper.resolve(action.data, context)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class UploadImagesActionParametersGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(action, context)
|
|
5
|
+
# Validate arguments
|
|
6
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be a Habarico::Action') unless action.is_a?(Habarico::Action)
|
|
7
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be of :"upload-images" type') unless action.type.to_sym == :"upload-images"
|
|
8
|
+
|
|
9
|
+
# Create model
|
|
10
|
+
Habarico::UploadImagesActionParameters.new(
|
|
11
|
+
reference: generate_reference(action, context),
|
|
12
|
+
target: generate_target(action, context),
|
|
13
|
+
accept: generate_accept(action, context),
|
|
14
|
+
image_field: generate_image_field(action, context)
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
protected
|
|
19
|
+
|
|
20
|
+
# ***********************************************************************
|
|
21
|
+
# Attribute generators
|
|
22
|
+
# ***********************************************************************
|
|
23
|
+
|
|
24
|
+
def generate_reference(action, _context)
|
|
25
|
+
action.upload_images_reference
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def generate_target(action, _context)
|
|
29
|
+
action.upload_images_target
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def generate_accept(action, _context)
|
|
33
|
+
action.upload_images_accept
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def generate_image_field(action, _context)
|
|
37
|
+
action.upload_images_image_field
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Habarico
|
|
2
|
+
class ViewActionEndpointParametersGenerator < AbstractGenerator
|
|
3
|
+
|
|
4
|
+
def generate(action, context)
|
|
5
|
+
# Validate arguments
|
|
6
|
+
raise Eluvia::Errors::StandardError.new('Argument `action` must be a Habarico::Action') unless action.is_a?(Habarico::Action)
|
|
7
|
+
|
|
8
|
+
# Create model
|
|
9
|
+
Habarico::ViewActionEndpointParameters.new(
|
|
10
|
+
reference: generate_reference(action, context),
|
|
11
|
+
action_name: generate_action_name(action, context),
|
|
12
|
+
record_pk: generate_record_pk(action, context)
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
protected
|
|
17
|
+
|
|
18
|
+
# ***********************************************************************
|
|
19
|
+
# Attribute generators
|
|
20
|
+
# ***********************************************************************
|
|
21
|
+
|
|
22
|
+
def generate_reference(action, _context)
|
|
23
|
+
action.endpoint_reference
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def generate_action_name(action, _context)
|
|
27
|
+
action.endpoint_action_name || action.name
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def generate_record_pk(action, context)
|
|
31
|
+
if action&.is_detail
|
|
32
|
+
context.record_pk
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|