Diff
Modified: branches/wf4ever/app/controllers/folders_controller.rb (3270 => 3271)
--- branches/wf4ever/app/controllers/folders_controller.rb 2012-12-14 16:56:41 UTC (rev 3270)
+++ branches/wf4ever/app/controllers/folders_controller.rb 2012-12-14 16:56:49 UTC (rev 3271)
@@ -1,39 +1,21 @@
require 'wf4ever/rosrs_client'
+require 'helpers/folders_helper'
class FoldersController < ApplicationController
-
- BASE_URI = "http://sandbox.wf4ever-project.org/rodl/ROs/"
- API_KEY = "32801fc0-1df1-4e34-b"
+ include FoldersHelper
+
def index
- @structure = {}
if params[:ro_uri].blank?
render :text => "Please supply an RO URI."
- else
- @session = ROSRS::Session.new(BASE_URI, API_KEY)
- @ro = ROSRS::ResearchObject.new(@session, params[:ro_uri])
- @structure = {:label => @ro.root_folder.name,
- :labelStyle => "root_folder",
- :uri => @ro.root_folder.uri}
- @resources = {}
- (@ro.resources + @ro.folders).each do |res|
- type = 'folder'
- leaf = false
- unless res.is_a?(ROSRS::Folder)
- type = 'resource'
- leaf = true
- end
- @resources[res.uri] = {:labelStyle => type, :uri => res.uri, :isLeaf => leaf}
- end
end
# Renders folder.html.erb
end
# Get a folder's contents when it is expanded in the UI
def folder_contents
- @session = ROSRS::Session.new(BASE_URI, API_KEY)
- @ro = ROSRS::ResearchObject.new(@session, params[:ro_uri])
- folder = ROSRS::Folder.new(@ro, params[:folder_uri])
+ ro = make_research_object(params[:ro_uri])
+ folder = ROSRS::Folder.new(ro, params[:folder_uri])
@contents = folder.contents.map {|fe| [fe.resource.uri, fe.name]}
respond_to do |format|
format.js { render :json => @contents }
Added: branches/wf4ever/app/helpers/folders_helper.rb (0 => 3271)
--- branches/wf4ever/app/helpers/folders_helper.rb (rev 0)
+++ branches/wf4ever/app/helpers/folders_helper.rb 2012-12-14 16:56:49 UTC (rev 3271)
@@ -0,0 +1,35 @@
+# myExperiment: app/helpers/folders_helper.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+module FoldersHelper
+ # TODO: Move to config
+ BASE_URI = "http://sandbox.wf4ever-project.org/rodl/ROs/"
+ API_KEY = "32801fc0-1df1-4e34-b"
+
+ def make_research_object(ro_uri)
+ session = ROSRS::Session.new(BASE_URI, API_KEY)
+ ROSRS::ResearchObject.new(session, ro_uri)
+ end
+
+ def make_tree_view_structure(ro)
+ {:label => ro.root_folder.name,
+ :labelStyle => "root_folder",
+ :uri => ro.root_folder.uri}
+ end
+
+ def make_resources(ro)
+ resources = {}
+ (ro.resources + ro.folders).each do |res|
+ type = 'folder'
+ leaf = false
+ unless res.is_a?(ROSRS::Folder)
+ type = 'resource'
+ leaf = true
+ end
+ resources[res.uri] = {:labelStyle => type, :uri => res.uri, :isLeaf => leaf}
+ end
+ resources
+ end
+
+end
\ No newline at end of file
Modified: branches/wf4ever/app/views/folders/_navigation.html.erb (3270 => 3271)
--- branches/wf4ever/app/views/folders/_navigation.html.erb 2012-12-14 16:56:41 UTC (rev 3270)
+++ branches/wf4ever/app/views/folders/_navigation.html.erb 2012-12-14 16:56:49 UTC (rev 3271)
@@ -1,3 +1,9 @@
+<%
+ro = make_research_object(ro_uri)
+structure = make_tree_view_structure(ro)
+resources = make_resources(ro)
+
+%>
<div id="nav-tabs" class="yui-navset">
<ul class="yui-nav">
<li class="selected"><a href="" View</em></a></li>
@@ -17,8 +23,8 @@
</div>
<script type="text/_javascript_">
- var tree = new YAHOO.widget.TreeView("tree", <%= @structure.to_json.html_safe -%> );
- var resourceData = <%= @resources.to_json.html_safe -%>; // Hash of RO resource data
+ var tree = new YAHOO.widget.TreeView("tree", <%= structure.to_json.html_safe -%> );
+ var resourceData = <%= resources.to_json.html_safe -%>; // Hash of RO resource data
// Handle users clicking on nodes
tree.subscribe("labelClick", function(node) {
@@ -32,7 +38,7 @@
function loadNodeData(node, fnLoadComplete) {
var nodeLabel = encodeURI(node.label);
- var sUrl = "<%= folder_contents_url -%>?folder_uri=" + node.data.uri + "&ro_uri=" + "<%= @ro.uri -%>";
+ var sUrl = "<%= folder_contents_url -%>?folder_uri=" + node.data.uri + "&ro_uri=" + "<%= ro_uri -%>";
var callback = {
success: function(oResponse) {
var oResults = eval("(" + oResponse.responseText + ")");
Modified: branches/wf4ever/app/views/folders/index.html.erb (3270 => 3271)
--- branches/wf4ever/app/views/folders/index.html.erb 2012-12-14 16:56:41 UTC (rev 3270)
+++ branches/wf4ever/app/views/folders/index.html.erb 2012-12-14 16:56:49 UTC (rev 3271)
@@ -5,7 +5,7 @@
<div class="content">
<div class="navigation">
- <%= render "folders/navigation" %>
+ <%= render :partial => "folders/navigation", :locals => {:ro_uri => params[:ro_uri]} %>
</div>
<div class="main">
<div id="demo" class="yui-navset">
Modified: branches/wf4ever/app/views/research_objects/_tree.rhtml (3270 => 3271)
--- branches/wf4ever/app/views/research_objects/_tree.rhtml 2012-12-14 16:56:41 UTC (rev 3270)
+++ branches/wf4ever/app/views/research_objects/_tree.rhtml 2012-12-14 16:56:49 UTC (rev 3271)
@@ -5,7 +5,7 @@
<div class="rotree">
- This is the tree
+ <%= render :partial => "folders/navigation", :locals => {:ro_uri => @contributable.url} %>
</div>
Modified: branches/wf4ever/app/views/research_objects/show.rhtml (3270 => 3271)
--- branches/wf4ever/app/views/research_objects/show.rhtml 2012-12-14 16:56:41 UTC (rev 3270)
+++ branches/wf4ever/app/views/research_objects/show.rhtml 2012-12-14 16:56:49 UTC (rev 3271)
@@ -47,9 +47,9 @@
<%= render :partial => "research_objects/diagram", :locals => { :contributable => @contributable } -%>
<%= render :partial => "research_objects/attribution", :locals => { :contributable => @contributable } -%>
- <%= render :partial => "research_objects/resources", :locals => { :contributable => @contributable } -%>
<% if false %>
+ <%= render :partial => "research_objects/resources", :locals => { :contributable => @contributable } -%>
<%= render :partial => "research_objects/manifest", :locals => { :contributable => @contributable } -%>
<%= render :partial => "research_objects/annotations", :locals => { :contributable => @contributable } -%>
<%= render :partial => "research_objects/statements", :locals => { :contributable => @contributable } -%>
@@ -81,6 +81,8 @@
<%= render :partial => "research_objects/status", :locals => { :contributable => @contributable } -%>
<%= render :partial => "research_objects/tree", :locals => { :contributable => @contributable } -%>
+ <% if false %>
+<% end %>
<%= render :partial => "contributions/uploader_box", :locals => { :contributable => @contributable } %>