hydra-editor 0.5.2 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1de46f211fcb46c498abbd028ab0648efe381bc7
4
- data.tar.gz: 2747c05d3cb87d8be8f5408d53d19dc3f2004d9a
3
+ metadata.gz: 9a019714d3a9953d60b3ec89910581f30917d704
4
+ data.tar.gz: 2ea18791705d16c26af05d51aafb692c5d1c99de
5
5
  SHA512:
6
- metadata.gz: 51dc5f83a5dd3c650c3a70dc944073e6f4a940c2967d2c9e933372ad0b8ca57f1e09817db2e66c17f3b91e2c51d5980cb45229da5351219117665d02775a801c
7
- data.tar.gz: 5bcfccc581f76ae8d116246f2a0199e15337ae3964781668b4c8c01914718ad0a9b3b8d097d6fcdf87c4f83787a9f4a9f6664a8a980c23ed7a59912f8b6766f2
6
+ metadata.gz: 0b51da1e6c2d35e090980d3540175ce8f39ff083a3d868beb63f45a0f88dcbbc6441ed5bdbbfc53b2f6c78a17c3c4196c6f8250fee8fae7cce32f216e224d019
7
+ data.tar.gz: 775e159e509e65587cb2bd1d42f25e3a5f5d956be12aeb5521a53ed0ec18112cdc27b725daccb5a6c8fde3b635c9979ef65bf1466425b4cc19d7c23b10262a94
data/Rakefile CHANGED
@@ -20,18 +20,22 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
-
24
23
  Bundler::GemHelper.install_tasks
25
24
 
26
25
  require 'rspec/core/rake_task'
27
26
  RSpec::Core::RakeTask.new(:spec)
28
27
 
28
+ require 'jettywrapper'
29
+ Jettywrapper.hydra_jetty_version = "v8.1.1"
30
+
29
31
  require 'engine_cart/rake_task'
30
32
 
31
- task ci: ['engine_cart:generate'] do
33
+ task ci: ['engine_cart:generate', 'jetty:clean'] do
32
34
  ENV['environment'] = "test"
33
- # run the tests
34
- Rake::Task["spec"].invoke
35
+ jetty_params = Jettywrapper.load_config
36
+ error = Jettywrapper.wrap(jetty_params) do
37
+ Rake::Task['spec'].invoke
38
+ end
35
39
  end
36
40
 
37
41
  task default: :ci
@@ -7,7 +7,7 @@ module RecordsControllerBehavior
7
7
  rescue_from HydraEditor::InvalidType do
8
8
  render 'records/choose_type'
9
9
  end
10
- helper_method :resource
10
+ helper_method :form
11
11
  end
12
12
 
13
13
  module ClassMethods
@@ -20,12 +20,12 @@ module RecordsControllerBehavior
20
20
  end
21
21
 
22
22
  def new
23
- initialize_fields
23
+ @form = build_form
24
24
  render 'records/new'
25
25
  end
26
26
 
27
27
  def edit
28
- initialize_fields
28
+ @form = build_form
29
29
  render 'records/edit'
30
30
  end
31
31
 
@@ -60,8 +60,7 @@ module RecordsControllerBehavior
60
60
  protected
61
61
 
62
62
  def object_as_json
63
- # ActiveFedora::Base#to_json causes a circular reference (before 7.0). Do something easy
64
- resource.terms_for_editing.each_with_object({}) { |term, h| h[term] = resource[term] }
63
+ resource.to_json
65
64
  end
66
65
 
67
66
  # Override this method if you want to set different metadata on the object
@@ -70,13 +69,7 @@ module RecordsControllerBehavior
70
69
  end
71
70
 
72
71
  def collect_form_attributes
73
- # removes attributes that were only changed by initialize_fields
74
- permitted_attributes.reject { |key, value| resource[key].empty? and value == [""] }
75
- end
76
-
77
- # we could probably do this with strong parameters if the gemspec depends on Rails 4+
78
- def permitted_attributes
79
- resource.terms_for_editing.each_with_object({}) { |key, attrs| attrs[key] = raw_attributes[key] if raw_attributes[key] }
72
+ form_class.model_attributes(raw_attributes)
80
73
  end
