Skip to content

Commit 3cb41c3

Browse files
author
Marylou Kunkle
committed
Added admin site and functionality; incomplete
Not everything works. The discussion and reply links are not correct. Will work on that later.
1 parent bb6186b commit 3cb41c3

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

controllers/admin.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#This is the 'admins' controller
2+
3+
# Show how many users there are
4+
get '/admin' do
5+
admin_only!
6+
#get usercount
7+
@usercount = Hacker.all.length
8+
today = Date.today
9+
@newusers = Hacker.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time}).length
10+
@newusernames = Hacker.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time})
11+
@forumposts = Discussion.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time}).length
12+
@postlinks = Discussion.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time})
13+
@forumreplies = Discussion.all(:updated_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time}).length
14+
15+
haml :"admin/index"
16+
end
17+

models/hacker.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Hacker
66

77
#we're storing a unique username
88
key :username, String, :unique => true
9+
timestamps!
910
#and a unique email
1011
key :email, String, :unique => true
1112

views/admin/index.haml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
%h1= current_user.username + "'s admin page"
2+
%img{:src => current_user.gravatar_url}
3+
4+
%p Total Hacker Count: #{@usercount}
5+
6+
%p New Users Today: #{@newusers}
7+
%ul
8+
- @newusernames.each do |name|
9+
%li
10+
%a{:href => "/hackers/#{name.username}"}= name.username
11+
12+
%p New Forum Discussions: #{@forumposts}
13+
%ul
14+
- @postlinks.each do |postlink|
15+
%li
16+
%a{:href => "/forums/#{postlink.title}"}= postlink.title
17+
18+
%p New Forum Replies: #{@forumreplies}
19+
%ul
20+
- @postlinks.each do |replylink|
21+
%li
22+
%a{:href => "/forums/#{replylink.title}/#{replylink.replies.title}"}= replylink.slug
23+
24+

0 commit comments

Comments
 (0)