Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Major search function improvements, new user page, improved reviews, …

…etc.
  • Loading branch information...
commit 2b988ada2de336fd68e8b7a5fe6cf983f1c4594e 1 parent 550a01b
Robert Kuykendall authored
4 app/controllers/items_controller.rb
@@ -10,7 +10,7 @@ class ItemsController < ApplicationController
10 10 # GET /items
11 11 # GET /items.xml
12 12 def index
13   - @items = Item.search(params[:search], params[:page], params[:order])
  13 + @items = Item.search(params)
14 14
15 15 users = User.find(:all, :conditions => [ "login LIKE ?", "%#{params[:search]}%" ] )
16 16 if users.count == 1
@@ -110,7 +110,7 @@ def before_items
110 110 raise ActiveRecord::RecordNotFound if @item == nil
111 111
112 112 if @item.tc_id == 0
113   - @items = Item.search(params[:search], params[:page], params[:order], @item, nil)
  113 + @items = Item.search(params.merge!({:user => @user, :tc => @item}))
114 114 render :action => 'index'
115 115 elsif action_name != 'destroy'
116 116 @version = @item.find_version if @item.find_version
2  app/controllers/tags_controller.rb
@@ -15,7 +15,7 @@ def index
15 15 # GET /tags/1.xml
16 16 def show
17 17 @tag = Tag.find_by_name(params[:id])
18   - @items = @tag.items.search(params[:search], params[:page], params[:order]) if @tag
  18 + @items = @tag.items.search(params) if @tag
19 19
20 20 respond_to do |format|
21 21 format.html { render :template => "items/index" }
17 app/controllers/users_controller.rb
@@ -5,7 +5,7 @@ class UsersController < ApplicationController
5 5 # GET /users
6 6 # GET /users.xml
7 7 def index
8   - @users = User.find(:all, :order => 'admin DESC, login ASC', :conditions => [ 'items_count > 1 OR reviews_count > 1' ])
  8 + @users = User.find(:all, :order => 'admin DESC, login ASC', :conditions => [ 'items_count > 0 OR reviews_count > 1' ])
9 9
10 10 respond_to do |format|
11 11 format.html # index.rhtml
@@ -17,16 +17,23 @@ def index
17 17 # GET /users/1.xml
18 18 def show
19 19 @user = User.find_by_permalink(params[:id])
20   - @items = Item.search(params[:search], params[:page], params[:order], nil, @user)
  20 + raise ActiveRecord::RecordNotFound if @user == nil
  21 +
  22 + @items = Item.search(params.merge!({:user => @user, :per_page => 50}))
  23 + @reviews = Review.find(:all, :order => 'created_at DESC', :conditions => [ 'user_id = ?', @user.id ] )
21 24
22 25 respond_to do |format|
23   - if current_user && current_user.admin == 1
24   - format.html { render :action => "show" }
  26 + if permission(@user)
  27 + format.html { render :action => "manage" }
25 28 else
26   - format.html { render :template => "items/index" }
  29 + format.html { render :action => "show" }
27 30 end
28 31 format.xml { render :xml => @items.to_xml }
29 32 end
  33 +
  34 + rescue ActiveRecord::RecordNotFound
  35 + redirect_back_or_default('/')
  36 + flash[:notice] = "User #{params[:id]} does not exist."
30 37 end
31 38
32 39 # render new.rhtml
18 app/models/item.rb
@@ -75,22 +75,24 @@ def self.order_sql(k, conditions)
75 75 # end
76 76
77 77
78   - def self.search(search = '', page = 1, order = 'new', tc = nil, user = nil)
79   - conditions = [ 'name LIKE ?', "%#{search}%" ]
  78 + def self.search(args = {})
  79 + perpage = args[:per_page] || 10
  80 +
  81 + conditions = [ 'name LIKE ?', "%#{ args[:search] || '' }%" ]
80 82
81   - if(!user)
  83 + if(!args[:user])
82 84 conditions[0] += ' AND versions_count > 0'
83 85 end
84 86
85   - if (tc)
  87 + if (args[:tc])
86 88 conditions[0] += ' AND tc_id = ?'
87   - conditions << tc.id
88   - elsif(user)
  89 + conditions << args[:tc].id
  90 + elsif(args[:user])
