linked_rails 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/linked_rails/bulk_controller.rb +26 -6
  3. data/app/controllers/linked_rails/enum_values_controller.rb +0 -42
  4. data/app/models/linked_rails/actions/item.rb +46 -30
  5. data/app/models/linked_rails/actions/list.rb +6 -25
  6. data/app/models/linked_rails/collection/configuration.rb +55 -0
  7. data/app/models/linked_rails/collection/filter.rb +1 -1
  8. data/app/models/linked_rails/collection/filter_field.rb +5 -1
  9. data/app/models/linked_rails/collection/filter_option.rb +1 -1
  10. data/app/models/linked_rails/collection/filterable.rb +3 -8
  11. data/app/models/linked_rails/collection/infinite.rb +102 -0
  12. data/app/models/linked_rails/collection/infinite_view.rb +1 -90
  13. data/app/models/linked_rails/collection/iri.rb +33 -52
  14. data/app/models/linked_rails/collection/iri_mapping.rb +14 -6
  15. data/app/models/linked_rails/collection/paginated.rb +45 -0
  16. data/app/models/linked_rails/collection/paginated_view.rb +1 -33
  17. data/app/models/linked_rails/collection/sortable.rb +1 -9
  18. data/app/models/linked_rails/collection/sorting.rb +1 -1
  19. data/app/models/linked_rails/collection/view.rb +15 -5
  20. data/app/models/linked_rails/collection.rb +33 -67
  21. data/app/models/linked_rails/creative_work.rb +1 -1
  22. data/app/models/linked_rails/entry_point.rb +8 -5
  23. data/app/models/linked_rails/enum_value.rb +39 -1
  24. data/app/models/linked_rails/form/field/resource_field.rb +2 -0
  25. data/app/models/linked_rails/form/field.rb +6 -8
  26. data/app/models/linked_rails/form/field_factory.rb +21 -10
  27. data/app/models/linked_rails/form/group.rb +2 -2
  28. data/app/models/linked_rails/form/page.rb +4 -4
  29. data/app/models/linked_rails/form.rb +13 -15
  30. data/app/models/linked_rails/manifest.rb +8 -2
  31. data/app/models/linked_rails/menus/item.rb +1 -1
  32. data/app/models/linked_rails/menus/list.rb +3 -2
  33. data/app/models/linked_rails/ontology/base.rb +1 -1
  34. data/app/models/linked_rails/ontology/class.rb +3 -3
  35. data/app/models/linked_rails/ontology.rb +5 -5
  36. data/app/models/linked_rails/sequence.rb +2 -2
  37. data/app/models/linked_rails/shacl/property_shape.rb +1 -1
  38. data/app/models/linked_rails/widget.rb +1 -1
  39. data/app/serializers/linked_rails/actions/item_serializer.rb +2 -1
  40. data/app/serializers/linked_rails/collection_serializer.rb +7 -2
  41. data/app/serializers/linked_rails/entry_point_serializer.rb +1 -1
  42. data/app/serializers/linked_rails/ontology_serializer.rb +2 -2
  43. data/lib/generators/linked_rails/install/install_generator.rb +5 -8
  44. data/lib/generators/linked_rails/install/templates/README +2 -0
  45. data/lib/generators/linked_rails/install/templates/app_menu_list.rb +36 -7
  46. data/lib/generators/linked_rails/install/templates/application_menu_list.rb +40 -1
  47. data/lib/generators/linked_rails/install/templates/initializer.rb +1 -2
  48. data/lib/generators/linked_rails/install/templates/locales.yml +12 -0
  49. data/lib/generators/linked_rails/install/templates/vocab.rb +1 -0
  50. data/lib/generators/linked_rails/install/templates/vocab.yml +2 -2
  51. data/lib/generators/linked_rails/model/model_generator.rb +0 -1
  52. data/lib/generators/linked_rails/model/templates/controller.rb.tt +5 -1
  53. data/lib/generators/linked_rails/model/templates/form.rb.tt +3 -0
  54. data/lib/generators/linked_rails/model/templates/menu_list.rb.tt +15 -0
  55. data/lib/generators/linked_rails/model/templates/policy.rb.tt +13 -0
  56. data/lib/generators/linked_rails/model/templates/serializer.rb.tt +1 -1
  57. data/lib/linked_rails/active_response/controller/collections.rb +1 -1
  58. data/lib/linked_rails/active_response/controller/crud_defaults.rb +3 -3
  59. data/lib/linked_rails/active_response/controller/params.rb +5 -5
  60. data/lib/linked_rails/active_response/controller.rb +11 -0
  61. data/lib/linked_rails/active_response/responders/rdf.rb +19 -10
  62. data/lib/linked_rails/callable_variable.rb +1 -1
  63. data/lib/linked_rails/collection_params_parser.rb +93 -0
  64. data/lib/linked_rails/controller/actionable.rb +118 -0
  65. data/lib/linked_rails/controller/authorization.rb +6 -0
  66. data/lib/linked_rails/controller/default_actions/create.rb +52 -0
  67. data/lib/linked_rails/controller/default_actions/destroy.rb +42 -0
  68. data/lib/linked_rails/controller/default_actions/update.rb +43 -0
  69. data/lib/linked_rails/controller.rb +20 -3
  70. data/lib/linked_rails/enhancements/creatable/controller.rb +1 -1
  71. data/lib/linked_rails/enhancements/destroyable/controller.rb +1 -1
  72. data/lib/linked_rails/enhancements/updatable/controller.rb +1 -1
  73. data/lib/linked_rails/enhancements.rb +0 -16
  74. data/lib/linked_rails/helpers/delta_helper.rb +26 -3
  75. data/lib/linked_rails/helpers/ontola_actions_helper.rb +2 -2
  76. data/lib/linked_rails/helpers/resource_helper.rb +1 -1
  77. data/lib/linked_rails/iri_mapper.rb +17 -39
  78. data/lib/linked_rails/middleware/linked_data_params.rb +7 -127
  79. data/lib/linked_rails/model/actionable.rb +69 -0
  80. data/lib/linked_rails/model/collections.rb +195 -39
  81. data/lib/linked_rails/model/dirty.rb +1 -1
  82. data/lib/linked_rails/model/enhancements.rb +1 -6
  83. data/lib/linked_rails/model/filtering.rb +2 -4
  84. data/lib/linked_rails/model/indexable.rb +5 -15
  85. data/lib/linked_rails/model/iri.rb +15 -17
  86. data/lib/linked_rails/model/iri_mapping.rb +35 -6
  87. data/lib/linked_rails/model/menuable.rb +34 -0
  88. data/lib/linked_rails/model/serialization.rb +0 -9
  89. data/lib/linked_rails/model/singularable.rb +55 -0
  90. data/lib/linked_rails/model/sorting.rb +0 -5
  91. data/lib/linked_rails/model/tables.rb +26 -0
  92. data/lib/linked_rails/model.rb +13 -5
  93. data/lib/linked_rails/params_parser.rb +131 -55
  94. data/lib/linked_rails/policy/attribute_conditions.rb +2 -2
  95. data/lib/linked_rails/policy.rb +24 -17
  96. data/lib/linked_rails/rdf_error.rb +2 -2
  97. data/lib/linked_rails/routes.rb +37 -22
  98. data/lib/linked_rails/serializer/actionable.rb +27 -0
  99. data/lib/linked_rails/serializer/menuable.rb +31 -0
  100. data/lib/linked_rails/serializer/singularable.rb +26 -0
  101. data/lib/linked_rails/serializer.rb +23 -10
  102. data/lib/linked_rails/test_methods.rb +114 -0
  103. data/lib/linked_rails/translate.rb +19 -9
  104. data/lib/linked_rails/uri_template.rb +30 -0
  105. data/lib/linked_rails/version.rb +1 -1
  106. data/lib/linked_rails/vocab.rb +8 -0
  107. data/lib/linked_rails.rb +25 -12
  108. data/lib/rails/welcome_controller.rb +3 -3
  109. data/lib/rdf/query_fix.rb +15 -0
  110. metadata +22 -25
  111. data/app/models/linked_rails/actions/default_actions/create.rb +0 -60
  112. data/app/models/linked_rails/actions/default_actions/destroy.rb +0 -45
  113. data/app/models/linked_rails/actions/default_actions/update.rb +0 -50
  114. data/app/models/linked_rails/actions/default_actions.rb +0 -17
  115. data/lib/generators/linked_rails/install/templates/application_action_list.rb +0 -3
  116. data/lib/generators/linked_rails/model/templates/action_list.rb.tt +0 -6
  117. data/lib/linked_rails/enhancements/actionable/model.rb +0 -71
  118. data/lib/linked_rails/enhancements/actionable/serializer.rb +0 -25
  119. data/lib/linked_rails/enhancements/creatable/action.rb +0 -15
  120. data/lib/linked_rails/enhancements/destroyable/action.rb +0 -15
  121. data/lib/linked_rails/enhancements/destroyable/routing.rb +0 -19
  122. data/lib/linked_rails/enhancements/indexable/model.rb +0 -10
  123. data/lib/linked_rails/enhancements/menuable/model.rb +0 -36
  124. data/lib/linked_rails/enhancements/menuable/serializer.rb +0 -33
  125. data/lib/linked_rails/enhancements/route_concerns.rb +0 -56
  126. data/lib/linked_rails/enhancements/singularable/controller.rb +0 -43
  127. data/lib/linked_rails/enhancements/singularable/model.rb +0 -47
  128. data/lib/linked_rails/enhancements/singularable/serializer.rb +0 -28
  129. data/lib/linked_rails/enhancements/tableable/model.rb +0 -28
  130. data/lib/linked_rails/enhancements/updatable/action.rb +0 -15
  131. data/lib/linked_rails/enhancements/updatable/routing.rb +0 -20
