Class: FinderController

Inherits:
ApplicationController show all
Defined in:
app/controllers/finder_controller.rb

Overview

require “create_activeresources”

Instance Method Summary collapse

Instance Method Details

#add_to_listObject



65
66
67
68
69
# File 'app/controllers/finder_controller.rb', line 65

def add_to_list
  path = params[:path]
  add_node_to_list(path)
  redirect_to(:controller => "analysis")
end

#childrenObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/finder_controller.rb', line 47

def children
  user = (=session[:user]) && User.()
  unless (path = params[:path]) && (parent = find_node(path,user) )
    head :not_found
    return
  end

  unless request.xhr?
    redirect_to :action => :index
    return
  end
  
  selected = params[:selected]

  session[:dir_tree] ||= Array.new
  open_dir([], [parent], session, selected)
end

#clear_treeObject



12
13
14
15
16
17
# File 'app/controllers/finder_controller.rb', line 12

def clear_tree
  session[:dir_tree] = nil
  session[:dir_tree_closed] = nil
  session[:dir_tree_selected] = nil
  redirect_to :action => :index
end

#create_treeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/finder_controller.rb', line 19

def create_tree
  if (path = params[:path])
    dir = open_tree(path)
    @selected_dir = session[:dir_tree_selected] = dir
  end
  @user = (=session[:user]) && User.()
  @parent = nil
  @dirs = Node.top_directory_nodes
  if GFDNAVI_OTHER_GFDNAVI_SERVERS
    GFDNAVI_OTHER_GFDNAVI_SERVERS.each{|gs|
    }
  end
=begin
 Node_Remote.each{|nr|
    @dirs += nr.find(:all, :from => :top_directory_nodes)
  }
=end
  @opened_dirs = (session[:dir_tree] ||= Array.new)
  @closed_dirs = (session[:dir_tree_closed] ||= Array.new)
  @selected_dir = session[:dir_tree_selected]
  if @dirs.length == 1
    path = @dirs[0].full_path
    @opened_dirs.push(path) unless @opened_dirs.include?(path)
    @closed_dirs.delete(path)
  end
  render :layout => false
end

#dir_statusObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/controllers/finder_controller.rb', line 94

def dir_status
  unless request.xhr?
    redirect_to :action => :index
    return
  end
  session[:dir_tree_closed] ||= Array.new
  user = (=session[:user]) && User.()
  if (path = params["opened"])
    session[:dir_tree_closed].delete path
    if params["selected"]
      dir = Node.find(:first, :conditions=>["path=?",path], :user=>user)
      session[:dir_tree_selected] = dir
    end
  elsif (path = params["closed"])
    dir = Node.find(:first, :conditions=>["path=?",path], :user=>user)
    if dir
      session[:dir_tree_closed].push(path) unless session[:dir_tree_closed].include?(path)
      if (dir_selected = session[:dir_tree_selected])
        dir_selected_path = dir_selected.path
        if /^#{path}/ =~ dir_selected_path && path != dir_selected_path
          render :update do |page|
            session[:dir_tree_selected] = dir
            page << "tree.dirSelected('#{path}', true);"
          end
          return
        end
      end
    end
  end
  render :nothing => true
end

#flexObject



216
217
218
219
# File 'app/controllers/finder_controller.rb', line 216

def flex
  @uri_prefix = uri_prefix.sub(/^http:\/\//,"")
  render :layout => false
end

#indexObject



8
9
10
# File 'app/controllers/finder_controller.rb', line 8

def index
  @path = params[:path]
end

#items_selectedObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/finder_controller.rb', line 71

def items_selected
  button = String.new
  params.keys.each { |key|
    case key
    when /^anal_viz/
      button = "Anal/Viz checked items"
      break
    when /^show/
      button = "Show checked items"
      break
    when /^dl/
      button = "Download checked items"
      break
    end
  }
  case button
    when "Anal/Viz checked items" then anal_viz_checked_items
    when "Show checked items"     then show_checked_items
    when "Download checked items" then download_checked_items
    else                          raise "error.\n"
  end
end

#open_tree(path) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'app/controllers/finder_controller.rb', line 152

def open_tree(path)
  if path
    flag = true
  else
    unless request.xhr?
      redirect_to :action => :index
      return
    end
    path = params[:path]
    flag = false
  end
  user = (=session[:user]) && User.()
  unless path && dir = find_node(path,user)
    render(:nothing => true) unless flag
    return
  end
  tree = ( session[:dir_tree] ||= Array.new )
  closed = ( session[:dir_tree_closed] ||= Array.new )
  ancestors = Array.new
  closes = Array.new unless flag
  parent = dir
  while (parent = parent.parent)
    pa = parent.full_path
    if tree.include?(pa)
      if closed.include?(pa)
        if flag
          closed.delete parent.path
        else
          closes.unshift parent
        end
      end
    else
      ancestors.unshift parent
    end
  end
  if flag
    ancestors.each{|an| tree.push an.full_path}
    return dir
  else
    closes.push(dir) if tree.include?(path) && !closed.include?(path)
    open_dir(closes, ancestors, session, false)
  end
end

#show_detailsObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'app/controllers/finder_controller.rb', line 126

def show_details
  if GFDNAVI_DATA_URL_PREFIX
    @url_prefix = (respond_to?(:relative_url_root) ? (relative_url_root || "") : request.respond_to?(:relative_url_root) ? request.relative_url_root : raise("bug") ) + GFDNAVI_DATA_URL_PREFIX
  end
  user = (=session[:user]) && User.()
  if path = params[:path]
    dir = find_node(path,user)
  else
    dir = session[:dir_tree_selected]
  end
  if dir
    session[:dir_tree_selected] = dir
    order = params[:order]
    @user = user
    @path = dir.path
    @dirs = dir.directory_nodes(:user=>@user, :order=>order)
    @dirs.delete_if {|d| d.name =~ /^[.]/}
    @vars = dir.variable_nodes(:user=>@user, :order=>order)
    @imgs = dir.image_nodes(:user=>@user, :order=>order)
    @klgs = dir.knowledge_nodes(:user=>@user, :order=>order)
    render :layout => false
  else
    render :nothing => true
  end
end

#show_imagesObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'app/controllers/finder_controller.rb', line 196

def show_images
  if path = params[:path]
    list = [[path, "1"]]
  else
    list = params[:list]
  end
  @images = Array.new
  if list
    list.each{|path,v|
      if v == "1"
        user = (=session[:user]) && User.()
        node = Node.find(:first, :conditions => ["path=?", path], :user => user)
        @images << path if node.image?
      end
    }
  end
  render :layout => !request.xhr?
end