Skip to content

Commit

Permalink
Merge pull request #133 from concord-consortium/poll-student-status
Browse files Browse the repository at this point in the history
Poll and update portal student status on homepage [#91186646]
  • Loading branch information
knowuh committed Aug 6, 2015
2 parents b1b1768 + 0627621 commit eba8c69
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 21 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -62,4 +62,5 @@
= require 'jquery_nested_form'
= require 'main_nav_more_menu'
= require 'main_nav_collections_menu'
= require 'poll_to_update_student_data_percentages'
*/
@@ -0,0 +1,33 @@
DEFAULT_POLL_INTERVAL_IN_SECONDS = 10

window.poll_to_update_student_data_percentages = (options) ->

# done if no poll url
if not options.poll_url
console.error "Missing poll_url option in poll_to_update_student_data_percentages() call" if console?.error
return

# get the poll interval or its default and then convert it to milliseconds if not already converted
poll_interval = parseInt(options.poll_interval)
poll_interval = DEFAULT_POLL_INTERVAL_IN_SECONDS if isNaN(poll_interval) or poll_interval < 1
poll_interval *= 1000 if poll_interval < 1000

update_percentages = (status) ->
for report_learner in status?.report_learners
$offering = jQuery(".offering_for_student[data-offering_id='#{report_learner.offering_id}']")
if $offering and report_learner.last_run
$offering.find('.last_run').html(report_learner.last_run)
$offering.find('.status_graphs .not_run').hide()
$offering.find('.status_graphs .progress').css({width: "#{report_learner.percentage}%"})
$offering.find('.status_graphs .run_graph').show()

# poll for percentage updates
poll = ->
jQuery.ajax options.poll_url,
success: (status) ->
update_percentages status
setTimeout poll, poll_interval

# wait for the initial poll
setTimeout poll, poll_interval

8 changes: 8 additions & 0 deletions app/controllers/portal/students_controller.rb
Expand Up @@ -5,6 +5,14 @@ class Portal::StudentsController < ApplicationController

public

def status
result = Portal::Student.find(params[:id]).status
respond_to do |format|
format.xml { render :xml => result }
format.json { render :json => result }
end
end

def index
@portal_students = Portal::Student.all

Expand Down
13 changes: 13 additions & 0 deletions app/models/portal/student.rb
Expand Up @@ -60,6 +60,19 @@ def self.generate_user_login(first_name, last_name)
return generated_login
end

def status
report_learners = Report::Learner.where(:student_id => self.id).map do |learner|
{
:offering_id => learner.offering_id,
:complete_percent => learner.complete_percent,
:last_run => learner.last_run_string
}
end
{
:report_learners => report_learners
}
end

def update_report_permissions(permission_form)
report_learners = Report::Learner.where(:student_id => self.id)
report_learners.each { |l| l.update_permission_forms; l.save }
Expand Down
13 changes: 13 additions & 0 deletions app/models/report/learner.rb
Expand Up @@ -34,6 +34,19 @@ def ensure_no_nils
return true
end

def last_run_string(opts={})
return Report::Learner.build_last_run_string(last_run, opts)
end

def self.build_last_run_string(last_run, opts={})
not_run_str = "not yet started" || opts[:not_run]
prefix = "Last run" || opts[:prefix]
format = "%b %d, %Y" || opts[:format]

return not_run_str if !last_run
return "#{prefix} #{last_run.strftime(format)}"
end

def calculate_last_run
bundle_logger = self.learner.bundle_logger
pub_logger = self.learner.periodic_bundle_logger
Expand Down
11 changes: 3 additions & 8 deletions app/models/report/offering_student_status.rb
Expand Up @@ -21,7 +21,7 @@ def sub_sections
def display_report_link?
(offering && offering.student_report_enabled? && offering_reportable?)
end

def offering_reportable?
(offering && offering.individual_reportable?)
end
Expand All @@ -32,7 +32,7 @@ def complete_percent
if learner
# check if this is a reportable thing, if not then base the percent on the existance of the learner
if offering_reportable?
learner.report_learner.complete_percent || 0
learner.report_learner.complete_percent || 0
else
# return 99.99 because all we can tell is whether it is in progress
# if we return 100 then the progress bar will indicate it is compelete
Expand Down Expand Up @@ -79,12 +79,7 @@ def never_run
end

def last_run_string(opts={})
not_run_str = "not yet started" || opts[:not_run]
prefix = "Last run" || opts[:prefix]
format = "%b %d, %Y" || opts[:format]

return not_run_str if never_run
return "#{prefix} #{last_run.strftime(format)}"
Report::Learner.build_last_run_string(last_run, opts)
end

end
5 changes: 5 additions & 0 deletions app/views/portal/students/_show.html.haml
Expand Up @@ -3,7 +3,12 @@
- unless current_visitor.anonymous?
%h3 Classes and Offerings:
= render :partial => 'portal/clazzes/list_for_student', :locals => { :portal_student => portal_student }
- poll_options = {poll_url: status_portal_student_url(portal_student.id, :format => :json), poll_interval: ENV['PORTAL_STUDENT_STATUS_UPDATE_POLL_INTERVAL_IN_SECONDS']}
- # note: there is a default value for the poll interval in the javascript
:javascript
poll_to_update_student_data_percentages(#{ poll_options.to_json })

%p
%h3 Enter a new class word to join another class:
= render :partial => 'portal/students/register', :locals => { :portal_student => portal_student }

11 changes: 5 additions & 6 deletions app/views/shared/_offering_for_student.html.haml
Expand Up @@ -10,7 +10,7 @@
- if offering.icon_image
%img{:src => offering.icon_image, :width => '100%'}
%td
.offering_for_student
.offering_for_student{ :data => { :offering_id => offering.id }}
%p
%span.type= runnable_type_label(offering) + ":"
%span.name= offering.name
Expand All @@ -27,11 +27,10 @@
Please wait while your activity loads
%span.wait_counter
.status_graphs
- if student_status.never_run
.not_run
You haven't started this yet.
- else
- percentage = student_status.complete_percent
.not_run{style: "display: #{student_status.never_run ? 'block' : 'none'}"}
You haven't started this yet.
- percentage = student_status.complete_percent
.run_graph{style: "display: #{student_status.never_run ? 'none' : 'block'}"}
%table.status_graphs
%tr.summary
%td.disclosure_widget
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -25,7 +25,6 @@
match '/portal/offerings/:id/activity/:activity_id' => 'portal/offerings#report', :as => :portal_offerings_report, :method => :get
match '/portal/learners/:id/activity/:activity_id' => 'portal/learners#report', :as => :portal_learners_report, :method => :get


post "help/preview_help_page"
post "home/preview_home_page"

Expand Down Expand Up @@ -237,6 +236,7 @@
member do
get :ask_consent
put :update_consent
get :status
end
end

Expand Down
8 changes: 8 additions & 0 deletions features/step_definitions/student_steps.rb
Expand Up @@ -83,6 +83,14 @@
page.should_not have_content(runnable_name)
end

Then /^I should see a link to generate a report of my work$/ do
page.should have_selector("div.run_graph", text: /generate a report of my work/i, visible: true)
end

Then /^I should not see a link to generate a report of my work$/ do
page.should_not have_selector("div.run_graph", text: /generate a report of my work/i, visible: true)
end

Given /^the student report is disabled for the (activity|investigation|external activity) "([^"]+)"$/ do |type, name|
material = nil
case type
Expand Down
12 changes: 6 additions & 6 deletions features/student_views_report.feature
Expand Up @@ -9,27 +9,27 @@ Feature: Student views report
And the database has been seeded
And a simple activity with a multiple choice exists
And the activity "simple activity" is assigned to the class "Class_with_no_assignment"

@lightweight
Scenario: Student sees report link
When I login with username: davy
Then I should not see "Generate a report of my work"
Then I should not see a link to generate a report of my work
And I should not see "Last run"
When run the activity
And choose "Choice 1"
And I press "Submit"
Then I should see "Last run"
When I should see "Generate a report of my work"
When I should see a link to generate a report of my work

@lightweight
Scenario: Student does not see report link if student report is disabled
When the student report is disabled for the activity "simple activity"
When I login with username: davy
Then I should not see "Generate a report of my work"
Then I should not see a link to generate a report of my work
And I should not see "Last run"
And run the activity
And choose "Choice 1"
And I press "Submit"
Then I should see "Last run"
And I should not see "Generate a report of my work"
And I should not see a link to generate a report of my work

0 comments on commit eba8c69

Please sign in to comment.