cortex-plugins-core 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ad03faa329368738afd7686e52d7e6f372d8b79
4
- data.tar.gz: ab0a2bd0e9d66d960fb8523f5112af6743b07b3d
3
+ metadata.gz: 1d1a73688bdd9211a0a2d10cc2684e1f4da60273
4
+ data.tar.gz: e90bb298eded507752ba92394a8060c79caf98b3
5
5
  SHA512:
6
- metadata.gz: 28a8bef94abea9e65bd54ea129ca375b2d976ad6221d46325df071cbafe66b5b91a77cfb74c06bc4da16e32f4f3acb52c9eeccb325984655fec90c18f0cf1891
7
- data.tar.gz: 9ab399e6f59acf27a72db85da70c6263ed649495e4a665a1188b32e0de1391879ad00bcc0c543fd192d155656ad855153554eb0884ab8988270608ec5df28ea3
6
+ metadata.gz: 6583a84706ff696839b07effd2a6a972e8a7d4be9d0ebcbec729d33bd6942daa1a016ead31411f8b99c0a5222f94542fdd8d4f651e64dd59d5f001e496abc310
7
+ data.tar.gz: a29a15fa4cf916975acd3b6b4c1d011486764a5d5da7f31c8bf174ff5595beb4ba9f95447600dfa38bced1b683aeeda859b8d6a987b53d6de0a1180179317b86
@@ -0,0 +1,2 @@
1
+ - if asset
2
+ = image_tag(asset['style_urls'][config[:thumbnail_style]], height: '50px')
@@ -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
@@ -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
@@ -5,7 +5,8 @@ class AssetFieldType < FieldType
5
5
  :asset_updated_at,
6
6
  :asset
7
7
 
8
- attr_reader :dimensions
8
+ attr_reader :dimensions,
9
+ :existing_data
9
10
 
10
11
  before_save :extract_dimensions
11
12
 
@@ -26,14 +27,16 @@ class AssetFieldType < FieldType
26
27
 
27
28
  def data
28
29
  {
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
- }
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
37
40
  }
38
41
  end
39
42
 
@@ -59,8 +62,8 @@ class AssetFieldType < FieldType
59
62
  unless tempfile.nil?
60
63
  geometry = Paperclip::Geometry.from_file(tempfile)
61
64
  @dimensions = {
62
- width: geometry.width.to_i,
63
- height: geometry.height.to_i
65
+ width: geometry.width.to_i,
66
+ height: geometry.height.to_i
64
67
  }
65
68
  end
66
69
  end
@@ -76,7 +79,7 @@ class AssetFieldType < FieldType
76
79
  end
77
80
 
78
81
  def validate_presence?
79
- @validations.key? :presence
82
+ validations.key? :presence
80
83
  end
81
84
 
82
85
  def attachment_size_validator
@@ -115,21 +118,21 @@ class AssetFieldType < FieldType
115
118
  attachment_content_type_validator.validate_each(self, :asset, asset)
116
119
  end
117
120
 
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
+
118
129
  def existing_metadata
119
130
  metadata.except!(:existing_data)
120
131
 
121
- unless @existing_data.empty?
122
- metadata[:path] = updated_url(@existing_data['asset']['url'])
132
+ unless existing_data.empty?
133
+ metadata[:path].gsub(":id", existing_data['asset_field_type_id']) if metadata[:path]
123
134
  end
124
135
 
125
136
  metadata
126
137
  end
127
-
128
- def updated_url(path)
129
- # Take the parse path of the existing URL and drop the first '/',
130
- # that will be added later and we don't want to duplicate it
131
- # Then remove the old file extension and replace it with the paperclipp'd new one
132
- new_path = URI.parse(path).path.slice(1..-1)
133
- new_path.gsub(File.extname(path), ".:extension")
134
- end
135
138
  end
