Skip to content

Commit

Permalink
Merge pull request #1274 from openjournals/dashboard-query-scoped
Browse files Browse the repository at this point in the history
Dashboard: list query scoped submissions
  • Loading branch information
xuanxu committed Sep 22, 2023
2 parents c3d115e + cd56d4f commit 6d77a89
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ TODO
}

.tabnav-tab {
padding: 1em 2em;
padding: 1em 1.6em;
background: #fff;
color: #2E294E;
transition: background-color .3s ease-out;
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
}
}

.grey-emoji {
color: transparent;
text-shadow: 0 0 0 #aaa;
}

table.dashboard-table, table.comments-table, table.toc-table{
margin-top: 1em;
width: 100%;
Expand Down
36 changes: 31 additions & 5 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class HomeController < ApplicationController
before_action :require_user, only: %w(profile update_profile)
before_action :require_editor, only: %w(dashboard reviews incoming stats all in_progress)
before_action :set_track, only: %w(all incoming in_progress)
before_action :set_track, only: %w(all incoming in_progress query_scoped)
# layout "dashboard", only: %w(dashboard reviews incoming stats all in_progress)

def index
Expand Down Expand Up @@ -78,9 +78,9 @@ def incoming
@pagy, @papers = pagy(incoming_scope.order(created_at: @order))
end

load_pending_invitations_for_papers(@papers)

@editor = current_user.editor
set_votes_by_paper_from_editor(@editor, @papers)
load_pending_invitations_for_papers(@papers)

render template: "home/reviews"
end
Expand All @@ -98,6 +98,26 @@ def in_progress
@pagy, @papers = pagy(in_progress_scope.order(created_at: @order))
end

set_votes_by_paper_from_editor(@editor, @papers)
load_pending_invitations_for_papers(@papers)

render template: "home/reviews"
end

def query_scoped
in_progress_query_scoped = Paper.unscoped.in_progress.query_scoped
in_progress_query_scoped = in_progress_query_scoped.by_track(@track.id) if @track.present?

@editor = current_user.editor
@order = params[:order].to_s.end_with?("-asc") ? "asc" : "desc"

if params[:order].to_s.include?("active-")
@pagy, @papers = pagy(in_progress_query_scoped.order(last_activity: @order))
else
@pagy, @papers = pagy(in_progress_query_scoped.order(created_at: @order))
end

set_votes_by_paper_from_editor(@editor, @papers)
load_pending_invitations_for_papers(@papers)

render template: "home/reviews"
Expand All @@ -116,6 +136,7 @@ def all
@pagy, @papers = pagy(all_scope.order(created_at: @order))
end

set_votes_by_paper_from_editor(@editor, @papers)
load_pending_invitations_for_papers(@papers)

render template: "home/reviews"
Expand Down Expand Up @@ -153,6 +174,11 @@ def load_pending_invitations_for_papers(papers)
end

def set_track
@track = Track.find(params[:track_id]) if params[:track_id].present?
end
@track = Track.find(params[:track_id]) if params[:track_id].present?
end

def set_votes_by_paper_from_editor(editor, papers)
in_scope_papers = papers.select {|p| p.labels.keys.include?("query-scope")}
@votes_by_paper_from_editor = in_scope_papers.any? ? Vote.where(editor: editor).where(paper: in_scope_papers).index_by(&:paper_id) : {}
end
end
13 changes: 10 additions & 3 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ def current_class?(test_path)
'tabnav-tab'
end

def vote_summary(paper)
def vote_summary(paper, votes_by_paper)
if paper.labels.keys.include?("query-scope")
capture do
concat(content_tag(:small, "👍(#{paper.votes.in_scope.count}) / 👎 (#{paper.votes.out_of_scope.count})"))
summary = ""
vote = votes_by_paper[paper.id]
summary = if vote.nil? || vote.comment?
content_tag(:small, "👍(#{paper.in_scope_votes.count}) / 👎 (#{paper.votes.out_of_scope.count})")
elsif vote.in_scope?
content_tag(:small, "👍(#{paper.in_scope_votes.count}) / <span class='grey-emoji'>👎</span> (#{paper.out_of_scope_votes.count})".html_safe)
elsif vote.out_of_scope?
content_tag(:small, "<span class='grey-emoji'>👍</span>(#{paper.in_scope_votes.count}) / 👎 (#{paper.out_of_scope_votes.count})".html_safe)
end
summary.html_safe
else
'OK'
end
Expand Down
1 change: 1 addition & 0 deletions app/models/paper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class Paper < ApplicationRecord
scope :search_import, -> { where(state: VISIBLE_STATES) }
scope :not_archived, -> { where('archived = ?', false) }
scope :by_track, -> (track_id) { where('track_id = ?', track_id) }
scope :query_scoped, -> { where("labels->>'query-scope' IS NOT NULL") }

before_create :set_sha, :set_last_activity
after_create :notify_editors, :notify_author
Expand Down
5 changes: 4 additions & 1 deletion app/views/home/_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
In progress papers
<div class="count-badge"><%= raw Paper.unscoped.in_progress.count %></div>
<% end %>
<%= link_to dashboard_query_scoped_path(track_id: @track), class: current_class?(dashboard_query_scoped_path) do %>
👍👎
<% end %>
<%= link_to dashboard_all_path(track_id: @track), class: current_class?(dashboard_all_path) do %>
All papers
<div class="count-badge"><%= raw Paper.unscoped.all.count %></div>
Expand All @@ -21,7 +24,7 @@
<% end %>
</div>

<% if [dashboard_incoming_path, dashboard_in_progress_path, dashboard_all_path].include?(request.path) && JournalFeatures.tracks? %>
<% if [dashboard_incoming_path, dashboard_in_progress_path, dashboard_query_scoped_path, dashboard_all_path].include?(request.path) && JournalFeatures.tracks? %>
<div class="float-right">
<%= select_tag :track_id, options_from_collection_for_select(Track.all, "id", "name", params[:track_id].presence), include_blank: "All tracks", class: "form-control left", style: "font-size:81%", onchange: "top.location.href='?track_id=' + this.options[this.selectedIndex].value;" %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/reviews.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<td class="state"><%= paper.state.titleize %></td>
<td><%= link_to paper.title, paper_url(paper), title: paper.title, class: "d-inline-block text-truncate", style: "max-width: 450px;" %><div class="time">Submitted <%= time_ago_in_words(paper.created_at) %> ago <%= pretty_labels_for(paper) %></div></td>
<% unless params[:editor]%>
<td class="text-center"><%= vote_summary(paper).html_safe %></td>
<td class="text-center"><%= vote_summary(paper, @votes_by_paper_from_editor) %></td>
<td class="text-center"><%= open_invites_for_paper(paper) %></td>
<% end %>
<td class="text-center"><%= review_issue_links(paper) %></td>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
get '/dashboard/all', to: "home#all", as: "dashboard_all"
get '/dashboard/incoming', to: "home#incoming", as: "dashboard_incoming"
get '/dashboard/in_progress', to: "home#in_progress", as: "dashboard_in_progress"
get '/dashboard/query_scoped', to: "home#query_scoped", as: "dashboard_query_scoped"
get '/dashboard', to: "home#dashboard"

get '/dashboard/*editor', to: "home#reviews"
Expand Down
11 changes: 11 additions & 0 deletions spec/models/paper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@
expect(track_A_papers.include?(paper_A1)).to be true
expect(track_A_papers.include?(paper_A2)).to be true
end

it "should find query scoped papers" do
paper_1, paper_2, paper_3, paper_4, paper_5 = create_list(:paper, 5)
paper_2.update labels: {"query-scope" => "FF0000"}
paper_4.update labels: {"query-scope" => "CC00CC"}

query_scoped_papers = Paper.query_scoped
expect(query_scoped_papers.size).to eq(2)
expect(query_scoped_papers.include?(paper_2)).to be true
expect(query_scoped_papers.include?(paper_4)).to be true
end
end

# GitHub stuff
Expand Down
29 changes: 26 additions & 3 deletions spec/system/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
before do
editor = create(:editor, login: "editor1")
@track = create(:track, name: "TestingTrack")
create(:paper, state: "submitted", title: "Paper Submitted", editor: nil)
query_scoped_paper = create(:paper, state: "submitted", title: "Paper Submitted", labels:{"query-scope" => "C0C"}, editor: nil)
create(:in_scope_vote, editor: editor, paper: query_scoped_paper)
create(:paper, state: "under_review", title: "Paper Under Review", editor: editor)
create(:paper, state: "review_pending", title: "Paper Review Pending No Editor", editor: nil, track: @track)
create(:paper, state: "review_pending", title: "Paper Review Pending No Editor", labels:{"query-scope" => "C0C"}, editor: nil, track: @track)
create(:paper, state: "review_pending", title: "Paper Review Pending With Editor", editor: editor, track: @track)
create(:accepted_paper, title: "Paper Accepted", editor: editor, track: @track)
create(:rejected_paper, title: "Paper Rejected")
Expand Down Expand Up @@ -74,6 +75,16 @@
expect(page).to_not have_content("Paper Rejected")
end

scenario "List query scoped papers" do
click_link "👍👎"
expect(page).to have_content("Paper Submitted")
expect(page).to have_content("Paper Review Pending No Editor")
expect(page).to_not have_content("Paper Under Review")
expect(page).to_not have_content("Paper Review Pending With Editor")
expect(page).to_not have_content("Paper Accepted")
expect(page).to_not have_content("Paper Rejected")
end

scenario "List all visible papers" do
click_link "All papers"
expect(page).to have_content("Paper Submitted")
Expand Down Expand Up @@ -112,7 +123,7 @@
end
end

scenario "Dropdown is visible only in incoming/in_progress/all_papers tabs" do
scenario "Dropdown is visible only in incoming/in_progress/query_scoped/all_papers tabs" do
expect(page).to_not have_css("select#track_id")

visit dashboard_incoming_path
Expand All @@ -124,6 +135,9 @@
visit dashboard_in_progress_path
expect(page).to have_css("select#track_id")

visit dashboard_query_scoped_path
expect(page).to have_css("select#track_id")

visit "/dashboard"
expect(page).to_not have_css("select#track_id")

Expand All @@ -150,6 +164,15 @@
expect(page).to_not have_content("Paper Accepted")
expect(page).to_not have_content("Paper Rejected")

visit dashboard_query_scoped_path(track_id: @track.id)

expect(page).to_not have_content("Paper Submitted")
expect(page).to have_content("Paper Review Pending No Editor")
expect(page).to_not have_content("Paper Under Review")
expect(page).to_not have_content("Paper Review Pending With Editor")
expect(page).to_not have_content("Paper Accepted")
expect(page).to_not have_content("Paper Rejected")


visit dashboard_all_path(track_id: @track.id)

Expand Down

0 comments on commit 6d77a89

Please sign in to comment.