89 91 conditions[0] += ' AND user_id = ?'
90   - conditions << user
  92 + conditions << args[:user].id
91 93 end
92 94
93   - paginate :page => page, :order => order_sql(order,conditions), :conditions => conditions
  95 + paginate :page => args[:page], :order => order_sql(args[:order],conditions), :conditions => conditions, :per_page => perpage
94 96 end
95 97
96 98
25 app/views/items/_show.html.erb
... ... @@ -0,0 +1,25 @@
  1 +<% version = show.find_version %>
  2 +<% screenshot = show.rand_screenshot %>
  3 +
  4 +<% if version != nil %>
  5 + <div class="map">
  6 + <%= download_button(version) %>
  7 + <h3><%= link_to clean(show.name), item_path(show) %> <%= clean(version.name) %></h3>
  8 + <h4><%= link_to clean(show.user.login), user_path(show.user) %> on <%= show.version_created_at.to_s(:readable_short) %></h4>
  9 + <div class="indent markdown">
  10 + <%= link_to ( image_tag url_for_file_column(screenshot, "file", "thumb")), item_path(show) if screenshot %>
  11 + <%= format(show.body) %>
  12 +
  13 + <%= content_tag(:h5, "Notes for version "+clean(version.name)+":") if version.body != "" %>
  14 + <%= format(version.body) %>
  15 +
  16 + <h4>
  17 + <%= pluralize(show.downloads.size, 'download') %>,
  18 + <%= pluralize(show.reviews.size, 'review') %>,
  19 + <%= pluralize(show.screenshots.size, 'screenshot') %>,
  20 + <%= "%.1f" % show.ratings_count %> rating
  21 + </h4>
  22 + </div>
  23 + </div>
  24 + <hr />
  25 +<% end %>
39 app/views/items/index.html.erb
@@ -2,43 +2,18 @@
2 2
3 3 <div class="sidebar">
4 4 <%= render :partial => "layouts/sort" %>
  5 + <%= render :partial => "layouts/site" %>
5 6 <hr />
6 7 </div>
7 8
8 9 <div class="content">
9 10
10   - <% if @items != nil and @items.count > 0 %>
11   - <% for item in @items %>
12   - <% version = item.find_version %>
13   - <% screenshot = item.rand_screenshot %>
14   -
15   - <% if version != nil %>
16   - <div class="map">
17   - <%= download_button(version) %>
18   - <h3><%= link_to clean(item.name), item_path(item) %> <%= clean(version.name) %></h3>
19   - <h4><%= link_to clean(item.user.login), user_path(item.user) %> on <%= item.version_created_at.to_s(:readable_short) %></h4>
20   - <div class="indent markdown">
21   - <%= link_to ( image_tag url_for_file_column(screenshot, "file", "thumb")), item_path(item) if screenshot %>
22   - <%= format(item.body) %>
23   -
24   - <%= content_tag(:h5, "Notes for version "+clean(version.name)+":") if version.body != "" %>
25   - <%= format(version.body) %>
26   -
27   - <h4>
28   - <%= pluralize(item.downloads.size, 'download') %>,
29   - <%= pluralize(item.reviews.size, 'review') %>,
30   - <%= pluralize(item.screenshots.size, 'screenshot') %>,
31   - <%= "%.1f" % item.ratings_count %> rating
32   - </h4>
33   - </div>
34   - </div>
35   - <hr />
36   - <% end %>
37   - <% end %>
38   - <% else %>
39   - <p>There are no results to display.</p>
  11 + <% if @items.count == 0 %>
  12 + <p>There are no results to display.</p>
40 13 <% end %>
41 14
  15 + <%= render :partial => 'items/show', :collection => @items %>
  16 +
42 17 <hr />
43 18 </div>
44 19
@@ -49,6 +24,4 @@
49 24
50 25 <hr />
51 26
52   -<%= will_paginate @items, :next_label => 'Next', :previous_label => 'Previous' %>
53   -
54   -<hr />
  27 +<%= will_paginate @items, :next_label => 'Next', :previous_label => 'Previous' %>
