Skip to content

Commit ac961dc

Browse files
committed
Merge branch 'develop'
2 parents 153c852 + 48cfffe commit ac961dc

File tree

18 files changed

+166
-36
lines changed

18 files changed

+166
-36
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ gem 'rails', '~> 5.0.1'
1212

1313
# Cortex-specific
1414
gem 'cortex-exceptions', '= 0.0.4'
15-
gem 'cortex-plugins-core', '= 0.11.0'
15+
gem 'cortex-plugins-core', '= 0.11.1'
1616

1717
# API
1818
gem 'grape', '~> 0.17'

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ GEM
137137
concurrent-ruby (1.0.4)
138138
connection_pool (2.2.1)
139139
cortex-exceptions (0.0.4)
140-
cortex-plugins-core (0.11.0)
140+
cortex-plugins-core (0.11.1)
141141
cells (~> 4.1)
142142
cells-haml (~> 0.0.10)
143143
cells-rails (~> 0.0.6)
@@ -723,7 +723,7 @@ DEPENDENCIES
723723
cells-rails (~> 0.0.7)
724724
codeclimate-test-reporter (~> 0.6)
725725
cortex-exceptions (= 0.0.4)
726-
cortex-plugins-core (= 0.11.0)
726+
cortex-plugins-core (= 0.11.1)
727727
database_cleaner (~> 1.5)
728728
devise (~> 4.2.0)
729729
dialog-polyfill-rails (~> 0.4.5)
@@ -814,4 +814,4 @@ RUBY VERSION
814814
ruby 2.4.0p0
815815

816816
BUNDLED WITH
817-
1.14.3
817+
1.14.6

Procfile.dev

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
web: bundle exec rails s -p 3000
2+
worker: bundle exec sidekiq -e development --config ./config/sidekiq.yml
23
client: rake assets:clobber react_on_rails:assets:clobber cortex:assets:webpack:build

app/assets/legacy_templates/media/bulk.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="panel panel-default">
44
<div class="panel-heading">Select CSV detailing assets' metadata</div>
55
<div class="panel-body">
6-
Please <a href="/bulk_templates/media.csv">click here</a> for a Bulk Media Upload CSV template, which includes some basic examples.
6+
Please <a href="/bulk_templates/media.csv">click here</a> for a Bulk Media Upload CSV template, which includes some basic examples. Empty cell values will be ignored, while cell values of 'N/A' will clear out existing record values.
77
<file-selector ng-model="data.mediaBulk.metadata"
88
required>
99
</file-selector>

app/assets/stylesheets/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@import 'layout';
1515

1616
@import 'components/card';
17+
@import 'components/confetti';
1718
@import 'components/content';
1819
@import 'components/dialog';
1920
@import 'components/flash';
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@include keyframes(bang) {
2+
from {
3+
@include transform( translate3d(0,0,0) );
4+
opacity: 1;
5+
}
6+
}
7+
8+
.confetti {
9+
width: 100%;
10+
position: absolute;
11+
12+
i {
13+
position: absolute;
14+
display: block;
15+
width: 5px;
16+
height: 7px;
17+
opacity: 0;
18+
}
19+
20+
@for $i from 1 through 50 {
21+
i:nth-of-type(#{$i}) {
22+
@include transform( translate3d(random(190) - 100 + px,random(50) - 100 + px,0) rotate(random(360) + deg) );
23+
background: hsla(random(360),100%,50%,1);
24+
@include animation(bang 2500ms ease-out forwards);
25+
opacity: 0;
26+
}
27+
}
28+
}
29+
30+
.confetti--left i {
31+
left: 0;
32+
}
33+
34+
.confetti--center i {
35+
left: 50%;
36+
}
37+
38+
.confetti--right i {
39+
right: 0;
40+
}

app/cells/wizard/field/show.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@
2525

2626
- if field_item.field.field_type_instance.class == ContentItemFieldType
2727
= cell(Plugins::Core::ContentItemCell, field_item, form: field_item_form).(:popup)
28+
29+
- if field_item.field.field_type_instance.class == AuthorFieldType
30+
= cell(Plugins::Core::AuthorCell, field_item, form: field_item_form).(:input)

