Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ class ApplicationController < ActionController::Base
allow_browser versions: :modern

include Pagy::Backend

private

def back_params
request.query_parameters.slice("q", "sort", "page")
end
helper_method :back_params
end
6 changes: 3 additions & 3 deletions app/controllers/publications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def create
@publication = current_user.publications.build(publication_params)
if @publication.save(context: :ui)
NotificationMailer.new_publication_notification(@publication).deliver_now
redirect_to @publication, notice: "Publication was successfully created."
redirect_to publication_path(@publication, back_params), notice: "Publication was successfully created."
else
render :new, status: :unprocessable_entity
end
Expand All @@ -56,15 +56,15 @@ def update
NotificationMailer.publication_update_notification(@publication, current_user, payload).deliver_now
@publication._notification_changes = nil
end
redirect_to @publication, notice: "Publication was successfully updated."
redirect_to publication_path(@publication, back_params), notice: "Publication was successfully updated."
else
render :edit, status: :unprocessable_entity
end
end

def destroy
@publication.destroy
redirect_to publications_path, notice: "Publication was successfully deleted."
redirect_to publications_path(back_params), notice: "Publication was successfully deleted."
end

private
Expand Down
6 changes: 5 additions & 1 deletion app/views/publications/_search_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@
<% end %>
</div>

<div class="text-end mt-4">
<div class="text-end mt-4 d-flex justify-content-end gap-2">
<%= link_to "Reset filters",
publications_path(back_params.except("q", "page")),
class: "btn btn-secondary" %>

<%= f.submit "Search", class: "btn btn-primary" %>
</div>
<% end %>
Expand Down
7 changes: 5 additions & 2 deletions app/views/publications/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<div class="mb-3">
<%= link_to publication_path(@publication), class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %>
<%= link_to publication_path(@publication, back_params),
class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %>
<i class="bi bi-arrow-left"></i> Back
<% end %>
</div>

<%= simple_form_for @publication, html: { class: 'needs-validation' } do |form| %>
<%= simple_form_for @publication,
url: publication_path(@publication, back_params),
html: { class: 'needs-validation' } do |form| %>

<div class="row align-items-center">
<div class="col-md-10">
Expand Down
8 changes: 4 additions & 4 deletions app/views/publications/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
data: { controller: "sort", action: "change->sort#submit" } %>
</div>
<div class="col-md-9 d-flex justify-content-end gap-3" data-controller="toggle-search">
<%= search_form_for @q, url: publications_path, method: :get do |f| %>
<%= search_form_for @q, url: publications_path(back_params.except("q", "page")), method: :get do |f| %>
<%= f.search_field :title_cont, class: "form-control search-field", placeholder: "Search publications by title" %>
<% end %>
<button class="btn btn-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#searchForm" aria-expanded="false" aria-controls="searchForm">
Expand All @@ -49,11 +49,11 @@

<div class="d-flex gap-2">
<% if user_signed_in? && current_user.moderator? %>
<%= link_to 'Modify research groups', research_groups_path, class: "btn btn-primary" %>
<%= link_to 'Modify research groups', research_groups_path(back_params), class: "btn btn-primary" %>
<% end %>

<% if user_signed_in? %>
<%= link_to 'New Publication', new_publication_path, class: "btn btn-primary" %>
<%= link_to 'New Publication', new_publication_path(back_params), class: "btn btn-primary" %>
<% end %>
</div>
</div>
Expand All @@ -64,7 +64,7 @@
<div class="card mb-3 shadow-sm border border-light-subtle">
<div class="card-body">
<h5 class="card-title text-primary-emphasis mb-2">
<%= link_to publication.title, publication_path(publication), class: "text-decoration-none" %>
<%= link_to publication.title, publication_path(publication, back_params), class: "text-decoration-none" %>
</h5>

<div class="d-flex flex-wrap gap-2 mb-2">
Expand Down
7 changes: 5 additions & 2 deletions app/views/publications/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<div class="mb-3">
<%= link_to publications_path, class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %>
<%= link_to publications_path(back_params),
class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %>
<i class="bi bi-arrow-left"></i> Back
<% end %>
</div>

<%= simple_form_for @publication, html: { class: 'needs-validation' } do |form| %>
<%= simple_form_for @publication,
url: publications_path(back_params),
html: { class: 'needs-validation' } do |form| %>

<div class="row align-items-center">
<div class="col-md-10">
Expand Down
7 changes: 4 additions & 3 deletions app/views/publications/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="mb-3">
<%= link_to publications_path, class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %>
<%= link_to publications_path(back_params),
class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %>
<i class="bi bi-arrow-left"></i> Back
<% end %>
</div>
Expand All @@ -13,9 +14,9 @@

<div class="col-md-2">
<div class="d-grid gap-2">
<%= link_to "Edit publication", edit_publication_path(@publication), class: 'btn btn-primary' %>
<%= link_to "Edit publication", edit_publication_path(@publication, back_params), class: 'btn btn-primary' %>

<%= button_to "Delete", publication_path(@publication),
<%= button_to "Delete", publication_path(@publication, back_params),
method: :delete,
data: { confirm: "Are you sure?" },
form: { class: "d-grid" },
Expand Down
3 changes: 2 additions & 1 deletion app/views/research_groups/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="mb-3">
<%= link_to publications_path, class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %>
<%= link_to publications_path(back_params),
class: "text-decoration-none text-muted small d-inline-flex align-items-center gap-1 fs-6" do %>
<i class="bi bi-arrow-left"></i> Back
<% end %>
</div>
Expand Down