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

Better youtube sets #28

Open
wants to merge 3 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
6 changes: 4 additions & 2 deletions assignments/sinatraapp/Peter_Nguyen/views/edit.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<form action="/sets/<%= @setname %>" method="post">
<input type="hidden" name="_method" value="put">
<label>Set Name</label>
<input type="text" disabled name="setname" value="<%= 'samplevalue' #an @variable goes here instead of a string %>">
<input type="text" disabled name="setname" value="<%=@setname%>">
<label>List of Videos</label>
<textarea name="videolist"><%= 'samplevalue' #an @variable goes here instead of a string %></textarea>
<textarea name="videolist">
<%[email protected]("\n")%>
</textarea>
<input type="submit">
</form>
4 changes: 4 additions & 0 deletions assignments/sinatraapp/Peter_Nguyen/views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
<%session["sets"].each_value do |set| %>
<h2>Set name: <%=set["name"]%></h2>
<h3>vids:</h3>
<a>| </a>
<%set["vidnums"].each do |vid| %>
<a><%=vid%> |</a>
<%end%>
<a href="/sets/<%=set["name"]%>">Show</a>
<a href="/sets/<%=set["name"]%>/edit">Edit</a>
<a href="/sets/<%=set["name"]%>/play">Play</a>
<%end%>
6 changes: 4 additions & 2 deletions assignments/sinatraapp/Peter_Nguyen/views/show.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<a href="/">Home</a>
<h1>Show a Set</h1>
<h3>Setname</h3>
<p><%= "setname variable goes here" %></p>
<p><%= @setname %></p>
<h3>Set of videos:</h3>
<p><%= "videoname variable goes here" %></p>
<p><%= session["sets"][@setname]["vidnums"] %></p>

<form action="/sets/<%= @setname %>" method="post">
<input name="_method" type="hidden" value="delete" />
<input type="submit" value="Delete">
</form>

56 changes: 22 additions & 34 deletions assignments/sinatraapp/Peter_Nguyen/youtubesets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,85 +34,73 @@

# "sets" => { "SETNAME" => { "name" => "SETNAME", "vidnums" => ["VID1", "VID2", "VID3"] } }

# def parseVids list
# a = params["videolist"].scan(/\S+\r\n/)
# "<p>#{a}</p>"

##CREATE page

post "/sets" do
a = params["videolist"].scan(/\S+\r\n/).map! {|a| a.chomp}
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('/')

# %{<p>#{session["sets"]}</p>}

#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
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.
end

##UPDATE page
put "/sets/:setname" 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})
#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
Expand Down