Skip to content

Commit

Permalink
Add a button to forgot all readings
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Dec 16, 2011
1 parent 1ee9696 commit 1b8185e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/controllers/readings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def destroy
end
end

def destroy_all
Node.unread_all_by(current_account.id)
redirect_to readings_path
end

protected

def find_node
Expand Down
11 changes: 10 additions & 1 deletion app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ def threads

### Readings ###

def self.readings_keys_of(account_id)
$redis.keys("readings/*/#{account_id}")
end

def self.readings_of(account_id)
ids = $redis.keys("readings/*/#{account_id}").map {|x| x.scan(/\/(\d+)\//).first.first }
ids = readings_keys_of(account_id).map {|x| x.scan(/\/(\d+)\//).first.first }
visible.where(:id => ids)
end

Expand All @@ -106,6 +110,11 @@ def unread_by(account_id)
$redis.del("readings/#{self.id}/#{account_id}")
end

def self.unread_all_by(account_id)
keys = readings_keys_of(account_id)
$redis.del(*keys) if keys.present?
end

def self.last_reading(node_id, account_id)
time = $redis.get("readings/#{node_id}/#{account_id}")
time && Time.at(time.to_i)
Expand Down
5 changes: 5 additions & 0 deletions app/views/readings/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
- content_for :column do
#readings_box.box
%h1 Mes lectures
= button_to "Tout oublier", readings_path, :method => :delete, :class => "delete_button"

=h1 "Les derniers contenus que j'ai lu"
= paginated_section @nodes do
#contents
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
end
end
resources :readings, :only => [:index, :destroy]
delete "readings" => "readings#destroy_all"
resources :tags, :only => [:index, :show] do
collection do
get :autocomplete
Expand Down

0 comments on commit 1b8185e

Please sign in to comment.