81
74
 
82
75
  def raw_attributes
@@ -97,13 +90,34 @@ module RecordsControllerBehavior
97
90
  HydraEditor.models.include? params[:type]
98
91
  end
99
92
 
100
- def initialize_fields
101
- resource.terms_for_editing.each do |key|
102
- # if value is empty, we create an one element array to loop over for output
103
- resource[key] = [''] if resource[key].empty?
93
+ def build_form
94
+ form_class.new(resource)
95
+ end
96
+
97
+ def form_class
98
+ @form_class ||= form_name.constantize
99
+ rescue NameError
100
+ raise NameError, "Unable to find a #{form_name} class"
101
+ end
102
+
103
+ def form_name
104
+ if resource_instance_name == 'record'.freeze
105
+ if params[:id]
106
+ "#{resource.class.name}Form"
107
+ elsif has_valid_type?
108
+ "#{params[:type]}Form"
109
+ else
110
+ 'RecordForm'
111
+ end
112
+ else
113
+ "#{resource_instance_name.camelize}Form"
104
114
  end
105
115
  end
106
116
 
117
+ def form
118
+ @form
119
+ end
120
+
107
121
  def resource
108
122
  get_resource_ivar
109
123
  end
@@ -0,0 +1,73 @@
1
+ module HydraEditor
2
+ module Form
3
+ extend ActiveSupport::Concern
4
+ include Hydra::Presenter
5
+ included do
6
+ class_attribute :required_fields
7
+ end
8
+
9
+ def initialize(model)
10
+ super
11
+ initialize_fields
12
+ end
13
+
14
+ def required?(key)
15
+ required_fields.include?(key)
16
+ end
17
+
18
+ def [](key)
19
+ @attributes[key.to_s]
20
+ end
21
+
22
+ def []=(key, value)
23
+ @attributes[key.to_s] = value
24
+ end
25
+
26
+ module ClassMethods
27
+ def model_attributes(form_params)
28
+ clean_params = sanitize_params(form_params)
29
+ terms.each do |key|
30
+ if clean_params[key] == ['']
31
+ clean_params[key] = []
32
+ end
33
+ end
34
+ clean_params
35
+ end
36
+
37
+ def sanitize_params(form_params)
38
+ form_params.permit(*permitted_params)
39
+ end
40
+
41
+ def permitted_params
42
+ @permitted ||= build_permitted_params
43
+ end
44
+
45
+ def build_permitted_params
46
+ permitted = []
47
+ terms.each do |term|
48
+ if multiple?(term)
49
+ permitted << { term => [] }
50
+ else
51
+ permitted << term
52
+ end
53
+ end
54
+ permitted << { permissions_attributes: [:type, :name, :access] }
55
+ permitted
56
+ end
57
+ end
58
+
59
+ protected
60
+ # override this method if you need to initialize more complex RDF assertions (b-nodes)
61
+ def initialize_fields
62
+ @attributes = model.attributes
63
+ terms.select { |key| self[key].blank? }.each do |key|
64
+ # if value is empty, we create an one element array to loop over for output
65
+ if self.class.multiple?(key)
66
+ self[key] = ['']
67
+ else
68
+ self[key] = ''
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -35,7 +35,7 @@ module RecordsHelperBehavior
35
35
 
36
36
  def record_form_action_url(record)
37
37
  router = respond_to?(:hydra_editor) ? hydra_editor : self
38
- record.new_record? ? router.records_path : router.record_path(record)
38
+ record.persisted? ? router.record_path(record) : router.records_path
39
39
  end
40
40
 
41
41
  def new_record_title
@@ -47,7 +47,7 @@ module RecordsHelperBehavior
47
47
  end
48
48
 
49
49
  def render_record_title
50
- Array(resource.title).first
50
+ Array(form.title).first
51
51
  end
52
52
 
53
53
  protected
@@ -56,7 +56,7 @@ module RecordsHelperBehavior
56
56
  # if no partial exists for the record_type it tries using "records" as a default
57
57
  def render_edit_field_partial_with_action(record_type, field_name, locals)
58
58
  partial = find_edit_field_partial(record_type, field_name)
