From f88f97ea7c90f6a422c115f225998b6772912547 Mon Sep 17 00:00:00 2001 From: Leonid Medovyy Date: Fri, 21 Jul 2023 07:27:01 -0700 Subject: [PATCH 1/2] adjusting styling --- app/frontend/stylesheets/admin/menu.sass | 2 +- app/models/discussion.rb | 2 +- app/views/discussions/index.html.slim | 5 ----- app/views/feeds/index.html.slim | 5 ----- app/views/imaginations/index.html.slim | 5 ----- app/views/layouts/application.html.slim | 22 ++++++++++++++++------ app/views/page/index.html.slim | 5 ----- app/views/stories/index.html.slim | 5 ----- app/views/tags/index.html.slim | 5 ----- app/views/tweets/index.html.slim | 5 ----- 10 files changed, 18 insertions(+), 43 deletions(-) diff --git a/app/frontend/stylesheets/admin/menu.sass b/app/frontend/stylesheets/admin/menu.sass index ef92ad8..e8b9c1e 100644 --- a/app/frontend/stylesheets/admin/menu.sass +++ b/app/frontend/stylesheets/admin/menu.sass @@ -1,5 +1,5 @@ .segment.basic.menu-wrapper - padding: 0.8em 0 1.7em + padding: 0.4em 0 1.3em .ui.container, .column diff --git a/app/models/discussion.rb b/app/models/discussion.rb index c5c6b38..9ac363a 100644 --- a/app/models/discussion.rb +++ b/app/models/discussion.rb @@ -60,5 +60,5 @@ class Discussion < ApplicationRecord } scope :published, -> { where(uploaded: true) } - scope :unpublished, -> { where(uploaded: false, invalid_json: false, processed: true) } + scope :unpublished, -> { ready_to_upload } end diff --git a/app/views/discussions/index.html.slim b/app/views/discussions/index.html.slim index dfd7c49..79d4a8c 100644 --- a/app/views/discussions/index.html.slim +++ b/app/views/discussions/index.html.slim @@ -1,11 +1,6 @@ =r ux.container =r ux.row =r ux.column width: 16 - =r ux.segment 'basic' - =r ux.text class: 'text-center', text: '🔒 This page is protected by devise. You can only see it if you are logged in & authorized. 🔒' - - =r ux.divider - =r ux.h2 'center aligned !font-mono' | Discussions =r ux.label text: @total_discussions, class: 'circular !bg-black !text-white' diff --git a/app/views/feeds/index.html.slim b/app/views/feeds/index.html.slim index d5c353d..00d79a4 100644 --- a/app/views/feeds/index.html.slim +++ b/app/views/feeds/index.html.slim @@ -1,11 +1,6 @@ =r ux.container =r ux.row =r ux.column width: 16 - =r ux.segment 'basic' - =r ux.text class: 'text-center', text: '🔒 This page is protected by devise. You can only see it if you are logged in & authorized. 🔒' - - =r ux.divider - =r ux.h2 'center aligned !font-mono' | Feeds =r ux.label text: @total_feeds, class: 'circular !bg-black !text-white' diff --git a/app/views/imaginations/index.html.slim b/app/views/imaginations/index.html.slim index fffc515..6f04828 100644 --- a/app/views/imaginations/index.html.slim +++ b/app/views/imaginations/index.html.slim @@ -1,11 +1,6 @@ =r ux.container =r ux.row =r ux.column width: 16 - =r ux.segment 'basic' - =r ux.text class: 'text-center', text: '🔒 This page is protected by devise. You can only see it if you are logged in & authorized. 🔒' - - =r ux.divider - =r ux.h2 'center aligned !font-mono' | Imaginations =r ux.label text: @total_imaginations, class: 'circular !bg-black !text-white' diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index 444a694..bd442ae 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -32,11 +32,11 @@ html lang="en" =r ux.grid =r ux.row 'menu' =r ux.column size: 16 - =r ux.menu ui: :on, class: 'inverted tiny black internal !bg-zinc-900 !font-mono', controller: 'dropdown' + =r ux.menu ui: :on, class: 'inverted mini 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' - =r ux.item class: "top right pointing dropdown #{dropdown_active?(stories_path)}", ui: :on + =r ux.item class: "dropdown #{dropdown_active?(stories_path)}", ui: :on =r ux.icon 'leaf' | Stories =r ux.icon 'dropdown' @@ -50,7 +50,7 @@ html lang="en" = link_to stories_path, class: "item" | All - =r ux.item class: "top right pointing dropdown #{dropdown_active?(discussions_path)}", ui: :on + =r ux.item class: "dropdown #{dropdown_active?(discussions_path)}", ui: :on =r ux.icon 'comments' | Discussions =r ux.icon 'dropdown' @@ -64,10 +64,20 @@ html lang="en" = link_to discussions_path, class: "item" | All - - = link_to tweets_path, class: "item #{menu_active?(tweets_path)}" + =r ux.item class: "dropdown #{dropdown_active?(tweets_path)}", ui: :on =r ux.icon 'twitter' | Tweets + =r ux.icon 'dropdown' + =r ux.menu + = link_to tweets_path(scope: :unpublished), class: "item" + | Unpublished + =r ux.divider + = link_to tweets_path(scope: :published), class: "item" + | Published + =r ux.divider + = link_to tweets_path, class: "item" + | All + = link_to imaginations_path, class: "item #{menu_active?(imaginations_path)}" =r ux.icon 'image' @@ -84,7 +94,7 @@ html lang="en" = link_to tags_path, class: "item" =r ux.icon 'tags' | Tags - =r ux.item class: 'top right pointing dropdown', ui: :on + =r ux.item class: 'dropdown', ui: :on = current_user.email =r ux.icon 'dropdown' =r ux.menu diff --git a/app/views/page/index.html.slim b/app/views/page/index.html.slim index 2af081b..724098e 100644 --- a/app/views/page/index.html.slim +++ b/app/views/page/index.html.slim @@ -1,11 +1,6 @@ =r ux.container =r ux.row =r ux.column width: 16 - =r ux.segment 'basic' - =r ux.text class: 'text-center', text: '🔒 This page is protected by devise. You can only see it if you are logged in & authorized. 🔒' - - =r ux.divider - =r ux.h2 'center aligned !font-mono !mb-8' | Topics =r ux.label text: @topics.count, class: 'circular !bg-black !text-white' diff --git a/app/views/stories/index.html.slim b/app/views/stories/index.html.slim index 87baeae..938a1f8 100644 --- a/app/views/stories/index.html.slim +++ b/app/views/stories/index.html.slim @@ -1,11 +1,6 @@ =r ux.container =r ux.row =r ux.column width: 16 - =r ux.segment 'basic' - =r ux.text class: 'text-center', text: '🔒 This page is protected by devise. You can only see it if you are logged in & authorized. 🔒' - - =r ux.divider - =r ux.h2 'center aligned !font-mono' | Stories =r ux.label text: @total_stories, class: 'circular !bg-black !text-white' diff --git a/app/views/tags/index.html.slim b/app/views/tags/index.html.slim index 6adbb37..e982b70 100644 --- a/app/views/tags/index.html.slim +++ b/app/views/tags/index.html.slim @@ -1,11 +1,6 @@ =r ux.container =r ux.row =r ux.column width: 16 - =r ux.segment 'basic' - =r ux.text class: 'text-center', text: '🔒 This page is protected by devise. You can only see it if you are logged in & authorized. 🔒' - - =r ux.divider - =r ux.h2 'center aligned !font-mono' | Tags =r ux.label text: @total_tags, class: 'circular !bg-black !text-white' diff --git a/app/views/tweets/index.html.slim b/app/views/tweets/index.html.slim index 649544f..1b11c8b 100644 --- a/app/views/tweets/index.html.slim +++ b/app/views/tweets/index.html.slim @@ -1,11 +1,6 @@ =r ux.container =r ux.row =r ux.column width: 16 - =r ux.segment 'basic' - =r ux.text class: 'text-center', text: '🔒 This page is protected by devise. You can only see it if you are logged in & authorized. 🔒' - - =r ux.divider - =r ux.h2 'center aligned !font-mono' | Tweets =r ux.label text: @total_tweets, class: 'circular !bg-black !text-white' From ea1841cbbbaf46fc6f67774b6bdcd368700916fc Mon Sep 17 00:00:00 2001 From: Leonid Medovyy Date: Fri, 21 Jul 2023 08:24:26 -0700 Subject: [PATCH 2/2] updated approval workflow & added filters --- app/controllers/tweets_controller.rb | 22 ++++++++++++++++++++-- app/models/tweet.rb | 8 ++++++++ app/views/layouts/application.html.slim | 10 ++++++++-- app/views/tweets/_tweet.html.slim | 3 ++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb index 85dcf6e..065808c 100644 --- a/app/controllers/tweets_controller.rb +++ b/app/controllers/tweets_controller.rb @@ -1,8 +1,10 @@ class TweetsController < ApplicationController include RestrictedAccess def index - @tweets = Tweet.all.order(id: :desc).page params[:page] - @total_tweets = Tweet.all.count + scope = set_scope + + @tweets = Tweet.send(scope).order(id: :desc).page params[:page] + @total_tweets = Tweet.send(scope).count end def show @@ -47,4 +49,20 @@ def disapprove @tweet.update(approved: false) redirect_to tweet_path(@tweet) end + + private + + def set_scope + if params[:scope] && params[:scope] == 'pending' + return 'needs_approval' + elsif params[:scope] && params[:scope] == 'approved' + return 'approved_tweets' + elsif params[:scope] && params[:scope] == 'denied' + return 'denied' + elsif params[:scope] && params[:scope] == 'published' + return 'published' + end + + 'all' + end end diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 65f7b1f..75e855f 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -15,4 +15,12 @@ # class Tweet < ApplicationRecord belongs_to :discussion + + scope :needs_approval, -> { where(approved: nil, uploaded: false, invalid_json: false) } + + scope :approved_tweets, -> { where(approved: true) } + + scope :denied, -> { where(approved: false) } + + scope :published, -> { where(uploaded: true) } end diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index bd442ae..4879e9f 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -69,8 +69,14 @@ html lang="en" | Tweets =r ux.icon 'dropdown' =r ux.menu - = link_to tweets_path(scope: :unpublished), class: "item" - | Unpublished + = link_to tweets_path(scope: :pending), class: "item" + | Pending + =r ux.divider + = link_to tweets_path(scope: :approved), class: "item" + | Approved + =r ux.divider + = link_to tweets_path(scope: :denied), class: "item" + | Denied =r ux.divider = link_to tweets_path(scope: :published), class: "item" | Published diff --git a/app/views/tweets/_tweet.html.slim b/app/views/tweets/_tweet.html.slim index dc1f7d4..16fa74f 100644 --- a/app/views/tweets/_tweet.html.slim +++ b/app/views/tweets/_tweet.html.slim @@ -13,7 +13,8 @@ = turbo_frame_tag frame_id =r ux.code - unless tweet.invalid_json - = highlight_hashtags(JSON.parse(tweet.stem)['tweet']) + = link_to edit_tweet_path(tweet), class: 'no-underline' + = highlight_hashtags(JSON.parse(tweet.stem)['tweet']) - else .text-red-700 | We could not generate the tweet automatically. Please click `edit` to manually create it.