Skip to content

Commit 621430f

Browse files
committed
Implement storage of thumbnail/style URLs, asset wizard info box, and asset thumbnail in index
1 parent 43a5c93 commit 621430f

File tree

5 files changed

+141
-22
lines changed

5 files changed

+141
-22
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- if asset
2+
= image_tag(asset['style_urls'][config[:thumbnail_style]], height: '50px')
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
- if asset
2+
:javascript
3+
document.addEventListener("DOMContentLoaded", function(event) {
4+
new Clipboard('#copy-asset-url');
5+
});
6+
7+
.asset-info.mdl-card.mdl-shadow--2dp
8+
.mdl-card__title
9+
%h2.mdl-card__title-text
10+
= image_tag(asset['url'], style: 'max-height: 200px;')
11+
.mdl-card__supporting-text
12+
%dl
13+
%dt Original Filename
14+
%dd
15+
= asset['file_name']
16+
%dt File Type
17+
%dd
18+
= asset['content_type']
19+
%dt File Size
20+
%dd
21+
= number_to_human_size(asset['file_size'])
22+
%dt Dimensions
23+
%dd
24+
= dimensions
25+
%dt Creator
26+
%dd
27+
= creator.fullname
28+
%dt Created
29+
%dd
30+
= created_at
31+
%dt Last Modified
32+
%dd
33+
= updated_at
34+
%dt URL
35+
%dd
36+
= link_to_asset
37+
.mdl-card__menu
38+
.mdl-button.mdl-button--icon.mdl-js-button.mdl-js-ripple-effect#copy-asset-url{data: {'clipboard-text': asset['url']}}
39+
%i.material-icons content_copy
40+
.mdl-tooltip{for: 'copy-asset-url'}
41+
Copy Asset URL
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module Plugins
2+
module Core
3+
class AssetInfoCell < Plugins::Core::Cell
4+
include ActionView::Helpers::NumberHelper
5+
6+
property :data
7+
property :content_item
8+
9+
def show
10+
render
11+
end
12+
13+
def index
14+
render
15+
end
16+
17+
private
18+
19+
def config
20+
@options[:config] || {}
21+
end
22+
23+
def asset
24+
data['asset']
25+
end
26+
27+
def dimensions
28+
"#{asset['dimensions']['width']} x #{asset['dimensions']['width']}"
29+
end
30+
31+
def creator
32+
content_item.creator
33+
end
34+
35+
def created_at
36+
content_item.created_at.to_formatted_s(:long_ordinal)
37+
end
38+
39+
def updated_at
40+
DateTime.parse(asset['updated_at']).to_formatted_s(:long_ordinal)
41+
end
42+
43+
def link_to_asset
44+
link_to(asset['url'], asset['url'])
45+
end
46+
end
47+
end
48+
end

app/models/asset_field_type.rb

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class AssetFieldType < FieldType
55
:asset_updated_at,
66
:asset
77

8-
attr_reader :dimensions
8+
attr_reader :dimensions,
9+
:existing_data
910

1011
before_save :extract_dimensions
1112

@@ -26,15 +27,16 @@ def data=(data_hash)
2627

2728
def data
2829
{
29-
'asset': {
30-
'file_name': asset_file_name,
31-
'url': asset.url,
32-
'dimensions': dimensions,
33-
'content_type': asset_content_type,
34-
'file_size': asset_file_size,
35-
'updated_at': asset_updated_at
36-
},
37-
'asset_field_type_id': id
30+
'asset': {
31+
'file_name': asset_file_name,
32+
'url': asset.url,
33+
'style_urls': style_urls,
34+
'dimensions': dimensions,
35+
'content_type': asset_content_type,
36+
'file_size': asset_file_size,
37+
'updated_at': asset_updated_at
38+
},
39+
'asset_field_type_id': id
3840
}
3941
end
4042

@@ -60,8 +62,8 @@ def extract_dimensions
6062
unless tempfile.nil?
6163
geometry = Paperclip::Geometry.from_file(tempfile)
6264
@dimensions = {
63-
width: geometry.width.to_i,
64-
height: geometry.height.to_i
65+
width: geometry.width.to_i,
66+
height: geometry.height.to_i
6567
}
6668
end
6769
end
@@ -77,7 +79,7 @@ def mapping_field_name
7779
end
7880

7981
def validate_presence?
80-
@validations.key? :presence
82+
validations.key? :presence
8183
end
8284

8385
def attachment_size_validator
@@ -116,11 +118,19 @@ def validate_asset_content_type
116118
attachment_content_type_validator.validate_each(self, :asset, asset)
117119
end
118120

121+
def style_urls
122+
if existing_data.empty?
123+
(metadata[:styles].map { |key, value| [key, asset.url(key)] }).to_h
124+
else
125+
existing_data[:asset][:style_urls]
126+
end
127+
end
128+
119129
def existing_metadata
120130
metadata.except!(:existing_data)
121131

122-
unless @existing_data.empty?
123-
metadata[:path].gsub(":id", @existing_data['asset_field_type_id']) if metadata[:path]
132+
unless existing_data.empty?
133+
metadata[:path].gsub(":id", existing_data['asset_field_type_id']) if metadata[:path]
124134
end
125135

126136
metadata

lib/tasks/cortex/core/media.rake

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace :cortex do
7373
"description": "Provide details and metadata that will enhance search or inform end-users.",
7474
"columns": [
7575
{
76-
"grid_width": 12,
76+
"grid_width": 6,
7777
"elements": [
7878
{
7979
"id": media.fields[1].id
@@ -95,6 +95,20 @@ namespace :cortex do
9595
"id": media.fields[5].id
9696
}
9797
]
98+
},
99+
{
100+
"grid_width": 6,
101+
"elements": [
102+
{
103+
"plugin": {
104+
"class_name": "plugins/core/asset_info",
105+
"render_method": "show",
106+
"data": {
107+
"field_id": media.fields.find_by_name('Asset').id
108+
}
109+
}
110+
},
111+
]
98112
}
99113
]
100114
}
@@ -118,12 +132,16 @@ namespace :cortex do
118132
"name": "Thumbnail",
119133
"cells": [{
120134
"field": {
121-
"method": "author_image"
122-
},
123-
"display": {
124-
"classes": [
125-
"circular"
126-
]
135+
"plugin": {
136+
"class_name": "plugins/core/asset_info",
137+
"render_method": "index",
138+
"data": {
139+
"field_id": media.fields.find_by_name('Asset').id
140+
},
141+
"config": {
142+
"thumbnail_style": "mini"
143+
}
144+
}
127145
}
128146
}]
129147
},

0 commit comments

Comments
 (0)