hydra-editor 1.0.4 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07b3e61fba7144fb5d24d64cdc241ab1c5e09f5a
4
- data.tar.gz: 046d6ccb60e056267ed1e09c29b74999715f2ccf
3
+ metadata.gz: dd1419f83e2d52941a3816a3087a012fd80bc98f
4
+ data.tar.gz: a0ca374521dd0fb94acdb553cd5fb9cd74666558
5
5
  SHA512:
6
- metadata.gz: 712434962668b46f9b6b4dbbc5df09e2acf60b02e4f43b06218a0df30d5891a3046ef938f8ab039c96f1d12da5cc1a072a641f1614308bcecc7fb93bd4154acf
7
- data.tar.gz: 3875cf1521283e6358fa89d400876665a931f719ce08ea8c0a54b24eebcd41acd4c6ad7720b7545865b9aa85eaa91403af9d365943e1437a0f772792598dd7a7
6
+ metadata.gz: 9ad0aad1cd3fdcf694bcf318f076107ef8c6b4bc108cd51e6e6fef4d8663b53504e25fce8010f0344692d0a1e51fb39654d50ee84036632155bb57b0aafe8b6e
7
+ data.tar.gz: d11f4e9817c7daa1aac868cb32890776ba364cb2f9855ded3c119da725334a241ac5a1d3820b6b202311c0537d73f24f5520f0045a27fb30c79877bf9e1490ed
data/History.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # History of hydra-editor releases
2
2
 
3
+ ## 1.1.0
4
+ * 2015-10-09: multiple? shouldn't raise errors when confronted with non-properties [Justin Coyne]
5
+ * 2015-09-17: Add an instance method version of multiple? [Justin Coyne]
6
+ * 2015-09-17: Update build matrix [Justin Coyne]
7
+ * 2015-09-17: Make add and remove button the same size [Justin Coyne]
8
+ * 2015-09-17: Use property instead of deprecated has_attributes [Justin Coyne]
9
+ * 2015-09-17: Pin bootstrap-sass to 3.3.4.1 for rails 4.1 build [Justin Coyne]
10
+ * 2015-06-10: Use html-safe translation to avoid raw() call [Jeremy Echols]
11
+ * 2015-04-23: Add <kbd> tags for more semantic form instructions [Jeremy Echols]
12
+ * 2015-04-21: Allow overriding jetty port [Jeremy Echols]
13
+ * 2015-04-21: Add form instructions for screen readers [Jeremy Echols]
14
+ * 2015-04-17: Don't hardcode a version of hydra-head in the test app [Justin Coyne]
15
+ * 2015-04-16: Split option-building from field-building [Jeremy Echols]
16
+ * 2015-04-14: Make [ENTER] default to submit the form [Jeremy Echols]
17
+
3
18
  ## 1.0.3
4
19
  * 2015-04-02: Updated README with info on how to set form labels [val99erie]
5
20
  * 2015-03-30: Add documentation to Form#model_attributes. (ci skip) [Justin Coyne]
@@ -1,4 +1,3 @@
1
1
  //= require hydra-editor/manage_repeating_fields
2
- //= require hydra-editor/keyboard_support
3
2
  //= require hydra-editor/editMetadata
4
3
 
