Skip to content

Commit

Permalink
819 replace page text with custom page (#854)
Browse files Browse the repository at this point in the history
* replace all occurances of page text with custom page

* fix unintended changes to migration files

* change missed instances of PageText

* change view folder name to custom pages

* nested module/classes for custom pages controller

* updated files that got missed for custom page change

* ran linter
  • Loading branch information
Trevor-Robinson authored Jul 3, 2024
1 parent feb4cb1 commit 5d8513c
Show file tree
Hide file tree
Showing 37 changed files with 133 additions and 123 deletions.
2 changes: 1 addition & 1 deletion app/controllers/organizations/adoptable_pets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def index
end

def show
@adoptable_pet_info = PageText.first&.adoptable_pet_info
@adoptable_pet_info = CustomPage.first&.adoptable_pet_info
@pet = Pet.find(params[:id])
authorize! @pet, with: Organizations::AdoptablePetPolicy

Expand Down
29 changes: 29 additions & 0 deletions app/controllers/organizations/staff/custom_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Organizations
module Staff
class CustomPagesController < Organizations::BaseController
layout "dashboard"
before_action :set_custom_page, only: %i[edit update]
def edit
end

def update
if @custom_page.update(custom_page_params)
redirect_to edit_staff_custom_page_path, notice: t(".success")
else
redirect_to edit_staff_custom_page_path, alert: @custom_page.errors.full_messages.to_sentence
end
end

private

def custom_page_params
params.require(:custom_page).permit(:hero, :about, :hero_image, :adoptable_pet_info, about_us_images: [])
end

def set_custom_page
@custom_page = CustomPage.first
authorize! @custom_page
end
end
end
end
25 changes: 0 additions & 25 deletions app/controllers/organizations/staff/page_texts_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/concerns/authorizable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
activate_staff
invite_staff
manage_organization_profile
manage_page_text
manage_custom_page
manage_staff
change_user_roles
]
Expand Down
6 changes: 3 additions & 3 deletions app/models/page_text.rb → app/models/custom_page.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# == Schema Information
#
# Table name: page_texts
# Table name: custom_pages
#
# id :bigint not null, primary key
# about :text
Expand All @@ -12,13 +12,13 @@
#
# Indexes
#
# index_page_texts_on_organization_id (organization_id)
# index_custom_pages_on_organization_id (organization_id)
#
# Foreign Keys
#
# fk_rails_... (organization_id => organizations.id)
#
class PageText < ApplicationRecord
class CustomPage < ApplicationRecord
acts_as_tenant(:organization)

has_one_attached :hero_image
Expand Down
2 changes: 1 addition & 1 deletion app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ class Organization < ApplicationRecord

has_one :profile, dependent: :destroy, class_name: "OrganizationProfile", required: true
has_one :location, through: :profile
has_one :page_text, dependent: :destroy
has_one :custom_page, dependent: :destroy
end
8 changes: 8 additions & 0 deletions app/policies/organizations/custom_page_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Organizations::CustomPagePolicy < ApplicationPolicy
pre_check :verify_organization!
pre_check :verify_active_staff!

def manage?
permission?(:manage_custom_page)
end
end
8 changes: 0 additions & 8 deletions app/policies/organizations/page_text_policy.rb

This file was deleted.

6 changes: 3 additions & 3 deletions app/services/organizations/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def signal(args)
create_staff_account
add_admin_role_to_staff_account
send_email
create_page_text
create_custom_page
end
rescue => e
raise "An error occurred: #{e.message}"
Expand Down Expand Up @@ -102,9 +102,9 @@ def send_email
.create_new_org_and_admin(@organization.slug).deliver_now
end

