Fix target subtreshold listing
Route targets under goal
This commit is contained in:
parent
09e27eb754
commit
406eabaccc
@ -8,6 +8,10 @@ module Concerns::Finders
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_goal_by_goal_id
|
||||
find_goal(params[:goal_id])
|
||||
end
|
||||
|
||||
def find_binding_goal_by_project_id
|
||||
@project = Project.find(params[:project_id])
|
||||
@goal = @project.goals.binding
|
||||
|
@ -6,12 +6,13 @@ class TargetsController < ApplicationController
|
||||
include Concerns::Finders
|
||||
|
||||
before_action :find_binding_goal_by_project_id, only: [:new, :edit]
|
||||
before_action :find_project_by_project_id, only: [:create, :subthresholds]
|
||||
before_action :find_project_by_project_id, only: [:create]
|
||||
before_action :find_quantity_by_quantity_id, only: [:toggle_exposure]
|
||||
#, if: ->{ params[:project_id].present? }
|
||||
#before_action :find_goal, only: [:index, :new],
|
||||
# unless: -> { @goal }
|
||||
before_action :find_goal, only: [:index, :toggle_exposure]
|
||||
before_action :find_goal_by_goal_id, only: [:index, :subthresholds]
|
||||
before_action :find_goal, only: [:toggle_exposure]
|
||||
before_action :authorize
|
||||
#before_action :set_view_params
|
||||
|
||||
@ -21,7 +22,6 @@ class TargetsController < ApplicationController
|
||||
|
||||
def new
|
||||
target = @goal.targets.new
|
||||
target.thresholds.new(quantity: Quantity.target.roots.last)
|
||||
@targets = [target]
|
||||
@effective_from = target.effective_from
|
||||
end
|
||||
@ -69,13 +69,14 @@ class TargetsController < ApplicationController
|
||||
end
|
||||
|
||||
def subthresholds
|
||||
@target = @project.goals.binding.targets.new
|
||||
quantity = @project.quantities.target.find_by(id: params['quantity_id'])
|
||||
@target = @goal.targets.new
|
||||
quantity = @project.quantities.target.find_by(id: params[:quantity_id])
|
||||
if quantity.nil?
|
||||
@last_quantity = @project.quantities.target.find(params[:parent_id])
|
||||
@target.thresholds.clear
|
||||
else
|
||||
@last_quantity = quantity
|
||||
@target.thresholds.new(quantity: quantity)
|
||||
@target.thresholds.first.quantity = quantity
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
<table id="goals" class="list odd-even">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= l(:field_name) %></th>
|
||||
<th style="width:20%"><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_description) %></th>
|
||||
<th style="width:5%"><%= l(:field_action) %></th>
|
||||
</tr>
|
||||
@ -12,7 +12,7 @@
|
||||
<tr id="goal-<%= g.id %>" class="primary goal">
|
||||
<td class="name unwrappable">
|
||||
<div style="float:left;">
|
||||
<%= checked_image g.is_binding %><%= link_to g.name, targets_goal_path(g) %>
|
||||
<%= checked_image g.is_binding %><%= link_to g.name, goal_targets_path(g) %>
|
||||
</div>
|
||||
<div style="float:right;">
|
||||
<%# TODO: display # of active targets/targeted quantities %>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<% if goal_f.object.is_binding? %>
|
||||
<p>
|
||||
<%= date_field :effective_from, value: @effective_from %>
|
||||
<%= goal_f.date_field :effective_from, value: @effective_from, required: true %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<h2><%= t ".heading_new_target" %></h2>
|
||||
|
||||
<%# url: project_targets_path(@project, @view_params), %>
|
||||
<%= labelled_form_for [@project, @goal], remote: true,
|
||||
<%= labelled_form_for @goal, remote: true,
|
||||
html: {id: 'new-target-form', name: 'new-target-form'} do |goal_f| %>
|
||||
|
||||
<%= error_messages_for *@targets %>
|
||||
|
@ -5,10 +5,10 @@
|
||||
<%= threshold_f.collection_select :quantity_id,
|
||||
@project.quantities.target.children_of(parent_id),
|
||||
:id, :name,
|
||||
{prompt: parent_id.nil? ? false : '.', required: true, no_label: true},
|
||||
{include_blank: parent_id.nil? ? false : '.', required: true, no_label: true},
|
||||
{autocomplete: 'off',
|
||||
onchange: "$.ajax({
|
||||
url: '#{subthresholds_project_targets_path(parent_id: parent_id)}',
|
||||
url: '#{subthresholds_goal_targets_path(@goal, parent_id: parent_id)}',
|
||||
data: 'quantity_id=' + $(this).val(),
|
||||
dataType: 'html',
|
||||
success: function(data) {
|
||||
|
@ -6,6 +6,9 @@
|
||||
</div>
|
||||
|
||||
<%= title [t("goals.index.heading"), project_goals_path(@project)], @goal.name %>
|
||||
<% if @goal.description? %>
|
||||
<p class="subtitle" style='white-space: pre-wrap;'><%= @goal.description %></p>
|
||||
<% end %>
|
||||
<div id='targets'>
|
||||
<%= render partial: 'targets/index' %>
|
||||
</div>
|
||||
|
@ -104,7 +104,7 @@ en:
|
||||
link_new_goal: 'New goal'
|
||||
targets:
|
||||
contextual:
|
||||
link_new_target: 'New target'
|
||||
link_new_target: 'New target(s)'
|
||||
form:
|
||||
choose_quantity: 'Choose quantity'
|
||||
button_new_target: 'Add target'
|
||||
|
@ -9,14 +9,18 @@ resources :projects, shallow: true do
|
||||
end
|
||||
resources :goals do
|
||||
member do
|
||||
get 'targets', controller: :targets, action: :index, as: :targets
|
||||
#get 'targets', controller: :targets, action: :index, as: :targets
|
||||
post 'toggle_exposure', controller: :targets
|
||||
end
|
||||
resources :targets, only: [:index] do
|
||||
collection do
|
||||
get 'subthresholds/(:parent_id)', action: :subthresholds, as: :subthresholds
|
||||
end
|
||||
end
|
||||
end
|
||||
resources :targets, except: [:show, :edit] do
|
||||
collection do
|
||||
get 'edit/:date', action: :edit, as: :edit
|
||||
get 'subthresholds/(:parent_id)', action: :subthresholds, as: :subthresholds
|
||||
post 'reapply/:date', action: :reapply, as: :reapply
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user