Skip to content

Commit

Permalink
changes tracking reader: dashboard and view partials, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
will-r committed Jul 13, 2011
1 parent dbb0a89 commit d6c7d13
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 82 deletions.
20 changes: 0 additions & 20 deletions app/helpers/forum_helper.rb
Expand Up @@ -47,24 +47,4 @@ def remove_link(post)
link_to t('forum_extension.delete'), topic_post_url(post.topic, post), :method => 'delete', :class => 'delete_post', :id => "delete_post_#{post.id}", :title => t("remove_post"), :confirm => t('forum_extension.really_remove_post')
end

def friendly_date(datetime)
I18n.l(datetime, :format => friendly_date_format(datetime)) if datetime
end

def friendly_date_format(datetime)
if datetime && date = datetime.to_date
if (date.to_datetime == Date.today)
:today
elsif (date.to_datetime == Date.yesterday)
:yesterday
elsif (date.to_datetime > 6.days.ago)
:recently
elsif (date.year == Date.today.year)
:this_year
else
:standard
end
end
end

end
7 changes: 7 additions & 0 deletions app/models/topic.rb
Expand Up @@ -12,6 +12,13 @@ class Topic < ActiveRecord::Base
named_scope :latest, lambda { |count|
{ :order => 'replied_at DESC', :limit => count }
}
named_scope :busiest, lambda { |count| {
:select => "topics.*, count(posts.id) AS post_count",
:joins => "INNER JOIN posts ON posts.topic_id = topics.id",
:group => column_names.map { |n| 'topics.' + n }.join(','),
:order => "post_count DESC",
:limit => count
}}
# adapted from the usual scope defined in has_groups, since here visibility is set at the forum level
named_scope :visible_to, lambda { |reader|
conditions = "forums.id IS NULL OR pp.group_id IS NULL"
Expand Down
12 changes: 12 additions & 0 deletions app/views/accounts/_posts.html.haml
@@ -0,0 +1,12 @@
- posts ||= @reader.posts.paginate(pagination_parameters)

%h2
=t('forum_extension.count_forum_messages', :count => posts.total_entries)

- if posts.empty?
%p
= t('forum_extension.no_posts')
- else
= pagination_and_summary_for(posts, t('forum_extension.post')) if posts.previous_page
= render :partial => 'posts/summary', :collection => posts
= pagination_and_summary_for(posts, t('forum_extension.post')) if posts.next_page
2 changes: 0 additions & 2 deletions app/views/admin/dashboard/_forum_dashboard.html.haml
Expand Up @@ -20,8 +20,6 @@
= t('forum_extension.started_by')
= link_to topic.reader.name, reader_url(topic.reader)
= friendly_date(topic.created_at)
%p.excerpt
= truncate_words(scrub_html(post.body), 16)
%p.minor
=t('forum_extension.administer_by_browsing')
- else
Expand Down
3 changes: 2 additions & 1 deletion app/views/admin/forums/new.html.haml
@@ -1,5 +1,6 @@
- render_region :main do |main|
- main.edit_header do
%h1 New Forum
%h1
= t('forum_extension.create_forum').titlecase
- main.edit_form do
= render :partial => 'form'
10 changes: 10 additions & 0 deletions app/views/dashboard/_posts.html.haml
@@ -0,0 +1,10 @@
- posts = current_reader.posts.latest(10)
- if posts.any?
.dashboard_module
%h3
=t('forum_extension.dashboard.posts_and_comments')
%ul
= render :partial => 'posts/summary', :collection => posts

%p
= link_to t('forum_extension.new_topic'), new_post_url, :class => 'post'
2 changes: 1 addition & 1 deletion app/views/posts/_post.html.haml
Expand Up @@ -19,7 +19,7 @@
= t('forum_extension.comment_on')
-elsif post.reply?
= t('forum_extension.reply_to')
= link_to post.topic.name, paginated_post_url(post)
= link_to_post(post)
- else
%h2
= post.reader.name
Expand Down
18 changes: 18 additions & 0 deletions app/views/posts/_summary.html.haml
@@ -0,0 +1,18 @@
- post ||= summary

%li.post
%strong
= link_to_post(post, :class => 'title')
%span.context
- if post.comment?
= t('forum_extension.comment_on')
= link_to post.page.title, post.page.url
= t('forum_extension.posted')
- elsif post.first?
= t('forum_extension.new_topic_started')
- else
= t('forum_extension.reply_posted')
= friendly_date(post.created_at)
%br
%span.excerpt
= truncate_words(scrub_html(post.body), 12)
23 changes: 0 additions & 23 deletions app/views/readers/_forum_messages.html.haml

This file was deleted.

8 changes: 6 additions & 2 deletions app/views/shared/_standard_forum_parts.html.haml
Expand Up @@ -19,6 +19,12 @@
.footer
= yield :controls

- content_for :controls do
= render :partial => 'readers/controls'

- content_for :signals do
= render :partial => 'readers/flasher'

- content_for :search do
= render :partial => 'posts/search_form', :locals => {:minimal => true}

Expand All @@ -37,5 +43,3 @@
= link_to t('forum_extension.new_topic_here'), new_post_url(:forum_id => @forum.id), :class => "post"
- else
= link_to t('forum_extension.new_topic'), new_post_url(), :class => "post"

= render :partial => 'shared/standard_reader_parts'
2 changes: 1 addition & 1 deletion app/views/topics/_busiest.html.haml
@@ -1,7 +1,7 @@
%h2
= t('forum_extension.top_topics')
%ul
- Topic.visible_to(current_reader).most_commented(10).each do |topic|
- Topic.visible_to(current_reader).busiest(10).each do |topic|
%li
= link_to_topic(topic, :class => 'title')
%br
Expand Down
4 changes: 0 additions & 4 deletions app/views/topics/index.html.haml
Expand Up @@ -26,10 +26,6 @@
- content_for :feedlink do
= feed_link(topics_url(:format => :rss))

- content_for :head do
%h1
= yield :title

- content_for :introduction do
%p
=t('forum_extension.topics_introduction')
Expand Down
20 changes: 11 additions & 9 deletions config/locales/en.yml
Expand Up @@ -15,6 +15,7 @@ en:
attachment:
content_types: "Permitted content types"
max_size: "Maximum attachment size"
cached?: "Forum pages cached?"
commentable_period: "Pages commentable for"
editable_period: "Posts editable for"
layout: "Forum layout"
Expand Down Expand Up @@ -64,6 +65,13 @@ en:
confirm_remove_post: "Delete post?"
confirm_remove_topic: "Delete topic?"
containing: "containing the phrase"
count_forum_messages:
zero: "No forum messages"
one: "One forum message"
other: "%{count} forum messages"
dashboard:
new_topic: "Start discussion"
posts_and_comments: "Your latest forum posts and page comments"
definitely_remove_post: "Yes: delete it"
description: Description
edit_forum: "Edit forum"
Expand All @@ -79,7 +87,8 @@ en:
forum: "Forum"
forums: "Discussion categories"
forum_configuration: "Forum settings"
forum_messages: "Forum messages from %{name}"
forum_messages: "Forum messages"
forum_messages_from: "Forum messages from %{name}"
forum_search: "Forum Search"
forum_show_introduction: ""
forums_heading: "Forum categories"
Expand Down Expand Up @@ -114,7 +123,7 @@ en:
new_forum: "New forum"
new_reply_to: "New reply to"
new_reply_from: "New reply from"
new_topic: "Start a new discussion"
new_topic: "Start discussion"
new_topic_button: "Submit topic"
new_topic_heading: "Start a new topic"
new_topic_introduction: ""
Expand Down Expand Up @@ -214,10 +223,3 @@ en:
topics_introduction: 'This is a list of all the discussions going on here, with the most recently updated first. You can also see a more organised list of <a href="/forum/forums">discussion categories</a> or <a href="/forum/posts">search</a> for particular posts and people.'
under: "under"
unknown_date: "unknown date"
time:
formats:
recently: "on %A at %l:%M%p"
standard: "on %B %e, %Y at %l:%M%p"
this_year: "on %B %e at %l:%M%p"
today: "today at %l:%M%p"
yesterday: "yesterday at %l:%M%p"
6 changes: 4 additions & 2 deletions forum_extension.rb
Expand Up @@ -16,7 +16,7 @@ def activate
ReaderNotifier.send :include, ForumReaderNotifier # sets up post-notification email
Page.send :include, ForumPage # makes commentable and reads some configuration
Page.send :include, ForumTags # defines radius tags for highlighting forum content on other pages
ReadersController.send :include, ForumReadersController # adds some partials and helpers to the reader pages
AccountsController.send :helper, ForumHelper # provides some linking and other helpers on reader pages
ReaderSessionsController.send :include, ForumReaderSessionsController # changes default login destination to the forum front page

unless defined? admin.forum # UI is a singleton
Expand All @@ -27,7 +27,9 @@ def activate
admin.page.edit.add :layout, "edit_commentability"
admin.reader_configuration.show.add :settings, "forum", :after => "administration"
admin.reader_configuration.edit.add :form, "edit_forum", :after => "administration"

admin.account.dashboard.add :main, 'dashboard/posts'
admin.account.show.add :main, 'accounts/posts'

if defined? RedCloth::DEFAULT_RULES
RedCloth.send :include, ForumRedCloth3
RedCloth::DEFAULT_RULES.push(:smilies)
Expand Down
7 changes: 0 additions & 7 deletions lib/commentable_model.rb
Expand Up @@ -21,13 +21,6 @@ def has_comments
:order => "replied_at DESC",
:limit => count
}}
named_scope :most_commented, lambda { |count| {
:select => "#{self.table_name}.*, count(posts.id) AS post_count",
:joins => "INNER JOIN posts ON posts.#{self.class.to_s.downcase}_id = #{self.table_name}.id",
:group => "#{self.table_name}.id",
:order => "post_count DESC",
:limit => count
}}
end
end

