Skip to content
Permalink
Browse files

Remove domains table, and replace with chart; address #146.

- Update display_domains helper for chart data
- Create controller methods for domains chart data feed
- Add route for feed
- Update Rubocop config
  • Loading branch information...
ruebot committed May 2, 2019
1 parent 4a3d99f commit 3ba58758a40172a81bc77494a3c1425be83e3c57
@@ -42,6 +42,7 @@ Metrics/BlockLength:
Metrics/ClassLength:
Exclude:
- app/controllers/dashboards_controller.rb
- app/controllers/collections_controller.rb

Metrics/CyclomaticComplexity:
Exclude:
@@ -3,17 +3,21 @@
# Collection controller methods.
class CollectionsController < ApplicationController
before_action :set_collection, only: %i[show]
before_action :set_user, only: %i[show download]
before_action :set_collection_id, only: %i[download]
before_action :set_user, only: %i[show download domains_chart]
before_action :set_collection_id, only: %i[download domains_chart]
before_action :set_account, only: %i[domains_chart]
before_action :gexf_path, only: %i[download_gexf]
before_action :graphml_path, only: %i[download_graphml]
before_action :domains_path, only: %i[download_domains]
before_action :domains_chart_data, only: %i[domains_chart]
before_action :fulltext_path, only: %i[download_fulltext]
before_action :textfilter_path, only: %i[download_textfilter]
before_action :correct_user, only: %i[show download download_gexf
download_fulltext download_domains
download_textfilter]

include CollectionsHelper

def download
WasapiDownloadJob.set(queue: :download)
.perform_later(@user, @collection_id)
@@ -61,6 +65,10 @@ def download_domains
)
end

def domains_chart
render json: domains_chart_data
end

def show; end

private
@@ -77,6 +85,12 @@ def set_user
@user = User.find(params[:user_id])
end

def set_account
@account = Collection.where(user_id: params[:user_id],
collection_id: params[:collection_id])
.pluck(:account)
end

def collection_params
params.require(:collection).permit(:title, :public, :user_id, :account)
end
@@ -120,4 +134,8 @@ def correct_user
@user = User.find(params[:user_id])
redirect_to(root_url) unless current_user?(@user)
end

def domains_chart_data
display_domains(@user.id, @collection_id.id, @account[0])
end
end
@@ -15,8 +15,9 @@ def display_domains(user_id, collection_id, account)
text = File.open(collection_domains).read
csv_text = text.delete! '()'
csv = CSV.parse(csv_text, headers: false)
csv.take(10).each do |row|
end
.sort_by { |line| line[1].to_i }
.reverse
csv.take(10)
end
end

@@ -79,6 +79,10 @@
<%= link_to('What does this graph show?', '#', data: { toggle: 'tooltip', title: 'This diagram visualizes the domains that are captured as well as any domains that they may link to. These linked-to domains may or may not be contained within the web archived collection. You can read more about this graph in our documentation.'}) %>
<% end %>
</div>
<% unless display_domains(@user.id, @collection.id, @collection.account).blank? %>
<h2>Domains</h2>
<%= column_chart user_collection_domains_chart_path(@user.id, @collection.id, @collection.account), download: {filename: 'domains_chart.png', background: '#ffffff'} %>
<% end %>
<% unless !File.exists? domains_path(@user.id, @collection.id, @collection.account) %>
<h2>Download Collection Derivatives</h2>
<div class="text-center">
@@ -100,29 +104,6 @@
<p><small><%=link_to("Learn more about these files here.", "/derivatives")%> <%=link_to("We also have prototype Archives Unleashed Cloud Jupyter Notebooks available.", "/documentation#notebooks")%></small></p>
</div>
<% end %>
<% unless display_domains(@user.id, @collection.id, @collection.account).blank? %>
<h2>Domains</h2>
<div class="table-responsive">
<table class="table table-striped sortable">
<thead>
<tr>
<th>Domain</th>
<th>Occurrences</th>
</tr>
</thead>
<tbody>
<% for display_domain in display_domains(@user.id, @collection.id, @collection.account) %>
<% display_domain %>
<tr>
<% display_domain.each do |element| %>
<td><%= element %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
</div>
<% end %>
</main>
</div>
</div>
@@ -13,6 +13,7 @@
get :download_graphml
get :download_fulltext
get :download_textfilter
get :domains_chart
end
end

0 comments on commit 3ba5875

Please sign in to comment.
You can’t perform that action at this time.