2  app/views/items/show.html.erb
@@ -59,5 +59,3 @@
59 59 <hr />
60 60
61 61 </div>
62   -
63   -<hr />
19 app/views/layouts/_site.html.erb
... ... @@ -0,0 +1,19 @@
  1 + <div class="navblock">
  2 + <h2 class="logo">Simplici7y Links</h2>
  3 + <ul>
  4 + <li><%= link_to 'About the project', item_path('simplici7y') %></li>
  5 + <li><%= link_to 'Popular tags', tags_path %></li>
  6 + <li><%= link_to 'Issue tracker', 'https://github.com/rkuykendall/Simplici7y/issues', :target => '_blank' %></li>
  7 + <li>
  8 + <script type="text/javascript" language="javascript">
  9 + <!--
  10 + ML="j\"/k0cK=t?i2.<:7>@b feRmnyld-p%usharoS";
  11 + MI="=RCQSED71GR:J8T>FTBES8C6OI3EHKRJJC=STBES8AS3OI3EHKRJJ<5TG@9POB0E587U:GMJ:5:?IN;4LN;41@UEHKCGECRHCEGR:J=2R@";
  12 + OT="";
  13 + for(j=0;j<MI.length;j++){
  14 + OT+=ML.charAt(MI.charCodeAt(j)-48);
  15 + }document.write(OT);
  16 + // --></script>
  17 + </li>
  18 + </ul>
  19 + </div>
60 app/views/layouts/_sort.html.erb
@@ -13,42 +13,30 @@
13 13 <% url = item_url(params[:id]) %>
14 14 <% end %>
15 15
16   - <h2><% form_tag(url, :method => :get) do %> <%= text_field_tag :search, params[:search], :placeholder => placeholder %> <% end %></h2>
17 16
18   - <%# content_tag(:li, ( link_to "New Submissions", params.merge(:order => :new) ) ) %>
19   - <%# content_tag(:li, ( link_to "Least updated", params.merge(:order => :old) ) ) %>
  17 + <div class="navblock search">
  18 + <h2><% form_tag(url, :method => :get) do %> <%= text_field_tag :search, params[:search], :placeholder => placeholder %> <% end %></h2>
  19 + <%# content_tag(:li, ( link_to "New Submissions", params.merge(:order => :new) ) ) %>
  20 + <%# content_tag(:li, ( link_to "Least updated", params.merge(:order => :old) ) ) %>
  21 + </div>
20 22
21   - <h2>Sort by User Reviews</h2>
22   - <ul>
23   - <%= content_tag(:li, ( link_to "Best Reviewed", params.merge(:order => :best) ) ) %>
24   - <%= content_tag(:li, ( link_to "Most Reviews", params.merge(:order => :loud) ) ) %>
25   - <%= content_tag(:li, ( link_to "Fewest Reviews", params.merge(:order => :quiet) ) ) %>
26   - <%# content_tag(:li, ( link_to "Worst Reviewed", params.merge(:order => :worst) ) ) %>
27   - </ul>
  23 + <div class="navblock">
  24 + <h2>Sort by User Reviews</h2>
  25 + <ul>
  26 + <%= content_tag(:li, ( link_to "Best Reviewed", params.merge(:order => :best) ) ) %>
  27 + <%= content_tag(:li, ( link_to "Most Reviews", params.merge(:order => :loud) ) ) %>
  28 + <%= content_tag(:li, ( link_to "Fewest Reviews", params.merge(:order => :quiet) ) ) %>
  29 + <%# content_tag(:li, ( link_to "Worst Reviewed", params.merge(:order => :worst) ) ) %>
  30 + </ul>
  31 + </div>
