Commit 211e635e02365fe7a5087b150807885a5c8255be

Authored by Eduardo Vital
Committed by Arthur Esposte
1 parent c6a2cc53

Create environment notification plugin

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Eduardo Vital <vitaldu@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Jéssica Cristina <jessica.cris1127@gmail.com>
Signed-off-by: Simião Carvalho <simiaosimis@gmail.com>
Signed-off-by: Victor Navarro <victor.matias.navarro@gmail.com>
Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@yahoo.com.br>
Showing 23 changed files with 721 additions and 0 deletions   Show diff stats
plugins/environment_notification/controllers/environment_notification_plugin_admin_controller.rb 0 → 100644
... ... @@ -0,0 +1,80 @@
  1 +class EnvironmentNotificationPluginAdminController < AdminController
  2 + before_filter :admin_required, :except => [:hide_notification]
  3 + def index
  4 + @notifications = environment.environment_notifications.order('updated_at DESC')
  5 + end
  6 +
  7 + def new
  8 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new
  9 + if request.post?
  10 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.new(params[:notifications])
  11 + @notification.message = @notification.message.html_safe
  12 + @notification.environment_id = environment.id
  13 + if @notification.save
  14 + session[:notice] = _("Notification successfully created")
  15 + redirect_to :action => :index
  16 + else
  17 + session[:notice] = _("Notification couldn't be created")
  18 + end
  19 + end
  20 + end
  21 +
  22 + def destroy
  23 + if request.delete?
  24 + notification = environment.environment_notifications.find_by_id(params[:id])
  25 + if notification && notification.destroy
  26 + session[:notice] = _('The notification was deleted.')
  27 + else
  28 + session[:notice] = _('Could not remove the notification')
  29 + end
  30 + end
  31 + redirect_to :action => :index
  32 + end
  33 +
  34 + def edit
  35 + @notification = environment.environment_notifications.find_by_id(params[:id])
  36 + if request.post?
  37 + if @notification.update_attributes(params[:notifications])
  38 + session[:notice] = _('The notification was edited.')
  39 + else
  40 + session[:notice] = _('Could not edit the notification.')
  41 + end
  42 + redirect_to :action => :index
  43 + end
  44 + end
  45 +
  46 + def change_status
  47 + @notification = environment.environment_notifications.find_by_id(params[:id])
  48 +
  49 + @notification.active = !@notification.active
  50 +
  51 + if @notification.save!
  52 + session[:notice] = _('The status of the notification was changed.')
  53 + else
  54 + session[:notice] = _('Could not change the status of the notification.')
  55 + end
  56 +
  57 + redirect_to :action => :index
  58 + end
  59 +
  60 + def hide_notification
  61 + result = false
  62 +
  63 + if logged_in?
  64 + @notification = environment.environment_notifications.find_by_id(params[:notification_id])
  65 +
  66 + if @notification
  67 + @notification.users << current_user
  68 + result = @notification.users.include?(current_user)
  69 + end
  70 + end
  71 +
  72 + render json: result
  73 + end
  74 +
  75 + protected
  76 + def admin_required
  77 + redirect_to :root unless current_user.person.is_admin?
  78 + end
  79 +
  80 +end
... ...
plugins/environment_notification/db/migrate/20150721132025_create_notification_table.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +class CreateNotificationTable < ActiveRecord::Migration
  2 + def up
  3 + create_table :environment_notifications do |t|
  4 + t.text :message
  5 + t.integer :environment_id
  6 + t.string :type
  7 + t.boolean :active
  8 + t.boolean :display_only_in_homepage, :default => false
  9 + t.boolean :display_to_all_users, :default => false
  10 + t.column :created_at, :datetime
  11 + t.column :updated_at, :datetime
  12 + end
  13 +
  14 + create_table :environment_notifications_users, id: false do |t|
  15 + t.belongs_to :environment_notification, index: true
  16 + t.belongs_to :user, index: true
  17 + end
  18 + end
  19 +
  20 + def down
  21 + drop_table :environment_notifications
  22 + drop_table :environment_notifications_users
  23 + end
  24 +end
