Commit 65ec2574ddd0d66b9af0320afb6e88ad8709f265
1 parent
7ef5f6b3
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
notification plugin
Showing
25 changed files
with
415 additions
and
0 deletions
Show diff stats
plugins/notification/controllers/notification_plugin_admin_controller.rb
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +class NotificationPluginAdminController < AdminController | |
2 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | |
3 | + | |
4 | + #FIXME create admin configuration for categories | |
5 | + def index | |
6 | + @settings ||= Noosfero::Plugin::Settings.new(environment, NotificationPlugin, params[:settings]) | |
7 | + if request.post? | |
8 | + @settings.categories = nil if @settings.categories.blank? | |
9 | + @settings.save! | |
10 | + redirect_to :action => 'index' | |
11 | + end | |
12 | + end | |
13 | + | |
14 | + def create | |
15 | + | |
16 | +#render :text => 'bli' | |
17 | +raise params.inspect | |
18 | + end | |
19 | + | |
20 | +end | ... | ... |
plugins/notification/controllers/notification_plugin_profile_controller.rb
0 → 100644
... | ... | @@ -0,0 +1,21 @@ |
1 | +class NotificationPluginProfileController < ProfileController | |
2 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | |
3 | + | |
4 | + #FIXME make this test | |
5 | + needs_profile | |
6 | + | |
7 | + protect 'see_loby_notes', :profile | |
8 | + | |
9 | + layout 'embed' | |
10 | + | |
11 | + def lobby_notes | |
12 | + @date = params[:date].nil? ? Date.today : Date.parse(params[:date]) | |
13 | + @events = profile.lobby_notes.by_day(@date).paginate(:per_page => per_page, :page => params[:page]) | |
14 | + | |
15 | + if request.xhr? | |
16 | + render :partial => 'event', :collection => @events | |
17 | + end | |
18 | + end | |
19 | + | |
20 | +end | |
21 | + | ... | ... |
... | ... | @@ -0,0 +1,6 @@ |
1 | +require_dependency 'profile' | |
2 | + | |
3 | +Profile.class_eval do | |
4 | + has_many :notifications, :source => 'articles', :class_name => 'NotificationPlugin::NotificationContent', :order => 'start_date' | |
5 | + has_many :lobby_notes, :source => 'articles', :class_name => 'NotificationPlugin::LobbyNoteContent', :order => 'start_date' | |
6 | +end | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +class NotificationPlugin < Noosfero::Plugin | |
2 | + | |
3 | + def self.plugin_name | |
4 | + "Notification Plugin" | |
5 | + end | |
6 | + | |
7 | + def self.plugin_description | |
8 | + _("A plugin that add a new content type called notification where a communitty adminsitrator could notify community .") | |
9 | + end | |
10 | + | |
11 | + def content_types | |
12 | + [NotificationPlugin::NotificationContent, NotificationPlugin::LobbyNoteContent] | |
13 | + end | |
14 | + | |
15 | +end | ... | ... |
plugins/notification/lib/notification_plugin/category_notification.rb
0 → 100644
plugins/notification/lib/notification_plugin/helpers/viewer_helper.rb
0 → 100644
... | ... | @@ -0,0 +1,8 @@ |
1 | +module NotificationPlugin::Helpers::ViewerHelper | |
2 | + | |
3 | + def lobby_notes_plugin_stylesheet | |
4 | + plugin_stylesheet_path = NotificationPlugin.public_path('style.css') | |
5 | + stylesheet_link_tag plugin_stylesheet_path, :cache => "cache/plugins-#{Digest::MD5.hexdigest plugin_stylesheet_path.to_s}" | |
6 | + end | |
7 | + | |
8 | +end | ... | ... |
plugins/notification/lib/notification_plugin/lobby_note_content.rb
0 → 100644
... | ... | @@ -0,0 +1,24 @@ |
1 | +class NotificationPlugin::LobbyNoteContent < Event | |
2 | + | |
3 | + def self.short_description | |
4 | + 'Lobby note for gatekeepers' | |
5 | + end | |
6 | + | |
7 | + def self.description | |
8 | + 'Notify gatekeeper' | |
9 | + end | |
10 | + | |
11 | +#FIXME make the html output specific | |
12 | +# def to_html(options = {}) | |
13 | +# source = options["source"] | |
14 | +# embeded = options.has_key? "embeded" | |
15 | +# prompt_id = options["prompt_id"] | |
16 | +# pairwise_content = self | |
17 | +# lambda do | |
18 | +# locals = {:pairwise_content => pairwise_content, :source => source, :embeded => embeded, :prompt_id => prompt_id } | |
19 | +# render :file => 'content_viewer/prompt.rhtml', :locals => locals | |
20 | +# end | |
21 | +# end | |
22 | +# | |
23 | + | |
24 | +end | ... | ... |
plugins/notification/lib/notification_plugin/notification_content.rb
0 → 100644
... | ... | @@ -0,0 +1,24 @@ |
1 | +class NotificationPlugin::NotificationContent < Article | |
2 | + | |
3 | + def self.short_description | |
4 | + 'Notification for users' | |
5 | + end | |
6 | + | |
7 | + def self.description | |
8 | + 'Notification for users of community' | |
9 | + end | |
10 | + | |
11 | +#FIXME make the html output specific | |
12 | +# def to_html(options = {}) | |
13 | +# source = options["source"] | |
14 | +# embeded = options.has_key? "embeded" | |
15 | +# prompt_id = options["prompt_id"] | |
16 | +# pairwise_content = self | |
17 | +# lambda do | |
18 | +# locals = {:pairwise_content => pairwise_content, :source => source, :embeded => embeded, :prompt_id => prompt_id } | |
19 | +# render :file => 'content_viewer/prompt.rhtml', :locals => locals | |
20 | +# end | |
21 | +# end | |
22 | +# | |
23 | + | |
24 | +end | ... | ... |
1.05 KB
... | ... | @@ -0,0 +1,78 @@ |
1 | +#wrap-1 { | |
2 | + width: 100% !important; | |
3 | +} | |
4 | + | |
5 | +#wrap-2 { | |
6 | + width: 100%; | |
7 | + position: absolute; | |
8 | + margin: 0px; | |
9 | + padding: 0px; | |
10 | +} | |
11 | + | |
12 | +#content { | |
13 | + box-shadow: none; | |
14 | + margin: 0px; | |
15 | + padding: 0px; | |
16 | +} | |
17 | + | |
18 | +.box-1 { | |
19 | + margin: 0px; | |
20 | +} | |
21 | + | |
22 | +body { | |
23 | + background: none; | |
24 | + width: 100%; | |
25 | + height: 100%; | |
26 | +} | |
27 | + | |
28 | +.lobby-notes { | |
29 | + width: 100%; | |
30 | + height: 100%; | |
31 | + font-size: 24px; | |
32 | + | |
33 | +} | |
34 | + | |
35 | +#lobby-note-elements { | |
36 | + list-style: none; | |
37 | + margin-left: 30px; | |
38 | + margin-right: 30px; | |
39 | + padding: 0px; | |
40 | +} | |
41 | + | |
42 | +#lobby-note-elements .title { | |
43 | + font-weight: bold; | |
44 | +} | |
45 | + | |
46 | +#lobby-note-elements .created_by { | |
47 | + font-size: 12px; | |
48 | +} | |
49 | + | |
50 | +#lobby-note-elements li { | |
51 | + border-top: solid #1759b2; | |
52 | + background-color: #f4f8fa; | |
53 | + padding: 10px; | |
54 | + width: 100%; | |
55 | + text-align: justify; | |
56 | + margin-top: 30px; | |
57 | +} | |
58 | + | |
59 | +.lobby-header{ | |
60 | + text-align: center; | |
61 | +} | |
62 | + | |
63 | +#content .lobby-header h1{ | |
64 | + text-align: center; | |
65 | + font-size: 30px; | |
66 | +} | |
67 | + | |
68 | +.lobby-header img{ | |
69 | + position: absolute; | |
70 | + left: 0px; | |
71 | + top: 0px; | |
72 | + margin-left: 30px; | |
73 | +} | |
74 | + | |
75 | +.lobby-header .before{ | |
76 | + float: left; | |
77 | + margin-left: 200px; | |
78 | +} | ... | ... |
plugins/notification/test/functional/notification_plugin_admin_controller_test.rb
0 → 100644
... | ... | @@ -0,0 +1,21 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | + | |
4 | +class NotificationPluginAdminControllerTest < ActionController::TestCase | |
5 | + | |
6 | + | |
7 | + def setup | |
8 | + @controller = NotificationPluginAdminController.new | |
9 | + @request = ActionController::TestRequest.new | |
10 | + @response = ActionController::TestResponse.new | |
11 | + @environment = fast_create(Environment) | |
12 | + | |
13 | + login_as(create_admin_user(@environment)) | |
14 | + end | |
15 | + | |
16 | + should 'get a first prompt' do | |
17 | + get :index | |
18 | + assert_response :success | |
19 | + end | |
20 | + | |
21 | +end | ... | ... |
plugins/notification/test/functional/notification_plugin_profile_controller_test.rb
0 → 100644
... | ... | @@ -0,0 +1,43 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class NotificationPluginProfileControllerTest < ActionController::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @environment = Environment.default | |
7 | + | |
8 | + @controller = NotificationPluginProfileController.new | |
9 | + @request = ActionController::TestRequest.new | |
10 | + @response = ActionController::TestResponse.new | |
11 | + | |
12 | + @user = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') | |
13 | + @profile = fast_create(Community, :environment_id => @environment.id) | |
14 | + @role = Role.create(:name => 'somerole', :permissions => ['see_loby_notes']) | |
15 | + @profile.affiliate(@user.person, role) | |
16 | + | |
17 | + login_as(@user.login) | |
18 | + end | |
19 | + | |
20 | + attr_reader :profile, :role | |
21 | + | |
22 | + should 'access lobby_notes action' do | |
23 | + get :lobby_notes, :profile => profile.identifier | |
24 | + assert :lobby_notes | |
25 | + assert_response :success | |
26 | + end | |
27 | + | |
28 | + should 'list the lobby notes of profile' do | |
29 | + note1 = fast_create(NotificationPlugin::LobbyNoteContent, :profile_id => profile.id, :start_date => Date.today) | |
30 | + note2 = fast_create(NotificationPlugin::LobbyNoteContent, :profile_id => profile.id, :start_date => Date.today) | |
31 | + get :lobby_notes, :profile => profile.identifier | |
32 | + | |
33 | + assert_equivalent [note1, note2], assigns(:events) | |
34 | + end | |
35 | + | |
36 | + should 'not see lobby_notes if there is no see_loby_notes permission' do | |
37 | + role.permissions = [] | |
38 | + role.save | |
39 | + get :lobby_notes, :profile => profile.identifier | |
40 | + assert_response :forbidden | |
41 | + end | |
42 | + | |
43 | +end | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +require File.dirname(__FILE__) + '/../../../test/test_helper' | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +require File.dirname(__FILE__) + '/../../test_helper' | |
2 | + | |
3 | +class ProfileTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should "comunity have notifications method defined" do | |
6 | + profile = Community.new | |
7 | + assert_nothing_raised do | |
8 | + profile.notifications | |
9 | + end | |
10 | + end | |
11 | + | |
12 | + should "comunity have lobby_notes method defined" do | |
13 | + profile = Community.new | |
14 | + assert_nothing_raised do | |
15 | + profile.lobby_notes | |
16 | + end | |
17 | + end | |
18 | + | |
19 | +end | ... | ... |
plugins/notification/test/unit/notification_plugin/category_test.rb
0 → 100644
... | ... | @@ -0,0 +1,11 @@ |
1 | +require File.dirname(__FILE__) + '/../../test_helper' | |
2 | + | |
3 | +class NotificationPlugin::CategoryNotificationTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should 'create the category for notifications' do | |
6 | + assert_nothing_raised NameError do | |
7 | + notification = CategoryNotification.new | |
8 | + end | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
plugins/notification/test/unit/notification_plugin/lobby_note_content_test.rb
0 → 100644
... | ... | @@ -0,0 +1,11 @@ |
1 | +require File.dirname(__FILE__) + '/../../test_helper' | |
2 | + | |
3 | +class NotificationPlugin::LobbyNoteContentTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should 'create the content type lobby note' do | |
6 | + assert_nothing_raised NameError do | |
7 | + note = LobbyNoteContent.new | |
8 | + end | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
plugins/notification/test/unit/notification_plugin/notification_content_test.rb
0 → 100644
... | ... | @@ -0,0 +1,11 @@ |
1 | +require File.dirname(__FILE__) + '/../../test_helper' | |
2 | + | |
3 | +class NotificationPlugin::NotificationContentTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should 'create the content type notification' do | |
6 | + assert_nothing_raised NameError do | |
7 | + notification = NotificationContent.new | |
8 | + end | |
9 | + end | |
10 | + | |
11 | +end | ... | ... |
plugins/notification/test/unit/notification_plugin_test.rb
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class NotificationPluginTest < ActiveSupport::TestCase | |
4 | + | |
5 | + should "add notification content for content types" do | |
6 | + notification = NotificationPlugin.new | |
7 | + assert notification.content_types.include?(NotificationPlugin::NotificationContent) | |
8 | + end | |
9 | + | |
10 | + should "add lobby notes content for content types" do | |
11 | + notification = NotificationPlugin.new | |
12 | + assert notification.content_types.include?(NotificationPlugin::LobbyNoteContent) | |
13 | + end | |
14 | + | |
15 | +end | ... | ... |
plugins/notification/views/notification_plugin_admin/index.rhtml
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +<h1><%= _('Notification settings')%></h1> | |
2 | + | |
3 | +<% form_for(:settings) do |f| %> | |
4 | + | |
5 | + <div id="notification-config-fields"> | |
6 | + </div> | |
7 | + <%= labelled_form_field _('Noitification Categories'), f.text_field(:categories) %> | |
8 | + <%= button_to_remote_without_text(:add, _('Add New Category'), | |
9 | + :update => 'notification-config-fields', | |
10 | + :loading => '$("notification-config-fields").addClassName("loading")', | |
11 | + :complete => '$("notification-config-fields").removeClassName("loading")', | |
12 | + :url => { :action => 'create'}) | |
13 | + %> | |
14 | + | |
15 | + | |
16 | + <% button_bar do %> | |
17 | + <%= submit_button(:save, _('Save'), :cancel => {:action => 'create'}) %> | |
18 | + <% end %> | |
19 | +<% end %> | |
20 | + | ... | ... |
plugins/notification/views/notification_plugin_profile/_event.rhtml
0 → 100644
... | ... | @@ -0,0 +1,9 @@ |
1 | +<li> | |
2 | + <div class='title'><%= event.title %></div> | |
3 | + <span class='created_by'> | |
4 | + <%= _("%{author} on %{date}") % {:author => event.author_name, :date => show_time(event.created_at) } %> | |
5 | + </span> | |
6 | + <div class='body'> | |
7 | + <%= event.body %> | |
8 | + </div> | |
9 | +</li> | ... | ... |
plugins/notification/views/notification_plugin_profile/lobby_notes.rhtml
0 → 100644
... | ... | @@ -0,0 +1,54 @@ |
1 | +<% extend NotificationPlugin::Helpers::ViewerHelper %> | |
2 | + | |
3 | +<%= lobby_notes_plugin_stylesheet %> | |
4 | + | |
5 | +<script type="text/javascript"> | |
6 | + | |
7 | +function update_stream(recursive) { | |
8 | + jQuery.ajax({ | |
9 | + url: '/profile/<%= params[:profile] %>/plugin/notification/lobby_notes', | |
10 | + type: 'get', | |
11 | + start : jQuery('#lobby-notes').addClass("loading"), | |
12 | + success: function(data) { | |
13 | + jQuery("#lobby-note-elements").html(data); | |
14 | + jQuery("#lobby-notes").removeClass("loading"); | |
15 | + }, | |
16 | + error: function(ajax, stat, errorThrown) { | |
17 | + } | |
18 | + }); | |
19 | + | |
20 | + if (recursive) { | |
21 | + setTimeout(function() { | |
22 | + update_stream(true); | |
23 | + }, 10000); | |
24 | + } | |
25 | +} | |
26 | + | |
27 | +jQuery(document).ready(function() { | |
28 | + jQuery('#lobby-notes').addClass("loading"); | |
29 | + | |
30 | + update_stream(true); | |
31 | +}); | |
32 | + | |
33 | +</script> | |
34 | + | |
35 | +<div id='lobby-notes' class='lobby-notes'> | |
36 | + | |
37 | + <div class='lobby-header'> | |
38 | + <%= image_tag profile.profile_custom_image(:thumb) %> | |
39 | + <h1> | |
40 | + <%= @profile.name %> | |
41 | + </h1> | |
42 | + <h2><%= _("You have %s notifications (%s)") % [ @events.count, show_date(@date)] %></h2> | |
43 | + <div class='before'> | |
44 | + <%= | |
45 | +#link_to _('Before'), {:action => 'lobby_notes'} | |
46 | +%> | |
47 | + </div> | |
48 | + </div> | |
49 | + | |
50 | + <ul id='lobby-note-elements'> | |
51 | + <%= render :partial => 'event', :collection => @events %> | |
52 | + </ul> | |
53 | + | |
54 | +</div> | ... | ... |