Module: ECDashboardModel
- Extended by:
- ECDashboardModel
- Included in:
- ECDashboardModel
- Defined in:
- lib/easycomments/ec_dashboard_model.rb
Instance Method Summary collapse
- #authenticate(username, password) ⇒ Object
- #comment_change_approval(id) ⇒ Object
- #edit_comment(id, new_body) ⇒ Object
- #get_all_posts ⇒ Object
- #get_comments(post) ⇒ Object
- #get_pending_comments(post) ⇒ Object
- #get_posts_with_pending ⇒ Object
- #get_total_pending ⇒ Object
- #ignore_comment(id) ⇒ Object
- #remove_comment(id) ⇒ Object
Instance Method Details
#authenticate(username, password) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/easycomments/ec_dashboard_model.rb', line 58 def authenticate(username, password) access = {} CONFIG[:users].each_pair do |u, p| if username == u && BCrypt::Password.new(p) == password access = {:has_access => true} else access = {:has_access => false} end end MultiJson.dump(access) end |
#comment_change_approval(id) ⇒ Object
26 27 28 29 30 |
# File 'lib/easycomments/ec_dashboard_model.rb', line 26 def comment_change_approval(id) comment = DB[:comments].where(:id => id).all.first DB[:comments].where(:id => id).update(:approved => !comment[:approved], :action_taken => true) MultiJson.dump({:status => "Approval status successfully changed."}) end |
#edit_comment(id, new_body) ⇒ Object
16 17 18 19 |
# File 'lib/easycomments/ec_dashboard_model.rb', line 16 def edit_comment(id, new_body) DB[:comments].where(:id => id).update(:body => new_body, :action_taken => true) MultiJson.dump({:status => "Comment successfully edited."}) end |
#get_all_posts ⇒ Object
12 13 14 |
# File 'lib/easycomments/ec_dashboard_model.rb', line 12 def get_all_posts MultiJson.dump({:posts => DB[:comments].map(:post).uniq}) end |
#get_comments(post) ⇒ Object
6 7 8 9 10 |
# File 'lib/easycomments/ec_dashboard_model.rb', line 6 def get_comments(post) comments = DB[:comments].where(:post => post).all.sort_by{|comment| comment[:id].to_i}.reverse #show latest comment first comments = comments.each{|comment| comment[:timestamp] = comment[:timestamp].strftime(TIMESTAMP_FORMAT)} MultiJson.dump({:comments => comments}) end |
#get_pending_comments(post) ⇒ Object
46 47 48 49 50 |
# File 'lib/easycomments/ec_dashboard_model.rb', line 46 def get_pending_comments(post) comments = DB[:comments].where(:post => post, :action_taken => false).all.sort_by{|comment| comment[:id].to_i}.reverse #show latest comment first comments = comments.each{|comment| comment[:timestamp] = comment[:timestamp].strftime(TIMESTAMP_FORMAT)} MultiJson.dump({:comments => comments}) end |
#get_posts_with_pending ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/easycomments/ec_dashboard_model.rb', line 37 def get_posts_with_pending pending =[] posts = DB[:comments].where(:action_taken => false).map(:post).uniq posts.each do |post| pending.push({:post => post, :pending => DB[:comments].where(:post => post, :action_taken => false).count}) end MultiJson.dump({:pending => pending}) end |
#get_total_pending ⇒ Object
32 33 34 35 |
# File 'lib/easycomments/ec_dashboard_model.rb', line 32 def get_total_pending pending = DB[:comments].where(:action_taken => false).all.count MultiJson.dump({:pending => pending}) end |
#ignore_comment(id) ⇒ Object
52 53 54 55 56 |
# File 'lib/easycomments/ec_dashboard_model.rb', line 52 def ignore_comment(id) comment = DB[:comments].where(:id => id).all.first DB[:comments].where(:id => id).update(:action_taken => true) MultiJson.dump({:status => "Comment successfully ignored."}) end |
#remove_comment(id) ⇒ Object
21 22 23 24 |
# File 'lib/easycomments/ec_dashboard_model.rb', line 21 def remove_comment(id) DB[:comments].where(:id => id).delete MultiJson.dump({:status => "Comment successfully removed."}) end |