Skip to content

Commit

Permalink
Merge pull request #740 from concord-consortium/fix-itsi-managed-iner…
Browse files Browse the repository at this point in the history
…active-save-error

handle saving managed and mw interactive updating from ITSI form
  • Loading branch information
scytacki authored Aug 23, 2021
2 parents 4b4ba7c + 76f25e7 commit f297023
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 41 deletions.
16 changes: 3 additions & 13 deletions app/controllers/interactive_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,11 @@ def update
end
end

def toggle_visibility
new_val = !@interactive.is_hidden
@interactive.update_attributes!(is_hidden: new_val)
if request.xhr?
render json: {is_hidden: new_val}
else
redirect_to :back
end
end

protected
def set_page
if params[:page_id]
@page = InteractivePage.find(params[:page_id], :include => :lightweight_activity)
@activity = @page.lightweight_activity
if @interactive
@page = @interactive.page
@activity = @interactive.activity
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/image_interactives/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- form_url = defined?(@page) ? page_image_interactive_path(@page, @interactive) : image_interactive_path(@interactive)
- form_url = image_interactive_path(@interactive)
= form_for @interactive, :url => form_url do |f|
= f.error_messages
=# f.hidden_field 'investigation_id', :value =>@activity.investigation.id # LightweightActivities currently don't belong_to Investigations
Expand Down
2 changes: 1 addition & 1 deletion app/views/managed_interactives/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- form_url = defined?(@page) ? page_managed_interactive_path(@page, @interactive) : managed_interactive_path(@interactive)
- form_url = managed_interactive_path(@interactive)
.managed-interactive-edit-id
Interactive ID:
%span.managed-interactve-id=@interactive.interactive_item_id
Expand Down
2 changes: 1 addition & 1 deletion app/views/mw_interactives/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- form_url = defined?(@page) ? page_mw_interactive_path(@page, @interactive) : mw_interactive_path(@interactive)
- form_url = mw_interactive_path(@interactive)
.mw-interactive-edit-id
Interactive ID:
%span.mw-interactve-id=@interactive.interactive_item_id
Expand Down
2 changes: 1 addition & 1 deletion app/views/video_interactives/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- form_url = defined?(@page) ? page_video_interactive_path(@page, @interactive) : video_interactive_path(@interactive)
- form_url = video_interactive_path(@interactive)
= nested_form_for @interactive, :url => form_url do |f|
= f.error_messages
= field_set_tag 'Poster URL' do
Expand Down
20 changes: 0 additions & 20 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,6 @@
end

resources :pages, :controller => 'interactive_pages', :constraints => { :id => /\d+/ }, :except => :create do
resources :mw_interactives, :controller => 'mw_interactives', :constraints => { :id => /\d+/ }, :except => :show do
member do
post 'toggle_visibility'
end
end
resources :managed_interactives, :controller => 'managed_interactives', :constraints => { :id => /\d+/ }, :except => :show do
member do
post 'toggle_visibility'
end
end
resources :image_interactives, :constraints => { :id => /\d+/ }, :except => :show do
member do
post 'toggle_visibility'
end
end
resources :video_interactives, :constraints => { :id => /\d+/ }, :except => :show do
member do
post 'toggle_visibility'
end
end
member do
get 'preview'
end
Expand Down
6 changes: 5 additions & 1 deletion spec/controllers/image_interactives_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
let (:page) { activity.pages.first }
let (:int) { FactoryGirl.create(:image_interactive, :url => 'http://mw.concord.org/modeler/_assets/img/cc-logo-1.png') }

before(:each) {
page.add_embeddable(int)
}

describe 'show' do
it 'is not routable' do
begin
Expand Down Expand Up @@ -38,7 +42,7 @@

expect(response.headers['Content-Type']).to match /text\/json/
value_hash = JSON.parse(response.body)
expect(value_hash['html']).to match %r[<form[^>]+action=\"/pages\/#{page.id}\/image_interactives\/#{int.id}\"[^<]+method=\"post]
expect(value_hash['html']).to match %r[<form[^>]+action=\"\/image_interactives\/#{int.id}\"[^<]+method=\"post]
end
end

Expand Down
6 changes: 5 additions & 1 deletion spec/controllers/managed_interactives_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
let (:page) { activity.pages.first }
let (:int) { FactoryGirl.create(:managed_interactive, :name => 'Test Managed Interactive', :url_fragment => '/interactive') }

before(:each) {
page.add_embeddable(int)
}

describe 'edit' do
it 'shows a form with values of the Managed Interactive filled in' do
get :edit, :id => int.id
Expand All @@ -22,7 +26,7 @@

expect(response.headers['Content-Type']).to match /text\/json/
value_hash = JSON.parse(response.body)
expect(value_hash['html']).to match %r[<form[^>]+action=\"/pages\/#{page.id}\/managed_interactives\/#{int.id}\"[^<]+method=\"post]
expect(value_hash['html']).to match %r[<form[^>]+action=\"\/managed_interactives\/#{int.id}\"[^<]+method=\"post]
end
end

Expand Down
6 changes: 5 additions & 1 deletion spec/controllers/mw_interactives_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
let (:page) { activity.pages.first }
let (:int) { FactoryGirl.create(:mw_interactive, :name => 'Test Interactive') }

before(:each) {
page.add_embeddable(int)
}

describe 'edit' do
it 'shows a form which renders the React-based MW Interactive editor' do
get :edit, :id => int.id
Expand All @@ -22,7 +26,7 @@

expect(response.headers['Content-Type']).to match /text\/json/
value_hash = JSON.parse(response.body)
expect(value_hash['html']).to match %r[<form[^>]+action=\"/pages\/#{page.id}\/mw_interactives\/#{int.id}\"[^<]+method=\"post]
expect(value_hash['html']).to match %r[<form[^>]+action=\"\/mw_interactives\/#{int.id}\"[^<]+method=\"post]
end
end

Expand Down
6 changes: 5 additions & 1 deletion spec/controllers/video_interactives_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
let (:page) { activity.pages.first }
let (:int) { FactoryGirl.create(:video_interactive, :poster_url => 'http://example.com/poster.png') }

before(:each) {
page.add_embeddable(int)
}

describe 'show' do
it 'is not routable' do
begin
Expand Down Expand Up @@ -37,7 +41,7 @@

expect(response.headers['Content-Type']).to match /text\/json/
value_hash = JSON.parse(response.body)
expect(value_hash['html']).to match %r[<form[^>]+action=\"/pages\/#{page.id}\/video_interactives\/#{int.id}\"[^<]+method=\"post]
expect(value_hash['html']).to match %r[<form[^>]+action=\"\/video_interactives\/#{int.id}\"[^<]+method=\"post]
end
end

Expand Down

0 comments on commit f297023

Please sign in to comment.