Skip to content

Commit

Permalink
Improve admin functionality
Browse files Browse the repository at this point in the history
* Only show published articles even if url is entered manually
* Add login and logout links
* Refactor admin menu and make small design fixes
* Improve ajax loading script for posts
* Change so the preview is of the intro and not the body
* Fix posts test that had a logical error
  • Loading branch information
mrDoktar committed May 28, 2010
1 parent 9913fad commit a181b34
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 30 deletions.
7 changes: 0 additions & 7 deletions app/controllers/logout_controller.rb

This file was deleted.

10 changes: 9 additions & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class PostsController < ApplicationController

before_filter :check_if_published, :only => :show

def index
@post = Post.latest.first
Expand All @@ -11,8 +13,14 @@ def index
end

def show
@post = Post.find_by_id(params[:id])
@posts = Post.latest.limit(10).includes(:tags) - [@post]
end

private

def check_if_published
@post = Post.find_by_id(params[:id])
redirect_to root_url unless @post.status? :published || current_user.admin?
end

end
13 changes: 13 additions & 0 deletions app/controllers/session_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class SessionController < ApplicationController
before_filter CASClient::Frameworks::Rails::Filter, :only => :login

def logout
@current_user = nil
reset_session
CASClient::Frameworks::Rails::Filter.logout(self, root_url) and return
end

def login
redirect_to root_url
end
end
4 changes: 4 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@ def status
return "unfinished"
end
end

def status?(status_comparison)
status == status_comparison.to_s
end

end
11 changes: 9 additions & 2 deletions app/views/admin/posts/_menu.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
- content_for(:menu) do
- if current_user && current_user.admin
%p
= link_to "Write a new post", [:new, :admin, :post], :class => "button in_menu"
= link_to "Write a new post", [:new, :admin, :post], :class => "button in_menu"
%br
= link_to "List all posts", [:admin, :posts], :class => "button in_menu"
- if defined? post
%br
= link_to "Edit this one", [:edit, :admin, post], :class => "button in_menu"
%br
= link_to "Delete this one", [:admin, post], :method => :delete, :confirm => "Are you sure?", :class => "button red in_menu"

10 changes: 9 additions & 1 deletion app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
= yield :javascript
= csrf_meta_tag
%body
#top_menu
#top_container
#top
#login_info
- if current_user
You are logged in as
= current_user.email
= link_to "Logout", logout_path
- else
= link_to "Login", login_url
#header_container
#header
= image_tag "fade.png", :id => "fade"
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/_listed_post.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
= raw "(" + link_to("Comments", post_path(listed_post, :anchor => "disqus_thread")) + ")"
.fadeout
.text
%p= truncate(strip_tags(textilize(listed_post.body)), :length => 150)
%p= strip_tags(textilize(listed_post.intro))
8 changes: 1 addition & 7 deletions app/views/posts/_post.html.haml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
= stylesheet "coderay"

= render :partial => "admin/posts/menu", :locals => {:post => post}
- content_for(:menu) do
- if current_user && current_user.admin
#admin_buttons
= link_to "Write a new post", [:new, :admin, :post], :class => "button in_menu"
%br
= link_to "Edit this one", [:edit, :admin, post], :class => "button in_menu"
%br
= link_to "Delete this one", [:admin, post], :method => :delete, :confirm => "Are you sure?", :class => "button red in_menu"
= list_headings(post.intro + post.body)

= render :partial => "post_info", :locals => {:post => post}
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
resources :posts
end

match '/logout' => 'logout#logout'
match '/logout' => 'session#logout'
match '/login' => 'session#login'

# The priority is based upon order of creation:
# first created -> highest priority.
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/admin_posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ $(function() {

allow_load_posts = true;
$.get("/admin/posts", "list=true" + extra, function(data) {
$("#loading_post").hide().removeClass("normal_position");
if(data == " ")
allow_load_posts = false;
else {
$("#loading_post").before(data);
$("#loading_post").hide().removeClass("normal_position");
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions public/javascripts/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ $(function() {

allow_load_posts = true;
$.get("/posts", "list=true" + extra, function(data) {
$("#loading_post").hide().removeClass("normal_position");
if(data == " ")
allow_load_posts = false;
else {
$("#loading_post").before(data);
$("#loading_post").hide().removeClass("normal_position");
checkPostsListHeight();
$("#posts").jScrollPane({reload: true, callbackOnBottom: loadPosts, maintainPosition: false});
}
Expand All @@ -79,7 +79,7 @@ $(function() {
var $menu = $("#menu");
var menu_height = $menu.height();
var menu_original_position = $menu.offset().top
var content_height = $("#content").height();
var content_height = $("#content").height() - 40;
$(window).scroll(function(){
var scroll_top = $(window).scrollTop();
var new_menu_top = scroll_top - menu_original_position
Expand Down
17 changes: 16 additions & 1 deletion public/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,25 @@ strong {
clear: both;
}

#top_menu {
#top_container {
height: 25px;
background-color: #242424;
}
#top {
width: 960px;
height: 25px;
position: relative;
margin-left: auto;
margin-right: auto;
}
#login_info {
font-size: 0.8em;
line-height: 1.875em;
margin-bottom: 1.875em;
text-align: right;
color: #E4E4E4;
padding-right: 1em;
}
#header_container {
height: 200px;
background: #294479;
Expand Down
4 changes: 2 additions & 2 deletions public/stylesheets/posts.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}
#post_selector {
line-height: 2em;
margin-bottom: 1em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
max-width: 1600px; }
Expand Down Expand Up @@ -80,7 +80,7 @@
max-width: 1600px;
margin-left: auto;
margin-right: auto;
clear: both; }
}
.post.important {
background-color: #d1f2ff; }
.post .info {
Expand Down
8 changes: 4 additions & 4 deletions spec/models/post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@

describe "calling scopes" do
before do
@post1 = Factory :post, :published_on => 4.days.ago
@post2 = Factory :post, :published_on => 2.days.ago
@post1 = Factory :post, :published_on => 4.days.ago.to_date
@post2 = Factory :post, :published_on => 2.days.ago.to_date
@post3 = Factory :post, :published_on => Date.today, :reviewed => false
@post4 = Factory :post, :published_on => 2.days.from_now
@post4 = Factory :post, :published_on => 2.days.from_now.to_date
end

it "should return published posts that are reviewd" do
Post.published.should have(2).post
end

it "should return unpublished posts" do
Post.unpublished.first.should eql(@post4)
Post.unpublished.first.should eql(@post3)
end

it "should return the latest posts sorted by published date" do
Expand Down

0 comments on commit a181b34

Please sign in to comment.