@@ -0,0 +1,154 @@
1
+ class AssetFieldType < FieldType
2
+ attr_accessor :asset_file_name,
3
+ :asset_content_type,
4
+ :asset_file_size,
5
+ :asset_updated_at,
6
+ :asset
7
+
8
+ attr_reader :dimensions,
9
+ :existing_data
10
+
11
+ before_save :extract_dimensions
12
+
13
+ do_not_validate_attachment_file_type :asset
14
+ validates :asset, attachment_presence: true, if: :validate_presence?
15
+ validate :validate_asset_size, if: :validate_size?
16
+ validate :validate_asset_content_type, if: :validate_content_type?
17
+
18
+ def metadata=(metadata_hash)
19
+ @metadata = metadata_hash.deep_symbolize_keys
20
+ @existing_data = metadata_hash[:existing_data]
21
+ Paperclip::HasAttachedFile.define_on(self.class, :asset, existing_metadata)
22
+ end
23
+
24
+ def data=(data_hash)
25
+ self.asset = data_hash.deep_symbolize_keys[:asset]
26
+ end
27
+
28
+ def data
29
+ {
30
+ <<<<<<< HEAD
31
+ 'asset': {
32
+ 'file_name': asset_file_name,
33
+ 'url': asset.url,
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
40
+ =======
41
+ 'asset': {
42
+ 'file_name': asset_file_name,
43
+ 'url': asset.url,
44
+ 'style_urls': style_urls,
45
+ 'dimensions': dimensions,
46
+ 'content_type': asset_content_type,
47
+ 'file_size': asset_file_size,
48
+ 'updated_at': asset_updated_at
49
+ }
50
+ >>>>>>> Implement storage of thumbnail/style URLs, asset wizard info box, and asset thumbnail in index
51
+ }
52
+ end
53
+
54
+ def field_item_as_indexed_json_for_field_type(field_item, options = {})
55
+ json = {}
56
+ json[mapping_field_name] = asset_file_name
57
+ json
58
+ end
59
+
60
+ def mapping
61
+ {name: mapping_field_name, type: :string, analyzer: :keyword}
62
+ end
63
+
64
+ private
65
+
66
+ def image?
67
+ asset_content_type =~ %r{^(image|(x-)?application)/(bmp|gif|jpeg|jpg|pjpeg|png|x-png)$}
68
+ end
69
+
70
+ def extract_dimensions
71
+ return unless image?
72
+ tempfile = asset.queued_for_write[:original]
73
+ unless tempfile.nil?
74
+ geometry = Paperclip::Geometry.from_file(tempfile)
75
+ @dimensions = {
76
+ width: geometry.width.to_i,
77
+ height: geometry.height.to_i
78
+ }
79
+ end
80
+ end
81
+
82
+ def allowed_content_types
83
+ validations[:allowed_extensions].collect do |allowed_content_type|
84
+ MimeMagic.by_extension(allowed_content_type).type
85
+ end
86
+ end
87
+
88
+ def mapping_field_name
89
+ "#{field_name.parameterize('_')}_asset_file_name"
90
+ end
91
+
92
+ def validate_presence?
93
+ validations.key? :presence
94
+ end
95
+
96
+ def attachment_size_validator
97
+ AttachmentSizeValidator.new(validations[:size].merge(attributes: :asset))
98
+ end
99
+
100
+ def attachment_content_type_validator
101
+ AttachmentContentTypeValidator.new({content_type: allowed_content_types}.merge(attributes: :asset))
102
+ end
103
+
104
+ alias_method :valid_presence_validation?, :validate_presence?
105
+
106
+ def validate_size?
107
+ begin
108
+ attachment_size_validator
109
+ true
110
+ rescue ArgumentError, NoMethodError
111
+ false
112
+ end
113
+ end
114
+
115
+ def validate_content_type?
116
+ begin
117
+ attachment_content_type_validator
118
+ true
119
+ rescue ArgumentError, NoMethodError
120
+ false
121
+ end
122
+ end
123
+
124
+ def validate_asset_size
125
+ attachment_size_validator.validate_each(self, :asset, asset)
126
+ end
127
+
128
+ def validate_asset_content_type
129
+ attachment_content_type_validator.validate_each(self, :asset, asset)
130
+ end
131
+
132
+ def style_urls
133
+ if existing_data.empty?
134
+ (metadata[:styles].map { |key, value| [key, asset.url(key)] }).to_h
135
+ else
136
+ existing_data[:asset][:style_urls]
137
+ end
138
+ end
139
+
140
+ def existing_metadata
141
+ metadata.except!(:existing_data)
142
+
143
+ <<<<<<< HEAD
144
+ unless @existing_data.empty?
145
+ metadata[:path].gsub(":id", @existing_data['asset_field_type_id']) if metadata[:path]
146
+ =======
147
+ unless existing_data.empty?
148
+ metadata[:path] = updated_url(existing_data['asset']['url'])
149
+ >>>>>>> Implement storage of thumbnail/style URLs, asset wizard info box, and asset thumbnail in index
150
+ end
151
+
152
+ metadata
153
+ end
154
+ end
@@ -1,7 +1,7 @@
1
1
  module Cortex
2
2
  module Plugins
3
3
  module Core
4
- VERSION = '0.4.5'
4
+ VERSION = '0.4.6'
5
5
  end
6
6
  end
7
7
  end
@@ -73,7 +73,7 @@ namespace :cortex do
73
73
  "description": "Provide details and metadata that will enhance search or inform end-users.",
74
74
  "columns": [
75
75
  {
76
- "grid_width": 12,
76
+ "grid_width": 6,
77
77
  "elements": [
78
78
  {
79
79
  "id": media.fields[1].id
@@ -95,6 +95,20 @@ namespace :cortex do
95
95
  "id": media.fields[5].id
96
96
  }
97
97
  ]
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
+ ]
98
112
  }
99
113
  ]
100
114
  }
@@ -118,12 +132,16 @@ namespace :cortex do
118
132
  "name": "Thumbnail",
119
133
  "cells": [{
120
134
  "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
+ }
127
145
  }
128
146
  }]
129
147
  },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cortex-plugins-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - CareerBuilder Employer Site & Content Products
@@ -121,6 +121,9 @@ files:
121
121
  - app/assets/javascripts/cortex-field_types-core/application.js
122
122
  - app/cells/plugins/core/asset/input.haml
123
123
  - app/cells/plugins/core/asset_cell.rb
124
+ - app/cells/plugins/core/asset_info/index.haml
125
+ - app/cells/plugins/core/asset_info/show.haml
126
+ - app/cells/plugins/core/asset_info_cell.rb
124
127
  - app/cells/plugins/core/boolean/checkbox.haml
125
128
  - app/cells/plugins/core/boolean/switch.haml
126
129
  - app/cells/plugins/core/boolean_cell.rb
@@ -141,6 +144,7 @@ files:
141
144
  - app/cells/plugins/core/user/dropdown.haml
142
145
  - app/cells/plugins/core/user_cell.rb
143
146
  - app/models/asset_field_type.rb
147
+ - app/models/asset_field_type.rb.orig
144
148
  - app/models/boolean_field_type.rb
145
149
  - app/models/date_time_field_type.rb
146
150
  - app/models/tag_field_type.rb