28 32
29   - <h2>Sort by Downloads</h2>
30   - <ul>
31   - <%= content_tag(:li, ( link_to "All Time", params.merge(:order => :popular) ) ) %>
32   - <%= content_tag(:li, ( link_to "Last 24 Hours", params.merge(:order => :day) ) ) %>
33   - <%= content_tag(:li, ( link_to "The Past Week", params.merge(:order => :week) ) ) %>
34   - <%= content_tag(:li, ( link_to "The Past Month", params.merge(:order => :month) ) ) %>
35   - <%# content_tag(:li, ( link_to "Fewest Downloads", params.merge(:order => :unpopular) ) ) %>
36   - </ul>
37   -
38   - <h2 class="logo">Simplici7y Links</h2>
39   - <ul>
40   - <li><%= link_to 'About the project', item_path('simplici7y') %></li>
41   - <li><%= link_to 'Popular tags', tags_path %></li>
42   - <li><%= link_to 'Issue tracker', 'https://github.com/rkuykendall/Simplici7y/issues', :target => '_blank' %></li>
43   - <li>
44   - <script type="text/javascript" language="javascript">
45   - <!--
46   - ML="j\"/k0cK=t?i2.<:7>@b feRmnyld-p%usharoS";
47   - MI="=RCQSED71GR:J8T>FTBES8C6OI3EHKRJJC=STBES8AS3OI3EHKRJJ<5TG@9POB0E587U:GMJ:5:?IN;4LN;41@UEHKCGECRHCEGR:J=2R@";
48   - OT="";
49   - for(j=0;j<MI.length;j++){
50   - OT+=ML.charAt(MI.charCodeAt(j)-48);
51   - }document.write(OT);
52   - // --></script>
53   - </li>
54   - </ul>
  33 + <div class="navblock">
  34 + <h2>Sort by Downloads</h2>
  35 + <ul>
  36 + <%= content_tag(:li, ( link_to "All Time", params.merge(:order => :popular) ) ) %>
  37 + <%= content_tag(:li, ( link_to "Last 24 Hours", params.merge(:order => :day) ) ) %>
  38 + <%= content_tag(:li, ( link_to "The Past Week", params.merge(:order => :week) ) ) %>
  39 + <%= content_tag(:li, ( link_to "The Past Month", params.merge(:order => :month) ) ) %>
  40 + <%# content_tag(:li, ( link_to "Fewest Downloads", params.merge(:order => :unpopular) ) ) %>
  41 + </ul>
  42 + </div>
56 app/views/layouts/_tags.html.erb
... ... @@ -1,28 +1,34 @@
1 1
2   - <h2>Gameplay Types</h2>
3   - <ul>
4   - <li><%= link_to 'Every Man for Himself', tag_path('emfh') %></li>
5   - <li><%= link_to 'Solo / Cooperative', tag_path('solocoop') %></li>
6   - <li><%= link_to 'King of the Hill', tag_path('koth') %></li>
7   - <li><%= link_to 'Kill the Man with the Ball', tag_path('ktmwtb') %></li>
8   - <li><%= link_to 'Capture the Flag', tag_path('ctf') %></li>
9   - <li><%= link_to 'Survival', tag_path('survival') %></li>
10   - </ul>
  2 + <div class="navblock">
  3 + <h2>Gameplay Types</h2>
  4 + <ul>
  5 + <li><%= link_to 'Every Man for Himself', tag_path('emfh') %></li>
  6 + <li><%= link_to 'Solo / Cooperative', tag_path('solocoop') %></li>
  7 + <li><%= link_to 'King of the Hill', tag_path('koth') %></li>
  8 + <li><%= link_to 'Kill the Man with the Ball', tag_path('ktmwtb') %></li>
  9 + <li><%= link_to 'Capture the Flag', tag_path('ctf') %></li>
  10 + <li><%= link_to 'Survival', tag_path('survival') %></li>
  11 + </ul>
  12 + </div>
11 13
12   - <h2>File Types</h2>
13   - <ul>
14   - <li><%= link_to 'Map', tag_path('map') %></li>
15   - <li><%= link_to 'Scenario', tag_path('scenario') %></li>
16   - <li><%= link_to 'Plugin', tag_path('plugin') %></li>
17   - <li><%= link_to 'Enhancement', tag_path('enhancement') %></li>
18   - <li><%= link_to 'Script', tag_path('script') %></li>
19   - <li><%= link_to 'Physics', tag_path('physics') %></li>
20   - <li><%= link_to 'Utility', tag_path('utility') %></li>
21   - </ul>
  14 + <div class="navblock">
  15 + <h2>File Types</h2>
  16 + <ul>
  17 + <li><%= link_to 'Map', tag_path('map') %></li>
  18 + <li><%= link_to 'Scenario', tag_path('scenario') %></li>
  19 + <li><%= link_to 'Plugin', tag_path('plugin') %></li>
  20 + <li><%= link_to 'Enhancement', tag_path('enhancement') %></li>
  21 + <li><%= link_to 'Script', tag_path('script') %></li>
  22 + <li><%= link_to 'Physics', tag_path('physics') %></li>
  23 + <li><%= link_to 'Utility', tag_path('utility') %></li>
  24 + </ul>
  25 + </div>