@@ -3,6 +3,11 @@
3
3
  module LinkedRails
4
4
  class Form
5
5
  class FieldFactory # rubocop:disable Metrics/ClassLength
6
+ DATABASE_ERRORS = [
7
+ 'PG::ConnectionBad'.safe_constantize,
8
+ ActiveRecord::StatementInvalid,
9
+ ActiveRecord::ConnectionNotEstablished
10
+ ].compact.freeze
6
11
  MAX_STR_LEN = 255
7
12
  VALIDATOR_SELECTORS = [
8
13
  [:min_length, ActiveModel::Validations::LengthValidator, :minimum],
@@ -15,7 +20,8 @@ module LinkedRails
15
20
 
16
21
  attr_accessor :field_options, :form, :key
17
22
 
18
- delegate :form_options_iri,
23
+ delegate :abstract_form,
24
+ :form_options_iri,
19
25
  :model_class,
20
26
  :model_policy!,
21
27
  :serializer_attributes,
@@ -24,6 +30,8 @@ module LinkedRails
24
30
  to: :form
25
31
 
26
32
  def condition_or_field
33
+ return field if abstract_form
34
+
27
35
  @condition_or_field ||= model_policy!.condition_for(
28
36
  key,
29
37
  field,
@@ -45,8 +53,7 @@ module LinkedRails
45
53
  end
46
54
 
47
55
  def attr_to_datatype # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
48
- name = serializer_attribute&.key&.to_s || key.to_s
49
- case attribute_type(name)
56
+ case attribute_type
50
57
  when :string, :text
51
58
  Vocab.xsd.string
52
59
  when :integer
@@ -58,22 +65,26 @@ module LinkedRails
58
65
  when :boolean
59
66
  Vocab.xsd.boolean
60
67
  when :decimal
61
- decimal_data_type(name)
68
+ decimal_data_type(attribute_name)
62
69
  when :file
63
70
  Vocab.ll[:blob]
64
71
  else
65
- Vocab.xsd.string if model_class.try(:defined_enums)&.key?(name)
72
+ Vocab.xsd.string if model_class.try(:defined_enums)&.key?(attribute_name)
66
73
  end
67
74
  end
68
75
 
69
- def attribute_type(name)
70
- model_class.try(:attribute_types).try(:[], name)&.type
71
- rescue PG::ConnectionBad, ActiveRecord::StatementInvalid, ActiveRecord::ConnectionNotEstablished
76
+ def attribute_name
77
+ serializer_attribute&.key&.to_s || key.to_s
78
+ end
79
+
80
+ def attribute_type
81
+ model_class.try(:attribute_types).try(:[], attribute_name)&.type
82
+ rescue *DATABASE_ERRORS
72
83
  :string
73
84
  end
74
85
 
75
86
  def attribute_validators
76
- @attribute_validators ||= model_class.validators.select { |v| v.attributes.include?(model_attribute) }
87
+ @attribute_validators ||= model_class&.validators&.select { |v| v.attributes.include?(model_attribute) }
77
88
  end
78
89
 
79
90
  def datatype
@@ -143,7 +154,7 @@ module LinkedRails
143
154
  when Vocab.ontola['datatype/postalRange']
144
155
  return Form::Field::PostalRangeInput
145
156
  else
146
- max_length && max_length > MAX_STR_LEN ? Form::Field::TextAreaInput : Form::Field::TextInput
157
+ attribute_type == :text ? Form::Field::TextAreaInput : Form::Field::TextInput
147
158
  end
148
159
  end
149
160
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
@@ -6,8 +6,8 @@ module LinkedRails
6
6
  attr_accessor :fields, :collapsible, :hidden, :footer
7
7
  attr_writer :description, :key, :label
8
8
 
9
- def initialize(attrs = {})
10
- super(attrs)
9
+ def initialize(**attrs)
10
+ super(**attrs)
11
11
  self.fields = []
12
12
  end
13
13
 
@@ -6,13 +6,13 @@ module LinkedRails
6
6
  attr_accessor :groups, :label, :description
7
7
  attr_writer :key
8
8
 
9
- def initialize(attrs = {})
10
- super(attrs)
9
+ def initialize(**attrs)
10
+ super(**attrs)
11
11
  self.groups = []
12
12
  end
13
13
 
14
- def add_group(opts)
15
- group = Form::Group.new(opts)
14
+ def add_group(**opts)
15
+ group = Form::Group.new(**opts)
16
16
  groups << group
17
17
  group
18
18
  end
@@ -6,9 +6,9 @@ module LinkedRails
6
6
  class Form # rubocop:disable Metrics/ClassLength
7
7
  include LinkedRails::Model
8
8
 
9
- class_attribute :pages, :model_class
9
+ class_attribute :abstract_form, :pages, :model_class
10
10
 
11
- def root_relative_iri(_opts = {})
11
+ def root_relative_iri(**_opts)
12
12
  self.class.form_iri_path
13
13
  end
14
14
 
@@ -85,7 +85,7 @@ module LinkedRails
85
85
  @default_page ||= page(:default)
86
86
  end
87
87
 
88
- def field(key, opts = {})
88
+ def field(key, **opts)
89
89
  current_group.fields << Form::FieldFactory.new(
90
90
  field_options: opts,
91
91
  form: self,
@@ -108,10 +108,10 @@ module LinkedRails
108
108
  current_page.footer_group
109
109
  end
110
110
 
111
- def group(key, opts = {})
111
+ def group(key, **opts)
112
112
  opts[:collapsible] = true unless opts.key?(:collapsible)
113
113
  opts[:key] = key
114
- group = current_page.add_group(opts)
114
+ group = current_page.add_group(**opts)
115
115
  @current_group = group
116
116
 
117
117
  yield if block_given?
@@ -120,26 +120,24 @@ module LinkedRails
120
120
  group
121
121
  end
122
122
 
123
- # rubocop:disable Naming/PredicateName
124
- def has_many(key, opts = {})
123
+ def has_many(key, **opts)
125
124
  opts[:input_field] = Form::Field::AssociationInput
126
125
  opts[:max_count] = 99
127
- field(key, opts)
126
+ field(key, **opts)
128
127
  end
129
128
 
130
- def has_one(key, opts = {})
129
+ def has_one(key, **opts)
131
130
  opts[:input_field] = Form::Field::AssociationInput
132
131
  opts[:max_count] = 1
133
- field(key, opts)
132
+ field(key, **opts)
134
133
  end
135
- # rubocop:enable Naming/PredicateName
136
134
 
137
135
  def hidden(&block)
138
136
  group(:hidden, collapsible: false, hidden: true, &block)
139
137
  end
140
138
 
141
- def page(key, opts = {})
142
- page = Form::Page.new(opts.merge(key: key))
139
+ def page(key, **opts)
140
+ page = Form::Page.new(**opts.merge(key: key))
143
141
  @current_page = page
144
142
  pages << @current_page
145
143
  yield if block_given?
@@ -147,9 +145,9 @@ module LinkedRails
147
145
  page
148
146
  end
149
147
 
150
- def resource(key, opts = {})
148
+ def resource(key, **opts)
151
149
  opts[:input_field] = Form::Field::ResourceField
152
- field(key, opts)
150
+ field(key, **opts)
153
151
  end
154
152
  end
155
153
  end
@@ -79,7 +79,7 @@ module LinkedRails
79
79
  }
80
80
  end
81
81
 
82
- def web_manifest_ontola_section
82
+ def web_manifest_ontola_section # rubocop:disable Metrics/MethodLength
83
83
  {
84
84
  css_class: css_class,
85
85
  header_background: header_background,
@@ -88,7 +88,9 @@ module LinkedRails
88
88
  primary_color: site_theme_color,
89
89
  secondary_color: site_secondary_color,
90
90
  theme: theme,
91
- theme_options: theme_options.to_query
91
+ theme_options: theme_options.to_query,
92
+ website_iri: LinkedRails.iri.to_s,
93
+ websocket_path: websocket_path
92
94
  }
93
95
  end
94
96
 
@@ -98,5 +100,9 @@ module LinkedRails
98
100
  scope: scope
99
101
  }
100
102
  end
103
+
104
+ def websocket_path
105
+ Rails.application.config.try(:action_cable).try(:mount_path).try(:[], 1..-1)
106
+ end
101
107
  end
102
108
  end
@@ -26,7 +26,7 @@ module LinkedRails
26
26
  def iri_template
27
27
  return parent.send(:iri_template) unless parent.is_a?(LinkedRails::Menus::List)
28
28
 
29
- return URITemplate.new("#{iri_base}{/tag}{#fragment}") if iri_base
29
+ return LinkedRails::URITemplate.new("#{iri_base}{/tag}{#fragment}") if iri_base
30
30
 
31
31
  iri_template_expand_path(parent.send(:iri_template), '{/tag}')
32
32
  end
@@ -34,7 +34,7 @@ module LinkedRails
34
34
  private
35
35
 
36
36
  def default_label(tag, options)
37
- I18n.t("menus.#{resource&.class&.name&.tableize}.#{tag}", options[:label_params])
37
+ I18n.t("menus.#{resource&.class&.name&.tableize}.#{tag}", **options[:label_params])
38
38
  end
39
39
 
40
40
  def menu_available?(_tag, options)
@@ -48,6 +48,7 @@ module LinkedRails
48
48
  options[:label_params] ||= {}
49
49
  options[:label_params][:default] ||= ["menus.default.#{tag}".to_sym, tag.to_s.capitalize]
50
50
  options[:label] ||= default_label(tag, options)
51
+ options[:action] = ontola_dialog_action(options[:href]) if options.delete(:dialog)
51
52
  options.except!(:policy_resource, :policy, :policy_arguments, :label_params)
52
53
  LinkedRails.menus_item_class.new(resource: resource, tag: tag, parent: self, **options)
53
54
  end
@@ -88,7 +89,7 @@ module LinkedRails
88
89
  _defined_menus || {}
89
90
  end
90
91
 
91
- def has_menu(tag, opts = {}) # rubocop:disable Naming/PredicateName
92
+ def has_menu(tag, **opts)
92
93
  defined_menus[tag] = opts
93
94
  end
94
95
 
@@ -9,7 +9,7 @@ module LinkedRails
9
9
 
10
10
  def data
11
11
  data = []
12
- iri.each_statement do |statement|
12
+ iri.try(:each_statement) do |statement|
13
13
  next unless include_data_statement?(statement)
14
14
 
15
15
  statement.graph_name = ::RDF::Serializers.config.default_graph
@@ -12,10 +12,10 @@ module LinkedRails
12
12
  end
13
13
 
14
14
  def parent_class
15
- if klass.superclass == ApplicationRecord
15
+ if klass&.superclass == ApplicationRecord
16
16
  Vocab.schema.Thing
17
17
  else
18
- klass.superclass.iri
18
+ klass&.superclass.try(:iri) || Vocab.schema.Thing
19
19
  end
20
20
  end
21
21
 
@@ -26,7 +26,7 @@ module LinkedRails
26
26
  end
27
27
 
28
28
  def properties
29
- @properties ||= klass.predicate_mapping.keys.map { |key| LinkedRails.ontology_property_class.new(iri: key) }
29
+ @properties ||= klass&.predicate_mapping&.keys&.map { |key| LinkedRails.ontology_property_class.new(iri: key) }
30
30
  end
31
31
 
32
32
  class << self
@@ -6,11 +6,11 @@ module LinkedRails
6
6
  include LinkedRails::Model
7
7
 
8
8
  def classes
9
- @classes ||= ApplicationRecord.descendants.map do |klass|
9
+ @classes ||= LinkedRails.linked_models.map do |klass|
10
10
  iri = klass.iri.is_a?(Array) ? klass.iri.first : klass.iri
11
11
 
12
- LinkedRails.ontology_class_class.new(klass: klass, iri: iri)
13
- end
12
+ LinkedRails.ontology_class_class.new(klass: klass, iri: iri) if iri
13
+ end.compact
14
14
  end
15
15
 
16
16
  def properties
@@ -26,8 +26,8 @@ module LinkedRails
26
26
  %i[classes properties]
27
27
  end
28
28
 
29
- def requested_resource(_opts, _user_context)
30
- LinkedRails.ontology_class.new
29
+ def requested_resource(opts, _user_context)
30
+ LinkedRails.ontology_class.new if opts[:iri].include?(new.root_relative_iri)
31
31
  end
32
32
  end
33
33
  end
@@ -5,7 +5,7 @@ module LinkedRails
5
5
  attr_accessor :node, :member_includes, :parent, :raw_members, :scope, :user_context
6
6
  alias read_attribute_for_serialization send
7
7
 
8
- def initialize(members, opts = {})
8
+ def initialize(members, **opts)
9
9
  self.member_includes = opts[:member_includes]
10
10
  self.node = opts[:id] || RDF::Node.new
11
11
  self.parent = opts[:parent]
@@ -14,7 +14,7 @@ module LinkedRails
14
14
  self.user_context = opts[:user_context]
15
15
  end
16
16
 
17
- def iri(_opts = {})
17
+ def iri(**_opts)
18
18
  node
19
19
  end
20
20
  alias id iri
@@ -35,7 +35,7 @@ module LinkedRails
35
35
  )
