From 04bf5a8742fa0ba9dd1f86dfdd259930e21b4719 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 15 Oct 2019 00:18:32 +0100 Subject: [PATCH] Convert images views from erb to haml --- app/views/spree/admin/images/_form.html.erb | 18 ------ app/views/spree/admin/images/_form.html.haml | 16 ++++++ app/views/spree/admin/images/edit.html.erb | 28 ---------- app/views/spree/admin/images/edit.html.haml | 21 +++++++ app/views/spree/admin/images/index.html.erb | 58 -------------------- app/views/spree/admin/images/index.html.haml | 43 +++++++++++++++ app/views/spree/admin/images/new.html.erb | 15 ----- app/views/spree/admin/images/new.html.haml | 10 ++++ spec/features/admin/products_spec.rb | 4 +- 9 files changed, 92 insertions(+), 121 deletions(-) delete mode 100644 app/views/spree/admin/images/_form.html.erb create mode 100644 app/views/spree/admin/images/_form.html.haml delete mode 100644 app/views/spree/admin/images/edit.html.erb create mode 100644 app/views/spree/admin/images/edit.html.haml delete mode 100644 app/views/spree/admin/images/index.html.erb create mode 100644 app/views/spree/admin/images/index.html.haml delete mode 100644 app/views/spree/admin/images/new.html.erb create mode 100644 app/views/spree/admin/images/new.html.haml diff --git a/app/views/spree/admin/images/_form.html.erb b/app/views/spree/admin/images/_form.html.erb deleted file mode 100644 index 51bcf751c4..0000000000 --- a/app/views/spree/admin/images/_form.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -
-
-
- <%= f.label Spree.t(:filename) %>
- <%= f.file_field :attachment %> -
-
- <%= f.label Spree::Variant.model_name.human %>
- <%= f.select :viewable_id, @variants, {}, {:class => 'select2 fullwidth'} %> -
-
-
- <%= f.label Spree.t(:alt_text) %>
- <%= f.text_area :alt, :rows => 4, :class => 'fullwidth' %> -
-
- -
\ No newline at end of file diff --git a/app/views/spree/admin/images/_form.html.haml b/app/views/spree/admin/images/_form.html.haml new file mode 100644 index 0000000000..a316040c3c --- /dev/null +++ b/app/views/spree/admin/images/_form.html.haml @@ -0,0 +1,16 @@ +%div + .four.columns.alpha + .field + = f.label t('spree.filename') + %br/ + = f.file_field :attachment + .field + = f.label Spree::Variant.model_name.human + %br/ + = f.select :viewable_id, @variants, {}, {class: 'select2 fullwidth'} + .field.omega.five.columns + = f.label t('spree.alt_text') + %br/ + = f.text_area :alt, rows: 4, class: 'fullwidth' + +.clear diff --git a/app/views/spree/admin/images/edit.html.erb b/app/views/spree/admin/images/edit.html.erb deleted file mode 100644 index 6bbb40c7c8..0000000000 --- a/app/views/spree/admin/images/edit.html.erb +++ /dev/null @@ -1,28 +0,0 @@ -<%= render :partial => 'spree/admin/shared/product_sub_menu' %> - -<%= render :partial => 'spree/admin/shared/product_tabs', :locals => { :current => 'Images' } %> - -<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @image } %> - -<% content_for :page_actions do %> -
  • <%= button_link_to Spree.t(:back_to_images_list), admin_product_images_url(@product), :icon => 'icon-arrow-left' %>
  • -<% end %> - -<%= form_for [:admin, @product, @image], :html => { :multipart => true } do |f| %> -
    - <%= @image.attachment_file_name%> -
    - <%= f.label Spree.t(:thumbnail) %>
    - <%= link_to image_tag(@image.attachment.url(:small)), @image.attachment.url(:product) %> -
    -
    - <%= render :partial => 'form', :locals => { :f => f } %> -
    -
    -
    - <%= button Spree.t('actions.update'), 'icon-refresh' %> - <%= Spree.t(:or) %> - <%= link_to Spree.t('actions.cancel'), admin_product_images_url(@product), :id => 'cancel_link', :class => 'button icon-remove' %> -
    -
    -<% end %> diff --git a/app/views/spree/admin/images/edit.html.haml b/app/views/spree/admin/images/edit.html.haml new file mode 100644 index 0000000000..9b691479b4 --- /dev/null +++ b/app/views/spree/admin/images/edit.html.haml @@ -0,0 +1,21 @@ += render partial: 'spree/admin/shared/product_sub_menu' += render partial: 'spree/admin/shared/product_tabs', locals: { current: 'Images' } += render partial: 'spree/shared/error_messages', locals: { target: @image } + +- content_for :page_actions do + %li= button_link_to t('spree.back_to_images_list'), admin_product_images_url(@product), icon: 'icon-arrow-left' + += form_for [:admin, @product, @image], html: { multipart: true } do |f| + %fieldset + %legend{align: "center"}= @image.attachment_file_name + .field.alpha.three.columns.align-center + = f.label t('spree.thumbnail') + %br/ + = link_to image_tag(@image.attachment.url(:small)), @image.attachment.url(:product) + .nine.columns.omega + = render partial: 'form', locals: { f: f } + .clear + .form-buttons.filter-actions.actions + = button t('spree.actions.update'), 'icon-refresh' + %span.or= t('spree.or') + = link_to t('spree.actions.cancel'), admin_product_images_url(@product), id: 'cancel_link', class: 'button icon-remove' diff --git a/app/views/spree/admin/images/index.html.erb b/app/views/spree/admin/images/index.html.erb deleted file mode 100644 index e08bb0903a..0000000000 --- a/app/views/spree/admin/images/index.html.erb +++ /dev/null @@ -1,58 +0,0 @@ -<%= render :partial => 'spree/admin/shared/product_sub_menu' %> - -<%= render :partial => 'spree/admin/shared/product_tabs', :locals => {:current => 'Images'} %> - -<% content_for :page_actions do %> -
  • <%= link_to_with_icon('icon-plus', Spree.t(:new_image), new_admin_product_image_url(@product), :id => 'new_image_link', :class => 'button') %>
  • -<% end %> - -
    - -<% unless @product.images.any? || @product.variant_images.any? %> -
    - <%= Spree.t(:no_images_found) %>. -
    -<% else %> - - - - - <% if @product.has_variants? %> - - <% end %> - - - - - - - <% if @product.has_variants? %> - - <% end %> - - - - - - - <% (@product.variant_images).each do |image| %> - - - - <% if @product.has_variants? %> - - <% end %> - - - - <% end %> - -
    <%= Spree.t(:thumbnail) %><%= Spree::Variant.model_name.human %><%= Spree.t(:alt_text) %>
    - - - <%= link_to image_tag(image.attachment.url(:mini)), image.attachment.url(:product) %> - <%= options_text_for(image) %><%= image.alt %> - <%= link_to_with_icon 'icon-edit', Spree.t(:edit), edit_admin_product_image_url(@product, image), :no_text => true, :data => {:action => 'edit'} %> - <%= link_to_delete image, { :url => admin_product_image_url(@product, image), :no_text => true } %> -
    -<% end %> diff --git a/app/views/spree/admin/images/index.html.haml b/app/views/spree/admin/images/index.html.haml new file mode 100644 index 0000000000..89124383e2 --- /dev/null +++ b/app/views/spree/admin/images/index.html.haml @@ -0,0 +1,43 @@ += render partial: 'spree/admin/shared/product_sub_menu' += render partial: 'spree/admin/shared/product_tabs', locals: { current: 'Images'} + +- content_for :page_actions do + %li= link_to_with_icon('icon-plus', t('spree.new_image'), new_admin_product_image_url(@product), id: 'new_image_link', class: 'button') + +#images + +- unless @product.images.any? || @product.variant_images.any? + .no-objects-found + = t('spree.no_images_found') + \. +- else + %table.index.sortable{ "data-sortable-link" => "#{update_positions_admin_product_images_url(@product)}" } + %colgroup + %col{ style: "width: 5%" }/ + %col{ style: "width: 10%" }/ + - if @product.has_variants? + %col{ style: "width: 25%" }/ + %col{ style: "width: 45%" }/ + %col{ style: "width: 15%" }/ + %thead + %tr + %th{:colspan => "2"}= t('spree.thumbnail') + - if @product.has_variants? + %th= Spree::Variant.model_name.human + %th= t('spree.alt_text') + %th.actions + %tbody + - (@product.variant_images).each do |image| + - tr_class = cycle('odd', 'even') + - tr_id = spree_dom_id(image) + %tr{class: tr_class, id: tr_id } + %td.no-border + %span.handle + %td + = link_to image_tag(image.attachment.url(:mini)), image.attachment.url(:product) + - if @product.has_variants? + %td= options_text_for(image) + %td= image.alt + %td.actions + = link_to_with_icon 'icon-edit', t('spree.edit'), edit_admin_product_image_url(@product, image), no_text: true, data: { action: 'edit'} + = link_to_delete image, { url: admin_product_image_url(@product, image), no_text: true } diff --git a/app/views/spree/admin/images/new.html.erb b/app/views/spree/admin/images/new.html.erb deleted file mode 100644 index 31841a2684..0000000000 --- a/app/views/spree/admin/images/new.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<%= form_for [:admin, @product, @image], :html => { :multipart => true } do |f| %> -
    - <%= Spree.t(:new_image) %> - - <%= render :partial => 'form', :locals => { :f => f } %> - -
    - <%= button Spree.t('actions.update'), 'icon-refresh' %> - <%= Spree.t(:or) %> - <%= link_to_with_icon 'icon-remove', Spree.t('actions.cancel'), admin_product_images_url(@product), :id => 'cancel_link', :class => 'button' %> -
    -
    -<% end %> - -<%= javascript_include_tag 'admin/images/new.js' %> \ No newline at end of file diff --git a/app/views/spree/admin/images/new.html.haml b/app/views/spree/admin/images/new.html.haml new file mode 100644 index 0000000000..22a1e01998 --- /dev/null +++ b/app/views/spree/admin/images/new.html.haml @@ -0,0 +1,10 @@ += form_for [:admin, @product, @image], html: { multipart: true } do |f| + %fieldset + %legend{ align: "center" }= t('spree.new_image') + = render partial: 'form', locals: { f: f } + .form-buttons.filter-actions.actions + = button t('spree.actions.update'), 'icon-refresh' + %span.or= t('spree.or') + = link_to_with_icon 'icon-remove', t('spree.actions.cancel'), admin_product_images_url(@product), id: 'cancel_link', class: 'button' + += javascript_include_tag 'admin/images/new.js' diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb index 9e1d0a4895..26c0af02ba 100644 --- a/spec/features/admin/products_spec.rb +++ b/spec/features/admin/products_spec.rb @@ -209,14 +209,14 @@ feature ' Spree::Image.create(viewable_id: product.master.id, viewable_type: 'Spree::Variant', alt: "position 1", attachment: image, position: 1) visit spree.admin_product_images_path(product) - expect(page).to have_selector "table[data-hook='images_table'] td img" + expect(page).to have_selector "table.index td img" expect(product.reload.images.count).to eq 1 accept_alert do page.find('a.delete-resource').click end - expect(page).to_not have_selector "table[data-hook='images_table'] td img" + expect(page).to_not have_selector "table.index td img" expect(product.reload.images.count).to eq 0 end end