Skip to content

Commit

Permalink
Merge pull request #2476 from manyfold3d/homepage-feed
Browse files Browse the repository at this point in the history
New activity feed on front page
  • Loading branch information
Floppy authored Aug 2, 2024
2 parents f21a189 + 9bc61c0 commit 2f1c68d
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 24 deletions.
5 changes: 2 additions & 3 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
class HomeController < ApplicationController
include ModelFilters
before_action :check_library_exists
skip_after_action :verify_policy_scoped

def index
@recent = policy_scope(Model).recent.limit(20)
# Eager load for performance
@recent = @recent.includes([:library, :model_files])
@feed = current_user.actor.activities.order(created_at: :desc).limit(20)
end

private
Expand Down
11 changes: 11 additions & 0 deletions app/models/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def organize=(value)
validate :destination_is_vacant, on: :update, if: :need_to_move_files?
validates :license, spdx: true, allow_nil: true

after_create :post_creation_activity
before_update :move_files, if: :need_to_move_files?

def parents
Expand Down Expand Up @@ -172,4 +173,14 @@ def move_files
def slugify_name
self.slug = name.parameterize
end

def post_creation_activity
default_user = User.first
return if default_user.nil?
Federails::Activity.create!(
actor: default_user.actor,
action: "Create",
entity: actor
)
end
end
28 changes: 28 additions & 0 deletions app/views/activities/_create_actor.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%- subject = activity&.actor %>
<%- object = activity&.entity %>
<%- thing = object&.entity %>
<% if thing %>
<div class="card border-0 border-bottom">
<div class="card-body py-2">
<div class="row">
<div class="col">
<%= link_to object.name, thing %>
</div>
<% if thing.is_a? Model %>
<div class="col col-auto">
<%= status_badges(thing) %>
</div>
<% end %>
<div class="col col-auto">
<small>
added
<% if subject.entity != current_user %>
by <%= subject.name %>
<% end %>
<%= t("home.index.how_long_ago", time: time_ago_in_words(thing.created_at)) %>
</small>
</div>
</div>
</div>
</div>
<% end %>
20 changes: 20 additions & 0 deletions app/views/activities/_create_following.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%- follow = activity.entity %>

<div class="card border-0 border-bottom">
<div class="card-body py-2">
<div class="row">
<div class="col">
<% if follow.actor.entity == current_user %>
You
<% else %>
<%= follow.actor.name %>
<% end %>
followed
<%= link_to follow.target_actor.name, follow.target_actor.entity %>
</div>
<div class="col col-auto">
<small><%= t("home.index.how_long_ago", time: time_ago_in_words(follow.created_at)) %></small>
</div>
</div>
</div>
</div>
Empty file.
21 changes: 5 additions & 16 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,13 @@
<% end %>
</div>
</div>
<% if @recent %>
<% if !@feed.empty? %>
<div class="row row-cols-2">
<div class="col-8 offset-md-2">
<p class="lead"><%= t(".recent") %></p>
<table class="table">
<% @recent.each do |model| %>
<tr>
<td>
<%= link_to model.name, model_path(model) %>
</td>
<td>
<%= status_badges(model) %>
</td>
<td><%= link_to model.library.name, model.library %></td>
<td><%= t(".how_long_ago", time: time_ago_in_words(model.created_at)) %></td>
</tr>
<% end %>
</table>
<p class="lead"><%= t(".recent_activity") %></p>
<% @feed.each do |activity| %>
<%= render partial: "activities/#{activity.action.parameterize}_#{activity.entity_type.demodulize.parameterize}", locals: {activity: activity} %>
<% end %>
</div>
</div>
<% end %>
1 change: 0 additions & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ de:
home:
index:
how_long_ago: vor %{time}
recent: Kürzlich hinzugefügte Modelle
search:
placeholder: Wonach suchen Sie?
jobs:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ en:
home:
index:
how_long_ago: "%{time} ago"
recent: Recently-added Models
recent_activity: Recent Activity
search:
placeholder: What are you looking for?
jobs:
Expand Down
1 change: 0 additions & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ fr:
home:
index:
how_long_ago: depuis %{time}
recent: Modèles récemment ajoutés
search:
placeholder: Que recherchez-vous ?
jobs:
Expand Down
1 change: 0 additions & 1 deletion config/locales/pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ pl:
home:
index:
how_long_ago: "%{time} temu"
recent: Ostatnio Dodane Modele
search:
placeholder: Czego szukasz?
jobs:
Expand Down
2 changes: 1 addition & 1 deletion spec/models/concerns/follower_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
end

it "creates a following activity" do # rubocop:todo RSpec/MultipleExpectations
activity = follower.activities.first
activity = follower.activities.where(entity_type: "Federails::Following").first
expect(activity.action).to eq "Create"
expect(activity.entity).to eq follower.following_follows.first
end
Expand Down

0 comments on commit 2f1c68d

Please sign in to comment.