... ...
plugins/environment_notification/lib/environment_notification_plugin.rb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +class EnvironmentNotificationPlugin < Noosfero::Plugin
  2 +
  3 + def self.plugin_name
  4 + "Environment Notifications Plugin"
  5 + end
  6 +
  7 + def self.plugin_description
  8 + _("A plugin for environment notifications.")
  9 + end
  10 +
  11 + def stylesheet?
  12 + true
  13 + end
  14 +
  15 + def js_files
  16 + %w(
  17 + public/environment_notification_plugin.js
  18 + )
  19 + end
  20 +
  21 + def body_beginning
  22 + expanded_template('environment_notification_plugin_admin/show_notification.html.erb')
  23 + end
  24 +
  25 + def admin_panel_links
  26 + {:title => _('Notification Manager'), :url => {:controller => 'environment_notification_plugin_admin', :action => 'index'}}
  27 + end
  28 +
  29 +end
... ...
plugins/environment_notification/lib/environment_notifications_user.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class EnvironmentNotificationsUser < ActiveRecord::Base
  2 + self.table_name = "environment_notifications_users"
  3 +
  4 + belongs_to :user
  5 + belongs_to :environment_notification, class_name: 'EnvironmentNotificationPlugin::EnvironmentNotification'
  6 +
  7 + attr_accessible :user_id, :environment_notification_id
  8 +
  9 + validates_uniqueness_of :user_id, :scope => :environment_notification_id
  10 +end
... ...
plugins/environment_notification/lib/ext/environment.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +require_dependency 'environment'
  2 +
  3 +class Environment
  4 + has_many :environment_notifications, class_name: 'EnvironmentNotificationPlugin::EnvironmentNotification'
  5 +end
... ...
plugins/environment_notification/lib/ext/user.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +require_dependency 'user'
  2 +
  3 +class User
  4 + has_many :environment_notifications_users
  5 + has_many :environment_notifications, :through => :environment_notifications_users
  6 +end
... ...
plugins/environment_notification/models/environment_notification_plugin/danger_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class EnvironmentNotificationPlugin::DangerNotification < EnvironmentNotificationPlugin::EnvironmentNotification
  2 +end
... ...
plugins/environment_notification/models/environment_notification_plugin/environment_notification.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +class EnvironmentNotificationPlugin::EnvironmentNotification < ActiveRecord::Base
  2 +
  3 + self.table_name = "environment_notifications"
  4 +
  5 + TYPE_LIST = [
  6 + "EnvironmentNotificationPlugin::WarningNotification",
  7 + "EnvironmentNotificationPlugin::SuccessNotification",
  8 + "EnvironmentNotificationPlugin::InformationNotification",
  9 + "EnvironmentNotificationPlugin::DangerNotification"
  10 + ]
  11 +
  12 + attr_accessible :message, :environment_id, :active, :type, :display_only_in_homepage, :display_to_all_users
  13 +
  14 + has_many :environment_notifications_users
  15 + has_many :users, :through => :environment_notifications_users
  16 +
  17 + validates_presence_of :message
  18 + validates_presence_of :environment_id
  19 + validate :notification_type_must_be_in_type_list
  20 +
  21 + def notification_type_must_be_in_type_list
  22 + unless TYPE_LIST.include?(type)
  23 + errors.add(:type, "invalid notification type")
  24 + end
  25 + end
  26 +
  27 +end
... ...
plugins/environment_notification/models/environment_notification_plugin/information_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class EnvironmentNotificationPlugin::InformationNotification < EnvironmentNotificationPlugin::EnvironmentNotification
  2 +end
... ...
plugins/environment_notification/models/environment_notification_plugin/success_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class EnvironmentNotificationPlugin::SuccessNotification < EnvironmentNotificationPlugin::EnvironmentNotification
  2 +end
