myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2436] trunk: reorganised comments as a nested re


From: noreply
Subject: [myexperiment-hackers] [2436] trunk: reorganised comments as a nested resource
Date: Mon, 21 Jun 2010 20:30:43 -0400 (EDT)

Revision
2436
Author
dgc
Date
2010-06-21 20:30:43 -0400 (Mon, 21 Jun 2010)

Log Message

reorganised comments as a nested resource

Modified Paths

Removed Paths

Diff

Modified: trunk/app/controllers/application.rb (2435 => 2436)


--- trunk/app/controllers/application.rb	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/app/controllers/application.rb	2010-06-22 00:30:43 UTC (rev 2436)
@@ -358,5 +358,15 @@
     end
     
   end
-  
+ 
+  # helper function to determine the context of a polymorphic nested resource
+
+  def extract_resource_context(params)
+    (Conf.contributor_models + Conf.contributable_models).each do |model_name|
+      id_param = "#{Conf.to_visible(model_name.underscore)}_id"
+      return Object.const_get(model_name).find_by_id(params[id_param]) if params[id_param]
+    end
+
+    nil
+  end 
 end

Modified: trunk/app/controllers/blobs_controller.rb (2435 => 2436)


--- trunk/app/controllers/blobs_controller.rb	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/app/controllers/blobs_controller.rb	2010-06-22 00:30:43 UTC (rev 2436)
@@ -191,45 +191,6 @@
     end
   end
   
-  # POST /files/1;comment
-  def comment 
-    text = params[:comment][:comment]
-    ajaxy = true
-    
-    if text.nil? or (text.length == 0)
-      text = params[:comment_0_comment_editor]
-      ajaxy = false
-    end
-
-    if text and text.length > 0
-      comment = Comment.create(:user => current_user, :comment => text)
-      @blob.comments << comment
-    end
-    
-    respond_to do |format|
-      if ajaxy
-        format.html { render :partial => "comments/comments", :locals => { :commentable => @blob } }
-      else
-        format.html { redirect_to file_url(@blob) }
-      end
-    end
-  end
-  
-  # DELETE /files/1;comment_delete
-  def comment_delete
-    if params[:comment_id]
-      comment = Comment.find(params[:comment_id].to_i)
-      # security checks:
-      if comment.user_id == current_user.id and comment.commentable_type.downcase == 'blob' and comment.commentable_id == @blob.id
-        comment.destroy
-      end
-    end
-    
-    respond_to do |format|
-      format.html { render :partial => "comments/comments", :locals => { :commentable => @blob } }
-    end
-  end
-  
   # POST /files/1;rate
   def rate
     if @blob.contributor_type == 'User' and @blob.contributor_id == current_user.id

Modified: trunk/app/controllers/networks_controller.rb (2435 => 2436)


--- trunk/app/controllers/networks_controller.rb	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/app/controllers/networks_controller.rb	2010-06-22 00:30:43 UTC (rev 2436)
@@ -7,7 +7,7 @@
   before_filter :login_required, :except => [:index, :show, :search, :all]
   
   before_filter :find_networks, : [:all]
-  before_filter :find_network, : [:membership_request, :show, :comment, :comment_delete, :tag]
+  before_filter :find_network, : [:membership_request, :show, :tag]
   before_filter :find_network_auth, : [:invite, :membership_invite, :membership_invite_external, :edit, :update, :destroy]
   
   # declare sweepers and which actions should invoke them
@@ -392,46 +392,7 @@
       format.html { redirect_to groups_url }
     end
   end
-  
-  # POST /networks/1;comment
-  def comment
-    text = params[:comment][:comment]
-    ajaxy = true
-    
-    if text.nil? or (text.length == 0)
-      text = params[:comment_0_comment_editor]
-      ajaxy = false
-    end
-    
-    if text and text.length > 0
-      comment = Comment.create(:user => current_user, :comment => text)
-      @network.comments << comment
-    end
-    
-    respond_to do |format|
-      if ajaxy
-        format.html { render :partial => "comments/comments", :locals => { :commentable => @network } }
-      else
-        format.html { redirect_to group_url(@network) }
-      end
-    end
-  end
-  
-  # DELETE /networks/1;comment_delete
-  def comment_delete
-    if params[:comment_id]
-      comment = Comment.find(params[:comment_id].to_i)
-      # security checks:
-      if comment.user_id == current_user.id and comment.commentable_type.downcase == 'network' and comment.commentable_id == @network.id
-        comment.destroy
-      end
-    end
-    
-    respond_to do |format|
-      format.html { render :partial => "comments/comments", :locals => { :commentable => @network } }
-    end
-  end
-  
+ 
   # POST /networks/1;tag
   def tag
     @network.tags_user_id = current_user