app/controllers/content_items_controller.rb

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,40 @@ def edit
3030
end
3131

3232
def update
33-
if content_item.update
34-
flash[:success] = "ContentItem updated"
33+
begin
34+
content_item.update
35+
rescue => e
36+
flash[:warning] = validation_message(e.message)
37+
@content_item = content_item_reload(content_type.content_items.find_by_id(params[:id]))
38+
@wizard = WizardDecoratorService.new(content_item: @content_item)
39+
40+
title = @content_item.field_items.find { |field_item| field_item.field.name == 'Title' }.data['text']
41+
add_breadcrumb content_type.name.pluralize, :content_type_content_items_path
42+
add_breadcrumb title
43+
add_breadcrumb 'Edit'
44+
45+
render :edit
3546
else
36-
flash[:warning] = "ContentItem failed to update! Reason: #{@content_item.errors.full_messages}"
47+
flash[:success] = "Hooray! #{content_type.name} Updated!"
48+
redirect_to content_type_content_items_path
3749
end
38-
39-
redirect_to content_type_content_items_path
4050
end
4151

4252
def create
4353
begin
4454
content_item.create
4555
rescue => e
46-
flash[:warning] = e.message
47-
@content_item = content_item_reload
56+
flash[:warning] = validation_message(e.message)
57+
@content_item = content_item_reload(content_type.content_items.new)
4858
@wizard = WizardDecoratorService.new(content_item: @content_item)
4959

60+
add_breadcrumb content_type.name.pluralize, :content_type_content_items_path
61+
add_breadcrumb 'New'
62+
5063
render :new
5164
else
52-
flash[:success] = 'ContentItem created'
53-
redirect_to content_type_content_items_path
65+
flash[:success] = "Hooray! #{content_type.name} Created!"
66+
redirect_to content_type_content_items_path
5467
end
5568
end
5669
end

app/helpers/content_item_helper.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ def content_item
77
@content_item ||= ContentItemService.new(id: params[:id], content_item_params: content_item_params, current_user: current_user, state: params[:content_item][:state])
88
end
99

10-
def content_item_reload
11-
@content_item = content_type.content_items.new
10+
def content_item_reload(content_item)
11+
@content_item = content_item
1212
content_type.fields.each do |field|
1313
@content_item.field_items << FieldItem.new(field: field, data: field_item_param_data(params_lookup[field.id]))
1414
end
@@ -51,7 +51,7 @@ def permit_param(param)
5151
if param.values[0].is_a?(Hash)
5252
{ param.keys[0].to_sym => param.values[0].keys }
5353
else
54-
param.keys[0]
54+
param.keys
5555
end
5656
end
5757

@@ -83,4 +83,8 @@ def field_item_param_data(field_item_params)
8383
params_hash['data'] || {}
8484
end
8585

86+
def validation_message(base_message)
87+
msg_array = base_message.gsub('Validation failed:', '').gsub('Field items', '').split(',')
88+
msg_array.map { |message| message.strip.titleize }
89+
end
8690
end

app/jobs/bulk_create_media_job.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def generate_media_attributes(zip_file, row_hash)
5454
type: row_hash['Type (Media, Youtube)']
5555
}
5656

57+
media_attributes = strip_attributes(media_attributes)
58+
5759
if row_hash['Type (Media, Youtube)'] == 'Media'
5860
begin
5961
media_attachment = zip_file.get_entry(row_hash['Filename'])
@@ -76,4 +78,11 @@ def write_status(message)
7678

7779
@bulk_job.save!
7880
end
81+
82+
def strip_attributes(attributes)
83+
# Don't update nil attributes, but do clear out attributes with a value of 'N/A'
84+
attributes.compact.transform_values do |attribute_value|
85+
attribute_value == 'N/A' ? nil : attribute_value
86+
end
87+
end
7988
end

0 commit comments

Comments
 (0)