22 26
23   - <h2>Scenarios</h2>
24   - <ul>
25   - <li><%= link_to 'Marathon', item_path('marathon') %></li>
26   - <li><%= link_to 'Marathon: Durandal', item_path('marathon-2-durandal') %></li>
27   - <li><%= link_to 'Marathon: Infinity', item_path('marathon-infinity') %></li>
28   - </ul>
  27 + <div class="navblock">
  28 + <h2>Scenarios</h2>
  29 + <ul>
  30 + <li><%= link_to 'Marathon', item_path('marathon') %></li>
  31 + <li><%= link_to 'Marathon: Durandal', item_path('marathon-2-durandal') %></li>
  32 + <li><%= link_to 'Marathon: Infinity', item_path('marathon-infinity') %></li>
  33 + </ul>
  34 + </div>
10 app/views/layouts/application.rhtml
@@ -41,15 +41,10 @@
41 41 <div id="container">
42 42 <% if flash[:notice] %>
43 43 <div class="notice"><%= flash[:notice] %></div>
44   - <% else %>
45   - <div class="notice">
46   - All maps and reviews submitted July 2nd were lost while updating S7. I am sorry for losing anything you wrote that day.
47   - </div>
48   - <% end %>
49   -
50   - <% if true %>
51 44 <% elsif !logged_in? %>
52 45 <div class="notice">
  46 + Welcome to Simplici7y, file sharing for the
  47 + <a href="http://marathon.sourceforge.net/" target="blank">Aleph One</a> community.
53 48 <%= link_to "Sign up", signup_url %> or
54 49 <%= link_to "log in", login_url %>
55 50 to start adding and reviewing files.
@@ -57,6 +52,7 @@
57 52 <% end %>
58 53
59 54 <%= yield %>
  55 + <hr />
60 56 </div>
61 57
62 58 <div id="footer">
2  app/views/reviews/_show.rhtml
... ... @@ -1,7 +1,7 @@
1 1 <% if show && show.item %>
2 2 <div class="review relevancy-<%= show.relevancy.to_s %>">
3 3 <%= stars(show.rating) %>
4   - <h3><%= clean(show.title) %> <%= '( ' + ( link_to clean(show.item.name), item_path(show.item) ) + ' )' if controller.action_name != 'show' %></h3>
  4 + <h3><%= clean(show.title) %> <%= '<span>' + ( link_to clean(show.item.name), item_path(show.item) ) + '</span>' if controller.action_name != 'show' or controller.controller_name != 'items' %></h3>
5 5 <h4><%= link_to clean(show.user.login), user_path(show.user) %> on <%= show.created_at.to_s(:readable_short) %>, Version <%= clean(show.version.name) %></h4>
6 6
7 7 <% if permission(show) %>
5 app/views/reviews/index.html.erb
@@ -5,8 +5,7 @@
5 5
6 6 <div class="content">
7 7 <%= render :partial => 'show', :collection => @reviews %>
  8 + <hr />
8 9 </div>
9 10
10   -<%= will_paginate @reviews, :next_label => 'Next', :previous_label => 'Previous' %>
11   -
12   -<hr />
  11 +<%= will_paginate @reviews, :next_label => 'Next', :previous_label => 'Previous' %>
4 app/views/screenshots/index.html.erb
@@ -19,6 +19,4 @@
19 19
20 20 <div class="ss_edit">
21 21 <%= link_to 'New screenshot', new_item_screenshot_path(@item), :class => 'button positive add-image' %>
22   -</div>
23   -
24   -<hr />
  22 +</div>
8 app/views/tags/index.html.erb
... ... @@ -1,7 +1,5 @@
1 1 <% for tag in @tags %>
2   -
3   - <span style="font-size: <%= ( tag.popularity.to_i + 60)/2 %>px; line-height: 1em; padding: 5px; display: inline-block;"><%= link_to clean(tag.name), tag_url(tag) %></span>
4   -
  2 + <span style="font-size: <%= ( tag.popularity.to_i + 60)/2 %>px;">
  3 + <%= link_to clean(tag.name), tag_url(tag) %>
  4 + </span>