Modified: trunk/app/controllers/packs_controller.rb (2435 => 2436)


--- trunk/app/controllers/packs_controller.rb	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/app/controllers/packs_controller.rb	2010-06-22 00:30:43 UTC (rev 2436)
@@ -183,45 +183,6 @@
     end
   end
   
-  # POST /packs/1;comment
-  def comment 
-    text = params[:comment][:comment]
-    ajaxy = true
-    
-    if text.nil? or (text.length == 0)
-      text = params[:comment_0_comment_editor]
-      ajaxy = false
-    end
-
-    if text and text.length > 0
-      comment = Comment.create(:user => current_user, :comment => text)
-      @pack.comments << comment
-    end
-    
-    respond_to do |format|
-      if ajaxy
-        format.html { render :partial => "comments/comments", :locals => { :commentable => @pack } }
-      else
-        format.html { redirect_to pack_url(@pack) }
-      end
-    end
-  end
-  
-  # DELETE /packs/1;comment_delete
-  def comment_delete
-    if params[:comment_id]
-      comment = Comment.find(params[:comment_id].to_i)
-      # security checks:
-      if comment.user_id == current_user.id and comment.commentable_type == 'Pack' and comment.commentable_id == @pack.id
-        comment.destroy
-      end
-    end
-    
-    respond_to do |format|
-      format.html { render :partial => "comments/comments", :locals => { :commentable => @pack } }
-    end
-  end
-  
   # POST /packs/1;tag
   def tag
     @pack.tags_user_id = current_user # acts_as_taggable_redux

Modified: trunk/app/controllers/workflows_controller.rb (2435 => 2436)


--- trunk/app/controllers/workflows_controller.rb	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/app/controllers/workflows_controller.rb	2010-06-22 00:30:43 UTC (rev 2436)
@@ -61,56 +61,6 @@
     end
   end
   
-  # POST /workflows/1;comment
-  def comment
-    text = params[:comment][:comment]
-    ajaxy = true
-
-    if text.nil? or (text.length == 0)
-      text = params[:comment_0_comment_editor]
-      ajaxy = false
-    end
-    
-    if text and text.length > 0
-      comment = Comment.create(:user => current_user, :comment => text)
-      @workflow.comments << comment
-    end
-  
-    respond_to do |format|
-      if ajaxy
-        format.html { render :partial => "comments/comments", :locals => { :commentable => @workflow } }
-      else
-        format.html { redirect_to workflow_url(@workflow) }
-      end
-    end
-  end
-  
-  # DELETE /workflows/1;comment_delete
-  def comment_delete
-    if params[:comment_id]
-      comment = Comment.find(params[:comment_id].to_i)
-      comment.destroy if Authorization.check(:action ="" 'destroy', :object => comment, :user => current_user)
-    end
-    
-    respond_to do |format|
-      format.html { render :partial => "comments/comments", :locals => { :commentable => @workflow } }
-    end
-  end
-  
-  def comments_timeline
-    respond_to do |format|
-      format.html # comments_timeline.rhtml
-    end
-  end
-  
-  # For simile timeline
-  def comments
-    @comments = Comment.find(:all, :conditions => [ "commentable_id = ? AND commentable_type = ? AND created_at > ? AND created_at < ?", @workflow.id, 'Workflow', params[:start].to_time, params[:end].to_time ] )
-    respond_to do |format|
-      format.json { render :partial => 'comments/timeline_json', :layout => false }
-    end
-  end
-  
   # POST /workflows/1;rate
   def rate
     if @workflow.contribution.contributor_type == 'User' and @workflow.contribution.contributor_id == current_user.id

Modified: trunk/app/views/comments/_comment.rhtml (2435 => 2436)


