new collection events in stream and profile

This commit is contained in:
Andrew Brown 2020-07-22 00:40:37 -07:00
parent 1c5e9c7d43
commit bc4f4a4656
10 changed files with 155 additions and 61 deletions

View File

@ -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

View File

@ -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

View File

@ -1,7 +1,7 @@
<div class="parallax-header slider" style="height: 1px; position: relative; top: -1px">
<ul class="slides">
<li>
<%= image_tag(collection.cover_image || collection.header_image) %>
<%= image_tag(collection.random_public_image) %>
<div class="caption center-align bordered-text">
<h4>
<i class="material-icons <%= PageCollection.color %>-text"><%= PageCollection.icon %></i>

View File

@ -23,7 +23,7 @@
<div class="col s12 m6 l6">
<div class="card-image">
<%= link_to [share.user, share] do %>
<%= image_tag content.cover_image %>
<%= image_tag content.random_public_image %>
<% end %>
<span class="card-title">
<%= link_to content do %>

View File

@ -0,0 +1,83 @@
<div class="stream-item">
<div class="row">
<div class="col s12">
<span class="right">
<%= render partial: 'content_page_shares/action_dropdown', locals: { share: share, content: content } %>
</span>
<%= link_to share.user, class: "#{User.color}-text" do %>
<%= image_tag share.user.image_url(size=20), class: 'left circle avatar' %>
<%= share.user.display_name %>
<% end %>
created the
<%= link_to content.title, content, class: "#{content.class.color}-text text-darken-1" %>
Collection.
<span class="right">
<%= link_to [share.user, share], class: 'grey-text' do %>
<%= time_ago_in_words share.created_at %> ago
<% end %>
</span>
</div>
</div>
<div class="main-container hoverable card row clearfix">
<div class="col s12 m6 l6">
<div class="card-image">
<%= link_to [share.user, share] do %>
<%= image_tag content.random_public_image %>
<% end %>
<span class="card-title">
<%= link_to content do %>
<i class="material-icons tiny <%= content.class.color %>-text"><%= content.class.icon %></i>
<span class="white-text bordered-text"><%= content.title %></i>
<% end %>
</span>
</div>
</div>
<div class="col s12 m6 l6">
<div class="card-content discussion-container">
<div class="metadata">
<%= link_to share.user, class: "#{User.color}-text" do %>
<%= image_tag share.user.image_url(size=20), class: 'left circle avatar' %>
<%= share.user.display_name %>
<% end %>
<span class="helper-text">
<%= share.content_page.description %>
</span>
</div>
<% if content.description.present? %>
<blockquote class="original-comment">
<%= simple_format content.description %>
</blockquote>
<% end %>
<% if content.page_types.any? %>
<br />
<p>
<% if content.allow_submissions? %>
Now accepting submissions for
<% else %>
This Collection is for
<% end %>
<%= content.page_types.to_sentence %>
pages.
</p>
<% end %>
<%= render partial: 'share_comments/form', locals: { share: share } %>
<br /><br />
<div class="uppercase grey-text center"><%= pluralize share.share_comments.count, 'comment' %></div>
<div class="row">
<% share.share_comments.each do |comment| %>
<%= render partial: 'share_comments/show', locals: { comment: comment, share: share } %>
<% end %>
</div>
<% if share.share_comments.count > 10 %>
<%= render partial: 'share_comments/form', locals: { share: share } %>
<% end %>
</div>
</div>
</div>
</div>

View File

@ -148,8 +148,9 @@
</li>
-->
<li>
<%= link_to main_app.explore_page_collections_path, class: 'waves-effect' do %>
<%= link_to main_app.page_collections_path, class: 'waves-effect' do %>
<i class="material-icons left <%= PageCollection.color %>-text"><%= PageCollection.icon %></i>
<span class="new badge <%= PageCollection.color %> white-text"></span>
Collections
<% end %>
</li>

View File

@ -1,11 +1,11 @@
<%= form_with(model: page_collection, local: true) do |f| %>
<% if page_collection.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(page_collection.errors.count, "error") %> prohibited this page_collection from being saved:</h2>
<h2 style="font-size: 1.5em"><%= pluralize(page_collection.errors.count, "error") %> prohibited this Collection from being saved:</h2>
<ul>
<ul class="browser-default">
<% page_collection.errors.full_messages.each do |message| %>
<li><%= message %></li>
<li class="red-text"><%= message %></li>
<% end %>
</ul>
</div>

View File

