Permalink
Browse files

Better notification messages

Update to use jaconda-api gem version >= 2
  • Loading branch information...
1 parent 6ff2872 commit e791c0a2c082b740dc369894fdda987992dd2fd7 @mironov committed Feb 27, 2011
Showing with 82 additions and 30 deletions.
  1. +2 −2 README.markdown
  2. +5 −1 app/views/settings/_jaconda_settings.html.erb
  3. +3 −2 config/locales/en.yml
  4. +3 −3 init.rb
  5. +69 −22 lib/notifier_hook.rb
View
@@ -12,6 +12,6 @@ Following actions will result in notifications to your Jaconda room:
- The Jaconda Notifications Plugin depends on the [official ruby wrapper](http://github.com/mironov/jaconda-api) for Jaconda API. This can be installed with:
$ sudo gem install jaconda
- Then install the Plugin following the general Redmine [plugin installation instructions](http://www.redmine.org/wiki/redmine/Plugins).
-- Go to the Plugins section of the Administration page, select Configure.
-- On this page fill out the numerical room id and api token.
+- Go to the Plugins section of the Administration page, select Configure.
+- On this page fill out the Jaconda subdomain, Room ID and Room token.
- Restart your Redmine web servers (e.g. mongrel, thin, mod_rails).
@@ -2,11 +2,15 @@
<legend><%= l(:jaconda_label_settings) %></legend>
<p>
+ <label><%= l(:jaconda_label_subdomain) %></label><%= text_field_tag 'settings[subdomain]', @settings['subdomain'] %>
+</p>
+
+<p>
<label><%= l(:jaconda_label_room_id) %></label><%= text_field_tag 'settings[room_id]', @settings['room_id'] %>
</p>
<p>
- <label><%= l(:jaconda_label_api_token) %></label><%= text_field_tag 'settings[api_token]', @settings['api_token'] %>
+ <label><%= l(:jaconda_label_room_token) %></label><%= text_field_tag 'settings[room_token]', @settings['room_token'] %>
</p>
</fieldset>
View
@@ -1,4 +1,5 @@
en:
jaconda_label_settings: Jaconda configuration settings
- jaconda_label_room_id: Numerical Room ID
- jaconda_label_api_token: API token
+ jaconda_label_subdomain: Subdomain
+ jaconda_label_room_id: Room ID
+ jaconda_label_room_token: Room token
View
@@ -9,8 +9,8 @@
name 'Redmine Jaconda Notifications plugin'
author 'Anton Mironov'
description 'A plugin to display Redmine activity on Jaconda'
- version '0.0.1'
+ version '1.0.0'
url 'http://github.com/mironov/redmine_jaconda_notifications'
-
- settings :default => {'room_id' => '', 'api_token' => ''}, :partial => 'settings/jaconda_settings'
+
+ settings :default => {'subdomain' => '', 'room_id' => '', 'room_token' => ''}, :partial => 'settings/jaconda_settings'
end
View
@@ -2,54 +2,101 @@ class NotifierHook < Redmine::Hook::Listener
def controller_issues_new_after_save(context = { })
redmine_url = "#{Setting[:protocol]}://#{Setting[:host_name]}"
- project = context[:project]
issue = context[:issue]
- user = issue.author
- deliver "#{user.firstname} created issue “#{issue.subject}”. Comment: “#{truncate_words(issue.description)}#{redmine_url}/issues/#{issue.id}"
+
+ text = "<i>#{CGI::escapeHTML("#{issue.author.name}")} created issue <a href=\"#{redmine_url}/issues/#{issue.id}\" target=\"_blank\">##{issue.id} #{CGI::escapeHTML(issue.subject)}</a></i>"
+ text += "<br />→ Tracker: <b>#{CGI::escapeHTML(issue.tracker.name)}</b>"
+ text += "<br />→ Priority: <b>#{CGI::escapeHTML(issue.priority.name)}</b>"
+ if issue.assigned_to
+ text += "<br />→ Assigned to: <b>#{CGI::escapeHTML(issue.assigned_to.name)}</b>"
+ end
+ if issue.start_date
+ text += "<br />→ Start: <b>#{CGI::escapeHTML(issue.start_date.strftime("%e %B %Y"))}</b>"
+ end
+ if issue.due_date
+ text += "<br />→ Due: <b>#{CGI::escapeHTML(issue.due_date.strftime("%e %B %Y"))}</b>"
+ end
+ if issue.estimated_hours
+ text += "<br />→ Estimated time: <b>#{CGI::escapeHTML(issue.estimated_hours)} hours</b>"
+ end
+ if issue.done_ratio
+ text += "<br />→ Done: <b>#{issue.done_ratio} %</b>"
+ end
+ text += "<br /><br />#{truncate_words(issue.description)}"
+
+ deliver text
end
-
+
def controller_issues_edit_after_save(context = { })
redmine_url = "#{Setting[:protocol]}://#{Setting[:host_name]}"
- project = context[:project]
issue = context[:issue]
journal = context[:journal]
- user = journal.user
- deliver "#{user.firstname} edited issue “#{issue.subject}”. Comment: “#{truncate_words(journal.notes)}”. #{redmine_url}/issues/#{issue.id}"
- end
+
+ text = "<i>#{CGI::escapeHTML("#{journal.user.name}")} updated issue <a href=\"#{redmine_url}/issues/#{issue.id}\" target=\"_blank\">##{issue.id} #{CGI::escapeHTML(issue.subject)}</a></i>"
+ text += "<br />→ Tracker: <b>#{CGI::escapeHTML(issue.tracker.name)}</b>"
+ text += "<br />→ Priority: <b>#{CGI::escapeHTML(issue.priority.name)}</b>"
+ if issue.assigned_to
+ text += "<br />→ Assigned to: <b>#{CGI::escapeHTML(issue.assigned_to.name)}</b>"
+ end
+ if issue.start_date
+ text += "<br />→ Start: <b>#{CGI::escapeHTML(issue.start_date.strftime("%e %B %Y"))}</b>"
+ end
+ if issue.due_date
+ text += "<br />→ Due: <b>#{CGI::escapeHTML(issue.due_date.strftime("%e %B %Y"))}</b>"
+ end
+ if issue.estimated_hours
+ text += "<br />→ Estimated time: <b>#{CGI::escapeHTML(issue.estimated_hours)} hours</b>"
+ end
+ if issue.done_ratio
+ text += "<br />→ Done: <b>#{issue.done_ratio} %</b>"
+ end
+ text += "<br /><br />#{truncate_words(journal.notes)}"
+
+ deliver text
+end
def controller_messages_new_after_save(context = { })
redmine_url = "#{Setting[:protocol]}://#{Setting[:host_name]}"
- project = context[:project]
message = context[:message]
- user = message.author
- deliver "#{user.firstname} wrote a new message “#{message.subject}” on #{project.name}: “#{truncate_words(message.content)}”. #{redmine_url}/boards/#{message.board.id}/topics/#{message.root.id}#message-#{message.id}"
+
+ text = "<i>#{CGI::escapeHTML("#{message.author.name}")} posted message <a href=\"#{redmine_url}/boards/#{message.board.id}/topics/#{message.root.id}#message-#{message.id}\" target=\"_blank\">#{CGI::escapeHTML(message.subject)}</a></i>"
+ text += "<br /><br />#{truncate_words(message.content)}"
+
+ deliver text
end
-
+
def controller_messages_reply_after_save(context = { })
redmine_url = "#{Setting[:protocol]}://#{Setting[:host_name]}"
- project = context[:project]
message = context[:message]
- user = message.author
- deliver "#{user.firstname} replied a message “#{message.subject}” on #{project.name}: “#{truncate_words(message.content)}”. #{redmine_url}/boards/#{message.board.id}/topics/#{message.root.id}#message-#{message.id}"
+
+ text = "<i>#{CGI::escapeHTML("#{message.author.name}")} commented message <a href=\"#{redmine_url}/boards/#{message.board.id}/topics/#{message.root.id}#message-#{message.id}\" target=\"_blank\">#{CGI::escapeHTML(message.subject)}</a></i>"
+ text += "<br /><br />#{truncate_words(message.content)}"
+
+ deliver text
end
-
+
def controller_wiki_edit_after_save(context = { })
redmine_url = "#{Setting[:protocol]}://#{Setting[:host_name]}"
project = context[:project]
page = context[:page]
- user = page.content.author
- deliver "#{user.firstname} edited the wiki “#{page.pretty_title}” on #{project.name}. #{redmine_url}/projects/#{project.identifier}/wiki/#{page.title}"
+
+ text = "<i>#{CGI::escapeHTML("#{page.content.author.name}")} edited wiki <a href=\"#{redmine_url}/projects/#{project.identifier}/wiki/#{page.title}\" target=\"_blank\">#{CGI::escapeHTML(page.pretty_title)}</a></i>"
+
+ deliver text
end
private
+
def deliver(message)
- Jaconda::API.authenticate(Setting.plugin_redmine_jaconda_notifications[:api_token])
- Jaconda::Message.create(:room_id => Setting.plugin_redmine_jaconda_notifications[:room_id], :text => message)
+ Jaconda::Notification.authenticate(Setting.plugin_redmine_jaconda_notifications)
+
+ Jaconda::Notification.notify(:text => message,
+ :sender_name => "redmine")
end
- def truncate_words(text, length = 20, end_string = '')
+ def truncate_words(text, length = 40, end_string = '')
return if text == nil
- words = text.split()
+ words = CGI::escapeHTML(text).gsub(/\r?\n/, '<br />').split()
words[0..(length-1)].join(' ') + (words.length > length ? end_string : '')
end
end

0 comments on commit e791c0a

Please sign in to comment.