@@ -8,8 +8,8 @@ var HydraEditor = (function($) {
8
8
  this.options = options;
9
9
 
10
10
  this.controls = $("<span class=\"input-group-btn field-controls\">");
11
- this.remover = $("<button class=\"btn btn-danger remove\"><i class=\"icon-white glyphicon-minus\"></i><span>Remove</span></button>");
12
- this.adder = $("<button class=\"btn btn-success add\"><i class=\"icon-white glyphicon-plus\"></i><span>Add</span></button>");
11
+ this.remover = $("<button type=\"button\" class=\"btn btn-danger remove\"><i class=\"icon-white glyphicon-minus\"></i><span>Remove</span></button>");
12
+ this.adder = $("<button type=\"button\" class=\"btn btn-success add\"><i class=\"icon-white glyphicon-plus\"></i><span>Add</span></button>");
13
13
 
14
14
  this.fieldWrapperClass = '.field-wrapper';
15
15
  this.warningClass = '.has-warning';
@@ -1,4 +1,8 @@
1
1
  .multi_value {
2
+ .btn.add, .btn.remove {
3
+ width: 6em;
4
+ }
5
+
2
6
  .field-wrapper {
3
7
  list-style-type:none;
4
8
  }
@@ -45,6 +45,10 @@ module HydraEditor
45
45
  end
46
46
  end
47
47
 
48
+ def multiple?(field)
49
+ HydraEditor::FieldMetadataService.multiple?(model_class, field)
50
+ end
51
+
48
52
  # Return a hash of all the parameters from the form as a hash.
49
53
  # This is typically used by the controller as the main read interface to the form.
50
54
  # This hash can then be used to create or update an object in the data store.
@@ -90,7 +94,7 @@ module HydraEditor
90
94
  # override this method if you need to initialize more complex RDF assertions (b-nodes)
91
95
  def initialize_field(key)
92
96
  # if value is empty, we create an one element array to loop over for output
93
- if self.class.multiple?(key)
97
+ if multiple?(key)
94
98
  self[key] = ['']
95
99
  else
96
100
  self[key] = ''
@@ -39,7 +39,7 @@ class MultiValueInput < SimpleForm::Inputs::CollectionInput
39
39
  # Although the 'index' parameter is not used in this implementation it is useful in an
40
40
  # an overridden version of this method, especially when the field is a complex object and
41
41
  # the override defines nested fields.
42
- def build_field(value, index)
42
+ def build_field_options(value, index)
43
43
  options = input_html_options.dup
44
44
 
45
45
  options[:value] = value
@@ -53,6 +53,12 @@ class MultiValueInput < SimpleForm::Inputs::CollectionInput
53
53
  options[:class] += ["#{input_dom_id} form-control multi-text-field"]
54
54
  options[:'aria-labelledby'] = label_id
55
55
  @rendered_first_element = true
56
+
57
+ options
58
+ end
59
+
60
+ def build_field(value, index)
61
+ options = build_field_options(value, index)
56
62
  if options.delete(:type) == 'textarea'.freeze
57
63
  @builder.text_area(attribute_name, options)
58
64
  else
@@ -3,6 +3,10 @@ module Hydra
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
5
  attr_reader :model
6
+
7
+ # model_class only needs to be set if you are using the
8
+ # deprecated class methods multiple? or unique? or if you
9
+ # need to use +model_name+ method or if this class includes Hydra::Editor::Form.
6
10
  class_attribute :model_class
7
11
  end
8
12
 
@@ -51,16 +55,22 @@ module Hydra
51
55
  self.class._terms
52
56
  end
53
57
 
58
+ # If the field is a reflection, delegate to the reflection.
59
+ # If the field is a property, delegate to the property.
60
+ # Otherwise return false
61
+ def multiple?(field)
62
+ HydraEditor::FieldMetadataService.multiple?(model.class, field)
63
+ end
64
+
54
65
  module ClassMethods
66
+ # @deprecated Because if we use an instance method, there will be no need to set self.model_class in most instances. Note, there is a class method multiple? on the form.
55
67
  def multiple?(field)
56
- if reflection = model_class.reflect_on_association(field)
57
- reflection.collection?
58
- else
59
- model_class.multiple?(field)
60
- end
68
+ Deprecation.warn(ClassMethods, "The class method multiple? has been deprecated. Use the instance method instead. This will be removed in version 2.0")
69
+ HydraEditor::FieldMetadataService.multiple?(model_class, field)
61
70
  end
62
71
 
63
72
  def unique?(field)
73
+ Deprecation.warn(ClassMethods, "The class method unique? has been deprecated. Use the instance method 'multiple?' instead. This will be removed in version 2.0")
64
74
  if reflection = model_class.reflect_on_association(field)
65
75
  !reflection.collection?
66
76
  else
@@ -0,0 +1,16 @@
1
+ module HydraEditor
2
+ class FieldMetadataService
3
+ # If the field is a reflection, delegate to the reflection.
4
+ # If the field is a property, delegate to the property.
5
+ # Otherwise return false
6
+ def self.multiple?(model_class, field)
7
+ if reflection = model_class.reflect_on_association(field)
8
+ reflection.collection?
9
+ elsif model_class.attribute_names.include?(field.to_s)
10
+ model_class.multiple?(field)
11
+ else
12
+ false
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,4 +1,5 @@
1
- <h2 class="non lower">
2
- <%= t('hydra_editor.form.title') %>
3
- <small class="pull-right"><span class="error">*</span> <%= t('hydra_editor.form.required_fields') %></small>
4
- </h2>
1
+ <p class="instructions"><%= t('hydra_editor.form.instructions_html') %></p>
2
+ <h2 class="non lower">
3
+ <%= t('hydra_editor.form.title') %>
4
+ <small class="pull-right"><span class="error">*</span> <%= t('hydra_editor.form.required_fields') %></small>
5
+ </h2>
@@ -1,4 +1,4 @@
1
- <% if f.object.class.multiple? key %>
1
+ <% if f.object.multiple? key %>
2
2
  <%= f.input key, as: :multi_value, input_html: { class: 'form-control' }, required: f.object.required?(key) %>
3
3
  <% else %>
4
4
  <%= f.input key, required: f.object.required?(key) %>
@@ -1,6 +1,6 @@
1
1
  default:
2
2
  startup_wait: 90
3
- jetty_port: 8983
3
+ jetty_port: <%= ENV['JETTY_PORT'] || 8983 %>
4
4
  java_opts:
5
5
  - "-Xmx256m"
6
6
  - "-XX:MaxPermSize=128m"
@@ -8,5 +8,8 @@ en:
8
8
  form:
9
9
  title: 'Descriptions'
10
10
  required_fields: 'indicates required fields'
11
+ instructions_html: 'Use the <kbd>Tab</kbd> key to navigate the form, press
12
+ <kbd>Space</kbd> to activate a button, and press
13
+ <kbd>Enter</kbd> to submit the whole form.'
11
14
  new:
12
15
  title: 'Create a New %s Record'
@@ -1,3 +1,3 @@
1
1
  module HydraEditor
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-16 00:00:00.000000000 Z
12
+ date: 2015-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -191,7 +191,6 @@ files:
191
191
  - Rakefile
192
192
  - app/assets/javascripts/hydra-editor/editMetadata.js
193
193
  - app/assets/javascripts/hydra-editor/hydra-editor.js
194
- - app/assets/javascripts/hydra-editor/keyboard_support.js
195
194
  - app/assets/javascripts/hydra-editor/manage_repeating_fields.js
196
195
  - app/assets/stylesheets/hydra-editor/hydra-editor.scss
197
196
  - app/assets/stylesheets/hydra-editor/multi_value_fields.scss
@@ -203,6 +202,7 @@ files:
203
202
  - app/helpers/records_helper.rb
204
203
  - app/inputs/multi_value_input.rb
205
204
  - app/presenters/hydra/presenter.rb
205
+ - app/services/hydra_editor/field_metadata_service.rb
206
206
  - app/views/records/_form.html.erb
207
207
  - app/views/records/_form_header.html.erb
208
208
  - app/views/records/choose_type.html.erb
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  version: '0'
238
238
  requirements: []
239
239
  rubyforge_project:
240
- rubygems_version: 2.4.5
240
+ rubygems_version: 2.4.5.1
241
241
  signing_key:
242
242
  specification_version: 4
243
243
  summary: A basic metadata editor for hydra-head
@@ -1,14 +0,0 @@
1
- Blacklight.onLoad(function() {
2
- $('body').on('keypress', '.multi-text-field', function(event) {
3
- var $activeField = $(event.target).parents('.field-wrapper'),
4
- $activeFieldControls = $activeField.children('.field-controls'),
5
- $addControl = $activeFieldControls.children('.add'),
6
- $removeControl = $activeFieldControls.children('.remove');
7
- if (event.keyCode == 13) {
8
- event.preventDefault();
9
- $addControl.click()
10
- $removeControl.click()
11
- }
12
- });
13
- });
14
-