Skip to content

Commit

Permalink
Restructure new findaproject page for #4129
Browse files Browse the repository at this point in the history
  • Loading branch information
benwbrum committed May 30, 2024
1 parent 5a44e89 commit 83515c0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
10 changes: 5 additions & 5 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ def landing_page
def new_landing_page
@search_results = search_results(params[:search])

# Get random Collections and DocSets from paying users
@owners = User.findaproject_owners.order(:display_name).joins(:collections)
.left_outer_joins(:document_sets).includes(:collections)
@org_owners = User.findaproject_orgs.order(:display_name).joins(:collections).left_outer_joins(:document_sets).distinct
@individual_owners = User.findaproject_individuals.order(:display_name).left_outer_joins(:document_sets).joins(:collections).distinct


# Sampled Randomly down to 8 items for Carousel
docsets = DocumentSet.carousel.includes(:owner).where(owner_user_id: @owners.ids.uniq).sample(5)
colls = Collection.carousel.includes(:owner).where(owner_user_id: @owners.ids.uniq).sample(5)
docsets = DocumentSet.carousel.includes(:owner).where(owner_user_id: @org_owners.ids + @individual_owners.ids).sample(5)
colls = Collection.carousel.includes(:owner).where(owner_user_id: @org_owners.ids + @individual_owners.ids).sample(5)
@collections = (docsets + colls).sample(8)

@tag_map = Tag.featured_tags.group(:ai_text).count
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class User < ApplicationRecord
scope :owners, -> { where(owner: true) }
scope :trial_owners, -> { owners.where(account_type: 'Trial') }
scope :findaproject_owners, -> { owners.where.not(account_type: [nil, 'Trial', 'Staff']) }
scope :findaproject_orgs, -> { owners.where(account_type: ['Large Organization', 'Small Organization']) }
scope :findaproject_individuals, -> { owners.where(account_type: ['Legacy', 'Individual Researcher']) }
scope :paid_owners, -> { non_trial_owners.where('paid_date > ?', Time.now) }
scope :expired_owners, -> { non_trial_owners.where('paid_date <= ?', Time.now) }
scope :active_mailers, -> { where(activity_email: true)}
Expand Down
9 changes: 9 additions & 0 deletions app/views/dashboard/_project_details.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-snippet = truncate(Loofah.fragment(project.intro_block).text(encode_special_chars: false), length: 300, separator: ' ') || ''
div.projects_details
-unless project.picture.blank?
.projects_details_image
=image_tag(project.picture_url(:thumb), alt: project.title)
.projects_collection
h5 =link_to project.title, collection_path(owner, project)
-unless snippet.empty?
.projects_collection_snippet = snippet
55 changes: 24 additions & 31 deletions app/views/dashboard/new_landing_page.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

.columns.project-list
article.maincol
ul.tagcloud
-@tag_map.each do |ai_text, collection_count|
-if collection_count > 0
li data-weight="#{collection_count}"
=link_to(ai_text, browse_tag_path(ai_text))
-unless params[:search]
ul.tagcloud
-@tag_map.each do |ai_text, collection_count|
-if collection_count > 0
li data-weight="#{collection_count}"
=link_to(ai_text, browse_tag_path(ai_text))

-if @search_results && @owners.empty?
-@search_results.each do |sr|
Expand All @@ -37,33 +38,25 @@
h5 =link_to sr.title, collection_path(sr.owner.slug, sr.id)
.projects_collection_snippet
=truncate(Loofah.fragment(sr.intro_block).text(encode_special_chars: false), length: 300, separator: ' ') || ''
-[@org_owners, @individual_owners].each do |owners|
-owners.each do |owner|
-if params[:search]
-projects = @search_results.select{ |p| p.owner_user_id == owner.id }
-else
-projects = (owner.random_collections + owner.random_document_sets).sample(3)
-unless projects.blank?
.project-list_projects
.projects-owner
h3.projects-owner_title
=link_to owner.display_name, user_profile_path(owner)
-if owner.about.present?
.description
=owner.about

-@owners.each do |owner|
-if params[:search]
-projects = @search_results.select{ |p| p.owner_user_id == owner.id }
-else
-projects = (owner.random_collections + owner.random_document_sets).sample(3)
-unless projects.blank?
.project-list_projects
.projects-owner
h3.projects-owner_title
=link_to owner.display_name, user_profile_path(owner)
-if owner.about.present?
.description
=owner.about

.projects
-projects.each do |project|
-snippet = truncate(Loofah.fragment(project.intro_block).text(encode_special_chars: false), length: 300, separator: ' ') || ''
div.projects_details
-unless project.picture.blank?
.projects_details_image
=image_tag(project.picture_url(:thumb), alt: project.title)
.projects_collection
h5 =link_to project.title, collection_path(owner, project)
-unless snippet.empty?
.projects_collection_snippet = snippet
.projects_link =link_to t('dashboard.landing_page.more'), user_profile_path(owner)
.projects
-projects.each do |project|
=render 'dashboard/project_details', project: project, owner: owner
.projects_link =link_to t('dashboard.landing_page.more'), user_profile_path(owner)

.project-list_link
=link_to t('.all_collections'), collections_list_path
Expand Down

0 comments on commit 83515c0

Please sign in to comment.