From 6ba8ad53761cc69a8b7f70b467b294d03e49aeba Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Tue, 25 Aug 2020 02:55:21 +0200 Subject: [PATCH] Preliminary Target :edit support --- app/controllers/targets_controller.rb | 5 +++-- app/helpers/targets_helper.rb | 2 +- config/routes.rb | 3 ++- test/system/targets_test.rb | 6 +++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/targets_controller.rb b/app/controllers/targets_controller.rb index bad1e22..591fd9c 100644 --- a/app/controllers/targets_controller.rb +++ b/app/controllers/targets_controller.rb @@ -5,7 +5,7 @@ class TargetsController < ApplicationController include Concerns::Finders - before_action :find_goal_by_project_id, only: [:index, :new] + before_action :find_goal_by_project_id, only: [:index, :new, :edit] #, if: ->{ params[:project_id].present? } #before_action :find_goal, only: [:index, :new], # unless: -> { @goal } @@ -51,6 +51,7 @@ class TargetsController < ApplicationController end def edit + @targets = @goal.targets.where(effective_from: params[:effective_from]) end def update @@ -108,6 +109,6 @@ class TargetsController < ApplicationController else {view: :by_scope, scope: :all} end - @view_params[:goal_id] = @goal.id if @goal + #@view_params[:goal_id] = @goal.id if @goal end end diff --git a/app/helpers/targets_helper.rb b/app/helpers/targets_helper.rb index 9940b2a..41669a1 100644 --- a/app/helpers/targets_helper.rb +++ b/app/helpers/targets_helper.rb @@ -6,7 +6,7 @@ module TargetsHelper def action_links(d) link_to(l(:button_reapply), reapply_project_targets_path(@project, d, @view_params), {remote: true, class: "icon icon-reload"}) + - link_to(l(:button_edit), edit_target_path(@project, d, @view_params), + link_to(l(:button_edit), edit_project_targets_path(@project, d, @view_params), {remote: true, class: "icon icon-edit"}) + delete_link(target_path(d), {remote: true, data: {}}) end diff --git a/config/routes.rb b/config/routes.rb index fea5548..9eafb4b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,8 +12,9 @@ resources :projects, shallow: true do post 'toggle_exposure', to: 'goals#toggle_exposure' end end - resources :targets, except: [:show] do + resources :targets, except: [:show, :edit] do collection do + get 'edit/:date', to: 'targets#edit', as: :edit post 'reapply/:date', to: 'targets#reapply', as: :reapply end end diff --git a/test/system/targets_test.rb b/test/system/targets_test.rb index ac7b1b0..a3bd56f 100644 --- a/test/system/targets_test.rb +++ b/test/system/targets_test.rb @@ -75,6 +75,10 @@ class TargetsTest < BodyTrackingSystemTestCase assert_equal @project1.goals.binding, Target.last.goal end - def test_edit + # TODO: test_create_failure(s) + # * restoring user input + # * removing empty targets + + def test_update end end