From fdfedf3bc9523f19e2995df2a617096e9fbb766d Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Sun, 24 Nov 2019 01:26:35 +0100 Subject: [PATCH] Added quantity edit form Changed quantity long text field width setting --- app/controllers/quantities_controller.rb | 19 ++++-- app/views/quantities/_form.html.erb | 5 +- app/views/quantities/_index.html.erb | 81 ++++++++++++++++++++++++ app/views/quantities/_list.html.erb | 60 ------------------ app/views/quantities/index.html.erb | 4 +- app/views/quantities/toggle.js.erb | 2 +- assets/stylesheets/body_tracking.css | 4 ++ config/routes.rb | 20 +++--- init.rb | 2 +- 9 files changed, 116 insertions(+), 81 deletions(-) create mode 100644 app/views/quantities/_index.html.erb delete mode 100644 app/views/quantities/_list.html.erb diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index 443df62..c401f29 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -1,7 +1,7 @@ class QuantitiesController < ApplicationController before_action :init_session_filters 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 def index @@ -21,6 +21,17 @@ class QuantitiesController < ApplicationController end end + def filter + session[:q_filters] = params[:filters] + prepare_quantities + render :toggle + end + + def edit + prepare_quantities + render :toggle + end + def destroy if @quantity.destroy flash[:notice] = 'Deleted quantity' @@ -34,12 +45,6 @@ class QuantitiesController < ApplicationController prepare_quantities end - def filter - session[:q_filters] = params[:filters] - prepare_quantities - render :toggle - end - def move direction = params[:direction].to_sym case direction diff --git a/app/views/quantities/_form.html.erb b/app/views/quantities/_form.html.erb index f2351dc..6a2c54c 100644 --- a/app/views/quantities/_form.html.erb +++ b/app/views/quantities/_form.html.erb @@ -9,8 +9,9 @@ <% end %>

<%= f.text_field :name, size: 25, required: true %>

-

<%= f.text_field :description, size: 200 %>

-

<%= f.text_field :formula, size: 200, placeholder: t('.formula_placeholder') %>

+

<%= f.text_field :description, style: "width: 100%;" %>

+

<%= f.text_field :formula, placeholder: t('.formula_placeholder'), + style: "width: 100%;" %>

<%= f.check_box :primary %>