Expand Down
9 changes: 9 additions & 0 deletions lib/forum_page.rb
Expand Up @@ -3,6 +3,15 @@ module ForumPage
def self.included(base)
base.class_eval {
has_comments

named_scope :busiest, lambda { |count| {
:select => "pages.*, count(posts.id) AS post_count",
:joins => "INNER JOIN posts ON posts.page_id = pages.id",
:group => column_names.map { |n| 'pages.' + n }.join(','),
:order => "post_count DESC",
:limit => count
}}

include InstanceMethods
}
end
Expand Down
2 changes: 0 additions & 2 deletions lib/forum_readers_controller.rb
Expand Up @@ -2,8 +2,6 @@ module ForumReadersController
def self.included(base)
base.class_eval do
helper :forum
add_show_partial 'readers/forum_messages'
add_index_partial 'readers/messages_summary'
end
end
end
5 changes: 2 additions & 3 deletions lib/forum_tags.rb
Expand Up @@ -7,20 +7,19 @@ module ForumTags
class TagError < StandardError; end

tag 'forum_css' do |tag|
styles = []
styles = tag.render("reader_css")
styles << %{<link rel="stylesheet" href="/cleditor/jquery.cleditor.css" media="all" />} if Radiant.config['forum.toolbar?']
styles << %{<link rel="stylesheet" href="/stylesheets/forum.css" media="all" />}
end

