linked_rails 0.0.4.pre.gfe77aae19 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +674 -21
  3. data/app/controllers/linked_rails/bulk_controller.rb +16 -81
  4. data/app/models/linked_rails/actions/item.rb +30 -23
  5. data/app/models/linked_rails/actions/list.rb +6 -0
  6. data/app/models/linked_rails/collection/filter_field.rb +3 -16
  7. data/app/models/linked_rails/collection/filterable.rb +4 -6
  8. data/app/models/linked_rails/collection/infinite.rb +6 -17
  9. data/app/models/linked_rails/collection/iri.rb +2 -25
  10. data/app/models/linked_rails/collection/iri_mapping.rb +1 -1
  11. data/app/models/linked_rails/collection/paginated.rb +3 -4
  12. data/app/models/linked_rails/collection/view.rb +10 -38
  13. data/app/models/linked_rails/collection.rb +25 -27
  14. data/app/models/linked_rails/enum_value.rb +1 -1
  15. data/app/models/linked_rails/form/field/association_input.rb +1 -7
  16. data/app/models/linked_rails/form/field/file_input.rb +0 -1
  17. data/app/models/linked_rails/form/field.rb +5 -31
  18. data/app/models/linked_rails/form/field_factory.rb +16 -29
  19. data/app/models/linked_rails/form/group.rb +4 -2
  20. data/app/models/linked_rails/form/page.rb +0 -4
  21. data/app/models/linked_rails/form.rb +6 -4
  22. data/app/models/linked_rails/manifest.rb +20 -94
  23. data/app/models/linked_rails/menus/item.rb +13 -10
  24. data/app/models/linked_rails/menus/list.rb +5 -13
  25. data/app/models/linked_rails/ontology/base.rb +0 -2
  26. data/app/models/linked_rails/ontology.rb +0 -1
  27. data/app/models/linked_rails/property_query.rb +0 -2
  28. data/app/models/linked_rails/sequence.rb +11 -2
  29. data/app/models/linked_rails/web_page.rb +4 -0
  30. data/app/models/linked_rails/web_site.rb +4 -0
  31. data/app/models/linked_rails/widget.rb +10 -3
  32. data/app/policies/linked_rails/collection_policy.rb +2 -2
  33. data/app/serializers/linked_rails/actions/item_serializer.rb +4 -3
  34. data/app/serializers/linked_rails/collection/filter_field_serializer.rb +2 -3
  35. data/app/serializers/linked_rails/collection/filter_option_serializer.rb +1 -1
  36. data/app/serializers/linked_rails/collection/filter_serializer.rb +1 -1
  37. data/app/serializers/linked_rails/collection/sorting_serializer.rb +1 -1
  38. data/app/serializers/linked_rails/collection/view_serializer.rb +3 -3
  39. data/app/serializers/linked_rails/collection_serializer.rb +13 -9
  40. data/app/serializers/linked_rails/condition_serializer.rb +3 -3
  41. data/app/serializers/linked_rails/entry_point_serializer.rb +2 -2
  42. data/app/serializers/linked_rails/enum_value_serializer.rb +0 -1
  43. data/app/serializers/linked_rails/form/field/association_input_serializer.rb +0 -1
  44. data/app/serializers/linked_rails/form/field_serializer.rb +1 -3
  45. data/app/serializers/linked_rails/form/group_serializer.rb +1 -1
  46. data/app/serializers/linked_rails/form/page_serializer.rb +1 -1
  47. data/app/serializers/linked_rails/menus/item_serializer.rb +3 -3
  48. data/app/serializers/linked_rails/menus/list_serializer.rb +1 -1
  49. data/app/serializers/linked_rails/sequence_serializer.rb +5 -2
  50. data/app/serializers/linked_rails/shacl/node_shape_serializer.rb +1 -1
  51. data/app/serializers/linked_rails/shacl/property_shape_serializer.rb +1 -1
  52. data/app/serializers/linked_rails/shacl/shape_serializer.rb +5 -5
  53. data/app/serializers/linked_rails/web_page_serializer.rb +3 -3
  54. data/app/serializers/linked_rails/web_site_serializer.rb +1 -1
  55. data/app/serializers/linked_rails/widget_serializer.rb +3 -3
  56. data/lib/generators/linked_rails/install/templates/locales.yml +0 -4
  57. data/lib/generators/linked_rails/install/templates/rdf_serializers_initializer.rb +1 -1
  58. data/lib/generators/linked_rails/model/templates/form.rb.tt +1 -1
  59. data/lib/generators/linked_rails/model/templates/policy.rb.tt +1 -1
  60. data/lib/generators/linked_rails/model/templates/serializer.rb.tt +1 -5
  61. data/lib/linked_rails/active_response/controller/collections.rb +1 -1
  62. data/lib/linked_rails/active_response/controller/crud_defaults.rb +1 -1
  63. data/lib/linked_rails/active_response/controller/params.rb +6 -6
  64. data/lib/linked_rails/active_response/controller.rb +22 -1
  65. data/lib/linked_rails/collection_params_parser.rb +1 -1
  66. data/lib/linked_rails/controller/actionable.rb +2 -5
  67. data/lib/linked_rails/controller/default_actions/create.rb +2 -2
  68. data/lib/linked_rails/controller/error_handling.rb +7 -12
  69. data/lib/linked_rails/controller.rb +1 -4
  70. data/lib/linked_rails/helpers/delta_helper.rb +58 -4
  71. data/lib/linked_rails/helpers/resource_helper.rb +1 -13
  72. data/lib/linked_rails/iri_mapper.rb +1 -1
  73. data/lib/linked_rails/middleware/linked_data_params.rb +27 -26
  74. data/lib/linked_rails/model/actionable.rb +8 -7
  75. data/lib/linked_rails/model/collections.rb +4 -10
  76. data/lib/linked_rails/model/dirty.rb +18 -6
  77. data/lib/linked_rails/model/filtering.rb +2 -2
  78. data/lib/linked_rails/model/indexable.rb +1 -1
  79. data/lib/linked_rails/model/iri.rb +2 -14
  80. data/lib/linked_rails/model/iri_mapping.rb +3 -3
  81. data/lib/linked_rails/model/menuable.rb +7 -1
  82. data/lib/linked_rails/model/serialization.rb +6 -2
  83. data/lib/linked_rails/model/singularable.rb +5 -7
  84. data/lib/linked_rails/model/tables.rb +1 -1
  85. data/lib/linked_rails/model.rb +2 -5
  86. data/lib/linked_rails/params_parser.rb +47 -48
  87. data/lib/linked_rails/policy.rb +30 -21
  88. data/lib/linked_rails/renderers.rb +0 -1
  89. data/lib/linked_rails/routes.rb +0 -1
  90. data/lib/linked_rails/serializer/singularable.rb +1 -1
  91. data/lib/linked_rails/serializer.rb +2 -6
  92. data/lib/linked_rails/translate.rb +0 -12
  93. data/lib/linked_rails/vocab.rb +0 -1
  94. data/lib/linked_rails.rb +3 -16
  95. data/lib/rdf/query_fix.rb +1 -1
  96. metadata +10 -59
  97. data/app/controllers/linked_rails/actions/objects_controller.rb +0 -9
  98. data/app/models/linked_rails/actions/object.rb +0 -38
  99. data/app/models/linked_rails/form/field/url_input.rb +0 -10
  100. data/app/policies/linked_rails/actions/object_policy.rb +0 -11
  101. data/app/policies/linked_rails/form_policy.rb +0 -13
  102. data/app/policies/linked_rails/ontology_policy.rb +0 -13
  103. data/app/serializers/linked_rails/actions/object_serializer.rb +0 -9
  104. data/app/serializers/linked_rails/form/field/file_input_serializer.rb +0 -11
  105. data/app/serializers/linked_rails/property_query_serializer.rb +0 -7
  106. data/app/workers/linked_rails/invalidation_stream_worker.rb +0 -16
  107. data/lib/linked_rails/controller/delta.rb +0 -58
  108. data/lib/linked_rails/controller/rendering.rb +0 -48
  109. data/lib/linked_rails/errors/forbidden.rb +0 -37
  110. data/lib/linked_rails/errors.rb +0 -3
  111. data/lib/linked_rails/middleware/error_handling.rb +0 -51
  112. data/lib/linked_rails/model/cacheable.rb +0 -45
  113. data/lib/linked_rails/railtie.rb +0 -11
  114. data/lib/linked_rails/storage.rb +0 -32
  115. data/lib/linked_rails/types/iri_type.rb +0 -37
  116. data/lib/linked_rails/url.rb +0 -11
  117. data/lib/rdf/list.rb +0 -9
