compony 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/compony.gemspec +15 -15
- data/lib/compony/components/destroy.rb +75 -0
- data/lib/compony/components/edit.rb +94 -0
- data/lib/compony/components/new.rb +93 -0
- data/lib/compony/model_fields/anchormodel.rb +1 -1
- data/lib/compony/model_fields/email.rb +12 -0
- data/lib/compony/version.rb +1 -1
- data/lib/compony.rb +5 -4
- metadata +6 -5
- data/lib/compony/components/resourceful/destroy.rb +0 -77
- data/lib/compony/components/resourceful/edit.rb +0 -96
- data/lib/compony/components/resourceful/new.rb +0 -95
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c832dc26e81d2231843d90891d9ca469d5e74dfd3b0e00a588bebf1e8d1f25a2
|
4
|
+
data.tar.gz: 7eb4e6953bbdf22fd67b7e6fa95d6f2ce012e2e350c1a4e3bb04bb34f3c2e9c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fba60b56710e929ad113ddf092019330810dd26036dfd7ce6550becac5e7bfb03d534ac80296707b4613fd12483690e83ff7e224a56b127677141bbd2e8f71d
|
7
|
+
data.tar.gz: 71719e23adfe9af22f347876540150b3435cd3226e5c7a409dc402368f5cc2879803341e2f213ab7f6fe920320eaec5feb1dbdde1a97fe122e4f2ea2b9281e49
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# 0.0.4
|
2
|
+
|
3
|
+
- Unscope the namespace of resourceful components
|
4
|
+
- Add field type :email
|
5
|
+
|
6
|
+
## Steps to take
|
7
|
+
|
8
|
+
- When inheriting from components, replace `Components::Resourceful::...` by `Components::...`
|
9
|
+
|
10
|
+
# 0.0.3
|
11
|
+
|
12
|
+
- Tolerate nil anchormodels
|
13
|
+
- Fix a nil pointer bug in namespace management
|
14
|
+
|
1
15
|
# 0.0.2
|
2
16
|
|
3
17
|
- Add new model field `Attachment`
|
data/compony.gemspec
CHANGED
@@ -2,31 +2,31 @@
|
|
2
2
|
# This file is auto-generated via: 'rake gemspec'.
|
3
3
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: compony 0.0.
|
5
|
+
# stub: compony 0.0.4 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "compony".freeze
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.4"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Sandro Kalbermatter".freeze, "contributors".freeze]
|
14
|
-
s.date = "
|
15
|
-
s.files = [".gitignore".freeze, ".ruby-version".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "Gemfile.lock".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "app/controllers/compony_controller.rb".freeze, "compony.gemspec".freeze, "config/locales/de.yml".freeze, "config/locales/en.yml".freeze, "config/routes.rb".freeze, "doc/resourceful_lifecycle.graphml".freeze, "doc/resourceful_lifecycle.pdf".freeze, "lib/compony.rb".freeze, "lib/compony/component.rb".freeze, "lib/compony/component_mixins/default/labelling.rb".freeze, "lib/compony/component_mixins/default/standalone.rb".freeze, "lib/compony/component_mixins/default/standalone/resourceful_verb_dsl.rb".freeze, "lib/compony/component_mixins/default/standalone/standalone_dsl.rb".freeze, "lib/compony/component_mixins/default/standalone/verb_dsl.rb".freeze, "lib/compony/component_mixins/resourceful.rb".freeze, "lib/compony/components/button.rb".freeze, "lib/compony/components/
|
14
|
+
s.date = "2023-05-28"
|
15
|
+
s.files = [".gitignore".freeze, ".ruby-version".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "Gemfile.lock".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "app/controllers/compony_controller.rb".freeze, "compony.gemspec".freeze, "config/locales/de.yml".freeze, "config/locales/en.yml".freeze, "config/routes.rb".freeze, "doc/resourceful_lifecycle.graphml".freeze, "doc/resourceful_lifecycle.pdf".freeze, "lib/compony.rb".freeze, "lib/compony/component.rb".freeze, "lib/compony/component_mixins/default/labelling.rb".freeze, "lib/compony/component_mixins/default/standalone.rb".freeze, "lib/compony/component_mixins/default/standalone/resourceful_verb_dsl.rb".freeze, "lib/compony/component_mixins/default/standalone/standalone_dsl.rb".freeze, "lib/compony/component_mixins/default/standalone/verb_dsl.rb".freeze, "lib/compony/component_mixins/resourceful.rb".freeze, "lib/compony/components/button.rb".freeze, "lib/compony/components/destroy.rb".freeze, "lib/compony/components/edit.rb".freeze, "lib/compony/components/form.rb".freeze, "lib/compony/components/new.rb".freeze, "lib/compony/components/with_form.rb".freeze, "lib/compony/controller_mixin.rb".freeze, "lib/compony/engine.rb".freeze, "lib/compony/method_accessible_hash.rb".freeze, "lib/compony/model_fields/anchormodel.rb".freeze, "lib/compony/model_fields/association.rb".freeze, "lib/compony/model_fields/attachment.rb".freeze, "lib/compony/model_fields/base.rb".freeze, "lib/compony/model_fields/boolean.rb".freeze, "lib/compony/model_fields/currency.rb".freeze, "lib/compony/model_fields/date.rb".freeze, "lib/compony/model_fields/datetime.rb".freeze, "lib/compony/model_fields/decimal.rb".freeze, "lib/compony/model_fields/email.rb".freeze, "lib/compony/model_fields/float.rb".freeze, "lib/compony/model_fields/integer.rb".freeze, "lib/compony/model_fields/phone.rb".freeze, "lib/compony/model_fields/rich_text.rb".freeze, "lib/compony/model_fields/string.rb".freeze, "lib/compony/model_fields/text.rb".freeze, "lib/compony/model_fields/time.rb".freeze, "lib/compony/model_mixin.rb".freeze, "lib/compony/request_context.rb".freeze, "lib/compony/version.rb".freeze, "lib/compony/view_helpers.rb".freeze, "lib/generators/component/USAGE".freeze, "lib/generators/component/component_generator.rb".freeze, "lib/generators/component/templates/component.rb.erb".freeze]
|
16
16
|
s.required_ruby_version = Gem::Requirement.new(">= 3.0.0".freeze)
|
17
|
-
s.rubygems_version = "3.
|
17
|
+
s.rubygems_version = "3.4.13".freeze
|
18
18
|
s.summary = "Needs summary".freeze
|
19
19
|
|
20
20
|
s.specification_version = 4
|
21
21
|
|
22
|
-
s.add_development_dependency(%q<yard>.freeze, [">= 0.9.28"
|
23
|
-
s.add_development_dependency(%q<rubocop>.freeze, [">= 1.48"
|
24
|
-
s.add_development_dependency(%q<rubocop-rails>.freeze, [">= 2.18.0"
|
25
|
-
s.add_runtime_dependency(%q<request_store>.freeze, [">= 1.5"
|
26
|
-
s.add_runtime_dependency(%q<dyny>.freeze, [">= 0.0.3"
|
27
|
-
s.add_runtime_dependency(%q<schemacop>.freeze, [">= 3.0.17"
|
28
|
-
s.add_runtime_dependency(%q<simple_form>.freeze, [">= 5.1.0"
|
29
|
-
s.add_runtime_dependency(%q<dslblend>.freeze, [">= 0.0.3"
|
30
|
-
s.add_runtime_dependency(%q<anchormodel>.freeze, ["~> 0.1.2"
|
31
|
-
s.add_runtime_dependency(%q<cancancan>.freeze, ["~> 3.4.0"
|
22
|
+
s.add_development_dependency(%q<yard>.freeze, [">= 0.9.28"])
|
23
|
+
s.add_development_dependency(%q<rubocop>.freeze, [">= 1.48"])
|
24
|
+
s.add_development_dependency(%q<rubocop-rails>.freeze, [">= 2.18.0"])
|
25
|
+
s.add_runtime_dependency(%q<request_store>.freeze, [">= 1.5"])
|
26
|
+
s.add_runtime_dependency(%q<dyny>.freeze, [">= 0.0.3"])
|
27
|
+
s.add_runtime_dependency(%q<schemacop>.freeze, [">= 3.0.17"])
|
28
|
+
s.add_runtime_dependency(%q<simple_form>.freeze, [">= 5.1.0"])
|
29
|
+
s.add_runtime_dependency(%q<dslblend>.freeze, [">= 0.0.3"])
|
30
|
+
s.add_runtime_dependency(%q<anchormodel>.freeze, ["~> 0.1.2"])
|
31
|
+
s.add_runtime_dependency(%q<cancancan>.freeze, ["~> 3.4.0"])
|
32
32
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Compony
|
2
|
+
module Components
|
3
|
+
# @api description
|
4
|
+
# This component is used for the Rails destroy paradigm. Asks for confirm when queried using GET.
|
5
|
+
class Destroy < Compony::Component
|
6
|
+
include Compony::ComponentMixins::Resourceful
|
7
|
+
|
8
|
+
setup do
|
9
|
+
standalone path: "#{family_name}/:id/destroy" do
|
10
|
+
verb :get do
|
11
|
+
authorize { can?(:destroy, @data) }
|
12
|
+
end
|
13
|
+
|
14
|
+
verb :delete do
|
15
|
+
authorize { can?(:destroy, @data) }
|
16
|
+
store_data # This enables the global store_data block defined below for this path and verb.
|
17
|
+
respond do
|
18
|
+
evaluate_with_backfire(&@on_destroyed_block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
label(:long) { |data| I18n.t('compony.components.destroy.label.long', data_label: data.label) }
|
24
|
+
label(:short) { |_| I18n.t('compony.components.destroy.label.short') }
|
25
|
+
icon { :trash }
|
26
|
+
color { :danger }
|
27
|
+
|
28
|
+
content do
|
29
|
+
div I18n.t('compony.components.destroy.confirm_question', data_label: @data.label)
|
30
|
+
div do
|
31
|
+
concat compony_button(comp_cst,
|
32
|
+
@data,
|
33
|
+
label: I18n.t('compony.components.destroy.confirm_button'),
|
34
|
+
method: :delete)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
store_data do
|
39
|
+
# Validate params against the form's schema
|
40
|
+
local_data = @data # Capture data for usage in the Schemacop call
|
41
|
+
schema = Schemacop::Schema3.new :hash, additional_properties: true do
|
42
|
+
if local_data.class.primary_key_type_key == :string
|
43
|
+
str! :id
|
44
|
+
else
|
45
|
+
int! :id, cast_str: true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
schema.validate!(controller.request.params)
|
49
|
+
|
50
|
+
# Perform destroy
|
51
|
+
@data.destroy!
|
52
|
+
end
|
53
|
+
|
54
|
+
on_destroyed do
|
55
|
+
flash.notice = I18n.t('compony.components.destroy.data_was_destroyed', data_label: @data.label)
|
56
|
+
redirect_to evaluate_with_backfire(&@on_destroyed_redirect_path_block), status: :see_other # 303: force GET
|
57
|
+
end
|
58
|
+
|
59
|
+
on_destroyed_redirect_path do
|
60
|
+
Compony.path(:index, family_cst)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# DSL method
|
65
|
+
def on_destroyed(&block)
|
66
|
+
@on_destroyed_block = block
|
67
|
+
end
|
68
|
+
|
69
|
+
# DSL method
|
70
|
+
def on_destroyed_redirect_path(&block)
|
71
|
+
@on_destroyed_redirect_path_block = block
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Compony
|
2
|
+
module Components
|
3
|
+
# @api description
|
4
|
+
# This component is used for the Rails edit and update paradigm. Performs update when the form is submitted.
|
5
|
+
class Edit < Compony::Components::WithForm
|
6
|
+
include Compony::ComponentMixins::Resourceful
|
7
|
+
setup do
|
8
|
+
submit_verb :patch
|
9
|
+
standalone path: "#{family_name}/:id/edit" do
|
10
|
+
verb :get do
|
11
|
+
authorize { can?(:edit, @data) }
|
12
|
+
assign_attributes # This enables the global assign_attributes block defined below for this path and verb.
|
13
|
+
end
|
14
|
+
verb submit_verb do
|
15
|
+
authorize { can?(:update, @data) }
|
16
|
+
assign_attributes # This enables the global assign_attributes block defined below for this path and verb.
|
17
|
+
store_data # This enables the global store_data block defined below for this path and verb.
|
18
|
+
respond do
|
19
|
+
if @update_succeeded
|
20
|
+
evaluate_with_backfire(&@on_updated_block)
|
21
|
+
else
|
22
|
+
evaluate_with_backfire(&@on_update_failed_block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
label(:long) { |data| I18n.t('compony.components.edit.label.long', data_label: data.label) }
|
29
|
+
label(:short) { |_| I18n.t('compony.components.edit.label.short') }
|
30
|
+
icon { :pencil }
|
31
|
+
|
32
|
+
content do
|
33
|
+
concat form_comp.render(controller, data: @data)
|
34
|
+
end
|
35
|
+
|
36
|
+
assign_attributes do
|
37
|
+
# Validate params against the form's schema
|
38
|
+
local_form_comp = form_comp # Capture form_comp for usage in the Schemacop call
|
39
|
+
local_data = @data # Capture data for usage in the Schemacop call
|
40
|
+
schema = Schemacop::Schema3.new :hash, additional_properties: true do
|
41
|
+
if local_data.class.primary_key_type_key == :string
|
42
|
+
str! :id
|
43
|
+
else
|
44
|
+
int! :id, cast_str: true
|
45
|
+
end
|
46
|
+
hsh? local_form_comp.schema_wrapper_key_for(local_data), &local_form_comp.schema_block_for(local_data)
|
47
|
+
end
|
48
|
+
schema.validate!(controller.request.params)
|
49
|
+
|
50
|
+
# TODO: Why are we not saving the validated params?
|
51
|
+
attrs_to_assign = controller.request.params[form_comp.schema_wrapper_key_for(@data)]
|
52
|
+
@data.assign_attributes(attrs_to_assign) if attrs_to_assign
|
53
|
+
end
|
54
|
+
|
55
|
+
store_data do
|
56
|
+
@update_succeeded = @data.save
|
57
|
+
end
|
58
|
+
|
59
|
+
on_updated do
|
60
|
+
flash.notice = I18n.t('compony.components.edit.data_was_updated', data_label: data.label)
|
61
|
+
redirect_to evaluate_with_backfire(&@on_updated_redirect_path_block)
|
62
|
+
end
|
63
|
+
|
64
|
+
on_updated_redirect_path do
|
65
|
+
if Compony.comp_class_for(:show, @data)
|
66
|
+
Compony.path(:show, @data)
|
67
|
+
else
|
68
|
+
Compony.path(:index, @data)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
on_update_failed do
|
73
|
+
Rails.logger.warn(@data&.errors&.full_messages)
|
74
|
+
render_standalone(controller, status: :unprocessable_entity)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# DSL method
|
79
|
+
def on_updated(&block)
|
80
|
+
@on_updated_block = block
|
81
|
+
end
|
82
|
+
|
83
|
+
# DSL method
|
84
|
+
def on_updated_redirect_path(&block)
|
85
|
+
@on_updated_redirect_path_block = block
|
86
|
+
end
|
87
|
+
|
88
|
+
# DSL method
|
89
|
+
def on_update_failed(&block)
|
90
|
+
@on_update_failed_block = block
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Compony
|
2
|
+
module Components
|
3
|
+
# @api description
|
4
|
+
# This component is used for the Rails new and create paradigm. Performs update when the form is submitted.
|
5
|
+
class New < Compony::Components::WithForm
|
6
|
+
include Compony::ComponentMixins::Resourceful
|
7
|
+
|
8
|
+
setup do
|
9
|
+
submit_verb :post
|
10
|
+
load_data { @data = data_class.new }
|
11
|
+
standalone path: "#{family_name}/new" do
|
12
|
+
verb :get do
|
13
|
+
authorize { can?(:create, data_class) }
|
14
|
+
assign_attributes # This enables the global assign_attributes block defined below for this path and verb.
|
15
|
+
end
|
16
|
+
verb submit_verb do
|
17
|
+
authorize { can?(:create, data_class) }
|
18
|
+
assign_attributes # This enables the global assign_attributes block defined below for this path and verb.
|
19
|
+
store_data # This enables the global store_data block defined below for this path and verb.
|
20
|
+
respond do
|
21
|
+
if @create_succeeded
|
22
|
+
evaluate_with_backfire(&@on_created_block)
|
23
|
+
else
|
24
|
+
evaluate_with_backfire(&@on_create_failed_block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
label(:long) { I18n.t('compony.components.new.label.long', data_class: data_class.model_name.human) }
|
31
|
+
label(:short) { I18n.t('compony.components.new.label.short') }
|
32
|
+
icon { :plus }
|
33
|
+
|
34
|
+
add_content do
|
35
|
+
h2 component.label
|
36
|
+
end
|
37
|
+
add_content do
|
38
|
+
concat form_comp.render(controller, data: @data)
|
39
|
+
end
|
40
|
+
|
41
|
+
assign_attributes do
|
42
|
+
local_form_comp = form_comp # Capture form_comp for usage in the Schemacop call
|
43
|
+
local_data = @data # Capture data for usage in the Schemacop call
|
44
|
+
schema = Schemacop::Schema3.new :hash, additional_properties: true do
|
45
|
+
hsh? local_form_comp.schema_wrapper_key_for(local_data), &local_form_comp.schema_block_for(local_data)
|
46
|
+
end
|
47
|
+
schema.validate!(controller.request.params)
|
48
|
+
|
49
|
+
# TODO: Why are we not saving the validated params?
|
50
|
+
attrs_to_assign = controller.request.params[form_comp.schema_wrapper_key_for(@data)]
|
51
|
+
@data.assign_attributes(attrs_to_assign) if attrs_to_assign
|
52
|
+
end
|
53
|
+
|
54
|
+
store_data do
|
55
|
+
@create_succeeded = @data.save
|
56
|
+
end
|
57
|
+
|
58
|
+
on_created do
|
59
|
+
flash.notice = I18n.t('compony.components.new.data_was_created', data_label: data.label)
|
60
|
+
redirect_to evaluate_with_backfire(&@on_created_redirect_path_block)
|
61
|
+
end
|
62
|
+
|
63
|
+
on_created_redirect_path do
|
64
|
+
if Compony.comp_class_for(:show, @data)
|
65
|
+
Compony.path(:show, @data)
|
66
|
+
else
|
67
|
+
Compony.path(:index, @data)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
on_create_failed do
|
72
|
+
Rails.logger.warn(@data&.errors&.full_messages)
|
73
|
+
render_standalone(controller, status: :unprocessable_entity)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# DSL method
|
78
|
+
def on_created(&block)
|
79
|
+
@on_created_block = block
|
80
|
+
end
|
81
|
+
|
82
|
+
# DSL method
|
83
|
+
def on_created_redirect_path(&block)
|
84
|
+
@on_created_redirect_path_block = block
|
85
|
+
end
|
86
|
+
|
87
|
+
# DSL method
|
88
|
+
def on_create_failed(&block)
|
89
|
+
@on_create_failed_block = block
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -7,7 +7,7 @@ module Compony
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def value_for(data, controller: nil, **_)
|
10
|
-
return transform_and_join(data.send(@name), controller
|
10
|
+
return transform_and_join(data.send(@name), controller:) { |el| el&.label }
|
11
11
|
end
|
12
12
|
|
13
13
|
def simpleform_input(form, _component, **input_opts)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Compony
|
2
|
+
module ModelFields
|
3
|
+
class Email < Base
|
4
|
+
def value_for(data, controller: nil, **_)
|
5
|
+
return transform_and_join(data.send(@name), controller:) do |el|
|
6
|
+
fail('Must pass controller to generate the link to the email.') unless controller
|
7
|
+
return controller.helpers.mail_to(data.send(@name))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/compony/version.rb
CHANGED
data/lib/compony.rb
CHANGED
@@ -220,7 +220,7 @@ module Compony
|
|
220
220
|
# Goes through model_field_namespaces and returns the first hit for the given constant
|
221
221
|
# @param constant [Constant] The constant that is searched, e.g. RichText -> would return e.g. Compony::ModelFields::RichText
|
222
222
|
def self.model_field_class_for(constant)
|
223
|
-
|
223
|
+
model_field_namespaces.each do |model_field_namespace|
|
224
224
|
model_field_namespace = model_field_namespace.constantize if model_field_namespace.is_a?(::String)
|
225
225
|
if model_field_namespace.const_defined?(constant, false)
|
226
226
|
return model_field_namespace.const_get(constant, false)
|
@@ -247,6 +247,7 @@ require 'compony/model_fields/currency'
|
|
247
247
|
require 'compony/model_fields/date'
|
248
248
|
require 'compony/model_fields/datetime'
|
249
249
|
require 'compony/model_fields/decimal'
|
250
|
+
require 'compony/model_fields/email'
|
250
251
|
require 'compony/model_fields/float'
|
251
252
|
require 'compony/model_fields/integer'
|
252
253
|
require 'compony/model_fields/phone'
|
@@ -264,9 +265,9 @@ require 'compony/component'
|
|
264
265
|
require 'compony/components/button'
|
265
266
|
require 'compony/components/form'
|
266
267
|
require 'compony/components/with_form'
|
267
|
-
require 'compony/components/
|
268
|
-
require 'compony/components/
|
269
|
-
require 'compony/components/
|
268
|
+
require 'compony/components/new'
|
269
|
+
require 'compony/components/edit'
|
270
|
+
require 'compony/components/destroy'
|
270
271
|
require 'compony/method_accessible_hash'
|
271
272
|
require 'compony/model_mixin'
|
272
273
|
require 'compony/request_context'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Kalbermatter
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|
@@ -182,10 +182,10 @@ files:
|
|
182
182
|
- lib/compony/component_mixins/default/standalone/verb_dsl.rb
|
183
183
|
- lib/compony/component_mixins/resourceful.rb
|
184
184
|
- lib/compony/components/button.rb
|
185
|
+
- lib/compony/components/destroy.rb
|
186
|
+
- lib/compony/components/edit.rb
|
185
187
|
- lib/compony/components/form.rb
|
186
|
-
- lib/compony/components/
|
187
|
-
- lib/compony/components/resourceful/edit.rb
|
188
|
-
- lib/compony/components/resourceful/new.rb
|
188
|
+
- lib/compony/components/new.rb
|
189
189
|
- lib/compony/components/with_form.rb
|
190
190
|
- lib/compony/controller_mixin.rb
|
191
191
|
- lib/compony/engine.rb
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- lib/compony/model_fields/date.rb
|
200
200
|
- lib/compony/model_fields/datetime.rb
|
201
201
|
- lib/compony/model_fields/decimal.rb
|
202
|
+
- lib/compony/model_fields/email.rb
|
202
203
|
- lib/compony/model_fields/float.rb
|
203
204
|
- lib/compony/model_fields/integer.rb
|
204
205
|
- lib/compony/model_fields/phone.rb
|
@@ -1,77 +0,0 @@
|
|
1
|
-
module Compony
|
2
|
-
module Components
|
3
|
-
module Resourceful
|
4
|
-
# @api description
|
5
|
-
# This component is used for the Rails destroy paradigm. Asks for confirm when queried using GET.
|
6
|
-
class Destroy < Compony::Component
|
7
|
-
include Compony::ComponentMixins::Resourceful
|
8
|
-
|
9
|
-
setup do
|
10
|
-
standalone path: "#{family_name}/:id/destroy" do
|
11
|
-
verb :get do
|
12
|
-
authorize { can?(:destroy, @data) }
|
13
|
-
end
|
14
|
-
|
15
|
-
verb :delete do
|
16
|
-
authorize { can?(:destroy, @data) }
|
17
|
-
store_data # This enables the global store_data block defined below for this path and verb.
|
18
|
-
respond do
|
19
|
-
evaluate_with_backfire(&@on_destroyed_block)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
label(:long) { |data| I18n.t('compony.components.destroy.label.long', data_label: data.label) }
|
25
|
-
label(:short) { |_| I18n.t('compony.components.destroy.label.short') }
|
26
|
-
icon { :trash }
|
27
|
-
color { :danger }
|
28
|
-
|
29
|
-
content do
|
30
|
-
div I18n.t('compony.components.destroy.confirm_question', data_label: @data.label)
|
31
|
-
div do
|
32
|
-
concat compony_button(comp_cst,
|
33
|
-
@data,
|
34
|
-
label: I18n.t('compony.components.destroy.confirm_button'),
|
35
|
-
method: :delete)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
store_data do
|
40
|
-
# Validate params against the form's schema
|
41
|
-
local_data = @data # Capture data for usage in the Schemacop call
|
42
|
-
schema = Schemacop::Schema3.new :hash, additional_properties: true do
|
43
|
-
if local_data.class.primary_key_type_key == :string
|
44
|
-
str! :id
|
45
|
-
else
|
46
|
-
int! :id, cast_str: true
|
47
|
-
end
|
48
|
-
end
|
49
|
-
schema.validate!(controller.request.params)
|
50
|
-
|
51
|
-
# Perform destroy
|
52
|
-
@data.destroy!
|
53
|
-
end
|
54
|
-
|
55
|
-
on_destroyed do
|
56
|
-
flash.notice = I18n.t('compony.components.destroy.data_was_destroyed', data_label: @data.label)
|
57
|
-
redirect_to evaluate_with_backfire(&@on_destroyed_redirect_path_block), status: :see_other # 303: force GET
|
58
|
-
end
|
59
|
-
|
60
|
-
on_destroyed_redirect_path do
|
61
|
-
Compony.path(:index, family_cst)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# DSL method
|
66
|
-
def on_destroyed(&block)
|
67
|
-
@on_destroyed_block = block
|
68
|
-
end
|
69
|
-
|
70
|
-
# DSL method
|
71
|
-
def on_destroyed_redirect_path(&block)
|
72
|
-
@on_destroyed_redirect_path_block = block
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
module Compony
|
2
|
-
module Components
|
3
|
-
module Resourceful
|
4
|
-
# @api description
|
5
|
-
# This component is used for the Rails edit and update paradigm. Performs update when the form is submitted.
|
6
|
-
class Edit < Compony::Components::WithForm
|
7
|
-
include Compony::ComponentMixins::Resourceful
|
8
|
-
setup do
|
9
|
-
submit_verb :patch
|
10
|
-
standalone path: "#{family_name}/:id/edit" do
|
11
|
-
verb :get do
|
12
|
-
authorize { can?(:edit, @data) }
|
13
|
-
assign_attributes # This enables the global assign_attributes block defined below for this path and verb.
|
14
|
-
end
|
15
|
-
verb submit_verb do
|
16
|
-
authorize { can?(:update, @data) }
|
17
|
-
assign_attributes # This enables the global assign_attributes block defined below for this path and verb.
|
18
|
-
store_data # This enables the global store_data block defined below for this path and verb.
|
19
|
-
respond do
|
20
|
-
if @update_succeeded
|
21
|
-
evaluate_with_backfire(&@on_updated_block)
|
22
|
-
else
|
23
|
-
evaluate_with_backfire(&@on_update_failed_block)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
label(:long) { |data| I18n.t('compony.components.edit.label.long', data_label: data.label) }
|
30
|
-
label(:short) { |_| I18n.t('compony.components.edit.label.short') }
|
31
|
-
icon { :pencil }
|
32
|
-
|
33
|
-
content do
|
34
|
-
concat form_comp.render(controller, data: @data)
|
35
|
-
end
|
36
|
-
|
37
|
-
assign_attributes do
|
38
|
-
# Validate params against the form's schema
|
39
|
-
local_form_comp = form_comp # Capture form_comp for usage in the Schemacop call
|
40
|
-
local_data = @data # Capture data for usage in the Schemacop call
|
41
|
-
schema = Schemacop::Schema3.new :hash, additional_properties: true do
|
42
|
-
if local_data.class.primary_key_type_key == :string
|
43
|
-
str! :id
|
44
|
-
else
|
45
|
-
int! :id, cast_str: true
|
46
|
-
end
|
47
|
-
hsh? local_form_comp.schema_wrapper_key_for(local_data), &local_form_comp.schema_block_for(local_data)
|
48
|
-
end
|
49
|
-
schema.validate!(controller.request.params)
|
50
|
-
|
51
|
-
# TODO: Why are we not saving the validated params?
|
52
|
-
attrs_to_assign = controller.request.params[form_comp.schema_wrapper_key_for(@data)]
|
53
|
-
@data.assign_attributes(attrs_to_assign) if attrs_to_assign
|
54
|
-
end
|
55
|
-
|
56
|
-
store_data do
|
57
|
-
@update_succeeded = @data.save
|
58
|
-
end
|
59
|
-
|
60
|
-
on_updated do
|
61
|
-
flash.notice = I18n.t('compony.components.edit.data_was_updated', data_label: data.label)
|
62
|
-
redirect_to evaluate_with_backfire(&@on_updated_redirect_path_block)
|
63
|
-
end
|
64
|
-
|
65
|
-
on_updated_redirect_path do
|
66
|
-
if Compony.comp_class_for(:show, @data)
|
67
|
-
Compony.path(:show, @data)
|
68
|
-
else
|
69
|
-
Compony.path(:index, @data)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
on_update_failed do
|
74
|
-
Rails.logger.warn(@data&.errors&.full_messages)
|
75
|
-
render_standalone(controller, status: :unprocessable_entity)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# DSL method
|
80
|
-
def on_updated(&block)
|
81
|
-
@on_updated_block = block
|
82
|
-
end
|
83
|
-
|
84
|
-
# DSL method
|
85
|
-
def on_updated_redirect_path(&block)
|
86
|
-
@on_updated_redirect_path_block = block
|
87
|
-
end
|
88
|
-
|
89
|
-
# DSL method
|
90
|
-
def on_update_failed(&block)
|
91
|
-
@on_update_failed_block = block
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
module Compony
|
2
|
-
module Components
|
3
|
-
module Resourceful
|
4
|
-
# @api description
|
5
|
-
# This component is used for the Rails new and create paradigm. Performs update when the form is submitted.
|
6
|
-
class New < Compony::Components::WithForm
|
7
|
-
include Compony::ComponentMixins::Resourceful
|
8
|
-
|
9
|
-
setup do
|
10
|
-
submit_verb :post
|
11
|
-
load_data { @data = data_class.new }
|
12
|
-
standalone path: "#{family_name}/new" do
|
13
|
-
verb :get do
|
14
|
-
authorize { can?(:create, data_class) }
|
15
|
-
assign_attributes # This enables the global assign_attributes block defined below for this path and verb.
|
16
|
-
end
|
17
|
-
verb submit_verb do
|
18
|
-
authorize { can?(:create, data_class) }
|
19
|
-
assign_attributes # This enables the global assign_attributes block defined below for this path and verb.
|
20
|
-
store_data # This enables the global store_data block defined below for this path and verb.
|
21
|
-
respond do
|
22
|
-
if @create_succeeded
|
23
|
-
evaluate_with_backfire(&@on_created_block)
|
24
|
-
else
|
25
|
-
evaluate_with_backfire(&@on_create_failed_block)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
label(:long) { I18n.t('compony.components.new.label.long', data_class: data_class.model_name.human) }
|
32
|
-
label(:short) { I18n.t('compony.components.new.label.short') }
|
33
|
-
icon { :plus }
|
34
|
-
|
35
|
-
add_content do
|
36
|
-
h2 component.label
|
37
|
-
end
|
38
|
-
add_content do
|
39
|
-
concat form_comp.render(controller, data: @data)
|
40
|
-
end
|
41
|
-
|
42
|
-
assign_attributes do
|
43
|
-
local_form_comp = form_comp # Capture form_comp for usage in the Schemacop call
|
44
|
-
local_data = @data # Capture data for usage in the Schemacop call
|
45
|
-
schema = Schemacop::Schema3.new :hash, additional_properties: true do
|
46
|
-
hsh? local_form_comp.schema_wrapper_key_for(local_data), &local_form_comp.schema_block_for(local_data)
|
47
|
-
end
|
48
|
-
schema.validate!(controller.request.params)
|
49
|
-
|
50
|
-
# TODO: Why are we not saving the validated params?
|
51
|
-
attrs_to_assign = controller.request.params[form_comp.schema_wrapper_key_for(@data)]
|
52
|
-
@data.assign_attributes(attrs_to_assign) if attrs_to_assign
|
53
|
-
end
|
54
|
-
|
55
|
-
store_data do
|
56
|
-
@create_succeeded = @data.save
|
57
|
-
end
|
58
|
-
|
59
|
-
on_created do
|
60
|
-
flash.notice = I18n.t('compony.components.new.data_was_created', data_label: data.label)
|
61
|
-
redirect_to evaluate_with_backfire(&@on_created_redirect_path_block)
|
62
|
-
end
|
63
|
-
|
64
|
-
on_created_redirect_path do
|
65
|
-
if Compony.comp_class_for(:show, @data)
|
66
|
-
Compony.path(:show, @data)
|
67
|
-
else
|
68
|
-
Compony.path(:index, @data)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
on_create_failed do
|
73
|
-
Rails.logger.warn(@data&.errors&.full_messages)
|
74
|
-
render_standalone(controller, status: :unprocessable_entity)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# DSL method
|
79
|
-
def on_created(&block)
|
80
|
-
@on_created_block = block
|
81
|
-
end
|
82
|
-
|
83
|
-
# DSL method
|
84
|
-
def on_created_redirect_path(&block)
|
85
|
-
@on_created_redirect_path_block = block
|
86
|
-
end
|
87
|
-
|
88
|
-
# DSL method
|
89
|
-
def on_create_failed(&block)
|
90
|
-
@on_create_failed_block = block
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|