Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile support with failback spike #188

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ push*.dat

# Vagrant files
.vagrant

*.swp
*seeds.rb
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: verify this change

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ignore this file as well. seeds.rb should not be part of .gitignore

32 changes: 31 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base

helper_method :current_user

before_filter :make_available_for_exception_notification
before_filter :make_available_for_exception_notification, :prepare_for_mobile

# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
Expand All @@ -16,6 +16,20 @@ def robot?
request.user_agent =~ bot
end

# Reference https://github.com/rails/rails/issues/3855
# Add a fallback for html, for the case where, eg, 'index.html.erb' exists,
# but not 'index.mobile.erb'
class MobileFallbackResolver < ::ActionView::FileSystemResolver
def find_templates(name, prefix, partial, details)
if details[:formats] == [:mobile]
details = details.dup
details[:formats] = [:mobile, :html, :json]
end
super
end
end
append_view_path MobileFallbackResolver.new('app/views')

private
def get_http_referer
if request.env["HTTP_REFERER"].nil? then
Expand Down Expand Up @@ -116,6 +130,22 @@ def has_permissions_or_redirect(level, url)
# '%m/%d/%Y'
#end

# Source: http://railscasts.com/episodes/199-mobile-devices
private
def mobile_device?
if session[:mobile_param]
session[:mobile_param] == "1"
else
request.user_agent =~ /Mobile|webOS/
end
end
helper_method :mobile_device?

def prepare_for_mobile
session[:mobile_param] = params[:mobile] if params[:mobile]
request.format = :mobile if mobile_device?
end

