muck-activity 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -1
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/app/controllers/muck/activities_controller.rb +6 -10
- data/app/helpers/muck_activity_helper.rb +27 -1
- data/app/models/activity.rb +15 -4
- data/app/models/activity_feed.rb +2 -0
- data/app/views/activities/_activity_feed.html.erb +5 -12
- data/app/views/activities/_cached_activities.html.erb +2 -1
- data/app/views/activities/_comment.html.erb +4 -0
- data/app/views/activities/_comments.html.erb +9 -0
- data/app/views/activities/_status_update.html.erb +1 -1
- data/app/views/activity_templates/_status_update.html.erb +4 -0
- data/locales/en.yml +3 -1
- data/muck-activity.gemspec +12 -3
- data/public/javascripts/muck_activities.js +44 -0
- data/test/test_helper.rb +1 -0
- metadata +15 -3
- data/pkg/muck-activity-0.1.3.gem +0 -0
data/README.rdoc
CHANGED
@@ -54,7 +54,11 @@ you might add a can_view? method like this:
|
|
54
54
|
self.member?(check_object) || (check_object.is_a?(User) && check_object.admin?)
|
55
55
|
end
|
56
56
|
|
57
|
-
==
|
57
|
+
== Configuration
|
58
|
+
If you would like to enable comments for your project's activities feeds you can do so by adding an entry to GlobalConfig.yml (configuration file added by muck)
|
59
|
+
|
60
|
+
enable_activity_comments: true
|
61
|
+
|
58
62
|
If you would like to add live updates to the user's activity feed you can do so by adding an entry to GlobalConfig.yml (configuration file added by muck)
|
59
63
|
|
60
64
|
enable_live_activity_updates: true
|
data/Rakefile
CHANGED
@@ -34,6 +34,7 @@ begin
|
|
34
34
|
gemspec.rubyforge_project = 'muck-activity'
|
35
35
|
gemspec.add_dependency "muck-engine"
|
36
36
|
gemspec.add_dependency "muck-users"
|
37
|
+
gemspec.add_dependency "muck-comments"
|
37
38
|
gemspec.files.include %w(
|
38
39
|
tasks/*
|
39
40
|
db/migrate/*.rb
|
@@ -42,7 +43,8 @@ begin
|
|
42
43
|
locales/*
|
43
44
|
rails/*
|
44
45
|
test/*
|
45
|
-
lib/**/*
|
46
|
+
lib/**/*
|
47
|
+
public/**/* )
|
46
48
|
end
|
47
49
|
rescue LoadError
|
48
50
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
@@ -1,19 +1,16 @@
|
|
1
1
|
class Muck::ActivitiesController < ApplicationController
|
2
2
|
unloadable
|
3
|
-
|
3
|
+
|
4
4
|
include ApplicationHelper
|
5
|
-
|
5
|
+
include MuckActivityHelper
|
6
|
+
|
6
7
|
before_filter :login_required
|
7
8
|
before_filter :find_parent, :only => [:index, :create]
|
8
9
|
before_filter :get_activity, :only => [:destroy]
|
9
10
|
|
10
11
|
def index
|
11
12
|
if @parent.can_view?(current_user)
|
12
|
-
|
13
|
-
@activities = @parent.activities.filter_by_template(params[:activity_filter]).after(params[:latest_activity_id]).paginate(:page => @page, :per_page => @per_page)
|
14
|
-
else
|
15
|
-
@activities = @parent.activities.filter_by_template(params[:activity_filter]).paginate(:page => @page, :per_page => @per_page)
|
16
|
-
end
|
13
|
+
@activities = get_activities(@parent)
|
17
14
|
respond_to do |format|
|
18
15
|
format.js do
|
19
16
|
render :partial => "activities/cached_activities", :locals => {:activities => @activities}
|
@@ -61,7 +58,7 @@ class Muck::ActivitiesController < ApplicationController
|
|
61
58
|
end
|
62
59
|
end
|
63
60
|
|
64
|
-
rescue => ex
|
61
|
+
rescue ActiveRecord::RecordInvalid => ex
|
65
62
|
|
66
63
|
if @activity
|
67
64
|
errors = @activity.errors.full_messages.to_sentence
|
@@ -95,7 +92,7 @@ class Muck::ActivitiesController < ApplicationController
|
|
95
92
|
if @activity.is_status_update
|
96
93
|
@new_status = get_status_html(@activities_object)
|
97
94
|
render(:update) do |page|
|
98
|
-
page << "jQuery('
|
95
|
+
page << "jQuery('##{@activity.dom_id}').fadeOut();"
|
99
96
|
page.replace_html 'current-status', @new_status if @new_status
|
100
97
|
end
|
101
98
|
end
|
@@ -149,7 +146,6 @@ class Muck::ActivitiesController < ApplicationController
|
|
149
146
|
format.js { render(:update){|page| page_alert(page, t("muck.activities.permission_denied"))}}
|
150
147
|
end
|
151
148
|
end
|
152
|
-
|
153
149
|
end
|
154
150
|
|
155
151
|
end
|
@@ -1,7 +1,25 @@
|
|
1
1
|
module MuckActivityHelper
|
2
2
|
|
3
|
+
def activity_comments(activity)
|
4
|
+
render :partial => 'activities/comments', :locals => { :activity => activity }
|
5
|
+
end
|
6
|
+
|
7
|
+
def activity_comment_link(activity, comment = nil)
|
8
|
+
if GlobalConfig.enable_activity_comments
|
9
|
+
comment_form(activity, comment = nil)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def has_comments_css(activity)
|
14
|
+
if activity.has_comments?
|
15
|
+
'activity-has-comments'
|
16
|
+
else
|
17
|
+
'activity-no-comments'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
3
21
|
def activity_feed_for(activities_object)
|
4
|
-
activities = activities_object
|
22
|
+
activities = get_activities(activities_object)
|
5
23
|
render :partial => 'activities/activity_feed', :locals => { :activities_object => activities_object, :activities => activities }
|
6
24
|
end
|
7
25
|
|
@@ -38,4 +56,12 @@ module MuckActivityHelper
|
|
38
56
|
request.url.gsub(request.query_string, '')
|
39
57
|
end
|
40
58
|
|
59
|
+
def get_activities(activities_object)
|
60
|
+
if !params[:latest_activity_id].blank?
|
61
|
+
activities_object.activities.filter_by_template(params[:activity_filter]).after(params[:latest_activity_id]).find(:all, :include => ['comments']).paginate(:page => @page, :per_page => @per_page)
|
62
|
+
else
|
63
|
+
activities_object.activities.filter_by_template(params[:activity_filter]).find(:all, :include => ['comments']).paginate(:page => @page, :per_page => @per_page)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
41
67
|
end
|
data/app/models/activity.rb
CHANGED
@@ -15,12 +15,15 @@
|
|
15
15
|
# updated_at :datetime
|
16
16
|
#
|
17
17
|
|
18
|
-
class Activity < ActiveRecord::Base
|
19
|
-
|
18
|
+
class Activity < ActiveRecord::Base
|
19
|
+
unloadable
|
20
|
+
|
20
21
|
belongs_to :item, :polymorphic => true
|
21
22
|
belongs_to :source, :polymorphic => true
|
22
23
|
has_many :activity_feeds
|
23
24
|
|
25
|
+
acts_as_commentable
|
26
|
+
|
24
27
|
validates_presence_of :source
|
25
28
|
|
26
29
|
named_scope :since, lambda { |time| {:conditions => ["activities.created_at > ?", time] } }
|
@@ -41,11 +44,19 @@ class Activity < ActiveRecord::Base
|
|
41
44
|
template || item.class.name.underscore
|
42
45
|
end
|
43
46
|
|
47
|
+
def has_comments?
|
48
|
+
@has_comments ||= !self.comments.blank?
|
49
|
+
end
|
50
|
+
|
44
51
|
# Checks to see if the specified object can edit this activity.
|
45
52
|
# Most likely check_object will be a user
|
46
53
|
def can_edit?(check_object)
|
47
|
-
|
48
|
-
|
54
|
+
if check_object.is_a?(User)
|
55
|
+
return true if check(check_object, :source_id)
|
56
|
+
else
|
57
|
+
source == check_object
|
58
|
+
end
|
59
|
+
false
|
49
60
|
end
|
50
61
|
|
51
62
|
end
|
data/app/models/activity_feed.rb
CHANGED
@@ -4,6 +4,9 @@
|
|
4
4
|
</div>
|
5
5
|
</div>
|
6
6
|
<%= will_paginate activities, :previous_label => t('muck.activities.paging_newer'), :next_label => t('muck.activities.paging_older') -%>
|
7
|
+
<% content_for :head do -%>
|
8
|
+
<%= javascript_tag %[var COMMENT_PROMPT = '#{t('muck.activities.write_prompt')}';] %>
|
9
|
+
<% end -%>
|
7
10
|
<% content_for :javascript do -%>
|
8
11
|
jQuery(document).ready(function(){
|
9
12
|
setup_submit_delete();
|
@@ -11,15 +14,5 @@
|
|
11
14
|
setInterval(function() {jQuery.ajax({success:function(request){update_feed(request);},url:'<%= activities_path(:parent_id => activities_object, :parent_type => activities_object.type, :activity_filter => params[:activity_filter], :format => 'js') %>&latest_activity_id=' + get_latest_activity_id()})}, <%=GlobalConfig.live_activity_update_interval%> * 1000)
|
12
15
|
<% end -%>
|
13
16
|
});
|
14
|
-
|
15
|
-
|
16
|
-
if(activities.length > 0){
|
17
|
-
return activities[0].id.replace('activity_', '');
|
18
|
-
} else {
|
19
|
-
return '';
|
20
|
-
}
|
21
|
-
}
|
22
|
-
function update_feed(request){
|
23
|
-
jQuery('#activity-feed-content').prepend(request);
|
24
|
-
}
|
25
|
-
<% end -%>
|
17
|
+
<% end -%>
|
18
|
+
<%= javascript_include_tag 'muck_activities' %>
|
@@ -1,7 +1,8 @@
|
|
1
1
|
<% if !activities.blank? -%>
|
2
2
|
<% activities.each do |activity| -%>
|
3
3
|
<% cache ("activities/#{I18n.locale}/#{activity.id}") do -%>
|
4
|
-
<%= render( :partial => "activity_templates/#{activity.partial}", :locals => {:activity => activity})
|
4
|
+
<%= render( :partial => "activity_templates/#{activity.partial}", :locals => {:activity => activity}) %>
|
5
|
+
<hr class="space">
|
5
6
|
<% end -%>
|
6
7
|
<% end -%>
|
7
8
|
<% end -%>
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<div class="actor-icon"><%= icon activity.source %></div>
|
2
|
+
<p><span class="actor"><%= link_to activity.source.display_name, activity.source %></span>
|
3
|
+
<span class="activity-time"><%= t("muck.activities.time_ago", :time_in_words => time_ago_in_words(activity.created_at)) %></span></p>
|
4
|
+
<p><%= h comment.body %></p>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<% if activity.has_comments? -%>
|
2
|
+
<div class="activity-comment">
|
3
|
+
<%= render( :partial => "activities/comment", :collection => activity.comments, :locals => { :activity => activity } ) %>
|
4
|
+
</div>
|
5
|
+
<% end -%>
|
6
|
+
<div id="<%=activity.dom_id%>_comment" class="activity-comment <%= has_comments_css(activity) %>">
|
7
|
+
<div class="actor-icon"><%= icon current_user %></div>
|
8
|
+
<%= activity_comment_link(activity) %>
|
9
|
+
</div>
|
@@ -12,7 +12,7 @@
|
|
12
12
|
<%= t("muck.activities.status_update_prompt") %>
|
13
13
|
<%= f.text_field :content, :id => 'status_update' %>
|
14
14
|
<span id="status-update-button">
|
15
|
-
<%= f.submit t('muck.activities.post'), :id => 'submit_status', :class=>"button" %>
|
15
|
+
<%= f.submit t('muck.activities.post'), :id => 'submit_status', :class => "button" %>
|
16
16
|
</span>
|
17
17
|
</div>
|
18
18
|
<%= f.hidden_field :template, :value => 'status_update' %>
|
@@ -3,6 +3,10 @@
|
|
3
3
|
<div class="activity-content">
|
4
4
|
<p><span class="actor"><%= link_to activity.source.display_name, activity.source %></span> <%= activity.content %></p>
|
5
5
|
<span class="activity-time"><%= t("muck.activities.time_ago", :time_in_words => time_ago_in_words(activity.created_at)) %></span>
|
6
|
+
<% if !activity.has_comments? -%>
|
7
|
+
<span><a id="comment_<%=activity.dom_id%>" class="make-comment" href="#"><%=t('muck.activities.make_comment')%></a></span>
|
8
|
+
<% end -%>
|
6
9
|
<%= delete_activity(activity, :image) %>
|
7
10
|
</div>
|
11
|
+
<%= activity_comments(activity) %>
|
8
12
|
</div>
|
data/locales/en.yml
CHANGED
@@ -20,4 +20,6 @@ en:
|
|
20
20
|
template_or_item_required: "An activity requires a template or an item to display correctly"
|
21
21
|
paging_newer: '« Newer'
|
22
22
|
paging_older: 'Older »'
|
23
|
-
all_activities: All Activities
|
23
|
+
all_activities: All Activities
|
24
|
+
make_comment: Comment
|
25
|
+
write_prompt: "Write a comment..."
|
data/muck-activity.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{muck-activity}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Justin Ball"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-13}
|
10
10
|
s.description = %q{Activity engine for the muck system.}
|
11
11
|
s.email = %q{justinball@gmail.com}
|
12
12
|
s.extra_rdoc_files = [
|
@@ -29,6 +29,10 @@ Gem::Specification.new do |s|
|
|
29
29
|
"app/views/activities/_activity_feed.html.erb",
|
30
30
|
"app/views/activities/_cached_activities.html.erb",
|
31
31
|
"app/views/activities/_cached_activities.html.erb",
|
32
|
+
"app/views/activities/_comment.html.erb",
|
33
|
+
"app/views/activities/_comment.html.erb",
|
34
|
+
"app/views/activities/_comments.html.erb",
|
35
|
+
"app/views/activities/_comments.html.erb",
|
32
36
|
"app/views/activities/_current_status.html.erb",
|
33
37
|
"app/views/activities/_current_status.html.erb",
|
34
38
|
"app/views/activities/_current_status_wrapper.html.erb",
|
@@ -117,8 +121,10 @@ Gem::Specification.new do |s|
|
|
117
121
|
"locales/zh.yml",
|
118
122
|
"locales/zh.yml",
|
119
123
|
"muck-activity.gemspec",
|
120
|
-
"pkg/muck-activity-0.1.3.gem",
|
121
124
|
"public/images/loading.gif",
|
125
|
+
"public/images/loading.gif",
|
126
|
+
"public/javascripts/muck_activities.js",
|
127
|
+
"public/javascripts/muck_activities.js",
|
122
128
|
"rails/init.rb",
|
123
129
|
"rails/init.rb",
|
124
130
|
"rdoc/classes/ActionController.html",
|
@@ -175,12 +181,15 @@ Gem::Specification.new do |s|
|
|
175
181
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
176
182
|
s.add_runtime_dependency(%q<muck-engine>, [">= 0"])
|
177
183
|
s.add_runtime_dependency(%q<muck-users>, [">= 0"])
|
184
|
+
s.add_runtime_dependency(%q<muck-comments>, [">= 0"])
|
178
185
|
else
|
179
186
|
s.add_dependency(%q<muck-engine>, [">= 0"])
|
180
187
|
s.add_dependency(%q<muck-users>, [">= 0"])
|
188
|
+
s.add_dependency(%q<muck-comments>, [">= 0"])
|
181
189
|
end
|
182
190
|
else
|
183
191
|
s.add_dependency(%q<muck-engine>, [">= 0"])
|
184
192
|
s.add_dependency(%q<muck-users>, [">= 0"])
|
193
|
+
s.add_dependency(%q<muck-comments>, [">= 0"])
|
185
194
|
end
|
186
195
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
jQuery(document).ready(function() {
|
2
|
+
jQuery('.activity-no-comments').hide();
|
3
|
+
hide_comment_boxes();
|
4
|
+
jQuery('.activity-has-comments').find('textarea').click(function(){
|
5
|
+
show_comment_box(this);
|
6
|
+
});
|
7
|
+
jQuery('.activity-has-comments').find('textarea').blur(function(){
|
8
|
+
textarea = jQuery(this);
|
9
|
+
if (textarea.val() == ''){
|
10
|
+
hide_comment_boxes();
|
11
|
+
}
|
12
|
+
});
|
13
|
+
});
|
14
|
+
|
15
|
+
function hide_comment_boxes(){
|
16
|
+
jQuery('.activity-has-comments').children('.actor-icon').hide();
|
17
|
+
jQuery('.activity-has-comments').find('.button').hide();
|
18
|
+
jQuery('.activity-has-comments').find('textarea').val(COMMENT_PROMPT);
|
19
|
+
jQuery('.activity-has-comments').find('textarea').addClass('min');
|
20
|
+
}
|
21
|
+
|
22
|
+
function show_comment_box(obj){
|
23
|
+
textarea = jQuery(obj);
|
24
|
+
textarea.addClass('max');
|
25
|
+
textarea.removeClass('min');
|
26
|
+
textarea.siblings('.actor-icon').show();
|
27
|
+
textarea.siblings('.button').show();
|
28
|
+
if (textarea.val() == COMMENT_PROMPT) {
|
29
|
+
textarea.val('');
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
function get_latest_activity_id(){
|
34
|
+
var activities = jQuery('#activity-feed-content').children('.activity-status-update');
|
35
|
+
if(activities.length > 0){
|
36
|
+
return activities[0].id.replace('activity_', '');
|
37
|
+
} else {
|
38
|
+
return '';
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
function update_feed(request){
|
43
|
+
jQuery('#activity-feed-content').prepend(request);
|
44
|
+
}
|
data/test/test_helper.rb
CHANGED
@@ -7,6 +7,7 @@ require 'ruby-debug'
|
|
7
7
|
require 'mocha'
|
8
8
|
require 'authlogic'
|
9
9
|
require 'authlogic/test_case'
|
10
|
+
require 'active_record'
|
10
11
|
require 'redgreen' rescue LoadError
|
11
12
|
require File.expand_path(File.dirname(__FILE__) + '/factories')
|
12
13
|
require File.join(File.dirname(__FILE__), 'shoulda_macros', 'controller')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muck-activity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Ball
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-13 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,6 +32,16 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0"
|
34
34
|
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: muck-comments
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
35
45
|
description: Activity engine for the muck system.
|
36
46
|
email: justinball@gmail.com
|
37
47
|
executables: []
|
@@ -51,6 +61,8 @@ files:
|
|
51
61
|
- app/models/activity_feed.rb
|
52
62
|
- app/views/activities/_activity_feed.html.erb
|
53
63
|
- app/views/activities/_cached_activities.html.erb
|
64
|
+
- app/views/activities/_comment.html.erb
|
65
|
+
- app/views/activities/_comments.html.erb
|
54
66
|
- app/views/activities/_current_status.html.erb
|
55
67
|
- app/views/activities/_current_status_wrapper.html.erb
|
56
68
|
- app/views/activities/_delete.html.erb
|
@@ -96,8 +108,8 @@ files:
|
|
96
108
|
- locales/zh-TW.yml
|
97
109
|
- locales/zh.yml
|
98
110
|
- muck-activity.gemspec
|
99
|
-
- pkg/muck-activity-0.1.3.gem
|
100
111
|
- public/images/loading.gif
|
112
|
+
- public/javascripts/muck_activities.js
|
101
113
|
- rails/init.rb
|
102
114
|
- rdoc/classes/ActionController.html
|
103
115
|
- rdoc/classes/ActionController/Routing.html
|
data/pkg/muck-activity-0.1.3.gem
DELETED
Binary file
|