Skip to content

Commit

Permalink
shared articles list design enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Oct 20, 2023
1 parent b3218ed commit 3353cc7
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 75 deletions.
41 changes: 37 additions & 4 deletions app/assets/javascripts/article-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ArticleForm {
this.initializeFormSubmitListener();
this.initializeToggleExtraUnitsButton();
} catch (e) {
console.log('Could not initialize article form', e);
console.log('Could not initialize article form', e, 'articleUnitRatioTemplate$', articleUnitRatioTemplate$, 'articleForm$', articleForm$, 'units', units, 'priceMarkup', priceMarkup, 'multiForm$', multiForm$, 'unitFieldsIdPrefix', unitFieldsIdPrefix, 'unitFieldsNamePrefix', unitFieldsNamePrefix);
}
}

Expand Down Expand Up @@ -92,14 +92,47 @@ class ArticleForm {
}

initializeToggleExtraUnitsButton() {
this.toggleExtraUnitsButton$.on('click', (e) => {
this.toggleExtraUnits();
});
if (this.toggleExtraUnitsButton$.length > 0) {
this.setExtraUnitsButtonStatus();

this.toggleExtraUnitsButton$.on('click', (e) => {
this.toggleExtraUnits();
});

this.supplierUnitSelect$.on('change', () => this.setExtraUnitsButtonStatus());
}
}

setExtraUnitsButtonStatus() {
if (this.hasDeviatingExtraUnits()) {
this.toggleExtraUnitsButton$.removeClass('default-values');
} else {
this.toggleExtraUnitsButton$.addClass('default-values');
}
}

hasDeviatingExtraUnits() {
if ($(`input[name^="${this.unitFieldsNamePrefix}[article_unit_ratios_attributes]"][name$="[quantity]"]`).length > 0) {
return true;
}

const supplierOrderUnit = this.supplierUnitSelect$.val();
if (supplierOrderUnit !== this.groupOrderUnit$.val() || supplierOrderUnit !== this.billingUnit$.val()) {
return true;
}

if (this.minimumOrderQuantity$.val().trim() != '') {
return true;
}

return false;
}

toggleExtraUnits() {
this.setExtraUnitsButtonStatus();
$(document).off('mousedown.extra-units');
this.extraUnits$.toggleClass('show');
this.toggleExtraUnitsButton$.toggleClass('show');

if (this.extraUnits$.hasClass('show')) {
$(document).on('mousedown.extra-units', (e) => {
Expand Down
18 changes: 18 additions & 0 deletions app/assets/stylesheets/article.less
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@
.extra-unit-fields-btn {
color: #000;
}

.toggle-extra-units.default-values {
color: #333;
opacity: 0.65;
}

.toggle-extra-units.show {
color: #333;
opacity: 1;
}

.sync-table .control-group {
margin-bottom: 0;
}

.sync-table .extra-unit-fields .control-group {
margin-bottom: 20px;
}
8 changes: 8 additions & 0 deletions app/assets/stylesheets/bootstrap_and_overrides.css.less
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ span.negative_amout {
display: flex;
}

.align-items-center {
align-items: center;
}

.ml-1 {
margin-left: 3px;
}
Expand All @@ -589,6 +593,10 @@ td.mr-1 > *:last-child {
margin-bottom: 3px;
}

.text-decoration-none:hover {
text-decoration: none;
}

// Wider popovers
.popover.wide {
max-width: 40vw;
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ def edit
end

def create
valid = false
Article.transaction do
@article = Article.create(supplier_id: @supplier.id)
@article.attributes = { latest_article_version_attributes: params[:article_version] }
@article.save
raise ActiveRecord::Rollback unless @article.valid?

valid = @article.save
end

if @article.valid? && @article.save
if valid
render :layout => false
else
render :action => 'new', :layout => false
Expand Down
6 changes: 3 additions & 3 deletions app/views/articles/_sync_table.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- price_markup = FoodsoftConfig[:price_markup].to_f
%table.table
%table.table.sync-table
%thead
%tr
%th= heading_helper Article, :name
Expand Down Expand Up @@ -43,10 +43,10 @@
%td{:style => highlight_new(attrs, :manufacturer)}= form.text_field 'manufacturer', class: 'input-small'
%td{:style => highlight_new(attrs, :origin)}= form.text_field 'origin', class: 'input-mini'
%td{:style => highlight_new(attrs, :supplier_order_unit)}
.d-flex.gap-1
.d-flex.gap-1.align-items-center
= form.input :supplier_order_unit, as: :select, collection: @article_units, label: false, value: changed_article.supplier_order_unit, include_blank: t('Custom (avoid if possible!)') + ':', input_html: {class: 'input-medium'}
= form.input :unit, input_html: {class: 'input-mini ml-1'}, label: false
%div.btn-link.toggle-extra-units
%div.btn-link.toggle-extra-units.text-decoration-none.default-values
%i.icon-cog{:style => highlight_new(attrs, [:article_unit_ratio_attributes, :minimum_order_quantity, :billing_unit, :group_order_unit, :group_order_granularity])}
%div.extra-unit-fields.form-horizontal
.fold-line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,15 @@ def convert_old_unit(old_compound_unit_str, unit_quantity)
group_order_unit: unit
}
else
supplier_order_unit = unit == 'XPP' ? 'XPA' : 'XPP'
{
supplier_order_unit: 'XPP',
supplier_order_unit: supplier_order_unit,
first_ratio: {
quantity: quantity * unit_quantity,
unit: unit
},
group_order_granularity: unit_quantity > 1 ? quantity : 1.0,
group_order_unit: unit_quantity > 1 ? unit : 'XPP'
group_order_unit: unit_quantity > 1 ? unit : supplier_order_unit
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@
})
end

it 'converts "4 piece" correctly' do
result = migration.send(:convert_old_unit, '4 piece', 1)
expect(result).to eq({
supplier_order_unit: 'XPA',
first_ratio: {
unit: 'XPP',
quantity: 4
},
group_order_granularity: 1.0,
group_order_unit: 'XPA'
})
end

it 'converts "1 bunch" correctly' do
result = migration.send(:convert_old_unit, '1 bunch', 1)
expect(result).to eq({
Expand Down
Loading

0 comments on commit 3353cc7

Please sign in to comment.