Skip to content

Commit

Permalink
tree structure
Browse files Browse the repository at this point in the history
  • Loading branch information
seouri committed Nov 16, 2009
1 parent c6eba64 commit 14bb7ba
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 18 deletions.
6 changes: 6 additions & 0 deletions app/controllers/treemap_controller.rb
@@ -0,0 +1,6 @@
class TreemapController < ApplicationController
def index
@tree_id = params[:id]
@tree = MeshTree.find(@tree_id) unless @tree_id.nil?
end
end
2 changes: 2 additions & 0 deletions app/helpers/treemap_helper.rb
@@ -0,0 +1,2 @@
module TreemapHelper
end
16 changes: 14 additions & 2 deletions app/models/mesh_tree.rb
@@ -1,7 +1,19 @@
class MeshTree < ActiveRecord::Base
belongs_to :subject
belongs_to :parent, :class_name => "MeshTree", :foreign_key => :parent_id

def self.children(parent_id = 0)
MeshTree.find_all_by_parent_id(parent_id, :include => [:subject => :subject_stats])
def self.children(parent_id = nil)
MeshTree.find_all_by_parent_id(parent_id, :include => [:subject => :subject_stats], :order => :id)
end

def ancestors
current = self
ancestor = []
while current.nil? == false do
parent = current.parent
current = parent
ancestor.push(parent) unless parent.nil?
end
ancestor.reverse
end
end
7 changes: 7 additions & 0 deletions app/views/layouts/application.html.erb
@@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
<%= yield %>
</body>
</html>
16 changes: 16 additions & 0 deletions app/views/treemap/index.html.erb
@@ -0,0 +1,16 @@
<%= link_to_unless_current("MeSH", treemap_path) %>
<% unless @tree.nil? %>
<% for a in @tree.ancestors %>
<%= link_to(a.subject.term, treemap_path(:id => a.id)) %>
<% end %>
<%= @tree.subject.term %>
<% end %>
<ul>
<% for t in MeshTree.children(@tree_id) %>
<% unless t.subject.nil? %>
<li><%= link_to(t.subject.term, treemap_path(:id => t.id)) %></li>
<% end %>
<% end %>
</ul>
1 change: 1 addition & 0 deletions config/routes.rb
@@ -1,4 +1,5 @@
ActionController::Routing::Routes.draw do |map|
map.treemap "treemap/:id", :controller => "treemap"
# The priority is based upon order of creation: first created -> highest priority.

