From 53da1bf8d9b41942c82a361356f3838abecc1d28 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 30 Oct 2018 09:11:52 +0100 Subject: [PATCH 1/3] Do not render the whole element editor in trash window --- app/helpers/alchemy/admin/elements_helper.rb | 5 ++--- .../alchemy/admin/elements/_element.html.erb | 2 +- app/views/alchemy/admin/trash/index.html.erb | 13 ++++++------- .../alchemy/admin/trash_controller_spec.rb | 8 ++++---- .../alchemy/admin/elements_helper_spec.rb | 18 +----------------- 5 files changed, 14 insertions(+), 32 deletions(-) diff --git a/app/helpers/alchemy/admin/elements_helper.rb b/app/helpers/alchemy/admin/elements_helper.rb index 79d370f448..0957263e7b 100644 --- a/app/helpers/alchemy/admin/elements_helper.rb +++ b/app/helpers/alchemy/admin/elements_helper.rb @@ -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 diff --git a/app/views/alchemy/admin/elements/_element.html.erb b/app/views/alchemy/admin/elements/_element.html.erb index 8b5a148e1a..739ef8d57e 100644 --- a/app/views/alchemy/admin/elements/_element.html.erb +++ b/app/views/alchemy/admin/elements/_element.html.erb @@ -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 %> diff --git a/app/views/alchemy/admin/trash/index.html.erb b/app/views/alchemy/admin/trash/index.html.erb index defa67e9bd..7d39ebaccd 100644 --- a/app/views/alchemy/admin/trash/index.html.erb +++ b/app/views/alchemy/admin/trash/index.html.erb @@ -8,13 +8,12 @@ <% end %>
<%- @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 -%>

diff --git a/spec/controllers/alchemy/admin/trash_controller_spec.rb b/spec/controllers/alchemy/admin/trash_controller_spec.rb index 0a53314fc8..07ab763379 100644 --- a/spec/controllers/alchemy/admin/trash_controller_spec.rb +++ b/spec/controllers/alchemy/admin/trash_controller_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/helpers/alchemy/admin/elements_helper_spec.rb b/spec/helpers/alchemy/admin/elements_helper_spec.rb index 4b4cfa2e1d..d3f1b347b3 100644 --- a/spec/helpers/alchemy/admin/elements_helper_spec.rb +++ b/spec/helpers/alchemy/admin/elements_helper_spec.rb @@ -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') } From 5d2b7a1380785e4031127d453e9161c747382d2a Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 30 Oct 2018 09:21:01 +0100 Subject: [PATCH 2/3] Truncate clipboard item name --- app/views/alchemy/admin/clipboard/index.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/alchemy/admin/clipboard/index.html.erb b/app/views/alchemy/admin/clipboard/index.html.erb index 7c2d2bc47d..970aab60bd 100644 --- a/app/views/alchemy/admin/clipboard/index.html.erb +++ b/app/views/alchemy/admin/clipboard/index.html.erb @@ -10,14 +10,14 @@

  • <% 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 %> <%= link_to render_icon(:times, size: 'xs'), From b9d15e84a5e43e97db4c1f6579f1c420e25ed3dd Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Sun, 11 Nov 2018 23:24:57 +0100 Subject: [PATCH 3/3] Remove elements with picture gallery from template tracker We removed the picture gallery feature and replaced it with nested elements. So we do not need to track the essence picture template for it. --- lib/alchemy/cache_digests/template_tracker.rb | 4 ---- spec/libraries/template_tracker_spec.rb | 8 -------- 2 files changed, 12 deletions(-) diff --git a/lib/alchemy/cache_digests/template_tracker.rb b/lib/alchemy/cache_digests/template_tracker.rb index 2aff95b67f..a0533b4f1f 100644 --- a/lib/alchemy/cache_digests/template_tracker.rb +++ b/lib/alchemy/cache_digests/template_tracker.rb @@ -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) diff --git a/spec/libraries/template_tracker_spec.rb b/spec/libraries/template_tracker_spec.rb index 64699ed88c..c07d361fef 100644 --- a/spec/libraries/template_tracker_spec.rb +++ b/spec/libraries/template_tracker_spec.rb @@ -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