Skip to content

Commit 9ea0924

Browse files
committed
Merge branch 'develop'
2 parents 00acd79 + a8882c7 commit 9ea0924

File tree

10 files changed

+45
-23
lines changed

10 files changed

+45
-23
lines changed

Gemfile

+1-1
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.8.0'
15+
gem 'cortex-plugins-core', '= 0.9.0'
1616

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

Gemfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ GEM
136136
concurrent-ruby (1.0.4)
137137
connection_pool (2.2.1)
138138
cortex-exceptions (0.0.4)
139-
cortex-plugins-core (0.8.0)
139+
cortex-plugins-core (0.9.0)
140140
cells (~> 4.1)
141141
cells-haml (~> 0.0.10)
142142
cells-rails (~> 0.0.6)
@@ -704,7 +704,7 @@ DEPENDENCIES
704704
cells-rails (~> 0.0.6)
705705
codeclimate-test-reporter (~> 0.6)
706706
cortex-exceptions (= 0.0.4)
707-
cortex-plugins-core (= 0.8.0)
707+
cortex-plugins-core (= 0.9.0)
708708
database_cleaner (~> 1.5)
709709
devise (~> 4.2.0)
710710
doorkeeper (~> 4.2)

app/assets/javascripts/media_popups.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ $(".media-select--wysiwyg").on("click", function (ev) {
5555
var element = $(this),
5656
id = element.data().id,
5757
title = element.data().title,
58-
src = element.data().src,
59-
alt = element.data().alt;
58+
url = element.data().url,
59+
alt = element.data().alt,
60+
asset_type = element.data().assetType;
6061

61-
media_select_defer.resolve({id: id, title: title, src: src, alt: alt});
62+
media_select_defer.resolve({id: id, title: title, url: url, alt: alt, asset_type: asset_type});
6263
});

app/cells/index/table_body.haml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
%tbody
2-
- context[:content_type].content_items.each do |content_item|
2+
- context[:content_items].each do |content_item|
33
%tr
44
- @options[:data][:columns].each do |column|
55
%td{ class: 'mdl-data-table__cell--non-numeric' }
66
= cell('index/content_item', nil, { cells: column[:cells], content_item: content_item }).(:column)
77
- if context[:popup]
88
%td{ class: 'mdl-data-table__cell--non-numeric' }
9-
%a{ href: "#", data: { id: content_item.id, title: content_item_title(content_item), thumb: content_item_thumb_url(content_item), src: content_item_asset_url(content_item), alt: content_item_asset_alt_text(content_item) }, class: "media-select--#{context[:popup]} mdl-button mdl-js-button mdl-button--icon" }
9+
%a{ href: "#", data: { id: content_item.id, title: content_item_title(content_item), thumb: content_item_thumb_url(content_item), url: content_item_asset_url(content_item), alt: content_item_asset_alt_text(content_item), asset_type: content_item_asset_type(content_item) }, class: "media-select--#{context[:popup]} mdl-button mdl-js-button mdl-button--icon" }
1010
%i{ class: 'material-icons' }
1111
add
1212
- else

app/cells/index_cell.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,24 @@ def render_table_header(column_data)
1919
column_data[:name]
2020
end
2121

22+
def asset_field_item(content_item)
23+
content_item.field_items.find { |field_item| field_item.field.name == 'Asset' }
24+
end
25+
2226
def content_item_title(content_item)
2327
content_item.field_items.find { |field_item| field_item.field.name == 'Title' }.data['text']
2428
end
2529

2630
def content_item_thumb_url(content_item)
27-
content_item.field_items.find { |field_item| field_item.field.name == 'Asset' }.data['asset']['style_urls']['mini']
31+
asset_field_item(content_item).data['asset']['style_urls']['mini']
2832
end
2933

3034
def content_item_asset_url(content_item)
31-
content_item.field_items.find { |field_item| field_item.field.name == 'Asset' }.data['asset']['url']
35+
asset_field_item(content_item).data['asset']['url']
36+
end
37+
38+
def content_item_asset_type(content_item)
39+
MimeMagic.new(asset_field_item(content_item).data['asset']['content_type']).mediatype
3240
end
3341

3442
def content_item_asset_alt_text(content_item)

app/controllers/content_items_controller.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class ContentItemsController < AdminController
44

55
def index
66
@index = IndexDecoratorService.new(content_type: content_type)
7+
@content_items = content_type.content_items
78
add_breadcrumb content_type.name.pluralize
89
end
910

