From 13e921a632bc74af4a2dcf5c6279c366a4eb6467 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Mon, 8 Apr 2013 01:00:49 +0200 Subject: [PATCH 1/8] Fixed some errors in articles#sync. Show better error messages. --- app/controllers/articles_controller.rb | 56 ++++++++++++++++++-------- app/models/order.rb | 2 +- app/views/articles/sync.html.haml | 5 ++- config/routes.rb | 1 + 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 820242d6..dd67dab7 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -74,12 +74,12 @@ class ArticlesController < ApplicationController end # Updates all article of specific supplier - # deletes all articles from params[outlisted_articles] def update_all + invalid_articles = false + begin Article.transaction do unless params[:articles].blank? - invalid_articles = false # Update other article attributes... @articles = Article.find(params[:articles].keys) @articles.each do |article| @@ -88,25 +88,18 @@ class ArticlesController < ApplicationController end end - raise "Artikel sind fehlerhaft. Bitte überprüfe Deine Eingaben." if invalid_articles - end - # delete articles - if params[:outlisted_articles] - params[:outlisted_articles].keys.each {|id| Article.find(id).mark_as_deleted } + raise ActiveRecord::Rollback if invalid_articles # Rollback all changes end end + end + + if invalid_articles + # An error has occurred, transaction has been rolled back. + flash.now.alert = 'Artikel sind fehlerhaft. Bitte überprüfen.' + render :edit_all + else # Successfully done. redirect_to supplier_articles_path(@supplier), notice: "Alle Artikel und Preise wurden aktalisiert" - - rescue => e - # An error has occurred, transaction has been rolled back. - if params[:sync] - flash[:error] = "Es trat ein Fehler beim Aktualisieren des Artikels '#{current_article.name}' auf: #{e.message}" - redirect_to(supplier_articles_path(@supplier)) - else - flash.now.alert = e.message - render :edit_all - end end end @@ -232,4 +225,33 @@ class ArticlesController < ApplicationController redirect_to supplier_articles_path(@supplier), :notice => "Der Katalog ist aktuell." end end + + # Updates, deletes articles when sync form is submitted + def update_synchronized + begin + Article.transaction do + # delete articles + if params[:outlisted_articles] + Article.find(params[:outlisted_articles].keys).each(&:mark_as_deleted) + end + + # Update articles + params[:articles].each do |id, attrs| + Article.find(id).update_attributes! attrs + end + end + + # Successfully done. + redirect_to supplier_articles_path(@supplier), notice: "Alle Artikel und Preise wurden aktalisiert" + + rescue ActiveRecord::RecordInvalid => invalid + # An error has occurred, transaction has been rolled back. + redirect_to supplier_articles_path(@supplier), + alert: "Es trat ein Fehler beim Aktualisieren des Artikels '#{invalid.record.name}' auf: #{invalid.record.errors.full_messages}" + + rescue => error + redirect_to supplier_articles_path(@supplier), + alert: "Es trat ein Fehler auf: #{error.message}" + end + end end diff --git a/app/models/order.rb b/app/models/order.rb index 6c6719ec..77c3f0b2 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -158,7 +158,7 @@ class Order < ActiveRecord::Base goa.save_results! # Delete no longer required order-history (group_order_article_quantities) and # TODO: Do we need articles, which aren't ordered? (units_to_order == 0 ?) - goa.group_order_article_quantities.clear + #goa.group_order_article_quantities.clear end end diff --git a/app/views/articles/sync.html.haml b/app/views/articles/sync.html.haml index d297c445..3879d219 100644 --- a/app/views/articles/sync.html.haml +++ b/app/views/articles/sync.html.haml @@ -1,6 +1,6 @@ - title 'Artikel mit externer Datenbank synchronisieren' -= form_tag update_all_supplier_articles_path(@supplier, :sync => "1") do += form_tag update_synchronized_supplier_articles_path(@supplier) do %h2 Auslisten ... %p - unless @outlisted_articles.empty? @@ -11,6 +11,9 @@ %li = hidden_field_tag "outlisted_articles[#{article.id}]", '1' = article.name + - if article.in_open_order + .alert + Achtung, #{article.name} wird gerade in einer laufenden Bestellung verwendet. Bitte erst Bestellung anpassen. - else %i Es müssen keine Artikel gelöscht werden. %hr/ diff --git a/config/routes.rb b/config/routes.rb index 9fefac04..cbcf2828 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,6 +117,7 @@ Foodsoft::Application.routes.draw do get :shared get :import post :sync + post :update_synchronized end end end From 03ea8e194ed0559402c1ed4fbc73e55775c36f18 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Mon, 8 Apr 2013 01:30:31 +0200 Subject: [PATCH 2/8] Fixed loosing assignments when updating a task. --- app/models/task.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/models/task.rb b/app/models/task.rb index bef3a44e..64c5ff20 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -66,13 +66,10 @@ class Task < ActiveRecord::Base # and makes the users responsible for the task # TODO: check for maximal number of users def user_list=(ids) - list = ids.split(",") + list = ids.split(",").map(&:to_i) new_users = (list - users.collect(&:id)).uniq old_users = users.reject { |user| list.include?(user.id) } - logger.debug "[debug] New users: #{new_users}" - logger.debug "Old users: #{old_users}" - self.class.transaction do # delete old assignments if old_users.any? @@ -84,7 +81,7 @@ class Task < ActiveRecord::Base if user.blank? errors.add(:user_list) else - if id == current_user_id + if id == current_user_id.to_i # current_user will accept, when he puts himself to the list of users self.assignments.build :user => user, :accepted => true else From 220343128c3207b07f6861607138fdacf443ffa1 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Mon, 8 Apr 2013 13:39:02 +0200 Subject: [PATCH 3/8] Fixed wrong articles total in group_order#show. --- app/views/group_orders/show.html.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/group_orders/show.html.haml b/app/views/group_orders/show.html.haml index 10b93c7c..f2b89df9 100644 --- a/app/views/group_orders/show.html.haml +++ b/app/views/group_orders/show.html.haml @@ -47,7 +47,6 @@ Erhalten %th Gesamtpreis %tbody - - total = 0 #set counter for order-sum - for category_name, order_articles in @order.articles_grouped_by_category %tr.article-category %td @@ -74,7 +73,7 @@ %td{colspan: "6"}=h oa.article.note %tr{class: cycle('even', 'odd', name: 'articles')} %th{colspan: "5"} Summe - %th= number_to_currency(total) + %th= number_to_currency(@group_order.price) %br/ = link_to_top - else From 9c21a14c7eee815471d9c4c10f2fd4702d3c88ee Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Mon, 8 Apr 2013 14:26:40 +0200 Subject: [PATCH 4/8] Update group results when editing order article in balancing. --- app/views/finance/order_articles/create.js.haml | 1 + app/views/finance/order_articles/update.js.haml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/app/views/finance/order_articles/create.js.haml b/app/views/finance/order_articles/create.js.haml index 8498e09c..cc43206e 100644 --- a/app/views/finance/order_articles/create.js.haml +++ b/app/views/finance/order_articles/create.js.haml @@ -1,2 +1,3 @@ $('#modalContainer').modal('hide'); $('#result_table').prepend('#{j(render('finance/balancing/order_article_result', order_article: @order_article))}'); +$('#summaryChangedWarning').show(); \ No newline at end of file diff --git a/app/views/finance/order_articles/update.js.haml b/app/views/finance/order_articles/update.js.haml index 1e895329..36e66ccd 100644 --- a/app/views/finance/order_articles/update.js.haml +++ b/app/views/finance/order_articles/update.js.haml @@ -1,2 +1,4 @@ $('#modalContainer').modal('hide'); $('#order_article_#{@order_article.id}').html('#{j(render('finance/balancing/order_article', order_article: @order_article))}'); +$('#group_order_articles_#{@order_article.id}').html('#{j(render('finance/balancing/group_order_articles', order_article: @order_article))}'); +$('#summaryChangedWarning').show(); \ No newline at end of file From 4966aae0ad01b00b57c798ad543678ba24d730d4 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Mon, 8 Apr 2013 14:27:23 +0200 Subject: [PATCH 5/8] Fixed modal forms. Submit form when hitting enter. --- app/views/articles/_form.html.haml | 4 ++-- app/views/finance/balancing/_edit_note.html.haml | 4 ++-- app/views/finance/group_order_articles/_form.html.haml | 4 ++-- app/views/finance/order_articles/_edit.html.haml | 6 +++--- app/views/finance/order_articles/_new.html.haml | 4 ++-- app/views/invites/_modal_form.html.haml | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/views/articles/_form.html.haml b/app/views/articles/_form.html.haml index d87cbf79..f38f498a 100644 --- a/app/views/articles/_form.html.haml +++ b/app/views/articles/_form.html.haml @@ -2,7 +2,7 @@ = f.hidden_field :shared_updated_on = f.hidden_field :supplier_id .modal-header - = button_tag "x", class: 'close', data: {dismiss: 'modal'} + = link_to 'x', '#', class: 'close', data: {dismiss: 'modal'} %h3 Neuen Artikel einfügen .modal-body = f.input :availability @@ -19,6 +19,6 @@ = f.input :tax = f.input :deposit .modal-footer - = button_tag "Schließen", class: 'btn', data: {dismiss: 'modal'} + = link_to 'Schließen', '#', class: 'btn', data: {dismiss: 'modal'} = f.submit class: 'btn btn-primary' diff --git a/app/views/finance/balancing/_edit_note.html.haml b/app/views/finance/balancing/_edit_note.html.haml index 24a32708..afd4b139 100644 --- a/app/views/finance/balancing/_edit_note.html.haml +++ b/app/views/finance/balancing/_edit_note.html.haml @@ -1,9 +1,9 @@ = simple_form_for @order, url: update_note_finance_order_path(@order), remote: true, method: :put do |f| .modal-header - = button_tag "x", class: 'close', data: {dismiss: 'modal'} + = link_to 'x', '#', class: 'close', data: {dismiss: 'modal'} %h3 Notiz bearbeiten .modal-body = f.input :note, input_html: {class: 'input-xlarge'} .modal-footer - = button_tag "Schließen", class: 'btn', data: {dismiss: 'modal'} + = link_to 'Schließen', '#', class: 'btn', data: {dismiss: 'modal'} = f.submit "Speichern", class: 'btn btn-primary' \ No newline at end of file diff --git a/app/views/finance/group_order_articles/_form.html.haml b/app/views/finance/group_order_articles/_form.html.haml index 679caf97..76f3aae8 100644 --- a/app/views/finance/group_order_articles/_form.html.haml +++ b/app/views/finance/group_order_articles/_form.html.haml @@ -1,11 +1,11 @@ = simple_form_for [:finance, @group_order_article], remote: true do |form| = form.hidden_field :order_article_id .modal-header - = button_tag "x", class: 'close', data: {dismiss: 'modal'} + = link_to 'x', '#', class: 'close', data: {dismiss: 'modal'} %h3 Mengenänderung für #{@order_article.article.name} .modal-body = form.input :ordergroup_id, as: :select, collection: Ordergroup.all.map { |g| [g.name, g.id] } = form.input :result, hint: "Einheit: #{@order_article.article.unit}" .modal-footer - = button_tag "Schließen", class: 'btn', data: {dismiss: 'modal'} + = link_to 'Schließen', '#', class: 'btn', data: {dismiss: 'modal'} = form.submit "Speichern", class: 'btn btn-primary' \ No newline at end of file diff --git a/app/views/finance/order_articles/_edit.html.haml b/app/views/finance/order_articles/_edit.html.haml index c2b92be6..53d23ea6 100644 --- a/app/views/finance/order_articles/_edit.html.haml +++ b/app/views/finance/order_articles/_edit.html.haml @@ -1,6 +1,6 @@ = simple_form_for [:finance, @order, @order_article], remote: true do |form| .modal-header - = button_tag "x", class: 'close', data: {dismiss: 'modal'} + = link_to 'x', '#', class: 'close', data: {dismiss: 'modal'} %h3 Artikel aktualisieren .modal-body = form.input :units_to_order @@ -20,5 +20,5 @@ = f.input :deposit = form.input :update_current_price, as: :boolean .modal-footer - = button_tag "Schließen", class: 'btn', data: {dismiss: 'modal'} - = form.submit class: 'btn btn-primary' \ No newline at end of file + = link_to 'Schließen', '#', class: 'btn', data: {dismiss: 'modal'} + = form.submit class: 'btn btn-primary' diff --git a/app/views/finance/order_articles/_new.html.haml b/app/views/finance/order_articles/_new.html.haml index 634a8538..b7de2136 100644 --- a/app/views/finance/order_articles/_new.html.haml +++ b/app/views/finance/order_articles/_new.html.haml @@ -1,9 +1,9 @@ = simple_form_for [:finance, @order, @order_article], remote: true do |form| .modal-header - = button_tag "x", class: 'close', data: {dismiss: 'modal'} + = link_to 'x', '#', class: 'close', data: {dismiss: 'modal'} %h3 Neuer gelieferter Artikel die Bestellung .modal-body = form.input :article_id, as: :select, collection: new_order_articles_collection .modal-footer - = button_tag "Schließen", class: 'btn', data: {dismiss: 'modal'} + = link_to 'Schließen', '#', class: 'btn', data: {dismiss: 'modal'} = form.submit class: 'btn btn-primary' \ No newline at end of file diff --git a/app/views/invites/_modal_form.html.haml b/app/views/invites/_modal_form.html.haml index 5be1b0a4..80a73d70 100644 --- a/app/views/invites/_modal_form.html.haml +++ b/app/views/invites/_modal_form.html.haml @@ -1,6 +1,6 @@ = simple_form_for @invite, remote: true do |form| .modal-header - = button_tag "x", class: 'close', data: {dismiss: 'modal'} + = link_to 'x', '#', class: 'close', data: {dismiss: 'modal'} %h3 Person einladen .modal-body %p @@ -13,5 +13,5 @@ = form.hidden_field :group_id = form.input :email .modal-footer - = button_tag "Schließen", class: 'btn', data: {dismiss: 'modal'} + = link_to 'Schließen', '#', class: 'btn', data: {dismiss: 'modal'} = form.submit class: 'btn btn-primary' From 20e439c2a70565bf1898917871084aae72fe3861 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Mon, 8 Apr 2013 14:40:02 +0200 Subject: [PATCH 6/8] Allow article price equal to zero. Closes #111 --- app/models/article.rb | 3 ++- app/models/article_price.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 80ef567e..097c6cbb 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -18,7 +18,8 @@ class Article < ActiveRecord::Base validates_presence_of :name, :unit, :price, :tax, :deposit, :unit_quantity, :supplier_id, :article_category validates_length_of :name, :in => 4..60 validates_length_of :unit, :in => 2..15 - validates_numericality_of :price, :unit_quantity, :greater_than => 0 + validates_numericality_of :price, :greater_than_or_equal_to => 0 + validates_numericality_of :unit_quantity, :greater_than => 0 validates_numericality_of :deposit, :tax validates_uniqueness_of :name, :scope => [:supplier_id, :deleted_at, :type] diff --git a/app/models/article_price.rb b/app/models/article_price.rb index e946fc92..29e8d507 100644 --- a/app/models/article_price.rb +++ b/app/models/article_price.rb @@ -4,7 +4,8 @@ class ArticlePrice < ActiveRecord::Base has_many :order_articles validates_presence_of :price, :tax, :deposit, :unit_quantity - validates_numericality_of :price, :unit_quantity, :greater_than => 0 + validates_numericality_of :price, :greater_than_or_equal_to => 0 + validates_numericality_of :unit_quantity, :greater_than => 0 validates_numericality_of :deposit, :tax localize_input_of :price, :tax, :deposit From 77d4caea68e87976396525c2fd3c3ca6e161a69b Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Mon, 8 Apr 2013 15:08:18 +0200 Subject: [PATCH 7/8] Added quiet_assets gem to have cleaner log file in developing. --- Gemfile | 3 +++ Gemfile.lock | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Gemfile b/Gemfile index f311f384..5af84990 100644 --- a/Gemfile +++ b/Gemfile @@ -55,4 +55,7 @@ group :development do # Get infos when not using proper eager loading gem 'bullet' + + # Hide assets requests in log + gem 'quiet_assets' end diff --git a/Gemfile.lock b/Gemfile.lock index 068602a0..821735fd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -126,6 +126,8 @@ GEM prawn (0.12.0) pdf-reader (>= 0.9.0) ttfunk (~> 1.0.2) + quiet_assets (1.0.2) + railties (>= 3.1, < 5.0) rack (1.4.5) rack-cache (1.2) rack (>= 0.4) @@ -237,6 +239,7 @@ DEPENDENCIES meta_search mysql2 prawn + quiet_assets rails (~> 3.2.9) resque ruby-prof From 5b81c53a7343c79698173deba43a80d605fee3af Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Mon, 8 Apr 2013 15:08:57 +0200 Subject: [PATCH 8/8] Fixed setting all user setting to false in user profile. --- app/views/shared/_user_form_fields.html.haml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/shared/_user_form_fields.html.haml b/app/views/shared/_user_form_fields.html.haml index ac1f9a5d..fa11b393 100644 --- a/app/views/shared/_user_form_fields.html.haml +++ b/app/views/shared/_user_form_fields.html.haml @@ -9,6 +9,7 @@ .controls - for setting in User::setting_keys.keys %label.checkbox{:for => "user[setting_attributes][#{setting}]"} + = hidden_field_tag "user[setting_attributes][#{setting}]", '0' = check_box_tag "user[setting_attributes][#{setting}]", '1', f.object.settings[setting] == '1' || f.object.settings_default(setting) = User::setting_keys[setting]