From 83515c0eb74c4a77ceb031ef2e58b71f6d8c8f03 Mon Sep 17 00:00:00 2001 From: "Ben W. Brumfield" Date: Thu, 30 May 2024 17:21:40 -0500 Subject: [PATCH] Restructure new findaproject page for #4129 --- app/controllers/dashboard_controller.rb | 10 ++-- app/models/user.rb | 2 + .../dashboard/_project_details.html.slim | 9 +++ .../dashboard/new_landing_page.html.slim | 55 ++++++++----------- 4 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 app/views/dashboard/_project_details.html.slim diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 44531d6ce7..dcda22903a 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index fd8e8780ad..bb81a94100 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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)} diff --git a/app/views/dashboard/_project_details.html.slim b/app/views/dashboard/_project_details.html.slim new file mode 100644 index 0000000000..ff9771c487 --- /dev/null +++ b/app/views/dashboard/_project_details.html.slim @@ -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 diff --git a/app/views/dashboard/new_landing_page.html.slim b/app/views/dashboard/new_landing_page.html.slim index 4b5587f650..0c0eb7f295 100644 --- a/app/views/dashboard/new_landing_page.html.slim +++ b/app/views/dashboard/new_landing_page.html.slim @@ -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| @@ -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