Changeset 596
- Timestamp:
- 09/09/07 19:34:02 (1 year ago)
- Files:
-
- apps/marble/trunk/app/controllers/admin/base.rb (added)
- apps/marble/trunk/app/controllers/admin/blogs.rb (deleted)
- apps/marble/trunk/app/controllers/admin/comments.rb (modified) (1 diff)
- apps/marble/trunk/app/controllers/admin/posts.rb (modified) (1 diff)
- apps/marble/trunk/app/controllers/admin/users.rb (modified) (5 diffs)
- apps/marble/trunk/app/controllers/auth.rb (modified) (1 diff)
- apps/marble/trunk/app/controllers/config (added)
- apps/marble/trunk/app/controllers/config/blogs.rb (added)
- apps/marble/trunk/app/controllers/config/users.rb (added)
- apps/marble/trunk/app/controllers/posts.rb (modified) (1 diff)
- apps/marble/trunk/app/helpers/global_helper.rb (modified) (1 diff)
- apps/marble/trunk/app/models/blog.rb (modified) (1 diff)
- apps/marble/trunk/app/models/membership.rb (modified) (1 diff)
- apps/marble/trunk/app/models/user.rb (modified) (2 diffs)
- apps/marble/trunk/app/views/exceptions/gone.html.erb (modified) (1 diff)
- apps/marble/trunk/app/views/exceptions/internal_server_error.html.erb (modified) (1 diff)
- apps/marble/trunk/app/views/exceptions/not_found.html.erb (modified) (1 diff)
- apps/marble/trunk/app/views/exceptions/unauthorized.html.erb (added)
- apps/marble/trunk/app/views/layout/admin.html.erb (modified) (2 diffs)
- apps/marble/trunk/app/views/layout/config.html.erb (added)
- apps/marble/trunk/config/router.rb (modified) (1 diff)
- apps/marble/trunk/public/stylesheets/admin.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
apps/marble/trunk/app/controllers/admin/comments.rb
r593 r596 1 1 module Admin 2 class Comments < Application2 class Comments < Base 3 3 self._layout = :admin 4 4 before :set_nav 5 def set_nav() @nav = "comments" end 5 6 6 7 magic_scaffold_here(Comment) { apps/marble/trunk/app/controllers/admin/posts.rb
r593 r596 1 1 module Admin 2 class Posts < Application2 class Posts < Base 3 3 self._layout = :admin 4 before :set_nav 5 def set_nav() @nav = "posts" end 4 6 5 7 magic_scaffold_here(Post) { apps/marble/trunk/app/controllers/admin/users.rb
r593 r596 1 1 module Admin 2 class Users < Application2 class Users < Base 3 3 self._layout = :admin 4 before :set_nav 5 def set_nav() @nav = "users" end 6 7 def index 8 @page = User.for_blog(@current_blog.id).paginate((params[:page] || 1).to_i, 10) 9 @users = @page.all 4 10 11 render :inline => <<-HTML.indent(2) 12 <%- if @users.size == 0 -%> 13 No users to show 14 <%- end -%> 15 <table> 16 <tr> 17 <th>Name</th> 18 <th>Email</th> 19 <th>Posts</th> 20 </tr> 21 <%- @users.each do |u| -%> 22 <tr> 23 <td><%= u.name %></td> 24 <td><%= u.email %></td> 25 <td><%= u.post_count rescue 0 %></td> 26 <td><a href="<%= url(:edit_user, :id => u.id) %>">edit</a></td> 27 </tr> 28 <%- end -%> 29 </table> 30 <%= 31 links = [] 32 links << %|<a href="#{url(:users, :page => @page.prev_page)}">Previous Page</a>| if @page.prev_page 33 links << %|<a href="#{url(:users, :page => @page.next_page)}">Next Page</a>| if @page.next_page 34 links << %|<a href="#{url(:new_user)}">new user</a>| 35 links.join(" | ") 36 %> 37 HTML 38 end 39 5 40 magic_scaffold_here(User) { 6 41 # NOTE: DO NOT EDIT the text below. Instead, cut out the method or … … 9 44 # actions that already exist in your controller class. 10 45 module Scaffold 11 def index12 @page = User.paginate((params[:page] || 1).to_i, 10)13 @users = @page.all14 15 render :inline => <<-HTML.indent(2)16 <%- if @users.size == 0 -%>17 No users to show18 <%- end -%>19 <table>20 <tr>21 <th>Id</th>22 <th>First name</th>23 <th>Surname</th>24 <th>Email</th>25 <th>Password</th>26 <th>Can create blogs</th>27 </tr>28 <%- @users.each do |u| -%>29 <tr>30 <td><%= u.id %></td>31 <td><%= u.first_name %></td>32 <td><%= u.surname %></td>33 <td><%= u.email %></td>34 <td><%= u.password %></td>35 <td><%= u.can_create_blogs %></td>36 <td><a href="<%= url(:edit_user, :id => u.id) %>">edit</a></td>37 </tr>38 <%- end -%>39 </table>40 <%=41 links = []42 links << %|<a href="#{url(:users, :page => @page.prev_page)}">Previous Page</a>| if @page.prev_page43 links << %|<a href="#{url(:users, :page => @page.next_page)}">Next Page</a>| if @page.next_page44 links << %|<a href="#{url(:new_user)}">new user</a>|45 links.join(" | ")46 %>47 HTML48 end49 50 46 def show 51 47 id = params[:id] … … 57 53 <li><strong>Id:</strong> <%= @user.id %></li> 58 54 <li><strong>First name:</strong> <%= @user.first_name %></li> 59 <li><strong> Surname:</strong> <%= @user.surname %></li>55 <li><strong>Last name:</strong> <%= @user.last_name %></li> 60 56 <li><strong>Email:</strong> <%= @user.email %></li> 61 57 <li><strong>Password:</strong> <%= @user.password %></li> … … 73 69 <ul> 74 70 <div class="form-element"><label for="user_first_name">First name:</label><br/><%= control_for @user, :first_name, :text %></div> 75 <div class="form-element"><label for="user_ surname">Surname:</label><br/><%= control_for @user, :surname, :text %></div>71 <div class="form-element"><label for="user_last_name">Last name:</label><br/><%= control_for @user, :last_name, :text %></div> 76 72 <div class="form-element"><label for="user_email">Email:</label><br/><%= control_for @user, :email, :text %></div> 77 73 <div class="form-element"><label for="user_password">Password:</label><br/><%= control_for @user, :password, :text %></div> … … 104 100 <ul> 105 101 <div class="form-element"><label for="user_first_name">First name:</label><br/><%= control_for @user, :first_name, :text %></div> 106 <div class="form-element"><label for="user_ surname">Surname:</label><br/><%= control_for @user, :surname, :text %></div>102 <div class="form-element"><label for="user_last_name">Last name:</label><br/><%= control_for @user, :last_name, :text %></div> 107 103 <div class="form-element"><label for="user_email">Email:</label><br/><%= control_for @user, :email, :text %></div> 108 104 <div class="form-element"><label for="user_password">Password:</label><br/><%= control_for @user, :password, :text %></div> apps/marble/trunk/app/controllers/auth.rb
r593 r596 21 21 if @user 22 22 session[:user_id] = @user.id 23 return redirect("/") 23 if session[:return_to] 24 returning(redirect(session[:return_to])) do 25 session[:return_to] = nil 26 end 27 else 28 redirect("/") 29 end 24 30 else 25 31 params.errors[:auth_failed] = "The email or password was incorrect." apps/marble/trunk/app/controllers/posts.rb
r583 r596 2 2 self._layout = :one_column 3 3 def index 4 @blog = Blog.f ilter(:subdomain =>request.subdomains.first).first4 @blog = Blog.for_subdomain(request.subdomains.first).first 5 5 if @blog 6 6 @page = Post.filter(:blog_id => @blog.id).paginate((params[:page] || 1).to_i, 10) apps/marble/trunk/app/helpers/global_helper.rb
r500 r596 1 1 module Merb 2 2 module GlobalHelper 3 # helpers deinfed here available to all views. 3 # helpers defined here available to all views. 4 def nav(key, html) 5 %{<li#{key == @nav ? " class=\"selected\"" : ""}>#{html}</li>} 6 end 4 7 end 5 8 end apps/marble/trunk/app/models/blog.rb
r500 r596 6 6 end 7 7 8 def self.for_subdomain(subdomain) 9 Blog.filter(:subdomain => subdomain) 10 end 11 12 def owners 13 end 14 15 def members 16 end 8 17 end 9 18 apps/marble/trunk/app/models/membership.rb
r500 r596 16 16 when 'test', 'development' 17 17 recreate_table 18 [ 19 {:user_id => 1, :blog_id => 1, :owner => true}, 20 {:user_id => 2, :blog_id => 1, :owner => false}, 21 {:user_id => 3, :blog_id => 1, :owner => false}, 22 {:user_id => 4, :blog_id => 2, :owner => true}, 23 {:user_id => 5, :blog_id => 2, :owner => false}, 24 {:user_id => 6, :blog_id => 2, :owner => false}, 25 {:user_id => 7, :blog_id => 3, :owner => true}, 26 {:user_id => 8, :blog_id => 3, :owner => false}, 27 {:user_id => 1, :blog_id => 3, :owner => false}, 28 {:user_id => 2, :blog_id => 2, :owner => false} 29 ].each{ |row| insert row } 30 18 31 end 19 32 end apps/marble/trunk/app/models/user.rb
r593 r596 9 9 end 10 10 11 def self.for_blog(blog_id) 12 dataset.left_outer_join(:memberships, :user_id => :id).filter(:blog_id => blog_id) 13 end 14 15 def name 16 [first_name, last_name].compact.join(" ") 17 end 18 19 def this 20 model.dataset.filter(:"users__#{primary_key}" => @pkey) 21 end 22 23 def owns_blog?(blog_id) 24 this.left_outer_join(:memberships, :user_id => :id).filter(:blog_id => blog_id, :owner => true).first 25 end 11 26 end 12 27 … … 28 43 {:first_name => 'Brianna', :last_name => "Harris", :email => "brianna.harris@gmail.com", :password => "test"} 29 44 ].each{ |row| insert row } 30 31 migrate { |m| m.rename_column :last_name => :surname }32 45 end 33 46 end apps/marble/trunk/app/views/exceptions/gone.html.erb
r583 r596 1 <h3>Gone</h3>2 <p>You've found a page that may have been here but is no longer.</p>1 <h3>Gone</h3> 2 <p>You've found a page that may have been here but is no longer.</p> 3 3 4 <h3>What Next?</h3>5 <p>If you arrived here from an outside source, please notify the other website that6 their link is no longer valid.</p>7 <p>On the other hand, if we made this mistake ourselves, please let us know how you8 got here and we'll see if we can't remedy the situation.</p>4 <h3>What Next?</h3> 5 <p>If you arrived here from an outside source, please notify the other website that 6 their link is no longer valid.</p> 7 <p>On the other hand, if we made this mistake ourselves, please let us know how you 8 got here and we'll see if we can't remedy the situation.</p> 9 9 10 <h3 class="red">Exception:</h3> 11 <p><%= message %></p> 12 <p><%= Merb.html_exception(exception) %></p> 13 14 10 <h3 class="red">Exception:</h3> 11 <p><%= message %></p> 12 <p><%= Merb.html_exception(exception) %></p> apps/marble/trunk/app/views/exceptions/internal_server_error.html.erb
r583 r596 1 <h3>Internal Server Error</h3>2 <p>Oops, we goofed up.</p>1 <h3>Internal Server Error</h3> 2 <p>Oops, we goofed up.</p> 3 3 4 <h3>What Next?</h3> 5 <p>You can use your browser's back button to return to the page you came from and try again or report the bug.</p> 6 7 <h3 class="red">Exception:</h3> 8 <p><%= Merb.html_exception(exception) %></p> 9 4 <h3>What Next?</h3> 5 <p>You can use your browser's back button to return to the page you came from and try again or report the bug.</p> 6 7 <h3 class="red">Exception:</h3> 8 <p><%= Merb.html_exception(exception) %></p> apps/marble/trunk/app/views/exceptions/not_found.html.erb
r583 r596 1 <h3>Page Not Found</h3>2 <p>You've found a page that doesn't exist.</p>1 <h3>Page Not Found</h3> 2 <p>You've found a page that doesn't exist.</p> 3 3 4 <h3>What Next?</h3>5 <p>If you arrived here from an outside source, please notify the other website that6 their link is no longer valid.</p>7 <p>On the other hand, if we made this mistake ourselves, please let us know how you8 got here and we'll see if we can't remedy the situation.</p>4 <h3>What Next?</h3> 5 <p>If you arrived here from an outside source, please notify the other website that 6 their link is no longer valid.</p> 7 <p>On the other hand, if we made this mistake ourselves, please let us know how you 8 got here and we'll see if we can't remedy the situation.</p> 9 9 10 <h3 class="red">Exception:</h3>11 <p><%= message %></p>10 <h3 class="red">Exception:</h3> 11 <p><%= message %></p> apps/marble/trunk/app/views/layout/admin.html.erb
r584 r596 2 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 3 <head> 4 <title>Marble Admin — Users</title>4 <title>Marble Admin<%= @title ? " — #{@title}" : "" %></title> 5 5 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> 6 6 <link rel="stylesheet" href="/stylesheets/master.css" type="text/css" media="screen" charset="utf-8"> … … 14 14 <hr /> 15 15 <ul id="admin-menu"> 16 <li>→</li> 17 <li><a href="<%= url(:users) %>">Users</a></li> 18 <li><a href="<%= url(:blogs) %>">Blogs</a></li> 19 <li><a href="<%= url(:posts) %>">Posts</a></li> 20 <li><a href="<%= url(:comments) %>">Comments</a></li> 16 <%= nav "users", %{<a href="#{url(:users)}" class="partition">Users</a>} %> 17 <%= nav "posts", %{<a href="#{url(:posts)}" class="partition">Posts</a>} %> 18 <%= nav "comments", %{<a href="#{url(:comments)}" class="partition">Comments</a>} %> 21 19 </ul> 22 20 <div style="clear:both"></div> 21 <hr /> 23 22 </div> 24 23 apps/marble/trunk/config/router.rb
r593 r596 22 22 puts "Compiling routes.." 23 23 Merb::Router.prepare do |r| 24 24 25 r.match("/config") do |app| 26 app.resources(:users, :controller => 'config/users') 27 app.resources(:blogs, :controller => 'config/posts') 28 # Default admin to Users#index 29 app.match(%r[/?]).to(:controller => 'config/users') 30 end 31 25 32 r.match("/admin") do |admin| 26 33 admin.resources(:users, :controller => 'admin/users') 27 admin.resources(:blogs, :controller => 'admin/blogs')28 34 admin.resources(:posts, :controller => 'admin/posts') 29 35 admin.resources(:comments, :controller => 'admin/comments') apps/marble/trunk/public/stylesheets/admin.css
r583 r596 8 8 } 9 9 ul#admin-menu li a { 10 padding: 2px 5px 2px 5px;10 padding: 2px 12px 2px 12px; 11 11 display: block; 12 12 text-decoration: none; 13 } 14 ul#admin-menu li a.partition { 15 border-right: 2px solid #ddd; 13 16 } 14 17 ul#admin-menu li a:hover {
