-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
420 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the import_users controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
class ImportStudentsController < ApplicationController | ||
include CsvImport | ||
def import | ||
# initialize | ||
file = params[:csv_upload] # the file object | ||
if file | ||
overwrite = (params[:overwrite] == '1') # update existing users? | ||
filepath = file.tempfile.path # the rails CSV class needs a filepath | ||
|
||
imported_students = csv_import(filepath) | ||
end | ||
|
||
# check if input file is valid and return appropriate error message if not | ||
if valid_input_file?(imported_students, file) | ||
# create the users and exit | ||
@hash_of_statuses = import_students(imported_students, overwrite) | ||
render 'imported' | ||
end | ||
end | ||
|
||
# functions like the RESTful new action by rendering a form with a GET request | ||
def import_page | ||
# limits the options for user.role to the following array, and displays them with more user-friendly labels. | ||
render 'import' # a form for uploading a csv file of users to import | ||
end | ||
|
||
|
||
private | ||
# this method checks that the user has uploaded a file and displays flash messages if there is an error. | ||
# putting these validations in the controller is not idiomatic in rails and there is likely a cleaner way to | ||
# do this. If we ever have to validate more input than this, we should remove this to a csv_import validations model. | ||
def valid_input_file?(imported_students, file) | ||
# check if the user has uploaded a file at all. | ||
if !file | ||
flash[:error] = 'Please select a file to upload.' | ||
redirect_to :back and return | ||
end | ||
|
||
|
||
|
||
# make sure the import went with proper headings / column handling | ||
|
||
accepted_keys = [:name, :role, :first_name, :nick_name, :goes_by, :last_name, :official_full_name, :net_id, :cell, :yale_email, :yale_email_alias, :non_yale_email, :queue, :old_queue, :college, :class_year, :t_shirt_size, :birthday, :dietary_needs] | ||
unless imported_students.first.keys == accepted_keys | ||
flash[:error] = 'Unable to import CSV file. Please ensure that the first line of the file exactly matches the sample input (login, first_name, etc.) Note that headers are case sensitive and must be in the correct order.' | ||
redirect_to :back and return | ||
end | ||
return true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ImportUsersHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<thead> | ||
<tr> | ||
<th>Login</th> | ||
<th>Name</th> | ||
<th>Phone</th> | ||
<th>Email</th> | ||
<th>Reason</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% students.each do |student_data| %> | ||
<% student = student_data.first %> | ||
<tr> | ||
<td><%= student[:first_name] + ' ' + user[:last_name] %></td> | ||
<td><%= student[:cell_phone] %></td> | ||
<td><%= student[:yale_email] %></td> | ||
</tr> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<h3>CSV Import Format</h3> | ||
<h5>Columns (must be in the first row of the CSV file)</h5> | ||
<%= form_tag csv_imported_path, :multipart => true do %> | ||
|
||
<p> | ||
<label>CSV file with users to import:</label> | ||
<%= file_field_tag 'csv_upload' %> | ||
</p> | ||
<p> | ||
<label>Update existing users' information?</label> | ||
<%= check_box_tag 'overwrite' %> | ||
</p> | ||
<%= submit_tag 'Import Users!', :class => 'btn' %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<% if @hash_of_statuses %> | ||
<% unless @hash_of_statuses[:fail].empty? %> | ||
<h2>students not successfully imported</h2> | ||
<table class="datatable-wide table table-striped table-bordered" id="student_import_errors_table"> | ||
<%= render :partial => 'import_table', :locals => {:students => @hash_of_statuses[:fail]} %> | ||
</table> | ||
<% unless @hash_of_statuses[:success].empty? %> | ||
<hr /> | ||
<% end %> | ||
<% end %> | ||
<% unless @hash_of_statuses[:success].empty? %> | ||
<h2>Students successfully imported</h2> | ||
<%= render :partial => 'students/table', :locals => {:students => @hash_of_statuses[:success]} %> | ||
<% end %> | ||
<% else %> | ||
<h2>Please follow <%= link_to "this link", :controller => :import_students, :action => :import_page %> to import students.</h2> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div id="flashes"> | ||
<%= render 'layouts/flash_alerts' %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<%# flash messages, if any %> | ||
<% flash.each do |name, msg| %> | ||
<% unless msg.blank? %> | ||
<%= content_tag :div, :id => "flash_#{name}", :class => "alert alert-#{(name == :notice || name == 'notice') ? "success" : "error"}" do %> | ||
<button class="close" data-dismiss="alert">×</button> | ||
<%= msg.gsub(/\n/, "<br />").html_safe %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% flash.clear %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<table id="table_info" class="datatable-wide table table-striped table-bordered"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>First Name</th> | ||
<th>Nickname</th> | ||
<th>Last Name</th> | ||
<th>Goes By</th> | ||
<th>Official Name</th> | ||
<th>NetID</th> | ||
<th>Cell Phone</th> | ||
<th>Yale Email</th> | ||
<th>Yale Email Alias</th> | ||
<th>Real Email</th> | ||
<th>Queue</th> | ||
<th>Old Queue</th> | ||
<th>Residential College/Graduate</th> | ||
<th>Class Year</th> | ||
<th>Birthday</th> | ||
<th>Other</th> | ||
</tr> | ||
<td><%= link_to @student.name, @student %></td> | ||
<td><%= link_to @student.first_name, @student %></td> | ||
<td><%= link_to @student.nick_name, @student %></td> | ||
<td><%= link_to @student.last_name, @student %></td> | ||
<td><%= link_to @student.goes_by, @student %></td> | ||
<td><%= link_to @student.official_full_name, @student %></td> | ||
<td><%= link_to @student.net_id, @student %></td> | ||
<td><%= link_to @student.cell, @student %></td> | ||
<td><%= link_to @student.yale_email, @student %></td> | ||
<td><%= link_to @student.yale_email_alias, @student %></td> | ||
<td><%= link_to @student.non_yale_email, @student %></td> | ||
<td><%= link_to @student.queue, @student %></td> | ||
<td><%= link_to @student.old_queue, @student %></td> | ||
<td><%= link_to @student.college, @student %></td> | ||
<td><%= link_to @student.class_year, @student %></td> | ||
<td><%= link_to @student.birthday, @student %></td> | ||
<td><%= link_to @student.other, @student %></td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<table id="table_students" class="datatable-wide table table-striped table-bordered"> | ||
<thead> | ||
<tr> | ||
<th>NetID</th> | ||
<th>First Name</th> | ||
<th>Nickname</th> | ||
<th>Last Name</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% for student in students %> | ||
<tr> | ||
<td><%= link_to student.net_id, student %></td> | ||
<td><%= link_to student.first_name, student %></td> | ||
<td><%= link_to student.nick_name, student %></td> | ||
<td><%= link_to student.last_name, student %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class AddRosterFieldsToStudent < ActiveRecord::Migration | ||
def change | ||
add_column :students, :role, :string | ||
add_column :students, :first_name, :string | ||
add_column :students, :nick_name, :string | ||
add_column :students, :goes_by, :string | ||
add_column :students, :last_name, :string | ||
add_column :students, :official_full_name, :string | ||
add_column :students, :net_id, :string | ||
add_column :students, :cell, :string | ||
add_column :students, :yale_email, :string | ||
add_column :students, :yale_email_alias, :string | ||
add_column :students, :non_yale_email, :string | ||
add_column :students, :queue, :string | ||
add_column :students, :old_queue, :string | ||
add_column :students, :college, :string | ||
add_column :students, :class_year, :integer | ||
add_column :students, :birthday, :string | ||
add_column :students, :other, :text | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.