diff --git a/plugins/notification/README b/plugins/notification/README new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/plugins/notification/README diff --git a/plugins/notification/controllers/notification_plugin_admin_controller.rb b/plugins/notification/controllers/notification_plugin_admin_controller.rb new file mode 100644 index 0000000..6d0b75a --- /dev/null +++ b/plugins/notification/controllers/notification_plugin_admin_controller.rb @@ -0,0 +1,20 @@ +class NotificationPluginAdminController < AdminController + append_view_path File.join(File.dirname(__FILE__) + '/../views') + + #FIXME create admin configuration for categories + def index + @settings ||= Noosfero::Plugin::Settings.new(environment, NotificationPlugin, params[:settings]) + if request.post? + @settings.categories = nil if @settings.categories.blank? + @settings.save! + redirect_to :action => 'index' + end + end + + def create + +#render :text => 'bli' +raise params.inspect + end + +end diff --git a/plugins/notification/controllers/notification_plugin_profile_controller.rb b/plugins/notification/controllers/notification_plugin_profile_controller.rb new file mode 100644 index 0000000..ca68bef --- /dev/null +++ b/plugins/notification/controllers/notification_plugin_profile_controller.rb @@ -0,0 +1,21 @@ +class NotificationPluginProfileController < ProfileController + append_view_path File.join(File.dirname(__FILE__) + '/../../views') + + #FIXME make this test + needs_profile + + protect 'see_loby_notes', :profile + + layout 'embed' + + def lobby_notes + @date = params[:date].nil? ? Date.today : Date.parse(params[:date]) + @events = profile.lobby_notes.by_day(@date).paginate(:per_page => per_page, :page => params[:page]) + + if request.xhr? + render :partial => 'event', :collection => @events + end + end + +end + diff --git a/plugins/notification/dependencies.rb b/plugins/notification/dependencies.rb new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/plugins/notification/dependencies.rb diff --git a/plugins/notification/install.rb b/plugins/notification/install.rb new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/plugins/notification/install.rb diff --git a/plugins/notification/lib/ext/profile.rb b/plugins/notification/lib/ext/profile.rb new file mode 100644 index 0000000..59dcb98 --- /dev/null +++ b/plugins/notification/lib/ext/profile.rb @@ -0,0 +1,6 @@ +require_dependency 'profile' + +Profile.class_eval do + has_many :notifications, :source => 'articles', :class_name => 'NotificationPlugin::NotificationContent', :order => 'start_date' + has_many :lobby_notes, :source => 'articles', :class_name => 'NotificationPlugin::LobbyNoteContent', :order => 'start_date' +end diff --git a/plugins/notification/lib/notification_plugin.rb b/plugins/notification/lib/notification_plugin.rb new file mode 100644 index 0000000..12b383e --- /dev/null +++ b/plugins/notification/lib/notification_plugin.rb @@ -0,0 +1,15 @@ +class NotificationPlugin < Noosfero::Plugin + + def self.plugin_name + "Notification Plugin" + end + + def self.plugin_description + _("A plugin that add a new content type called notification where a communitty adminsitrator could notify community .") + end + + def content_types + [NotificationPlugin::NotificationContent, NotificationPlugin::LobbyNoteContent] + end + +end diff --git a/plugins/notification/lib/notification_plugin/category_notification.rb b/plugins/notification/lib/notification_plugin/category_notification.rb new file mode 100644 index 0000000..7d051aa --- /dev/null +++ b/plugins/notification/lib/notification_plugin/category_notification.rb @@ -0,0 +1,4 @@ +#FIXME make this test +class NotificationPlugin::CategoryNotification < Category + +end diff --git a/plugins/notification/lib/notification_plugin/helpers/viewer_helper.rb b/plugins/notification/lib/notification_plugin/helpers/viewer_helper.rb new file mode 100644 index 0000000..efd8d85 --- /dev/null +++ b/plugins/notification/lib/notification_plugin/helpers/viewer_helper.rb @@ -0,0 +1,8 @@ +module NotificationPlugin::Helpers::ViewerHelper + + def lobby_notes_plugin_stylesheet + plugin_stylesheet_path = NotificationPlugin.public_path('style.css') + stylesheet_link_tag plugin_stylesheet_path, :cache => "cache/plugins-#{Digest::MD5.hexdigest plugin_stylesheet_path.to_s}" + end + +end diff --git a/plugins/notification/lib/notification_plugin/lobby_note_content.rb b/plugins/notification/lib/notification_plugin/lobby_note_content.rb new file mode 100644 index 0000000..707f4db --- /dev/null +++ b/plugins/notification/lib/notification_plugin/lobby_note_content.rb @@ -0,0 +1,24 @@ +class NotificationPlugin::LobbyNoteContent < Event + + def self.short_description + 'Lobby note for gatekeepers' + end + + def self.description + 'Notify gatekeeper' + end + +#FIXME make the html output specific +# def to_html(options = {}) +# source = options["source"] +# embeded = options.has_key? "embeded" +# prompt_id = options["prompt_id"] +# pairwise_content = self +# lambda do +# locals = {:pairwise_content => pairwise_content, :source => source, :embeded => embeded, :prompt_id => prompt_id } +# render :file => 'content_viewer/prompt.rhtml', :locals => locals +# end +# end +# + +end diff --git a/plugins/notification/lib/notification_plugin/notification_content.rb b/plugins/notification/lib/notification_plugin/notification_content.rb new file mode 100644 index 0000000..40ea6f0 --- /dev/null +++ b/plugins/notification/lib/notification_plugin/notification_content.rb @@ -0,0 +1,24 @@ +class NotificationPlugin::NotificationContent < Article + + def self.short_description + 'Notification for users' + end + + def self.description + 'Notification for users of community' + end + +#FIXME make the html output specific +# def to_html(options = {}) +# source = options["source"] +# embeded = options.has_key? "embeded" +# prompt_id = options["prompt_id"] +# pairwise_content = self +# lambda do +# locals = {:pairwise_content => pairwise_content, :source => source, :embeded => embeded, :prompt_id => prompt_id } +# render :file => 'content_viewer/prompt.rhtml', :locals => locals +# end +# end +# + +end diff --git a/plugins/notification/public/ajax-loader.gif b/plugins/notification/public/ajax-loader.gif new file mode 100644 index 0000000..5f78ce7 Binary files /dev/null and b/plugins/notification/public/ajax-loader.gif differ diff --git a/plugins/notification/public/javascripts/lobby_note.js b/plugins/notification/public/javascripts/lobby_note.js new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/plugins/notification/public/javascripts/lobby_note.js diff --git a/plugins/notification/public/style.css b/plugins/notification/public/style.css new file mode 100644 index 0000000..8101ad9 --- /dev/null +++ b/plugins/notification/public/style.css @@ -0,0 +1,78 @@ +#wrap-1 { + width: 100% !important; +} + +#wrap-2 { + width: 100%; + position: absolute; + margin: 0px; + padding: 0px; +} + +#content { + box-shadow: none; + margin: 0px; + padding: 0px; +} + +.box-1 { + margin: 0px; +} + +body { + background: none; + width: 100%; + height: 100%; +} + +.lobby-notes { + width: 100%; + height: 100%; + font-size: 24px; + +} + +#lobby-note-elements { + list-style: none; + margin-left: 30px; + margin-right: 30px; + padding: 0px; +} + +#lobby-note-elements .title { + font-weight: bold; +} + +#lobby-note-elements .created_by { + font-size: 12px; +} + +#lobby-note-elements li { + border-top: solid #1759b2; + background-color: #f4f8fa; + padding: 10px; + width: 100%; + text-align: justify; + margin-top: 30px; +} + +.lobby-header{ + text-align: center; +} + +#content .lobby-header h1{ + text-align: center; + font-size: 30px; +} + +.lobby-header img{ + position: absolute; + left: 0px; + top: 0px; + margin-left: 30px; +} + +.lobby-header .before{ + float: left; + margin-left: 200px; +} diff --git a/plugins/notification/test/functional/notification_plugin_admin_controller_test.rb b/plugins/notification/test/functional/notification_plugin_admin_controller_test.rb new file mode 100644 index 0000000..7ab190a --- /dev/null +++ b/plugins/notification/test/functional/notification_plugin_admin_controller_test.rb @@ -0,0 +1,21 @@ +require File.dirname(__FILE__) + '/../test_helper' + + +class NotificationPluginAdminControllerTest < ActionController::TestCase + + + def setup + @controller = NotificationPluginAdminController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @environment = fast_create(Environment) + + login_as(create_admin_user(@environment)) + end + + should 'get a first prompt' do + get :index + assert_response :success + end + +end diff --git a/plugins/notification/test/functional/notification_plugin_profile_controller_test.rb b/plugins/notification/test/functional/notification_plugin_profile_controller_test.rb new file mode 100644 index 0000000..f17c87a --- /dev/null +++ b/plugins/notification/test/functional/notification_plugin_profile_controller_test.rb @@ -0,0 +1,43 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class NotificationPluginProfileControllerTest < ActionController::TestCase + + def setup + @environment = Environment.default + + @controller = NotificationPluginProfileController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @user = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe') + @profile = fast_create(Community, :environment_id => @environment.id) + @role = Role.create(:name => 'somerole', :permissions => ['see_loby_notes']) + @profile.affiliate(@user.person, role) + + login_as(@user.login) + end + + attr_reader :profile, :role + + should 'access lobby_notes action' do + get :lobby_notes, :profile => profile.identifier + assert :lobby_notes + assert_response :success + end + + should 'list the lobby notes of profile' do + note1 = fast_create(NotificationPlugin::LobbyNoteContent, :profile_id => profile.id, :start_date => Date.today) + note2 = fast_create(NotificationPlugin::LobbyNoteContent, :profile_id => profile.id, :start_date => Date.today) + get :lobby_notes, :profile => profile.identifier + + assert_equivalent [note1, note2], assigns(:events) + end + + should 'not see lobby_notes if there is no see_loby_notes permission' do + role.permissions = [] + role.save + get :lobby_notes, :profile => profile.identifier + assert_response :forbidden + end + +end diff --git a/plugins/notification/test/test_helper.rb b/plugins/notification/test/test_helper.rb new file mode 100644 index 0000000..cca1fd3 --- /dev/null +++ b/plugins/notification/test/test_helper.rb @@ -0,0 +1 @@ +require File.dirname(__FILE__) + '/../../../test/test_helper' diff --git a/plugins/notification/test/unit/ext/profile_test.rb b/plugins/notification/test/unit/ext/profile_test.rb new file mode 100644 index 0000000..2a4718a --- /dev/null +++ b/plugins/notification/test/unit/ext/profile_test.rb @@ -0,0 +1,19 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class ProfileTest < ActiveSupport::TestCase + + should "comunity have notifications method defined" do + profile = Community.new + assert_nothing_raised do + profile.notifications + end + end + + should "comunity have lobby_notes method defined" do + profile = Community.new + assert_nothing_raised do + profile.lobby_notes + end + end + +end diff --git a/plugins/notification/test/unit/notification_plugin/category_test.rb b/plugins/notification/test/unit/notification_plugin/category_test.rb new file mode 100644 index 0000000..b59407d --- /dev/null +++ b/plugins/notification/test/unit/notification_plugin/category_test.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class NotificationPlugin::CategoryNotificationTest < ActiveSupport::TestCase + + should 'create the category for notifications' do + assert_nothing_raised NameError do + notification = CategoryNotification.new + end + end + +end diff --git a/plugins/notification/test/unit/notification_plugin/lobby_note_content_test.rb b/plugins/notification/test/unit/notification_plugin/lobby_note_content_test.rb new file mode 100644 index 0000000..1e60ce2 --- /dev/null +++ b/plugins/notification/test/unit/notification_plugin/lobby_note_content_test.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class NotificationPlugin::LobbyNoteContentTest < ActiveSupport::TestCase + + should 'create the content type lobby note' do + assert_nothing_raised NameError do + note = LobbyNoteContent.new + end + end + +end diff --git a/plugins/notification/test/unit/notification_plugin/notification_content_test.rb b/plugins/notification/test/unit/notification_plugin/notification_content_test.rb new file mode 100644 index 0000000..2425e93 --- /dev/null +++ b/plugins/notification/test/unit/notification_plugin/notification_content_test.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/../../test_helper' + +class NotificationPlugin::NotificationContentTest < ActiveSupport::TestCase + + should 'create the content type notification' do + assert_nothing_raised NameError do + notification = NotificationContent.new + end + end + +end diff --git a/plugins/notification/test/unit/notification_plugin_test.rb b/plugins/notification/test/unit/notification_plugin_test.rb new file mode 100644 index 0000000..4b8086a --- /dev/null +++ b/plugins/notification/test/unit/notification_plugin_test.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class NotificationPluginTest < ActiveSupport::TestCase + + should "add notification content for content types" do + notification = NotificationPlugin.new + assert notification.content_types.include?(NotificationPlugin::NotificationContent) + end + + should "add lobby notes content for content types" do + notification = NotificationPlugin.new + assert notification.content_types.include?(NotificationPlugin::LobbyNoteContent) + end + +end diff --git a/plugins/notification/views/notification_plugin_admin/index.rhtml b/plugins/notification/views/notification_plugin_admin/index.rhtml new file mode 100644 index 0000000..49124dd --- /dev/null +++ b/plugins/notification/views/notification_plugin_admin/index.rhtml @@ -0,0 +1,20 @@ +

