Skip to content

Commit

Permalink
🧹 Start futzing with a TextBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
zspencer committed Mar 28, 2024
1 parent c8b7267 commit 2e0dcd4
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 52 deletions.
19 changes: 0 additions & 19 deletions app/controllers/slots_controller.rb

This file was deleted.

5 changes: 5 additions & 0 deletions app/furniture/text_block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class TextBlock < ApplicationRecord
belongs_to :slot
has_one :section, through: :slot
has_one :space, through: :section
end
11 changes: 11 additions & 0 deletions app/furniture/text_block/text_block_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class TextBlock
class TextBlockPolicy < ApplicationPolicy
alias_method :text_block, :object
def create?
current_person.member_of?(text_block.space)
end

class Scope < ApplicationScope
end
end
end
Empty file.
10 changes: 10 additions & 0 deletions app/furniture/text_block/text_blocks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class TextBlock
class TextBlocksController < ApplicationController
expose :text_block, scope: -> { policy_scope(TextBlock, policy_scope_class: TextBlockPolicy::Scope) }, model: TextBlock,
build: ->(params, scope) { scope.new(params.merge(slottable: slottable)) }

def new
authorize(text_block, policy_class: TextBlockPolicy)
end
end
end
Empty file added app/lib/appends_routes.rb
Empty file.
2 changes: 1 addition & 1 deletion app/lib/space_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def self.append_routes(router)
router.resources :rooms, only: %i[show edit update new create destroy] do
Furniture.append_routes(router)
router.resources :furnitures, only: %i[create edit update destroy]
router.resources :slots, only: %i[new create]
router.resource :hero_image, controller: "room/hero_images"
router.resources :text_block, controller: "text_block/text_blocks"
end

router.resources :utilities
Expand Down
1 change: 0 additions & 1 deletion app/models/furniture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# as JSON, so that {Furniture} can be tweaked and configured as appropriate for
# it's particular use case.
class Furniture < ApplicationRecord
include RankedModel
location(parent: :room)

include RankedModel
Expand Down
3 changes: 3 additions & 0 deletions app/models/section.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Section < Room

end
1 change: 1 addition & 0 deletions app/models/slot.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Slot < ApplicationRecord
belongs_to :section, class_name: "Room", inverse_of: :slots
self.location_parent = :section
has_one :space, through: :section

belongs_to :slottable, polymorphic: true, inverse_of: :slot
Expand Down
6 changes: 2 additions & 4 deletions app/views/rooms/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
<h2>Gizmos (but lighter)</h2>
<%- end %>
<%- card.with_footer(variant: :action_bar) do%>
<%= link_to "Add a Slottable", room.location(:new, child: :slot),
class: "button w-full" %>
<%- end %>
<%= link_to "Add Text Block", room.location(:new, child: :text_block), class: "button"%>
<%- end %>
<%- end %>
<div class="mt-3 gap-y-3">
Expand Down
5 changes: 0 additions & 5 deletions app/views/slots/new.html.erb

This file was deleted.

7 changes: 7 additions & 0 deletions db/migrate/20240328004901_create_text_blocks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CreateTextBlocks < ActiveRecord::Migration[7.1]
def change
create_table :text_blocks, id: :uuid do |t|
t.timestamps
end
end
end
49 changes: 27 additions & 22 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_03_14_003612) do
ActiveRecord::Schema[7.1].define(version: 2024_03_28_004901) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"

create_enum :invitation_status, [
"pending",
"sent",
"accepted",
"rejected",
"expired",
"ignored",
"revoked",
"sent",
], force: :cascade

