Skip to content

Commit

Permalink
Merge pull request #1524 from tvdeyen/fixed-elements-pre
Browse files Browse the repository at this point in the history
Fixed elements prerequisite
  • Loading branch information
tvdeyen authored Dec 10, 2018
2 parents c522c93 + b9d15e8 commit 284a6f8
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 46 deletions.
5 changes: 2 additions & 3 deletions app/helpers/alchemy/admin/elements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,14 @@ def element_array_for_options(element, object_method, cell = nil)
end

# CSS classes for the element editor partial.
def element_editor_classes(element, local_assigns)
def element_editor_classes(element)
[
'element-editor',
element.content_definitions.present? ? 'with-contents' : 'without-contents',
element.nestable_elements.any? ? 'nestable' : 'not-nestable',
element.taggable? ? 'taggable' : 'not-taggable',
element.folded ? 'folded' : 'expanded',
element.compact? ? 'compact' : nil,
local_assigns[:draggable] == false ? 'not-draggable' : 'draggable'
element.compact? ? 'compact' : nil
].join(' ')
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/alchemy/admin/clipboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<li id="clipboard_item_<%= item.id -%>" class="<%= item_class -%>">
<% if item_class == 'pages' %>
<%= render_icon(:file, style: 'regular') %>
<%= item.name %>
<%= truncate(item.name, length: 50) %>
<% else %>
<% if item.public? %>
<%= render_icon('window-maximize', style: 'regular', class: 'element') %>
<% else %>
<%= render_icon('window-close', class: 'element') %>
<% end %>
<%= item.display_name_with_preview_text(60) %>
<%= truncate(item.display_name_with_preview_text(50), length: 50) %>
<% end %>
<span class="float_right">
<%= link_to render_icon(:times, size: 'xs'),
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/elements/_element.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= content_tag :div,
id: "element_#{element.id}",
data: {'element-id' => element.id, 'element-name' => element.name},
class: element_editor_classes(element, local_assigns) do %>
class: element_editor_classes(element) do %>

<%= render 'alchemy/admin/elements/element_header', element: element %>

Expand Down
13 changes: 6 additions & 7 deletions app/views/alchemy/admin/trash/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
<% end %>
<div id="trash_items">
<%- @elements.each do |element| -%>
<%= render partial: 'alchemy/admin/elements/element',
object: element,
locals: {
draggable: @allowed_elements.any? do |e|
e['name'] == element.name || e.fetch('nestable_elements', []).include?(element.name)
end
} %>
<% draggable = @allowed_elements.any? { |e| e['name'] == element.name || element.name.in?(e.fetch('nestable_elements', [])) } %>
<%= content_tag :div,
data: {'element-id' => element.id, 'element-name' => element.name},
class: ['element-editor', draggable ? 'draggable' : 'not-draggable'] do %>
<%= render 'alchemy/admin/elements/element_header', element: element %>
<% end %>
<%- end -%>
</div>
<p>
Expand Down
4 changes: 0 additions & 4 deletions lib/alchemy/cache_digests/template_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ def dependencies
element_templates cell_definition($1)
when /alchemy\/elements\/_(.+)_view/
essences = essence_types($1)
element = element_definition($1)
if element && element['picture_gallery']
essences += ['EssencePicture']
end
essences.map { |name| "alchemy/essences/_#{name.underscore}_view" }.uniq
else
ActionView::DependencyTracker::ERBTracker.call(@name, @template)
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/alchemy/admin/trash_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ module Admin

it "should hold trashed elements" do
get :index, params: {page_id: alchemy_page.id}
expect(response.body).to have_selector("#element_#{element.id}.element-editor")
expect(response.body).to have_selector("[data-element-id=\"#{element.id}\"].element-editor")
end

it "should not hold elements that are not trashed" do
element = create(:alchemy_element, page: alchemy_page, public: false)
get :index, params: {page_id: alchemy_page.id}
expect(response.body).not_to have_selector("#element_#{element.id}.element-editor")
expect(response.body).not_to have_selector("[data-element-id=\"#{element.id}\"].element-editor")
end

context "with unique elements inside the trash" do
Expand All @@ -39,7 +39,7 @@ module Admin

it "unique elements should be draggable" do
get :index, params: {page_id: alchemy_page.id}
expect(response.body).to have_selector("#element_#{trashed.id}.element-editor.draggable")
expect(response.body).to have_selector("[data-element-id=\"#{trashed.id}\"].element-editor.draggable")
end
end

Expand All @@ -54,7 +54,7 @@ module Admin

it "unique elements should not be draggable" do
get :index, params: {page_id: page.id}
expect(response.body).to have_selector("#element_#{trashed.id}.element-editor.not-draggable")
expect(response.body).to have_selector("[data-element-id=\"#{trashed.id}\"].element-editor.not-draggable")
end
end
end
Expand Down
18 changes: 1 addition & 17 deletions spec/helpers/alchemy/admin/elements_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,30 +174,14 @@ module Alchemy
end

describe '#element_editor_classes' do
subject { element_editor_classes(element, locals) }
subject { element_editor_classes(element) }

let(:element) { build_stubbed(:alchemy_element) }
let(:locals) { Hash.new }

it "returns css classes for element editor partial" do
is_expected.to include('element-editor')
end

context 'with draggable in locals set to true' do
let(:locals) { {draggable: true} }
it { is_expected.to include('draggable') }
end

context 'with draggable in locals set to false' do
let(:locals) { {draggable: false} }
it { is_expected.to include('not-draggable') }
end

context 'with draggable in locals set to nil' do
let(:locals) { {draggable: nil} }
it { is_expected.to include('draggable') }
end

context 'with element is folded' do
let(:element) { build_stubbed(:alchemy_element, folded: true) }
it { is_expected.to include('folded') }
Expand Down
8 changes: 0 additions & 8 deletions spec/libraries/template_tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ module CacheDigests
it "returns all essence layout view partial names for that element" do
is_expected.to include('alchemy/essences/_essence_text_view')
end

context 'and element has picture_gallery enabled' do
let(:elements) { [{'name' => 'text', 'picture_gallery' => true}] }

it "has EssencePicture as template dependency" do
is_expected.to include('alchemy/essences/_essence_picture_view')
end
end
end

context 'that has no definition' do
Expand Down

0 comments on commit 284a6f8

Please sign in to comment.