1
0

Fix target subtreshold listing

Route targets under goal
This commit is contained in:
cryptogopher 2021-03-06 13:00:50 +01:00
parent 09e27eb754
commit 406eabaccc
9 changed files with 27 additions and 15 deletions

View File

@ -8,6 +8,10 @@ module Concerns::Finders
render_404 render_404
end end
def find_goal_by_goal_id
find_goal(params[:goal_id])
end
def find_binding_goal_by_project_id def find_binding_goal_by_project_id
@project = Project.find(params[:project_id]) @project = Project.find(params[:project_id])
@goal = @project.goals.binding @goal = @project.goals.binding

View File

@ -6,12 +6,13 @@ class TargetsController < ApplicationController
include Concerns::Finders include Concerns::Finders
before_action :find_binding_goal_by_project_id, only: [:new, :edit] 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] before_action :find_quantity_by_quantity_id, only: [:toggle_exposure]
#, if: ->{ params[:project_id].present? } #, if: ->{ params[:project_id].present? }
#before_action :find_goal, only: [:index, :new], #before_action :find_goal, only: [:index, :new],
# unless: -> { @goal } # 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 :authorize
#before_action :set_view_params #before_action :set_view_params
@ -21,7 +22,6 @@ class TargetsController < ApplicationController
def new def new
target = @goal.targets.new target = @goal.targets.new
target.thresholds.new(quantity: Quantity.target.roots.last)
@targets = [target] @targets = [target]
@effective_from = target.effective_from @effective_from = target.effective_from
end end
@ -69,13 +69,14 @@ class TargetsController < ApplicationController
end end
def subthresholds def subthresholds
@target = @project.goals.binding.targets.new @target = @goal.targets.new
quantity = @project.quantities.target.find_by(id: params['quantity_id']) quantity = @project.quantities.target.find_by(id: params[:quantity_id])
if quantity.nil? if quantity.nil?
@last_quantity = @project.quantities.target.find(params[:parent_id]) @last_quantity = @project.quantities.target.find(params[:parent_id])
@target.thresholds.clear
else else
@last_quantity = quantity @last_quantity = quantity
@target.thresholds.new(quantity: quantity) @target.thresholds.first.quantity = quantity
end end
end end

View File

@ -2,7 +2,7 @@
<table id="goals" class="list odd-even"> <table id="goals" class="list odd-even">
<thead> <thead>
<tr> <tr>
<th><%= l(:field_name) %></th> <th style="width:20%"><%= l(:field_name) %></th>
<th><%= l(:field_description) %></th> <th><%= l(:field_description) %></th>
<th style="width:5%"><%= l(:field_action) %></th> <th style="width:5%"><%= l(:field_action) %></th>
</tr> </tr>
@ -12,7 +12,7 @@
<tr id="goal-<%= g.id %>" class="primary goal"> <tr id="goal-<%= g.id %>" class="primary goal">
<td class="name unwrappable"> <td class="name unwrappable">
<div style="float:left;"> <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>
<div style="float:right;"> <div style="float:right;">
<%# TODO: display # of active targets/targeted quantities %> <%# TODO: display # of active targets/targeted quantities %>

View File

@ -1,6 +1,6 @@
<% if goal_f.object.is_binding? %> <% if goal_f.object.is_binding? %>
<p> <p>
<%= date_field :effective_from, value: @effective_from %> <%= goal_f.date_field :effective_from, value: @effective_from, required: true %>
</p> </p>
<% end %> <% end %>

View File

@ -1,7 +1,7 @@
<h2><%= t ".heading_new_target" %></h2> <h2><%= t ".heading_new_target" %></h2>
<%# url: project_targets_path(@project, @view_params), %> <%# 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| %> html: {id: 'new-target-form', name: 'new-target-form'} do |goal_f| %>
<%= error_messages_for *@targets %> <%= error_messages_for *@targets %>

View File

@ -5,10 +5,10 @@
<%= threshold_f.collection_select :quantity_id, <%= threshold_f.collection_select :quantity_id,
@project.quantities.target.children_of(parent_id), @project.quantities.target.children_of(parent_id),
:id, :name, :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', {autocomplete: 'off',
onchange: "$.ajax({ 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(), data: 'quantity_id=' + $(this).val(),
dataType: 'html', dataType: 'html',
success: function(data) { success: function(data) {

View File

@ -6,6 +6,9 @@
</div> </div>
<%= title [t("goals.index.heading"), project_goals_path(@project)], @goal.name %> <%= 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'> <div id='targets'>
<%= render partial: 'targets/index' %> <%= render partial: 'targets/index' %>
</div> </div>

View File

@ -104,7 +104,7 @@ en:
link_new_goal: 'New goal' link_new_goal: 'New goal'
targets: targets:
contextual: contextual:
link_new_target: 'New target' link_new_target: 'New target(s)'
form: form:
choose_quantity: 'Choose quantity' choose_quantity: 'Choose quantity'
button_new_target: 'Add target' button_new_target: 'Add target'

View File

@ -9,14 +9,18 @@ resources :projects, shallow: true do
end end
resources :goals do resources :goals do
member do member do
get 'targets', controller: :targets, action: :index, as: :targets #get 'targets', controller: :targets, action: :index, as: :targets
post 'toggle_exposure', controller: :targets post 'toggle_exposure', controller: :targets
end end
resources :targets, only: [:index] do
collection do
get 'subthresholds/(:parent_id)', action: :subthresholds, as: :subthresholds
end
end
end end
resources :targets, except: [:show, :edit] do resources :targets, except: [:show, :edit] do
collection do collection do
get 'edit/:date', action: :edit, as: :edit get 'edit/:date', action: :edit, as: :edit
get 'subthresholds/(:parent_id)', action: :subthresholds, as: :subthresholds
post 'reapply/:date', action: :reapply, as: :reapply post 'reapply/:date', action: :reapply, as: :reapply
end end
end end