@@ -22,8 +23,10 @@ def edit
2223
@content_item = content_type.content_items.find_by_id(params[:id])
2324
@wizard = WizardDecoratorService.new(content_item: @content_item)
2425

26+
title = @content_item.field_items.find { |field_item| field_item.field.name == 'Title' }.data['text']
2527
add_breadcrumb content_type.name.pluralize, :content_type_content_items_path
26-
add_breadcrumb "Edit #{@content_item.id}"
28+
add_breadcrumb title
29+
add_breadcrumb 'Edit'
2730
end
2831

2932
def update

app/helpers/popup_helper.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
module PopupHelper
22
def media_content_type
3-
@media_content_type ||= ContentType.find_by_name("Media")
3+
@media_content_type ||= ContentType.find_by_name('Media')
4+
end
5+
6+
def media_content_items
7+
@media_content_items ||= media_content_type.content_items
8+
end
9+
10+
def media_asset_field
11+
@media_asset_field ||= media_content_type.fields.find_by_name('Asset')
12+
end
13+
14+
def media_image_content_items
15+
@media_image_content_items ||= media_content_items.select do |content_item|
16+
MimeMagic.new(content_item.field_items.find_by_field_id(media_asset_field).data['asset']['content_type']).mediatype == 'image'
17+
end
418
end
519

620
def media_index

app/helpers/widget_parsers/media_helper.rb

+3-7
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ def self.widget_nodes_for(document)
2121
def self.render_widget_inner(widget)
2222
Nokogiri::HTML::Builder.new do |doc|
2323
element, tag_type = content_item_element(widget['id'])
24-
if widget['scale']
25-
element.merge!({scale: widget['scale']})
26-
else
27-
element.merge!({width: widget['width'], height: widget['height']})
28-
end
24+
element.merge!({width: widget['width'], height: widget['height'], alt: widget['alt'], style: widget['style'], class: widget['class']})
2925

3026
doc.send(tag_type, element)
3127
end.doc.root
@@ -37,10 +33,10 @@ def self.content_item_element(id)
3733

3834
if asset_field_item.data["asset"]["content_type"].include?("image")
3935
element = { src: url }
40-
tag_type = "img"
36+
tag_type = 'img'
4137
else
4238
element = { href: url }
43-
tag_type = "a"
39+
tag_type = 'a'
4440
end
4541

4642
[element, tag_type]
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
= cell("index", @index, context: { content_type: content_type }).(:index)
1+
= cell("index", @index, context: { content_type: content_type, content_items: @content_items }).(:index)

app/views/content_items/_popup.haml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
.dialog-backdrop.hidden{ 'data-type': 'wysiwyg'}
33
%div.dialog-div.mdl-dialog#mediaInsert
44
.mdl-dialog__content.mdl-dialog-media
5-
= cell('index', media_index, context: { content_type: media_content_type, popup: 'wysiwyg' }).(:index)
5+
= cell('index', media_index, context: { content_type: content_type, content_items: media_content_items, popup: 'wysiwyg' }).(:index)
66
.mdl-dialog__actions.mdl-dialog__actions.modal-footer
77
.mdl-button.mdl-js-button.mdl-button--raised.close CLOSE
88
.dialog-backdrop.hidden{ 'data-type': 'featured' }
99
%div.dialog-div.mdl-dialog#mediaFeatured
1010
.mdl-dialog__content.mdl-dialog-media
11-
= cell('index', media_index, context: { content_type: media_content_type, popup: 'featured' }).(:index)
11+
= cell('index', media_index, context: { content_type: content_type, content_items: media_image_content_items, popup: 'featured' }).(:index)
1212
.mdl-dialog__actions.mdl-dialog__actions.modal-footer
1313
.mdl-button.mdl-js-button.mdl-button--raised.close CLOSE
1414
.dialog-backdrop.hidden{ 'data-type': 'tile' }
1515
%div.dialog-div.mdl-dialog#mediaTile
1616
.mdl-dialog__content.mdl-dialog-media
17-
= cell('index', media_index, context: { content_type: media_content_type, popup: 'tile' }).(:index)
17+
= cell('index', media_index, context: { content_type: content_type, content_items: media_image_content_items, popup: 'tile' }).(:index)
1818
.mdl-dialog__actions.mdl-dialog__actions.modal-footer
1919
.mdl-button.mdl-js-button.mdl-button--raised.close CLOSE

0 commit comments

Comments
 (0)