--- trunk/app/views/comments/_comment.rhtml	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/app/views/comments/_comment.rhtml	2010-06-22 00:30:43 UTC (rev 2436)
@@ -21,7 +21,7 @@
 					[
 					<%= link_to_remote( "delete",
 							:update => "commentsBox", 
-							:url ="" { :controller => controller.controller_name.to_s, :action ="" "comment_delete", :comment_id => comment.id },
+							:url ="" rest_resource_uri(comment.commentable) + "/comments/#{comment.id}",
 							:method => :delete,
 							:complete => "new Effect.Highlight('commentsBox', { duration: 1.5 }); $('comment').value = '';",
 							:confirm => "Are you sure you want to delete this comment?" ) %>

Modified: trunk/app/views/comments/_comments.rhtml (2435 => 2436)


--- trunk/app/views/comments/_comments.rhtml	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/app/views/comments/_comments.rhtml	2010-06-22 00:30:43 UTC (rev 2436)
@@ -8,11 +8,9 @@
 	<span class="count_text" style="vertical-align: middle;">(<%= commentable.comments.length %>)</span>
 </h2>
 
-<% if url_to_timeline -%>
-	<ul class="sectionIcons">
-		<li><%= icon('timeline', url_to_timeline, nil, nil, 'View Timeline')%></li>
-	</ul>
-<% end -%>
+<ul class="sectionIcons">
+  <li><%= icon('timeline', rest_resource_uri(commentable) + "/comments/timeline", nil, nil, 'View Timeline')%></li>
+</ul>
 
 <div class="commentsBox">
 	
@@ -45,7 +43,7 @@
 			<% # Hack for FCKEditor: -%>
 			<% @comment = Comment.new; @comment.id = 0 -%>
 			
-			<% form_remote_tag(:url ="" { :controller => controller.controller_name.to_s, :action ="" "comment" },
+			<% form_remote_tag(:url ="" rest_resource_uri(commentable) + "/comments",
 								 :before => fckeditor_before_js("comment", "comment"),
 							   :update => 'commentsBox', 
 							   :loading => "Element.show('addcomment_indicator')",

Deleted: trunk/app/views/comments/_timeline.rhtml (2435 => 2436)


--- trunk/app/views/comments/_timeline.rhtml	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/app/views/comments/_timeline.rhtml	2010-06-22 00:30:43 UTC (rev 2436)
@@ -1,37 +0,0 @@
-<%
-  comments_timeline = ::Simile::Timeline::Timeline.new(
-    :name        => "Comments",
-    :event_source => comments_url_for_timeline,
-    :event_band   => :days,
-    :bands       => {
-      :months => {
-        :trackGap       => '0.1',
-        :showEventText  => 'false',
-        :width          => '"25%"',
-        :intervalUnit   => 'Timeline.DateTime.MONTH',
-        :intervalPixels => '200'
-      },
-      :days => {
-        :trackGap       => '0.1',
-        :showEventText  => 'false',
-        :width          => '"25%"',
-        :intervalUnit   => 'Timeline.DateTime.DAY',
-        :intervalPixels => '100'
-      },
-      :hours => {
-        :width          => '"50%"',
-        :intervalUnit   => 'Timeline.DateTime.HOUR',
-        :intervalPixels => '20'
-      }
-    },
-    :bands_order => [ :months, :days, :hours ],
-    :synchronize => {
-      :months => :hours,
-      :days   => :hours
-    },
-    :highlight => [ :months, :days ]
-  )
-
-%>
-
-<%= simile_timeline(comments_timeline, { :class => 'default_timeline' } ) %>
\ No newline at end of file

Modified: trunk/app/views/layouts/_myexperiment.rhtml (2435 => 2436)


--- trunk/app/views/layouts/_myexperiment.rhtml	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/app/views/layouts/_myexperiment.rhtml	2010-06-22 00:30:43 UTC (rev 2436)
@@ -13,7 +13,7 @@
 		<%= stylesheet_link_tag Conf.stylesheet %>
 		<%= stylesheet_link_tag 'gadgets' %>
 		
-		<% if ["workflows", "users"].include?(controller.controller_name.downcase) and ["comments_timeline", "timeline"].include?(controller.action_name.downcase) -%>
+		<% if controller.action_name.downcase == "timeline" %>
 			<script src="" type="text/_javascript_"></script>
 		<% end -%>
 		

Deleted: trunk/app/views/workflows/comments_timeline.rhtml (2435 => 2436)


--- trunk/app/views/workflows/comments_timeline.rhtml	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/app/views/workflows/comments_timeline.rhtml	2010-06-22 00:30:43 UTC (rev 2436)
@@ -1,3 +0,0 @@
-<h1>Comments Timeline for Workflow: <%= contributable @workflow.id, 'Workflow' %></h1>
-
-<%= render :partial => "comments/timeline", :locals => { :comments_url_for_timeline => comments_workflow_url(@workflow) } %>

Modified: trunk/app/views/workflows/show.rhtml (2435 => 2436)


--- trunk/app/views/workflows/show.rhtml	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/app/views/workflows/show.rhtml	2010-06-22 00:30:43 UTC (rev 2436)
@@ -369,7 +369,7 @@
 <br/>
 
 <div id="commentsBox">
-	<%= render :partial => "comments/comments", :locals => { :commentable => @workflow, :url_to_timeline => comments_timeline_workflow_path(@workflow) } %>
+	<%= render :partial => "comments/comments", :locals => { :commentable => @workflow } %>
 </div>
 
 <%= render :partial => "contributions/alternative_formats", :locals => {

Modified: trunk/config/default_settings.yml (2435 => 2436)


--- trunk/config/default_settings.yml	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/config/default_settings.yml	2010-06-22 00:30:43 UTC (rev 2436)
@@ -33,6 +33,16 @@
 
 site_logo: logo.png
 
+# contributor_models - These are the models for things that can contribute to
+#                      myExperiment.
+
+contributor_models: [User, Network]
+
+# contributable_models - These are the models for the things that myExperiment
+#                        contributors can contribute.
+
+contributable_models: [Workflow, Blob, Pack, Blog]
+
 # page_template - This is the page template for all the pages except for
 #                 the front page of the web site.
 #

Modified: trunk/config/routes.rb (2435 => 2436)


--- trunk/config/routes.rb	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/config/routes.rb	2010-06-22 00:30:43 UTC (rev 2436)
@@ -77,9 +77,7 @@
   # packs
   map.resources :packs, 
     :collection => { :search => :get }, 
-    :member => { :comment => :post, 
-                 :comment_delete => :delete,
-                 :statistics => :get,
+    :member => { :statistics => :get,
                  :favourite => :post,
                  :favourite_delete => :delete,
                  :tag => :post,
@@ -92,7 +90,7 @@
                  :quick_add => :post,
                  :resolve_link => :post,
                  :items => :get } do |pack|
-    # No nested resources yet
+    pack.resources :comments, :collection => { :timeline => :get }
   end
     
 
@@ -105,21 +103,18 @@
                  :statistics => :get,
                  :favourite => :post, 
                  :favourite_delete => :delete, 
-                 :comment => :post, 
-                 :comment_delete => :delete, 
                  :rate => :post, 
                  :tag => :post, 
                  :create_version => :post, 
                  :destroy_version => :delete, 
                  :edit_version => :get, 
                  :update_version => :put, 
-                 :comments_timeline => :get, 
-                 :comments => :get,
                  :process_tag_suggestions => :post,
                  :tag_suggestions => :get } do |workflow|
     # workflows have nested citations
     workflow.resources :citations
     workflow.resources :reviews
+    workflow.resources :comments, :collection => { :timeline => :get }
   end
 
   # workflow redirect for linked data model
@@ -143,14 +138,13 @@
                  :statistics => :get,
                  :favourite => :post,
                  :favourite_delete => :delete,
-                 :comment => :post, 
-                 :comment_delete => :delete, 
                  :rate => :post, 
                  :tag => :post } do |file|
     # Due to restrictions in the version of Rails used (v1.2.3), 
     # we cannot have reviews as nested resources in more than one top level resource.
     # ie: we cannot have polymorphic nested resources.
     #file.resources :reviews
+    file.resources :comments, :collection => { :timeline => :get }
   end
 
   # blogs
@@ -222,11 +216,10 @@
                  :membership_invite => :post,
                  :membership_invite_external => :post,
                  :membership_request => :get, 
-                 :comment => :post, 
-                 :comment_delete => :delete, 
                  :rate => :post, 
                  :tag => :post } do |group|
     group.resources :announcements, :controller => :group_announcements
+    group.resources :comments, :collection => { :timeline => :get }
   end
   
   # The priority is based upon order of creation: first created -> highest priority.

Modified: trunk/lib/conf.rb (2435 => 2436)


--- trunk/lib/conf.rb	2010-06-17 20:25:36 UTC (rev 2435)
+++ trunk/lib/conf.rb	2010-06-22 00:30:43 UTC (rev 2436)
@@ -26,6 +26,14 @@
     self.fetch_entry('site_logo')
   end
 
+  def self.contributor_models
+    self.fetch_entry('contributor_models')
+  end
+
+  def self.contributable_models
+    self.fetch_entry('contributable_models')
+  end
+
   def self.notifications_email_address
     self.fetch_entry('notifications_email_address')
   end
@@ -172,8 +180,29 @@
     @config = session["portal"] if session["portal"]
   end
 
+  # helper function to convert model aliases
+
+  def self.to_model(str)
+    self.model_alias_convert(self.model_aliases, str)
+  end
+
+  def self.to_visible(str)
+    self.model_alias_convert(self.model_aliases.invert, str)
+  end
+
 private
 
+  def self.model_alias_convert(map, str)
+    map.each do |k, v|
+      return v                      if str == k
+      return v.underscore           if str == k.underscore
+      return v.pluralize            if str == k.pluralize
+      return v.underscore.pluralize if str == k.underscore.pluralize
+    end
+
+    str
+  end
+
   def self.fetch_entry(key, default = nil)
 
     if @config != nil

reply via email to

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