@@ -19,14 +19,14 @@ module LinkedRails
19
19
  class Collection # rubocop:disable Metrics/ClassLength
20
20
  include ActiveModel::Model
21
21
  include LinkedRails::Model::Actionable
22
- include LinkedRails::Model::IRI
22
+ include LinkedRails::Model::Iri
23
23
  include LinkedRails::Collection::Configuration
24
24
  include LinkedRails::Collection::Filterable
25
- include LinkedRails::Collection::IRI
26
- include LinkedRails::Collection::IRIMapping
25
+ include LinkedRails::Collection::Iri
26
+ include LinkedRails::Collection::IriMapping
27
27
  include LinkedRails::Collection::Sortable
28
28
 
29
- attr_accessor :name, :policy, :user_context
29
+ attr_accessor :name, :policy, :user_context, :view
30
30
  attr_writer :association_base, :views
31
31
 
32
32
  alias id iri
@@ -67,8 +67,17 @@ module LinkedRails
67
67
  super(options.merge(except: %w[association_class unfiltered_collection collection]))
68
68
  end
69
69
 
70
- def child_resource
71
- @child_resource ||= build_child
70
+ def build_child # rubocop:disable Metrics/AbcSize
71
+ child =
72
+ parent&.build_child(association_class, user_context: user_context) ||
73
+ association_class.build_new(parent: parent, user_context: user_context)
74
+
75
+ parser = LinkedRails::ParamsParser.new(user_context: user_context, params: {filter: @filter})
76
+ permitted_child_keys = Pundit.policy(user_context, child)&.permitted_attributes || []
77
+ permitted_attributes_from_filters = parser.attributes_from_filters(association_class).permit(permitted_child_keys)
78
+
79
+ child.assign_attributes(permitted_attributes_from_filters)
80
+ child
72
81
  end