59
- render partial: partial, locals: locals.merge({key: field_name})
59
+ render partial, locals.merge(key: field_name)
60
60
  end
61
61
 
62
62
  def find_edit_field_partial(record_type, field_name)
@@ -0,0 +1,85 @@
1
+ module Hydra
2
+ module ActiveModelPresenter
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ attr_reader :model
6
+ class_attribute :model_class
7
+ end
8
+
9
+ def initialize(object)
10
+ @model = object
11
+ end
12
+
13
+ def to_key
14
+ model.to_key
15
+ end
16
+
17
+ def to_param
18
+ model.to_param
19
+ end
20
+
21
+ def to_model
22
+ model.to_model
23
+ end
24
+
25
+ def persisted?
26
+ model.persisted?
27
+ end
28
+
29
+ def [](key)
30
+ model[key]
31
+ end
32
+
33
+ module ClassMethods
34
+ def model_name
35
+ if model_class.nil?
36
+ raise "You must set `self.model_class = ' after including Hydra::Presenter on #{self}."
37
+ end
38
+ model_class.model_name
39
+ end
40
+ end
41
+ end
42
+
43
+ module Presenter
44
+ extend ActiveSupport::Concern
45
+ include ActiveModelPresenter
46
+ included do
47
+ class_attribute :_terms, instance_accessor: false
48
+ end
49
+
50
+ def terms
51
+ self.class._terms
52
+ end
53
+
54
+ module ClassMethods
55
+ def multiple?(field)
56
+ model_class.multiple?(field)
57
+ end
58
+
59
+ def unique?(field)
60
+ model_class.unique?(field)
61
+ end
62
+
63
+ def terms=(terms)
64
+ self._terms = terms
65
+ create_term_accessors(terms)
66
+ end
67
+
68
+ def terms
69
+ self._terms
70
+ end
71
+
72
+ private
73
+
74
+ def create_term_accessors(terms)
75
+ # we delegate to the array accessor, because the array accessor is overridden in MultiForm
76
+ # which is included by GenericFileEditForm
77
+ terms.each do |term|
78
+ define_method term do
79
+ self[term]
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -1,9 +1,9 @@
1
- <%= bootstrap_form_for resource, url: record_form_action_url(resource), html: {class: 'form-inline editor'} do |f| %>
1
+ <%= bootstrap_form_for form, url: record_form_action_url(form), html: {class: 'form-inline editor'} do |f| %>
2
2
  <div id="descriptions_display">
3
3
  <%= render 'records/form_header' %>
4
4
  <div class="well">
5
- <% f.object.terms_for_editing.each do |term| %>
6
- <%= render partial: "records/edit_field", locals: {f: f, render_req: true, key: term } %>
5
+ <% f.object.terms.each do |term| %>
6
+ <%= render "records/edit_field", f: f, render_req: true, key: term %>
7
7
  <% end %>
8
8
  </div> <!-- /well -->
9
9
  </div>
@@ -0,0 +1,6 @@
1
+ default:
2
+ startup_wait: 90
3
+ jetty_port: 8983
4
+ java_opts:
5
+ - "-Xmx256m"
6
+ - "-XX:MaxPermSize=128m"
@@ -1,6 +1,6 @@
1
1
  class HydraEditor::ControllerResource < CanCan::ControllerResource
2
2
  def find_resource
3
- ActiveFedora::Base.find(id_param, cast: true)
3
+ ActiveFedora::Base.find(id_param)
4
4
  end
5
5
 
6
6
  def resource_class
@@ -1,10 +1,9 @@
1
1
  module HydraEditor
2
2
  class Engine < ::Rails::Engine
3
3
  engine_name 'hydra_editor'
