1
0

Added quantity edit form

Changed quantity long text field width setting
This commit is contained in:
cryptogopher 2019-11-24 01:26:35 +01:00
parent 8c073494e5
commit fdfedf3bc9
9 changed files with 116 additions and 81 deletions

View File

@ -1,7 +1,7 @@
class QuantitiesController < ApplicationController class QuantitiesController < ApplicationController
before_action :init_session_filters before_action :init_session_filters
before_action :find_project_by_project_id, only: [:index, :create, :filter] before_action :find_project_by_project_id, only: [:index, :create, :filter]
before_action :find_quantity, only: [:destroy, :toggle, :move] before_action :find_quantity, only: [:edit, :update, :destroy, :toggle, :move]
before_action :authorize before_action :authorize
def index def index
@ -21,6 +21,17 @@ class QuantitiesController < ApplicationController
end end
end end
def filter
session[:q_filters] = params[:filters]
prepare_quantities
render :toggle
end
def edit
prepare_quantities
render :toggle
end
def destroy def destroy
if @quantity.destroy if @quantity.destroy
flash[:notice] = 'Deleted quantity' flash[:notice] = 'Deleted quantity'
@ -34,12 +45,6 @@ class QuantitiesController < ApplicationController
prepare_quantities prepare_quantities
end end
def filter
session[:q_filters] = params[:filters]
prepare_quantities
render :toggle
end
def move def move
direction = params[:direction].to_sym direction = params[:direction].to_sym
case direction case direction

View File

@ -9,8 +9,9 @@
</div> </div>
<% end %> <% end %>
<p><%= f.text_field :name, size: 25, required: true %></p> <p><%= f.text_field :name, size: 25, required: true %></p>
<p><%= f.text_field :description, size: 200 %></p> <p><%= f.text_field :description, style: "width: 100%;" %></p>
<p><%= f.text_field :formula, size: 200, placeholder: t('.formula_placeholder') %></p> <p><%= f.text_field :formula, placeholder: t('.formula_placeholder'),
style: "width: 100%;" %></p>
<p><%= f.check_box :primary %></p> <p><%= f.check_box :primary %></p>
</div> </div>

View File

@ -0,0 +1,81 @@
<%= render :partial => 'quantities/filters',
:locals => {:url => filter_project_quantities_path(@project)} %>
<% if @quantities.any? { |q| q.persisted? } %>
<table class="list">
<thead>
<tr>
<th><%= l(:field_name) %></th>
<th><%= l(:field_order) %></th>
<th><%= l(:field_domain) %></th>
<th><%= l(:field_description) %></th>
<th><%= l(:field_action) %></th>
</tr>
</thead>
<tbody>
<% Quantity.each_with_level(@quantities) do |q, level| %>
<%
next if q.new_record?
quantity_class = "quantity"
quantity_class += " project idnt idnt-#{level+1}"
quantity_class += " primary" if q.primary
%>
<tr id="quantity-<%= q.id %>" class="<%= quantity_class %>">
<td class="name">
<%= link_to '', toggle_quantity_path(q), {
remote: true,
method: :post,
class: "icon #{q.primary ? "icon-fav" : "icon-fav-off"}"
}
%>
<%= q.name %>
</td>
<td class="order">
<% [:up, :down, :left, :right].each do |direction| %>
<%=
if q.movable?(direction)
link_to '', move_quantity_path(q, direction), {
remote: true,
method: :post,
class: "icon icon-move-#{direction}"
}
else
link_to '', '', {class: "icon"}
end
%>
<% end %>
</td>
<td class="domain"><%= q.domain %></td>
<td class="description"><%= q.description %></td>
<td class="action">
<%=
link_to l(:button_edit), edit_quantity_path(q), {
remote: true,
class: "icon icon-edit"
}
%>
<%= delete_link quantity_path(q), {remote: true, data: {}} %>
</td>
</tr>
<% next unless (action_name == "edit") && (q == @quantity) %>
<tr>
<td class="form" colspan="6">
<div id="edit-quantity">
<%= labelled_form_for @quantity, url: quantity_path(@quantity), method: :patch,
remote: true, html: {id: 'quantity-edit-form'} do |f| %>
<%= render :partial => 'quantities/form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<%=
link_to l(:button_cancel), "#", :onclick => '$("#edit-quantity").hide()'
%>
<% end %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@ -1,60 +0,0 @@
<%= render :partial => 'quantities/filters',
:locals => {:url => filter_project_quantities_path(@project)} %>
<% if @quantities.any? { |q| q.persisted? } %>
<table class="list">
<thead>
<tr>
<th><%= l(:field_name) %></th>
<th><%= l(:field_order) %></th>
<th><%= l(:field_domain) %></th>
<th><%= l(:field_description) %></th>
<th><%= l(:field_action) %></th>
</tr>
</thead>
<tbody>
<% Quantity.each_with_level(@quantities) do |q, level| %>
<%
next if q.new_record?
quantity_class = "quantity"
quantity_class += " project idnt idnt-#{level+1}"
quantity_class += " primary" if q.primary
quantity_class += " anchor" if @anchor == q.id
%>
<tr id="quantity-<%= q.id %>" class="<%= quantity_class %>">
<td class="name">
<%= link_to '', toggle_quantity_path(q), {
remote: true,
method: :post,
class: "icon #{q.primary ? "icon-fav" : "icon-fav-off"}"
}
%>
<%= q.name %>
</td>
<td class="order">
<% [:up, :down, :left, :right].each do |direction| %>
<%=
if q.movable?(direction)
link_to '', move_quantity_path(q, direction), {
remote: true,
method: :post,
class: "icon icon-move-#{direction}"
}
else
link_to '', '', {class: "icon"}
end
%>
<% end %>
</td>
<td class="domain"><%= q.domain %></td>
<td class="description"><%= q.description %></td>
<td class="action">
<%= delete_link quantity_path(q), {remote: true, data: {}} %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@ -5,7 +5,7 @@
<div class="contextual"> <div class="contextual">
<% if User.current.allowed_to?(:manage_common, @project) %> <% if User.current.allowed_to?(:manage_common, @project) %>
<%= link_to t(".link_new_quantity"), '#', :class => 'icon icon-add', <%= link_to t(".link_new_quantity"), '#', :class => 'icon icon-add',
:onclick => '$("#add-quantity").show(); $("#quantity_name").focus(); return false;' %> :onclick => '$("#add-quantity").toggle(); $("#quantity_name").focus(); return false;' %>
<% end %> <% end %>
</div> </div>
@ -24,5 +24,5 @@
<h2><%= t ".heading" %></h2> <h2><%= t ".heading" %></h2>
<div id='quantities'> <div id='quantities'>
<%= render :partial => 'quantities/list' %> <%= render :partial => 'quantities/index' %>
</div> </div>