# Sample of regular route:
Expand Down
32 changes: 16 additions & 16 deletions db/mesh_trees.dat
@@ -1,4 +1,4 @@
1 A 999901 0
1 A 999901
2 A01 1829 1
3 A01.047 5 2
4 A01.047.025 34841 3
Expand Down Expand Up @@ -2662,7 +2662,7 @@
2662 A17.815.830 13545 2657
2663 A17.815.830.206 1050 2662
2664 A17.815.830.480 4439 2662
2665 B 999902 0
2665 B 999902
2666 B01 818 2665
2667 B01.050 828 2666
2668 B01.050.116 829 2667
Expand Down Expand Up @@ -7615,7 +7615,7 @@
7615 B07.600 46588 7556
7616 B08 50298 2665
7617 B08.700 12228 7616
7618 C 999903 0
7618 C 999903
7619 C01 1423 7618
7620 C01.252 1424 7619
7621 C01.252.100 16470 7620
Expand Down Expand Up @@ -17933,7 +17933,7 @@
17933 C23.888.942.900 53584 17919
17934 C23.888.971 14770 17603
17935 C23.888.971.468 6628 17934
17936 D 999904 0
17936 D 999904
17937 D01 7287 17936
17938 D01.029 143 17937
17939 D01.029.260 148 17938
Expand Down Expand Up @@ -36868,7 +36868,7 @@
36868 D27.888.723.697 10573 36860
36869 D27.888.723.748 10574 36860
36870 D27.888.723.853 12378 36860
36871 E 999905 0
36871 E 999905
36872 E01 3933 36871
36873 E01.158 3936 36872
36874 E01.158.600 7090 36873
Expand Down Expand Up @@ -40634,7 +40634,7 @@
40634 E07.950.500 15919 40633
40635 E07.960 14962 40295
40636 E07.970 14963 40295
40637 F 999906 0
40637 F 999906
40638 F01 1520 40637
40639 F01.058 223 40638
40640 F01.058.288 30141 40639
Expand Down Expand Up @@ -41652,7 +41652,7 @@
41652 F04.754.864.581.813 12681 41646
41653 F04.754.864.696 12114 41643
41654 F04.824 12565 41492
41655 G 999907 0
41655 G 999907
41656 G01 55585 41655
41657 G01.060 55580 41656
41658 G01.060.249 55587 41657
Expand Down Expand Up @@ -44589,7 +44589,7 @@
44589 G17.820.750 16012 44585
44590 G17.830 13269 44573
44591 G17.830.500 8390 44590
44592 H 999908 0
44592 H 999908
44593 H01 10811 44592
44594 H01.158 1690 44593
44595 H01.158.100 715 44594
Expand Down Expand Up @@ -45004,7 +45004,7 @@
45004 H02.956.465 10341 45003
45005 H02.956.692 13522 45003
45006 H02.956.858 14731 45003
45007 I 999909 0
45007 I 999909
45008 I01 12942 45007
45009 I01.076 883 45008
45010 I01.076.201 884 45009
Expand Down Expand Up @@ -45578,7 +45578,7 @@
45578 I03.883.420 5101 45577
45579 I03.946 14937 45523
45580 I03.946.900 14940 45579
45581 J 999910 0
45581 J 999910
45582 J01 13676 45581
45583 J01.040 383 45582
45584 J01.040.090 822 45583
Expand Down Expand Up @@ -46098,7 +46098,7 @@
46098 J02.500.850.790 11198 46076
46099 J02.500.850.800 18724 46076
46100 J02.500.850.900 14674 46076
46101 K 999911 0
46101 K 999911
46102 K01 6809 46101
46103 K01.093 1154 46102
46104 K01.093.206 2325 46103
Expand Down Expand Up @@ -46309,7 +46309,7 @@
46309 K01.844.799.867 15013 46305
46310 K01.844.949 28725 46286
46311 K01.922 35621 46102
46312 L 999912 0
46312 L 999912
46313 L01 7254 46312
46314 L01.040 1868 46313
46315 L01.080 2910 46313
Expand Down Expand Up @@ -46761,7 +46761,7 @@
46761 L01.906.575.622 11338 46759
46762 L01.906.575.748 11382 46759
46763 L01.906.787 18511 46758
46764 M 999913 0
46764 M 999913
46765 M01 9272 46764
46766 M01.050 23 46765
46767 M01.055 32721 46765
Expand Down Expand Up @@ -46987,7 +46987,7 @@
46987 M01.975.790 10822 46984
46988 M01.975.807 37841 46984
46989 M01.975.825 14931 46984
46990 N 999914 0
46990 N 999914
46991 N01 11154 46990
46992 N01.224 3710 46991
46993 N01.224.033 17677 46992
Expand Down Expand Up @@ -49061,7 +49061,7 @@
49061 N06.890.160.215 10512 49057
49062 N06.890.235 5457 49056
49063 N06.890.410 6267 49056
49064 V 999922 0
49064 V 999922
49065 V01 52181 49064
49066 V01.070 20504 49065
49067 V01.100 19480 49065
Expand Down Expand Up @@ -49235,7 +49235,7 @@
49235 V04.500 13487 49232
49236 V04.500.500 52061 49235
49237 V04.500.750 52060 49235
49238 Z 999926 0
49238 Z 999926
49239 Z01 5842 49238
49240 Z01.058 349 49239
49241 Z01.058.266 352 49240
Expand Down
8 changes: 8 additions & 0 deletions test/functional/treemap_controller_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class TreemapControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
4 changes: 4 additions & 0 deletions test/unit/helpers/treemap_helper_test.rb
@@ -0,0 +1,4 @@
require 'test_helper'

class TreemapHelperTest < ActionView::TestCase
end

0 comments on commit 14bb7ba

Please sign in to comment.