Skip to content

Commit

Permalink
Add start_date parameter and update project ordering
Browse files Browse the repository at this point in the history
Update transaction check in show.html.erb

Update rendering of projects in show.html.erb
  • Loading branch information
andrew committed Jan 23, 2024
1 parent 22c3d21 commit d63037d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/controllers/collectives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def show
@collective = Collective.find_by_slug!(params[:id])
@range = range
@period = period
start_date = params[:start_date].presence || range.days.ago
@pagy, @projects = pagy(@collective.projects_with_repository.active.source.order_by_stars)
@transactions = @collective.transactions.created_after(start_date).any?
end

def chart_data
Expand Down
5 changes: 5 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ class Project < ApplicationRecord
scope :active, -> { where("(repository ->> 'archived') = ?", 'false') }
scope :archived, -> { where("(repository ->> 'archived') = ?", 'true') }

scope :fork, -> { where("(repository ->> 'fork') = ?", 'true') }
scope :source, -> { where("(repository ->> 'fork') = ?", 'false') }

scope :language, ->(language) { where("(repository ->> 'language') = ?", language) }
scope :owner, ->(owner) { where("(repository ->> 'owner') = ?", owner) }
scope :keyword, ->(keyword) { where("keywords @> ARRAY[?]::varchar[]", keyword) }
scope :with_repository, -> { where.not(repository: nil) }

scope :order_by_stars, -> { order(Arel.sql("(repository ->> 'stargazers_count')::int desc nulls last")) }

def self.sync_least_recently_synced
Project.where(last_synced_at: nil).or(Project.where("last_synced_at < ?", 1.day.ago)).order('last_synced_at asc nulls first').limit(500).each do |project|
project.sync_async
Expand Down
9 changes: 5 additions & 4 deletions app/views/collectives/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<h2>Transactions</h2>

<% if @collective.transactions_count && @collective.transactions_count > 0 %>
<% if @transactions %>

<%= line_chart chart_data_collective_path(chart: 'all_transactions', period: @period, range: @range), title: 'All Transactions' %>
<%= line_chart chart_data_collective_path(chart: 'expenses', period: @period, range: @range), title: 'Expenses' %>
Expand All @@ -37,7 +37,7 @@

<% else %>
<p>
No transactions yet.
No transactions in this period.
</p>
<% end %>

Expand All @@ -51,10 +51,11 @@
</p>
<% end %>

<% if @collective.projects_with_repository.any? %>
<% if @projects.any? %>
<h2>Repositories</h2>

<%= render @collective.projects_with_repository %>
<%= render @projects %>
<%== pagy_bootstrap_nav(@pagy) if @pagy.pages > 1 %>
<% else %>
<p>
No repositories found.
Expand Down

0 comments on commit d63037d

Please sign in to comment.