From 28d179708fe91737a0221fdad290adf5eb79e889 Mon Sep 17 00:00:00 2001 From: albert Date: Sat, 25 Jun 2011 16:33:30 -0400 Subject: [PATCH] changes --- app/controllers/artists_controller.rb | 2 +- app/controllers/comments_controller.rb | 4 +- app/controllers/notes_controller.rb | 4 +- app/controllers/tag_aliases_controller.rb | 2 +- .../tag_implications_controller.rb | 2 +- app/controllers/tags_controller.rb | 2 +- app/controllers/users_controller.rb | 2 +- app/helpers/application_helper.rb | 9 ++- app/models/post.rb | 2 + app/models/user.rb | 17 ++++- app/views/comments/index_by_comment.html.erb | 2 +- app/views/comments/index_by_post.html.erb | 6 +- app/views/post_sets/_blank.html.erb | 2 +- app/views/tag_aliases/index.html.erb | 4 +- app/views/tag_implications/index.html.erb | 4 +- app/views/tags/index.html.erb | 6 +- app/views/users/index.html.erb | 64 +++++++++++++++++++ app/views/users/new.html.erb | 2 +- 18 files changed, 113 insertions(+), 23 deletions(-) diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index 5a465dbee..c12590cb4 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -14,7 +14,7 @@ class ArtistsController < ApplicationController def index @search = Artist.search(params[:search]) - @artists = @search.paginate(:page => params[:page]) + @artists = @search.paginate(params[:page]) respond_with(@artists) end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 0e1bfb2f4..ccc79f869 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -39,7 +39,7 @@ class CommentsController < ApplicationController private def index_by_post - @posts = Post.tag_match(params[:tags]).commented_before(params[:before_date] || Time.now).limit(8) + @posts = Post.commented_before(Time.now).tag_match(params[:tags]).paginate(params[:page]) respond_with(@posts) do |format| format.html {render :action => "index_by_post"} end @@ -47,7 +47,7 @@ private def index_by_comment @search = Comment.search(params[:search]) - @comments = @search.paginate(:page => params[:page]) + @comments = @search.paginate(params[:page]) respond_with(@comments) do |format| format.html {render :action => "index_by_comment"} end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 561b97377..ded7f8c31 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -52,7 +52,7 @@ private end def index_by_post - @posts = Post.tag_match(params[:tags]).noted_before(params[:before_date] || Time.now).limit(8) + @posts = Post.tag_match(params[:tags]).noted_before(params[:before_date] || Time.now).paginate(params[:page]) respond_with(@posts) do |format| format.html {render :action => "index_by_post"} end @@ -60,7 +60,7 @@ private def index_by_note @search = Note.search(params[:search]) - @notes = @search.paginate(:page => params[:page]) + @notes = @search.paginate(params[:page]) respond_with(@notes) do |format| format.html {render :action => "index_by_note"} end diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index d1823c5f6..61f4a03d5 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -9,7 +9,7 @@ class TagAliasesController < ApplicationController def index @search = TagAlias.search(params[:search]) - @tag_aliases = @search.paginate(:page => params[:page]) + @tag_aliases = @search.paginate(params[:page]) respond_with(@tag_aliases) end diff --git a/app/controllers/tag_implications_controller.rb b/app/controllers/tag_implications_controller.rb index 67e5cdbe4..91ace2f76 100644 --- a/app/controllers/tag_implications_controller.rb +++ b/app/controllers/tag_implications_controller.rb @@ -9,7 +9,7 @@ class TagImplicationsController < ApplicationController def index @search = TagImplication.search(params[:search]) - @tag_implications = @search.paginate(:page => params[:page]) + @tag_implications = @search.paginate(params[:page]) respond_with(@tag_implicationes) end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 2a14c5079..215baba8f 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -9,7 +9,7 @@ class TagsController < ApplicationController def index @search = Tag.search(params[:search]) - @tags = @search.paginate(:page => params[:page]) + @tags = @search.paginate(params[:page]) respond_with(@tags) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 11650f23d..c7a319709 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -16,7 +16,7 @@ class UsersController < ApplicationController def index @search = User.search(params[:search]) - @users = @search.paginate(:page => params[:page]) + @users = @search.paginate(params[:page]) respond_with(@users) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 538516ea3..c2a5e2c7c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -35,12 +35,11 @@ module ApplicationHelper protected def nav_link_match(controller, url) + puts "controller=#{controller} url=#{url}" + url =~ case controller - when "tag_aliases", "tag_implications" - /^\/tags/ - - when "sessions", "user_maintenance" - /^\/users/ + when "sessions", "users" + /^\/(session|users)/ when "forum_posts" /^\/forum_topics/ diff --git a/app/models/post.rb b/app/models/post.rb index 32bf8ec8e..97a929a63 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -40,6 +40,8 @@ class Post < ActiveRecord::Base scope :available_for_moderation, lambda {where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])} scope :hidden_from_moderation, lambda {where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])} scope :tag_match, lambda {|query| Post.tag_match_helper(query)} + scope :positive, where("score > 1") + scope :negative, where("score < -1") search_methods :tag_match scope :after_id, Proc.new {|num| if num.present? diff --git a/app/models/user.rb b/app/models/user.rb index 948edc408..f5bd18e4e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,7 +7,7 @@ class User < ActiveRecord::Base attr_accessor :password, :old_password attr_accessible :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr validates_length_of :name, :within => 2..20, :on => :create - validates_format_of :name, :with => /\A[^\s;,]+\Z/, :on => :create, :message => "cannot have whitespace, commas, or semicolons" + validates_format_of :name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons" validates_uniqueness_of :name, :case_sensitive => false, :on => :create validates_uniqueness_of :email, :case_sensitive => false, :on => :create, :if => lambda {|rec| !rec.email.blank?} validates_length_of :password, :minimum => 5, :if => lambda {|rec| rec.new_record? || !rec.password.blank?} @@ -22,6 +22,7 @@ class User < ActiveRecord::Base has_many :feedback, :class_name => "UserFeedback", :dependent => :destroy has_one :ban has_many :subscriptions, :class_name => "TagSubscription" + has_many :note_versions, :foreign_key => "updater_id" belongs_to :inviter, :class_name => "User" scope :named, lambda {|name| where(["lower(name) = ?", name])} scope :admins, where("is_admin = TRUE") @@ -143,6 +144,13 @@ class User < ActiveRecord::Base end end + def level_string + if is_admin? + "Admin" + elsif is_moderator? + "Moderator" + end + def normalize_level if is_admin? self.is_moderator = true @@ -254,6 +262,12 @@ class User < ActiveRecord::Base end end + module PostMethods + def posts + Post.where("uploader_string = ?", "uploader:#{id}") + end + end + include BanMethods include NameMethods include PasswordMethods @@ -264,6 +278,7 @@ class User < ActiveRecord::Base include BlacklistMethods include ForumMethods include LimitMethods + include PostMethods def initialize_default_image_size self.default_image_size = "Medium" diff --git a/app/views/comments/index_by_comment.html.erb b/app/views/comments/index_by_comment.html.erb index fce4fb6dc..8033b96c9 100644 --- a/app/views/comments/index_by_comment.html.erb +++ b/app/views/comments/index_by_comment.html.erb @@ -8,7 +8,7 @@ -
+
<%= sequential_paginator(@comments) %>
diff --git a/app/views/comments/index_by_post.html.erb b/app/views/comments/index_by_post.html.erb index b067a8d83..93c28bcfb 100644 --- a/app/views/comments/index_by_post.html.erb +++ b/app/views/comments/index_by_post.html.erb @@ -1,5 +1,9 @@
+ <% if @posts.empty? %> + <%= render "post_sets/blank" %> + <% end %> + <% @posts.each do |post| %>
@@ -10,7 +14,7 @@
<% end %> -
+
<%= sequential_paginator(@posts) %>
diff --git a/app/views/post_sets/_blank.html.erb b/app/views/post_sets/_blank.html.erb index 460517bfc..56eb23be4 100644 --- a/app/views/post_sets/_blank.html.erb +++ b/app/views/post_sets/_blank.html.erb @@ -1,3 +1,3 @@

Nobody here but us chickens!

-

<%= link_to "Go back", :back %>.

\ No newline at end of file +

<%= link_to "Go back", :back %>

\ No newline at end of file diff --git a/app/views/tag_aliases/index.html.erb b/app/views/tag_aliases/index.html.erb index 52220f4e0..b7c554541 100644 --- a/app/views/tag_aliases/index.html.erb +++ b/app/views/tag_aliases/index.html.erb @@ -36,7 +36,9 @@
- <%= will_paginate(@aliases) %> + <%= numbered_paginator(@tag_aliases) do |page| %> + <%= link_to(page, tag_aliases_path(:page => page)) %> + <% end %>
<%= render "secondary_links" %> diff --git a/app/views/tag_implications/index.html.erb b/app/views/tag_implications/index.html.erb index 8d38e1642..466ef2f89 100644 --- a/app/views/tag_implications/index.html.erb +++ b/app/views/tag_implications/index.html.erb @@ -36,7 +36,9 @@
- <%= will_paginate(@implications) %> + <%= numbered_paginator(@tag_implications) do |page| %> + <%= link_to(page, tag_impliactions_path(:page => page)) %> + <% end %>
<%= render "secondary_links" %> diff --git a/app/views/tags/index.html.erb b/app/views/tags/index.html.erb index a2842c0ac..314faf9f0 100644 --- a/app/views/tags/index.html.erb +++ b/app/views/tags/index.html.erb @@ -18,8 +18,10 @@ -
- <%= will_paginate(@tags) %> +
+ <%= numbered_paginator(@tags) do |page| %> + <%= link_to(page, tags_path(:page => page)) %> + <% end %>
<%= render "secondary_links" %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index e69de29bb..ca52af5c3 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -0,0 +1,64 @@ +
+
+

Users

+ + <% simple_form_for(@search) do |f| %> + <%= f.input :name_contains, :label => "Name" %> + <%= f.input :is_banned_is_true, :label => "Banned" %> + <%= f.input :is_privileged_is_true, :label => "Privileged" %> + <%= f.input :is_contributor_is_true, :label => "Contributor" %> + <%= f.input :is_janitor_is_true, :label => "Janitor" %> + <%= f.input :is_moderator_is_true, :label => "Moderator" %> + <%= f.input :is_admin_is_true, :label => "Admin" %> + <%= f.sort_link "Name", :name %> + <%= f.sort_link "Date", :created_at_desc %> + <%= f.button :submit %> + <% end %> + + + + + + + + + + + + + + + + <% @users.each do |user| %> + + + + + <% if user.posts.count > 100 %> + + + <% else %> + + + <% end %> + + + + + <% end %> + +
NamePostsDeleted% Pos% NegNotesLevelJoined
+ <%= link_to user.pretty_name, user_path(user.id) %> + <% if user.inviter %> + ← <%= link_to user.inviter.name, user_path(user.inviter_id) %> + <% end %> + <%= link_to user.posts.count, posts_path(:tags => "uploader:#{user.name}") %><%= user.posts.deleted.count %><%= number_to_percentage(100 * user.posts.positive.count.to_f / user.posts.count, :precision => 0) %><%= number_to_percentage(100 * user.posts.negative.count.to_f / user.posts.count, :precision => 0) %><%= link_to user.note_versions.count, note_versions_path(:search => {:updater_id_eq => user.id}) %><%= user.pretty_level %><%= time_ago_in_words user.created_at %> ago
+ +
+ <%= will_paginate(@users) %> +
+ + <%= render :partial => "footer" %> +
+
+ diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index b664e83d9..0b46b418d 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -52,7 +52,7 @@

There are some restrictions on names:

    -
  • Name: Your name must be at least 2 characters and at most 20 characters long. It cannot contain spaces, commas, colons, or semi-colons. All characters must be US-ASCII.
  • +
  • Name: Your name must be at least 2 characters and at most 20 characters long. It cannot contain spaces or colons. All characters must be US-ASCII.
  • Password: Your password must be at least 5 characters long.
  • Email: