Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nicer admin home + some more stuff #1031

Merged
merged 9 commits into from
Jun 6, 2024
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
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ gem 'rails-html-sanitizer'
gem 'rack-cors', '~> 2.0'
gem 'rapidjson'
gem 'redis'
gem 'responders'
gem 'rubyzip', '~> 2.3.0' # 3.0 will be breaking
gem 'sassc-rails', '~> 2.1'
gem 'sidekiq'
Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ DEPENDENCIES
rails-html-sanitizer
rapidjson
redis
responders
rubocop
rubocop-capybara
rubocop-rails
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'application_responder'
require 'analytics'
require_relative '../../lib/analytics'

# rubocop:disable Rails/ApplicationController
module Api
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/bulk/queries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def create
existing_queries = indexed_queries.keys

non_existing_queries = unique_queries - existing_queries
non_existing_queries.each_with_index do |query_text, index|
non_existing_queries.each_with_index do |query_text, _index|
query = @case.queries.build(query_text: query_text)
query.insert_at(index + 1)
# query.insert_at(index + 1)
queries_to_import << query
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module V1
# rubocop:disable Metrics/ClassLength
class CasesController < Api::ApiController
before_action :set_case, only: [ :show, :update, :destroy ]
before_action :case_with_all_the_bells_whistles, only: [ :show ]
before_action :check_case, only: [ :show, :update, :destroy ]

def_param_group :case_params do
Expand Down Expand Up @@ -65,6 +64,7 @@ def index
def show
respond_with @case
end

api :POST, '/api/cases', 'Create a new case.'
param_group :case_params
def create
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api/v1/queries/positions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Queries
class PositionsController < Api::V1::Queries::ApplicationController
def update
if @query.move_to(params[:after], params[:reverse])

@case.queries.reload # Need to reload to reflect change
@display_order = @case.queries.map(&:id)

respond_with @query, @display_order
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# frozen_string_literal: true

require 'application_responder'
require 'analytics'
require_relative '../lib/analytics'

class ApplicationController < ActionController::Base
include Authentication::CurrentUserManager
include Authentication::CurrentCaseManager
include Authentication::CurrentBookManager

self.responder = ApplicationResponder

respond_to :html, :js

before_action :set_current_user
Expand Down
19 changes: 4 additions & 15 deletions app/controllers/concerns/authentication/current_case_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def set_case
Case.public_cases.find_by(id: decrypt_case_id(case_id))
elsif current_user
current_user.cases_involved_with.where(id: case_id).first
else
Case.public_cases.find_by(id: case_id)
end

if @case.nil? # We didn't find a match, so let's see if it's a public case
@case = Case.public_cases.find_by(id: case_id)
end
end

def set_recent_cases
Expand Down Expand Up @@ -75,19 +77,6 @@ def recent_cases count
end
# rubocop:enable Metrics/MethodLength

def case_with_all_the_bells_whistles
if current_user
@case = current_user
.cases_involved_with
.where(id: params[:case_id])
.includes(:tries )
.preload([ queries: [ :ratings ], tries: [ :curator_variables, :search_endpoint ] ])
.order('tries.try_number DESC')
.first
end
@case = Case.public_cases.find_by(id: params[:case_id]) if @case.nil?
end

def check_case
render json: { message: 'Case not found!' }, status: :not_found unless @case
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/arrangement/item.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'arrangement/list'
require_relative 'list'

module Arrangement
module Item
Expand Down
4 changes: 2 additions & 2 deletions app/models/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
# queries_ibfk_1 (case_id => cases.id)
#

require 'arrangement/item'
require_relative 'concerns/arrangement/item'

class Query < ApplicationRecord
# Arrangement
include Arrangement::Item

# Associations
belongs_to :case, autosave: true, optional: false
belongs_to :case, autosave: true, optional: false, touch: true

has_many :ratings,
dependent: :destroy
Expand Down
1 change: 0 additions & 1 deletion app/models/selection_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def self.random_query_doc_based_on_strategy book, user
# Randomly select a query doc where we don't have any judgements, and weight it by the position,
# so that position of 1 should be returned more often than a position of 5 or 10.
def self.random_query_doc_pair_for_single_judge book
# book.query_doc_pairs.includes(:judgements).where(:judgements=>{id:nil}).order(Arel.sql('RAND()')).first
book.query_doc_pairs.includes(:judgements)
.where(:judgements=>{ id: nil })
.order(Arel.sql('-LOG(1.0 - RAND()) * position'))
Expand Down
33 changes: 26 additions & 7 deletions app/views/admin/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,31 @@
<h2>
Admin Panel
</h2>
<ul>
<li><%= link_to 'Users', admin_users_path %>
<li><%= link_to 'Quepid Communal Scorers', admin_communal_scorers_path %></li>
<li><%= link_to 'Announcements', admin_announcements_path %>
<li><%= link_to 'Job Manager', sidekiq_web_path %></li>
<li><%= link_to 'Websocket Tester', admin_websocket_tester_index_path %></li>
</ul>

<div class="card" style="">
<div class="card-body">
<h5 class="card-title">Managing Quepid</h5>
<p class="card-text">Configure Quepid to work for your users.</p>

<ul class="list-group list-group-flush">
<li class="list-group-item"><%= link_to 'Users', admin_users_path %>
<li class="list-group-item"><%= link_to 'Quepid Communal Scorers', admin_communal_scorers_path %></li>
<li class="list-group-item"><%= link_to 'Announcements', admin_announcements_path %>
</ul>
</div>
</div>
<p/>
<div class="card" style="">
<div class="card-body">
<h5 class="card-title">Background Jobs</h5>
<p class="card-text">These tools are to help you manage the various background jobs in Quepid.</p>

<ul class="list-group list-group-flush">
<li class="list-group-item"><%= link_to 'Job Manager', sidekiq_web_path %></li>

<li class="list-group-item"><%= link_to 'Websocket Tester', admin_websocket_tester_index_path %></li>
</ul>
</div>
</div>
</div>
</div>
4 changes: 3 additions & 1 deletion app/views/home/case_prophet.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<turbo-frame id="case_frame_<%= @case.id %>">
<h5 class="card-title"><%= number_with_precision(@case.last_score.score, precision: 2) unless @case.scores.empty? %> <%= @case.scorer.name %></h5>
<p class="card-text">
<% if @case.scores %>
<% if @case.scores.empty? %>
<small><code>no scores</code></small>
<% else %>

<%= @case.first_score.created_at.to_date.to_fs(:short) %>
<% if @case.scores.count > 1 and @case.first_score.created_at.to_date.to_fs(:short) != @case.last_score.updated_at.to_date.to_fs(:short) %>
Expand Down
7 changes: 2 additions & 5 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@

module Quepid
class Application < Rails::Application
# Use the responders controller from the responders gem
config.app_generators.scaffold_controller :responders_controller

# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.1
config.active_support.cache_format_version = 7.0 # remove when load_defaults is 7.0
config.load_defaults 7.1
# config.active_support.cache_format_version = 7.1 # remove when load_defaults is 7.0

# Configuration for the application, engines, and railties goes here.
#
Expand Down
135 changes: 0 additions & 135 deletions config/initializers/new_framework_defaults_7_0.rb

This file was deleted.

2 changes: 1 addition & 1 deletion config/initializers/session_store.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_quepid_session', same_site: :lax
Rails.application.config.session_store :cookie_store, key: '_quepid_session', same_site: :strict
37 changes: 0 additions & 37 deletions config/puma.txt

This file was deleted.

Loading