create_enum :membership_status, [
Expand Down Expand Up @@ -87,7 +87,7 @@
t.integer "sluggable_id", null: false
t.string "sluggable_type", limit: 50
t.string "scope"
t.datetime "created_at", precision: nil
t.datetime "created_at"
t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true
t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type"
t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id"
Expand Down Expand Up @@ -291,7 +291,7 @@
t.string "email", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "operator", default: false
t.boolean "operator", default: false, null: false
t.index ["email"], name: "index_people_on_email", unique: true
end

Expand Down Expand Up @@ -344,6 +344,11 @@
t.index ["slug", "client_id"], name: "index_spaces_on_slug_and_client_id", unique: true
end

create_table "text_blocks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "utility_hookups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "space_id"
t.string "name", null: false
Expand All @@ -355,29 +360,29 @@
t.index ["space_id"], name: "index_utility_hookups_on_space_id"
end

add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "journal_entries", "furnitures", column: "journal_id"
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id", validate: false
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id", validate: false
add_foreign_key "journal_entries", "furnitures", column: "journal_id", validate: false
add_foreign_key "journal_keywords", "furnitures", column: "journal_id"
add_foreign_key "marketplace_cart_products", "marketplace_orders", column: "cart_id"
add_foreign_key "marketplace_cart_products", "marketplace_products", column: "product_id"
add_foreign_key "marketplace_delivery_areas", "furnitures", column: "marketplace_id"
add_foreign_key "marketplace_notification_methods", "furnitures", column: "marketplace_id"
add_foreign_key "marketplace_orders", "marketplace_delivery_areas", column: "delivery_area_id"
add_foreign_key "marketplace_orders", "marketplace_shoppers", column: "shopper_id"
add_foreign_key "marketplace_cart_products", "marketplace_orders", column: "cart_id", validate: false
add_foreign_key "marketplace_cart_products", "marketplace_products", column: "product_id", validate: false
add_foreign_key "marketplace_delivery_areas", "furnitures", column: "marketplace_id", validate: false
add_foreign_key "marketplace_notification_methods", "furnitures", column: "marketplace_id", validate: false
add_foreign_key "marketplace_orders", "marketplace_delivery_areas", column: "delivery_area_id", validate: false
add_foreign_key "marketplace_orders", "marketplace_shoppers", column: "shopper_id", validate: false
add_foreign_key "marketplace_product_tags", "marketplace_products", column: "product_id"
add_foreign_key "marketplace_product_tags", "marketplace_tags", column: "tag_id"
add_foreign_key "marketplace_product_tax_rates", "marketplace_products", column: "product_id"
add_foreign_key "marketplace_product_tax_rates", "marketplace_tax_rates", column: "tax_rate_id"
add_foreign_key "marketplace_products", "furnitures", column: "marketplace_id"
add_foreign_key "marketplace_shoppers", "people"
add_foreign_key "marketplace_tax_rates", "furnitures", column: "marketplace_id"
add_foreign_key "marketplace_tax_rates", "spaces", column: "bazaar_id"
add_foreign_key "marketplace_product_tax_rates", "marketplace_products", column: "product_id", validate: false
add_foreign_key "marketplace_product_tax_rates", "marketplace_tax_rates", column: "tax_rate_id", validate: false
add_foreign_key "marketplace_products", "furnitures", column: "marketplace_id", validate: false
add_foreign_key "marketplace_shoppers", "people", validate: false
add_foreign_key "marketplace_tax_rates", "furnitures", column: "marketplace_id", validate: false
add_foreign_key "marketplace_tax_rates", "spaces", column: "bazaar_id", validate: false
add_foreign_key "marketplace_vendor_representatives", "furnitures", column: "marketplace_id"
add_foreign_key "marketplace_vendor_representatives", "people"
add_foreign_key "memberships", "invitations"
add_foreign_key "memberships", "invitations", validate: false
add_foreign_key "rooms", "media", column: "hero_image_id"
add_foreign_key "slots", "rooms", column: "section_id"
add_foreign_key "space_agreements", "spaces"
add_foreign_key "spaces", "rooms", column: "entrance_id"
add_foreign_key "space_agreements", "spaces", validate: false
add_foreign_key "spaces", "rooms", column: "entrance_id", validate: false
end
4 changes: 4 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@
)
journal = FactoryBot.create(:journal, room: journal_section)
FactoryBot.create_list(:journal_entry, 7, :with_keywords, :published, journal:)

_content_block_section = FactoryBot.create(:room, space:, name: "Content Block-o-Clock",
description: "Content Blocks show static Words, Photos, or Videos!"
)
2 changes: 2 additions & 0 deletions spec/system/slots_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "rails_helper"

RSpec.describe "Slots" do
include ActionText::SystemTestHelper

let(:space) { create(:space, :with_members) }
let(:section) { create(:room, space:) }

Expand Down

0 comments on commit 2e0dcd4

Please sign in to comment.