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 46: Line 46:
=== expertiza/app/controllers/instructor_controller.rb ===
=== expertiza/app/controllers/instructor_controller.rb ===


A new instructor_controller.rb file has been added. This controller currently contains the actions to switch to student view and revert back to instructor view.
A new role_switch_controller.rb file has been added. This controller contains the actions to open/close student view.
<pre>
<pre>
class InstructorController < ApplicationController
class RoleSwitchController < ApplicationController
   # check to see if the current action is allowed
   # check to see if the current action is allowed
   def action_allowed?
   def action_allowed?
     # only an instructor is allowed to perform all the actions in
     # instructor,admin,superadmin is allowed to perform all the actions in
     # this controller
     # this controller
     return true if session[:user].role.instructor?
     ['Super-Administrator',
    'Administrator',
    'Instructor'].include? current_role_name
   end
   end


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


   # destroys student_view in session object and redirects to
   # closes student_view in session object and redirects to
   # tree_display/list after updating hidden_menu_items
   # tree_display/list after reverting the menu list as per the role
   def revert_to_instructor_view
   def close_student_view
     session.delete(:student_view)
     session.delete(:student_view)
     MenuItemsHelper.update_hidden_menu_items_for_instructor_view(session)
     role = session[:user].role
    session[:menu] = role.cache[:menu]
     redirect_to controller: 'tree_display', action: 'list'
     redirect_to controller: 'tree_display', action: 'list'
   end
   end
Line 76: Line 80:
=== expertiza/config/routes.rb ===
=== expertiza/config/routes.rb ===


New post methods are added in ''config/routes.rb''. The routes are directed to the instructor controller's ''set_student_view'' and ''revert_to_instructor_view'' actions.
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.


<pre>
<pre>
   resources :instructor, only: [] do
   resources :role_switch, only: [] do
     collection do
     collection do
       post  :set_student_view
       post  :open_student_view
       post  :revert_to_instructor_view
       post  :close_student_view
     end
     end
   end
   end
</pre>
</pre>


Line 140: Line 143:


== External Links ==
== External Links ==
# Link to forked repository [[https://github.com/akshayravichandran/expertiza]]
# Link to forked repository [[https://github.com/hrshagrwl/expertiza]]
# Link to screen cast [[https://youtu.be/lRZT4q7YDLA]]


==References==
==References==

Revision as of 21:14, 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 in the top-most part of the web page. (i.e Displaying the menu items, the logout button etc.)

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.

<% if session[:user].role.instructor? %>
                 <% if session.key?(:student_view) %>
                     <%= link_to "Revert to Instructor View", {controller: "instructor", action: "revert_to_instructor_view"},
                                 method: :post, :style => "color: white" %>
                 <% else %>
                     <%= link_to "Switch to Student View", {controller: "instructor", action: "set_student_view"},
                                 method: :post, :style => "color: white" %>
                 <% end %>
             <% end %>

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.

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

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.

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 and Course Evaluation are hidden when in instructor 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:

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