Skip to content

Commit

Permalink
Refactor code for projects with multiple repositories
Browse files Browse the repository at this point in the history
Add org_owner? method to Collective model

Update navigation in index and show views
  • Loading branch information
andrew committed Jan 23, 2024
1 parent 03a96a8 commit f3b159d
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 59 deletions.
4 changes: 2 additions & 2 deletions app/controllers/collectives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def show
@range = range
@period = period
start_date = params[:start_date].presence || range.days.ago
if @collective.projects_count > 1
if @collective.projects_with_repository.length > 1
projects_scope = @collective.projects_with_repository.active.source
else
projects_scope = @collective.projects_with_repository.active
projects_scope = @collective.projects_with_repository
end
@pagy, @projects = pagy(projects_scope.order_by_stars)
@transactions = @collective.transactions.created_after(start_date).any?
Expand Down
5 changes: 5 additions & 0 deletions app/models/collective.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def no_license?
projects_with_repository.all?{|p| p.no_license? }
end

def org_owner?
return false if owner.nil?
owner['kind'] == 'organization'
end

def sync_async
SyncCollectiveWorker.perform_async(id)
end
Expand Down
40 changes: 40 additions & 0 deletions app/views/collectives/_audit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<h3>Audit</h3>

<div class='row'>
<div class='col-12'>
<ul>
<li>
<strong>Owned by an org:</strong>
<%= @collective.org_owner? ? '✅' : '❌' %>
</li>
<li>
<strong>Repositories found:</strong>
<%= @collective.projects_with_repository.any? ? '✅' : '❌' %>
</li>
<li>
<strong>Open Source License:</strong>
<%= !@collective.no_license? ? '✅' : '❌' %>
</li>
<li>
<strong>Active Repositories:</strong>
<%= !@collective.inactive? ? '✅' : '❌' %>
</li>
<% if @collective.archived? %>
<li>
<strong>Unarchived Repositories:</strong>
<%= !@collective.archived? ? '✅' : '❌' %>
</li>
<% end %>
<li>
<strong>Funding links:</strong>
<%= !@collective.no_funding? ? '✅' : '❌' %>
</li>
<% if @collective.missing_s? %>
<li>
<strong>Missing s:</strong>
<%= !@collective.missing_s? ? '✅' : '❌' %>
</li>
<% end %>
</ul>
</div>
</div>
23 changes: 23 additions & 0 deletions app/views/collectives/_nav.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<ul class="nav nav-tabs my-3">
<li class="nav-item">
<a class="nav-link active" href='/'>
Collectives
<span class="badge text-bg-secondary">
<%= number_with_delimiter Collective.all.count %>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href='/projects'>
Projects
<span class="badge text-bg-secondary">
<%= number_with_delimiter Project.with_repository.active.count %>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href='/audit'>
Audit
</a>
</li>
</ul>
24 changes: 1 addition & 23 deletions app/views/collectives/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
<div class="container-md">

<ul class="nav nav-tabs my-3">
<li class="nav-item">
<a class="nav-link active" href='/'>
Collectives
<span class="badge text-bg-secondary">
<%= number_with_delimiter @pagy.count %>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href='/projects'>
Projects
<span class="badge text-bg-secondary">
<%= number_with_delimiter Project.with_repository.active.count %>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href='/audit'>
Audit
</a>
</li>
</ul>
<%= render 'nav' %>

<%= form_with url: request.path, method: :get do |form| %>
<%= form.label :range, 'Select range:' %>
Expand Down
4 changes: 4 additions & 0 deletions app/views/collectives/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<% @meta_title = "#{@collective}" %>

<div class="container-md">
<%= render 'nav' %>

<h1>
<%= @collective.to_s %><br/>
</h1>
Expand All @@ -25,6 +27,8 @@

<%= render 'stats' %>

<%= render 'audit' %>

<h2>Transactions</h2>

<% if @transactions %>
Expand Down
34 changes: 34 additions & 0 deletions app/views/projects/_nav.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<ul class="nav nav-tabs my-3">
<li class="nav-item">
<a class="nav-link" href='/'>
Collectives
<span class="badge text-bg-secondary">
<%= number_with_delimiter Collective.all.count %>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link active" href='/projects'>
Projects
<span class="badge text-bg-secondary">
<%= number_with_delimiter Project.with_repository.active.count %>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href='/audit'>
Audit
</a>
</li>
<li class="nav-item ms-auto">
<div class="dropdown">
<button class="btn btn-light dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Sort
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item <%= 'active' if params[:sort] == 'last_synced_at' %>" href="<%= url_for(sort: 'last_synced_at', order: 'desc') %>">Recently synced</a></li>
<li><a class="dropdown-item <%= 'active' if params[:stars] == 'stars' %>" href="<%= url_for(sort: 'stars', order: 'desc') %>">Stars</a></li>
</ul>
</div>
</li>
</ul>
35 changes: 1 addition & 34 deletions app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
<div class="container-md">

<ul class="nav nav-tabs my-3">
<li class="nav-item">
<a class="nav-link" href='/'>
Collectives
<span class="badge text-bg-secondary">
<%= number_with_delimiter Collective.all.count %>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link active" href='/projects'>
Projects
<span class="badge text-bg-secondary">
<%= number_with_delimiter @pagy.count %>
</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href='/audit'>
Audit
</a>
</li>
<li class="nav-item ms-auto">
<div class="dropdown">
<button class="btn btn-light dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Sort
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item <%= 'active' if params[:sort] == 'last_synced_at' %>" href="<%= url_for(sort: 'last_synced_at', order: 'desc') %>">Recently synced</a></li>
<li><a class="dropdown-item <%= 'active' if params[:stars] == 'stars' %>" href="<%= url_for(sort: 'stars', order: 'desc') %>">Stars</a></li>
</ul>
</div>
</li>
</ul>
<%= render 'nav' %>

<%= render @projects %>
<%== pagy_bootstrap_nav(@pagy) if @pagy.pages > 1 %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<% @meta_title = "#{@project}" %>

<div class="container-md">

<%= render 'nav' %>

<h1>
<%= @project.to_s %><br/>
</h1>
Expand Down

0 comments on commit f3b159d

Please sign in to comment.