Skip to content

Commit

Permalink
Added dashboard functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Lee committed Oct 23, 2011
1 parent 9480013 commit 40ef6f0
Show file tree
Hide file tree
Showing 22 changed files with 1,516 additions and 16 deletions.
15 changes: 14 additions & 1 deletion app/controllers/events_controller.rb
Expand Up @@ -8,12 +8,24 @@ def new

def show
@event = Event.find(params[:id])
@count = @event.attempts.find(:all, :conditions => ['completed_at IS NOT NULL']).count
render :template => 'events/show', :layout => 'dashboard'
end

def congratulations
@event = Event.find(params[:id])
end

def presentation
@event = Event.find(params[:id])
render :template => 'events/presentation', :layout => false
end

def counter
@event = Event.find(params[:id])
render :text => @event.attempts.find(:all, :conditions => ['completed_at IS NOT NULL']).count
end

def create
@event = Event.new(params[:event])
respond_to do |format|
Expand All @@ -31,8 +43,9 @@ def edit

def update
@event = Event.find_by_token(params[:id], :conditions => { :key => params[:event].delete(:key) })
Rails.logger.info @event.inspect
respond_to do |format|
if !@event.nil? && @event.update_attributes(params[:event])
if !@event.nil? && @event.update_attributes!(params[:event])
flash[:notice] = 'Your details were successfully updated.'
format.html { redirect_to event_path(@event) }
else
Expand Down
4 changes: 3 additions & 1 deletion app/models/event.rb
Expand Up @@ -6,7 +6,7 @@ class KeyExists < StandardError; end

set_primary_key 'token'

attr_accessible :name, :email, :instructions
attr_accessible :name, :email, :instructions, :flickr_group_id, :twitter_account

before_validation :set_token, :set_key, :on => :create

Expand All @@ -19,6 +19,8 @@ class KeyExists < StandardError; end
:format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}
validates :name, :presence => true,
:length => {:minimum => 3, :maximum => 254}
validates :twitter_account, :length => {:minimum => 0, :maximum => 254}
validates :flickr_group_id, :length => {:minimum => 0, :maximum => 254}
validates :instructions, :length => { :maximum => 2000 }

protected
Expand Down
4 changes: 4 additions & 0 deletions app/views/events/_form.html.erb
Expand Up @@ -3,6 +3,10 @@
<%= fields.text_field :name %><br />
<%= fields.label :email, 'Your Email' %>:
<%= fields.text_field :email %><br />
<%= fields.label :twitter_account, 'Twitter Account' %>:
<%= fields.text_field :twitter_account %><br />
<%= fields.label :flickr_group_id, 'Flickr Group ID' %>:
<%= fields.text_field :flickr_group_id %><br />
<%= fields.label :instructions, 'Event Instructions' %>:
<%= fields.text_area :instructions %><br />
<% end %>
27 changes: 27 additions & 0 deletions app/views/events/presentation.html.erb
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>Maze</title>
</head>
<body>
<iframe name="Frame1" id="Frame1" src="" frameborder="0" width=100% height=800></iframe>

<script>
var arrURL=new Array (
"<%= event_path(@event.id) %>",
"/pages/help");
var curIndex=0;
var timer=0;
var refreshRate=30; //seconds
function ChangeFrame()
{
clearTimeout(timer);
var url=arrURL[curIndex];
document.getElementById('Frame1').setAttribute('src',url);
curIndex = ((curIndex+1)%arrURL.length);
timer = setTimeout("ChangeFrame()", refreshRate*1000);
}
ChangeFrame();
</script>
</body>
</html>
89 changes: 84 additions & 5 deletions app/views/events/show.html.erb
@@ -1,9 +1,88 @@
<h1><%= @event.name %> dashboard</h1>

<%= render :partial => '/shared/flash' , :locals => {:flash => flash} %>

<div>Robots made it through the maze</div>
<div>Twitter Account</div>
<div>Flickr Photos</div>
<div class="row">
<div class="span16">
<div class="row">
<div class="span6">&nbsp;</div>
<div class="span2">
<div style="font-size: 35px; line-height:38px">Robot Tries</div>
</div>
<div class="span2">
<div id="flip-counter" class="flip-counter"></div>
</div>
<div class="span6">&nbsp;</div>
</div>
</div>
</div>
<div class="row">
<div class="span6">
<% unless @event.twitter_account.blank? %>
<p style="font-size: 20px;">Latest from twitter</p>
<div id="twitter" style="width:300px"></div>
<% end %>
</div>
<div class="span10">
<% unless @event.flickr_group_id.blank? %>
<p style="font-size: 20px;">Latest from flickr</p>
<div id="flickr"></div>
<% end %>
</div>
</div>