36
36
  attr_writer :has_value, :sh_in
37
37
 
38
- def has_value # rubocop:disable Naming/PredicateName
38
+ def has_value
39
39
  @has_value.respond_to?(:call) ? @has_value.call : @has_value
40
40
  end
41
41
 
@@ -8,7 +8,7 @@ module LinkedRails
8
8
  attr_writer :resources, :size
9
9
  attr_accessor :parent, :topology
10
10
 
11
- def iri(_opts = {})
11
+ def iri(**_opts)
12
12
  @iri ||= RDF::Node.new
13
13
  end
14
14
 
@@ -12,7 +12,8 @@ module LinkedRails
12
12
  end
13
13
  attribute :action_status, predicate: Vocab.schema.actionStatus
14
14
  attribute :favorite, predicate: Vocab.ontola[:favoriteAction]
15
- attribute :url, predicate: Vocab.schema.url do |object|
15
+ attribute :one_click, predicate: Vocab.ontola[:oneClick]
16
+ attribute :target_url, predicate: Vocab.schema.url do |object|
16
17
  object.target[:id] if object.target.is_a?(Hash)
17
18
  end
18
19
  attribute :error, predicate: Vocab.schema.error
@@ -11,8 +11,13 @@ module LinkedRails
11
11
  attribute :total_count, predicate: Vocab.as.totalItems do |object|
