Skip to content

Commit e2a0be2

Browse files
committed
Merge branch 'develop'
2 parents 674512a + 389a1bc commit e2a0be2

File tree

18 files changed

+130
-17
lines changed

18 files changed

+130
-17
lines changed

Diff for: app/assets/javascripts/ckeditor/plugins/cortex_media_insert/plugin.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
(function (global) {
1+
(function (global) {
22
'use strict';
33

44
global.CKEDITOR.plugins.add('cortex_media_insert', {
55
icons: 'media',
66
init: function (editor) {
77
editor.addCommand('insertMedia', {
88
exec: function (editor) {
9-
window.MODALS.featured.open();
9+
window.MODALS.wysiwyg.open();
1010

1111
global.media_select = {};
1212
global.media_select_defer = $.Deferred();
1313
global.media_select_defer.promise(global.media_select);
1414

1515
global.media_select.done(function (media) {
16-
window.MODALS.featured.close();
16+
window.MODALS.wysiwyg.close();
1717

1818
var mediaTag = editor.document.createElement('media');
1919
mediaTag.setAttribute('id', media.id);
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
//= require ckeditor/init
22
//= require ../ckeditor/config
3+
4+
//= require_tree ./cells
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
$('.media-select--featured').click(function (elem) {
2+
var id = $(this).data().id;
3+
var title = $(this).data().title;
4+
var thumb_url = $(this).data().thumb;
5+
6+
$(".association_content_item_id").val(id);
7+
8+
$('.content-item-button__selection').remove();
9+
$('.content-item-button').append(
10+
'<div class="content-item-button__selection">' +
11+
'<img src="' + thumb_url + '" height="50px">' +
12+
'<div class="content-item-button__selection__text">' +
13+
'Selected Media: ' +
14+
title +
15+
'</div></div>'
16+
);
17+
18+
window.MODALS.featured.close();
19+
});

Diff for: app/cells/plugins/core/asset/association.haml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
= render_associated_content_item_thumb
2+
.content-item-button__selection__text
3+
Selected Media:
4+
= associated_content_item_title

Diff for: app/cells/plugins/core/asset_cell.rb

+13
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ module Core
33
class AssetCell < Plugins::Core::Cell
44
include ActionView::Helpers::NumberHelper
55
include UtilityHelper
6+
include Cells::AssociationHelper
67

78
def input
89
render
910
end
1011

12+
def association
13+
render
14+
end
15+
1116
private
1217

1318
def render_allowed_asset_extensions
@@ -33,6 +38,14 @@ def render_label
3338
def render_input
3439
@options[:form].file_field 'data[asset]'
3540
end
41+
42+
def associated_content_item_thumb_url
43+
data['asset']['style_urls']['mini']
44+
end
45+
46+
def render_associated_content_item_thumb
47+
image_tag(associated_content_item_thumb_url, height: '50px')
48+
end
3649
end
3750
end
3851
end

Diff for: app/cells/plugins/core/asset_info_cell.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def updated_at
4141
end
4242

4343
def link_to_asset
44-
link_to(asset['url'], asset['url'])
44+
link_to asset['url'], asset['url'], target: '_blank'
4545
end
4646
end
4747
end

Diff for: app/cells/plugins/core/content_item/popup.haml

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
= render_field_id
2+
= render_content_item_id
3+
14
= render_label
25
%br
3-
%button.content_item_button.text-center.popup--open
4-
.button_content
6+
%button.content-item-button.popup--open
7+
.content-item-button__select.content-item-button__select--selected
58
%i{ class: "material-icons icon" }
69
cloud_upload
710
%br
8-
%span.content_item_button-text
9-
Click to add a
11+
%span.content-item-button__select__text
12+
Click to select a
1013
= field.name
11-
from the media library
14+
from the Media library
15+
- if associated_content_item && associated_primary_field_type_class == AssetFieldType
16+
.content-item-button__selection
17+
= render_association_cell
1218
%small
1319
Recommended size: 1452px x 530px with a live area of 930px x 530px

Diff for: app/cells/plugins/core/content_item_cell.rb

+44-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,51 @@ def popup
77

88
private
99

10+
def value
11+
data&.[]('content_item_id')
12+
end
13+
14+
def associated_content_item
15+
ContentItem.find_by_id(value)
16+
end
17+
18+
def associated_primary_field
19+
associated_content_item.content_type.fields.find_by_name(field.metadata['field_name'])
20+
end
21+
22+
def associated_primary_field_type_class
23+
associated_primary_field.field_type_instance.class
24+
end
25+
26+
def associated_primary_field_item
27+
associated_content_item.field_items.find_by_field_id associated_primary_field
28+
end
29+
30+
def associated_content_item_title
31+
# Gross hack, this should rely on 'primary title field' config feature in future, and should use a scope
32+
title_field_item = associated_content_item.field_items.find do |field_item|
33+
field_item.field.name == 'Title'
34+
end
35+
36+
title_field_item.data['text']
37+
end
38+
1039
def render_label
11-
"Add #{field.name}"
40+
"Select #{field.name}"
41+
end
42+
43+
def render_content_item_id
44+
@options[:form].hidden_field 'data[content_item_id]', value: value, class: 'association_content_item_id'
45+
end
46+
47+
def render_association_cell
48+
cell(Plugins::Core::AssetCell, associated_primary_field_item,
49+
associated_content_item: associated_content_item,
50+
associated_primary_field: associated_primary_field,
51+
associated_primary_field_type_class: associated_primary_field_type_class,
52+
associated_primary_field_item: associated_primary_field_item,
53+
associated_content_item_title: associated_content_item_title)
54+
.(:association)
1255
end
1356
end
1457
end

Diff for: app/models/boolean_field_type.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def data=(data_hash)
77

88
def field_item_as_indexed_json_for_field_type(field_item, options = {})
99
json = {}
10-
json[mapping_field_name] = field_item.data['boolean']
10+
json[mapping_field_name] = field_item.data['value']
1111
json
1212
end
1313

Diff for: app/models/content_item_field_type.rb

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
class ContentItemFieldType < FieldType
2+
attr_accessor :content_item_id
3+
4+
def data=(data_hash)
5+
@content_item_id = data_hash.deep_symbolize_keys[:content_item_id]
6+
end
7+
8+
def field_item_as_indexed_json_for_field_type(field_item, options = {})
9+
json = {}
10+
json[mapping_field_name] = field_item.data['content_item_id']
11+
json
12+
end
13+
214
def mapping
315
{ name: mapping_field_name, type: :string, analyzer: :snowball }
416
end

Diff for: app/models/date_time_field_type.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def data=(data_hash)
1010

1111
def field_item_as_indexed_json_for_field_type(field_item, options = {})
1212
json = {}
13-
json[mapping_field_name] = field_item.data['date_time']
13+
json[mapping_field_name] = field_item.data['timestamp']
1414
json
1515
end
1616

Diff for: app/models/tag_field_type.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def data=(data_hash)
1010

1111
def field_item_as_indexed_json_for_field_type(field_item, options = {})
1212
json = {}
13-
json[mapping_field_name] = field_item.data['tag']
13+
json[mapping_field_name] = field_item.data['tag_list']
1414
json
1515
end
1616

Diff for: app/models/text_field_type.rb

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
class TextFieldType < FieldType
22
attr_accessor :text
3+
jsonb_accessor :data, text: :string
34

45
validates :text, presence: true, if: :validate_presence?
56
validate :text_length, if: :validate_length?
7+
validate :text_unique, if: :validate_uniqueness?
68

79
def data=(data_hash)
810
@text = data_hash.deep_symbolize_keys[:text]
@@ -25,14 +27,24 @@ def mapping_field_name
2527
end
2628

2729
def text_present
28-
errors.add(:text, "must be present") if @text.empty?
30+
errors.add(:text, 'must be present') if @text.empty?
2931
end
3032

3133
def text_length
3234
validator = LengthValidator.new(validations[:length].merge(attributes: [:text]))
3335
validator.validate_each(self, :text, text)
3436
end
3537

38+
def text_unique
39+
unless field.field_items.jsonb_contains(:data, text: text).empty?
40+
errors.add(:text, "#{field.name} Must be unique")
41+
end
42+
end
43+
44+
def validate_uniqueness?
45+
@validations.key? :uniqueness
46+
end
47+
3648
def validate_presence?
3749
@validations.key? :presence
3850
end

Diff for: app/models/tree_field_type.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def data=(data_hash)
2121

2222
def field_item_as_indexed_json_for_field_type(field_item, options = {})
2323
json = {}
24-
json[mapping_field_name] = field_item.data['tree']
24+
json[mapping_field_name] = field_item.data['values']
2525
json
2626
end
2727

Diff for: app/models/user_field_type.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def data=(data_hash)
1010

1111
def field_item_as_indexed_json_for_field_type(field_item, options = {})
1212
json = {}
13-
json[mapping_field_name] = field_item.data['user']
13+
json[mapping_field_name] = field_item.data['user_id']
1414
json
1515
end
1616

Diff for: cortex-plugins-core.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
2222
s.add_dependency "cells-haml", "~> 0.0.10"
2323
s.add_dependency "mimemagic", "~> 0.3.2"
2424
s.add_dependency "ckeditor", "= 4.2.0"
25+
s.add_dependency "jsonb_accessor", "~> 1.0.0.beta"
2526

2627
s.add_development_dependency "sqlite3"
2728
end

Diff for: lib/cortex/plugins/core/engine.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'ckeditor'
2+
require 'jsonb_accessor'
23

34
module Cortex
45
module Plugins

Diff for: lib/cortex/plugins/core/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Cortex
22
module Plugins
33
module Core
4-
VERSION = '0.5.0'
4+
VERSION = '0.6.0'
55
end
66
end
77
end

0 commit comments

Comments
 (0)