Skip to content

Commit

Permalink
Merge pull request solidusio#2400 from tvdeyen/promotions-ui-fixes
Browse files Browse the repository at this point in the history
Promotions admin UI fixes
  • Loading branch information
tvdeyen authored Nov 30, 2017
2 parents 51a3ea1 + af8427e commit 974e7bf
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 139 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="fullwidth tier">
<a class="fa fa-trash remove js-remove-tier"></a>
<div class="row">
<div class="col-6">
<a class="fa fa-trash remove js-remove-tier"></a>
<div class="input-group">
<span class="input-group-addon">$</span>
<input class="js-base-input form-control" type="text" value={{baseField.value}}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
}
}

#promotion-pilicy-select {
#promotion-policy-select {
overflow: auto;
margin-bottom: 1.5rem;
}

.promotion-block {
// padding: 0 5px 5px;
padding: 0 1.25rem 0.5rem;
background-color: lighten($color-border, 5);
border: 1px solid $color-border;
border-radius: 3px;
Expand All @@ -34,14 +35,19 @@
margin-bottom: 0;
}

// Fix the padding added by the .fa icon rule
.fa:before {
padding-right: 0;
}

.promo-rule-option-value {
position: relative;
padding-bottom: 10px;

.remove {
cursor: pointer;
position: absolute;
right: 10px;
right: 0;
top: 10px;

&:hover {
Expand Down Expand Up @@ -118,8 +124,8 @@

a.delete {
position: absolute;
top: 3px;
right: 5px;
top: 1.25rem;
right: 1.25rem;
cursor: pointer;

&:hover {
Expand All @@ -130,12 +136,14 @@

.promotion-title {
text-align: left;
font-size: 85%;
font-size: 1rem;
border-bottom: 1px solid $color-border;
padding: 0 10px;
padding: 0.75rem 0;
margin-bottom: 0.75rem;

&.no-text {
border: none;
padding-bottom: 0;
margin-bottom: 0.25rem;
}
}
4 changes: 2 additions & 2 deletions backend/app/views/spree/admin/promotions/_actions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<%= form_tag spree.admin_promotion_promotion_actions_path(@promotion), remote: true, id: 'new_promotion_action_form' do %>
<% options = options_for_select( Rails.application.config.spree.promotions.actions.map {|action| [ action.model_name.human, action.name] } ) %>
<fieldset>
<legend align="center"><%= plural_resource_name(Spree::PromotionAction) %></legend>
<legend align="center"><%= t('spree.promotion_actions') %></legend>
<% if can?(:update, @promotion) %>
<div class="field">
<%= label_tag :action_type, t('spree.add_action_of_type')%>
<%= select_tag 'action_type', options, class: 'custom-select fullwidth' %>
<%= select_tag 'action_type', options, include_blank: t(:choose_promotion_action, scope: 'spree'), class: 'custom-select fullwidth' %>
</div>
<div class="filter-actions actions">
<%= button t('spree.actions.add') %>
Expand Down
6 changes: 4 additions & 2 deletions backend/app/views/spree/admin/promotions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
<% end %>

<%= f.field_container :advertise do %>
<%= f.check_box :advertise %>
<%= f.label :advertise %>
<%= label_tag do %>
<%= f.check_box :advertise %>
<%= Spree::Promotion.human_attribute_name(:advertise) %>
<% end %>
<% end %>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="promotion_rule promotion-block col-12" id="<%= dom_id promotion_rule %>">
<% type_name = promotion_rule.model_name.element %>
<h6 class='promotion-title <%= 'no-text' if type_name == 'user_logged_in' || type_name == 'first_order'%>'><%= promotion_rule.class.human_attribute_name(:description) %></h6>
<h6 class='promotion-title <%= 'no-text' if type_name.in? %w(user_logged_in first_order one_use_per_user) %>'><%= promotion_rule.class.human_attribute_name(:description) %></h6>
<% if can?(:destroy, promotion_rule) %>
<%= link_to_with_icon 'trash', '', spree.admin_promotion_promotion_rule_path(@promotion, promotion_rule), remote: true, method: :delete, class: 'delete' %>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions backend/app/views/spree/admin/promotions/_rules.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<% if can?(:update, @promotion) %>
<div class="field">
<%= label_tag :promotion_rule_type, t('spree.add_rule_of_type') %>
<%= select_tag('promotion_rule[type]', options_for_promotion_rule_types(@promotion), class: 'custom-select fullwidth') %>
<%= select_tag('promotion_rule[type]', options_for_promotion_rule_types(@promotion), include_blank: t(:choose_promotion_rule, scope: 'spree'), class: 'custom-select fullwidth') %>
</div>
<div class="filter-actions actions">
<%= button t('spree.actions.add') %>
Expand All @@ -19,7 +19,7 @@

<%= form_for @promotion, url: object_url, method: :put do |f| %>
<fieldset class="no-border-top">
<div id="promotion-pilicy-select" class="align-center row">
<div id="promotion-policy-select" class="align-center row">
<% Spree::Promotion::MATCH_POLICIES.each do |policy| %>
<div class="col-6">
<label><%= f.radio_button :match_policy, policy %> <%= t "spree.promotion_form.match_policies.#{policy}" %></label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<div class="col-12">
<div class="row">
<div class="col-12">
<div class="field">
<% field_name = "#{param_prefix}[preferred_group_size]" %>
<%= label_tag field_name, t('spree.group_size') %>
<%= number_field_tag field_name, promotion_action.preferred_group_size, class: "fullwidth", min: 1 %>
</div>
</div>
</div>
<div class="field">
<% field_name = "#{param_prefix}[preferred_group_size]" %>
<%= label_tag field_name, t('spree.group_size') %>
<%= number_field_tag field_name, promotion_action.preferred_group_size, class: "fullwidth", min: 1 %>
</div>

<%= render "spree/admin/promotions/actions/create_item_adjustments",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
<div class="col-12">
<div class="calculator-fields js-calculator-fields row">

<div class="col-6">
<div class="field">
<% field_name = "#{param_prefix}[calculator_type]" %>
<%= label_tag field_name, Spree::Calculator.model_name.human %>
<%= select_tag field_name,
options_from_collection_for_select(calculators, :to_s, :description, promotion_action.calculator.type),
class: 'type-select js-calculator-type custom-select fullwidth' %>
</div>
<div class="calculator-fields js-calculator-fields row">
<div class="col-6">
<div class="field">
<% field_name = "#{param_prefix}[calculator_type]" %>
<%= label_tag field_name, t('spree.admin.promotions.actions.calculator_label') %>
<%= select_tag field_name,
options_from_collection_for_select(calculators, :to_s, :description, promotion_action.calculator.type),
class: 'type-select js-calculator-type custom-select fullwidth' %>
</div>

<div class="col-6">
<div class="settings">
<% calculators.each do |calculator_class| %>
<% calculator = promotion_action.calculator.class == calculator_class ? promotion_action.calculator : calculator_class.new %>
<div class="js-calculator-preferences" data-calculator-type="<%= calculator_class %>">
<% type_name = calculator.type.demodulize.underscore %>
<% if lookup_context.exists?("fields",
["spree/admin/promotions/calculators/#{type_name}"], true) %>
<%= render "spree/admin/promotions/calculators/#{type_name}/fields",
calculator: calculator, prefix: param_prefix %>
<% else %>
<%= render "spree/admin/promotions/calculators/default_fields",
calculator: calculator, prefix: param_prefix %>
<% end %>
</div>
<% end %>
</div>
</div>
<div class="col-6">
<div class="settings">
<% calculators.each do |calculator_class| %>
<% calculator = promotion_action.calculator.class == calculator_class ? promotion_action.calculator : calculator_class.new %>
<div class="js-calculator-preferences" data-calculator-type="<%= calculator_class %>">
<% type_name = calculator.type.demodulize.underscore %>
<% if lookup_context.exists?("fields",
["spree/admin/promotions/calculators/#{type_name}"], true) %>
<%= render "spree/admin/promotions/calculators/#{type_name}/fields",
calculator: calculator, prefix: param_prefix %>
<% else %>
<%= render "spree/admin/promotions/calculators/default_fields",
calculator: calculator, prefix: param_prefix %>
<% end %>
</div>
<% end %>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<%= fields_for "#{prefix}[calculator_attributes]", calculator do |f| %>
<%= f.label :preferred_amount %>
<%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :preferred_amount, currency_attr: :preferred_currency %>
<% end %>
<div class="field">
<%= fields_for "#{prefix}[calculator_attributes]", calculator do |f| %>
<%= f.label :preferred_amount %>
<%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :preferred_amount, currency_attr: :preferred_currency %>
<% end %>
</div>

<div class="field">
<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<%= fields_for "#{prefix}[calculator_attributes]", calculator do |f| %>
<%= f.label :preferred_amount %>
<%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :preferred_amount, currency_attr: :preferred_currency %>
<% end %>
<div class="field">
<%= fields_for "#{prefix}[calculator_attributes]", calculator do |f| %>
<%= f.label :preferred_amount %>
<%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :preferred_amount, currency_attr: :preferred_currency %>
<% end %>
</div>
22 changes: 10 additions & 12 deletions backend/app/views/spree/admin/promotions/rules/_item_total.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<div class="col-12">
<div class="row">
<div class="col-6">
<div class="field">
<%= select_tag "#{param_prefix}[preferred_operator]", options_for_select(Spree::Promotion::Rules::ItemTotal::OPERATORS.map{|o| [t(o, scope: 'spree.item_total_rule.operators'),o]}, promotion_rule.preferred_operator), {class: 'custom-select select_item_total fullwidth'} %>
</div>
<div class="row">
<div class="col-6">
<div class="field">
<%= select_tag "#{param_prefix}[preferred_operator]", options_for_select(Spree::Promotion::Rules::ItemTotal::OPERATORS.map{|o| [t(o, scope: 'spree.item_total_rule.operators'),o]}, promotion_rule.preferred_operator), {class: 'custom-select select_item_total fullwidth'} %>
</div>
<div class="col-6">
<div class="field">
<%= fields_for param_prefix, promotion_rule do |f| %>
<%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :preferred_amount, currency_attr: :preferred_currency %>
<% end %>
</div>
</div>
<div class="col-6">
<div class="field">
<%= fields_for param_prefix, promotion_rule do |f| %>
<%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :preferred_amount, currency_attr: :preferred_currency %>
<% end %>
</div>
</div>
</div>

This file was deleted.

18 changes: 8 additions & 10 deletions backend/app/views/spree/admin/promotions/rules/_nth_order.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<div class="col-12">
<div class="row">
<div class="col-6">
<div class="field">
<%= Spree::Promotion::Rules::NthOrder.human_attribute_name(:form_text) %>
</div>
<div class="row">
<div class="col-6">
<div class="field">
<%= Spree::Promotion::Rules::NthOrder.human_attribute_name(:form_text) %>
</div>
<div class="col-6">
<div class="field">
<%= number_field_tag "#{param_prefix}[preferred_nth_order]", promotion_rule.preferred_nth_order, class: 'fullwidth' %>
</div>
</div>
<div class="col-6">
<div class="field">
<%= number_field_tag "#{param_prefix}[preferred_nth_order]", promotion_rule.preferred_nth_order, class: 'fullwidth' %>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<div class="col-12">
<div class="field promo-rule-option-values">
<div class="param-prefix hidden" data-param-prefix="<%= param_prefix %>"></div>
<div class="row">
<div class="col-6"><%= label_tag nil, Spree::Product.model_name.human %></div>
<div class="col-6"><%= label_tag nil, plural_resource_name(Spree::OptionValue) %></div>
</div>
<div class="clear"></div>
<div class="field promo-rule-option-values">
<div class="param-prefix hidden" data-param-prefix="<%= param_prefix %>"></div>
<div class="row">
<div class="col-6"><%= label_tag nil, Spree::Product.model_name.human %></div>
<div class="col-6"><%= label_tag nil, plural_resource_name(Spree::OptionValue) %></div>
</div>

<div class="js-promo-rule-option-values"></div>
<div class="js-promo-rule-option-values"></div>

<button class="button js-add-promo-rule-option-value"><%= t('spree.actions.add') %></button>
</div>
<button class="button js-add-promo-rule-option-value"><%= t('spree.actions.add') %></button>
</div>

<%= content_tag :div, nil, class: "hidden js-original-promo-rule-option-values",
Expand Down
22 changes: 12 additions & 10 deletions backend/app/views/spree/admin/promotions/rules/_product.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<div class="col-12">
<div class="field products_rule_products">
<%= label_tag "#{param_prefix}_product_ids_string", t('spree.product_rule.choose_products') %>
<%= hidden_field_tag "#{param_prefix}[product_ids_string]", promotion_rule.product_ids.join(","), class: "product_picker fullwidth" %>
<div class="row">
<div class="col-12">
<div class="field products_rule_products">
<%= label_tag "#{param_prefix}_product_ids_string", t('spree.product_rule.choose_products') %>
<%= hidden_field_tag "#{param_prefix}[product_ids_string]", promotion_rule.product_ids.join(","), class: "product_picker fullwidth" %>
</div>
</div>
</div>
<div class="col-12">
<div class="field">
<label>
<%= t('spree.product_rule.label', select: select_tag("#{param_prefix}[preferred_match_policy]", options_for_select(Spree::Promotion::Rules::Product::MATCH_POLICIES.map{|s| [t("spree.product_rule.match_#{s}"),s] }, promotion_rule.preferred_match_policy), {class: 'select_product custom-select'})).html_safe %>
</label>
<div class="col-12">
<div class="field">
<label>
<%= t('spree.product_rule.label', select: select_tag("#{param_prefix}[preferred_match_policy]", options_for_select(Spree::Promotion::Rules::Product::MATCH_POLICIES.map{|s| [t("spree.product_rule.match_#{s}"),s] }, promotion_rule.preferred_match_policy), {class: 'select_product custom-select'})).html_safe %>
</label>
</div>
</div>
</div>
24 changes: 9 additions & 15 deletions backend/app/views/spree/admin/promotions/rules/_taxon.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
<div class="row">
<div class="col-11">
<div class="field taxons_rule_taxons">
<%= label_tag "#{param_prefix}_taxon_ids_string", t('spree.taxon_rule.choose_taxons') %>
<%= hidden_field_tag "#{param_prefix}[taxon_ids_string]", promotion_rule.taxon_ids.join(","), class: "taxon_picker fullwidth", id: 'product_taxon_ids' %>
</div>
</div>
<div class="col-12">
<div class="field">
<label>
<%= t('spree.taxon_rule.label', select: select_tag("#{param_prefix}[preferred_match_policy]", options_for_select(Spree::Promotion::Rules::Taxon::MATCH_POLICIES.map{|s| [t("spree.taxon_rule.match_#{s}"),s] }, promotion_rule.preferred_match_policy), {class: 'select_taxon custom-select'})).html_safe %>
</label>
</div>
</div>
</div>
<div class="field taxons_rule_taxons">
<%= label_tag "#{param_prefix}_taxon_ids_string", t('spree.taxon_rule.choose_taxons') %>
<%= hidden_field_tag "#{param_prefix}[taxon_ids_string]", promotion_rule.taxon_ids.join(","), class: "taxon_picker fullwidth", id: 'product_taxon_ids' %>
</div>
<div class="field">
<label>
<%= t('spree.taxon_rule.label', select: select_tag("#{param_prefix}[preferred_match_policy]", options_for_select(Spree::Promotion::Rules::Taxon::MATCH_POLICIES.map{|s| [t("spree.taxon_rule.match_#{s}"),s] }, promotion_rule.preferred_match_policy), {class: 'select_taxon custom-select'})).html_safe %>
</label>
</div>
8 changes: 3 additions & 5 deletions backend/app/views/spree/admin/promotions/rules/_user.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<div class="col-12">
<div class="field">
<label><%= t('spree.user_rule.choose_users') %></label><br>
<input type='hidden' name='<%= param_prefix %>[user_ids_string]' class='user_picker fullwidth' value='<%= promotion_rule.user_ids.join(",") %>'>
</div>
<div class="field">
<label><%= t('spree.user_rule.choose_users') %></label><br>
<input type='hidden' name='<%= param_prefix %>[user_ids_string]' class='user_picker fullwidth' value='<%= promotion_rule.user_ids.join(",") %>'>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= select_tag "#{param_prefix}[preferred_role_ids]",
options_from_collection_for_select(
Spree::Role.all, :id, :name, promotion_rule.preferred_role_ids
), class: 'custom-select fullwidth', multiple: true %>
), class: 'select2 fullwidth', multiple: true %>
</div>
<div class="form-group">
<label>
Expand Down
Loading

0 comments on commit 974e7bf

Please sign in to comment.