Permalink
Browse files

Fixing various issues

  • Loading branch information...
1 parent 8bd6ccf commit 42e5d733f6da54f02ebb26da31bc9b9b0fd54659 Rob Lee committed Oct 23, 2011
@@ -22,11 +22,11 @@ def show
@attempt = @event.attempts.find(params[:id])
end
- def retrieve
- @attempt = @event.attempts.new
+ def search
+ @attempt = Attempt.new
end
- def search
+ def retrieve
@attempt = @event.attempts.find_by_token(params[:attempt][:id])
if @attempt
redirect_to event_attempt_path(@event, @attempt)
@@ -1,32 +1,24 @@
class EventsController < ApplicationController
- before_filter :assert_event, :only => [:show, :worksheet, :congratulations, :edit]
-
- def index
- end
+ before_filter :assert_event, :only => [:show, :worksheet, :congratulations, :edit, :presentation, :counter]
def new
@event = Event.new
end
- def show
+ def dashboard
@count = @event.attempts.find(:all, :conditions => ['completed_at IS NOT NULL']).count
render :template => 'events/show', :layout => 'dashboard'
end
- def worksheet
- end
-
def congratulations
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
@@ -46,7 +38,7 @@ def edit
def update
@event = Event.find_by_token(params[:id], :conditions => { :key => params[:event].delete(:key) })
- Rails.logger.info @event.inspect
+ params[:event].delete(:email) if params[:event][:email].blank?
respond_to do |format|
if !@event.nil? && @event.update_attributes!(params[:event])
flash[:notice] = 'Your details were successfully updated.'
@@ -0,0 +1,9 @@
+<h1>Search for an attempt</h2>
+
+<p>If you have previously submitted an attempt, then enter your token below to find it:</p>
+
+<%= form_for [@event, @attempt], :url => retrieve_event_attempts_url(@event), :method => :post, :html => { :id => 'data'} do |f| %>
+ <%= f.label :id, 'Token' %>:
+ <%= f.text_field :id %><br />
+ <%= f.submit 'Find', :class => 'btn primary' %>
+<% end %>
@@ -2,7 +2,7 @@
<%= fields.label :name, 'Event Name' %>:
<%= fields.text_field :name %><br />
<%= fields.label :email, 'Your Email' %>:
- <%= fields.text_field :email %><br />
+ <%= fields.text_field :email, :value => '' %><br />
<%= fields.label :twitter_account, 'Twitter Account' %>:
<%= fields.text_field :twitter_account %><br />
<%= fields.label :flickr_group_id, 'Flickr Group ID' %>:
@@ -0,0 +1,88 @@
+<%= render :partial => '/shared/flash' , :locals => {:flash => flash} %>
+
+<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 %>
@@ -1,88 +1,82 @@
-<%= render :partial => '/shared/flash' , :locals => {:flash => flash} %>
+<h2>Intro</h2>
-<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>
+<%= render :partial => '/shared/flash', :locals => {:flash => flash} %>
+<p>The objective of this task is to program the robot to navigate through the maze.</p>
-<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>
+<ol>
+<li>If you are doing this task for the first time, open the <%= link_to "program editor", new_event_attempt_url(@event) %> ( <%= new_event_attempt_url(@event) %> )</li>
+<li>If you have already done this task, but want to edit your attempt then <%= link_to 'search here', search_event_attempts_url(@event) %></li>
+</ol>
-<% 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 %>
+<h2>Commands</h2>
+
+<p>You can control the robot using the following commands:</p>
+
+<table>
+ <thead>
+ <tr>
+ <th>Command</th>
+ <th>Alternative</th>
+ <th>Description of command</th>
+ <th>Example</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <th>forward <i>&lt;x&gt;</i></th>
+ <th>fd <i>&lt;x&gt;</i></th>
+ <td>Move the robot forward by <i>x</i> units.</td>
+ <td>forward 5</td>
+ </tr>
+ <tr>
+ <th>back <i>&lt;x&gt;</i></th>
+ <th>bk <i>&lt;x&gt;</i></th>
+ <td>Move the robot back by <i>x</i> units.</td>
+ <td>back 5</td>
+ </tr>
+ <tr>
+ <th>left <i>&lt;a&gt;</i></th>
+ <th>lt <i>&lt;a&gt;</i></th>
+ <td>Turn the robot <i>a</i> degrees to the left.</td>
+ <td>left 90</td>
+ </tr>
+ <tr>
+ <th>right <i>&lt;a&gt;</i></th>
+ <th>rt <i>&lt;a&gt;</i></th>
+ <td>Turn the robot <i>a</i> degrees to the right.</td>
+ <td>right 90</td>
+ </tr>
+ <tr>
+ <th>sleep <i>&lt;a&gt;</i></th>
+ <th> </th>
+ <td>The robot will sleep for <i>a</i> milliseconds.</td>
+ <td>sleep 1000</td>
+ </tr>
+
+ </tbody>
+</table>
+
+<h2>More advanced control structures</h2>
+
+<table>
+ <thead>
+ <tr>
+ <th>Command</th>
+ <th>Description of expression</th>
+ <th>Example</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <th>repeat <i>&lt;K&gt;</i> [ <i>&lt;commands&gt;</i> ]</th>
+ <td>Repeat block <i>&lt;K&gt;</i>-times.</td>
+ <td><pre>
+repeat 4 [
+ left 90
+ fd 5
+]</pre></td>
+ </tr>
+ </tbody>
+</table>
@@ -14,7 +14,7 @@
<li><%= link_to 'Home', '/' %></li>
<li><%= link_to 'Help & Resources', help_pages_path %></li>
<% if @event %>
- <li><%= link_to 'Worksheet', worksheet_event_path(@event) unless @event.new_record? %></li>
+ <li><%= link_to 'Worksheet', event_path(@event) unless @event.new_record? %></li>
<li><%= link_to 'Amend Event', edit_event_path(@event) unless @event.new_record? %></li>
<li><%= link_to 'Submit Program', new_event_attempt_path(@event) unless @event.new_record? %></li>
<% else%>
View
@@ -10,15 +10,15 @@
resources :events do
member do
- get 'worksheet'
+ get 'dashboard'
get 'counter'
get 'presentation'
end
resources :attempts do
- get 'program'
collection do
- get 'retrieve'
- post 'search'
+ get 'program'
+ get 'search'
+ post 'retrieve'
end
end
end

0 comments on commit 42e5d73

Please sign in to comment.