73
82
 
74
83
  def columns
@@ -103,6 +112,15 @@ module LinkedRails
103
112
  self.class.new(**attrs)
104
113
  end
105
114
 
115
+ def preview_includes
116
+ {
117
+ default_view: default_view.preview_includes,
118
+ filter_fields: :options,
119
+ filters: [],
120
+ sortings: []
121
+ }
122
+ end
123
+
106
124
  def total_count
107
125
  @total_count ||= association_base.try(:total_count) || unscoped_association.count
108
126
  end
@@ -128,16 +146,6 @@ module LinkedRails
128
146
 
129
147
  private
130
148
 
131
- def build_child
132
- child =
133
- parent&.build_child(association_class, user_context: user_context) ||
134
- association_class.build_new(parent: parent, user_context: user_context)
135
-
136
- child.assign_attributes(association_base.where_values_hash) if association_base.respond_to?(:where_values_hash)
137
- child.assign_attributes(permitted_attributes_from_filters(child))
138
- child
139
- end
140
-
141
149
  def collection_view_class
142
150
  LinkedRails.collection_view_class
143
151
  end
@@ -156,12 +164,6 @@ module LinkedRails
156
164
  type == :paginated
157
165
  end
158
166
 
159
- def permitted_attributes_from_filters(child)
160
- return {} if @filter.empty?
161
-
162
- Pundit.policy(user_context, child).try(:permitted_attributes_from_filters, @filter) || {}
163
- end
164
-
165
167
  def title_from_translation
166
168
  plural = association_class.name.tableize
167
169
 
@@ -174,11 +176,7 @@ module LinkedRails
174
176
 
175
177
  def new_child_values
176
178
  instance_values