tag 'forum_js' do |tag|
scripts = []
scripts = tag.render("reader_js")
scripts << %{
<script type="text/javascript" src="/cleditor/jquery.cleditor.js"></script>
<script type="text/javascript" src="/cleditor/jquery.cleditor.icon.js"></script>
<script type="text/javascript" src="/cleditor/jquery.cleditor.xhtml.js"></script>
} if Radiant.config['forum.toolbar?']
scripts << %{<script type="text/javascript" src="/javascripts/forum.js"></script>}
scripts.join
end

tag 'forum' do |tag|
Expand Down
4 changes: 0 additions & 4 deletions public/stylesheets/sass/forum.sass
Expand Up @@ -238,10 +238,6 @@ p.add_comment, p.add_reply
span.formnote
+small

// dashboard module
// emoticons in message display are interpolated by our redcloth extension as <img class="emoticon something" />
img.emoticon
Expand Down
2 changes: 1 addition & 1 deletion radiant-forum-extension.gemspec
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.summary = RadiantForumExtension::SUMMARY
s.description = RadiantForumExtension::DESCRIPTION

s.add_dependency 'radiant-reader-extension', "~> 2.0.0.rc3"
s.add_dependency 'radiant-reader-extension', "~> 3.0.0.rc1"
s.add_dependency 'acts_as_list', "~> 0.1.2"

ignores = if File.exist?('.gitignore')
Expand Down

0 comments on commit d6c7d13

Please sign in to comment.