CSC/ECE 517 Fall 2017/E1757 Introduce a Student View for instructors

From Expertiza_Wiki
Jump to navigation Jump to search

This wiki page documents the changes made as a part of E1757 which allows users with instructor role to view Expertiza as a student.

Introduction

Background

In Expertiza, instructors can act as students, but they do so by using different pull-down menus. This is potentially confusing, especially for Assignments, which appear both in the admin and student menus.

An instructor sees the following menus across the top (if his/her window is wide enough; otherwise, the menus show up when the menu icon is clicked on):

Home Manage Survey Deployments Assignments Course Evaluation Profile Contact Us

A student sees these menus:

Home Assignments Course Evaluations Profile Contact Us

On the instructor’s Manage menu, one of the options is “Assignments”. Having Assignments appear in two places in the menu is potentially confusing. Manage > Assignments allows the instructor to edit and create assignments. The Assignments menu that both students and instructors see allows them to participate in assignments.

Hence, to avoid confusion, a new view is introduced.

Problem statement

To create a Student View that would make the instructor view the system the way (s)he would view it if they were a student. Once the instructor is in student view, the menu items are same as a student would view, so to come back as the instructor, a button should be visible to the instructor that would exit the Student View and take the instructor back to his/her home page.

Team

  1. Amit Kanwar
  2. Apoorva Mehta
  3. Gaurav Joshi

Mentor - Ed Gehringer

Development

student_view_controller.rb

A new controller is created app/controllers/student_view_controller.rb to handle the new student view functionality, which sets and instructor to student view and reverts the view back to instructor.

@@ -0,0 +1,21 @@
class StudentViewController < ApplicationController
  def action_allowed?
    case params[:action]
    when 'set'
	true
    when 'revert'
	true
    end
  end

  def set
    session[:student_view] = true
    redirect_back
  end

  def revert
    session.delete(:student_view)
    redirect_back
  end

end

role_instructor.yml

A new view is created for the instructor in config/role_instructor.yml which will show the view under the Manage menu item. The view id is 25.

      51: &25 !ruby/object:Menu::Node
        content_page_id:
        controller_action_id: 15
        id: 51
        label: Student View
        name: student_view
        parent:
        parent_id: 37
        site_controller_id: 35
        url: "/student_view/set"

_navigation.html.erb

A new session variable (:student_view) will be used to check if an instructor is in student view or not and will be used to exit the Student view, code changes in app/views/shared/_navigation.html.erb

   <% if session.key?(:student_view) %>
      <%= form_for :student_view, url: '/student_view/revert', html: {id: 'instructor-form'} do |f| %>
          <button type="button" class="btn btn-primary" id="instructor-button">Revert to Instructor View</button>
      <% end %>
   <% end %>
    jQuery("#instructor-button").click(function(event) {
	jQuery("#instructor-form").submit()
    });

_suckerfish.html.erb

The different menu items are shown for particular roles, we check the new session variable to show or hide the various menu items accordingly for the instructor in app/views/menu_items/_suckerfish.html.erb

   student_view = session.key?(:student_view) ? ([1, 26, 27, 2, 14].include? item_id) ? true : false : false
   instructor_view = !session.key?(:student_view) ? ([1, 37, 35, 30, 27, 2, 13, 38, 44, 45, 33, 50, 51, 36, 14].include? item_id) ? true: false : false
   if !student_view and !instructor_view then
     conditional = false
   if session[:user].role.name == "Instructor" then
     if !student_view and !instructor_view then
       conditional = false
     else
       conditional = true
     end

routes.rb

The new controller methods are added in config/routes.rb

  post '/student_view/set', to: 'student_view#set'
  post '/student_view/revert', to: 'student_view#revert'


Testing

The user needs to log-in as instructor to view the developed functionality, this won't be visible for other user roles-

1. Go to Manage > Student View

2. Instructor views Expertiza as a student.

3. A revert button appears at the top right corner, to exit the Student view.

4. Clicking the button takes you back to the instructor view.

External Links

  1. link for forked repository [[1]]