Skip to content

Commit

Permalink
Update admin category routing
Browse files Browse the repository at this point in the history
With the old routes now removed we can rename the new category routes to
match the old.
  • Loading branch information
gbp committed Nov 22, 2023
1 parent 578fd2b commit 2debeea
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions app/controllers/admin/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create
@category = Category.new(category_params)
if @category.save
flash[:notice] = 'Category was successfully created.'
redirect_to admin_new_categories_path
redirect_to admin_categories_path
else
@category.build_all_translations
render action: 'new'
Expand All @@ -34,7 +34,7 @@ def edit
def update
if @category.update(category_params)
flash[:notice] = 'Category was successfully updated.'
redirect_to admin_new_categories_path
redirect_to admin_categories_path
else
@category.build_all_translations
render action: 'edit'
Expand All @@ -44,7 +44,7 @@ def update
def destroy
@category.destroy
flash[:notice] = 'Category was successfully destroyed.'
redirect_to admin_new_categories_path
redirect_to admin_categories_path
end

def reorder
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/categories/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<div class="row">
<div class="span8">
<div id="category_form">
<%= form_for @category, url: admin_new_category_path(@category), html: { class: "form form-horizontal" } do |f| %>
<%= form_for @category, url: admin_category_path(@category), html: { class: "form form-horizontal" } do |f| %>
<%= render partial: 'form', locals: { f: f } %>

<div class="form-actions">
<%= f.submit 'Save', accesskey: 's', class: 'btn btn-success' %>
<%= link_to 'Public page', list_public_bodies_by_tag_path(@category.category_tag), class: 'btn' if @category.category_tag %>
<%= link_to 'List all', admin_new_categories_path, class: 'btn' %>
<%= link_to 'List all', admin_categories_path, class: 'btn' %>
</div>
<% end %>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/views/admin/categories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<span class="badge"><%= heading.children.size %></span>
<%= chevron_right %>
</a>
<strong><%= link_to(heading.title, edit_admin_new_category_path(heading), title: "view full details") %></strong>
<strong><%= link_to(heading.title, edit_admin_category_path(heading), title: "view full details") %></strong>
</span>
</div>

Expand All @@ -34,13 +34,13 @@
<i class="icon-move"></i>
<% end %>

<%= link_to(category.title, edit_admin_new_category_path(category), title: "view full details") %>
<%= link_to(category.title, edit_admin_category_path(category), title: "view full details") %>
</div>
<% end %>
</div>

<div class="form-actions save-panel">
<%= link_to "Save", '#', class: "btn btn-success disabled save-order", "data-heading-id" => heading.id, "data-list-id" => "#heading_#{heading.id}_category_list", 'data-endpoint' => reorder_admin_new_category_path(heading) %><p class="save-notice" data-unsaved-text="There are unsaved changes to the order of categories." data-success-text="Changes saved." data-error-text="There was an error saving your changes: ">Drag and drop to change the order of categories.</p>
<%= link_to "Save", '#', class: "btn btn-success disabled save-order", "data-heading-id" => heading.id, "data-list-id" => "#heading_#{heading.id}_category_list", 'data-endpoint' => reorder_admin_category_path(heading) %><p class="save-notice" data-unsaved-text="There are unsaved changes to the order of categories." data-success-text="Changes saved." data-error-text="There was an error saving your changes: ">Drag and drop to change the order of categories.</p>
</div>
</div>
</div>
Expand All @@ -49,6 +49,6 @@
</div>

<div class="form-actions save-panel">
<%= link_to "Save", '#', class: "btn btn-success disabled save-order", "data-list-id" => '#category_list', 'data-endpoint' => reorder_admin_new_category_path(Category.public_body_root) %><p class="save-notice" data-unsaved-text="There are unsaved changes to the order of category headings." data-success-text="Changes saved." data-error-text="There was an error saving your changes: ">Drag and drop to change the order of category headings.</p>
<%= link_to "Save", '#', class: "btn btn-success disabled save-order", "data-list-id" => '#category_list', 'data-endpoint' => reorder_admin_category_path(Category.public_body_root) %><p class="save-notice" data-unsaved-text="There are unsaved changes to the order of category headings." data-success-text="Changes saved." data-error-text="There was an error saving your changes: ">Drag and drop to change the order of category headings.</p>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/admin/categories/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<div class="row">
<div class="span8">
<div id="public_category_form">
<%= form_for @category, url: admin_new_categories_path, html: { class: "form form-horizontal" } do |f| %>
<%= form_for @category, url: admin_categories_path, html: { class: "form form-horizontal" } do |f| %>
<%= f.hidden_field :parent_id %>
<%= render partial: 'form', locals: { f: f } %>

<div class="form-actions">
<%= f.submit "Create", class: "btn btn-primary" %>
<%= link_to 'List all', admin_new_categories_path, class: "btn" %>
<%= link_to 'List all', admin_categories_path, class: "btn" %>
</div>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin_general/_admin_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Authorities<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><%= link_to 'Authorities', admin_bodies_path %></li>
<li><%= link_to 'New Categories', admin_new_categories_path %></li>
<li><%= link_to 'Categories', admin_categories_path %></li>
<li><%= link_to 'Tags', admin_tags_path(model_type: 'PublicBody') %></li>
</ul>
</li>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def matches?(request)

#### Admin::Categories controller
namespace :admin do
resources :categories, path: 'new_categories', as: 'new_categories' do
resources :categories do
post 'reorder', on: :member
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/admin/categories_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

it 'redirects to the categories index' do
post :create, params: { category: params }
expect(response).to redirect_to(admin_new_categories_path)
expect(response).to redirect_to(admin_categories_path)
end
end

Expand Down Expand Up @@ -270,7 +270,7 @@

it 'redirects to the category edit page' do
post :update, params: { id: category.id, category: params }
expect(response).to redirect_to(admin_new_categories_path)
expect(response).to redirect_to(admin_categories_path)
end

it 'saves edits to category_tag if the category has no associated bodies' do
Expand Down Expand Up @@ -373,7 +373,7 @@

it 'redirects to the edit page after a successful update' do
post :update, params: { id: category.id, category: { title: 'Title' } }
expect(response).to redirect_to(admin_new_categories_path)
expect(response).to redirect_to(admin_categories_path)
end
end

Expand Down Expand Up @@ -451,7 +451,7 @@

it 'redirects to the categories index' do
delete :destroy, params: { id: category.id }
expect(response).to redirect_to(admin_new_categories_path)
expect(response).to redirect_to(admin_categories_path)
end
end

Expand Down

0 comments on commit 2debeea

Please sign in to comment.