12
12
  object.total_count if object.type == :paginated
13
13
  end
14
- attribute :iri_template, predicate: Vocab.ontola[:iriTemplate]
15
- attribute :iri_template_opts, predicate: Vocab.ontola[:iriTemplateOpts]
14
+ attribute :iri_template, predicate: Vocab.ontola[:iriTemplate] do |object|
15
+ object
16
+ .iri_template
17
+ .to_s
18
+ .gsub('{route_key}', object.route_key.to_s)
19
+ .gsub('{/parent_iri*}', object.parent&.iri&.to_s&.split('?')&.first || LinkedRails.iri)
20
+ end
16
21
  attribute :default_type, predicate: Vocab.ontola[:defaultType], &:type
17
22
  attribute :display, predicate: Vocab.ontola[:collectionDisplay] do |object|
18
23
  Vocab.ontola["collectionDisplay/#{object.display || :default}"]
@@ -6,7 +6,7 @@ module LinkedRails
6
6
 
7
7
  attribute :label, predicate: Vocab.schema.name
8
8
  attribute :description, predicate: Vocab.schema.text
9
- attribute :url, predicate: Vocab.schema.url
9
+ attribute :target_url, predicate: Vocab.schema.url
10
10
  attribute :http_method, key: :method, predicate: Vocab.schema.httpMethod do |object|
