simple_forum 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +17 -16
- data/app/assets/images/simple_forum/galdomedia-logo.png +0 -0
- data/app/assets/javascripts/simple_forum/application.js +5 -1
- data/app/assets/javascripts/simple_forum/moderators.js +40 -0
- data/app/assets/stylesheets/simple_forum/admin.css +15 -0
- data/app/assets/stylesheets/simple_forum/base.css +10 -0
- data/app/controllers/simple_forum/admin/base_controller.rb +7 -0
- data/app/controllers/simple_forum/admin/categories_controller.rb +70 -0
- data/app/controllers/simple_forum/admin/forums_controller.rb +88 -0
- data/app/controllers/simple_forum/application_controller.rb +29 -6
- data/app/controllers/simple_forum/forums_controller.rb +4 -4
- data/app/controllers/simple_forum/posts_controller.rb +2 -2
- data/app/controllers/simple_forum/topics_controller.rb +3 -3
- data/app/models/simple_forum/forum.rb +2 -10
- data/app/models/simple_forum/moderatorship.rb +1 -1
- data/app/models/simple_forum/post.rb +3 -3
- data/app/models/simple_forum/topic.rb +1 -9
- data/app/models/simple_forum/user_activity.rb +68 -61
- data/app/views/layouts/simple_forum.html.erb +22 -3
- data/app/views/layouts/simple_forum/admin.html.erb +70 -0
- data/app/views/simple_forum/admin/categories/_form.html.erb +9 -0
- data/app/views/simple_forum/admin/categories/edit.html.erb +18 -0
- data/app/views/simple_forum/admin/categories/index.html.erb +45 -0
- data/app/views/simple_forum/admin/categories/new.html.erb +17 -0
- data/app/views/simple_forum/admin/categories/show.html.erb +35 -0
- data/app/views/simple_forum/admin/forums/_form.html.erb +45 -0
- data/app/views/simple_forum/admin/forums/_moderator.html.erb +5 -0
- data/app/views/simple_forum/admin/forums/edit.html.erb +21 -0
- data/app/views/simple_forum/admin/forums/index.html.erb +77 -0
- data/app/views/simple_forum/admin/forums/new.html.erb +20 -0
- data/app/views/simple_forum/admin/forums/show.html.erb +55 -0
- data/app/views/simple_forum/forums/index.html.erb +4 -4
- data/app/views/simple_forum/forums/show.html.erb +4 -4
- data/app/views/simple_forum/posts/edit.html.erb +4 -10
- data/app/views/simple_forum/topics/_post.html.erb +4 -4
- data/app/views/simple_forum/topics/new.html.erb +1 -1
- data/app/views/simple_forum/topics/show.html.erb +3 -3
- data/config/locales/simple_forum.en.yml +130 -0
- data/config/locales/simple_forum.pl.yml +1 -0
- data/config/routes.rb +8 -0
- data/db/migrate/20110330123461_create_simple_forum_user_activities.rb +17 -0
- data/lib/generators/simple_forum/install_generator.rb +4 -5
- data/lib/generators/simple_forum/views_generator.rb +18 -0
- data/lib/generators/templates/simple_forum.rb +28 -24
- data/lib/simple_forum.rb +53 -30
- data/lib/simple_forum/configuration.rb +39 -0
- data/lib/simple_forum/engine.rb +8 -1
- data/lib/simple_forum/extensions/user.rb +18 -0
- data/lib/simple_forum/version.rb +2 -2
- metadata +97 -74
@@ -4,7 +4,7 @@ module SimpleForum
|
|
4
4
|
:class_name => "SimpleForum::Forum"
|
5
5
|
|
6
6
|
belongs_to :user,
|
7
|
-
:class_name => instance_eval(&
|
7
|
+
:class_name => instance_eval(&SimpleForum.invoke(:user_class)).name
|
8
8
|
|
9
9
|
validates :forum, :user, :presence => true
|
10
10
|
validates :user_id, :uniqueness => {:scope => :forum_id, :allow_nil => true}
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module SimpleForum
|
2
2
|
class Post < ::ActiveRecord::Base
|
3
3
|
belongs_to :user,
|
4
|
-
:class_name => instance_eval(&
|
4
|
+
:class_name => instance_eval(&SimpleForum.invoke(:user_class)).name
|
5
5
|
|
6
6
|
belongs_to :edited_by,
|
7
|
-
:class_name => instance_eval(&
|
7
|
+
:class_name => instance_eval(&SimpleForum.invoke(:user_class)).name
|
8
8
|
|
9
9
|
belongs_to :deleted_by,
|
10
|
-
:class_name => instance_eval(&
|
10
|
+
:class_name => instance_eval(&SimpleForum.invoke(:user_class)).name
|
11
11
|
|
12
12
|
belongs_to :topic,
|
13
13
|
:counter_cache => true,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SimpleForum
|
2
2
|
class Topic < ::ActiveRecord::Base
|
3
|
-
belongs_to :user, :class_name => instance_eval(&
|
3
|
+
belongs_to :user, :class_name => instance_eval(&SimpleForum.invoke(:user_class)).name
|
4
4
|
|
5
5
|
belongs_to :forum,
|
6
6
|
:class_name => "SimpleForum::Forum", :counter_cache => true
|
@@ -98,14 +98,6 @@ module SimpleForum
|
|
98
98
|
update_attribute(:is_closed, true)
|
99
99
|
end
|
100
100
|
|
101
|
-
def recent_activity?(user)
|
102
|
-
SimpleForum::UserActivity.new(user).recent_activity?(self)
|
103
|
-
end
|
104
|
-
|
105
|
-
def bang_recent_activity(user)
|
106
|
-
SimpleForum::UserActivity.new(user).bang(self)
|
107
|
-
end
|
108
|
-
|
109
101
|
def increment_views_count
|
110
102
|
self.class.increment_counter(:views_count, self)
|
111
103
|
end
|
@@ -1,80 +1,87 @@
|
|
1
|
-
|
1
|
+
module SimpleForum
|
2
|
+
class UserActivity < ::ActiveRecord::Base
|
2
3
|
|
3
|
-
class
|
4
|
+
class Checker
|
5
|
+
attr_reader :user, :hash
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
def initialize(user, hash)
|
8
|
+
@user = user
|
9
|
+
@hash = hash
|
10
|
+
end
|
8
11
|
|
9
|
-
|
12
|
+
def recent_activity?(object)
|
13
|
+
type = object.class.base_class.name.to_sym
|
14
|
+
hash[type] ||= {}
|
15
|
+
read_at = hash[type][object.id]
|
16
|
+
return unless read_at
|
10
17
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
if object.is_a?(SimpleForum::Forum)
|
19
|
+
recent_post = object.recent_post
|
20
|
+
recent_post && recent_post.created_at > read_at
|
21
|
+
elsif object.is_a?(SimpleForum::Topic)
|
22
|
+
object.last_updated_at && object.last_updated_at > read_at
|
23
|
+
elsif object.respond_to?(:updated_at)
|
24
|
+
object.updated_at > self[object]
|
25
|
+
end
|
19
26
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
false
|
27
|
+
|
28
|
+
def bang(object)
|
29
|
+
return unless user
|
30
|
+
UserActivity.bang(object, user)
|
25
31
|
end
|
32
|
+
|
26
33
|
end
|
27
|
-
end
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
35
|
+
belongs_to :user,
|
36
|
+
:class_name => instance_eval(&SimpleForum.invoke(:user_class)).name
|
32
37
|
|
33
|
-
|
34
|
-
@@store ||= PStore.new(File.join(PATH, FILE))
|
35
|
-
end
|
38
|
+
belongs_to :memoryable, :polymorphic => true
|
36
39
|
|
37
|
-
|
38
|
-
self.class.store
|
39
|
-
end
|
40
|
+
scope :only_read, where("#{quoted_table_name}.read_at IS NOT NULL")
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
def self.recent_activity_for_user(user)
|
43
|
+
if user && user.persisted?
|
44
|
+
u = user
|
45
|
+
hash = self.where(:user_id => user.try(:id)).to_hash
|
46
|
+
else
|
47
|
+
u = nil
|
48
|
+
hash = {}
|
49
|
+
end
|
50
|
+
Checker.new(u, hash)
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
def self.to_hash(collection=nil)
|
54
|
+
collection ||= only_read.all
|
55
|
+
{}.tap do |hash|
|
56
|
+
collection.each do |a|
|
57
|
+
hash[a.memoryable_type.to_sym] ||= {}
|
58
|
+
hash[a.memoryable_type.to_sym][a.memoryable_id] = a.read_at
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
def self.bang(object, user)
|
64
|
+
if am = load(object, user)
|
65
|
+
update_all({:read_at => Time.now}, {:id => am.id})
|
66
|
+
else
|
67
|
+
am = create_for(object, user)
|
68
|
+
end
|
69
|
+
am
|
64
70
|
end
|
65
|
-
end
|
66
71
|
|
67
|
-
|
72
|
+
def self.load(object, user, conditions=nil)
|
73
|
+
scope = self.where({:memoryable_type => object.class.name, :memoryable_id => object.id, :user_id => user.id})
|
74
|
+
scope = scope.where(conditions) if conditions
|
75
|
+
scope.first
|
76
|
+
end
|
68
77
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
else
|
76
|
-
object.model_name.cache_key
|
78
|
+
def self.create_for(object, user, time=Time.now)
|
79
|
+
SimpleForum::UserActivity.create do |m|
|
80
|
+
m.memoryable = object
|
81
|
+
m.user = user
|
82
|
+
m.read_at = time
|
83
|
+
end
|
77
84
|
end
|
78
|
-
end
|
79
85
|
|
86
|
+
end
|
80
87
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html lang="<%= I18n.locale %>">
|
3
3
|
<head>
|
4
|
-
<meta
|
4
|
+
<meta charset="utf-8">
|
5
|
+
|
5
6
|
<title><%= yield(:title) || '' %></title>
|
7
|
+
|
6
8
|
<%= favicon_link_tag %>
|
7
9
|
|
8
10
|
<%= stylesheet_link_tag "simple_forum/application" %>
|
@@ -20,9 +22,26 @@
|
|
20
22
|
<body>
|
21
23
|
|
22
24
|
<p class="logo">
|
23
|
-
<%= link_to image_tag('
|
25
|
+
<%= link_to image_tag('simple_forum/galdomedia-logo.png', :alt => 'GaldoMedia'), "http://galdomedia.pl", :title => "GaldoMedia" %>
|
24
26
|
</p>
|
25
27
|
|
28
|
+
<ul class="links">
|
29
|
+
<% if user_authenticated? %>
|
30
|
+
<li>
|
31
|
+
<%= link_to t('simple_forum.sign_out'), main_app.send(:"#{SimpleForum.sign_out_path}_path"), :method => main_app.routes.routes.named_routes["#{SimpleForum.sign_out_path}"].verb === "DELETE" ? :delete : :get %>
|
32
|
+
</li>
|
33
|
+
<% if forum_admin? %>
|
34
|
+
<li>
|
35
|
+
<%= link_to t('simple_forum.forum_administration'), simple_forum.admin_forums_path %>
|
36
|
+
</li>
|
37
|
+
<% end %>
|
38
|
+
<% else %>
|
39
|
+
<li>
|
40
|
+
<%= link_to t('simple_forum.sign_in'), main_app.send(:"#{SimpleForum.sign_in_path}_path") %>
|
41
|
+
</li>
|
42
|
+
<% end %>
|
43
|
+
</ul>
|
44
|
+
|
26
45
|
<% if flash.present? %>
|
27
46
|
<div id="flash_messages">
|
28
47
|
<% flash.each do |key, val| %>
|
@@ -46,4 +65,4 @@
|
|
46
65
|
</div>
|
47
66
|
|
48
67
|
</body>
|
49
|
-
</html>
|
68
|
+
</html>
|
@@ -0,0 +1,70 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="<%= I18n.locale %>">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
|
6
|
+
<title><%= yield(:title) || '' %></title>
|
7
|
+
|
8
|
+
<%= favicon_link_tag %>
|
9
|
+
|
10
|
+
<%= stylesheet_link_tag "simple_forum/admin" %>
|
11
|
+
|
12
|
+
<%= yield :stylesheets %>
|
13
|
+
|
14
|
+
<%= csrf_meta_tag %>
|
15
|
+
|
16
|
+
<%= javascript_include_tag "simple_forum/application" %>
|
17
|
+
|
18
|
+
<%= yield :javascripts %>
|
19
|
+
|
20
|
+
<%= yield :head %>
|
21
|
+
</head>
|
22
|
+
<body>
|
23
|
+
<div id="container">
|
24
|
+
<div id="header">
|
25
|
+
<h1>
|
26
|
+
<%= link_to "Forum", simple_forum.root_path %>
|
27
|
+
</h1>
|
28
|
+
|
29
|
+
<div id="user-navigation">
|
30
|
+
<!--<ul class="wat-cf"></ul>-->
|
31
|
+
</div>
|
32
|
+
<div id="main-navigation">
|
33
|
+
<ul class="wat-cf">
|
34
|
+
<%= content_tag(:li, :class => controller.controller_path == 'simple_forum/admin/forums' ? 'active' : '') do %>
|
35
|
+
<%= link_to SimpleForum::Forum.model_name.human(:count => 3), simple_forum.admin_forums_path %>
|
36
|
+
<% end %>
|
37
|
+
<%= content_tag(:li, :class => controller.controller_path == 'simple_forum/admin/categories' ? 'active' : '') do %>
|
38
|
+
<%= link_to SimpleForum::Category.model_name.human(:count => 3), simple_forum.admin_categories_path %>
|
39
|
+
<% end %>
|
40
|
+
</ul>
|
41
|
+
</div>
|
42
|
+
</div>
|
43
|
+
<div id="wrapper" class="wat-cf">
|
44
|
+
<div class="flash">
|
45
|
+
<% flash.each do |type, message| %>
|
46
|
+
<%= content_tag(:div, :class => "message #{type}") do %>
|
47
|
+
<p>
|
48
|
+
<%= message %>
|
49
|
+
</p>
|
50
|
+
<% end %>
|
51
|
+
<% end %>
|
52
|
+
</div>
|
53
|
+
<div id="main">
|
54
|
+
<%= yield %>
|
55
|
+
|
56
|
+
<div id="footer">
|
57
|
+
<div class="block">
|
58
|
+
<p>
|
59
|
+
Copyright © #{Time.current.year}.
|
60
|
+
</p>
|
61
|
+
</div>
|
62
|
+
</div>
|
63
|
+
</div>
|
64
|
+
<div id="sidebar">
|
65
|
+
<%= yield :sidebar %>
|
66
|
+
</div>
|
67
|
+
</div>
|
68
|
+
</div>
|
69
|
+
</body>
|
70
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<div class="block">
|
2
|
+
<div class="secondary-navigation">
|
3
|
+
<ul class="wat-cf">
|
4
|
+
<li>
|
5
|
+
<%= link_to "#{t("web-app-theme.list", :default => "List")}", simple_forum.admin_categories_path %>
|
6
|
+
</li>
|
7
|
+
</ul>
|
8
|
+
</div>
|
9
|
+
<div class="content">
|
10
|
+
<h2 class="title">
|
11
|
+
Edit
|
12
|
+
</h2>
|
13
|
+
|
14
|
+
<div class="inner">
|
15
|
+
<%= render :partial => "form" %>
|
16
|
+
</div>
|
17
|
+
</div>
|
18
|
+
</div>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<div class="block">
|
2
|
+
<div class="secondary-navigation">
|
3
|
+
<ul class="wat-cf">
|
4
|
+
<li>
|
5
|
+
<%= link_to "#{t("web-app-theme.new", :default => "New")}", simple_forum.new_admin_category_path %>
|
6
|
+
</li>
|
7
|
+
</ul>
|
8
|
+
</div>
|
9
|
+
<div class="content">
|
10
|
+
<h2 class="title">
|
11
|
+
<%= SimpleForum::Category.model_name.human(:count => 3) %>
|
12
|
+
</h2>
|
13
|
+
|
14
|
+
<div class="inner">
|
15
|
+
<table class="table">
|
16
|
+
<thead>
|
17
|
+
<tr>
|
18
|
+
<th>ID</th>
|
19
|
+
<th><%= SimpleForum::Category.human_attribute_name :name %></th>
|
20
|
+
<th class="last"> </th>
|
21
|
+
</tr>
|
22
|
+
</thead>
|
23
|
+
<tbody>
|
24
|
+
<% @categories.each do |c| %>
|
25
|
+
<tr>
|
26
|
+
<td><%= c.id %></td>
|
27
|
+
<td><%= c.name %></td>
|
28
|
+
<td class="last">
|
29
|
+
<%= link_to t("web-app-theme.show", :default => "Show"), simple_forum.admin_category_path(c) %>
|
30
|
+
|
|
31
|
+
<%= link_to t("web-app-theme.edit", :default => "Edit"), simple_forum.edit_admin_category_path(c) %>
|
32
|
+
|
|
33
|
+
<%= link_to t("web-app-theme.delete", :default => "Delete"), simple_forum.admin_category_path(c), :method => :delete, :confirm => t('simple_forum.are_you_sure', :default => 'Are you sure?') %>
|
34
|
+
|
35
|
+
</td>
|
36
|
+
</tr>
|
37
|
+
<% end %>
|
38
|
+
</tbody>
|
39
|
+
</table>
|
40
|
+
</div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
</div>
|
44
|
+
|
45
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<div class="block">
|
2
|
+
<div class="secondary-navigation">
|
3
|
+
<ul class="wat-cf">
|
4
|
+
<li>
|
5
|
+
<%= link_to "#{t("web-app-theme.list", :default => "List")}", simple_forum.admin_categories_path %>
|
6
|
+
</li>
|
7
|
+
</ul>
|
8
|
+
</div>
|
9
|
+
<div class="content">
|
10
|
+
<h2 class="title">
|
11
|
+
New
|
12
|
+
</h2>
|
13
|
+
<div class="inner">
|
14
|
+
<%= render :partial => "form" %>
|
15
|
+
</div>
|
16
|
+
</div>
|
17
|
+
</div>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<div class="block">
|
2
|
+
<div class="secondary-navigation">
|
3
|
+
<ul class="wat-cf">
|
4
|
+
<li>
|
5
|
+
<%= link_to "#{t("web-app-theme.list", :default => "List")}", simple_forum.admin_categories_path %>
|
6
|
+
</li>
|
7
|
+
<li>
|
8
|
+
<%= link_to "#{t("web-app-theme.edit", :default => "Edit")}", simple_forum.edit_admin_category_path(resource) %>
|
9
|
+
</li>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<div class="content">
|
13
|
+
<h2 class="title">
|
14
|
+
<%= SimpleForum::Category.model_name.human %>
|
15
|
+
</h2>
|
16
|
+
|
17
|
+
<div class="inner">
|
18
|
+
<p>
|
19
|
+
<strong><%= resource.class.human_attribute_name :name %></strong>:
|
20
|
+
<%= resource.name %>
|
21
|
+
</p>
|
22
|
+
|
23
|
+
<p>
|
24
|
+
<strong><%= resource.class.human_attribute_name :body %></strong>:
|
25
|
+
<%= simple_format(resource.body) %>
|
26
|
+
</p>
|
27
|
+
|
28
|
+
<p>
|
29
|
+
<strong><%= resource.class.human_attribute_name :position %></strong>:
|
30
|
+
<%= resource.position %>
|
31
|
+
</p>
|
32
|
+
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
</div>
|