Skip to content

Commit

Permalink
Added user page with review and item caches. Modified search bar. Add…
Browse files Browse the repository at this point in the history
…ed Gravatar.
  • Loading branch information
rkuykendall committed Jul 4, 2011
1 parent dffc88c commit 550a01b
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 75 deletions.
5 changes: 5 additions & 0 deletions app/controllers/items_controller.rb
Expand Up @@ -12,6 +12,11 @@ class ItemsController < ApplicationController
def index
@items = Item.search(params[:search], params[:page], params[:order])

users = User.find(:all, :conditions => [ "login LIKE ?", "%#{params[:search]}%" ] )
if users.count == 1
flash[:notice] = "Were you looking for <a href='#{user_path(users.first.permalink)}'>#{users.first.login}</a>?"
end

respond_to do |format|
format.html # index.html.erb
format.rss { render :action => 'index.xml.builder' }
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/users_controller.rb
Expand Up @@ -5,11 +5,11 @@ class UsersController < ApplicationController
# GET /users
# GET /users.xml
def index
@items = Item.search(params[:search], params[:page], params[:order], nil, current_user)
@users = User.find(:all, :order => 'admin DESC, login ASC', :conditions => [ 'items_count > 1 OR reviews_count > 1' ])

respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @items.to_xml }
format.xml { render :xml => @users.to_xml }
end
end

Expand All @@ -21,7 +21,7 @@ def show

respond_to do |format|
if current_user && current_user.admin == 1
format.html { render :action => "index" }
format.html { render :action => "show" }
else
format.html { render :template => "items/index" }
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/item.rb
Expand Up @@ -7,7 +7,7 @@ class Item < ActiveRecord::Base
has_many :downloads, :dependent => :destroy
has_many :reviews

belongs_to :user
belongs_to :user, :counter_cache => true

validates_presence_of :name, :body, :user_id
validates_format_of :name, :with => /\A[^<>]+\Z/i, :message => "can not contain brackets."
Expand Down
2 changes: 1 addition & 1 deletion app/models/review.rb
@@ -1,7 +1,7 @@
class Review < ActiveRecord::Base
belongs_to :item, :counter_cache => true
belongs_to :version
belongs_to :user
belongs_to :user, :counter_cache => true

validates_presence_of :title, :rating, :body, :item_id, :version_id, :user_id
validates_format_of :title, :with => /\A[^<>]*\Z/i, :message => "can not contain brackets."
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
@@ -1,12 +1,16 @@
require 'digest/sha1'
class User < ActiveRecord::Base
include Gravtastic
is_gravtastic :email

# Virtual attribute for the unencrypted password
attr_accessor :password
# title is the field name you want to convert to a permalink
has_permalink :login
# you can also specifiy a different permalink field in your database by giving a second paramater
# has_permalink :title, :my_permalink_field


# we now add the to_param method which Rails's routing uses
def to_param
permalink
Expand Down
22 changes: 13 additions & 9 deletions app/views/items/_form.html.erb
@@ -1,12 +1,16 @@
<fieldset>
<legend>Basic Information</legend>
<legend>Item Information</legend>

<div class="form_sidenote">
Items on Simplici7y consist of basic information, and version-specific information. Basic information shouldn't change with each new version. Put information about your changes in the version release notes.
</div>
<div class="form_sidenote">
<u>Suggested tags</u><br />(separate with spaces)</small><br />
<b>File Types:</b> map script utility film<br />
<b>Gameplay:</b> emfh koth ktmwtb emfhs solocoop</a><br />
<p>You can use Simplici7y to share something with the Aleph One community.</p>

<p>Items on Simplici7y consist of <strong>item information</strong>, and <strong>version information</strong>.</p>

<p><strong>Item information</strong> shouldn't change with each new version. Put information about your changes in the version release notes on the next page.</p>

<p>You can tag your item with
<strong>file types</strong> like map, scenario, plugin, enhancement, script, physics and utility, or
<strong>gameplay types</strong> like emfh, solocoop, koth, ktmwtb, ctf and survival to help people find it.</p>
</div>

<ol>
Expand All @@ -19,11 +23,11 @@
<%= f.collection_select(:tc_id, Tag.find_by_name('scenario').items, :id, :name, { :include_blank => true }) if Tag.find_by_name('scenario') %>
</li>
<li>
<label for="tags">Tags</label>
<label for="tags">Tags <small>separate with spaces</small></label>
<%= text_field_tag 'tags', @item.tag_list %>
</li>
<li>
<label for="item_body">Body <em>*</em> <small><a href="http://daringfireball.net/projects/markdown/basics">advanced formatting</a></small></label>
<label for="item_body">Body <em>*</em> <small><a href="http://daringfireball.net/projects/markdown/basics" target="_blank">advanced formatting</a></small></label>
<%= f.text_area :body, :class => 'summary' %>
</li>
</ol>
Expand Down
8 changes: 5 additions & 3 deletions app/views/items/index.html.erb
@@ -1,11 +1,13 @@


