diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index e7705c047..d5f208bb7 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -8,6 +8,13 @@ class Stringer < Sinatra::Base erb :index end + get "/news/:feed_id" do + @unread_stories = StoryRepository.unread_by_feed_id(params[:feed_id]) + @feed_id = params[:feed_id] + + erb :index + end + get "/archive" do @read_stories = StoryRepository.read(params[:page]) @@ -16,17 +23,21 @@ class Stringer < Sinatra::Base put "/stories/:id" do json_params = JSON.parse(request.body.read, symbolize_names: true) - + story = StoryRepository.fetch(params[:id]) story.is_read = !!json_params[:is_read] story.keep_unread = !!json_params[:keep_unread] - + StoryRepository.save(story) end post "/mark_all_as_read" do MarkAllAsRead.new(params[:story_ids]).mark_as_read - - redirect to("/news") + + if params[:feed_id] + redirect to("/news/#{params[:feed_id]}") + else + redirect to("/news") + end end -end \ No newline at end of file +end diff --git a/app/repositories/story_repository.rb b/app/repositories/story_repository.rb index 552ca2ae9..0ebac1a33 100644 --- a/app/repositories/story_repository.rb +++ b/app/repositories/story_repository.rb @@ -27,6 +27,10 @@ def self.unread Story.where(is_read: false).order("published desc") end + def self.unread_by_feed_id(feed_id) + unread.where(feed_id: feed_id) + end + def self.read(page = 1) Story.where(is_read: true).order("published desc").page(page).per_page(15) end @@ -37,7 +41,7 @@ def self.read_count def self.extract_content(entry) sanitized_content = "" - + if entry.content sanitized_content = entry.content.sanitize elsif entry.summary diff --git a/app/views/index.erb b/app/views/index.erb index 55a710b1b..bea1c9849 100644 --- a/app/views/index.erb +++ b/app/views/index.erb @@ -5,16 +5,16 @@ <% end %>
- <%= render_partial :action_bar, { stories: @unread_stories } %> + <%= render_partial :action_bar, { stories: @unread_stories, feed_id: @feed_id } %>
<% if @unread_stories.empty? %> <%= render_partial :zen %> <% else %> <%= render_js :stories, { stories: @unread_stories } %> - +
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/partials/_action_bar.erb b/app/views/partials/_action_bar.erb index 326fdf89d..5b2678e11 100644 --- a/app/views/partials/_action_bar.erb +++ b/app/views/partials/_action_bar.erb @@ -1,11 +1,14 @@
+ + + <%= render_partial :mark_all_as_read_form, - {stories: stories} %> + {stories: stories, feed_id: feed_id} %> - +
diff --git a/app/views/partials/_feed.erb b/app/views/partials/_feed.erb index 117547826..1c0e5bb39 100644 --- a/app/views/partials/_feed.erb +++ b/app/views/partials/_feed.erb @@ -3,7 +3,7 @@

" data-placement="left"> - <%= feed.name %> + <%= feed.name %> diff --git a/app/views/partials/_mark_all_as_read_form.erb b/app/views/partials/_mark_all_as_read_form.erb index 8e34745cd..c03ed414c 100644 --- a/app/views/partials/_mark_all_as_read_form.erb +++ b/app/views/partials/_mark_all_as_read_form.erb @@ -2,6 +2,7 @@

<% stories.each do |story| %> + <% end %> -
\ No newline at end of file +
diff --git a/app/views/partials/_tutorial_action_bar.erb b/app/views/partials/_tutorial_action_bar.erb index f5ed6d893..a99829b66 100644 --- a/app/views/partials/_tutorial_action_bar.erb +++ b/app/views/partials/_tutorial_action_bar.erb @@ -3,7 +3,7 @@ <%= render_partial :mark_all_as_read_form, - {stories: stories} %> + {stories: stories, feed_id: nil} %> diff --git a/spec/controllers/stories_controller_spec.rb b/spec/controllers/stories_controller_spec.rb index 8e7c36be2..63adabed5 100644 --- a/spec/controllers/stories_controller_spec.rb +++ b/spec/controllers/stories_controller_spec.rb @@ -123,5 +123,14 @@ last_response.status.should be 302 URI::parse(last_response.location).path.should eq "/news" end + + it "marks all unread stories of a feed as read and reload the page" do + MarkAllAsRead.any_instance.should_receive(:mark_as_read).once + + post "/mark_all_as_read", story_ids: ["1", "2", "3"], feed_id: 4 + + last_response.status.should be 302 + URI::parse(last_response.location).path.should eq "/news/4" + end end -end \ No newline at end of file +end