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 +4 -4
- data/Rakefile +8 -4
- data/app/controllers/concerns/records_controller_behavior.rb +30 -16
- data/app/forms/hydra_editor/form.rb +73 -0
- data/app/helpers/concerns/records_helper_behavior.rb +3 -3
- data/app/presenters/hydra/presenter.rb +85 -0
- data/app/views/records/_form.html.erb +3 -3
- data/config/jetty.yml +6 -0
- data/lib/hydra_editor/controller_resource.rb +1 -1
- data/lib/hydra_editor/engine.rb +2 -3
- data/lib/hydra_editor/version.rb +1 -1
- metadata +30 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a019714d3a9953d60b3ec89910581f30917d704
|
4
|
+
data.tar.gz: 2ea18791705d16c26af05d51aafb692c5d1c99de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
34
|
-
|
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 :
|
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
|
-
|
23
|
+
@form = build_form
|
24
24
|
render 'records/new'
|
25
25
|
end
|
26
26
|
|
27
27
|
def edit
|
28
|
-
|
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
|
-
|
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
|
-
|
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
|
101
|
-
resource
|
102
|
-
|
103
|
-
|
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.
|
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(
|
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
|
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
|
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.
|
6
|
-
<%= render
|
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>
|
data/config/jetty.yml
ADDED
data/lib/hydra_editor/engine.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
module HydraEditor
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
engine_name 'hydra_editor'
|
4
|
-
config.
|
4
|
+
config.eager_load_paths += %W(
|
5
5
|
#{config.root}/app/helpers/concerns
|
6
|
-
#{config.root}/app/
|
7
|
-
#{config.root}/app/models/concerns
|
6
|
+
#{config.root}/app/presenters
|
8
7
|
)
|
9
8
|
initializer "hydra-editor.initialize" do
|
10
9
|
require "cancan"
|
data/lib/hydra_editor/version.rb
CHANGED
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.
|
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:
|
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: '
|
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: '
|
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:
|
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:
|
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:
|
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:
|
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:
|
235
|
+
version: 1.3.1
|
231
236
|
requirements: []
|
232
237
|
rubyforge_project:
|
233
|
-
rubygems_version: 2.
|
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
|