Skip to content

Commit 1e9fe0c

Browse files
committed
Merge branch 'develop'
2 parents 8043f6b + 8908057 commit 1e9fe0c

25 files changed

+357
-35
lines changed

.gitignore

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,68 @@
1+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2+
#
3+
# If you find yourself ignoring temporary files generated by your text editor
4+
# or operating system, you probably want to add a global ignore instead:
5+
# git config --global core.excludesfile '~/.gitignore_global'
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
/vendor/bundle
10+
/vendor/assets
11+
12+
# Ignore the default SQLite database.
13+
/db/*.sqlite3
14+
/db/*.sqlite3-journal
15+
16+
# Ignore all logfiles and tempfiles.
17+
/log/*.log
18+
/tmp
19+
20+
# Debug
21+
.byebug_history
22+
23+
# OS Files
24+
.DS_Store
25+
._.DS_Store
26+
.directory
27+
28+
# Text-editor/IDE generated files
29+
*.sublime-workspace
30+
*.sublime-project
31+
/.idea
32+
*.iml
33+
34+
*.rbc
35+
*.sassc
36+
.sass-cache
37+
capybara-*.html
38+
.powrc
39+
/public/system
40+
/coverage/
41+
/spec/tmp
42+
**.orig
43+
rerun.txt
44+
.env
45+
146
Gemfile.lock
2-
.bundle/
3-
log/*.log
4-
pkg/
47+
.ruby-version
48+
.ruby-gemset
49+
50+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51+
.rvmrc
52+
53+
# React on Rails
54+
npm-debug.log*
55+
node_modules
56+
57+
# Generated js bundles
58+
/app/assets/webpack/*
59+
60+
# Test app
561
test/dummy/db/*.sqlite3
662
test/dummy/db/*.sqlite3-journal
763
test/dummy/log/*.log
864
test/dummy/tmp/
9-
.idea/
65+
66+
# build artifacts
1067
*.gem
68+
pkg/

.npmignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CHANGELOG.md
2+
Gemfile
3+
README.md
4+
app
5+
coverage
6+
docs
7+
examples
8+
node_modules
9+
react_on_rails.gemspec
10+
Dockerfile_tests
11+
Gemfile.lock
12+
Rakefile
13+
bin
14+
docker-compose.yml
15+
etc
16+
lib
17+
rakelib
18+
ruby-lint.yml
19+
spec
20+
node_modules
21+
tmp
22+
gen-examples
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.mdl-textfield.mdl-js-textfield.authorfield
2+
= render_field_id
3+
= render_label
4+
= render_input
5+
= render_default_value

app/cells/plugins/core/author_cell.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module Plugins
2+
module Core
3+
class AuthorCell < Plugins::Core::Cell
4+
include Devise::Controllers::Helpers
5+
6+
def input
7+
render
8+
end
9+
10+
private
11+
12+
def value
13+
data&.[]('author_name') || current_user.fullname
14+
end
15+
16+
def render_label
17+
@options[:form].label 'data[author_name]', field.name, class: 'mdl-textfield__label'
18+
end
19+
20+
def render_input
21+
@options[:form].text_field 'data[author_name]', value: value, placeholder: @options[:placeholder], class: 'mdl-textfield__input', required: required?
22+
end
23+
24+
def render_default_value
25+
@options[:form].hidden_field 'data[default_author_name]', value: current_user.fullname
26+
end
27+
end
28+
end
29+
end

app/cells/plugins/core/cell.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module Plugins
22
module Core
33
class Cell < FieldCell
4+
include ReactOnRailsHelper
5+
46
view_paths << "#{Cortex::Plugins::Core::Engine.root}/app/cells"
57

68
def required?
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
= react_component("HelloWorld2App", props: hello_world_props)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Plugins
2+
module Core
3+
class ReactTestCell < Plugins::Core::Cell
4+
def show
5+
render
6+
end
7+
8+
private
9+
10+
def hello_world_props
11+
{ name: 'Stranger' }
12+
end
13+
end
14+
end
15+
end

app/models/asset_field_type.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def data
3636
'file_size': asset_file_size,
3737
'updated_at': asset_updated_at
3838
},
39+
'media_title': media_title,
3940
'asset_field_type_id': id
4041
}
4142
end
@@ -74,6 +75,10 @@ def allowed_content_types
7475
end
7576
end
7677

78+
def media_title
79+
existing_data['media_title'] || ContentItemService.form_fields[@metadata[:naming_data][:title]][:text].parameterize.underscore
80+
end
81+
7782
def mapping_field_name
7883
"#{field_name.parameterize('_')}_asset_file_name"
7984
end
@@ -128,11 +133,7 @@ def style_urls
128133

129134
def existing_metadata
130135
metadata.except!(:existing_data)
131-
132-
unless existing_data.empty?
133-
metadata[:path].gsub!(":id", existing_data['asset_field_type_id']) if metadata[:path]
134-
end
135-
136+
metadata[:path].gsub!(":media_title", media_title) if metadata[:path]
136137
metadata
137138
end
138139
end

app/models/author_field_type.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class AuthorFieldType < FieldType
2+
attr_accessor :author_name
3+
jsonb_accessor :data, author_name: :string
4+
5+
validates :author_name, presence: true, if: :validate_presence?
6+
7+
def data=(data_hash)
8+
data_hash[:author_name] = data_hash[:default_author_name] if data_hash.deep_symbolize_keys[:author_name].blank?
9+
@author_name = data_hash.deep_symbolize_keys[:author_name]
10+
end
11+
12+
def field_item_as_indexed_json_for_field_type(field_item, options = {})
13+
json = {}
14+
json[mapping_field_name] = field_item.data['author_name']
15+
json
16+
end
17+
18+
def mapping
19+
{author_name: mapping_field_name, type: :string, analyzer: :snowball}
20+
end
21+
22+
private
23+
24+
def mapping_field_name
25+
"#{field_name.parameterize('_')}_author_name"
26+
end
27+
28+
def author_name_present
29+
errors.add(:author_name, 'must be present') if @author_name.empty?
30+
end
31+
32+
def validate_presence?
33+
@validations.key? :presence
34+
end
35+
end

app/models/tree_field_type.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,17 @@ def mapping_field_name
3636
end
3737

3838
def minimum
39-
unless @values.nil?
40-
if @values.length >= @validations[:minimum]
41-
true
42-
else
43-
errors.add(:minimum, "You have selected too few values.")
44-
false
45-
end
39+
if !@values.nil? && @values[:values].length >= @validations[:minimum]
40+
true
41+
else
42+
errors.add(:minimum, "You have selected too few values.")
43+
false
4644
end
4745
end
4846

4947
def maximum
5048
unless @values.nil?
51-
if @values.length <= @validations[:maximum]
49+
if @values[:values].length <= @validations[:maximum]
5250
true
5351
else
5452
errors.add(:maximum, "You have selected too many values.")

0 commit comments

Comments
 (0)