11
11
  object.http_method.upcase
12
12
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module LinkedRails
4
4
  class OntologySerializer < LinkedRails.serializer_parent_class
5
- has_many :classes
6
- has_many :properties
5
+ has_many :classes, serializer: LinkedRails::Ontology::ClassSerializer
6
+ has_many :properties, serializer: LinkedRails::Ontology::PropertySerializer
7
7
  end
8
8
  end
@@ -12,7 +12,6 @@ module LinkedRails
12
12
  def install # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
13
13
  template 'vocab.rb', 'lib/vocab.rb'
14
14
  template 'initializer.rb', 'config/initializers/linked_rails.rb'
15
- template 'application_action_list.rb', 'app/actions/application_action_list.rb'
16
15
  template 'application_form.rb', 'app/forms/application_form.rb'
17
16
  template 'application_menu_list.rb', 'app/menus/application_menu_list.rb'
18
17
  template 'application_policy.rb', 'app/policies/application_policy.rb'
@@ -22,9 +21,12 @@ module LinkedRails
22
21
  template 'rdf_serializers_initializer.rb', 'config/initializers/rdf_serializers.rb'
23
22
  template 'locales.yml', 'config/locales/linked_rails.en.yml'
24
23
  template 'vocab.yml', 'config/locales/vocab.en.yml'