diff --git a/app/views/quantities/_index.html.erb b/app/views/quantities/_index.html.erb new file mode 100644 index 0000000..ad3f448 --- /dev/null +++ b/app/views/quantities/_index.html.erb @@ -0,0 +1,81 @@ +<%= render :partial => 'quantities/filters', + :locals => {:url => filter_project_quantities_path(@project)} %> + +<% if @quantities.any? { |q| q.persisted? } %> + + + + + + + + + + + + <% 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 + %> + + + + + + + + <% next unless (action_name == "edit") && (q == @quantity) %> + + + + <% end %> + +
<%= l(:field_name) %><%= l(:field_order) %><%= l(:field_domain) %><%= l(:field_description) %><%= l(:field_action) %>
+ <%= link_to '', toggle_quantity_path(q), { + remote: true, + method: :post, + class: "icon #{q.primary ? "icon-fav" : "icon-fav-off"}" + } + %> + <%= q.name %> + + <% [: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 %> + <%= q.domain %><%= q.description %> + <%= + link_to l(:button_edit), edit_quantity_path(q), { + remote: true, + class: "icon icon-edit" + } + %> + <%= delete_link quantity_path(q), {remote: true, data: {}} %> +
+
+ <%= 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 %> +
+
+<% else %> +

<%= l(:label_no_data) %>

+<% end %> diff --git a/app/views/quantities/_list.html.erb b/app/views/quantities/_list.html.erb deleted file mode 100644 index 160d583..0000000 --- a/app/views/quantities/_list.html.erb +++ /dev/null @@ -1,60 +0,0 @@ -<%= render :partial => 'quantities/filters', - :locals => {:url => filter_project_quantities_path(@project)} %> - -<% if @quantities.any? { |q| q.persisted? } %> - - - - - - - - - - - - <% 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 - %> - - - - - - - - <% end %> - -
<%= l(:field_name) %><%= l(:field_order) %><%= l(:field_domain) %><%= l(:field_description) %><%= l(:field_action) %>
- <%= link_to '', toggle_quantity_path(q), { - remote: true, - method: :post, - class: "icon #{q.primary ? "icon-fav" : "icon-fav-off"}" - } - %> - <%= q.name %> - - <% [: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 %> - <%= q.domain %><%= q.description %> - <%= delete_link quantity_path(q), {remote: true, data: {}} %> -
-<% else %> -

<%= l(:label_no_data) %>

-<% end %> diff --git a/app/views/quantities/index.html.erb b/app/views/quantities/index.html.erb index 372f627..18448df 100644 --- a/app/views/quantities/index.html.erb +++ b/app/views/quantities/index.html.erb @@ -5,7 +5,7 @@
<% if User.current.allowed_to?(:manage_common, @project) %> <%= 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 %>
@@ -24,5 +24,5 @@

<%= t ".heading" %>

- <%= render :partial => 'quantities/list' %> + <%= render :partial => 'quantities/index' %>
diff --git a/app/views/quantities/toggle.js.erb b/app/views/quantities/toggle.js.erb index eb6067e..2f11725 100644 --- a/app/views/quantities/toggle.js.erb +++ b/app/views/quantities/toggle.js.erb @@ -1,3 +1,3 @@ $('div[id^=flash_]').remove(); $('#content').prepend('<%= escape_javascript(render_flash_messages) %>'); -$('#quantities').html('<%= escape_javascript(render :partial => 'quantities/list') %>'); +$('#quantities').html('<%= escape_javascript(render :partial => 'quantities/index') %>'); diff --git a/assets/stylesheets/body_tracking.css b/assets/stylesheets/body_tracking.css index b6d7a5c..9da6748 100644 --- a/assets/stylesheets/body_tracking.css +++ b/assets/stylesheets/body_tracking.css @@ -17,6 +17,10 @@ table.list td.value { white-space: nowrap; max-width: 1px; } +table.list td.form { + padding-right: 2px; + text-align: left; +} fieldset#filters table.filter td {padding-left: 8px;} .icon-move-left { background-image: url(../images/1leftarrow.png); } diff --git a/config/routes.rb b/config/routes.rb index 23707e3..4d7a9ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,17 +10,21 @@ resources :projects do post 'toggle', on: :member end resources :ingredients, :only => [:index, :create, :destroy] do - get 'nutrients', on: :collection - post 'toggle_nutrient_column', on: :collection post 'toggle', on: :member - get 'filter', on: :collection - get 'filter_nutrients', on: :collection - post 'import', on: :collection + collection do + get 'nutrients' + get 'filter' + get 'filter_nutrients' + post 'toggle_nutrient_column' + post 'import' + end end resources :sources, :only => [:index, :create, :destroy] - resources :quantities, :only => [:index, :create, :destroy] do - post 'toggle', on: :member - post 'move/:direction', to: 'quantities#move', as: :move, on: :member + resources :quantities, :only => [:index, :create, :edit, :update, :destroy] do + member do + post 'toggle' + post 'move/:direction', to: 'quantities#move', as: :move + end get 'filter', on: :collection end resources :units, :only => [:index, :create, :destroy] diff --git a/init.rb b/init.rb index 6f81e53..0c03f9b 100644 --- a/init.rb +++ b/init.rb @@ -27,7 +27,7 @@ Redmine::Plugin.register :body_tracking do :measurements => [:create, :destroy, :toggle], :ingredients => [:create, :destroy, :toggle, :import, :toggle_nutrient_column], :sources => [:create, :destroy], - :quantities => [:create, :destroy, :toggle, :move], + :quantities => [:create, :edit, :update, :destroy, :toggle, :move], :units => [:create, :destroy], }, require: :loggedin end