Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
wired up the show featued_link page
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulbot committed Apr 23, 2012
1 parent d16d708 commit 0ddc713
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.css
Expand Up @@ -10,4 +10,4 @@
* *
*= require_self *= require_self
*= require_tree . *= require_tree .
*/ */
8 changes: 8 additions & 0 deletions app/controllers/links_controller.rb
@@ -1,5 +1,13 @@
class LinksController < ApplicationController 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 def approve
@link = Link.find(params[:id]) @link = Link.find(params[:id])
@link.moderation_status = :approved @link.moderation_status = :approved
Expand Down
9 changes: 6 additions & 3 deletions app/controllers/searches_controller.rb
Expand Up @@ -5,10 +5,13 @@ def featured_link
# load the search item # load the search item
@search = Search.find(params[:id]) @search = Search.find(params[:id])
# figure out what the featured link is # figure out what the featured link is
@has_featured_link = true #@search.has_featured_link? @has_featured_link = @search.has_featured_link?
@featured_link = Link.find(5) #Link.find(@search.featured_link_id) @featured_link = Link.find(@search.featured_link_id) if @has_featured_link
# render it without any of the standard templating # 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 end


def links def links
Expand Down
4 changes: 4 additions & 0 deletions app/models/search.rb
Expand Up @@ -16,6 +16,10 @@ def latest_results
return results return results
end end


def has_featured_link?
featured_link_id!=nil
end

def been_run? def been_run?
self.last_id != nil && self.last_id > 0 self.last_id != nil && self.last_id > 0
end end
Expand Down
7 changes: 2 additions & 5 deletions app/views/layouts/skeletal.html.erb
Expand Up @@ -18,6 +18,8 @@
</style> </style>
<%= stylesheet_link_tag "application", :media => "all" %> <%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>

<!-- Le fav and touch icons --> <!-- Le fav and touch icons -->
<link href="images/favicon.ico" rel="shortcut icon"> <link href="images/favicon.ico" rel="shortcut icon">
<link href="images/apple-touch-icon.png" rel="apple-touch-icon"> <link href="images/apple-touch-icon.png" rel="apple-touch-icon">
Expand All @@ -28,10 +30,5 @@


<%= yield %> <%= yield %>


<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<%= javascript_include_tag "application" %>

</body> </body>
</html> </html>
30 changes: 27 additions & 3 deletions app/views/searches/featured_link.html.erb
@@ -1,5 +1,29 @@
<h1 id="ll-feature-title"><%=@search.query%></h1> <h1 id="ll-feature-title"><%=@search.query%></h1>


<% if @has_featured_link %> <script type="text/javascript">
<iframe id="ll-feature-content" src=<%=@featured_link.url%>> //<![CDATA[
<% end %> 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">
5 changes: 4 additions & 1 deletion app/views/searches/index.html.erb
Expand Up @@ -15,8 +15,11 @@
<td><%= link_to search.query, search_path(search) %></td> <td><%= link_to search.query, search_path(search) %></td>
<td><%= search.created_at %></td> <td><%= search.created_at %></td>
<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 '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' %> <%= link_to 'Destroy', search_path(search), :method => :delete, :confirm => 'Are you sure?', :class => 'btn btn-mini btn-danger' %>
</td> </td>
</tr> </tr>
Expand Down
9 changes: 7 additions & 2 deletions app/views/searches/links.html.erb
Expand Up @@ -6,9 +6,14 @@
FEATURED FEATURED
<% end %> <% end %>
</div> </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"><%=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> </div>
<% end %> <% end %>


3 changes: 3 additions & 0 deletions config/routes.rb
@@ -1,6 +1,7 @@
LinkLoader::Application.routes.draw do LinkLoader::Application.routes.draw do
match 'links/:id/approve' => 'links#approve' match 'links/:id/approve' => 'links#approve'
match 'links/:id/reject' => 'links#reject' match 'links/:id/reject' => 'links#reject'
match 'links/:id/feature' => 'links#feature'


resources :links resources :links


Expand All @@ -10,6 +11,8 @@


resources :searches resources :searches


root :to => 'searches#index'

# The priority is based upon order of creation: # The priority is based upon order of creation:
# first created -> highest priority. # first created -> highest priority.


Expand Down

0 comments on commit 0ddc713

Please sign in to comment.