5 5 <% end %>
6   -
7   -<hr />
47 app/views/users/manage.html.erb
... ... @@ -0,0 +1,47 @@
  1 +<div class="simple">
  2 +
  3 + <h2>Your Uploads</h2>
  4 +
  5 + <% if @items[0] == nil %>
  6 + <p>You can use Simplici7y to share something with the Aleph One community.</p>
  7 + <%= link_to "Add your first item", new_item_url, :class => 'button positive add' %>
  8 + <% else %>
  9 + <p><%= link_to "Add a new item", new_item_url, :class => 'button positive add' %></p>
  10 + <% for item in @items %>
  11 + <% versions = item.versions %>
  12 + <% if versions[0] != nil %>
  13 + <div class="manage_map">
  14 + <table class="manage">
  15 + <tr>
  16 + <th scope="col">Version</th>
  17 + <th scope="col">Downloads</th>
  18 + <th scope="col">Uploaded</th>
  19 + </tr>
  20 + <% for version in versions %>
  21 + <tr class="<%= "newest" if version == item.find_version %>">
  22 + <td width="100px">
  23 + <%= clean(version.name) %>
  24 + </td>
  25 + <td width="100px"><%= version.downloads.size %></td>
  26 + <td width="100px"><%= version.created_at.to_s(:readable_short) %></td>
  27 + </tr>
  28 + <% end %>
  29 + </table>
  30 +
  31 + <h3><%= link_to clean(truncate(item.name, 16)), item_path(item) %></h3>
  32 + <%= pluralize(item.reviews.size, 'review') %><br /> <%= pluralize(item.downloads.size, 'downloads') %>
  33 + <hr />
  34 + </div>
  35 + <% else %>
  36 + <div class="notice">
  37 + <%= clean(truncate(item.name, 16)) %> is missing its first version: <%= link_to 'add version', new_item_version_url(item) %> or <%= link_to "destroy", item_url(item), :class => 'controls', :confirm => "Are you sure?", :method => :delete %>.
  38 + </div>
  39 + <% end %>
  40 + <% end %>
  41 + <% end %>
  42 +
  43 +</div>
  44 +
  45 +<%= will_paginate @items, :next_label => 'Next', :previous_label => 'Previous' %>
  46 +
  47 +<hr />
55 app/views/users/show.html.erb
... ... @@ -1,51 +1,10 @@
1 1 <div class="content">
2   -
3   - <h2>Your Uploads</h2>
4   -
5   - <% if @items[0] == nil %>
6   - <p>You can use Simplici7y to share something with the Aleph One community.</p>
7   - <%= link_to "Add your first item", new_item_url, :class => 'button positive add' %>
8   - <% else %>
9   - <p><%= link_to "Add a new item", new_item_url, :class => 'button positive add' %></p>
10   - <% for item in @items %>
11   - <% versions = item.versions %>
12   - <% if versions[0] != nil %>
13   - <div class="manage_map">
14   - <table class="manage">
15   - <tr>
16   - <th scope="col">Version</th>
17   - <th scope="col">Downloads</th>
18   - <th scope="col">Uploaded</th>
19   - </tr>
20   - <% for version in versions %>
21   - <tr class="<%= "newest" if version == item.find_version %>">
22   - <td width="100px">
23   - <% if version == item.find_version %>
24   - <%= clean(version.name) %></small>
25   - <% else %>
26   - <%= clean(version.name) %>
27   - <% end %>
28   - </td>
29   - <td><%= version.downloads.size %></td>
30   - <td><%= version.created_at.to_s(:readable_short) %></td>
31   - </tr>
32   - <% end %>
33   - </table>
34   -
35   - <h3><%= link_to clean(item.name), item_path(item) %></h3>
36   - <%= pluralize(item.reviews.size, 'review') %><br /> <%= pluralize(item.downloads.size, 'downloads') %>
37   - <hr />
38   - </div>
39   - <% else %>
40   - <div class="notice">
41   - <%= clean(item.name) %> is missing its first revision, <%= link_to 'add one', new_item_version_url(item) %> or <%= link_to "Destroy it", item_url(item), :class => 'controls', :confirm => "Are you sure?", :method => :delete %>.
42   - </div>
43   - <% end %>
44   - <% end %>
45   -
46   - <%= will_paginate @items, :next_label => 'Next', :previous_label => 'Previous' %>
47   - <% end %>
48   -
  2 + <%= render :partial => "layouts/sort" %>
  3 + <hr />
  4 +
  5 + <%= render :partial => 'items/show', :collection => @items %>
