Added: branches/packs/app/controllers/annotations_controller.rb (0 => 3630)
--- branches/packs/app/controllers/annotations_controller.rb (rev 0)
+++ branches/packs/app/controllers/annotations_controller.rb 2013-08-27 13:43:09 UTC (rev 3630)
@@ -0,0 +1,101 @@
+# myExperiment: app/controllers/annotations_controller.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+require 'rdf'
+
+include ResearchObjectsHelper
+
+class AnnotationsController < ApplicationController
+
+ def index
+ @pack = Pack.find(params[:pack_id])
+
+ @annotations = @pack.research_object.annotations_with_templates
+ end
+
+ def show
+ @pack = Pack.find(params[:pack_id])
+
+ @annotation = @pack.research_object.resources.find(:first, :conditions => { :uuid => params[:id] })
+
+ @graph = load_graph(@annotation.ao_body.content_blob.data, @annotation.ao_body.content_type)
+
+ @annotation_template, @parameters = @pack.research_object.find_template_from_graph(@graph, Conf.ro_templates)
+ end
+
+ def create
+
+ pack = Pack.find(params[:pack_id])
+
+ unless Authorization.check('create', Resource, current_user, pack)
+ render_401("You are not authorized to view this resource's relationships.")
+ return
+ end
+
+ template = Conf.ro_templates[params[:annotation_type]]
+
+ if template.nil?
+ render_500("Unknown annotation type")
+ return
+ end
+
+ parameters = {}
+
+ template["parameters"].each do |parameter|
+
+ parameters[parameter["symbol"]] = case parameter["type"]
+
+ when "string"
+ RDF::Literal(params[parameter["symbol"]])
+ when "resource"
+ pack.research_object.find_using_path(params[parameter["symbol"]]).uri
+ end
+ end
+
+puts "template = #{template.inspect}"
+puts "parameters = #{parameters.inspect}"
+ targets = template["targets"].map { |t| parameters[t] }
+
+puts "targets = #{targets.inspect}"
+ graph = Pack.first.research_object.create_graph_using_ro_template(parameters, template)
+
+ pack.research_object.create_annotation(
+ :body_graph => graph,
+ :content_type => 'application/rdf+xml',
+ :resources => targets,
+ :creator_uri => user_path(current_user))
+
+ redirect_to pack_path(pack)
+ end
+
+ def destroy
+
+ pack = Pack.find(params[:pack_id])
+
+ annotation = pack.research_object.resources.find_by_uuid(params[:id])
+
+ # Destroy annotation body and also the annotation
+
+ annotation.ao_body.destroy
+ annotation.destroy
+
+ pack.research_object.update_manifest!
+
+ redirect_to pack_path(pack)
+ end
+
+ def new
+
+ @pack = Pack.find(params[:pack_id])
+
+ @annotation_template = Conf.ro_templates[params[:template]]
+
+ if address@hidden
+ render_404("Annotation template not found.")
+ return
+ end
+ end
+
+end
Added: branches/packs/app/views/packs/item_show.html.erb (0 => 3630)
--- branches/packs/app/views/packs/item_show.html.erb (rev 0)
+++ branches/packs/app/views/packs/item_show.html.erb 2013-08-27 13:43:09 UTC (rev 3630)
@@ -0,0 +1,70 @@
+<h1>Item: <%= @title -%></h1>
+
+<h2>Metadata</h2>
+
+<table class="metadata">
+ <tr>
+ <td>Title</td>
+ <td>
+ <%=h @title -%>
+ <%= link_to('Add title', new_pack_annotation_path(@pack, { :template => 'title', :resource => @item.path })) -%>
+ </td>
+ </tr>
+ <tr>
+ <td>File name</td>
+ <td><%=h @item.folder_entry.entry_name -%></td>
+ </tr>
+ <tr>
+ <td>File size</td>
+ <td><%=h @item.size.to_s -%></td>
+ </tr>
+ <tr>
+ <td>SHA1</td>
+ <td class="sha1"><%=h @item.sha1 -%></td>
+ </tr>
+ <tr>
+ <td>Content type</td>
+ <td class="content_type"><%=h @item.content_type -%></td>
+ </tr>
+</table>
+
+<h1>Debug</h1>
+
+<div id="tabsContainer" class="tabsContainer"></div>
+
+<div class="tabContainer">
+ <div class="tabTitle">User level annotations</div>
+ <div class="tabContent">
+ <% @visible_annotations.each do |annotation| %>
+ <%= render(:partial => "annotation", :locals => { :pack => @pack, :annotation => annotation } ) -%>
+ <% end %>
+ </div>
+</div>
+
+<div class="tabContainer">
+ <div class="tabTitle">Annotation graphs</div>
+ <div class="tabContent">
+ <% @annotations.each do |annotation| %>
+
+ <h2><%=h annotation[:template].inspect -%></h2>
+ <p><%=h annotation[:annotation].uri.to_s -%></p>
+
+ <% annotation[:graph].each do |statement| %>
+ <div style="margin: 8px; box-shadow: 4px 4px 8px #ddd;">
+ <table class="simple" style="width: 100%">
+ <tr><td><%=h statement.subject -%></td></tr>
+ <tr><td><%=h statement.predicate -%></td></tr>
+ <tr><td><%=h statement.object -%></td></tr>
+ </table>
+ </div>
+ <% end %>
+ <% end %>
+ </div>
+</div>
+
+<div class="tabContainer">
+ <div class="tabTitle">Resource metadata</div>
+ <div class="tabContent">
+ <pre><%=h @item.to_yaml -%></pre>
+ </div>
+</div>