Skip to content

Commit

Permalink
Admin section introduced.
Browse files Browse the repository at this point in the history
For now it only includes only development tools:

* A link to recompute all the news score and rank information.
* A link that shows the home page annotated with news id, score, rank.

The user needs to have the "a" flag to access this section.
  • Loading branch information
antirez committed Oct 10, 2012
1 parent 1c43c9e commit 5ceb465
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
33 changes: 31 additions & 2 deletions app.rb
Expand Up @@ -499,6 +499,28 @@ def render_comment_subthread(comment,sep="")
end
end

get '/admin' do
redirect "/" if !$user || !user_is_admin?($user)
H.page {
H.div(:id => "adminlinks") {
H.h2 {"Admin"}+
H.h3 {"Developer tools"}+
H.ul {
H.li {
H.a(:href=>"/recompute") {
"Recompute news score and rank (may be slow!)"
}
}+
H.li {
H.a(:href=>"/?debug=1") {
"Show annotated home page"
}
}
}
}
}
end

###############################################################################
# API implementation
###############################################################################
Expand Down Expand Up @@ -824,7 +846,7 @@ def check_api_secret
# The link is not shown at all if the user is not logged in, while
# it is shown with a badge showing the number of replies for logged in
# users.
def replies_link
def navbar_replies_link
return "" if !$user
count = $user['replies'] || 0
H.a(:href => "/replies", :class => "replies") {
Expand All @@ -835,14 +857,21 @@ def replies_link
}
end

def navbar_admin_link
return "" if !$user || !user_is_admin?($user)
H.b {
H.a(:href => "/admin") {"admin"}
}
end

def application_header
navitems = [ ["top","/"],
["latest","/latest/0"],
["submit","/submit"]]
navbar = H.nav {
navitems.map{|ni|
H.a(:href=>ni[1]) {H.entities ni[0]}
}.inject{|a,b| a+"\n"+b}+replies_link
}.inject{|a,b| a+"\n"+b}+navbar_replies_link+navbar_admin_link
}
rnavbar = H.nav(:id => "account") {
if $user
Expand Down
2 changes: 1 addition & 1 deletion page.rb
Expand Up @@ -128,7 +128,7 @@ def page()
self.meta(:charset => "utf-8")+
self.title{H.entities @title}+
self.meta(:content => :index, :name => :robots)+
self.link(:href => "/css/style.css?v=8", :rel => "stylesheet",
self.link(:href => "/css/style.css?v=9", :rel => "stylesheet",
:type => "text/css")+
self.link(:href => "/images/favicon.png", :rel => "shortcut icon")+
self.script(:src => "/js/jquery.1.6.4.min.js"){}+
Expand Down
10 changes: 9 additions & 1 deletion public/css/style.css
Expand Up @@ -16,6 +16,10 @@ h2 {
color:#333;
}

li {
list-style-type: none;
}

header {
display:block;
position:relative;
Expand Down Expand Up @@ -251,7 +255,6 @@ topcomment {
}

.userinfo ul li {
list-style-type: none;
margin-bottom:10px;
}

Expand Down Expand Up @@ -292,3 +295,8 @@ topcomment {
left:-5px;
opacity:0.7
}

#adminlinks li {
list-style-type: disc;
margin-left:20px;
}

0 comments on commit 5ceb465

Please sign in to comment.