177
- .slice(
178
- 'iri_template',
179
- *LinkedRails::Model::Collections::COLLECTION_STATIC_OPTIONS.keys.map(&:to_s),
180
- *LinkedRails::Model::Collections::COLLECTION_CUSTOMIZABLE_OPTIONS.keys.map { |key| "default_#{key}" }
181
- )
179
+ .slice('iri_template', *LinkedRails::Model::Collections::COLLECTION_STATIC_OPTIONS.keys.map(&:to_s))
182
180
  .merge(
183
181
  unfiltered_collection: filtered? ? @unfiltered_collection : self,
184
182
  user_context: user_context
@@ -5,7 +5,7 @@ module LinkedRails
5
5
  include ActiveModel::Model
6
6
  include LinkedRails::Model
7
7
 
8
- attr_accessor :attr, :close_match, :exact_match, :group_by, :identifier, :key, :klass, :type
8
+ attr_accessor :attr, :close_match, :exact_match, :group_by, :key, :klass, :type
9
9
  attr_writer :iri, :label
10
10
 
11
11
  def label
@@ -9,13 +9,7 @@ module LinkedRails
9
9
  def datatype; end
10
10
 
11
11
  def nested_form
12
- @nested_form ||= target_class.form_class
13
- end
14
-
15
- def target_class
16
- return @target_class if @target_class
17
-
18
- klass_name.constantize unless form.abstract_form
12
+ @nested_form ||= klass_name.constantize.form_class
19
13
  end
20
14
 
21
15
  private
@@ -4,7 +4,6 @@ module LinkedRails
4
4
  class Form
5
5
  class Field
6
6
  class FileInput < Field
7
- attr_accessor :max_size
8
7
  end
9
8
  end
10
9
  end
@@ -2,27 +2,25 @@
2
2
 
3
3
  module LinkedRails
4
4
  class Form
5
- class Field < LinkedRails::Resource # rubocop:disable Metrics/ClassLength
5
+ class Field < LinkedRails::Resource
6
6
  attr_writer :description,
7
7
  :helper_text,
8
8
  :label,
9
- :max_inclusive,
10
9
  :max_length,
11
10
  :min_count,
12
- :min_inclusive,
13
11
  :min_length,
14
- :pattern,
15
- :path,
16
- :placeholder,
17
12
  :sh_in,
18
- :start_adornment
13
+ :pattern,
14
+ :path
19
15
  attr_accessor :datatype,
20
16
  :default_value,
21
17
  :max_count,
22
18
  :max_count_prop,
19
+ :max_inclusive,
23
20
  :max_inclusive_prop,
24
21
  :max_length_prop,
25
22
  :min_count_prop,
23
+ :min_inclusive,
26
24
  :min_inclusive_prop,
27
25
  :min_length_prop,
28
26
  :model_attribute,
@@ -42,10 +40,6 @@ module LinkedRails
42
40
  helper_text_from_attribute || helper_text_fallback
43
41
  end
44
42
 
45
- def max_inclusive
46
- @max_inclusive || validators[:max_inclusive]
47
- end
48
-
49
43
  def max_length
50
44
  @max_length || validators[:max_length]
51
45
  end
@@ -54,10 +48,6 @@ module LinkedRails
54
48
  @min_count || (validators[:presence] ? 1 : nil)
55
49
  end
56
50
 
57
- def min_inclusive
58
- @min_inclusive || validators[:min_inclusive]
59
- end
60
-
61
51
  def min_length
62
52
  @min_length || validators[:min_length]
63
53
  end
@@ -79,20 +69,12 @@ module LinkedRails
79
69
  true
80
70
  end
81
71
 
82
- def placeholder
83
- placeholder_from_attribute || placeholder_fallback
84
- end
85
-
86
72
  def sh_in
87
73
  return validators[:sh_in] if @sh_in.blank?
88
74
 
89
75
  @sh_in.respond_to?(:call) ? @sh_in.call : @sh_in
90
76
  end
91
77
 
92
- def start_adornment
93
- @start_adornment.respond_to?(:call) ? @start_adornment.call : @start_adornment
94
- end
95
-
96
78
  private
97
79
 
98
80
  def description_from_attribute
@@ -123,14 +105,6 @@ module LinkedRails
123
105
  LinkedRails.translate(:property, :label, path) if path
124
106
  end
125
107
 
126
- def placeholder_from_attribute
127
- @placeholder.respond_to?(:call) ? @placeholder.call : @placeholder
128
- end
129
-
130
- def placeholder_fallback
131
- LinkedRails.translate(:field, :placeholder, self, false)
132
- end
133
-
134
108
  class << self
135
109
  def iri
136
110
  Vocab.form[name.demodulize]
@@ -11,9 +11,7 @@ module LinkedRails
11
11
  MAX_STR_LEN = 255
12
12
  VALIDATOR_SELECTORS = [
13
13
  [:min_length, ActiveModel::Validations::LengthValidator, :minimum],
14
- [:min_inclusive, ActiveModel::Validations::NumericalityValidator, :greater_than_or_equal_to],
15
14
  [:max_length, ActiveModel::Validations::LengthValidator, :maximum],
16
- [:max_inclusive, ActiveModel::Validations::NumericalityValidator, :less_than_or_equal_to],
17
15
  [:pattern, ActiveModel::Validations::FormatValidator, :with],
18
16
  [:presence, ActiveModel::Validations::PresenceValidator, nil],
19
17
  [:sh_in, ActiveModel::Validations::InclusionValidator, :in]
@@ -32,27 +30,26 @@ module LinkedRails
32
30
  to: :form
33
31
 
34
32
  def condition_or_field
35
- return @condition_or_field if instance_variable_defined?(:@condition_or_field)
33
+ return field if abstract_form
36
34
 
37
- alternatives = node_shapes_for(
35
+ @condition_or_field ||= model_policy!.condition_for(
38
36
  key,
37
+ field,
39
38
  property: field_options[:if] || [],
40
39
  sh_not: field_options[:unless] || []
41
40
  )
42
- @condition_or_field =
43
- if alternatives.count == 1
44
- Condition.new(shape: alternatives.first, pass: field)
45
- elsif alternatives.count.positive?
46
- Condition.new(shape: SHACL::NodeShape.new(or: alternatives), pass: field)
47
- else
48
- field
49
- end
50
41
  end
51
42
 
52
43
  private
53
44
 
54
45
  def attr_column(name)
55
- model_class.column_for_attribute(name)
46
+ column_model =
47
+ if model_class.is_delegated_attribute?(name)
48
+ model_class.class_for_delegated_attribute(name)
49
+ else
50
+ model_class
51
+ end
52
+ column_model.column_for_attribute(name)
56
53
  end
57
54
 
58
55
  def attr_to_datatype # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
@@ -182,15 +179,6 @@ module LinkedRails
182
179
  @model_attribute ||= (model_class.try(:attribute_alias, key) || key).to_sym
183
180
  end
184
181
 
185
- def node_shapes_for(attr, property: [], sh_not: [])
186
- alternatives = abstract_form ? [] : model_policy!.condition_alternatives(attr, field.permission_required?)
187
- alternatives = [[]] if alternatives.empty? && (property.any? || sh_not.any?)
188
-
189
- alternatives.map do |props|
190
- SHACL::NodeShape.new(property: props + property, sh_not: sh_not)
191
- end
192
- end
193
-
194
182
  def normalized_key(key)
195
183
  return key.to_s[0...-3].to_sym if key.to_s.ends_with?('_id')
196
184
  return key.to_s[0...-4].pluralize.to_sym if key.to_s.ends_with?('_ids')
@@ -220,15 +208,14 @@ module LinkedRails
220
208
  def validator(klass, option_key)
221
209
  matched_validator = validator_by_class(klass)
222
210
 
223
- value = option_key ? matched_validator&.options.try(:[], option_key) : matched_validator.present?
224
-
225
- value unless value.respond_to?(:call)
211
+ option_key ? matched_validator&.options.try(:[], option_key) : matched_validator.present?
226
212
  end
227
213
 
228
214
  def validator_by_class(klass)
229
- attribute_validators&.detect do |validator|
230
- validator.is_a?(klass) && validator.options[:if].blank? && validator.options[:unless].blank?
231
- end
215
+ matched_validator = attribute_validators&.detect { |v| v.is_a?(klass) }
216
+ return if matched_validator.blank?
217
+
218
+ matched_validator if matched_validator.options[:if].blank? && matched_validator.options[:unless].blank?
232
219
  end
233
220
 
234
221
  def validators
@@ -236,7 +223,7 @@ module LinkedRails
236
223
  VALIDATOR_SELECTORS.map do |key, klass, option_key|
237
224
  [key, validator(klass, option_key)]
238
225
  end
239
- ].compact
226
+ ]
240
227
  end
241
228
  end
242
229
  end
@@ -12,11 +12,13 @@ module LinkedRails
12
12
  end
13
13
 
14
14
  def description
15
- @description.respond_to?(:call) ? @description.call : @description
15
+ @description = @description.call if @description.respond_to?(:call)
16
+ @description
16
17
  end
17
18
 
18
19
  def label
19
- @label.respond_to?(:call) ? @label.call : @label
20
+ @label = @label.call if @label.respond_to?(:call)
21
+ @label
20
22
  end
21
23
 
22
24
  def rdf_type
@@ -21,10 +21,6 @@ module LinkedRails
21
21
  @footer_group ||= add_group(collapsible: false, footer: true, key: :footer)
22
22
  end
23
23
 
24
- def footer_group!
25
- @footer_group
26
- end
27
-
28
24
  class << self
29
25
  def iri
30
26
  Vocab.form[:Page]
@@ -5,7 +5,6 @@ require 'pundit'
5
5
  module LinkedRails
6
6
  class Form # rubocop:disable Metrics/ClassLength
7
7
  include LinkedRails::Model
8
- include LinkedRails::Model::Cacheable
9
8
 
10
9
  class_attribute :abstract_form, :pages, :model_class
11
10
 
@@ -64,6 +63,10 @@ module LinkedRails
64
63
  @serializer_reflections ||= serializer_class&.relationships_to_serialize || {}
65
64
  end
66
65
 
66
+ def preview_includes
67
+ [pages: {groups: [fields: [:fail, :pass, shape: [:property, nested_shapes: :property]]]}]
68
+ end
69
+
67
70
  private
68
71
 
69
72
  def current_group
@@ -91,10 +94,9 @@ module LinkedRails
91
94
  end
92
95
 
93
96
  def find_form_class(params)
94
- form_name = [params[:module], "#{params[:id]&.singularize}_forms"].compact.join('/').classify
95
- requested_class = form_name.safe_constantize
97
+ requested_class = [params[:module], "#{params[:id]&.singularize}_forms"].compact.join('/').classify
96
98
 
97
- requested_class if requested_class && requested_class < LinkedRails::Form
99
+ LinkedRails::Form.descendants.detect { |klass| klass.to_s == requested_class }
98
100
  end
99
101
 
100
102
  def footer
@@ -5,27 +5,6 @@ module LinkedRails
5
5
  include ActiveModel::Model
6
6
  include LinkedRails::Model
7
7
 
8
- def save
9
- Storage.hset(
10
- :persistent,
11
- :manifest,
12
- URL.as_href(LinkedRails.iri) => web_manifest.to_json
13
- )
14
- end
15
-
16
- def web_manifest
17
- web_manifest_base.merge(
18
- ontola: web_manifest_ontola_section,
19
- serviceworker: web_manifest_sw_section
20
- )
21
- end
22
-
23
- private
24
-
25
- def allowed_external_sources
26
- []
27
- end
28
-
29
8
  def app_name
30
9
  Rails.application.railtie_name.chomp('_application').humanize
31
10
  end
@@ -38,27 +17,8 @@ module LinkedRails
38
17
  '#eef0f2'
39
18
  end
40
19
 
41
- def blob_preview_iri
42
- return unless ActiveStorage::Blob.service.present?
43
-
44
- "#{LinkedRails.iri(path: 'rails/active_storage/blobs/redirect')}/{signed_id}/preview"
45
- end
46
-
47
- def blob_upload_iri
48
- return unless ActiveStorage::Blob.service.present?
49
-
50
- LinkedRails.iri(path: 'rails/active_storage/direct_uploads')
51
- end
52
-
53
20
  def css_class; end
54
21
 
55
- def csp_entries
56
- {
57
- connectSrc: [ActiveStorage::Blob.service.try(:bucket)&.url].compact,
58
- scriptSrc: [ActiveStorage::Blob.service.try(:bucket)&.url].compact
59
- }
60
- end
61
-
62
22
  def header_background
63
23
  :primary
64
24
  end
@@ -67,16 +27,17 @@ module LinkedRails
67
27
  :white
68
28
  end
69
29
 
70
- def icons
71
- []
72
- end
73
-
74
- def lang
75
- :nl
30
+ def preload_iris
31
+ [
32
+ scope,
33
+ LinkedRails.iri(path: 'ns/core').to_s,
34
+ LinkedRails.iri(path: 'c_a').to_s,
35
+ LinkedRails.iri(path: 'menus').to_s
36
+ ]
76
37
  end
77
38
 
78
39
  def scope
79
- LinkedRails.iri.to_s
40
+ @scope ||= LinkedRails.iri.to_s
80
41
  end
81
42
 
82
43
  def site_theme_color
@@ -91,46 +52,43 @@ module LinkedRails
91
52
  app_name
92
53
  end
93
54
 
94
- def start_url
95
- scope == '/' ? scope : "#{scope}/"
96
- end
97
-
98
55
  def theme; end
99
56
 
100
57
  def theme_options
101
58
  {}
102
59
  end
103
60
 
61
+ def web_manifest
62
+ web_manifest_base.merge(
63
+ ontola: web_manifest_ontola_section,
64
+ serviceworker: web_manifest_sw_section
65
+ )
66
+ end
67
+
104
68
  def web_manifest_base # rubocop:disable Metrics/MethodLength
105
69
  {
106
70
  background_color: background_color,
107
71
  dir: :rtl,
108
72
  display: :standalone,
109
- icons: icons,
110
- lang: lang,
73
+ lang: :nl,
111
74
  name: app_name,
112
75
  scope: scope,
113
76
  short_name: app_name,
114
- start_url: start_url,
77
+ start_url: scope,
115
78
  theme_color: site_theme_color
116
79
  }
117
80
  end
118
81
 
119
82
  def web_manifest_ontola_section # rubocop:disable Metrics/MethodLength
120
83
  {
121
- allowed_external_sources: allowed_external_sources,
122
- blob_preview_iri: blob_preview_iri,
123
- blob_upload_iri: blob_upload_iri,
124
- csp: csp_entries,
84
+ css_class: css_class,
125
85
  header_background: header_background,
126
86
  header_text: header_text,
127
- preconnect: preconnect,
87
+ preload: preload_iris,
128
88
  primary_color: site_theme_color,
129
89
  secondary_color: site_secondary_color,
130
- styled_headers: styled_headers,
131
90
  theme: theme,
132
91
  theme_options: theme_options.to_query,
133
- tracking: tracking,
134
92
  website_iri: LinkedRails.iri.to_s,
135
93
  websocket_path: websocket_path
136
94
  }
@@ -138,7 +96,7 @@ module LinkedRails
138
96
 
139
97
  def web_manifest_sw_section
140
98
  {
141
- src: "#{scope.chomp('/')}/sw.js",
99
+ src: "#{scope}/sw.js?manifestLocation=#{Rack::Utils.escape("#{scope}/manifest.json")}",
142
100
  scope: scope
143
101
  }
144
102
  end
@@ -146,37 +104,5 @@ module LinkedRails
146
104
  def websocket_path
147
105
  Rails.application.config.try(:action_cable).try(:mount_path).try(:[], 1..-1)
148
106
  end
149
-
150
- def preconnect
151
- []
152
- end
153
-
154
- def styled_headers
155
- false
156
- end
157
-
158
- def tracking
159
- []
160
- end
161
-
162
- class << self
163
- def destroy(iri)
164
- Storage.hdel(:persistent, :manifest, URL.as_href(iri))
165
- end
166
-
167
- def move(from, to)
168
- Storage.hset(
169
- :persistent,
170
- :redirect_prefix,
171
- URL.as_href(from) => URL.as_href(to)
172
- )
173
-
174
- data = Storage.hget(:persistent, :manifest, URL.as_href(from))
175
-
176
- Storage.hset(:persistent, :manifest, URL.as_href(to), data) if data
177
-
178
- destroy(from)
179
- end
180
- end
181
107
  end
182
108
  end
@@ -12,7 +12,7 @@ module LinkedRails
12
12
  delegate :iri_opts, to: :parent
13
13
 
14
14
  alias id iri
15
- %i[action href image label iri_base].each do |method|
15
+ %i[action href image label menus iri_base].each do |method|
16
16
  callable_variable(method, instance: :parent)
17
17
  end
18
18
 
@@ -36,7 +36,7 @@ module LinkedRails
36
36
 
37
37
  @menu_sequence ||=
38
38
  LinkedRails::Sequence.new(
39
- -> { menus },
39
+ -> { menus&.compact&.each { |menu| menu.parent = self } },
40
40
  id: menu_sequence_iri,
41
41
  parent: self,
42
42
  scope: false
@@ -52,12 +52,6 @@ module LinkedRails
52
52
  sequence_iri
53
53
  end
54
54
 
55
- def menus
56
- return @menus unless @menus.respond_to?(:call)
57
-
58
- @menus = parent.instance_exec(&@menus).compact.each { |menu| menu.parent = self }
59
- end
60
-
61
55
  def rdf_type
62
56
  type || Vocab.ontola[:MenuItem]
63
57
  end
@@ -73,15 +67,24 @@ module LinkedRails
73
67
  end
74
68
 
75
69
  class << self
70
+ def base_includes
71
+ [action: :target]
72
+ end
73
+
76
74
  def preview_includes
77
- [menu_sequence: [members: [menu_sequence: :members]]]
75
+ base_includes + [
76
+ menu_sequence: [
77
+ members: base_includes +
78
+ [menu_sequence: [members: base_includes]]
79
+ ]
80
+ ]
78
81
  end
79
82
 
80
83
  def requested_index_resource(params, user_context)
81
84
  parent = parent_from_params(params, user_context)
82
85
  return if parent.blank?
83
86
 
84
- parent.try(:menu_sequence)
87
+ parent.menu_sequence
85
88
  end
86
89
  end
87
90
  end
@@ -20,17 +20,15 @@ module LinkedRails
20
20
  end
21
21
 
22
22
  def iri_opts
23
- return {} if resource.blank?
24
-
25
- resource.try(:singular_resource?) ? resource.singular_iri_opts : resource.iri_opts
23
+ resource&.iri_opts || {}
26
24
  end
27
25
 
28
26
  def menus
29
- @menus ||= available_menus.map(&method(:memoized_menu_item))
27
+ @menus ||= available_menus.map(&method(:menu_item))
30
28
  end
31
29
 
32
30
  def menu(tag)
33
- memoized_menu_item(tag, available_menus[tag].dup) if available_menus.key?(tag)
31
+ menu_item(tag, available_menus[tag].dup) if available_menus.key?(tag)
34
32
  end
35
33
 
36
34
  private
@@ -39,11 +37,6 @@ module LinkedRails
39
37
  I18n.t("menus.#{resource&.class&.name&.tableize}.#{tag}", **options[:label_params])
40
38
  end
41
39
 
42
- def memoized_menu_item(tag, options)
43
- @memoized_menu_item ||= {}
44
- @memoized_menu_item[tag] ||= menu_item(tag, options)
45
- end
46
-
47
40
  def menu_available?(_tag, options)
48
41
  options[:condition].nil? || call_option(options[:condition], resource)
49
42
  end
@@ -70,9 +63,7 @@ module LinkedRails
70
63
  end
71
64
 
72
65
  def iri_template
73
- base_template = resource.send(resource.try(:singular_resource?) ? :singular_iri_template : :iri_template)
74
-
75
- @iri_template ||= iri_template_expand_path(base_template, '/menus')
66
+ @iri_template ||= iri_template_expand_path(resource.send(:iri_template), '/menus')
76
67
  end
77
68
 
78
69
  class << self
@@ -110,6 +101,7 @@ module LinkedRails
110
101
  LinkedRails::Sequence.new(
111
102
  menu_list.menus,
112
103
  id: menu_list.iri,
104
+ member_includes: Item.preview_includes,
113
105
  scope: false
114
106
  )
115
107
  end
@@ -41,8 +41,6 @@ module LinkedRails
41
41
  end
42
42
 
43
43
  def include_data_statement?(statement)
44
- return false if statement.subject.node? || statement.object.node?
45
-
46
44
  statement.predicate != Vocab.rdfs.label &&
47
45
  statement.predicate != Vocab.rdfs.range &&
48
46
  statement.predicate != Vocab.rdfs.domain
@@ -4,7 +4,6 @@ module LinkedRails
4
4
  class Ontology
5
5
  include ActiveModel::Model
6
6
  include LinkedRails::Model
7
- include LinkedRails::Model::Cacheable
8
7
 
9
8
  def classes
10
9
  @classes ||= LinkedRails.linked_models.map do |klass|