24
+ route 'find_tenant_route'
25
25
  route 'use_linked_rails'
26
26
  application 'config.middleware.use LinkedRails::Middleware::LinkedDataParams'
27
27
  application 'config.jwt_encryption_method = :hs512'
28
+ gsub_file('config/environments/development.rb', 'config.eager_load = false', 'config.eager_load = true')
29
+ gsub_file('config/environments/development.rb', 'config.cache_classes = false', 'config.cache_classes = true')
28
30
  inject_includes
29
31
 
30
32
  readme 'README'
@@ -37,17 +39,12 @@ module LinkedRails
37
39
  inject_model_include
38
40
  end
39
41
 
40
- def inject_controller_include# rubocop:disable Metrics/MethodLength
42
+ def inject_controller_include
41
43
  sentinel = /class ApplicationController < ActionController::API\n/m
42
44
  in_root do
43
45
  inject_into_file(
44
46
  'app/controllers/application_controller.rb',
45
- optimize_indentation(
46
- "include ActionController::MimeResponds\n"\
47
- "include ActiveResponse::Controller\n"\
48
- 'include LinkedRails::Controller',
49
- 2
50
- ),
47
+ optimize_indentation('include LinkedRails::Controller', 2),
51
48
  after: sentinel
52
49
  )
53
50
  end