4
- config.autoload_paths += %W(
4
+ config.eager_load_paths += %W(
5
5
  #{config.root}/app/helpers/concerns
6
- #{config.root}/app/controllers/concerns
7
- #{config.root}/app/models/concerns
6
+ #{config.root}/app/presenters
8
7
  )
9
8
  initializer "hydra-editor.initialize" do
10
9
  require "cancan"
@@ -1,3 +1,3 @@
1
1
  module HydraEditor
2
- VERSION = "0.5.2"
2
+ VERSION = "1.0.0.beta1"
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: 0.5.2
4
+ version: 1.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -9,28 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-14 00:00:00.000000000 Z
12
+ date: 2014-12-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: 3.2.13
21
- - - "<"
18
+ - - "~>"
22
19
  - !ruby/object:Gem::Version
23
- version: '5.0'
20
+ version: '4.1'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: 3.2.13
31
- - - "<"
25
+ - - "~>"
32
26
  - !ruby/object:Gem::Version
33
- version: '5.0'
27
+ version: '4.1'
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: bootstrap_form
36
30
  requirement: !ruby/object:Gem::Requirement
@@ -51,20 +45,14 @@ dependencies:
51
45
  requirements:
52
46
  - - ">="
53
47
  - !ruby/object:Gem::Version
54
- version: 6.3.0
55
- - - "<"
56
- - !ruby/object:Gem::Version
57
- version: '9.0'
48
+ version: 9.0.0.beta8
58
49
  type: :runtime
59
50
  prerelease: false
60
51
  version_requirements: !ruby/object:Gem::Requirement
61
52
  requirements:
62
53
  - - ">="
63
54
  - !ruby/object:Gem::Version
64
- version: 6.3.0
65
- - - "<"
66
- - !ruby/object:Gem::Version
67
- version: '9.0'
55
+ version: 9.0.0.beta8
68
56
  - !ruby/object:Gem::Dependency
69
57
  name: cancancan
70
58
  requirement: !ruby/object:Gem::Requirement
@@ -155,14 +143,14 @@ dependencies:
155
143
  requirements:
156
144
  - - ">="
157
145
  - !ruby/object:Gem::Version
158
- version: '0'
146
+ version: 9.0.0.beta2
159
147
  type: :development
160
148
  prerelease: false
161
149
  version_requirements: !ruby/object:Gem::Requirement
162
150
  requirements:
163
151
  - - ">="
164
152
  - !ruby/object:Gem::Version
165
- version: '0'
153
+ version: 9.0.0.beta2
166
154
  - !ruby/object:Gem::Dependency
167
155
  name: engine_cart
168
156
  requirement: !ruby/object:Gem::Requirement
@@ -177,6 +165,20 @@ dependencies:
177
165
  - - ">="
178
166
  - !ruby/object:Gem::Version
179
167
  version: '0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: jettywrapper
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '1.8'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '1.8'
180
182
  description: A basic metadata editor for hydra-head
181
183
  email:
182
184
  - hydra-tech@googlegroups.com
@@ -194,8 +196,10 @@ files:
194
196
  - app/assets/stylesheets/hydra-editor/hydra-editor.css
195
197
  - app/controllers/concerns/records_controller_behavior.rb
196
198
  - app/controllers/records_controller.rb
199
+ - app/forms/hydra_editor/form.rb
197
200
  - app/helpers/concerns/records_helper_behavior.rb
198
201
  - app/helpers/records_helper.rb
202
+ - app/presenters/hydra/presenter.rb
199
203
  - app/views/records/_edit_field.html.erb
200
204
  - app/views/records/_form.html.erb
201
205
  - app/views/records/_form_header.html.erb
@@ -204,6 +208,7 @@ files:
204
208
  - app/views/records/edit_fields/_default.html.erb
205
209
  - app/views/records/edit_fields/_suffix.html.erb
206
210
  - app/views/records/new.html.erb
211
+ - config/jetty.yml
207
212
  - config/locales/hydra_editor.yml
208
213
  - config/routes.rb
209
214
  - lib/hydra-editor.rb
@@ -225,12 +230,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
230
  version: '0'
226
231
  required_rubygems_version: !ruby/object:Gem::Requirement
227
232
  requirements:
228
- - - ">="
233
+ - - ">"
229
234
  - !ruby/object:Gem::Version
230
- version: '0'
235
+ version: 1.3.1
231
236
  requirements: []
232
237
  rubyforge_project:
233
- rubygems_version: 2.4.6
238
+ rubygems_version: 2.2.2
234
239
  signing_key:
235
240
  specification_version: 4
236
241
  summary: A basic metadata editor for hydra-head