... ...
plugins/environment_notification/models/environment_notification_plugin/warning_notification.rb 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class EnvironmentNotificationPlugin::WarningNotification < EnvironmentNotificationPlugin::EnvironmentNotification
  2 +end
... ...
plugins/environment_notification/public/environment_notification_plugin.js 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +(function($) {
  2 + "use strict";
  3 +
  4 + function notificationBar() {
  5 + var completeMessage = $(".notification-bar").remove();
  6 + $("#content-inner").before(completeMessage);
  7 + },
  8 +
  9 + function hideNotification(){
  10 + var notification = $(this).parent();
  11 + var id = notification.attr("data-notification");
  12 +
  13 + $.ajax({
  14 + url: noosfero_root()+"/admin/plugin/environment_notification/hide_notification",
  15 + type: "POST",
  16 + data: {notification_id: id},
  17 + success: function(response) {
  18 + notification.fadeOut();
  19 + }
  20 + });
  21 + }
  22 +
  23 + function mceRestrict() {
  24 + tinyMCE.init({
  25 + menubar : false,
  26 + selector: "textarea",
  27 + plugins: [
  28 + "autolink link"
  29 + ],
  30 + toolbar: "bold italic underline | link"
  31 + });
  32 + }
  33 +
  34 + jQuery(document).ready(function(){
  35 + notificationBar();
  36 + $(".notification-close").on("click", hideNotification);
  37 + mceRestrict();
  38 + });
  39 +
  40 +})(jQuery);
0 41 \ No newline at end of file
... ...
plugins/environment_notification/public/images/close.png 0 → 100644

240 Bytes

plugins/environment_notification/public/images/hide.png 0 → 100644

389 Bytes

plugins/environment_notification/public/images/show.png 0 → 100644

364 Bytes

plugins/environment_notification/style.css 0 → 100644
... ... @@ -0,0 +1,141 @@
  1 +.notification-bar {
  2 + display: block;
  3 +}
  4 +
  5 +.notification:hover {
  6 + opacity: 0.8;
  7 +}
  8 +
  9 +#notification-manager {
  10 + overflow: auto;
  11 +}
  12 +
  13 +.notification .notification-close {
  14 + background: url(public/images/close.png) no-repeat;
  15 + background-position: center;
  16 + width: 20px;
  17 + height: 20px;
  18 +}
  19 +
  20 +.warningnotification,
  21 +.informationnotification,
  22 +.successnotification,
  23 +.dangernotification {
  24 + margin-bottom: 10px;
  25 + padding: 7px 10px;
  26 + border-radius: 5px;
  27 + border: 1px solid blue;
  28 + font-size: 16px;
  29 + color: white;
  30 + overflow: auto;
  31 +}
  32 +
  33 +.warningnotification p,
  34 +.informationnotification p,
  35 +.successnotification p,
  36 +.dangernotification p {
  37 + margin: 0px;
  38 +}
  39 +
  40 +.warningnotification {
  41 + background: #EEA236;
  42 + border: 1px solid #EEA236;
  43 +}
  44 +
  45 +.informationnotification {
  46 + background: #5BC0DE;
  47 + border: 1px solid #46B8DA;
  48 +}
  49 +
  50 +.successnotification {
  51 + background: #5CB85C;
  52 + border: 1px solid #4CAE4C;
  53 +}
  54 +
  55 +.dangernotification {
  56 + background: #C9302C;
  57 + border: 1px solid #AC2925;
  58 +}
  59 +
  60 +a.button.icon-deactivate {
  61 + background: url(public/images/hide.png) no-repeat;
  62 + background-position: center;
  63 +}
  64 +
  65 +a.button.icon-activate {
  66 + background: url(public/images/show.png) no-repeat;
  67 + background-position: center;
  68 +}
  69 +
  70 +.notification-line {
  71 + display: inline;
  72 + padding-top: 10px;
  73 + vertical-align: middle;
  74 + border-bottom: 1px solid #ccc;
  75 +}
  76 +
  77 +.notification-title-bar {
  78 + float: left;
  79 + width: 100%;
  80 + font-style: 14px;
  81 + font-weight: 700;
  82 + border-bottom: 2px solid black;
  83 + padding: 9px 0;
  84 +}
  85 +
  86 +.notification-title {
  87 + width: 80%;
  88 + float: left;
  89 + text-align: center;
  90 +}
  91 +
  92 +.action-title {
  93 + width: 20%;
  94 + float: left;
  95 + text-align: center;
  96 +}
  97 +
  98 +.notification-action {
  99 + width: 18%;
  100 + float: left;
  101 + height: 30px;
  102 + padding-top: 9px;
  103 +}
  104 +
  105 +.main-bar .button,
  106 +.notification-action .button {
  107 + border-radius: 3px;
  108 +}
  109 +
  110 +.notification-message {
  111 + width: 82%;
  112 + float: left;
  113 +}
  114 +
  115 +.new-notification {
  116 + float: right;
  117 + width: auto;
  118 +}
  119 +
  120 +.back-button {
  121 + float: left;
  122 +}
  123 +
  124 +.main-bar {
  125 + display: inline;
  126 + width: 100%;
  127 +}
  128 +
  129 +.notification-bar .notification .notification-message {
  130 + width: 90%;
  131 + float: left;
  132 +}
  133 +
  134 +.notification-bar .notification .notification-close {
  135 + background: url(public/images/close.png) no-repeat;
  136 + background-position: center;
  137 + width: 20px;
  138 + height: 20px;
  139 + float: right;
  140 + cursor: pointer;
  141 +}
