work on post views

This commit is contained in:
albert
2010-03-12 12:32:31 -05:00
parent 15c134b270
commit 9f29ffc8c3
18 changed files with 486 additions and 317 deletions

View File

@@ -1,6 +1,4 @@
class SessionsController < ApplicationController
before_filter :member_only, :only => [:destroy]
def new
@user = User.new
end
@@ -9,14 +7,14 @@ class SessionsController < ApplicationController
if User.authenticate(params[:name], params[:password])
@user = User.find_by_name(params[:name])
session[:user_id] = @user.id
redirect_to(params[:url] || posts_path, :notice => "You have logged in")
redirect_to(params[:url] || posts_path, :notice => "You are now logged in.")
else
render :action => "edit", :flash => "Password was incorrect"
redirect_to(new_session_path, :notice => "Password was incorrect.")
end
end
def destroy
session[:user_id] = nil
redirect_to(posts_path, :notice => "You have logged out")
session.delete(:user_id)
redirect_to(posts_path, :notice => "You are now logged out.")
end
end

View File

@@ -96,6 +96,10 @@ class AnonymousUser
false
end
def blacklisted_tags
""
end
%w(banned privileged contributor janitor moderator admin).each do |name, value|
normalized_name = name.downcase.gsub(/ /, "_")

View File

@@ -102,4 +102,8 @@ class PostSet
def to_json
posts.to_json
end
def presenter
@presnter ||= PostSetPresenter.new(self)
end
end

View File

@@ -3,13 +3,13 @@ require 'digest/sha1'
class User < ActiveRecord::Base
class Error < Exception ; end
attr_accessor :password
attr_accessible :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
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
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_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}
validates_length_of :password, :minimum => 5, :if => lambda {|rec| rec.new_record? || !rec.password.blank?}
validates_inclusion_of :default_image_size, :in => %w(medium large original)
validates_confirmation_of :password
validates_presence_of :email, :if => lambda {|rec| rec.new_record? && Danbooru.config.enable_email_verification?}
@@ -176,6 +176,10 @@ class User < ActiveRecord::Base
include EmailVerificationMethods
include BlacklistMethods
include ForumMethods
def initialize_default_image_size
self.default_image_size = "Medium"
end
def can_update?(object, foreign_key = :user_id)
is_moderator? || is_admin? || object.__send__(foreign_key) == id

View File

@@ -0,0 +1,36 @@
class PostSetPresenter
attr_accessor :post_set
def initialize(post_set)
@post_set = post_set
end
def posts
post_set.posts
end
def tag_list_html
""
end
def wiki_html
""
end
def pagination_html
end
def post_previews_html
html = ""
posts.each do |post|
html << %{<article id="post_#{post.id}" data-id="#{post.id}" data-tags="#{h(post.tag_string)}" data-uploader="#{h(post.uploader_name)}" data-rating="#{post.rating}" data-width="#{post.image_width}" data-height="#{post.image_height}">}
html << %{<a href="/posts/#{post.id}">}
html << %{<img src="#{post.preview_url}>"}
html << %{</a>}
html << %{</article>}
end
html
end
end

View File

@@ -4,16 +4,21 @@
<title><%= yield(:page_title) || Danbooru.config.app_name %></title>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="top" title="<%= Danbooru.config.app_name %>" href="/">
<%= csrf_meta_tag %>
<% unless @current_user.blacklisted_tags.blank? %>
<meta name="blacklisted-tags" content="<%= h @current_user.blacklisted_tags %>">
<% end %>
<%= auto_discovery_link_tag :atom, posts_path(:format => "atom", :tags => params[:tags]) %>
<%= stylesheet_link_tag "default" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" %>
<%= javascript_include_tag "rails" %>
<%= Danbooru.config.custom_html_header_content %>
<%= yield :html_header_content %>
</head>
<body>
<nav>
<h1><%= link_to(Danbooru.config.app_name, "/") %><%= yield :page_header %></h1>
<ul>
<menu>
<% if @current_user.is_anonymous? %>
<%= nav_link_to("Login", new_session_path) %>
<% else %>
@@ -28,7 +33,7 @@
<%= nav_link_to("Wiki", wiki_page_path(:id => "help:home")) %>
<%= nav_link_to("Forum", forum_topics_path, :class => (@current_user.has_forum_been_updated? ? "forum-updated" : nil)) %>
<%= nav_link_to("&raquo;".html_safe, site_map_path) %>
</ul>
</menu>
<%= yield :secondary_nav_links %>
</nav>
@@ -61,9 +66,9 @@
</div>
<% end %>
<section id="content">
<div id="content">
<%= yield :layout %>
</section>
</div>
<%= yield :page_footer_content %>
</body>

View File

