From 2421ddb747d69dae27cb82085e877b6de798cd33 Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Sat, 12 Apr 2014 15:37:40 -0400 Subject: [PATCH 1/3] semiworking app --- .../sinatraapp/Peter_Nguyen/views/edit.erb | 6 ++-- .../sinatraapp/Peter_Nguyen/views/index.erb | 4 +++ .../sinatraapp/Peter_Nguyen/views/show.erb | 6 ++-- .../sinatraapp/Peter_Nguyen/youtubesets.rb | 28 +++++++++++++------ 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/assignments/sinatraapp/Peter_Nguyen/views/edit.erb b/assignments/sinatraapp/Peter_Nguyen/views/edit.erb index 4e1c399..037c39b 100644 --- a/assignments/sinatraapp/Peter_Nguyen/views/edit.erb +++ b/assignments/sinatraapp/Peter_Nguyen/views/edit.erb @@ -2,8 +2,10 @@
- + - +
diff --git a/assignments/sinatraapp/Peter_Nguyen/views/index.erb b/assignments/sinatraapp/Peter_Nguyen/views/index.erb index 78b68aa..45c2114 100644 --- a/assignments/sinatraapp/Peter_Nguyen/views/index.erb +++ b/assignments/sinatraapp/Peter_Nguyen/views/index.erb @@ -6,7 +6,11 @@ <%session["sets"].each_value do |set| %>

Set name: <%=set["name"]%>

vids:

+ | <%set["vidnums"].each do |vid| %> <%=vid%> | <%end%> + ">Show + /edit">Edit + /play">Play <%end%> diff --git a/assignments/sinatraapp/Peter_Nguyen/views/show.erb b/assignments/sinatraapp/Peter_Nguyen/views/show.erb index ad88fb2..ff0633a 100644 --- a/assignments/sinatraapp/Peter_Nguyen/views/show.erb +++ b/assignments/sinatraapp/Peter_Nguyen/views/show.erb @@ -1,10 +1,12 @@ +Home

Show a Set

Setname

-

<%= "setname variable goes here" %>

+

<%= @setname %>

Set of videos:

-

<%= "videoname variable goes here" %>

+

<%= session["sets"][@setname]["vidnums"] %>

