Skip to content

Commit

Permalink
Subject view
Browse files Browse the repository at this point in the history
Show the trees a subject is in.
  • Loading branch information
frankieroberto committed Jul 23, 2015
1 parent 6006349 commit 65dd410
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 16 deletions.
14 changes: 14 additions & 0 deletions app/assets/stylesheets/application.css
Expand Up @@ -14,6 +14,9 @@
*= require_self
*/

body {
font-family: Garamond, Georgia, serif;
}

.breadcrumb {
font-size: 2em;
Expand All @@ -35,4 +38,15 @@

.aka abbr {
font-size: 0.8em;
}

.identifier {
color: grey;
font-size: 0.5em;
vertical-align: top;
}

.identifier a {
margin: 0 3px;
vertical-align: inherit;
}
32 changes: 32 additions & 0 deletions app/controllers/subjects_controller.rb
@@ -0,0 +1,32 @@
class SubjectsController < ApplicationController


def show
@subject = Subject.find_by(scheme: 'mesh', identifier: params[:id])

@trees = []

@subject.tree_numbers.each do |tree_number|

parent_tree_numbers = [tree_number]

while !tree_number.blank?

tree_number = tree_number.gsub(/\.?[^\/\.]+\z/, '')
parent_tree_numbers << tree_number unless tree_number.blank?

end

@trees << Subject.select('*')
.from("(select *, unnest(tree_numbers) as tree_number from subjects) as subjects")
.where(tree_number: parent_tree_numbers)
.order(:tree_number)

end

@records = @subject.records.select(:identifier, :title).limit(50)

end


end
14 changes: 14 additions & 0 deletions app/models/subject.rb
Expand Up @@ -5,4 +5,18 @@ def records
Record.where("metadata->'650' @> '[{\"0\" : \"#{identifier}\"}]'::jsonb")
end

def related_subjects

@related_subjects ||= begin

if related_identifiers.length > 0
Subject.where(identifier: related_identifiers)
else
[]
end

end

end

end
16 changes: 16 additions & 0 deletions app/views/shared/_records.html.erb
@@ -0,0 +1,16 @@
<% if records.length > 0 %>
<% if records.length == 50 %>
<h2>50+ Wellcome Library records</h2>
<% else %>
<h2><%= pluralize(@records.length, 'Wellcome Library record') %></h2>
<% end %>

<ul>
<% records.each do |record| %>
<li><%= link_to record.title, record %></li>
<% end %>
</ul>
<% else %>
<p>There’s nothing in the Wellcome Library collection about this (yet).</p>
<% end %>
6 changes: 6 additions & 0 deletions app/views/shared/_related_subjects.html.erb
@@ -0,0 +1,6 @@
<% if related_subjects.length > 0 %>
<p>Related:
<%= related_subjects.collect do |subject| %>
<% link_to(subject.label, subject_path(subject.identifier)) %>
<% end.join(', ').html_safe %>
<% end %>
26 changes: 26 additions & 0 deletions app/views/subjects/show.html.erb
@@ -0,0 +1,26 @@
<% @trees.each do |tree| %>

<p>
<%= link_to 'Top', '/tree' %> /
<%= tree.collect do |subject| %>
<% link_to subject.label, "/tree/#{subject.tree_number.gsub('.', '/')}" %>
<% end.join(" / ").html_safe %>
</p>

<% end %>

<h1><%= @subject.label %></h1>

<% if @subject.all_labels.length > 1 %>
<p>Also known as: <%= (@subject.all_labels - [@subject.label]).collect {|s| content_tag('b', s)}.join(', ').html_safe %>.</p>
<% end %>
<%= render 'shared/related_subjects', related_subjects: @subject.related_subjects %>

<p class="description">
<%= @subject.description %>
</p>



<%= render 'shared/records', records: @records %>
21 changes: 5 additions & 16 deletions app/views/tree/show.html.erb
Expand Up @@ -4,12 +4,16 @@

<%= @parent_subjects.collect {|s| link_to(s.label, "/tree/#{s.tree_number.gsub('.', '/')}") + ' /' }.join(' ').html_safe %>
<h1><%= @subject.label %></h1>
<span class="identifier">(<%= link_to @subject.identifier, subject_path(@subject.identifier) %>)</span>
</div>

<% if @subject.all_labels.length > 1 %>
<p>Also known as: <%= (@subject.all_labels - [@subject.label]).collect {|s| content_tag('b', s)}.join(', ').html_safe %>.</p>
<% end %>
<%= render 'shared/related_subjects', related_subjects: @subject.related_subjects %>


<p class="description">
<%= @subject.description %>
</p>
Expand All @@ -19,19 +23,4 @@
<%= render 'tree', subjects: @child_subjects %>
<% end %>
<% if @records.length > 0 %>
<% if @records.length == 50 %>
<h2>50+ Wellcome Library records</h2>
<% else %>
<h2><%= pluralize(@records.length, 'Wellcome Library record') %></h2>
<% end %>

<ul>
<% @records.each do |record| %>
<li><%= link_to record.title, record %></li>
<% end %>
</ul>
<% else %>
<p>There’s nothing in the Wellcome Library collectiona about this (yet).</p>
<% end %>
<%= render 'shared/records', records: @records %>
2 changes: 2 additions & 0 deletions config/routes.rb
Expand Up @@ -4,6 +4,8 @@

resources :tree, only: [:index, :show], constraints: {id: /[^\.]+/}

resources :subjects, only: :show, path: ''

root 'home#show'

end

0 comments on commit 65dd410

Please sign in to comment.