49 6 </div>
50 7
51   -<hr />
  8 +<div class="content">
  9 + <%= render :partial => 'reviews/show', :collection => @reviews %>
  10 +</div>
3  db/migrate/20110703232022_add_user_count_caches.rb
@@ -6,6 +6,9 @@ def self.up
6 6 User.reset_column_information
7 7
8 8 User.find(:all).each do |u|
  9 + # This command will fail to write if the column is identified as a counter cache.
  10 + # Remove the counter cache => true from the review model before running.
  11 + # For some reason, items works just fine.
9 12 u.update_attribute :reviews_count, Review.find(:all, :conditions => [ "user_id = ?", u.id ]).length
10 13 u.update_attribute :items_count, Item.find(:all, :conditions => [ "versions_count > 0 AND user_id = ?", u.id ]).length
11 14 end
55 db/migrate/20110704185846_update_ratings_caches.rb
... ... @@ -0,0 +1,55 @@
  1 +class UpdateRatingsCaches < ActiveRecord::Migration
  2 + def self.up
  3 + for item in Item.find(:all)
  4 +
  5 + puts item.name
  6 +
  7 + #--------------------[ Update Rating Relevancy ]--------------------#
  8 +
  9 + reviews = item.reviews.find(:all, :order => 'created_at DESC')
  10 + version = item.versions.reverse[0]
  11 +
  12 + reviews.each_with_index do |review, index|
  13 + # Start at zero
  14 + review.relevancy = 0
  15 +
  16 + # If it's an old version, bump it to 1
  17 + review.relevancy = 1 if review.version_id != version.id
  18 +
  19 + # If there's a newer review, bump it to 3
  20 + (0...index).each do |r|
  21 + reviews[index].relevancy = 2 if reviews[r].user_id == review.user_id
  22 + end
  23 +
  24 + # If it's by the owner, bump it to 2
  25 + review.relevancy = 2 if review.user_id == item.user_id
  26 + end
  27 + reviews.each(&:save!)
  28 +
  29 +
  30 +
  31 + #--------------------[ Update Rating Counts ]--------------------#
  32 +
  33 + total = 0.0
  34 + average = 0.0
  35 + weighted = 0.0
  36 + reviews = item.reviews.find(:all, :conditions => [ 'relevancy < 2' ])
  37 + count = reviews.length.to_f
  38 +
  39 + if count > 0
  40 + for review in reviews
  41 + total += review.rating
  42 + end
  43 +
  44 + average = total / count
  45 + weighted = average + ( average - 2.5 ) * ( count / 10.0 )
  46 + end
  47 +
  48 + item.update_attributes(:ratings_count => average, :ratings_weighted_count => weighted)
  49 +
  50 + end
  51 + end
  52 +
  53 + def self.down
  54 + end
  55 +end
2  db/schema.rb
@@ -9,7 +9,7 @@
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11
12   -ActiveRecord::Schema.define(:version => 20110703232022) do
  12 +ActiveRecord::Schema.define(:version => 20110704185846) do
13 13
14 14 create_table "downloads", :force => true do |t|
15 15 t.integer "user_id"
124 public/stylesheets/application.css
... ... @@ -1,3 +1,4 @@
  1 +