... ...
plugins/environment_notification/test/functional/environment_notification_plugin_admin_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,153 @@
  1 +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
  2 +require(
  3 + File.expand_path(File.dirname(__FILE__)) +
  4 + '/../../controllers/environment_notification_plugin_admin_controller'
  5 +)
  6 +
  7 +class EnvironmentNotificationPluginAdminController; def rescue_action(e) raise e end;
  8 +end
  9 +
  10 +class EnvironmentNotificationPluginAdminControllerTest < ActionController::TestCase
  11 + def setup
  12 + @controller = EnvironmentNotificationPluginAdminController.new
  13 + @request = ActionController::TestRequest.new
  14 + @response = ActionController::TestResponse.new
  15 + @person = create_user('person').person
  16 +
  17 + @environment = Environment.default
  18 + @environment.enable_plugin('EnvironmentNotificationPlugin')
  19 + @environment.save!
  20 +
  21 + login_as(@person.user.login)
  22 + end
  23 +
  24 + attr_accessor :person
  25 +
  26 + should 'an admin be able to create a notification' do
  27 + @environment.add_admin(@person)
  28 + post :new, :notifications => {
  29 + :message => "Message",
  30 + :active => true,
  31 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  32 + }
  33 + assert_redirected_to :action => 'index'
  34 + notification = EnvironmentNotificationPlugin::EnvironmentNotification.last
  35 + assert_equal "Message", notification.message
  36 + assert notification.active
  37 + assert_equal "EnvironmentNotificationPlugin::DangerNotification", notification.type
  38 + end
  39 +
  40 + should 'an user not to be able to create a notification' do
  41 + post :new, :notifications => {
  42 + :message => "Message",
  43 + :active => true,
  44 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  45 + }
  46 + assert_redirected_to :root
  47 + assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.last
  48 + end
  49 +
  50 + should 'an admin be able to edit a notification' do
  51 + @environment.add_admin(@person)
  52 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  53 + :environment_id => @environment.id,
  54 + :message => "Message",
  55 + :active => true,
  56 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  57 + )
  58 + post :edit, :id => @notification.id, :notifications => {
  59 + :message => "Edited Message",
  60 + :active => false,
  61 + :type => "EnvironmentNotificationPlugin::WarningNotification"
  62 + }
  63 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.last
  64 + assert_redirected_to :action => 'index'
  65 + assert_equal "Edited Message", @notification.message
  66 + assert !@notification.active
  67 + assert_equal "EnvironmentNotificationPlugin::WarningNotification", @notification.type
  68 + end
  69 +
  70 + should 'an user not to be able to edit a notification' do
  71 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  72 + :environment_id => @environment.id,
  73 + :message => "Message",
  74 + :active => true,
  75 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  76 + )
  77 + post :edit, :notifications => {
  78 + :message => "Edited Message",
  79 + :active => false,
  80 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  81 + }
  82 + @notification.reload
  83 + assert_redirected_to :root
  84 + assert_equal "Message", @notification.message
  85 + assert @notification.active
  86 + end
  87 +
  88 + should 'an admin be able to destroy a notification' do
  89 + @environment.add_admin(@person)
  90 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  91 + :environment_id => @environment.id,
  92 + :message => "Message",
  93 + :active => true,
  94 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  95 + )
  96 + delete :destroy, :id => @notification.id
  97 + assert_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id)
  98 + end
  99 +
  100 + should 'an user not to be able to destroy a notification' do
  101 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  102 + :environment_id => @environment.id,
  103 + :message => "Message",
  104 + :active => true,
  105 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  106 + )
  107 + delete :destroy, :id => @notification.id
  108 +
  109 + assert_redirected_to :root
  110 + assert_not_nil EnvironmentNotificationPlugin::EnvironmentNotification.find_by_id(@notification.id)
  111 + end
  112 +
  113 + should 'an admin be able to change Notification status' do
  114 + @environment.add_admin(@person)
  115 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  116 + :environment_id => @environment.id,
  117 + :message => "Message",
  118 + :active => true,
  119 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  120 + )
  121 + post :change_status, :id => @notification.id
  122 + assert_redirected_to :action => 'index'
  123 +
  124 + @notification.reload
  125 + assert !@notification.active
  126 + end
  127 +
  128 + should 'an user not be able to change Notification status' do
  129 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  130 + :environment_id => @environment.id,
  131 + :message => "Message",
  132 + :active => true,
  133 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  134 + )
  135 + post :change_status, :id => @notification.id
  136 + assert_redirected_to :root
  137 +
  138 + @notification.reload
  139 + assert @notification.active
  140 + end
  141 +
  142 + should 'a logged in user be able to permanently hide notifications' do
  143 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  144 + :environment_id => @environment.id,
  145 + :message => "Message",
  146 + :active => true,
  147 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  148 + )
  149 + post :hide_notification, :notification_id => @notification.id
  150 + assert_equal "true", @response.body
  151 + assert_equal true, @notification.users.include?(@person.user)
  152 + end
  153 +end
