Finished Sources implementation
This commit is contained in:
parent
35f8ec4b2c
commit
593e11ff53
@ -7,7 +7,7 @@ class IngredientsController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@ingredient = @project.ingredients.new
|
@ingredient = @project.ingredients.new
|
||||||
# passing attr for after_initialize
|
# passing attr for Nutrient after_initialize
|
||||||
@ingredient.nutrients.new(ingredient: @ingredient)
|
@ingredient.nutrients.new(ingredient: @ingredient)
|
||||||
@ingredients = @project.ingredients.includes(:ref_unit)
|
@ingredients = @project.ingredients.includes(:ref_unit)
|
||||||
@ingredients << @ingredient
|
@ingredients << @ingredient
|
||||||
|
@ -39,7 +39,7 @@ class SourcesController < ApplicationController
|
|||||||
# :find_* methods are called before :authorize,
|
# :find_* methods are called before :authorize,
|
||||||
# @project is required for :authorize to succeed
|
# @project is required for :authorize to succeed
|
||||||
def find_source
|
def find_source
|
||||||
@unit = Source.find(params[:id])
|
@source = Source.find(params[:id])
|
||||||
@project = @source.project
|
@project = @source.project
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
|
@ -1,2 +1,5 @@
|
|||||||
class Source < ActiveRecord::Base
|
class Source < ActiveRecord::Base
|
||||||
|
belongs_to :project, required: false
|
||||||
|
|
||||||
|
validates :name, presence: true, uniqueness: {scope: :project_id}
|
||||||
end
|
end
|
||||||
|
6
app/views/sources/_form.html.erb
Normal file
6
app/views/sources/_form.html.erb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<%= error_messages_for @source %>
|
||||||
|
|
||||||
|
<div class="box tabular">
|
||||||
|
<p><%= f.text_field :name, required: true, size: 20 %></p>
|
||||||
|
<p><%= f.text_area :description, rows: 3, cols: 60 %></p>
|
||||||
|
</div>
|
@ -1 +1,48 @@
|
|||||||
<h2>SourcesController#index</h2>
|
<% content_for :sidebar do %>
|
||||||
|
<%= render :partial => 'body_trackers/sidebar' %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="contextual">
|
||||||
|
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||||
|
<%= link_to t(".heading_new_source"), '#', :class => 'icon icon-add',
|
||||||
|
:onclick => 'showAndScrollTo("add-source", "source_name"); return false;' %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="add-source" <%= 'style=display:none;' if @source.errors.empty? %>>
|
||||||
|
<h2><%= t ".heading_new_source" %></h2>
|
||||||
|
|
||||||
|
<%= labelled_form_for @source,
|
||||||
|
:url => project_sources_path(@project),
|
||||||
|
:html => {:id => 'source-form'} do |f| %>
|
||||||
|
<%= render :partial => 'sources/form', :locals => { :f => f } %>
|
||||||
|
<%= submit_tag l(:button_create) %>
|
||||||
|
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-source").hide()' %>
|
||||||
|
<% end %>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2><%= t ".heading" %></h2>
|
||||||
|
<% if @sources.many? %>
|
||||||
|
<table class="list">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= l(:field_name) %></th>
|
||||||
|
<th><%= l(:field_description) %></th>
|
||||||
|
<th style="width:15%"><%= l(:field_action) %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @sources.each do |s| %>
|
||||||
|
<% next if s.new_record? %>
|
||||||
|
<tr id="source-<%= s.id %>" class="source">
|
||||||
|
<td class="name"><%= s.name %></td>
|
||||||
|
<td class="description"><%= s.description %></td>
|
||||||
|
<td><%= delete_link source_path(s), data: {} %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% else %>
|
||||||
|
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||||
|
<% end %>
|
||||||
|
@ -54,6 +54,10 @@ en:
|
|||||||
groups:
|
groups:
|
||||||
other: 'other'
|
other: 'other'
|
||||||
meat: 'meat'
|
meat: 'meat'
|
||||||
|
sources:
|
||||||
|
index:
|
||||||
|
heading: 'Data sources'
|
||||||
|
heading_new_source: 'New source'
|
||||||
quantities:
|
quantities:
|
||||||
index:
|
index:
|
||||||
heading: 'Quantities'
|
heading: 'Quantities'
|
||||||
|
@ -3,6 +3,7 @@ module BodyTracking
|
|||||||
Project.class_eval do
|
Project.class_eval do
|
||||||
has_many :ingredients, -> { order "name" }, dependent: :destroy
|
has_many :ingredients, -> { order "name" }, dependent: :destroy
|
||||||
|
|
||||||
|
has_many :sources, dependent: :destroy
|
||||||
has_many :quantities, -> { order "lft" }, dependent: :destroy
|
has_many :quantities, -> { order "lft" }, dependent: :destroy
|
||||||
has_many :units, dependent: :destroy
|
has_many :units, dependent: :destroy
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user