protected
def make_available_for_exception_notification
request.env["exception_notifier.exception_data"] = {
Expand Down
1 change: 1 addition & 0 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def export_to_csv
def index_core
respond_to do |format|
format.html { render :action => "index" }
format.mobile { render :action => "index" }
format.xml { render :xml => @courses }
end
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/deliverables_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def my_deliverables
@past_courses = user.registered_for_these_courses_during_past_semesters()
respond_to do |format|
format.html { render :action => "index" }
format.mobile { render :action => "index" }
format.xml { render :xml => @deliverables }
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def index
@key_contact_results.uniq!
respond_to do |format|
format.html { render :html => @key_contact_results }
format.mobile { render :mobile => @key_contact_results, layout: 'mobile' }
format.json { render :json => @key_contact_results }
end
end
Expand Down Expand Up @@ -108,6 +109,7 @@ def search
end

respond_to do |format|
format.mobile { render :json => @people_hash, :layout => false }
format.json { render :json => @people_hash, :layout => false }
end
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def index

respond_to do |format|
format.html # index.html.erb
format.mobile {render file: 'welcome/_navigation', layout: 'mobile' }
format.xml { render :xml => @courses }
end
end
Expand Down
41 changes: 41 additions & 0 deletions app/views/layouts/mobile.mobile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<meta content="Carnegie Mellon University" name="author">
<meta content="index,follow" name="robots">
<meta content="31 days" name="revisit-after">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<%# stylesheet_link_tag '/cmu_sv_standard_v4/reset.css', :media => "all", :rel => "stylesheet" %>
<%= stylesheet_link_tag 'site' %>
<%= stylesheet_link_tag 'twiki' %>
<%= csrf_meta_tag %>
<%= javascript_include_tag 'http://code.jquery.com/jquery-1.9.0.min.js',
'http://code.jquery.com/ui/1.10.0/jquery-ui.min.js',
"jquery_ujs.js",
"application" %>
<link rel="stylesheet" href='http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css' type="text/css" media="all"/>

<%= yield :tablesorter %>

<%= stylesheet_link_tag '/cmu_sv_standard_v4/mobile' %>
<!--[if gte IE 5.5000]><![if lt IE 7]>
<%= stylesheet_link_tag '/cmu_sv_standard_v4/ie.css', :media => "screen", :rel => "stylesheet" %>
<![endif]><![endif]--><!--[if gte IE 7]><![if lt IE 8]>
<%= stylesheet_link_tag '/cmu_sv_standard_v4/ie7.css', :media => "screen", :rel => "stylesheet" %>
<![endif]><![endif]-->
<%= stylesheet_link_tag '/cmu_sv_standard_v4/khaki-content.css', :media => "screen", :rel => "stylesheet" %>
<%= stylesheet_link_tag '/cmu_sv_standard_v4/print.css', :media => "print" %>
<%= stylesheet_link_tag 'site_print.css', :media => "print" %>
<%= stylesheet_link_tag 'scaffold' %>

<title><%= (title = yield :title) ? title : 'Silicon Valley Campus - Carnegie Mellon University' %></title>
<%= yield :javascript %>
<%= yield :head %>
</head>

<body>
<%= yield %>
</body>
</html>
36 changes: 36 additions & 0 deletions app/views/welcome/_navigation.mobile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div id="nav">
<%# link_to image_tag("/images/whiteboard.jpg", :alt => "Whiteboard logo", :border => 0, :width => "30%"), root_path %>
<%= link_to image_tag("/images/whiteboard.jpg", :alt => "Whiteboard logo", :border => 0), root_path %>
<ul>
<li class="standard"><a href="/people">People</a></li>
<li class="standard"><a href="/courses">Courses</a></li>
<ul>
<li class="standard">
<a href=<%= "/courses/semester/#{AcademicCalendar.current_semester()}#{AcademicCalendar.current_semester_year()}" %>><%= AcademicCalendar.current_semester() %> <%= AcademicCalendar.current_semester_year() %>
Courses</a></li>

<% if AcademicCalendar.next_semester_is_soon %>
<li class="standard">
<a href=<%= "/courses/semester/#{AcademicCalendar.next_semester()}#{AcademicCalendar.next_semester_year}" %>><%= AcademicCalendar.next_semester() %> <%= AcademicCalendar.next_semester_year %>
Courses</a></li>
<% end %>
</ul>
<li class="standard"><%= link_to "Presentations", today_presentations_url, :class => "Lv1NavLink" %></li>
<% if current_user %>
<li class="standard"><%= link_to "My Deliverables", my_deliverables_path(current_user.twiki_name), :class => "Lv1NavLink" %></li>
<li class="standard"><%= link_to "My Teams", my_teams_path(current_user.twiki_name), :class => "Lv1NavLink" %></li>
<li class="standard"><%= link_to "Logout " + current_user.first_name, destroy_user_session_path, :class => "Lv1NavLink" %></li>
<% else %>
<li class="standard"><font color="#626262">My Deliverables (Login required)</font></li>
<li class="standard"><font color="#626262">My Teams (Login required)</font></li>
<li class="standard"><%= link_to "Login ", user_omniauth_authorize_path(:google_apps), :class => "Lv1NavLink" %></li>
<% end %>
</ul>
<div class="hr">
<hr>
</div>
<%= yield :left_nav %>
<% if @is_in_grade_book %>
<%= render :partial=>"layouts/grade_book_menu" %>
<% end %>
</div>
4 changes: 1 addition & 3 deletions app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<% content_for :title, 'Whiteboard LMS for CMU-SV' %>

<%# render :partial=>'rss_feeds/index', :locals => {:rss_feeds => @rss_feeds} %>

<h1>Whiteboard.sv.cmu.edu</h1>
Expand Down Expand Up @@ -42,4 +40,4 @@
<% if current_user && current_user.is_admin %>
<h2>Admin only</h2>
<p><%= link_to "Config", config_path %></p>
<% end %>
<% end %>
45 changes: 45 additions & 0 deletions app/views/welcome/index.mobile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<% content_for :title, 'Whiteboard LMS for CMU-SV (Mobile)' %>

<%# render :partial=>'rss_feeds/index', :locals => {:rss_feeds => @rss_feeds} %>

<h1>Whiteboard.sv.cmu.edu</h1>

<form action="<%= search_index_path %>" id="searchform" method="get" role="search">
<div>
<label for="s" class="screen-reader-text">Search for:</label>
<input type="text" id="query" name="query" value="">
<input type="submit" value="Search" id="searchsubmit">
(Note: searches through curriculum pages)
</div>
</form>

<% if current_user %>
<table class="layout_table">
<tr>
<td>
<%= render :partial => "/courses/my_courses" %>
</td>
<td>
<h1>Pages</h1>
<%= link_to "Orientation", "/pages/orientation" %>
</td>
</tr>
</table>
<% end %>


<% if current_user && (current_user.is_staff || current_user.is_admin) %>
<h2>Faculty views</h2>
<p><a href="/teams">All teams</a></p>
<h2>Admin notes</h2>
<p>The current semester is <%= current_semester() %>. The current time is <%= l Time.now, :format => :chatty %> </p>
<% end %>

<h2>New features</h2>
<p><%= link_to "New Features", new_features_path %></p>
<p><%= link_to "Google Mailing Lists", mailing_lists_path %></p>

<% if current_user && current_user.is_admin %>
<h2>Admin only</h2>
<p><%= link_to "Config", config_path %></p>
<% end %>
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
#
# The :"*/*" and "*/*" formats below is required to match Internet
# Explorer requests.
# config.navigational_formats = [:"*/*", "*/*", :html]
config.navigational_formats = [:"*/*", "*/*", :html, :mobile]

# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
Expand Down
1 change: 1 addition & 0 deletions config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Mime::Type.register_alias "text/html", :mobile
14 changes: 7 additions & 7 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@
factory :your_name_here, :parent => :person do
is_student 1
is_part_time 0
graduation_year "2012"
graduation_year "2013"
masters_program "SE"
masters_track "Tech"
twiki_name "FirstLast"
first_name "First"
last_name "Last"
human_name "Your Name"
email "your.email@sv.cmu.edu"
webiso_account "your.name@andrew.cmu.edu"
twiki_name "DavidLiu"
first_name "David"
last_name "Liu"
human_name "David Liu"
email "david.liu@sv.cmu.edu"
webiso_account "david.liu@andrew.cmu.edu"
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: Ignore this commit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. This should not have been checked in. Our Bad.


end
Expand Down
Loading