-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9496 from alphagov/content-modelling/refactor-con…
…trollers Refactor create/edit controllers
- Loading branch information
Showing
35 changed files
with
744 additions
and
1,134 deletions.
There are no files selected for viewing
This file contains 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 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
89 changes: 89 additions & 0 deletions
89
..._store/app/controllers/content_object_store/content_block/editions/workflow_controller.rb
This file contains 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,89 @@ | ||
class ContentObjectStore::ContentBlock::Editions::WorkflowController < ContentObjectStore::BaseController | ||
NEW_BLOCK_STEPS = { | ||
review: "review", | ||
}.freeze | ||
|
||
UPDATE_BLOCK_STEPS = { | ||
review_links: "review_links", | ||
schedule_publishing: "schedule_publishing", | ||
}.freeze | ||
|
||
def show | ||
step = params[:step] | ||
@content_block_edition = ContentObjectStore::ContentBlock::Edition.find(params[:id]) | ||
@schema = ContentObjectStore::ContentBlock::Schema.find_by_block_type(@content_block_edition.document.block_type) | ||
|
||
case step | ||
when UPDATE_BLOCK_STEPS[:review_links] | ||
review_links | ||
when UPDATE_BLOCK_STEPS[:schedule_publishing] | ||
schedule_publishing | ||
when NEW_BLOCK_STEPS[:review] | ||
review | ||
end | ||
end | ||
|
||
def update | ||
step = params[:step] | ||
@content_block_edition = ContentObjectStore::ContentBlock::Edition.find(params[:id]) | ||
@schema = ContentObjectStore::ContentBlock::Schema.find_by_block_type(@content_block_edition.document.block_type) | ||
|
||
case step | ||
when UPDATE_BLOCK_STEPS[:review_links] | ||
redirect_to content_object_store.content_object_store_content_block_workflow_path(id: @content_block_edition.id, step: :schedule_publishing) | ||
when UPDATE_BLOCK_STEPS[:schedule_publishing] | ||
schedule_or_publish | ||
when NEW_BLOCK_STEPS[:review] | ||
publish | ||
end | ||
end | ||
|
||
private | ||
|
||
def review | ||
@content_block_edition = ContentObjectStore::ContentBlock::Edition.find(params[:id]) | ||
|
||
render :review | ||
end | ||
|
||
def review_links | ||
@content_block_document = @content_block_edition.document | ||
@host_content_items = ContentObjectStore::GetHostContentItems.by_embedded_document( | ||
content_block_document: @content_block_document, | ||
) | ||
|
||
render :review_links | ||
end | ||
|
||
def schedule_publishing | ||
@content_block_document = @content_block_edition.document | ||
|
||
render :schedule_publishing | ||
end | ||
|
||
def schedule_or_publish | ||
@content_block_edition = ContentObjectStore::ContentBlock::Edition.find(params[:id]) | ||
@schema = ContentObjectStore::ContentBlock::Schema.find_by_block_type(@content_block_edition.document.block_type) | ||
|
||
if params[:schedule_publishing].blank? | ||
@content_block_edition.errors.add(:schedule_publishing, "cannot be blank") | ||
raise ActiveRecord::RecordInvalid, @content_block_edition | ||
elsif params[:schedule_publishing] == "schedule" | ||
ContentObjectStore::ScheduleEditionService.new(@schema).call(@content_block_edition, scheduled_publication_params) | ||
message = "#{@content_block_edition.block_type.humanize} scheduled successfully" | ||
else | ||
publish and return | ||
end | ||
|
||
redirect_to content_object_store.content_object_store_content_block_document_path(@content_block_edition.document), | ||
flash: { notice: message } | ||
rescue ActiveRecord::RecordInvalid | ||
render "content_object_store/content_block/editions/workflow/schedule_publishing" | ||
end | ||
|
||
def publish | ||
new_edition = ContentObjectStore::PublishEditionService.new(@schema).call(@content_block_edition) | ||
redirect_to content_object_store.content_object_store_content_block_document_path(new_edition.document), | ||
flash: { notice: "#{new_edition.block_type.humanize} created successfully" } | ||
end | ||
end |
92 changes: 14 additions & 78 deletions
92
...nt_object_store/app/controllers/content_object_store/content_block/editions_controller.rb
This file contains 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
40 changes: 0 additions & 40 deletions
40
...nt_object_store/app/controllers/content_object_store/content_block/workflow_controller.rb
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
...ngines/content_object_store/app/forms/content_object_store/content_block/document_form.rb
This file contains 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,25 @@ | ||
class ContentObjectStore::ContentBlock::DocumentForm | ||
include ContentObjectStore::Engine.routes.url_helpers | ||
|
||
attr_reader :schema, :content_block_edition | ||
|
||
def initialize(schema:, content_block_edition: ContentObjectStore::ContentBlock::Edition.new) | ||
@schema = schema | ||
@content_block_edition = content_block_edition | ||
end | ||
|
||
def url | ||
content_object_store_content_block_documents_path(block_type: schema.block_type) | ||
end | ||
|
||
def attributes | ||
schema.fields.each_with_object({}) do |field, hash| | ||
hash[field] = nil | ||
hash | ||
end | ||
end | ||
|
||
def back_path | ||
content_object_store_content_block_documents_path | ||
end | ||
end |
This file contains 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
5 changes: 0 additions & 5 deletions
5
...nes/content_object_store/app/helpers/content_object_store/content_block/edition_helper.rb
This file was deleted.
Oops, something went wrong.
This file contains 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.