<script type="text/javascript">
//<![CDATA[
var robotcounter;
function updateCounter(token)
{
$.ajax({
method: 'get',
url : '/events/'+token+'/counter',
dataType : 'text',
success: function (text) { robotcounter.setValue(parseInt(text)); }
});

}
$(function(){
// Initialize a new counter
robotcounter = new flipCounter('flip-counter', {value: <%= @count %>, digits: 4, auto: false});
});
setInterval("updateCounter('<%=h @event.token %>')", 5000);
//]]>
</script>

<% unless @event.twitter_account.blank? %>
<script type="text/javascript">
$('#twitter').jTweetsAnywhere({
username: '<%=h @event.twitter_account %>',
count: 5,
showTweetFeed: {
showTimestamp: {
refreshInterval: 15
},
autorefresh: {
mode: 'auto-insert',
interval: 60
},
paging: { mode: 'none' }
}
});
</script>
<% end %>
<% unless @event.flickr_group_id.blank? %>
<script type="text/javascript">
$.getJSON("http://api.flickr.com/services/feeds/groups_pool.gne?jsoncallback=?",{id:"<%=h @event.flickr_group_id %>", format: "json" },
function(data) {
$.each(data.items, function(i,item){
console.log(item)
console.log(item.media)
$("<img/>").attr({src : item.media.m.replace('_m.','_z.')}).appendTo("#flickr");
if ( i == 3 ) {
$('#flickr').coinslider({ hoverPause: false, navigation: true, width: 640, height: 400, delay: 5000 });
return false;
}
});
});
</script>
<% end %>
5 changes: 1 addition & 4 deletions app/views/layouts/application.html.erb
Expand Up @@ -3,15 +3,13 @@
<head>
<title>Maze</title>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css">
<script src="http://twitter.github.com/bootstrap/1.3.0/bootstrap-alerts.js" type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<%# javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>

<div class="container">

<% unless controller.controller_name == 'events' and controller.action_name == 'show' %>
<ul class="tabs">
<li><%= link_to 'Home', '/' %></li>
<li><%= link_to 'Help & Resources', help_pages_path %></li>
Expand All @@ -22,7 +20,6 @@
<li><%= link_to 'Add an event', new_event_path %></li>
<% end %>
</ul>
<% end %>

<%= yield %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/attempt.html.erb
Expand Up @@ -53,7 +53,7 @@ home
clean

repeat 4 [
forward 100
forward 1
right 90
]
<% else %>
Expand Down
28 changes: 28 additions & 0 deletions app/views/layouts/dashboard.html.erb
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Maze</title>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css">
<link rel="stylesheet" href="/stylesheets/jquery.jtweetsanywhere-1.2.1.css">

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

<script src="/javascripts/jquery.jtweetsanywhere-1.2.1.min.js" type="text/javascript"></script>
<%# javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<!-- My flip counter script, REQUIRED -->
<script type="text/javascript" src="/javascripts/flipcounter.min.js"></script>
<!-- Style sheet for the counter, REQUIRED -->
<link rel="stylesheet" type="text/css" href="/stylesheets/counter.css" />

<script type="text/javascript" src="/javascripts/coin-slider.min.js"></script>
<link rel="stylesheet" type="text/css" href="/stylesheets/coin-slider-styles.css" />
</head>
<body>

<div class="container">
<%= yield %>
</div>

</body>
</html>
4 changes: 4 additions & 0 deletions config/routes.rb
Expand Up @@ -9,6 +9,10 @@
end

resources :events do
member do
get 'counter'
get 'presentation'
end
resources :attempts do
get 'program'
end
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20111023113917_add_social_media_to_events.rb
@@ -0,0 +1,6 @@
class AddSocialMediaToEvents < ActiveRecord::Migration
def change
add_column :events, :flickr_group_id, :string
add_column :events, :twitter_account, :string
end
end
11 changes: 7 additions & 4 deletions db/schema.rb
@@ -1,3 +1,4 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand All @@ -10,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20111001185301) do
ActiveRecord::Schema.define(:version => 20111023113917) do

create_table "attempts", :id => false, :force => true do |t|
t.string "token", :limit => 5
Expand All @@ -23,14 +24,16 @@
end

create_table "events", :id => false, :force => true do |t|
t.string "token", :limit => 5
t.string "key", :limit => 5
t.string "token", :limit => 5
t.string "key", :limit => 5
t.string "name"
t.string "email"
t.text "instructions"
t.boolean "active", :default => true
t.boolean "active", :default => true
t.datetime "created_at"
t.datetime "updated_at"
t.string "flickr_group_id"
t.string "twitter_account"
end

end
Binary file added public/images/digits-bottom.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/digits-top.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/digits.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 40ef6f0

Please sign in to comment.