... ...
plugins/environment_notification/test/functional/home_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,105 @@
  1 +require File.expand_path(File.dirname(__FILE__)) + '/../../../../test/test_helper'
  2 +require 'home_controller'
  3 +
  4 +class HomeController; def rescue_action(e) raise e end;
  5 +end
  6 +
  7 +class HomeControllerTest < ActionController::TestCase
  8 + def setup
  9 + @controller = HomeController.new
  10 + @request = ActionController::TestRequest.new
  11 + @response = ActionController::TestResponse.new
  12 + @person = create_user('person').person
  13 +
  14 + @environment = Environment.default
  15 + @environment.enable_plugin('EnvironmentNotificationPlugin')
  16 + @environment.save!
  17 + end
  18 +
  19 + attr_accessor :person
  20 +
  21 + should 'an active notification be displayed on home page for a logged in user' do
  22 + login_as(@person.user.login)
  23 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  24 + :environment_id => @environment.id,
  25 + :message => "Hello, this is a Notification Message",
  26 + :active => true,
  27 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  28 + )
  29 + get :index
  30 + assert_match /Hello, this is a Notification Message/, @response.body
  31 + end
  32 +
  33 +
  34 + should 'an active notification not be displayed on home page for unlogged user' do
  35 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  36 + :environment_id => @environment.id,
  37 + :message => "Hello, this is a Notification Message",
  38 + :active => true,
  39 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  40 + )
  41 + get :index
  42 + assert_no_match /Hello, this is a Notification Message/, @response.body
  43 + end
  44 +
  45 + should 'an active notification be displayed on home page for unlogged user' do
  46 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  47 + :environment_id => @environment.id,
  48 + :message => "Hello, this is a Notification Message",
  49 + :display_to_all_users => true,
  50 + :active => true,
  51 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  52 + )
  53 + get :index
  54 + assert_match /Hello, this is a Notification Message/, @response.body
  55 + end
  56 +
  57 + should 'only display the notification with display_to_all_users option for unlogged user ' do
  58 + @notification1 = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  59 + :environment_id => @environment.id,
  60 + :message => "Hello, this is an old Notification Message",
  61 + :active => true,
  62 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  63 + )
  64 +
  65 + @notification2 = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  66 + :environment_id => @environment.id,
  67 + :message => "Hello, this is a new Notification Message",
  68 + :display_to_all_users => true,
  69 + :active => true,
  70 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  71 + )
  72 +
  73 +
  74 + get :index
  75 + assert_no_match /Hello, this is a Notification Message/, @response.body
  76 + assert_match /Hello, this is a new Notification Message/, @response.body
  77 + end
  78 +
  79 + should 'an inactive notification not be displayed on home page' do
  80 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  81 + :environment_id => @environment.id,
  82 + :message => "Hello, this is a Notification Message",
  83 + :active => false,
  84 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  85 + )
  86 + get :index
  87 + assert_no_match /Hello, this is a Notification Message/, @response.body
  88 + end
  89 +
  90 +
  91 + should 'an active notification not be displayed to a logged in user after been closed by him' do
  92 + login_as(@person.user.login)
  93 + @notification = EnvironmentNotificationPlugin::EnvironmentNotification.create(
  94 + :environment_id => @environment.id,
  95 + :message => "Hello, this is a Notification Message",
  96 + :active => true,
  97 + :type => "EnvironmentNotificationPlugin::DangerNotification"
  98 + )
  99 + @notification.users << @person.user
  100 + @notification.save!
  101 + assert_equal true, @notification.users.include?(@person.user)
  102 + get :index
  103 + assert_no_match /Hello, this is a Notification Message/, @response.body
  104 + end
  105 +end
