myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [3694] branches/packs/app: added title / descript


From: noreply
Subject: [myexperiment-hackers] [3694] branches/packs/app: added title / description sync for packs
Date: Mon, 9 Sep 2013 15:48:59 +0000 (UTC)

Revision
3694
Author
dgc
Date
2013-09-09 15:48:58 +0000 (Mon, 09 Sep 2013)

Log Message

added title / description sync for packs

Modified Paths

Diff

Modified: branches/packs/app/controllers/annotations_controller.rb (3693 => 3694)


--- branches/packs/app/controllers/annotations_controller.rb	2013-09-06 21:26:06 UTC (rev 3693)
+++ branches/packs/app/controllers/annotations_controller.rb	2013-09-09 15:48:58 UTC (rev 3694)
@@ -12,7 +12,7 @@
   before_filter :find_and_auth_resource_context
 
   def index
-    @annotations = @context.research_object.annotations_with_templates
+    @annotations = @context.research_object.all_annotations_with_templates
   end 
 
   def show

Modified: branches/packs/app/controllers/packs_controller.rb (3693 => 3694)


--- branches/packs/app/controllers/packs_controller.rb	2013-09-06 21:26:06 UTC (rev 3693)
+++ branches/packs/app/controllers/packs_controller.rb	2013-09-09 15:48:58 UTC (rev 3694)
@@ -166,6 +166,7 @@
           @pack.tags_user_id = current_user
           @pack.tag_list = convert_tags_to_gem_format params[:pack][:tag_list]
           @pack.update_tags
+          @pack.update_annotations_from_model(current_user)
         end
         
         # update policy
@@ -197,6 +198,7 @@
     respond_to do |format|
       if @pack.update_attributes(params[:pack])
         @pack.refresh_tags(convert_tags_to_gem_format(params[:pack][:tag_list]), current_user) if params[:pack][:tag_list]
+        @pack.update_annotations_from_model(current_user)
         policy_err_msg = update_policy(@pack, params, current_user)
         if policy_err_msg.blank?
           update_layout(@pack, params[:layout]) unless params[:policy_type] == "group"

Modified: branches/packs/app/helpers/research_objects_helper.rb (3693 => 3694)


--- branches/packs/app/helpers/research_objects_helper.rb	2013-09-06 21:26:06 UTC (rev 3693)
+++ branches/packs/app/helpers/research_objects_helper.rb	2013-09-09 15:48:58 UTC (rev 3694)
@@ -22,6 +22,8 @@
       "http://purl.org/wf4ever/roterms#"       => "roterms"
   }
 
+  private
+
   def pretty_rdf_xml(text)
 
     descriptions = { }

Modified: branches/packs/app/models/pack.rb (3693 => 3694)


--- branches/packs/app/models/pack.rb	2013-09-06 21:26:06 UTC (rev 3693)
+++ branches/packs/app/models/pack.rb	2013-09-09 15:48:58 UTC (rev 3694)
@@ -715,6 +715,61 @@
     return ""
   end
 
+  def update_annotations_from_model(user)
+
+    title_annotation = research_object.annotations_of_type("title").first
+    annotation_title = title_annotation[:parameters][:title].to_s if title_annotation
+
+    description_annotation = research_object.annotations_of_type("description").first
+    annotation_description = description_annotation[:parameters][:description].to_s if description_annotation
+
+    if title != annotation_title
+
+      if annotation_title
+        title_annotation[:annotation].ao_body.destroy
+        title_annotation[:annotation].destroy
+      end
+
+      parameters = {}
+
+      parameters[:title]    = RDF::Literal(title)
+      parameters[:resource] = RDF::URI(research_object.uri)
+
+      template = Conf.ro_templates["title"]
+
+      body_graph = research_object.create_graph_using_ro_template(parameters, template)
+
+      research_object.create_annotation(
+          :body_graph => body_graph,
+          :content_type => 'application/rdf+xml',
+          :resources => ['.'],
+          :creator_uri => "/users/#{user.id}")
+    end
+
+    if description != annotation_description
+
+      if annotation_description
+        description_annotation[:annotation].ao_body.destroy
+        description_annotation[:annotation].destroy
+      end
+
+      parameters = {}
+
+      parameters[:description] = RDF::Literal(description)
+      parameters[:resource]    = RDF::URI(research_object.uri)
+
+      template = Conf.ro_templates["description"]
+
+      body_graph = research_object.create_graph_using_ro_template(parameters, template)
+
+      research_object.create_annotation(
+          :body_graph => body_graph,
+          :content_type => 'application/rdf+xml',
+          :resources => ['.'],
+          :creator_uri => "/users/#{user.id}")
+    end
+  end
+
   protected
   
   # produces html string containing the required messaged, enclosed within left-padded P tag, belonging to 'none_text' class

Modified: branches/packs/app/models/research_object.rb (3693 => 3694)


--- branches/packs/app/models/research_object.rb	2013-09-06 21:26:06 UTC (rev 3693)
+++ branches/packs/app/models/research_object.rb	2013-09-09 15:48:58 UTC (rev 3694)
@@ -76,6 +76,11 @@
     resources.find(:first, :conditions => { :is_root_folder => true } )
   end
 
+  def annotations
+    annotation_resources.find(:all,
+        :conditions => { :resource_path => '.' }).map { |ar| ar.annotation }
+  end
+
   def new_or_update_resource(opts = {})
 
     changed = []
@@ -615,10 +620,8 @@
     graph
   end
 
-  def annotations_with_templates
+  def annotations_with_templates_aux(annotations)
 
-    annotations = annotation_resources.map { |annotation_resource| annotation_resource.annotation }
-     
     annotations.uniq.map do |annotation|
 
       graph = load_graph(annotation.ao_body.content_blob.data, :content_type => annotation.ao_body.content_type)
@@ -634,6 +637,26 @@
     end
   end
 
+  def all_annotations_with_templates
+    return @all_annotations_with_templates if @all_annotations_with_templates
+
+    all_annotations = annotation_resources.map { |ar| ar.annotation }
+
+    @all_annotations_with_templates = annotations_with_templates_aux(all_annotations)
+  end
+
+  def annotations_with_templates
+    return @annotations_with_templates if @annotations_with_templates
+
+    @annotations_with_templates = annotations_with_templates_aux(annotations)
+  end
+
+  def annotations_of_type(type)
+    annotations_with_templates.select do |annotation|
+      annotation[:template] && annotation[:template]["label"] == type
+    end
+  end
+
 private
 
   def create_manifest #:nodoc:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]