View File

@ -1,3 +1,3 @@
$('div[id^=flash_]').remove(); $('div[id^=flash_]').remove();
$('#content').prepend('<%= escape_javascript(render_flash_messages) %>'); $('#content').prepend('<%= escape_javascript(render_flash_messages) %>');
$('#quantities').html('<%= escape_javascript(render :partial => 'quantities/list') %>'); $('#quantities').html('<%= escape_javascript(render :partial => 'quantities/index') %>');

View File

@ -17,6 +17,10 @@ table.list td.value {
white-space: nowrap; white-space: nowrap;
max-width: 1px; max-width: 1px;
} }
table.list td.form {
padding-right: 2px;
text-align: left;
}
fieldset#filters table.filter td {padding-left: 8px;} fieldset#filters table.filter td {padding-left: 8px;}
.icon-move-left { background-image: url(../images/1leftarrow.png); } .icon-move-left { background-image: url(../images/1leftarrow.png); }

View File

@ -10,17 +10,21 @@ resources :projects do
post 'toggle', on: :member post 'toggle', on: :member
end end
resources :ingredients, :only => [:index, :create, :destroy] do resources :ingredients, :only => [:index, :create, :destroy] do
get 'nutrients', on: :collection
post 'toggle_nutrient_column', on: :collection
post 'toggle', on: :member post 'toggle', on: :member
get 'filter', on: :collection collection do
get 'filter_nutrients', on: :collection get 'nutrients'
post 'import', on: :collection get 'filter'
get 'filter_nutrients'
post 'toggle_nutrient_column'
post 'import'
end
end end
resources :sources, :only => [:index, :create, :destroy] resources :sources, :only => [:index, :create, :destroy]
resources :quantities, :only => [:index, :create, :destroy] do resources :quantities, :only => [:index, :create, :edit, :update, :destroy] do
post 'toggle', on: :member member do
post 'move/:direction', to: 'quantities#move', as: :move, on: :member post 'toggle'
post 'move/:direction', to: 'quantities#move', as: :move
end
get 'filter', on: :collection get 'filter', on: :collection
end end
resources :units, :only => [:index, :create, :destroy] resources :units, :only => [:index, :create, :destroy]

View File

@ -27,7 +27,7 @@ Redmine::Plugin.register :body_tracking do
:measurements => [:create, :destroy, :toggle], :measurements => [:create, :destroy, :toggle],
:ingredients => [:create, :destroy, :toggle, :import, :toggle_nutrient_column], :ingredients => [:create, :destroy, :toggle, :import, :toggle_nutrient_column],
:sources => [:create, :destroy], :sources => [:create, :destroy],
:quantities => [:create, :destroy, :toggle, :move], :quantities => [:create, :edit, :update, :destroy, :toggle, :move],
:units => [:create, :destroy], :units => [:create, :destroy],
}, require: :loggedin }, require: :loggedin
end end