Skip to content

Commit

Permalink
Article form usability and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Oct 27, 2023
1 parent 0002749 commit 948ef32
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
28 changes: 20 additions & 8 deletions app/assets/javascripts/article-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ArticleForm {
this.priceUnit$ = $(`#${this.unitFieldsIdPrefix}_price_unit`, this.articleForm$);
this.tax$ = $(`#${this.unitFieldsIdPrefix}_tax`, this.articleForm$);
this.deposit$ = $(`#${this.unitFieldsIdPrefix}_deposit`, this.articleForm$);
this.fcPrice$ = $(`#${this.unitFieldsIdPrefix}_fc_price`, this.articleForm$);
this.fcPrice$ = $(`#article_fc_price`, this.articleForm$);
this.unitsToOrder$ = $('#order_article_units_to_order', this.articleForm$);
this.unitsReceived$ = $('#order_article_units_received', this.articleForm$);
this.toggleExtraUnitsButton$ = $('.toggle-extra-units', this.articleForm$);
Expand Down Expand Up @@ -184,6 +184,7 @@ class ArticleForm {
this.unit$.change(() => {
this.setMinimumOrderUnitDisplay();
this.updateAvailableBillingAndGroupOrderUnits();
this.updateUnitMultiplierLabels();
});
this.unit$.keyup(() => this.unit$.trigger('change'));

Expand Down Expand Up @@ -227,11 +228,11 @@ class ArticleForm {
e.preventDefault();
e.stopPropagation();

this.onAddClicked();
this.onAddRatioClicked();
});
}

onAddClicked() {
onAddRatioClicked() {
const newRow$ = this.articleUnitRatioTemplate$.clone();
$('tbody', this.unitRatiosTable$).append(newRow$);

Expand Down Expand Up @@ -337,7 +338,8 @@ class ArticleForm {
}
return unit.label;
} else {
return this.unit$.val();
const unitVal = this.unit$.val();
return unitVal ? unitVal : '?';
}
}
}
Expand All @@ -348,7 +350,8 @@ class ArticleForm {
const chosenOption$ = $(`option[value="${this.supplierUnitSelect$.val()}"]`, this.supplierUnitSelect$);
unitsSelectedAbove.push({ key: chosenOption$.val(), label: chosenOption$.text() });
} else {
unitsSelectedAbove.push({ key: '', label: this.unit$.val() });
const unitVal = this.unit$.val();
unitsSelectedAbove.push({ key: '', label: unitVal ? unitVal : '?' });
}

const selectedRatioUnits = $('tr select[name$="[unit]"]', this.unitRatiosTable$).map((_, ratioSelect) => ({
Expand All @@ -373,6 +376,7 @@ class ArticleForm {
}

this.updateUnitsInSelect(availableUnits, this.billingUnit$);
this.billingUnit$.parents('.fold-line').css('display', availableUnits.length > 1 ? 'block' : 'none');
this.updateUnitsInSelect(availableUnits, this.groupOrderUnit$);
this.updateUnitsInSelect(availableUnits, this.priceUnit$);
}
Expand All @@ -398,17 +402,25 @@ class ArticleForm {
}

unitSelect$.trigger('change');

unitSelect$.parents('.control-group').find('.immutable_unit_label').remove();
if (units.length === 1) {
unitSelect$.hide();
unitSelect$.parents('.control-group').append($(`<div class="immutable_unit_label control-label">${units[0].label}</div>`))
} else {
unitSelect$.show();
}
}

setFieldVisibility() {
const firstUnitRatioQuantity$ = $('tr input[name$="[quantity]"]:first', this.unitRatiosTable$);
const firstUnitRatioUnit$ = $('tr select[name$="[unit]"]:first', this.unitRatiosTable$);

const supplierOrderUnitSet = !!this.unit$.val() || !!this.supplierUnitSelect$.val();
const unitRationsVisible = supplierOrderUnitSet;
this.unitRatiosTable$.parents('.fold-line').toggle(unitRationsVisible);
const unitRatiosVisible = supplierOrderUnitSet || this.unitRatiosTable$.find('tbody tr').length > 0;
this.unitRatiosTable$.parents('.fold-line').toggle(unitRatiosVisible);

if (!unitRationsVisible) {
if (!unitRatiosVisible) {
$('tbody tr', this.unitRatiosTable$).remove();
}

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ def update_all
def update_selected
raise I18n.t('articles.controller.error_nosel') if params[:selected_articles].nil?

articles = Article.find(params[:selected_articles])
articles = Article.with_latest_versions_and_categories
.includes(latest_article_version: [:article_unit_ratios])
.find(params[:selected_articles])
Article.transaction do
case params[:selected_action]
when 'destroy'
Expand Down
2 changes: 0 additions & 2 deletions app/models/order_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ def update_results!
if order.open?
self.quantity = group_order_articles.collect(&:quantity).sum
self.tolerance = group_order_articles.collect(&:tolerance).sum
require 'byebug'
byebug
self.units_to_order = calculate_units_to_order(quantity, tolerance)
enforce_boxfill if order.boxfill?
save!
Expand Down

0 comments on commit 948ef32

Please sign in to comment.