Skip to content
Browse files

wired up the show featued_link page

  • Loading branch information...
1 parent d16d708 commit 0ddc713c0fe2ba86531857977d3e36561816ece1 @rahulbot rahulbot committed Apr 23, 2012
View
2 app/assets/stylesheets/application.css
@@ -10,4 +10,4 @@
*
*= require_self
*= require_tree .
-*/
+*/
View
8 app/controllers/links_controller.rb
@@ -1,5 +1,13 @@
class LinksController < ApplicationController
+ def feature
+ @link = Link.find(params[:id])
+ @search = Search.find(@link.search_id)
+ @search.featured_link_id = @link.id
+ @search.save
+ redirect_to "/searches/"+@link.search_id.to_s+"/links"
+ end
+
def approve
@link = Link.find(params[:id])
@link.moderation_status = :approved
View
9 app/controllers/searches_controller.rb
@@ -5,10 +5,13 @@ def featured_link
# load the search item
@search = Search.find(params[:id])
# figure out what the featured link is
- @has_featured_link = true #@search.has_featured_link?
- @featured_link = Link.find(5) #Link.find(@search.featured_link_id)
+ @has_featured_link = @search.has_featured_link?
+ @featured_link = Link.find(@search.featured_link_id) if @has_featured_link
# render it without any of the standard templating
- render :layout => "skeletal"
+ respond_to do |format|
+ format.html { render :layout => "skeletal" }
+ format.json { render json: @featured_link}
+ end
end
def links
View
4 app/models/search.rb
@@ -16,6 +16,10 @@ def latest_results
return results
end
+ def has_featured_link?
+ featured_link_id!=nil
+ end
+
def been_run?
self.last_id != nil && self.last_id > 0
end
View
7 app/views/layouts/skeletal.html.erb
@@ -18,6 +18,8 @@
</style>
<%= stylesheet_link_tag "application", :media => "all" %>
+ <%= javascript_include_tag "application" %>
+
<!-- Le fav and touch icons -->
<link href="images/favicon.ico" rel="shortcut icon">
<link href="images/apple-touch-icon.png" rel="apple-touch-icon">
@@ -28,10 +30,5 @@
<%= yield %>
- <!-- Le javascript
- ================================================== -->
- <!-- Placed at the end of the document so the pages load faster -->
- <%= javascript_include_tag "application" %>
-
</body>
</html>
View
30 app/views/searches/featured_link.html.erb
@@ -1,5 +1,29 @@
<h1 id="ll-feature-title"><%=@search.query%></h1>
-<% if @has_featured_link %>
- <iframe id="ll-feature-content" src=<%=@featured_link.url%>>
-<% end %>
+<script type="text/javascript">
+//<![CDATA[
+currentContentUrl = null;
+
+function updateContentUrl(newUrl){
+ if(currentContentUrl!=newUrl){
+ $('#ll-feature-content').attr('src',newUrl);
+ currentContentUrl = newUrl;
+ }
+}
+
+function fetchFeaturedLink(){
+ $.getJSON('/searches/<%=@search.id%>/featured_link.json', function(data) {
+ updateContentUrl(data.url);
+ });
+}
+
+function startPeriodicUpdating(){
+ fetchFeaturedLink();
+ handle = setInterval("fetchFeaturedLink()", 5000);
+}
+
+$(startPeriodicUpdating);
+//]]>
+</script>
+
+<iframe id="ll-feature-content">
View
5 app/views/searches/index.html.erb
@@ -15,8 +15,11 @@
<td><%= link_to search.query, search_path(search) %></td>
<td><%= search.created_at %></td>
<td>
- <%= link_to 'Edit', edit_search_path(search), :class => 'btn btn-mini' %>
<%= link_to 'Update Results', 'searches/'+search.id.to_s+'/update_results', :class => 'btn btn-mini' %>
+ <%= link_to 'See Links', 'searches/'+search.id.to_s+'/links', :class => 'btn btn-mini' %>
+ <%= link_to 'Featured Link', 'searches/'+search.id.to_s+'/featured_link', :class => 'btn btn-mini' %>
+ <br />
+ <%= link_to 'Edit', edit_search_path(search), :class => 'btn btn-mini' %>
<%= link_to 'Destroy', search_path(search), :method => :delete, :confirm => 'Are you sure?', :class => 'btn btn-mini btn-danger' %>
</td>
</tr>
View
9 app/views/searches/links.html.erb
@@ -6,9 +6,14 @@
FEATURED
<% end %>
</div>
- <div class="span6"><%=l.url %></div>
+ <div class="span6"><%=link_to(l.url,l.url) %></div>
<div class="span1"><%=l.frequency %></div>
- <div class="span1"> <a href="/links/<%=l.id%>/approve">Approve</a> <a href="/links/<%=l.id%>/reject">Reject</a> <%=l.moderation_status %></div>
+ <div class="span1">
+ <a href="/links/<%=l.id%>/approve">Approve</a>
+ <a href="/links/<%=l.id%>/reject">Reject</a>
+ <a href="/links/<%=l.id%>/feature">Feature</a>
+ <%=l.moderation_status %>
+ </div>
</div>
<% end %>
View
3 config/routes.rb
@@ -1,6 +1,7 @@
LinkLoader::Application.routes.draw do
match 'links/:id/approve' => 'links#approve'
match 'links/:id/reject' => 'links#reject'
+ match 'links/:id/feature' => 'links#feature'
resources :links
@@ -10,6 +11,8 @@
resources :searches
+ root :to => 'searches#index'
+
# The priority is based upon order of creation:
# first created -> highest priority.

0 comments on commit 0ddc713

Please sign in to comment.
Something went wrong with that request. Please try again.