@@ -2,4 +2,6 @@ Add the following to config/development.rb
2
2
  config.hosts = []
3
3
  config.hosts << 'localhost'
4
4
  config.hosts << '.svc.cluster.local'
5
+ config.hosts << [YOUR_LOCAL_HOSTNAME]
5
6
 
7
+ And update the host in config/initializers/linked_rails.rb
@@ -8,29 +8,58 @@ class AppMenuList < ApplicationMenuList
8
8
  menus: -> { user_menu_items }
9
9
 
10
10
  def iri_template
11
- @iri_template ||= URITemplate.new('/menus{#fragment}')
11
+ @iri_template ||= LinkedRails::URITemplate.new('/menus{#fragment}')
12
12
  end
13
13
 
14
14
  private
15
15
 
16
- def navigation_links
17
- items = []
18
- items << menu_item(
16
+ def home_menu_item
17
+ menu_item(
19
18
  :home,
20
19
  label: I18n.t('menus.home'),
21
20
  href: LinkedRails.iri,
22
21
  image: 'fa-home'
23
22
  )
24
- items
23
+ end
24
+
25
+ def navigation_links
26
+ [home_menu_item]
25
27
  end
26
28
 
27
29
  def user_menu_items
28
30
  return [] if user_context.guest?
29
31
 
30
- [user_menu_sign_out_item]
32
+ [
33
+ otp_menu_item,
34
+ sign_out_menu_item
35
+ ]
36
+ end
37
+
38
+ def otp_menu_item
39
+ if user_context.otp_active?
40
+ delete_otp_menu_item
41
+ else
42
+ add_otp_menu_item
43
+ end
44
+ end
45
+
46
+ def delete_otp_menu_item
47
+ menu_item(
48
+ :otp,
49
+ label: I18n.t('menus.delete_otp'),
50
+ href: LinkedRails.iri(path: 'u/otp_secret/delete')
51
+ )
52
+ end
53
+
54
+ def add_otp_menu_item
55
+ menu_item(
56
+ :otp,
57
+ label: I18n.t('menus.add_otp'),
58
+ href: LinkedRails.iri(path: 'u/otp_secret/new')
59
+ )
31
60
  end
32
61
 
33
- def user_menu_sign_out_item
62
+ def sign_out_menu_item
34
63
  menu_item(
35
64
  :signout,
36
65
  action: Vocab.libro['actions/logout'],
@@ -1,3 +1,42 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class ApplicationMenuList < LinkedRails::Menus::List; end
3
+ class ApplicationMenuList < LinkedRails::Menus::List
4
+ include LinkedRails::Helpers::OntolaActionsHelper
5
+
6
+ private
7
+
8
+ def copy_menu_item(url)
9
+ menu_item(
10
+ :copy,
11
+ action: ontola_copy_action(url),
12
+ item_type: 'copy',
13
+ image: 'fa-clipboard',
14
+ href: url
15
+ )
16
+ end
17
+
18
+ def delete_menu_item(resource)
19
+ iri = resource.iri.dup
20
+ iri.path += '/delete'
21
+
22
+ menu_item(
23
+ :destroy,
24
+ action: ontola_dialog_action(iri),
25
+ href: iri,
26
+ image: 'fa-close',
27
+ policy: :destroy?
28
+ )
29
+ end
30
+
31
+ def edit_menu_item(resource)
32
+ iri = resource.iri.dup
33
+ iri.path += '/edit'
34
+
35
+ menu_item(
36
+ :edit,
37
+ image: 'fa-edit',
38
+ href: iri,
39
+ policy: :update?
40
+ )
41
+ end
42
+ end
@@ -2,8 +2,7 @@
2
2
 
3
3
  require_relative '../../lib/vocab'
4
4
 
5
- LinkedRails.host = 'example.com'
5
+ LinkedRails.host = raise('Enter your host. Use an ENV var if you have multiple environments')
6
6
  LinkedRails.scheme = :https
7
- LinkedRails.app_vocab = Vocab.example
8
7
 
9
8
  LinkedRails::Renderers.register!
@@ -1,4 +1,16 @@
1
1
  en:
2
+ actions:
3
+ default:
4
+ create:
5
+ label: "New %{type}"
6
+ success: 'Created successfully'
7
+ destroy:
8
+ label: "Delete"
9
+ description: "Are you sure you want to delete this %{type}?"
10
+ success: 'Destroyed successfully'
11
+ update:
12
+ label: "Edit"
13
+ success: 'Updated successfully'
2
14
  linked_rails:
3
15
  status:
4
16
  400: "Error in request"
@@ -2,4 +2,5 @@
2
2
 
3
3
  class Vocab < LinkedRails::Vocab
4
4
  register(:example, 'https://example.com/my_vocab#')
5
+ app_vocabulary :example
5
6
  end
@@ -1,10 +1,10 @@
1
1
  en:
2
2
  foaf:
3
3
  name:
4
- label: "Naam"
4
+ label: "Name"
5
5
  ontola:
6
6
  password:
7
- label: "Wachtwoord"
7
+ label: "Password"
8
8
  quickActions:
9
9
  label: "Actions"
10
10
  rdfv:
@@ -17,7 +17,6 @@ module LinkedRails
17
17
  end
18
18
 
19
19
  def copy_files # rubocop:disable Metrics/AbcSize
20
- template 'action_list.rb', File.join('app', 'actions', class_path, "#{file_name}_action_list.rb")
21
20
  template 'controller.rb', File.join('app', 'controllers', class_path, "#{plural_file_name}_controller.rb")
22
21
  template 'form.rb', File.join('app', 'forms', class_path, "#{file_name}_form.rb")
23
22
  template 'menu_list.rb', File.join('app', 'menus', class_path, "#{file_name}_menu_list.rb")
@@ -2,6 +2,10 @@
2
2
 
3
3
  <% module_namespacing do -%>
4
4
  class <%= controller_class_name %>Controller < ApplicationController
5
- active_response :show, :index
5
+ active_response :show, :index
6
+
7
+ has_collection_create_action
8
+ has_resource_update_action
9
+ has_resource_destroy_action
6
10
  end
7
11
  <% end -%>
@@ -2,5 +2,8 @@
2
2
 
3
3
  <% module_namespacing do -%>
4
4
  class <%= class_name %>Form < ApplicationForm
5
+ <% attributes.each do |attribute| -%>
6
+ field :<%= attribute.name %>
7
+ <% end -%>
5
8
  end
6
9
  <% end -%>
@@ -2,5 +2,20 @@
2
2
 
3
3
  <% module_namespacing do -%>
4
4
  class <%= class_name %>MenuList < ApplicationMenuList
5
+ has_menu(
6
+ :actions,
7
+ image: 'fa-ellipsis-v',
8
+ menus: -> { action_menu_items }
9
+ )
10
+
11
+ private
12
+
13
+ def action_menu_items
14
+ [
15
+ edit_menu_item(resource),
16
+ delete_menu_item(resource),
17
+ copy_menu_item(resource.iri),
18
+ ]
19
+ end
5
20
  end
6
21
  <% end -%>