1 2 /* ==============================
2 3 Meyer CSS Reset
3 4 ============================== */
@@ -66,19 +67,21 @@ html, body {
66 67 width: 960px;
67 68 margin: 0 auto;
68 69 }
69   -
70   -.content { /* 480px in the end, half */
71   - width: 460px;
72   - padding-left: 20px;
73   - float: left;
74   -}
75   -
76   -.sidebar { /* 240px in the end, one fourth */
77   - width: 220px;
78   - margin-left: 20px;
79   - float: left;
80   - display: inline; /* floats are handled as block elements, this is to fix
81   - a margin collapsing bug in IE */
  70 + .content { /* 480px in the end, half */
  71 + width: 460px;
  72 + padding-left: 20px;
  73 + float: left;
  74 + }
  75 + .sidebar { /* 240px in the end, one fourth */
  76 + width: 220px;
  77 + margin-left: 20px;
  78 + float: left;
  79 + display: inline; /* floats are handled as block elements, this is to fix
  80 + a margin collapsing bug in IE */
  81 + }
  82 + .simple, form.cmxform { /* Center of the page */
  83 + width: 560px;
  84 + padding: 30px 200px 0 200px;
82 85 }
83 86
84 87 hr {
@@ -400,6 +403,15 @@ div#menu a.username {
400 403 Footer
401 404 ============================== */
402 405
  406 +html {
  407 + background-color: #343434;
  408 +}
  409 +
  410 +body {
  411 + background-color: white;
  412 +}
  413 +
  414 +
403 415 div#footer {
404 416 clear: both;
405 417
@@ -501,25 +513,49 @@ div.notice {
501 513 margin-bottom: 10px;
502 514 }
503 515
504   -.sidebar ul {
  516 +
  517 +/* ==============================
  518 + Navblocks
  519 + ============================== */
  520 +
  521 +.navblock {
  522 + width: 220px;
  523 + margin: 0;
  524 + padding: 0;
  525 +}
  526 +
  527 +.navblock ul {
505 528 margin-bottom: 20px;
506 529 }
507   - .sidebar ul li {
  530 + .navblock ul li {
508 531 list-style: none;
509 532 }
510   - .sidebar ul li a:link,
511   - .sidebar ul li a:visited {
  533 + .navblock ul li a:link,
  534 + .navblock ul li a:visited {
512 535 color: #666;
513 536 }
514   - .sidebar ul li a:hover {
  537 + .navblock ul li a:hover {
515 538 color: #336699;
516 539 }
517   - .sidebar ul li a:active {
  540 + .navblock ul li a:active {
518 541 color: #fff;
519 542 }
520 543
  544 +#container .content .navblock {
  545 + float: left;
  546 +}
  547 +
  548 +#container .content .navblock + hr {
  549 + margin-bottom: 20px;
  550 +}
  551 +
  552 +#container .content .navblock.search,
  553 +#container .content .navblock.search input {
  554 + width: 440px;
  555 +}
  556 +
521 557 #search {
522   - width: 180px;
  558 + width: 195px;
523 559 padding: 2px;
524 560 margin: 0;
525 561 margin-bottom: 15px;
@@ -559,6 +595,10 @@ div.manage_map {
559 595 color: #666;
560 596 }
561 597
  598 +.manage_map hr {
  599 + width: 560px;
  600 +}
  601 +
562 602 div.quote img {
563 603 float: right;
564 604 border: 1px solid black;
@@ -571,11 +611,6 @@ div.quote img {
571 611 CMX Form
572 612 ============================== */
573 613
574   -form.cmxform {
575   - width: 560px;
576   - padding: 30px 200px 0 200px;
577   -}
578   -
579 614 form.cmxform em {
580 615 font-style: normal;
581 616 color: #f00;
@@ -734,6 +769,28 @@ div.review {
734 769 margin-bottom: 30px;
735 770 }
736 771
  772 +h3 span,
  773 +h3 span a {
  774 + color: #ccc;
  775 + text-decoration: none;
  776 +}
  777 +
  778 +
  779 +/* ==============================
  780 + Tags
  781 + ============================== */
  782 +
  783 +body.tags #container span {
  784 + line-height: 1em;
  785 + padding: 5px;
  786 + display: inline-block;
  787 +}
  788 +
  789 +body.tags #container span a {
  790 + text-decoration: none;
  791 +}
  792 +
  793 +
737 794
738 795 /* ==============================
739 796 Users
@@ -751,6 +808,23 @@ div.user {
751 808 float: left;
752 809 }
753 810
  811 +div.user {
  812 + background-image: -webkit-gradient(
  813 + linear,
  814 + left bottom,
  815 + left top,
  816 + color-stop(0.46, rgb(252,252,252)),
  817 + color-stop(0.73, rgb(255,255,255))
  818 + );
  819 + background-image: -moz-linear-gradient(
  820 + center bottom,
  821 + rgb(252,252,252) 46%,
  822 + rgb(255,255,255) 73%
  823 + );
  824 +}
  825 +div.user:hover {
  826 + background-image: none;
  827 +}
754 828
755 829 body.users.index #container a {
756 830 text-decoration: none;

0 comments on commit 2b988ad

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