From 6bd0e4c1de3979f0d6a462b0a76bf79089350274 Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Wed, 22 Nov 2023 12:11:12 +0000 Subject: [PATCH] Add global property to Doodads --- app/assets/stylesheets/application.css.sass | 5 +++-- app/controllers/application_controller.rb | 5 +++++ app/controllers/doodads_controller.rb | 2 +- app/views/doodads/_form.html.haml | 1 + app/views/doodads/show.html.haml | 4 ++++ app/views/layouts/_footer.html.haml | 3 +++ db/migrate/20231122115709_add_is_global_to_doodads.rb | 5 +++++ db/schema.rb | 3 ++- 8 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20231122115709_add_is_global_to_doodads.rb diff --git a/app/assets/stylesheets/application.css.sass b/app/assets/stylesheets/application.css.sass index 41c75010..01877ba1 100644 --- a/app/assets/stylesheets/application.css.sass +++ b/app/assets/stylesheets/application.css.sass @@ -31,6 +31,7 @@ p h1 font-size: 7vmin margin-bottom: 0 + padding-left: .33em font-family: "Press Start 2P", "Anton", Impact, fantasy, sans-serif // h2 @@ -76,9 +77,9 @@ header border-radius: 0 13em 0 0 font-size: 2em > h1 - padding-top: .6em align-self: start - text-indent: .4em + // padding-top: .6em + // text-indent: .4em #home-headline, .home-headline diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0fda6566..1e3d44ca 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base # skip_before_action :verify_authenticity_token after_action :flash_to_http_header before_action :get_footer_tokens + before_action :get_global_doodads if (Rails.env.development? || Rails.env.test?) include Pundit::Authorization @@ -43,6 +44,10 @@ class ApplicationController < ActionController::Base @footer_tokens = policy_scope(Token) end + def get_global_doodads + @global_doodads = policy_scope(Doodad).where(is_global: true) + end + def flash_to_http_header return unless request.xhr? return if flash.empty? diff --git a/app/controllers/doodads_controller.rb b/app/controllers/doodads_controller.rb index 53f8ff66..eff29704 100644 --- a/app/controllers/doodads_controller.rb +++ b/app/controllers/doodads_controller.rb @@ -68,6 +68,6 @@ class DoodadsController < ApplicationController # Only allow a list of trusted parameters through. def doodad_params - params.require(:doodad).permit(:body, :user_id, :is_public) + params.require(:doodad).permit(:body, :user_id, :is_public, :is_global) end end diff --git a/app/views/doodads/_form.html.haml b/app/views/doodads/_form.html.haml index 92ed62d3..0807319b 100644 --- a/app/views/doodads/_form.html.haml +++ b/app/views/doodads/_form.html.haml @@ -5,6 +5,7 @@ = f.input :body = f.hidden_field :user_id = f.input :is_public + = f.input :is_global .form-actions = f.button :submit diff --git a/app/views/doodads/show.html.haml b/app/views/doodads/show.html.haml index 8548ac36..998a5ceb 100644 --- a/app/views/doodads/show.html.haml +++ b/app/views/doodads/show.html.haml @@ -9,6 +9,10 @@ %p %b Is public: = @doodad.is_public +%p + %b Is global: + = @doodad.is_global + = link_to 'Edit', edit_doodad_path(@doodad) if policy(@doodad).edit? \| diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 4b5b6f14..9982748d 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -4,3 +4,6 @@ %h3 Tokens - @footer_tokens.each do |token| = link_to token.name, token +.global-doodads + %h1 Global Doodads + = render @global_doodads diff --git a/db/migrate/20231122115709_add_is_global_to_doodads.rb b/db/migrate/20231122115709_add_is_global_to_doodads.rb new file mode 100644 index 00000000..e3b1ca21 --- /dev/null +++ b/db/migrate/20231122115709_add_is_global_to_doodads.rb @@ -0,0 +1,5 @@ +class AddIsGlobalToDoodads < ActiveRecord::Migration[6.1] + def change + add_column :doodads, :is_global, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 3e259abb..6c191d46 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_11_21_150256) do +ActiveRecord::Schema.define(version: 2023_11_22_115709) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -30,6 +30,7 @@ ActiveRecord::Schema.define(version: 2023_11_21_150256) do t.boolean "is_public" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "is_global", default: false t.index ["user_id"], name: "index_doodads_on_user_id" end