+ diff --git a/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb b/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb index 200d24d..3635a02 100644 --- a/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb +++ b/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb @@ -40,6 +40,7 @@ ##CREATE page post "/sets" do + session["sets"] ||= {} a = params["videolist"].scan(/\S+\r\n/).map! {|a| a.chomp} session["sets"].store(params["setname"], {"name" => params["setname"], "vidnums" => a}) redirect to('/') @@ -66,30 +67,37 @@ #erb :index #we'll want it to redirect to index later (maybe optionally with a status message at the top?) end +# Testing purposes only get "/hello/:name" do @name = params[:name] - session[:peter] = "bob" - + session[:peter] = "bob" erb :hello, :locals => {:name => params[:name]} + end ##SHOW page get "/sets/:setname" do + session["sets"] ||= {} + @setname = params[:setname] #find the set in session, set the variables to @variables so the view can have them erb :show #just describe what the set has in it, displaying that on the page end ##PLAY page get "/sets/:setname/play" do + session["sets"] ||= {} #find the set in session # session[params[:setname]] - + @videonumber = session["sets"][params[:setname]]["vidnums"].sample #Pull out a random videonumber and set that to an @variable so the view can have it erb :play #actually plays the embedded video! end ##EDIT page get "/sets/:setname/edit" do + session["sets"] ||= {} + @setname = params[:setname] + @vids = session["sets"][@setname]["vidnums"] #parse the youtubelinks params into separate video numbers - from a comma separated string into an array #find the setname, set the variables to @variables so the view can have them - it will make them the form defaults erb :edit #same as new except it puts in the form defaults. @@ -97,22 +105,26 @@ ##UPDATE page put "/sets/:setname" do + session["sets"] ||= {} + a = params["videolist"].scan(/\S+\r\n/).map! {|a| a.chomp} + session["sets"].store(params["setname"], {"name" => params["setname"], "vidnums" => a}) #find setname in session + redirect to('/') #update the variables in session to match parameters - "success going to 'put /sets/:setname!'" #just for testing, we shouldn't render this in the end but instead render an erb + # "success going to 'put /sets/:setname!'" #just for testing, we shouldn't render this in the end but instead render an erb #erb :index #we'll want it to redirect to index later (maybe optionally with a status message at the top?) end ##DESTROY page delete "/sets/:setname" do + session["sets"] ||= {} #delete the set setname from session - "success going to 'delete /sets/:setname'!" #just for testing, we shouldn't render this in the end but instead render an erb + session["sets"].delete(params[:setname]) + # "success going to 'delete /sets/:setname'!" #just for testing, we shouldn't render this in the end but instead render an erb + redirect to('/') #erb :index #we'll want it to redirect to index later (maybe optionally with a status message at the top?) end - - - #Session page for troubleshooting the session get '/session' do session[:sessiontestvariable] = 3.14 From ce394523a1e359ad3a26be9d6350d93a85bb7d66 Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Sat, 12 Apr 2014 15:43:40 -0400 Subject: [PATCH 2/3] fixed small regex bug --- assignments/sinatraapp/Peter_Nguyen/youtubesets.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb b/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb index 3635a02..2c0b5b6 100644 --- a/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb +++ b/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb @@ -41,7 +41,7 @@ ##CREATE page post "/sets" do session["sets"] ||= {} - a = params["videolist"].scan(/\S+\r\n/).map! {|a| a.chomp} + a = params["videolist"].scan(/\S+\r\n|\S+/).map! {|a| a.chomp} session["sets"].store(params["setname"], {"name" => params["setname"], "vidnums" => a}) redirect to('/') @@ -106,7 +106,7 @@ ##UPDATE page put "/sets/:setname" do session["sets"] ||= {} - a = params["videolist"].scan(/\S+\r\n/).map! {|a| a.chomp} + a = params["videolist"].scan(/\S+\r\n|\S+/).map! {|a| a.chomp} session["sets"].store(params["setname"], {"name" => params["setname"], "vidnums" => a}) #find setname in session redirect to('/') From 953c346a5ea998abcc2e9c7ef837a7eb3c19be9f Mon Sep 17 00:00:00 2001 From: Peter Nguyen Date: Sat, 12 Apr 2014 15:45:10 -0400 Subject: [PATCH 3/3] more code cleanup --- .../sinatraapp/Peter_Nguyen/youtubesets.rb | 26 +------------------ 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb b/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb index 2c0b5b6..8b563dd 100644 --- a/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb +++ b/assignments/sinatraapp/Peter_Nguyen/youtubesets.rb @@ -34,37 +34,13 @@ # "sets" => { "SETNAME" => { "name" => "SETNAME", "vidnums" => ["VID1", "VID2", "VID3"] } } -# def parseVids list -# a = params["videolist"].scan(/\S+\r\n/) -# "

#{a}

" - ##CREATE page + post "/sets" do session["sets"] ||= {} a = params["videolist"].scan(/\S+\r\n|\S+/).map! {|a| a.chomp} session["sets"].store(params["setname"], {"name" => params["setname"], "vidnums" => a}) redirect to('/') - - # %{

#{session["sets"]}

} - - #One way to debug is to print variable values to the page - #make sure the last line in this block is the thing you want printed, and comment out anything below - #Uncomment the next line to make some show up on the page - #params.to_s - - #If you don't want to use pry you can comment this out, but it might help! - #Pry will halt the server whenever it hits this line. The terminal tab you have that has the sinatra server running - # => will have an irb-like command prompt in it and you can manipulate params and session and everything from here - # binding.pry - - #parse the youtubelinks params into separate video numbers - from a comma separated string into an array - #set the session stuff for the set to equal the right things - - # "success going to 'post /sets!'" #just for testing, we shouldn't render this in the end but instead render an erb - - redirect to('/') - - #erb :index #we'll want it to redirect to index later (maybe optionally with a status message at the top?) end # Testing purposes only