<%= _('Notification settings')%>

+ +<% form_for(:settings) do |f| %> + +
+
+ <%= labelled_form_field _('Noitification Categories'), f.text_field(:categories) %> + <%= button_to_remote_without_text(:add, _('Add New Category'), + :update => 'notification-config-fields', + :loading => '$("notification-config-fields").addClassName("loading")', + :complete => '$("notification-config-fields").removeClassName("loading")', + :url => { :action => 'create'}) + %> + + + <% button_bar do %> + <%= submit_button(:save, _('Save'), :cancel => {:action => 'create'}) %> + <% end %> +<% end %> + diff --git a/plugins/notification/views/notification_plugin_profile/_event.rhtml b/plugins/notification/views/notification_plugin_profile/_event.rhtml new file mode 100644 index 0000000..c54baef --- /dev/null +++ b/plugins/notification/views/notification_plugin_profile/_event.rhtml @@ -0,0 +1,9 @@ +
  • +
    <%= event.title %>
    + + <%= _("%{author} on %{date}") % {:author => event.author_name, :date => show_time(event.created_at) } %> + +
    + <%= event.body %> +
    +
  • diff --git a/plugins/notification/views/notification_plugin_profile/lobby_notes.rhtml b/plugins/notification/views/notification_plugin_profile/lobby_notes.rhtml new file mode 100644 index 0000000..8e5a1f2 --- /dev/null +++ b/plugins/notification/views/notification_plugin_profile/lobby_notes.rhtml @@ -0,0 +1,54 @@ +<% extend NotificationPlugin::Helpers::ViewerHelper %> + +<%= lobby_notes_plugin_stylesheet %> + + + +
    + +
    + <%= image_tag profile.profile_custom_image(:thumb) %> +

    + <%= @profile.name %> +

    +

    <%= _("You have %s notifications (%s)") % [ @events.count, show_date(@date)] %>

    +
    + <%= +#link_to _('Before'), {:action => 'lobby_notes'} +%> +
    +
    + + + +
    -- libgit2 0.21.2