From 745d6de42beac1eb152c5a85cc7462263e68f2f8 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Sat, 26 Oct 2019 21:00:37 +0200 Subject: [PATCH] Added Quantity ordering Some table columns made unwrappable --- app/controllers/quantities_controller.rb | 22 ++++++++++++- app/views/quantities/index.html.erb | 38 +++++++++++++++++++++-- assets/images/1leftarrow.png | Bin 0 -> 254 bytes assets/images/1rightarrow.png | Bin 0 -> 255 bytes assets/stylesheets/body_tracking.css | 5 +++ config/locales/en.yml | 3 +- config/routes.rb | 1 + init.rb | 2 +- 8 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 assets/images/1leftarrow.png create mode 100644 assets/images/1rightarrow.png diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index 4889123..0e2bccb 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -1,6 +1,6 @@ class QuantitiesController < ApplicationController before_action :find_project_by_project_id, only: [:index, :create] - before_action :find_quantity, only: [:destroy, :toggle] + before_action :find_quantity, only: [:destroy, :toggle, :up, :down, :left, :right] before_action :authorize def index @@ -31,6 +31,26 @@ class QuantitiesController < ApplicationController redirect_to project_quantities_url(@project) end + def up + @quantity.move_left if @quantity.left_sibling.present? + redirect_to project_quantities_url(@project) + end + + def down + @quantity.move_right if @quantity.right_sibling.present? + redirect_to project_quantities_url(@project) + end + + def left + @quantity.move_to_right_of(@quantity.parent) if @quantity.parent.present? + redirect_to project_quantities_url(@project) + end + + def right + @quantity.move_to_child_of(@quantity.left_sibling) if @quantity.left_sibling.present? + redirect_to project_quantities_url(@project) + end + private def quantity_params diff --git a/app/views/quantities/index.html.erb b/app/views/quantities/index.html.erb index bcd54a4..b0043d1 100644 --- a/app/views/quantities/index.html.erb +++ b/app/views/quantities/index.html.erb @@ -27,10 +27,11 @@ + - + @@ -42,11 +43,44 @@ quantity_class += " primary" if q.primary %> + diff --git a/assets/images/1leftarrow.png b/assets/images/1leftarrow.png new file mode 100644 index 0000000000000000000000000000000000000000..f2f02731b450b281372ae392c158986c94033665 GIT binary patch literal 254 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbK}V1Q4E>wgA@d+*QPdw*@tx$HT| zil2YKxAY#6y!QP4z4zbWuYF#9@B6X;|Nmcmer(RM>i_@0Z++gg^jOc7y~W?ZzkmPz z`PTO>Ywz`}z1Fkz98kPv&fb>X56UxuhBKA~`2{mLJiCzwvL>4nJ@ErkR#;MwT z(m+8sPZ!4!iK)p63i2Pi7kskZ=@R&3O$-y$i5fSvyfVWSJ7a79-4>G=gt?XZg*Pz- wv`lwqIvT)d=jdsY-MZw0j9Sk#10e>6FM5o(-fL#}0ZnA^boFyt=akR{0M5j0BLDyZ literal 0 HcmV?d00001 diff --git a/assets/images/1rightarrow.png b/assets/images/1rightarrow.png new file mode 100644 index 0000000000000000000000000000000000000000..ea12516a871700ec4e138fed8d38b1b50cd14d2c GIT binary patch literal 255 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbK}V1Q4E>wgA@d+*QPdw*@tx$HT| zil2YKxAY#6y!QP4z4zbWuYF#9@B6X;|Nmcmer(RM>i_@0Z++gg^jOc7y~W?ZzkmPz z`PTO>Ywz`}z1Fkz98kPv&fb>X56UxuhBKA~`2{mLJiCzwvL>4nJ@ErkR#;MwT z(m+9XPZ!4!iK)p63gR6ci#a_w3m0*DaD6IVz~NEwVUvL(cZcyugGC)3n?G+bHdf;7 y*jT(-@v|fg%Z`XZ9?_>xo5Nb>FSuRE%)l~{@z%AM#l1iy89ZJ6T-G@yGywo^QEzwv literal 0 HcmV?d00001 diff --git a/assets/stylesheets/body_tracking.css b/assets/stylesheets/body_tracking.css index df6123e..0a1b032 100644 --- a/assets/stylesheets/body_tracking.css +++ b/assets/stylesheets/body_tracking.css @@ -1,3 +1,8 @@ table.list tr.quantity.primary td.name {font-weight: bold;} table.list td.action, table.list td.value {text-align: right;} +table.list td.action, +table.list td.name {white-space: nowrap;} + +.icon-move-left { background-image: url(../images/1leftarrow.png); } +.icon-move-right { background-image: url(../images/1rightarrow.png); } diff --git a/config/locales/en.yml b/config/locales/en.yml index 585f381..97738e2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,6 +1,7 @@ # English strings go here for Rails i18n en: body_trackers_menu_caption: 'Body trackers' + field_order: 'Order' field_action: 'Action' field_reference: 'Reference' field_group: 'Group' @@ -10,7 +11,7 @@ en: field_domain: 'Domain' field_parent_quantity: 'Parent' field_shortname: 'Short name' - button_toggle: 'Toggle' + button_primary: 'Primary' activerecord: errors: models: diff --git a/config/routes.rb b/config/routes.rb index bfdc24c..c52acc8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,7 @@ resources :projects do resources :sources, :only => [:index, :create, :destroy] resources :quantities, :only => [:index, :create, :destroy] do post 'toggle', on: :member + post 'up', 'down', 'left', 'right', on: :member end resources :units, :only => [:index, :create, :destroy] end diff --git a/init.rb b/init.rb index 6f87ae9..ab1b3ab 100644 --- a/init.rb +++ b/init.rb @@ -24,7 +24,7 @@ Redmine::Plugin.register :body_tracking do :body_trackers => [:defaults], :ingredients => [:create, :destroy, :import], :sources => [:create, :destroy], - :quantities => [:create, :destroy, :toggle], + :quantities => [:create, :destroy, :toggle, :up, :down, :left, :right], :units => [:create, :destroy], }, require: :loggedin end
<%= l(:field_order) %> <%= l(:field_name) %> <%= l(:field_domain) %> <%= l(:field_description) %><%= l(:field_action) %><%= l(:field_action) %>
+ <%= + if q.left_sibling.present? + link_to '', up_quantity_path(q), {method: :post, class: "icon icon-move-up"} + else + link_to '', '', {class: "icon"} + end + %> + <%= + if q.right_sibling.present? + link_to '', down_quantity_path(q), + {method: :post, class: "icon icon-move-down"} + else + link_to '', '', {class: "icon"} + end + %> + <%= + if q.parent.present? + link_to '', left_quantity_path(q), + {method: :post, class: "icon icon-move-left"} + else + link_to '', '', {class: "icon"} + end + %> + <%= + if q.left_sibling.present? + link_to '', right_quantity_path(q), + {method: :post, class: "icon icon-move-right"} + else + link_to '', '', {class: "icon"} + end + %> + <%= q.name %> <%= q.domain %> <%= q.description %> - <%= link_to l(:button_toggle), toggle_quantity_path(q), + <%= link_to l(:button_primary), toggle_quantity_path(q), {method: :post, class: "icon #{q.primary ? "icon-fav" : "icon-fav-off"}"} %> <%= delete_link quantity_path(q), data: {} %>