def create_page_text
def create_custom_page
ActsAsTenant.with_tenant(@organization) do
PageText.create!
CustomPage.create!
end
end
end
4 changes: 2 additions & 2 deletions app/views/layouts/dashboard/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
<% end %>
</li>
<li class="nav-item">
<%= active_link_to edit_staff_page_text_path(@page_text), class: "nav-link" do %>
<i class="nav-icon fe fe-file-text me-2"></i>Page Text
<%= active_link_to edit_staff_custom_page_path(@custom_page), class: "nav-link" do %>
<i class="nav-icon fe fe-file-text me-2"></i>Custom Page
<% end %>
</li>
<li class="nav-item">
Expand Down
14 changes: 7 additions & 7 deletions app/views/organizations/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<section id="hero">
<div class="bg-image" style="background-image: url('<%= Current.organization.page_text&.hero_image&.attached? ? url_for(Current.organization.page_text.hero_image) : asset_path('dog-run.png') %>'); background-position: center; background-size: cover;">
<div class="bg-image" style="background-image: url('<%= Current.organization.custom_page&.hero_image&.attached? ? url_for(Current.organization.custom_page.hero_image) : asset_path('dog-run.png') %>'); background-position: center; background-size: cover;">
<div class="mask py-lg-16 py-5" style="background-color: rgba(255, 255, 255, 0.8);">
<div class="container">
<div class="d-flex row justify-content-center align-items-center">
<div class="d-flex justify-content-center">
<h1 class="display-2 fw-bold mb-1 text-primary "><%= Current.organization.name %></h1>
</div>
<div class="d-flex justify-content-center">
<p class="lead mb-4 text-black"><%= Current.organization.page_text&.hero || "Where every paw finds a home" %></p>
<p class="lead mb-4 text-black"><%= Current.organization.custom_page&.hero || "Where every paw finds a home" %></p>
</div>
<div class="d-flex justify-content-center">
<%= link_to '#', class: "btn btn-dark btn-lg rounded-1 me-2" do %>
Expand Down Expand Up @@ -134,8 +134,8 @@
<div class="row pb-3">
<div class="col-lg-4 col-md-6 mb-4 mb-lg-0">
<span class="ratio ratio-1x1 w-100 border border-0">
<% if Current.organization.page_text.about_us_images.attached? && Current.organization.page_text.about_us_images.count > 0 %>
<%= image_tag(Current.organization.page_text.about_us_images.first,
<% if Current.organization.custom_page.about_us_images.attached? && Current.organization.custom_page.about_us_images.count > 0 %>
<%= image_tag(Current.organization.custom_page.about_us_images.first,
class: 'rounded-5 w-100 px-4 px-lg-0', style: "object-fit: cover;") %>
<% else %>
<%= image_tag('danielle_2.jpg', class: 'rounded-5 w-100 px-4 px-lg-0',
Expand All @@ -145,13 +145,13 @@
</div>
<div class="col-lg-4 px-4 order-last order-lg-0">
<p class='justify bigger'>
<%= Current.organization.page_text&.about || "#{Current.organization.name} was founded by an incredible group of ladies in April of 2020. Our initial goal was to have both a rescue and a spay/neuter clinic, however, we quickly realized that it would be more efficient to separate into two organizations." %>
<%= Current.organization.custom_page&.about || "#{Current.organization.name} was founded by an incredible group of ladies in April of 2020. Our initial goal was to have both a rescue and a spay/neuter clinic, however, we quickly realized that it would be more efficient to separate into two organizations." %>
</p>
</div>
<div class="col-lg-4 col-md-6 d-none d-md-block mb-4 mb-lg-0">
<span class="ratio ratio-1x1 w-100 border border-0">
<% if Current.organization.page_text.about_us_images.attached? && Current.organization.page_text.about_us_images.count >= 2 %>
<%= image_tag(Current.organization.page_text.about_us_images.second,
<% if Current.organization.custom_page.about_us_images.attached? && Current.organization.custom_page.about_us_images.count >= 2 %>
<%= image_tag(Current.organization.custom_page.about_us_images.second,
class: 'w-100 rounded-5 px-4 px-lg-0', style: "object-fit: cover;") %>
<% else %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= bootstrap_form_with model: page_text, :url => staff_page_text_path(@page_text), method: :patch do |form| %>
<%= bootstrap_form_with model: custom_page, :url => staff_custom_page_path(@custom_page), method: :patch do |form| %>
<div class='card-body'>
<div class="d-lg-flex align-items-center justify-content-between">
<h3 class="mb-1">Landing page details</h3>
Expand All @@ -7,7 +7,7 @@
</div>
<div class="row mt-3">
<div class="col-lg-6">
<%= form.fields_for :page_text do |page_text_form| %>
<%= form.fields_for :custom_page do |custom_page_form| %>
<div class="form-group">
<%= form.text_field :hero,
label: "Hero",
Expand All @@ -30,7 +30,7 @@
accept: 'image/png, image/jpeg',
label: "About Us Images",
class: 'form-control' %>
<% @page_text.about_us_images.each do |image| %>
<% @custom_page.about_us_images.each do |image| %>
<%= form.hidden_field :about_us_images, multiple: true, value: image.signed_id %>
<% end %>
<small class="form-text text-muted">You can upload up to 2 images. <br> Images must be .png or .jpeg under 2MB </small>
Expand All @@ -51,6 +51,6 @@
<div class="mt-5">
<div class="mt-5">
<div class="mt-5">
<%= render ImageAttachmentTableComponent.new(images: @page_text.images) %>
<%= render ImageAttachmentTableComponent.new(images: @custom_page.images) %>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<%= render DashboardPageComponent.new(crumb: :page_text) do |c| %>
<% c.with_header_title { "Page Text" } %>

<%= render DashboardPageComponent.new(crumb: :custom_page) do |c| %>
<% c.with_header_title { "Custom Page" } %>
<% c.with_header_subtitle { "Edit your page" } %>
<% c.with_body do %>
<section id="account_select">
<div>
<div>
<%= render "form", page_text: @page_text %>
<%= render "form", custom_page: @custom_page %>
</div>
</div>
</section>
Expand Down
4 changes: 2 additions & 2 deletions config/breadcrumbs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
link "Edit Profile", edit_staff_organization_profile_path(organization)
end

crumb :page_text do |page_text|
link "Edit Page Text", edit_staff_page_text_path(page_text)
crumb :custom_page do |custom_page|
link "Edit Custom Page", edit_staff_custom_page_path(custom_page)
end

crumb :staff_index do
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ en:
complete?: "Show Completed"
destroy:
success: "Task was successfully deleted."
page_texts:
custom_pages:
update:
success: "Page text updated successfully!"
matches:
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace :staff do
resource :organization_profile, only: %i[edit update]
resource :page_text, only: %i[edit update]
resource :custom_page, only: %i[edit update]
resources :profile_reviews, only: [:show]

resources :pets do
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20240225160909_create_page_texts.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreatePageTexts < ActiveRecord::Migration[7.0]
class CreateCustomPages < ActiveRecord::Migration[7.0]
def change
create_table :page_texts do |t|
t.references :organization, null: false, foreign_key: true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddAdoptablePetInfoToPageTexts < ActiveRecord::Migration[7.1]
class AddAdoptablePetInfoToCustomPages < ActiveRecord::Migration[7.1]
def change
add_column :page_texts, :adoptable_pet_info, :text
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeCustomPagesToCustomPages < ActiveRecord::Migration[7.1]
def change
rename_table :page_texts, :custom_pages
end
end
24 changes: 12 additions & 12 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion db/seeds/01_alta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name: "Alta Pet Rescue",
slug: "alta",
profile: OrganizationProfile.new(email: "alta@email.com", phone_number: "250 816 8212", location: orga_location),
page_text: PageText.new(hero: "Where every paw finds a home", about: "Alta was founded by an incredible group of ladies in April of 2020. Our initial goal was to have both a rescue and a spay/neuter clinic, however, we quickly realized that it would be more efficient to separate into two organizations.")
custom_page: CustomPage.new(hero: "Where every paw finds a home", about: "Alta was founded by an incredible group of ladies in April of 2020. Our initial goal was to have both a rescue and a spay/neuter clinic, however, we quickly realized that it would be more efficient to separate into two organizations.")
)

ActsAsTenant.with_tenant(@organization) do
Expand Down
2 changes: 1 addition & 1 deletion db/seeds/02_baja.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name: "Baja",
slug: "baja",
profile: OrganizationProfile.new(email: "baja@email.com", phone_number: "250 816 8212", location: orga_location),
page_text: PageText.new(hero: "hero text", about: "about us text")
custom_page: CustomPage.new(hero: "hero text", about: "about us text")
)

ActsAsTenant.with_tenant(@organization) do
Expand Down
6 changes: 3 additions & 3 deletions test/components/image_attachment_table_component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class ImageAttachmentTableComponentTest < ViewComponent::TestCase
setup do
ActiveStorage::Current.url_options = {host: "localhost", port: 3000}

page_text = create(:page_text, :with_about_us_image)
@component = ImageAttachmentTableComponent.new(images: page_text.images)
@image = page_text.images[0]
custom_page = create(:custom_page, :with_about_us_image)
@component = ImageAttachmentTableComponent.new(images: custom_page.images)
@image = custom_page.images[0]

render_inline(@component)
end
Expand Down
Loading

0 comments on commit 5d8513c

Please sign in to comment.