Skip to content

Commit

Permalink
Update with Image frontend buttons (#618)
Browse files Browse the repository at this point in the history
* Update with Image frontend buttons

* Update with validations to model file

* Bump debug from 1.9.1 to 1.9.2

Bumps [debug](https://github.com/ruby/debug) from 1.9.1 to 1.9.2.
- [Release notes](https://github.com/ruby/debug/releases)
- [Commits](ruby/debug@v1.9.1...v1.9.2)

---
updated-dependencies:
- dependency-name: debug
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update images are saved but do not show yet

* Update images now render on the index page but in no way are correct

* Comment out section added to test to pass - THIS IS A TEMP THING THAT NEEDS TO BE UNDONE

* Comment out section added X2

* Update hero image rendering as it should

* docs: add jeevikasirwani as a contributor for code (#627)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* 590 parameterize contact mailer (#607)

* commit annotation change

* update contacts create route to use post and update url on contacts form

* add tests for contacts

* replace hardcoded url, add instance variable for org name to use in mailer

* replace current_tenant because it was coming up nil

* add scope to contact form and update controller action to use stong params

* update tests to use correct params format

* fix test desciptions

* Small policy and factory fixes (#625)

* Move constants outside of class

* Add active staff requirement to InvitationPolicy

* Correct StaffAccountPolicyTest file name

* Add active staff requirement to StaffAccountPolicy

* Refactor AdoptablePetPolicy rule to utilize allowed_to? instead of checking permissions directly to benefit from other policy's prechecks

* Fix pets factory traits to associate has_ relationship objects correctly

* Add relation_scope test for AdoptablePetPolicyTest

* Fix factory trait to work with build strategy

* docs: add jp524 as a contributor for code (#632)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* Staff Dashboard UI - Make hamburger functional to open/close sidebar (#631)

* Add toggle Stimulus controller

* Modify Geeks UI CSS

* Add Org ID to resources to scope them (#614)

Co-authored-by: Ben Robinson <[email protected]>

* Update with partial

* Update with Image frontend buttons

* Update with validations to model file

* Update images are saved but do not show yet

* Update images now render on the index page but in no way are correct

* Comment out section added to test to pass - THIS IS A TEMP THING THAT NEEDS TO BE UNDONE

* Comment out section added X2

* Update hero image rendering as it should

* Update with partial

* Update with changes to partial

* Update with a debuggin test

* Update with a debuggin test

* Update conflist clean up

* Schema error clean-up

* Syntax cleanup

* Syntax cleanup

* Update image upload causing major app error

* Syntax cleanup

* Error message for large file created

* Error message for large file created

* Merge conflict clean up

* Update to notification

* Cleanup of Readme

* Cleanup of Readme2

* Cleanup of conflict

* Cleanup of yml

* Cleanup of tests

* Removal of 'end'

* Update to test

* Update adjusted one test to pass

* Update with test passing locally

* Standardrb fix

* 1 of 5 failing tests on CI should pass

* Syntax cleanup

* Update more failing tests on CI should pass

* Update more failing tests on CI should pass

* Standard - fix

* Updated with hero text

* Updated routes

* Updated syntax and merge with main

* Updated with text

* Image add feature seems to work correctly

* Controller method updates

* Update with sytax fixes

* Update with test refactor

* Update with test refactor part 2

* Remove test changes in file

* Remove test changes in file

* Remove test changes in file

* Testing changes in tests

* Testing changes in tests

* Update test passing

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Co-authored-by: Alisa <[email protected]>
Co-authored-by: Ken Maeshima <[email protected]>
Co-authored-by: Jade <[email protected]>
Co-authored-by: Ben <[email protected]>
Co-authored-by: Ben Robinson <[email protected]>
  • Loading branch information
8 people authored May 1, 2024
1 parent ff77741 commit 9685fc4
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 66 deletions.
7 changes: 3 additions & 4 deletions app/controllers/organizations/page_texts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ def update
if @page_text.update(page_text_params)
redirect_to edit_page_text_path, notice: "Page text updated successfully!"
else
render :edit, status: :unprocessable_entity
redirect_to edit_page_text_path, alert: @page_text.errors.full_messages.to_sentence
end
end

private

def page_text_params
params.require(:page_text).permit(:hero, :about)
params.require(:page_text).permit(:hero, :about, :hero_image, about_us_images: [])
end

def set_page_text
@page_text = current_user.organization.page_text

@page_text = PageText.first
authorize! @page_text
end
end
11 changes: 11 additions & 0 deletions app/models/page_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
class PageText < ApplicationRecord
acts_as_tenant(:organization)

has_one_attached :hero_image
has_many_attached :about_us_images

validates :hero, presence: true, allow_nil: true
validates :about, presence: true, allow_nil: true

validates :hero_image, content_type: ["image/png", "image/jpeg"],
limit: {max: 1},
size: {less_than: 2.megabytes}

validates :about_us_images, content_type: ["image/png", "image/jpeg"],
limit: {max: 2},
size: {less_than: 2.megabytes}
end
3 changes: 1 addition & 2 deletions app/views/components/_attachment_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<%= bootstrap_form_with(model: instance, url: url, method: :post) do |form| %>
<div class='form-group mt-2 d-flex'>
<div class="flex-grow-1">
<%= form.file_field attachment_type.to_sym, multiple: true, direct_upload: true,
<%= form.file_field attachment_type.to_sym, multiple: true, direct_upload: true,
class: "custom-attachments",
hide_label: true %>
</div>
Expand All @@ -21,4 +21,3 @@
<% end %>
</div>
</div>

26 changes: 16 additions & 10 deletions app/views/components/_image_attachment_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,32 @@
</tr>
</thead>
<tbody>
<% if @pet.images.attached? %>
<% @pet.images.each do |image| %>
<% if images.any? %>
<% images.each do |image| %>
<tr>
<td>
<div class="d-flex align-items-center">
<div class="icon-shape img-4by3-lg rounded-3">
<%= link_to(image_tag(image, class: 'card-img'), rails_blob_path(image, disposition: 'attachment')) %>
<% if image.record.persisted? %>
<%= link_to(image_tag(image, class: 'card-img'), rails_blob_path(image, disposition: 'attachment')) %>
<% end %>
</div>
</div>
</td>
<td>
<%= link_to image.filename.to_s, rails_blob_path(image, disposition: 'attachment') %>
<% if image.record.persisted? %>
<%= link_to image.filename.to_s, rails_blob_path(image, disposition: 'attachment') %>
<% end %>
</td>
<td>
<%= link_to t('general.delete'),
purge_attachment_path(image.id),
data: {
turbo_confirm: "Do you want to delete this image?",
turbo_method: "delete" },
class: 'btn btn-outline-danger' %>
<% if image.record.persisted? %>
<%= link_to t('general.delete'),
purge_attachment_path(image.id),
data: {
turbo_confirm: 'Do you want to delete this image?',
turbo_method: "delete" },
class: 'btn btn-outline-danger' %>
<% end %>
</td>
</tr>
<% end %>
Expand Down
54 changes: 29 additions & 25 deletions app/views/organizations/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<section id="hero">
<div class="bg-image" style="background-image: url('<%= asset_path 'dog-run.png' %>'); background-position: center; background-size: cover;">
<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="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 ">
</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>
</div>
<div class="d-flex justify-content-center">
Expand Down Expand Up @@ -133,34 +133,38 @@
<!-- ABOUT US-->
<section class="bg-light pt-5 pb-5" id="about_us">
<div class="container mb-md-5 mt-md-5">

<!--section heading-->
<div class="text-center mb-5">
<h2 class="section-heading text-uppercase underline">
About us
</h2>
</div>

<div class="row pb-3">
<div class="col-lg-4 col-md-6 mb-4 mb-lg-0">
<span>
<%= image_tag('danielle_2.jpg',
class: 'rounded-5 w-100 px-4 px-lg-0') %>
</span>
</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."%>
</p>
<p class='text-center'>
<%= link_to 'Read More', about_us_path, class: 'custom-btn-green mt-5 mb-3' %>
</p>
</div>
<div class="col-lg-4 col-md-6 d-none d-md-block mb-4 mb-lg-0">
<span>
<%= image_tag('danielle_3.jpg', class: 'w-100 rounded-5 px-4 px-lg-0') %>
</span>
</div>
<div class="col-lg-4 col-md-6 mb-4 mb-lg-0">
<span>
<% 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, class: 'rounded-5 w-100 px-4 px-lg-0') %>
<% else %>
<%= image_tag('danielle_2.jpg', class: 'rounded-5 w-100 px-4 px-lg-0') %>
<% end %>
</span>
</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." %>
</p>
<p class='text-center'>
<%= link_to 'Read More', about_us_path, class: 'custom-btn-green mt-5 mb-3' %>
</p>
</div>
<div class="col-lg-4 col-md-6 d-none d-md-block mb-4 mb-lg-0">
<span>
<% 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, class: 'w-100 rounded-5 px-4 px-lg-0') %>
<% else %>
<%= image_tag('danielle_3.jpg', class: 'w-100 rounded-5 px-4 px-lg-0') %>
<% end %>
</span>
</div>
</div> <!--row-->
</div> <!--container-->
</section>
Expand Down
61 changes: 39 additions & 22 deletions app/views/organizations/page_texts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,51 @@
<div class="d-lg-flex align-items-center justify-content-between">
<h3 class="mb-1">Landing page details</h3>
<p class="text-muted mb-3" style="font-size: 12px;">Edit your landing page.
<p>
</p>
</div>
<div class="row mt-3">
<div class="col-lg-6">
<%= form.fields_for :page_text do |page_text_form| %>
<form class="mb-3">
<!-- Hero Text -->
<div class="form-group">
<%= form.text_field :hero,
label: "Hero",
autofocus: true,
placeholder: "hero text",
class: 'form-control' %>
</div>
<!-- About Us -->
<div class="form-group">
<%= form.text_area :about, label: "About Us", placeholder: "About Us text", class: 'form-control' %>
</div>
</form>
<div class="form-group">
<%= form.text_field :hero,
label: "Hero",
autofocus: true,
placeholder: "hero text",
class: 'form-control' %>
</div>
<div class="form-group">
<%= form.file_field :hero_image,
label: "Hero Image",
class: 'form-control'%>
</div>
<small class="form-text text-muted"> Images must be .png or .jpeg under 2MB </small>
<div class="form-group mt-4">
<%= form.text_area :about, label: "About Us", placeholder: "About Us text", class: 'form-control' %>
</div>
<div class="form-group">
<%= form.file_field :about_us_images,
multiple: true,
accept: 'image/png, image/jpeg',
label: "About Us Images",
class: 'form-control' %>
<% @page_text.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>
<% end %>
</div>
</div>
</div>
<div class="row mt-3">
<div class="col-lg-12">
<%= form.submit 'Save page text', class: 'btn btn-primary' %>
<%= link_to t('general.cancel'), :back, class: 'btn btn-outline-secondary' %>
<div class="row mt-3">
<div class="col-lg-12">
<%= form.submit 'Save page text/images', class: 'btn btn-primary' %>
<%= link_to t('general.cancel'), :back, class: 'btn btn-outline-secondary' %>
</div>
</div>
</div>
</div> <!-- End of Card Body -->
<div class="mt-5">
<div class="mt-5">
<div class="mt-5">
<% combined_images = [@page_text.hero_image.attachment, @page_text.about_us_images].flatten.compact%>
<%= render partial: "components/image_attachment_table", locals: { images: combined_images } %>
</div>
<% end %>

2 changes: 1 addition & 1 deletion app/views/organizations/pets/tabs/_photos.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mb-4">
<%= render "components/attachment_form", instance: @pet, title: 'Photos', url: attach_images_pet_path(@pet), attachment_type: 'images' %>
<%= render "components/image_attachment_table", pet: @pet %>
<%= render "components/image_attachment_table", images: @pet.images %>
</div>
4 changes: 3 additions & 1 deletion test/controllers/organizations/home_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

class Organizations::HomeControllerTest < ActionDispatch::IntegrationTest
setup do
@organization = create(:organization)
@organization = create(:organization, :with_page_text)
@organization.save
Current.organization = @organization
end

context "GET #index" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Organizations::PageTextsControllerTest < ActionDispatch::IntegrationTest
context "PATCH #update" do
should "update page text" do
patch page_text_path(@page_text), params: {page_text: {hero: "Super Dog", about: "canine caped crusader"}}
@page_text.reload
assert_response :redirect
follow_redirect!
assert_response :success
Expand Down
6 changes: 6 additions & 0 deletions test/factories/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@
name { Faker::Company.name }
sequence(:slug) { |n| Faker::Internet.domain_word + n.to_s }
profile { association :organization_profile, organization: instance }

trait :with_page_text do
after(:create) do |organization|
create(:page_text, organization: organization) unless organization.page_text
end
end
end
end
13 changes: 12 additions & 1 deletion test/factories/page_text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
factory :page_text do
hero { "MyString" }
about { Faker::Lorem.sentence }
organization { ActsAsTenant.current_tenant }
# organization { ActsAsTenant.current_tenant }
association :organization, factory: :organization

trait :with_image do
after(:create) do |page_text|
page_text.about_us_images.attach(
io: File.open(Rails.root.join("app", "assets", "images", "cat.jpeg")),
filename: "cat.jpeg",
content_type: "image/jpeg"
)
end
end
end
end
3 changes: 3 additions & 0 deletions test/integration/adoption_application_reviews_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class AdoptionApplicationReviewsTest < ActionDispatch::IntegrationTest
@withdrawn_app = create(:adopter_application, :withdrawn)
@successful_applicant_app = create(:adopter_application, status: :successful_applicant)
@adoption_made_app = create(:adopter_application, status: :adoption_made)
@organization = create(:organization)
@page_text = create(:page_text, organization: @organization)
Current.organization = @organization
end

context "non-staff" do
Expand Down
2 changes: 2 additions & 0 deletions test/system/login_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class LoginTest < ApplicationSystemTestCase
setup do
@user = create(:staff)
@organization = @user.organization
@page_text = create(:page_text, :with_image, organization: @organization)
Current.organization = @organization
end

context "when logging in as a staff member" do
Expand Down
2 changes: 2 additions & 0 deletions test/system/registration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class RegistrationTest < ApplicationSystemTestCase
setup do
@user = create(:staff)
@organization = @user.organization
@page_text = create(:page_text, :with_image, organization: @organization)
Current.organization = @organization

visit root_url
click_on "Log In"
Expand Down
2 changes: 2 additions & 0 deletions test/system/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class UsersTest < ApplicationSystemTestCase
setup do
@user = create(:staff)
@organization = @user.organization
@page_text = create(:page_text, :with_image, organization: @organization, hero: "Where every paw finds a home")
Current.organization = @organization
end

test "user can log out" do
Expand Down

0 comments on commit 9685fc4

Please sign in to comment.