Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to filter stories by scope #89

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class StoriesController < ApplicationController
include RestrictedAccess
def index
@stories = Story.viewable.order(id: :desc).page params[:page]
@total_stories = Story.viewable.count
scope = set_scope

@stories = Story.send(scope).order(id: :desc).page params[:page]
@total_stories = Story.send(scope).count
end

def show
Expand All @@ -14,4 +16,14 @@ def show
end
@images = Image.where(story: @story, invalid_prompt: false)
end

def set_scope
if params[:scope] && params[:scope] == 'unpublished'
return 'unpublished_stories'
elsif params[:scope] && params[:scope] == 'published'
return 'published_stories'
end

'viewable'
end
end
4 changes: 4 additions & 0 deletions app/frontend/stylesheets/admin/menu.sass
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
&:hover, &:active
background: transparent

.item.active-dropdown
font-weight: bold
color: white

.logo
width: auto
max-height: 45px
Expand Down
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def menu_active?(test_path)
''
end

def dropdown_active?(test_path)
return 'active-dropdown' if request.path == test_path

''
end

def highlight_hashtags(tweet)
return "<p class='text-red-700'>The tweet is empty. Please click `edit` to create it.</p>".html_safe if tweet.blank?

Expand Down
11 changes: 11 additions & 0 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,15 @@ class Story < ApplicationRecord
.left_joins(:discussion)
.where(discussions: { id: nil })
}

scope :unpublished_stories, lambda {
joins(:discussion)
.where(discussions: { uploaded: false, processed: false, invalid_json: false })
}

scope :published_stories, lambda {
joins(:discussion)
.where(discussions: { uploaded: true })
}

end
15 changes: 13 additions & 2 deletions app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,23 @@ html lang="en"
=r ux.grid
=r ux.row 'menu'
=r ux.column size: 16
=r ux.menu ui: :on, class: 'inverted small black internal !bg-zinc-900 !font-mono'
=r ux.menu ui: :on, class: 'inverted tiny black internal !bg-zinc-900 !font-mono', controller: 'dropdown'
=r ux.item url: root_path, class: "logo-item #{menu_active?(root_path)}}"
=r ux.header text: '{e}', class: 'inverted logo !font-mono'
= link_to stories_path, class: "item #{menu_active?(stories_path)}"

=r ux.item class: "top right pointing dropdown #{dropdown_active?(stories_path)}", ui: :on
=r ux.icon 'leaf'
| Stories
=r ux.icon 'dropdown'
=r ux.menu
= link_to stories_path(scope: :unpublished), class: "item"
| Unpublished
=r ux.divider
= link_to stories_path(scope: :published), class: "item"
| Published
=r ux.divider
= link_to stories_path, class: "item"
| All

= link_to discussions_path, class: "item #{menu_active?(discussions_path)}"
=r ux.icon 'comments'
Expand Down