-
Notifications
You must be signed in to change notification settings - Fork 112
Refactor how section ordering is handled #1837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fa32212
Extract template customizations into own controller
Bodacious f40be47
Refactor Template model methods
Bodacious d33c03e
Fix view logic in draggable sections
Bodacious 7b1fe80
Add button for customising phase
Bodacious 19c3ea4
Fix rubocop violations in GuidanceService
Bodacious a1d727e
Rename GuidanceService to GuidancePresenter
Bodacious f5bee2f
Fix bug in phase preview order sections
Bodacious 66b0c6a
Refactor preview action/controller code
Bodacious a6f40bf
Fix Section ordering in various views
Bodacious a361c1f
Fix rubocop violations
Bodacious 3703bf7
Fix bug forcing Phases to be modifiable
Bodacious f469e4b
Fix broken tests
Bodacious 525c178
Update method to check if section is draggable
Bodacious 8d1fe15
Extract copy action into its own resource
Bodacious 3d1ea64
Extract customization transfers to own controller
Bodacious e45f733
Remove redundant routing condition
Bodacious d824bd1
Fix Rubocop violation issues
Bodacious a7ff152
Change condition for section draggable
Bodacious f57d201
Refactor instance variable in PlansController
Bodacious dd55261
Fix broken tests
Bodacious 1e44d0b
Add test support for 'de' locale
Bodacious 1edf690
Merge branch 'development' into refactor/section-reordering
Bodacious 61000f6
Fix merge issue in plans controller
Bodacious 0a3a200
Fix broken specs in plan#request_feedback
Bodacious File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
# This module holds helper controller methods for controllers that deal with Templates | ||
# | ||
module TemplateMethods | ||
|
||
private | ||
|
||
def template_type(template) | ||
template.customization_of.present? ? _("customisation") : _("template") | ||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class OrgAdmin::PhaseVersionsController < ApplicationController | ||
|
||
include Versionable | ||
|
||
def create | ||
@phase = Phase.find(params[:phase_id]) | ||
authorize @phase, :create? | ||
@new_phase = get_modifiable(@phase) | ||
flash[:notice] = if @new_phase == @phase | ||
"This template is already a draft" | ||
else | ||
"New version of Template created" | ||
end | ||
redirect_to org_admin_template_phase_url(@new_phase.template, @new_phase) | ||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/controllers/org_admin/template_copies_controller.rb
F438
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class OrgAdmin::TemplateCopiesController < ApplicationController | ||
|
||
include TemplateMethods | ||
|
||
after_action :verify_authorized | ||
|
||
# POST /org_admin/templates/:id/copy (AJAX) | ||
def create | ||
@template = Template.find(params[:template_id]) | ||
authorize @template, :copy? | ||
begin | ||
new_copy = @template.generate_copy!(current_user.org) | ||
flash[:notice] = "#{template_type(@template).capitalize} was successfully copied." | ||
redirect_to edit_org_admin_template_path(new_copy) | ||
rescue StandardError => e | ||
flash[:alert] = failed_create_error(@template, template_type(@template)) | ||
if request.referrer.present? | ||
redirect_to :back | ||
else | ||
redirect_to org_admin_templates_path | ||
end | ||
end | ||
end | ||
|
||
end |
34 changes: 34 additions & 0 deletions
34
app/controllers/org_admin/template_customization_transfers_controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
class OrgAdmin::TemplateCustomizationTransfersController < ApplicationController | ||
|
||
after_action :verify_authorized | ||
|
||
# POST /org_admin/templates/:id/transfer_customization | ||
# the funder template's id is passed through here | ||
def create | ||
@template = Template.includes(:org).find(params[:template_id]) | ||
authorize @template, :transfer_customization? | ||
if @template.upgrade_customization? | ||
begin | ||
new_customization = @template.upgrade_customization! | ||
redirect_to org_admin_template_path(new_customization) | ||
rescue StandardError => e | ||
flash[:alert] = _("Unable to transfer your customizations.") | ||
if request.referrer.present? | ||
redirect_to :back | ||
else | ||
redirect_to org_admin_templates_path | ||
end | ||
end | ||
else | ||
flash[:notice] = _("That template is no longer customizable.") | ||
if request.referrer.present? | ||
redirect_to :back | ||
else | ||
redirect_to org_admin_templates_path | ||
end | ||
end | ||
end | ||
|
||
end |
27 changes: 27 additions & 0 deletions
27
app/controllers/org_admin/template_customizations_controller.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class OrgAdmin::TemplateCustomizationsController < ApplicationController | ||
|
||
include Paginable | ||
include Versionable | ||
after_action :verify_authorized | ||
|
||
# POST /org_admin/templates/:id/customize | ||
def create | ||
@template = Template.find(params[:template_id]) | ||
authorize(@template, :customize?) | ||
if @template.customize?(current_user.org) | ||
begin | ||
@customisation = @template.customize!(current_user.org) | ||
redirect_to org_admin_template_path(@customisation) | ||
return | ||
rescue ArgumentError => e | ||
flash[:alert] = _("Unable to customize that template.") | ||
end | ||
else | ||
flash[:notice] = _("That template is not customizable.") | ||
end | ||
redirect_to :back | ||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I hadn't even heard of presenters in Rails before (learn something new every day) :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a "native" Rails concept. But a good general principle to call on when you'd like to clean up code in an MVC paradigm :)