Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
More wiring for tracker feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Choi committed Nov 10, 2012
1 parent 220a645 commit 386a701
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
14 changes: 8 additions & 6 deletions public/js/application.js
Expand Up @@ -8,17 +8,19 @@


$(document).ready(function(){

if (location.href.search("/curriculum") !== -1 &&
location.href.search("/curriculum_toc") === -1
) { /* show the progress checkbox and email field */

$.get("/student", function(data){

var html = ich.studentProgress(JSON.parse(data));
$.get("/student", function(rawdata){
var data = JSON.parse(rawdata);
var html = ich.studentProgress(data);
$("h2:contains('Next Step'),h2:contains('Finished')").after(html);

if (JSON.parse(data).name !== 'Jane Doe') {
if (data.name) {
$("span#name").attr('contenteditable', false);
} else {
$("span#name").html("CHANGME");
}

$("span[contenteditable=true]").blur(function(){
Expand All @@ -36,7 +38,7 @@


}
$("#student-identity")

});

}(jQuery));
9 changes: 8 additions & 1 deletion schema.sql
@@ -1,5 +1,12 @@
create table students (
student_id serial primary key,
name varchar not null,
name varchar null,
created timestamp with time zone default now()
);

create table completions (
completion_id serial primary key,
student_id integer references students (student_id) on delete cascade,
page varchar,
created timestamp with time zone default now()
);
7 changes: 5 additions & 2 deletions views/layout.erb
Expand Up @@ -23,10 +23,13 @@
<form id="progress-tick">
Check this box if you're done this unit:
<input type="checkbox" value="<%= request.path_info %>" id="done"/>
|&nbsp;
&nbsp;
|&nbsp; &nbsp;
Your name:
<span id="name" contenteditable="true">{{ name }}</span>
&nbsp; |&nbsp; &nbsp;
{{#student_id}}
Student ID: <span id="studentId">{{student_id}}</span>
{{/student_id}}
</div>
</script>
</head>
Expand Down
38 changes: 27 additions & 11 deletions web.rb
Expand Up @@ -34,6 +34,9 @@ def initialize
@app = ::Deck::RackApp.public_file_server
end

enable :sessions
set :session_secret, 'railsbridgebosmit'

Compass.configuration do |config|
config.project_path = File.dirname(__FILE__)
config.sass_dir = 'views/stylesheets'
Expand All @@ -48,34 +51,47 @@ def initialize
:no_intra_emphasis => true,
:fenced_code_blocks => true,
:renderer => HTMLwithCodeRay.new
enable :sessions


get '/dbcheck' do
DB.tables.inspect
end

def load_student
if session[:student_id] && (@student = Student[session[:student_id]])
@student
elsif session[:student_id]
session.clear
nil
end
end

post '/student' do
@student = Student.create(:name => params[:name].strip)
session[:student_id] = @student.student_id.to_s
puts "Created student: #{@student.values.inspect}"
@student.values.to_json
if load_student
@student.update(:name => params[:name])
@student.values.to_json
else
{:error => "No student found"}
end
end

get '/student' do
puts "Session id #{session[:student_id]}"
res = if session[:student_id] && (@student = Student[session[:student_id].to_i])
load_student
res = if @student
@student.values
elsif session[:student_id]
session.clear
{name: 'Jane Doe'}
else
{name: 'Jane Doe'}
@student = Student.create(:name => nil)
session[:student_id] = @student.student_id
puts "Created student #{@student.student_id}"
@student.values
end
puts "Sending student data: #{res.inspect}"
res.to_json
end

post '/progress' do
post '/completions' do

end


Expand Down

0 comments on commit 386a701

Please sign in to comment.