Skip to content

Commit

Permalink
added experimental tree views
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Aug 31, 2016
1 parent 688c6bf commit 24c438a
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 0 deletions.
56 changes: 56 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,59 @@ tr.top td{
display: block;
float: left;
}

/*
Tree structure using CSS:
http://stackoverflow.com/questions/14922247/how-to-get-a-tree-in-html-using-pure-css
*/

.tree, .tree ul{
list-style-type: none;
margin-left: 0 0 0 10px;
padding: 0;
position: relative;
overflow:hidden;
}

.tree li{
margin: 0;
padding: 0 12px;
position: relative;
}

.tree li::before, .tree li::after{
content: '';
position: absolute;
left: 0;
}

/* horizontal line on inner list items */
.tree li::before{
border-top: 1px solid #999;
top: 10px;
width: 10px;
height: 0;
}

/* vertical line on list items */
.tree li:after{
border-left: 1px solid #999;
height: 100%;
width: 0px;
top: -10px;
}

/* lower line on list items from the first level because they don't have parents */
.tree > li::after{
top: 10px;
}

/* hide line from the last of the first level list items */
.tree > li:last-child::after{
display: none;
}


.tree ul:last-child li:last-child:after{
height:20px;
}
3 changes: 3 additions & 0 deletions app/controllers/tree_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class TreeController < ApplicationController
before_action :find_project
end
1 change: 1 addition & 0 deletions app/models/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Dependency < ActiveRecord::Base
scope :with_project, -> { joins(:project).where('projects.id IS NOT NULL') }
scope :without_project_id, -> { where(project_id: nil) }
scope :with_project_name, -> { where("project_name <> ''") }
scope :kind, ->(kind) { where(kind: kind) }

after_create :update_project_id

Expand Down
20 changes: 20 additions & 0 deletions app/views/tree/_dependency.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<% requirements ||= '' %>
<% @license_names << project.normalize_licenses %>
<li>
<%= project %> - <%= version.number %> <em class='text-muted'><%= requirements %> - <%= project.normalize_licenses.join(', ') %> <% if project.status.present? && project.status.downcase != 'active' %>- <%= project.status %><% end %></em>
<% dependencies = version.dependencies.kind('normal').includes(:project) %>
<% if dependencies.any? %>
<ul>
<%dependencies.each do |dependency| %>
<% if dependency.project && index < 10 && !@project_names.include?(dependency.project_name) %>
<% @project_names << dependency.project_name %>
<%= render partial: 'tree/dependency', locals: {project: dependency.project, version: dependency.project.latest_stable_release, requirements: dependency.requirements, index: index + 1} %>
<% else %>
<li>
<%= dependency.project_name %> <em class='text-muted'><%= dependency.requirements %></em>
</li>
<% end %>
<% end %>
</ul>
<% end %>
</li>
16 changes: 16 additions & 0 deletions app/views/tree/_reverse_dependency.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<li>
<%= project.name %> - <em class='text-muted'><%= project.normalize_licenses.join(', ') %></em>
<% dependents = project.dependent_projects %>
<% if dependents.any? %>
<ul>
<% dependents.each do |dependent| %>
<% if index < 3 && !@project_names.include?(dependent.name) %>
<% @project_names << dependent.name %>
<%= render partial: 'tree/reverse_dependency', locals: {project: dependent, index: index + 1} %>
<% else %>
<li><%= dependent.name %> - <em class='text-muted'><%= project.normalize_licenses.join(', ') %></em></li>
<% end %>
<% end %>
</ul>
<% end %>
</li>
10 changes: 10 additions & 0 deletions app/views/tree/reverse.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Reverse Dependency Tree for <%= link_to @project, project_path(@project.to_param) %> on <%= link_to @project.platform, platform_path(@project.platform) %> </h1>

<% version = @project.latest_version %>
<% project = @project %>
<% @project_names = [@project.name] %>
<% @license_names = @project.normalize_licenses %>

<ul class='tree'>
<%= render partial: 'tree/reverse_dependency', locals: {project: project, index: 0} %>
</ul>
17 changes: 17 additions & 0 deletions app/views/tree/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h1>Dependency Tree for <%= link_to @project, project_path(@project.to_param) %> on <%= link_to @project.platform, platform_path(@project.platform) %> </h1>

<% version = @project.latest_version %>
<% project = @project %>
<% @project_names = [@project.name] %>
<% @license_names = @project.normalize_licenses %>

<ul class='tree'>
<%= render partial: 'tree/dependency', locals: {project: project, version: version, requirements: '', index: 0} %>
</ul>
<hr>
<p>
Unique dependencies: <%= @project_names.uniq.length %>
</p>
<p>
Unique licenses: <%= @license_names.flatten.uniq.length %> <em class='text-muted'><%= @license_names.flatten.uniq.join(', ') %></em>
</p>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
get '/stats/github', to: 'stats#github', as: :github_stats
end

get '/tree/:platform/:name', to: 'tree#show'
get '/reverse-tree/:platform/:name', to: 'tree#reverse'

get '/github/issues', to: 'github_issues#index', as: :issues

get '/pricing', to: 'account_subscriptions#plans', as: :pricing
Expand Down

0 comments on commit 24c438a

Please sign in to comment.