1
0

Renamed: column -> exposure

Moved toggle_column_options to body_trackers helper
This commit is contained in:
cryptogopher 2020-04-25 15:42:22 +02:00
parent 5e3322fe96
commit a4781b4fcd
18 changed files with 57 additions and 55 deletions

View File

@ -10,7 +10,7 @@ class FoodsController < ApplicationController
before_action :init_session_filters
before_action :find_project_by_project_id,
only: [:index, :new, :create, :nutrients, :filter, :autocomplete, :import]
before_action :find_quantity_by_quantity_id, only: [:toggle_column]
before_action :find_quantity_by_quantity_id, only: [:toggle_exposure]
before_action :find_food, only: [:edit, :update, :destroy, :toggle]
before_action :authorize
@ -62,7 +62,7 @@ class FoodsController < ApplicationController
prepare_nutrients
end
def toggle_column
def toggle_exposure
@project.nutrient_exposures.toggle!(@quantity)
prepare_nutrients
end

View File

@ -7,9 +7,9 @@ class MeasurementsController < ApplicationController
before_action :init_session_filters
before_action :find_project_by_project_id, only: [:index, :new, :create, :filter]
before_action :find_quantity_by_quantity_id, only: [:toggle_column]
before_action :find_quantity_by_quantity_id, only: [:toggle_exposure]
before_action :find_measurement, only: [:edit, :update, :destroy, :retake]
before_action :find_measurement_routine, only: [:readouts, :toggle_column]
before_action :find_measurement_routine, only: [:readouts, :toggle_exposure]
before_action :authorize
def index
@ -82,7 +82,7 @@ class MeasurementsController < ApplicationController
prepare_readouts
end
def toggle_column
def toggle_exposure
@routine.readout_exposures.toggle!(@quantity)
prepare_readouts
end

View File

@ -15,6 +15,16 @@ module BodyTrackersHelper
t.strftime("%R") if t
end
def toggle_exposure_options(enabled, domain)
disabled = []
enabled = enabled.to_a
options = nested_set_options(@project.quantities.send(domain)) do |q|
disabled << q.id if enabled.include?(q)
raw("#{'&ensp;' * q.level}#{q.name}")
end
options_for_select(options, disabled: disabled)
end
def unit_options
@project.units.map do |u|
[u.shortname, u.id]

View File

@ -5,16 +5,6 @@ module FoodsHelper
end
end
def toggle_column_options
disabled = []
enabled_quantities = @project.nutrient_quantities.to_a
options = nested_set_options(@project.quantities.diet) do |q|
disabled << q.id if enabled_quantities.include?(q)
raw("#{'&ensp;' * q.level}#{q.name}")
end
options_for_select(options, disabled: disabled)
end
def visibility_options(selected)
options = [["visible", 1], ["hidden", 0]]
options_for_select(options, selected)

View File

@ -5,16 +5,6 @@ module MeasurementsHelper
.html_safe
end
def toggle_column_options
disabled = []
enabled_quantities = @routine.quantities.to_a
options = nested_set_options(@project.quantities.measurement) do |q|
disabled << q.id if enabled_quantities.include?(q)
raw("#{'&ensp;' * q.level}#{q.name}")
end
options_for_select(options, disabled: disabled)
end
def quantity_options
nested_set_options(@project.quantities.measurement) do |q|
raw("#{'&ensp;' * q.level}#{q.name}")

View File

@ -4,7 +4,7 @@ class MeasurementRoutine < ActiveRecord::Base
foreign_key: 'routine_id', dependent: :restrict_with_error,
extend: BodyTracking::ItemsWithQuantities
has_many :readout_exposures, as: :view, dependent: :destroy,
class_name: 'Exposure', extend: BodyTracking::TogglableColumns
class_name: 'Exposure', extend: BodyTracking::TogglableExposures
has_many :quantities, -> { order "lft" }, through: :readout_exposures
validates :name, presence: true, uniqueness: {scope: :project_id}

View File

@ -17,7 +17,7 @@
<th style="width:<%= 100/total_width %>%" class="closable ellipsible">
<div style="float:right;position:relative;">
<%= link_to '',
toggle_column_project_foods_path(@project, quantity_id: q.id),
toggle_exposure_project_foods_path(@project, quantity_id: q.id),
{class: "icon icon-close", method: :post, remote: true} %>
</div>
<%= q.name %>

View File

@ -1,14 +1,15 @@
<fieldset id="options" class="collapsible">
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
<div>
<%= form_tag toggle_column_project_foods_path(@project),
id: 'toggle-column-form', name: 'toggle-column-form',
<%= form_tag toggle_exposure_project_foods_path(@project),
id: 'toggle-exposure-form', name: 'toggle-exposure-form',
method: :post, remote: true do %>
<table>
<tr>
<td style="width:100%"></td>
<td><%= select_tag 'quantity_id', toggle_column_options %></td>
<td><%= select_tag 'quantity_id',
toggle_exposure_options(@project.nutrient_quantities, :diet) %></td>
<td><%= submit_tag l(:button_add) %></td>
</tr>
</table>

