From bc4f4a465661daec58d2372df2b0690ca85bd66a Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 22 Jul 2020 00:40:37 -0700 Subject: [PATCH] new collection events in stream and profile --- .../page_collections_controller.rb | 14 +++- app/models/page_collection.rb | 7 +- .../components/_collection_header.html.erb | 2 +- ..._stream_added_to_page_collection.html.erb} | 2 +- .../_stream_new_page_collection.html.erb | 83 ++++++++++++++++++ app/views/layouts/_sidenav.html.erb | 3 +- app/views/page_collections/_form.html.erb | 6 +- app/views/page_collections/index.html.erb | 84 +++++++++---------- app/views/stream/_share.html.erb | 7 +- app/views/users/show.html.erb | 8 +- 10 files changed, 155 insertions(+), 61 deletions(-) rename app/views/content_page_shares/{_stream_page_collection.html.erb => _stream_added_to_page_collection.html.erb} (97%) create mode 100644 app/views/content_page_shares/_stream_new_page_collection.html.erb diff --git a/app/controllers/page_collections_controller.rb b/app/controllers/page_collections_controller.rb index 450dd16f..a1bd881f 100644 --- a/app/controllers/page_collections_controller.rb +++ b/app/controllers/page_collections_controller.rb @@ -36,10 +36,18 @@ class PageCollectionsController < ApplicationController # Build page types from params checkbox list @page_collection.page_types = page_collection_page_types_param - # TODO publish new collection to followers if public - if @page_collection.save - redirect_to @page_collection, notice: 'Page collection was successfully created.' + # Add a stream event for every user following this user if the collection is public + ContentPageShare.create( + user_id: current_user.id, + content_page_type: PageCollection.name, + content_page_id: @page_collection.reload.id, + shared_at: @page_collection.created_at, + privacy: 'public', + message: "I created a new Collection!" + ) + + redirect_to @page_collection, notice: 'Your collection was successfully created.' else render :new end diff --git a/app/models/page_collection.rb b/app/models/page_collection.rb index c083209d..d70b53d8 100644 --- a/app/models/page_collection.rb +++ b/app/models/page_collection.rb @@ -9,7 +9,7 @@ class PageCollection < ApplicationRecord has_many :page_collection_reports has_one_attached :header_image, dependent: :destroy - validates :header_image, attached: false, + validates :header_image, attached: false, presence: true, content_type: { in: ['image/png', 'image/jpg', 'image/jpeg', 'image/gif'], message: 'must be a PNG, JPG, JPEG, or GIF' @@ -23,6 +23,8 @@ class PageCollection < ApplicationRecord less_than: 500.kilobytes, message: "can't be larger than 500KB" } + + validates :title, presence: true def pending_submissions page_collection_submissions.where(accepted_at: nil).order('submitted_at ASC') @@ -36,9 +38,8 @@ class PageCollection < ApplicationRecord User.where(id: accepted_submissions.pluck(:user_id) - [user.id]) end - # Some quick aliases so we can treat this like a content page in streams: def random_public_image - cover_image + cover_image || header_image end def name title diff --git a/app/views/content/components/_collection_header.html.erb b/app/views/content/components/_collection_header.html.erb index 151e316c..8a77273e 100644 --- a/app/views/content/components/_collection_header.html.erb +++ b/app/views/content/components/_collection_header.html.erb @@ -1,7 +1,7 @@