Disallowed moving quantity into parent/child relationship if domains differ
Generalized quantity up/down/left/right actions into 'move'
This commit is contained in:
parent
0820a90897
commit
8c073494e5
@ -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, :up, :down, :left, :right]
|
before_action :find_quantity, only: [:destroy, :toggle, :move]
|
||||||
before_action :authorize
|
before_action :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@ -40,26 +40,19 @@ class QuantitiesController < ApplicationController
|
|||||||
render :toggle
|
render :toggle
|
||||||
end
|
end
|
||||||
|
|
||||||
def up
|
def move
|
||||||
@quantity.move_left if @quantity.left_sibling.present?
|
direction = params[:direction].to_sym
|
||||||
prepare_quantities
|
case direction
|
||||||
render :toggle
|
when :up
|
||||||
end
|
@quantity.move_left
|
||||||
|
when :down
|
||||||
|
@quantity.move_right
|
||||||
|
when :left
|
||||||
|
@quantity.move_to_right_of(@quantity.parent)
|
||||||
|
when :right
|
||||||
|
@quantity.move_to_child_of(@quantity.left_sibling)
|
||||||
|
end if @quantity.movable?(direction)
|
||||||
|
|
||||||
def down
|
|
||||||
@quantity.move_right if @quantity.right_sibling.present?
|
|
||||||
prepare_quantities
|
|
||||||
render :toggle
|
|
||||||
end
|
|
||||||
|
|
||||||
def left
|
|
||||||
@quantity.move_to_right_of(@quantity.parent) if @quantity.parent.present?
|
|
||||||
prepare_quantities
|
|
||||||
render :toggle
|
|
||||||
end
|
|
||||||
|
|
||||||
def right
|
|
||||||
@quantity.move_to_child_of(@quantity.left_sibling) if @quantity.left_sibling.present?
|
|
||||||
prepare_quantities
|
prepare_quantities
|
||||||
render :toggle
|
render :toggle
|
||||||
end
|
end
|
||||||
|
@ -23,6 +23,22 @@ class Quantity < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def movable?(direction)
|
||||||
|
case direction
|
||||||
|
when :up
|
||||||
|
self.left_sibling.present?
|
||||||
|
when :down
|
||||||
|
self.right_sibling.present?
|
||||||
|
when :left
|
||||||
|
self.parent.present?
|
||||||
|
when :right
|
||||||
|
left = self.left_sibling
|
||||||
|
left.present? && (left.domain == self.domain)
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def toggle_primary!
|
def toggle_primary!
|
||||||
self.toggle!(:primary)
|
self.toggle!(:primary)
|
||||||
end
|
end
|
||||||
|
@ -32,50 +32,19 @@
|
|||||||
<%= q.name %>
|
<%= q.name %>
|
||||||
</td>
|
</td>
|
||||||
<td class="order">
|
<td class="order">
|
||||||
|
<% [:up, :down, :left, :right].each do |direction| %>
|
||||||
<%=
|
<%=
|
||||||
if q.left_sibling.present?
|
if q.movable?(direction)
|
||||||
link_to '', up_quantity_path(q), {
|
link_to '', move_quantity_path(q, direction), {
|
||||||
remote: true,
|
remote: true,
|
||||||
method: :post,
|
method: :post,
|
||||||
class: "icon icon-move-up"
|
class: "icon icon-move-#{direction}"
|
||||||
}
|
|
||||||
else
|
|
||||||
link_to '', '', {class: "icon"}
|
|
||||||
end
|
|
||||||
%>
|
|
||||||
<%=
|
|
||||||
if q.right_sibling.present?
|
|
||||||
link_to '', down_quantity_path(q), {
|
|
||||||
remote: true,
|
|
||||||
method: :post,
|
|
||||||
class: "icon icon-move-down"
|
|
||||||
}
|
|
||||||
else
|
|
||||||
link_to '', '', {class: "icon"}
|
|
||||||
end
|
|
||||||
%>
|
|
||||||
<%=
|
|
||||||
if q.parent.present?
|
|
||||||
link_to '', left_quantity_path(q), {
|
|
||||||
remote: true,
|
|
||||||
method: :post,
|
|
||||||
class: "icon icon-move-left"
|
|
||||||
}
|
|
||||||
else
|
|
||||||
link_to '', '', {class: "icon"}
|
|
||||||
end
|
|
||||||
%>
|
|
||||||
<%=
|
|
||||||
if q.left_sibling.present?
|
|
||||||
link_to '', right_quantity_path(q), {
|
|
||||||
remote: true,
|
|
||||||
method: :post,
|
|
||||||
class: "icon icon-move-right"
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
link_to '', '', {class: "icon"}
|
link_to '', '', {class: "icon"}
|
||||||
end
|
end
|
||||||
%>
|
%>
|
||||||
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="domain"><%= q.domain %></td>
|
<td class="domain"><%= q.domain %></td>
|
||||||
<td class="description"><%= q.description %></td>
|
<td class="description"><%= q.description %></td>
|
||||||
|
@ -20,7 +20,7 @@ resources :projects do
|
|||||||
resources :sources, :only => [:index, :create, :destroy]
|
resources :sources, :only => [:index, :create, :destroy]
|
||||||
resources :quantities, :only => [:index, :create, :destroy] do
|
resources :quantities, :only => [:index, :create, :destroy] do
|
||||||
post 'toggle', on: :member
|
post 'toggle', on: :member
|
||||||
post 'up', 'down', 'left', 'right', on: :member
|
post 'move/:direction', to: 'quantities#move', as: :move, on: :member
|
||||||
get 'filter', on: :collection
|
get 'filter', on: :collection
|
||||||
end
|
end
|
||||||
resources :units, :only => [:index, :create, :destroy]
|
resources :units, :only => [:index, :create, :destroy]
|
||||||
|
2
init.rb
2
init.rb
@ -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, :up, :down, :left, :right],
|
:quantities => [:create, :destroy, :toggle, :move],
|
||||||
:units => [:create, :destroy],
|
:units => [:create, :destroy],
|
||||||
}, require: :loggedin
|
}, require: :loggedin
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user