Diff
Modified: trunk/app/helpers/application_helper.rb (2143 => 2144)
--- trunk/app/helpers/application_helper.rb 2009-03-29 13:30:56 UTC (rev 2143)
+++ trunk/app/helpers/application_helper.rb 2009-03-29 13:50:59 UTC (rev 2144)
@@ -51,21 +51,12 @@
def owner_text(thing)
return '' if thing.nil?
-
- case thing.class.to_s
- when "Workflow"
- return "Original Uploader"
- when "Blob"
- return "Uploader"
- when "Pack"
- return "Creator"
- when "Network"
- return "Admin"
- when "Profile"
- return "User"
- else
- return ''
- end
+
+ text = thing.class.owner_text if thing.class.respond_to?('owner_text')
+
+ return '' if text.nil?
+
+ text
end
def datetime(old_dt, long=true)
Modified: trunk/app/models/blob.rb (2143 => 2144)
--- trunk/app/models/blob.rb 2009-03-29 13:30:56 UTC (rev 2143)
+++ trunk/app/models/blob.rb 2009-03-29 13:50:59 UTC (rev 2144)
@@ -4,11 +4,15 @@
# See license.txt for details.
require 'acts_as_contributable'
+require 'acts_as_site_entity'
require 'acts_as_creditable'
require 'acts_as_attributor'
require 'acts_as_attributable'
class Blob < ActiveRecord::Base
+
+ acts_as_site_entity :owner_text => 'Uploader'
+
acts_as_contributable
acts_as_bookmarkable
Modified: trunk/app/models/blog.rb (2143 => 2144)
--- trunk/app/models/blog.rb 2009-03-29 13:30:56 UTC (rev 2143)
+++ trunk/app/models/blog.rb 2009-03-29 13:50:59 UTC (rev 2144)
@@ -3,9 +3,13 @@
# Copyright (c) 2007 University of Manchester and the University of Southampton.
# See license.txt for details.
+require 'acts_as_site_entity'
require 'acts_as_contributable'
class Blog < ActiveRecord::Base
+
+ acts_as_site_entity
+
acts_as_contributable
acts_as_bookmarkable
Modified: trunk/app/models/network.rb (2143 => 2144)
--- trunk/app/models/network.rb 2009-03-29 13:30:56 UTC (rev 2143)
+++ trunk/app/models/network.rb 2009-03-29 13:50:59 UTC (rev 2144)
@@ -5,11 +5,14 @@
require 'acts_as_contributor'
require 'acts_as_creditor'
+require 'acts_as_site_entity'
class Network < ActiveRecord::Base
acts_as_contributor
acts_as_creditor
+ acts_as_site_entity :owner_text => 'Admin'
+
acts_as_commentable
acts_as_taggable
@@ -51,10 +54,6 @@
alias_method :contributor, :owner
- def label
- return title
- end
-
def owner?(userid)
user_id.to_i == userid.to_i
end
Modified: trunk/app/models/pack.rb (2143 => 2144)
--- trunk/app/models/pack.rb 2009-03-29 13:30:56 UTC (rev 2143)
+++ trunk/app/models/pack.rb 2009-03-29 13:50:59 UTC (rev 2144)
@@ -4,6 +4,7 @@
# See license.txt for details.
require 'acts_as_contributable'
+require 'acts_as_site_entity'
require 'uri'
require 'zip/zip'
require 'tempfile'
@@ -11,6 +12,9 @@
class Pack < ActiveRecord::Base
+
+ acts_as_site_entity :owner_text => 'Creator'
+
acts_as_contributable
acts_as_bookmarkable
Modified: trunk/app/models/profile.rb (2143 => 2144)
--- trunk/app/models/profile.rb 2009-03-29 13:30:56 UTC (rev 2143)
+++ trunk/app/models/profile.rb 2009-03-29 13:50:59 UTC (rev 2144)
@@ -3,6 +3,8 @@
# Copyright (c) 2007 University of Manchester and the University of Southampton.
# See license.txt for details.
+require 'acts_as_site_entity'
+
class Profile < ActiveRecord::Base
belongs_to :owner,
@@ -34,6 +36,8 @@
belongs_to :picture
validates_email_veracity_of :email
+
+ acts_as_site_entity :owner_text => 'User'
acts_as_solr :fields => [ :email,
:website,
Modified: trunk/app/models/user.rb (2143 => 2144)
--- trunk/app/models/user.rb 2009-03-29 13:30:56 UTC (rev 2143)
+++ trunk/app/models/user.rb 2009-03-29 13:50:59 UTC (rev 2144)
@@ -5,6 +5,7 @@
require 'digest/sha1'
+require 'acts_as_site_entity'
require 'acts_as_contributor'
require 'acts_as_creditor'
@@ -24,10 +25,6 @@
has_many :experiments, :as => :contributor,
:conditions => ["contributor_type = ?", "User"]
- def label
- return name
- end
-
def self.most_recent(limit=5)
self.find(:all,
:order => "users.created_at DESC",
@@ -276,6 +273,8 @@
return Conf.admins.include?(self.username.downcase)
end
+ acts_as_site_entity
+
acts_as_contributor
has_many :blobs, :as => :contributor
Modified: trunk/app/models/workflow.rb (2143 => 2144)
--- trunk/app/models/workflow.rb 2009-03-29 13:30:56 UTC (rev 2143)
+++ trunk/app/models/workflow.rb 2009-03-29 13:50:59 UTC (rev 2144)
@@ -3,8 +3,8 @@
# Copyright (c) 2007 University of Manchester and the University of Southampton.
# See license.txt for details.
+require 'acts_as_site_entity'
require 'acts_as_contributable'
-require 'acts_as_contributable'
require 'acts_as_creditable'
require 'acts_as_attributor'
require 'acts_as_attributable'
@@ -32,6 +32,8 @@
before_validation :check_unique_name
before_validation :extract_metadata
+ acts_as_site_entity :owner_text => 'Original Uploader'
+
acts_as_contributable
acts_as_bookmarkable
Modified: trunk/lib/acts_as_contributable.rb (2143 => 2144)
--- trunk/lib/acts_as_contributable.rb 2009-03-29 13:30:56 UTC (rev 2143)
+++ trunk/lib/acts_as_contributable.rb 2009-03-29 13:50:59 UTC (rev 2144)
@@ -69,11 +69,6 @@
return contribution.contributor.title if contribution.contributor.respond_to?('title')
end
- def label
- return name if respond_to?('name')
- return title if respond_to?('title')
- end
-
# This is so that the updated_at time on the record tallies up with the
# contributable
def save_contributable_record
Added: trunk/lib/acts_as_site_entity.rb (0 => 2144)
--- trunk/lib/acts_as_site_entity.rb (rev 0)
+++ trunk/lib/acts_as_site_entity.rb 2009-03-29 13:50:59 UTC (rev 2144)
@@ -0,0 +1,50 @@
+# myExperiment: lib/acts_as_site_entity.rb
+#
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+module MyExperiment
+ module Acts #:nodoc:
+ module SiteEntity #:nodoc:
+ def self.included(mod)
+ mod.extend(ClassMethods)
+ end
+
+ module ClassMethods
+ def acts_as_site_entity(args = {})
+
+ class_eval do
+ extend MyExperiment::Acts::SiteEntity::SingletonMethods
+ end
+ include MyExperiment::Acts::SiteEntity::InstanceMethods
+
+ self.owner_text = args[:owner_text] ? args[:owner_text] : ''
+ end
+ end
+
+ module SingletonMethods
+
+ def owner_text=(new_value)
+ @owner_text = new_value
+ end
+
+ def owner_text
+ @owner_text
+ end
+ end
+
+ module InstanceMethods
+
+ def label
+ return name if respond_to?('name')
+ return title if respond_to?('title')
+ end
+ end
+ end
+ end
+end
+
+ActiveRecord::Base.class_eval do
+ include MyExperiment::Acts::SiteEntity
+end
+