@@ -0,0 +1,97 @@
<% unless @post_set.suggestions.blank? %>
<div class="notice">
Maybe you meant: <%= @post_set.suggestions.map {|x| link_to(x, posts_path(:tags => x), :class => "tag-type-#{Tag.type_name(x)}" )}.to_sentence(:last_word_connector => ", or ", :two_words_connector => " or ") %>
</div>
<% end %>
<aside>
<section id="search-box">
<h1>Search</h1>
<% form_tag(posts_path, :method => "get") do %>
<%= text_field_tag("tags", params[:tags], :size => 20) %>
<%= submit_tag "Go" %>
<% end %>
</section>
<% if @current_user.is_privileged? %>
<section id="mode-box">
<h1>Mode</h1>
<form action="/">
<select name="mode">
<option value="view">View posts</option>
<option value="edit">Edit posts</option>
<option value="add-fav">Add to favorites</option>
<option value="remove-fav">Remove from favorites</option>
<option value="rating-s">Rate safe</option>
<option value="rating-q">Rate questionable</option>
<option value="rating-e">Rate explicit</option>
<option value="vote-up">Vote up</option>
<option value="vote-down">Vote down</option>
<option value="lock-rating">Lock rating</option>
<option value="lock-note">Lock notes</option>
<option value="edit-tag-script">Edit tag script</option>
<option value="apply-tag-script">Apply tag script</option>
<% if @current_user.is_janitor? %>
<option value="approve">Approve post</option>
<% end %>
<option value="flag">Flag post</option>
</select>
</form>
</section>
<% end %>
<section id="blacklist-box">
<h1>Blacklisted</h1>
<%= link_to "Hidden", "#" %>
<ul>
</ul>
</section>
<div id="tag-and-wiki-box">
<menu>
<li><h1>Tags</h1></li>
<li><h1>Wiki</h1></li>
</menu>
<section id="tag-box">
<h2>Tags</h2>
<%= @post_set.presenter.tag_list_html %>
</section>
<section id="wiki-box">
<h2>Wiki</h2>
<%= @post_set.presenter.wiki_html %>
</section>
</div>
</aside>
<section>
<h1>Posts</h1>
<%= @post_set.presenter.post_previews_html %>
</section>
<footer>
<%= @post_set.presenter.pagination_html %>
</footer>
<% content_for(:page_title) do %>
/<%= @post_set.tags %>
<% end %>
<% content_for(:page_header) do %>
/ <%= @post_set.tags %>
<% end %>
<% content_for(:secondary_nav_links) do %>
<menu>
<li>Listing</li>
<li>Upload</li>
<li>Popular</li>
<li>Favorites</li>
<li>Subscriptions</li>
<li>Changes</li>
<li>Approvals</li>
<li>Moderate</li>
<li>Help</li>
</menu>
<% end %>

View File

@@ -19,10 +19,18 @@
<aside>
<h2>Help</h2>
<ul>
<menu>
<li><%= link_to "I don't have an account", new_user_path %></li>
<li><%= link_to "I forgot my password", reset_password_info_path %></li>
<li><%= link_to "I forgot my login", login_reminder_info_path %></li>
<li><%= link_to "I want to delete my account", delete_account_info_path %></li>
</ul>
</menu>
</aside>
<% content_for(:page_title) do %>
login
<% end %>
<% content_for(:page_header) do %>
/ login
<% end %>

View File

@@ -1,3 +1,70 @@
<% form_for @user do |f| %>
<fieldset>
<legend>Basic</legend>
<p>
<%= f.label :email %>
<%= f.text_field :email %>
</p>
<p>
<%= f.label :receive_email_notifications, "Email notifications" %>
<%= f.check_box :receive_email_notifications %>
</p>
<p>
<%= f.label :comment_threshold %>
<%= f.text_field :comment_threshold, :size => 2 %>
</p>
<p>
<%= f.label :always_resize_images %>
<%= f.check_box :always_resize_images %>
</p>
<p>
<%= f.label :default_image_size %>
<%= f.select :default_image_size, %w(Medium Large Original) %>
</p>
<p>
<%= f.label :favorite_tags %>
<%= f.text_area :favorite_tags, :rows => 5 %>
</p>
<p>
<%= f.label :blacklisted_tags %>
<%= f.text_area :blacklisted_tags, :rows => 5 %>
</p>
</fieldset>
<fieldset>
<legend>Special</legend
<p>For security purposes, changing the following settings requires you to re-enter your password. You can leave the new password field blank to keep your current one.</p>
<p>
<%= f.label :name %>
<%= f.text_field :name %>
</p>
<p>
<%= f.label :password, "New password" %>
<%= f.text_field :password %>
</p>
<p>
<%= f.label :old_password %>
<%= f.text_field :old_password %>
</p>
</fieldset>
<%= submit_tag "Submit" %>
<% end %>
<% content_for(:page_title) do %>
/<%= @user.name %>/Settings
<% end %>
<% content_for(:page_header) do %>
/ <%= @user.name %> / Settings
<% end %>

View File

@@ -1,11 +1,14 @@
<h1><%= @user.name %></h1>
<nav>
<ul>
<li><%= link_to "Settings", edit_user_path(@user) %></li>
<li><%= link_to "Log out", session_path(0), :method => :delete %></li>
</ul>
</nav>
<% content_for(:page_title) do %>
users/<%= @user.name %>
<% end %>
<% content_for(:page_header) do %>
/ <%= @user.name %>
<% end %>
<% end %>