<div class="sidebar">
<%= render :partial => "layouts/sort" %>
<hr />
</div>

<div class="content">
<div class="content">

<% if @items != nil %>
<% if @items != nil and @items.count > 0 %>
<% for item in @items %>
<% version = item.find_version %>
<% screenshot = item.rand_screenshot %>
Expand Down Expand Up @@ -34,7 +36,7 @@
<% end %>
<% end %>
<% else %>
<p>Nothing to see here, move along...</p>
<p>There are no results to display.</p>
<% end %>

<hr />
Expand Down
7 changes: 2 additions & 5 deletions app/views/layouts/_sort.html.erb
Expand Up @@ -13,13 +13,10 @@
<% url = item_url(params[:id]) %>
<% end %>

<h2>Search &amp; Sorting</h2>
<h2><% form_tag(url, :method => :get) do %> <%= text_field_tag :search, params[:search], :placeholder => placeholder %> <% end %></h2>

<ul>
<%= content_tag(:li, ( link_to "New Submissions", params.merge(:order => :new) ) ) %>
<li><% form_tag(url, :method => :get) do %> <%= text_field_tag :search, params[:search], :placeholder => placeholder %> <% end %></li>
<%# content_tag(:li, ( link_to "New Submissions", params.merge(:order => :new) ) ) %>
<%# content_tag(:li, ( link_to "Least updated", params.merge(:order => :old) ) ) %>
</ul>

<h2>Sort by User Reviews</h2>
<ul>
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/application.rhtml
Expand Up @@ -13,16 +13,16 @@
<link rel="icon" type="image/png" href="/images/favicon.png"/>
</head>

<body>
<body class="<%= controller.controller_name + ' ' + controller.action_name %>">
<div id="menu">
<ul id="navigation">
<li><a href="/" class="logo">Simplici<span>7</span>y</a></li>
<li><%= link_to('Downloads', items_path); %></li>
<li><%= link_to('Reviews', reviews_path) %></li>
<li><%= link_to "Users", users_path %></li>

<% if logged_in? %>
<li><%= link_to clean(current_user.login), user_path(current_user), :class => 'username' %></li>
<li><%= link_to "Uploads", users_path, :class => 'control' %></li>
<li><%= link_to "Submit", new_item_path, :class => 'control' %></li>
<li><%= link_to "Settings", edit_user_path(current_user), :class => 'control' %></li>
<li><%= link_to "Log out", logout_path, :class => 'control' %></li>
Expand Down
56 changes: 8 additions & 48 deletions app/views/users/index.html.erb
@@ -1,51 +1,11 @@
<div class="content">
<h2>Your Uploads</h2>

<% if @items[0] == nil %>
<p>You can use Simplici7y to share something with the Aleph One community.</p>
<%= link_to "Add your first item", new_item_url, :class => 'button positive add' %>
<% else %>
<p><%= link_to "Add a new item", new_item_url, :class => 'button positive add' %></p>
<% for item in @items %>
<% versions = item.versions %>
<% if versions[0] != nil %>
<div class="manage_map">
<table class="manage">
<tr>
<th scope="col">Version</th>
<th scope="col">Downloads</th>
<th scope="col">Uploaded</th>
</tr>
<% for version in versions %>
<tr class="<%= "newest" if version == item.find_version %>">
<td width="100px">
<% if version == item.find_version %>
<%= clean(version.name) %></small>
<% else %>
<%= clean(version.name) %>
<% end %>
</td>
<td><%= version.downloads.size %></td>
<td><%= version.created_at.to_s(:readable_short) %></td>
</tr>
<% end %>
</table>

<h3><%= link_to clean(item.name), item_path(item) %></h3>
<%= pluralize(item.reviews.size, 'review') %>, <%= pluralize(item.downloads.size, 'downloads') %>
<hr />
</div>
<% else %>
<div class="notice">
<%= 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 %>.
</div>
<% end %>
<% end %>
<%= will_paginate @items, :next_label => 'Next', :previous_label => 'Previous' %>
<% end %>

</div>
<% for user in @users %>
<a href="<%= user_path(user.permalink) %>">
<div class="user">
<%= content_tag :h3, truncate(user.login, 15, "...") %>
<%= content_tag :h4, ( pluralize(user.items_count, 'item') + ', ' + pluralize(user.reviews_count, 'review') ) %>
</div>
</a>
<% end %>

<hr />
51 changes: 51 additions & 0 deletions app/views/users/show.html.erb
@@ -0,0 +1,51 @@
<div class="content">

<h2>Your Uploads</h2>

<% if @items[0] == nil %>
<p>You can use Simplici7y to share something with the Aleph One community.</p>
<%= link_to "Add your first item", new_item_url, :class => 'button positive add' %>
<% else %>
<p><%= link_to "Add a new item", new_item_url, :class => 'button positive add' %></p>
<% for item in @items %>
<% versions = item.versions %>
<% if versions[0] != nil %>
<div class="manage_map">
<table class="manage">
<tr>
<th scope="col">Version</th>
<th scope="col">Downloads</th>
<th scope="col">Uploaded</th>
</tr>
<% for version in versions %>
<tr class="<%= "newest" if version == item.find_version %>">
<td width="100px">
<% if version == item.find_version %>
<%= clean(version.name) %></small>
<% else %>
<%= clean(version.name) %>
<% end %>
</td>
<td><%= version.downloads.size %></td>
<td><%= version.created_at.to_s(:readable_short) %></td>
</tr>
<% end %>
</table>

<h3><%= link_to clean(item.name), item_path(item) %></h3>
<%= pluralize(item.reviews.size, 'review') %><br /> <%= pluralize(item.downloads.size, 'downloads') %>
<hr />
</div>
<% else %>
<div class="notice">
<%= 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 %>.
</div>
<% end %>
<% end %>
<%= will_paginate @items, :next_label => 'Next', :previous_label => 'Previous' %>
<% end %>

</div>

<hr />
2 changes: 1 addition & 1 deletion app/views/versions/_form.html.erb
@@ -1,5 +1,5 @@
<fieldset>
<legend>Version information</legend>
<legend>Version Information</legend>
<div class="form_sidenote">
Aleph One's <i>.SceA</i> format is twenty times smaller when zipped.
</div>
Expand Down
3 changes: 3 additions & 0 deletions config/environment.rb
Expand Up @@ -83,6 +83,9 @@
gem 'sanitize', '~> 2.0.1'
require 'sanitize'

gem 'gravtastic'
require 'gravtastic'


ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:readable_long => lambda { |time| time.strftime("%A the #{time.day.ordinalize} of %B, %Y") },
Expand Down
18 changes: 18 additions & 0 deletions db/migrate/20110703232022_add_user_count_caches.rb
@@ -0,0 +1,18 @@
class AddUserCountCaches < ActiveRecord::Migration
def self.up
add_column :users, :items_count, :integer, :default => 0
add_column :users, :reviews_count, :integer, :default => 0

User.reset_column_information

User.find(:all).each do |u|
u.update_attribute :reviews_count, Review.find(:all, :conditions => [ "user_id = ?", u.id ]).length
u.update_attribute :items_count, Item.find(:all, :conditions => [ "versions_count > 0 AND user_id = ?", u.id ]).length
end
end

def self.down
remove_column :users, :items_count
remove_column :users, :reviews_count
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110626215610) do
ActiveRecord::Schema.define(:version => 20110703232022) do

create_table "downloads", :force => true do |t|
t.integer "user_id"
Expand Down Expand Up @@ -85,6 +85,8 @@
t.datetime "remember_token_expires_at"
t.string "permalink"
t.integer "admin", :default => 0, :null => false
t.integer "items_count", :default => 0
t.integer "reviews_count", :default => 0
end

create_table "versions", :force => true do |t|
Expand Down
24 changes: 23 additions & 1 deletion public/stylesheets/application.css
Expand Up @@ -519,9 +519,10 @@ div.notice {
}

#search {
width: 120px;
width: 180px;
padding: 2px;
margin: 0;
margin-bottom: 15px;

font-size: inherit;
border: solid 1px #ddd;
Expand Down Expand Up @@ -734,6 +735,27 @@ div.review {
}


/* ==============================
Users
============================== */

div.user {
width: 160px;
padding: 10px;
margin: 5px;
border-top: 1px solid #eee;
border-left: 1px solid #ddd;
border-right: 1px solid #ccc;
border-bottom: 1px solid #bbb;
overflow: hidden;
float: left;
}


body.users.index #container a {
text-decoration: none;
}


/* ==============================
Screenshots
Expand Down

0 comments on commit 550a01b

Please sign in to comment.