Skip to content
Open
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: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ gem "sprockets-es6"
gem "suspenders"
gem "title"
gem "uglifier"
gem "jbuilder", "~> 2.6.1"

group :development do
gem "listen"
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ GEM
high_voltage (3.0.0)
honeybadger (2.6.1)
i18n (0.7.0)
jbuilder (2.6.1)
activesupport (>= 3.0.0, < 5.1)
multi_json (~> 1.2)
jquery-rails (4.2.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
Expand All @@ -139,6 +142,7 @@ GEM
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.9.1)
multi_json (1.12.1)
neat (1.8.0)
sass (>= 3.3)
thor (~> 0.19)
Expand Down Expand Up @@ -324,6 +328,7 @@ DEPENDENCIES
formulaic
high_voltage
honeybadger
jbuilder (~> 2.6.1)
jquery-rails
launchy
listen
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
//
//= require jquery
//= require jquery_ujs
//= require datatables.min

//= require_tree .
20 changes: 20 additions & 0 deletions app/assets/javascripts/reports.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$(document).ready(function() {
$('#intent-table').DataTable( {
"ajax": {
"url": $('#intent-table').attr('data-src'),
"type": "GET"
},
"columns": [
{ "data": "lastName", className: "student-last" },
{ "data": "firstName", className: "student-first" },
{ "data": "intent", className: "student-intent" },
{ "data": "editStr", className: "student-report-btn" }
],
"rowId": "rowId"
});
});

// TODO: Figure out proper inline editing (left for future work)
// $(document).on('change', '.autosubmit', function() {
// $(this).parents('form:first').submit();
// });
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

@import "bourbon";
@import "neat";
@import "datatables.min";

@import "base/base";
@import "refills/flashes";
10 changes: 9 additions & 1 deletion app/controllers/draws_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true
# Controller for Draws
class DrawsController < ApplicationController
before_action :set_draw, only: [:show, :edit, :update, :destroy]
before_action :set_draw, only: [:show, :edit, :update, :destroy,
:intent_report]

def show
@intent_metrics = IntentMetricsQuery.call(@draw)
Expand Down Expand Up @@ -31,6 +32,13 @@ def destroy
handle_action(**result)
end

def intent_report
respond_to do |format|
format.html { @report_src = draw_intent_report_path(@draw, format: :json) }
format.json { @students = @draw.students }
end
end

private

def authorize!
Expand Down
4 changes: 4 additions & 0 deletions app/policies/draw_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def update?
user.rep? || user.admin?
end

def intent_report?
user.admin?
end

class Scope < Scope # rubocop:disable Style/Documentation
def resolve
scope
Expand Down
11 changes: 11 additions & 0 deletions app/views/draws/intent_report.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1 class="report-title"><%= @draw.name %> Intent Report</h1>
<table id="intent-table" data-src="<%= @report_src %>">
<thead>
<tr>
<td>Last Name</td>
<td>First Name</td>
<td>Intent</td>
<td>Edit</td>
</tr>
</thead>
</table>
10 changes: 10 additions & 0 deletions app/views/draws/intent_report.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
json.data @students.each do |student|
json.extract! student, :id
json.rowId "student-#{student.id}"
json.lastName student.last_name
json.firstName student.name
json.intent student.intent
# TODO: figure out proper inline form, left for posterity
# json.intent simple_form_for(student, url: user_update_intent_path(student)) { |f| f.select :intent, { collection: User.intents.keys }, {}, { class: 'autosubmit' } }
json.editStr link_to 'Edit', user_edit_intent_path(student)
end
3 changes: 3 additions & 0 deletions app/views/draws/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<% end %>
</tbody>
</table>
<% if policy(@draw).intent_report? %>
<%= link_to 'View intent report', draw_intent_report_path(@draw) %>
<% end %>
</div>
<%= link_to 'Delete', draw_path(@draw), method: :delete %>

6 changes: 4 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
resources :rooms
resources :users
resources :draws
get 'users/:id/intent', to: 'users#edit_intent'
put 'users/:id/intent', to: 'users#update_intent'
get 'users/:id/intent', to: 'users#edit_intent', as: 'user_edit_intent'
patch 'users/:id/intent', to: 'users#update_intent', as: 'user_update_intent'
get 'draws/:id/intent_report', to: 'draws#intent_report',
as: 'draw_intent_report'
end
57 changes: 57 additions & 0 deletions spec/features/draws/draw_intent_report_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.feature 'Draw intent report' do
let(:draw) { FactoryGirl.create(:draw) }

context 'as an admin' do
before { log_in(FactoryGirl.create(:admin)) }

it 'is accessible' do
visit draw_path(draw)
click_link('View intent report')

expect(page).to have_css('.report-title',
text: "#{draw.name} Intent Report")
end

it 'displays tables with the appropriate users', :js do
intent_users = create_intent_users(draw)

visit draw_intent_report_path(draw)
save_and_open_page

# expect(page_has_correct_intent_report(page, intent_users))
intent_users.each do |status, student|
expect(page).to have_css("#student-#{student.id} .student-first", text: student.name)
expect(page).to have_css("#student-#{student.id} .student-last", text: student.last_name)
expect(page).to have_css("#student-#{student.id} .student-intent", text: intent)
end
end

def create_intent_users(draw)
User.intents.keys.map do |intent|
[intent, FactoryGirl.create(:user, draw: draw, intent: intent)]
end.to_h
end

def page_has_correct_intent_report(page, intent_users)
intent_users.all? do |status, user|
page.has_css?("tr\#student-#{user.id} .student-first", text: user.name) &&
page.has_css?("tr\#student-#{user.id} .student-last", text: user.last_name) &&
page.has_css?("tr\#student-#{user.id} .student-intent", text: status)
end
end
end

context 'as a student' do
before { log_in(FactoryGirl.create(:student)) }

it 'does not have a link on the status page' do
visit draw_path(draw)

expect(page).not_to have_link('View intent report',
href: draw_intent_report_path(draw))
end
end
end
Loading