E1826 Add student view for instructor: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 31: Line 31:
== Implementation ==
== Implementation ==
=== expertiza/app/views/shared/_navigation.html.erb ===
=== expertiza/app/views/shared/_navigation.html.erb ===
This file is shared between all views and is responsible for rendering all the elements in the top-most part of the web page. (i.e Displaying the menu items, the logout button etc.)
This file is shared between all views and is responsible for rendering all the elements on the navigation bar including the menu items.


In order to switch between '''instructor view''' and '''student view''', the following code was added. When the user is in '''instructor view''', there is a link named "Switch to Student View" to switch to '''student view''' and when the user is in '''student view''', 'here is a link named "Revert to Instructor View" to switch back to the '''instructor view'''.
In order to switch between default view and student view, the following code was added. When in default view, the instructor is presented with a link, ''Open Student View'', to switch to student view and when in student view, the ''Close Student View'' link can be used to switch back to the default view.
<% if session[:user].role.instructor? %>
<pre>
                  <% if session.key?(:student_view) %>
<% if session[:user] and !session[:user].role.student? and !session[:user].role.ta? %>
                      <%= link_to "Revert to Instructor View", {controller: "instructor", action: "revert_to_instructor_view"},
  <% if session.key?(:student_view) %>
                                  method: :post, :style => "color: white" %>
    <%= link_to "Close Student View", {controller: "role_switch", action: "close_student_view"}, method: :post, :style => "color: white" %>
                  <% else %>
  <% else %>
                      <%= link_to "Switch to Student View", {controller: "instructor", action: "set_student_view"},
    <%= link_to "Open Student View", {controller: "role_switch", action: "open_student_view"}, method: :post, :style => "color: white" %>
                                  method: :post, :style => "color: white" %>
  <% end %>
                  <% end %>
<% end %>
              <% end %>
</pre>
 
=== expertiza/app/controllers/role_switch_controller.rb ===
=== expertiza/app/controllers/instructor_controller.rb ===


A new role_switch_controller.rb file has been added. This controller contains the actions to open/close student view.
A new ''role_switch_controller.rb'' file has been added. This controller contains the actions to open/close student view.
<pre>
<pre>
class RoleSwitchController < ApplicationController
class RoleSwitchController < ApplicationController
Line 92: Line 91:


== Manual UI Testing ==
== Manual UI Testing ==
The user needs to log-in as an instructor to view this functionality.


1. Login as an instructor. Enter 'instructor6' as username and 'password' as password.
1. Login as an instructor. Enter 'instructor6' as username and 'password' as password.
Line 109: Line 106:


== Automated Test Plan ==
== Automated Test Plan ==
1. '''Check whether ''Assignments'' and ''Course Evaluation'' are hidden when in instructor view.'''   
1. '''Check whether ''Assignments'' is absent in the menu in default view and there is an option to ''Open Student View'''''   
This test case is to check if the menu items ''Assignments'' and ''Course Evaluation'' are hidden when an instructor is in instructor view. The following lines can be added to a spec/features file:
This test case is to check if the menu item ''Assignments'' is absent when an instructor is in default view. The following lines can be added to a spec/features file:


<pre>
<pre>

Revision as of 21:50, 28 October 2018

Introduction

Background

The navigation for an instructor follows the below structure.

  • Home
  • Manage...
    • Users
    • Questionnaires
    • Courses
    • Assignments
    • Impersonate User
    • Anonymized View
  • Survey Deployments
  • Assignments
  • Course Evaluation
  • Profile
  • Contact Us

And that for a student follows the below structure.

  • Home
  • Assignments
  • Pending Surveys
  • Profile
  • Contact Us

For an instructor, the menu item 'Assignments' is present in 2 places - in the main menu as 'Assignments' and in the sub-menu as 'Manage.../Assignments' (italicized above). This could potentially be confusing. 'Manage.../Assignments' sub-menu item allows the instructor to create/edit assignments. The menu item 'Assignments' allows an instructor to participate in assignments. This is typically something that the instructor wants to do in a student role and hence there needs to be a student view for instructors to act as students without impersonating them and thus reducing confusion. The same needs to be implemented for admin and super admin as well.

Problem statement

Create a student view for instructors so that they can perform student operations without impersonating them. When an instructor logs in, he/she is in the default view with corresponding menu items (with the exception of the 'Assignments' menu item). There should be an option to switch to and revert back from the student view. When in student view, an instructor is presented with the student menu as listed above.

Implementation

expertiza/app/views/shared/_navigation.html.erb

This file is shared between all views and is responsible for rendering all the elements on the navigation bar including the menu items.

In order to switch between default view and student view, the following code was added. When in default view, the instructor is presented with a link, Open Student View, to switch to student view and when in student view, the Close Student View link can be used to switch back to the default view.

<%  if session[:user] and !session[:user].role.student? and !session[:user].role.ta? %>
  <% if session.key?(:student_view) %>
    <%= link_to "Close Student View", {controller: "role_switch", action: "close_student_view"}, method: :post, :style => "color: white" %>
  <% else %>
    <%= link_to "Open Student View", {controller: "role_switch", action: "open_student_view"}, method: :post, :style => "color: white" %>
  <% end %>
<% end %>

expertiza/app/controllers/role_switch_controller.rb

A new role_switch_controller.rb file has been added. This controller contains the actions to open/close student view.

class RoleSwitchController < ApplicationController
  # check to see if the current action is allowed
  def action_allowed?
    # instructor,admin,superadmin is allowed to perform all the actions in
    # this controller
    ['Super-Administrator',
     'Administrator',
     'Instructor'].include? current_role_name
  end

  # sets student_view in session object and redirects to
  # student_task/list after updating menu list
  def open_student_view
    session[:student_view] = true
    role = Role.student
    session[:menu] = role.cache[:menu]
    redirect_to controller: 'student_task', action: 'list'
  end

  # closes student_view in session object and redirects to
  # tree_display/list after reverting the menu list as per the role
  def close_student_view
    session.delete(:student_view)
    role = session[:user].role
    session[:menu] = role.cache[:menu]
    redirect_to controller: 'tree_display', action: 'list'
  end
end

expertiza/config/routes.rb

New post methods are added in config/routes.rb. The routes are directed to the role switch controller's open_student_view and close_student_view actions.

  resources :role_switch, only: [] do
    collection do
      post  :open_student_view
      post  :close_student_view
    end
  end

Manual UI Testing

1. Login as an instructor. Enter 'instructor6' as username and 'password' as password.

2. Click on Open Student View below username to switch to student view.



3. Click on Close Student View below username to come back to default view.


Automated Test Plan

1. Check whether Assignments is absent in the menu in default view and there is an option to Open Student View This test case is to check if the menu item Assignments is absent when an instructor is in default view. The following lines can be added to a spec/features file:

it " can display relevant menu items after login as an admin/instructor/TA", js: true do
    create(:instructor)
    login_as 'instructor6'
    visit '/tree_display/list'
    expect(page).to have_current_path('/tree_display/list')
    expect(page).to have_content('Manage content')
    expect(page).to have_content('Survey Deployments')
    expect(page).not_to have_content('Assignments')
    expect(page).not_to have_content('Course Evaluation')
end

2. Check whether Manage content and Survey Deployments are hidden in student view. This test case is to check if the menu items Manage content and Survey Deployments are hidden when the instructor switches to student view. The following lines are to be added:

it "can display relevant menu items when switching to student view", js: true do
    create(:instructor)
    login_as 'instructor6'
    visit '/tree_display/list'
    click_link 'Swtich to Student View'
    expect(page).to have_current_path('/student_task/list')
    expect(page).to have_content('Assignments')
    expect(page).to have_content('Course Evaluation')
    expect(page).not_to have_content('Manage content')
    expect(page).not_to have_content('Survey Deployments')
end

External Links

  1. Link to forked repository [[1]]

References

Expertiza

Expertiza Github

Expertiza Documentation

RSpec Documentation