@ -1,44 +1,44 @@
<div class="row">
<h1 class="center" style="font-size: 2em">
<i class="material-icons <%= PageCollection.color %>-text"><%= PageCollection.icon %></i>
Your collections
</h1>
<% @my_collections.each do |collection| %>
<div class="col s12 m6 l4">
<%= link_to collection do %>
<div class="hoverable card" style="height: 240px">
<div class="card-image">
<%= image_tag collection.cover_image, style: 'max-height: 300px;' %>
<span class="card-title">
<%= collection.title %>
<br />
<small>
<% if collection.subtitle? %>
<%= collection.subtitle %>
<% else %>
<% if @my_collections.any? || current_user.on_premium_plan? %>
<div class="row">
<h1 class="center" style="font-size: 2em">
<i class="material-icons <%= PageCollection.color %>-text"><%= PageCollection.icon %></i>
Your collections
</h1>
<% @my_collections.each do |collection| %>
<div class="col s12 m6 l4">
<%= link_to collection do %>
<div class="hoverable card <%= PageCollection.color %>" style="height: 250px">
<div class="card-image">
<%= image_tag collection.cover_image || collection.header_image, style: 'max-height: 300px;' %>
<span class="card-title">
<%= collection.title %>
<br />
<small>
<% collection.page_types.each do |icon| %>
<% klass = icon.constantize %>
<i class="material-icons left tooltipped tiny bordered-text <%= klass.color %>-text" data-tooltip="<%= icon.pluralize %>"><%= klass.icon %></i>
<% end %>
<% end %>
</small>
</span>
</small>
</span>
</div>
</div>
</div>
<% end %>
</div>
<% end %>
<div class="col s12 m6 l4">
<%= link_to new_page_collection_path do %>
<div class="card-panel <%= PageCollection.color %> white-text hoverable center" style="height: 246px;">
<br /><br />
<% end %>
</div>
<% end %>
<% if current_user.on_premium_plan? %>
<div class="col s12 m6 l4">
<%= link_to new_page_collection_path do %>
<div class="card-panel <%= PageCollection.color %> white-text hoverable center" style="height: 246px;">
<br /><br />
<i class="material-icons large">add</i><br />
Create a collection
<i class="material-icons large">add</i><br />
Create a collection
</div>
<% end %>
</div>
<% end %>
</div>
</div>
<% end %>
<% if @network_collections.any? %>
<div class="row">
@ -49,9 +49,9 @@
<% @network_collections.each do |collection| %>
<div class="col s12 m6 l4">
<%= link_to collection do %>
<div class="hoverable card" style="height: 240px">
<div class="hoverable card <%= PageCollection.color %>" style="height: 250px">
<div class="card-image">
<%= image_tag collection.cover_image, style: 'max-height: 300px;' %>
<%= image_tag collection.cover_image || collection.header_image, style: 'max-height: 300px;' %>
<span class="card-title">
<%= collection.title %>
<br />
@ -83,21 +83,17 @@
<% @random_collections.each do |collection| %>
<div class="col s12 m6 l4">
<%= link_to collection do %>
<div class="hoverable card" style="height: 240px">
<div class="hoverable card <%= PageCollection.color %>" style="height: 250px">
<div class="card-image">
<%= image_tag collection.cover_image, style: 'max-height: 300px;' %>
<%= image_tag collection.cover_image || collection.header_image, style: 'max-height: 300px;' %>
<span class="card-title">
<%= collection.title %>
<br />
<small>
<% if collection.subtitle? %>
<%= collection.subtitle %>
<% else %>
<% collection.page_types.each do |icon| %>
<% klass = icon.constantize %>
<i class="material-icons left tooltipped tiny bordered-text <%= klass.color %>-text" data-tooltip="<%= icon.pluralize %>"><%= klass.icon %></i>
<% end %>
<% end %>
<% collection.page_types.each do |icon| %>
<% klass = icon.constantize %>
<i class="material-icons left tooltipped tiny bordered-text <%= klass.color %>-text" data-tooltip="<%= icon.pluralize %>"><%= klass.icon %></i>
<% end %>
</small>
</span>
</div>

View File

@ -6,7 +6,12 @@
<%= render partial: 'content_page_shares/stream_discussion', locals: { share: share, content: share.content_page } %>
<% elsif share.content_page_type == PageCollection.name %>
<%= render partial: 'content_page_shares/stream_page_collection', locals: { share: share, content: share.content_page } %>
<% if share.secondary_content_page.present? %>
<%= render partial: 'content_page_shares/stream_added_to_page_collection', locals: { share: share, content: share.content_page } %>
<% else %>
<%= render partial: 'content_page_shares/stream_new_page_collection', locals: { share: share, content: share.content_page } %>
<% end %>
<% elsif share.content_page_type == Document.name %>
<%= render partial: 'content_page_shares/stream_document_share', locals: { share: share, content: share.content_page } %>

View File

@ -139,7 +139,7 @@
<%= link_to page_collection do %>
<div class="hoverable card">
<div class="card-image">
<%= image_tag page_collection.cover_image %>
<%= image_tag page_collection.random_public_image %>
<span class="card-title">
<i class="material-icons bordered-text <%= PageCollection.color %>-text"><%= PageCollection.icon %></i>
<%= page_collection.title %><br />
@ -160,12 +160,12 @@
<% if @user.page_collections.any? %>
<h3 class="grey-text center">My Collections</h3>
<% @user.page_collections.each do |page_collection| %>
<% @user.page_collections.each.with_index do |page_collection, i| %>
<div class="col s12 m6 l4">
<%= link_to page_collection do %>
<div class="hoverable card">
<div class="hoverable card"">
<div class="card-image">
<%= image_tag page_collection.cover_image %>
<%= image_tag page_collection.random_public_image, height: 250 %>
<span class="card-title">
<i class="material-icons bordered-text <%= PageCollection.color %>-text"><%= PageCollection.icon %></i>
<%= page_collection.title %><br />