Added Ingredients import action
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class IngredientsController < ApplicationController
|
||||
before_action :find_project_by_project_id, only: [:index, :create]
|
||||
before_action :find_project_by_project_id, only: [:index, :create, :import]
|
||||
before_action :find_ingredient, only: [:destroy]
|
||||
before_action :authorize
|
||||
|
||||
@@ -29,6 +29,9 @@ class IngredientsController < ApplicationController
|
||||
redirect_to project_ingredients_url(@project)
|
||||
end
|
||||
|
||||
def import
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ingredient_params
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Ingredient < ActiveRecord::Base
|
||||
enum group: {
|
||||
meat: 0
|
||||
other: 0,
|
||||
meat: 1
|
||||
}
|
||||
|
||||
belongs_to :project
|
||||
@@ -27,8 +28,10 @@ class Ingredient < ActiveRecord::Base
|
||||
|
||||
after_initialize do
|
||||
if new_record?
|
||||
self.ref_amount ||= 100
|
||||
units = self.project.units
|
||||
self.ref_unit ||= units.find_by(shortname: 'g') || units.first
|
||||
self.group ||= :other
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -4,11 +4,34 @@
|
||||
|
||||
<div class="contextual">
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<%= link_to t(".heading_import_ingredients"), '#', :class => 'icon icon-file',
|
||||
:onclick => 'showAndScrollTo("import-ingredients", "filename"); return false;' %>
|
||||
<%= link_to t(".heading_new_ingredient"), '#', :class => 'icon icon-add',
|
||||
:onclick => 'showAndScrollTo("add-ingredient", "ingredient_name"); return false;' %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div id="import-ingredients" style="display:none;">
|
||||
<h2><%= t ".heading_import_ingredients" %></h2>
|
||||
|
||||
<%= form_tag import_project_ingredients_path(@project),
|
||||
:multipart => true,
|
||||
:id => 'import-form' do %>
|
||||
<div class="box tabular">
|
||||
<p>
|
||||
<label><%= t ".label_import_select_csv_file" %></label>
|
||||
<%= file_field_tag 'file' %>
|
||||
</p>
|
||||
<p>
|
||||
<%= t ".import_hints" %>
|
||||
</p>
|
||||
</div>
|
||||
<%= submit_tag l(:button_import) %>
|
||||
<%= link_to l(:button_cancel), "#", :onclick => '$("#import-ingredients").hide()' %>
|
||||
<% end %>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
<div id="add-ingredient" <%= 'style=display:none;' if @ingredient.errors.empty? %>>
|
||||
<h2><%= t ".heading_new_ingredient" %></h2>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user