... ...
plugins/environment_notification/views/environment_notification_plugin_admin/_form.html.erb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +<% abstract_options = {:value => @notification.message, :style => 'width: 100%; height: 200px;'} %>
  2 +
  3 +<%= button :back, _('Back'), :controller => 'environment_notification_plugin_admin' %>
  4 +
  5 +<%= form_for :notifications do |f| %>
  6 +
  7 + <%= render :file => 'shared/tiny_mce' %>
  8 +
  9 + <%= labelled_form_field(_("Enter your message here:"), f.text_area(:message, abstract_options)) %>
  10 +
  11 + <%= labelled_form_field(_('Notifications Status'), select(:notifications, :active, options_for_select_with_title({"Active" => true, "Inactive" => false}, @notification.active))) %>
  12 +
  13 + <%= labelled_form_field(_('Notifications Type'), select(:notifications, :type, options_for_select_with_title({"Information" => "EnvironmentNotificationPlugin::InformationNotification", "Warning" => "EnvironmentNotificationPlugin::WarningNotification", "Success" => "EnvironmentNotificationPlugin::SuccessNotification", "Danger" => "EnvironmentNotificationPlugin::DangerNotification"}, @notification.type))) %>
  14 +
  15 + <div>
  16 + <%= labelled_check_box(_("Display only in the homepage"), 'notifications[display_only_in_homepage]', '1', @notification.display_only_in_homepage?) %>
  17 + </div>
  18 +
  19 + <div>
  20 + <%= labelled_check_box(_("Display to not logged users too"), 'notifications[display_to_all_users]', '1', @notification.display_to_all_users?) %>
  21 + </div>
  22 +
  23 + <% button_bar do %>
  24 + <%= submit_button 'save', _('Save'), :cancel => { :action => 'index' } %>
  25 + <% end %>
  26 +
  27 +<% end %>