View File

@ -1,4 +1,6 @@
<% if @meals.any? { |m| m.persisted? } %>
<%= render partial: 'meals/options' %>
<table id="meals" class="odd-even list">
<tbody>
<% @meals.group_by { |m| m.eaten_at ? m.eaten_at.to_date : Date.current }

View File

@ -0,0 +1,17 @@
<fieldset id="options" class="collapsible">
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
<div>
<%= form_tag toggle_exposure_project_meals_path(@project),
id: 'toggle-exposure-form', name: 'toggle-exposure-form',
method: :post, remote: true do %>
<table>
<tr>
<td style="width:100%"></td>
<td><%= select_tag 'quantity_id', toggle_column_options %></td>
<td><%= submit_tag l(:button_add) %></td>
</tr>
</table>
<% end %>
</div>
</fieldset>

View File

@ -1,14 +1,15 @@
<fieldset id="options" class="collapsible">
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
<div>
<%= form_tag toggle_column_measurement_routine_path(@routine),
id: 'toggle-column-form', name: 'toggle-column-form',
<%= form_tag toggle_exposure_measurement_routine_path(@routine),
id: 'toggle-exposure-form', name: 'toggle-exposure-form',
method: :post, remote: true do %>
<table>
<tr>
<td style="width:100%"></td>
<td><%= select_tag 'quantity_id', toggle_column_options %></td>
<td><%= select_tag 'quantity_id',
toggle_exposure_options(@routine.quantities, :measurement) %></td>
<td><%= submit_tag l(:button_add) %></td>
</tr>
</table>

View File

@ -17,7 +17,7 @@
<th style="width:<%= 100/total_width %>%" class="closable ellipsible">
<div style="float:right;position:relative;">
<%= link_to '',
toggle_column_measurement_routine_path(@routine, quantity_id: q.id),
toggle_exposure_measurement_routine_path(@routine, quantity_id: q.id),
{class: "icon icon-close", method: :post, remote: true} %>
</div>
<%= q.name %>

View File

@ -20,7 +20,7 @@ resources :projects, shallow: true do
resources :measurement_routines, only: [:show, :edit] do
member do
get 'readouts', to: 'measurements#readouts'
post 'toggle_column', to: 'measurements#toggle_column'
post 'toggle_exposure', to: 'measurements#toggle_exposure'
end
end
resources :measurements, only: [:index, :new, :create, :edit, :update, :destroy] do
@ -35,7 +35,7 @@ resources :projects, shallow: true do
post 'toggle', on: :member
collection do
get 'nutrients'
post 'toggle_column'
post 'toggle_exposure'
get 'filter'
get 'autocomplete'
post 'import'

View File

@ -27,8 +27,8 @@ Redmine::Plugin.register :body_tracking do
meals: [:new, :create, :edit, :update, :destroy, :edit_notes, :update_notes,
:toggle_eaten],
measurement_routines: [:edit],
measurements: [:new, :create, :edit, :update, :destroy, :retake, :toggle_column],
foods: [:new, :create, :edit, :update, :destroy, :toggle, :toggle_column,
measurements: [:new, :create, :edit, :update, :destroy, :retake, :toggle_exposure],
foods: [:new, :create, :edit, :update, :destroy, :toggle, :toggle_exposure,
:import],
sources: [:create, :destroy],
quantities: [:new, :create, :edit, :update, :destroy, :move, :new_child, :create_child],

View File

@ -13,7 +13,7 @@ module BodyTracking::ProjectPatch
has_many :units, dependent: :destroy
has_many :nutrient_exposures, as: :view, dependent: :destroy,
class_name: 'Exposure', extend: BodyTracking::TogglableColumns
class_name: 'Exposure', extend: BodyTracking::TogglableExposures
has_many :nutrient_quantities, -> { order "lft" }, through: :nutrient_exposures,
source: 'quantity'
end

View File

@ -1,7 +0,0 @@
module BodyTracking::TogglableColumns
# TODO: enforce 'domain' identity between quantites and receiving collection?
def toggle!(q)
column = find_by(quantity: q)
column ? destroy(column) : create(quantity: q)
end
end

View File

@ -0,0 +1,7 @@
module BodyTracking::TogglableExposures
# TODO: enforce 'domain' identity between quantites and receiving collection?
def toggle!(q)
exposure = find_by(quantity: q)
exposure ? destroy(exposure) : create(quantity: q)
end
end

View File

@ -1,9 +0,0 @@
require File.expand_path('../../test_helper', __FILE__)
class QuantityColumnTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
end
end