... ...
plugins/environment_notification/views/environment_notification_plugin_admin/edit.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= render :partial => "form" %>
... ...
plugins/environment_notification/views/environment_notification_plugin_admin/index.html.erb 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +<div id="notification-manager">
  2 + <div class="notification-manager-title">
  3 + <h1><%= _("Environment Notifications") %></h1>
  4 + </div>
  5 + <div class="buttons-bar">
  6 + <div class="new-notification">
  7 + <%= button :new, _('New Notification'), {:action => :new}, :method => :get %>
  8 + </div>
  9 + <div class="back-button">
  10 + <%= button :back, _('Back to control panel'), {:controller => 'admin_panel', :action => :index}, :method => :get %>
  11 + </div>
  12 + </div>
  13 +
  14 + <div class="notification-title-bar">
  15 + <div class="notification-title">
  16 + <%= _('Notifications') %>
  17 + </div>
  18 + <div class="action-title">
  19 + <%= _('Actions') %>
  20 + </div>
  21 + </div>
  22 +
  23 + <% @notifications.each do |notification| %>
  24 + <div class="notification-line">
  25 + <div class="notification-message">
  26 + <%= truncate(notification.message, length: 50) %>
  27 + </div>
  28 + <div class="notification-action">
  29 + <% if notification.active? %>
  30 + <%= button_without_text :deactivate, _('Deactivate'), {:action => :change_status, :id => notification}, :method => :post, :confirm => _("Do you want to change the status of this notification?") %>
  31 + <% else %>
  32 + <%= button_without_text :activate, _('Activate'), {:action => :change_status, :id => notification}, :method => :post, :confirm => _("Do you want to change the status of this notification?") %>
  33 + <% end %>
  34 + <%= button_without_text :edit, _('Edit'), {:action => 'edit', :id => notification.id} if !remove_content_button(:edit, notification) %>
  35 + <%= button_without_text :delete, _('Delete'), {:action => :destroy, :id => notification}, :method => :delete, :confirm => _("Do you want to delete this notification?") %>
  36 + </div>
  37 + </div>
  38 + <% end %>
  39 +</div>
  40 +
... ...
plugins/environment_notification/views/environment_notification_plugin_admin/new.html.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +<%= render :partial => "form" %>
... ...
plugins/environment_notification/views/environment_notification_plugin_admin/show_notification.html.erb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +<div class="notification-bar">
  2 + <% if logged_in? %>
  3 + <% @notifications = environment.environment_notifications.order('updated_at DESC').where(active: true) %>
  4 + <% @deactivated = current_user.environment_notifications %>
  5 + <% @notifications = @notifications - @deactivated %>
  6 + <% else %>
  7 + <% @notifications = environment.environment_notifications.order('updated_at DESC').where(active: true) %>
  8 + <% end %>
  9 +
  10 + <% @notifications.each do |notification| %>
  11 + <% if controller_path == "home" || !notification.display_only_in_homepage? %>
  12 + <% if logged_in? || notification.display_to_all_users? %>
  13 + <div class="<%= notification.type.gsub("EnvironmentNotificationPlugin::", "").downcase %> notification" data-notification="<%=notification.id%>">
  14 + <div class="notification-message">
  15 + <%= notification.message %>
  16 + </div>
  17 + <% if logged_in? %>
  18 + <div class="notification-close"></div>
  19 + <% end %>
  20 + </div>
  21 + <% end %>
  22 + <% end %>
  23 + <% end %>
  24 +</div>
... ...