spree_custom_notifications 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/LICENSE +26 -0
- data/README.md +37 -0
- data/Rakefile +15 -0
- data/app/assets/images/close.png +0 -0
- data/app/assets/javascripts/admin/jquery-timer.js +2135 -0
- data/app/assets/javascripts/admin/spree_custom_notifications.js +24 -0
- data/app/assets/javascripts/store/spree_custom_notifications.js +17 -0
- data/app/assets/stylesheets/admin/spree_custom_notifications.css +23 -0
- data/app/assets/stylesheets/store/spree_custom_notifications.css +23 -0
- data/app/controllers/spree/admin/notifications_controller.rb +76 -0
- data/app/controllers/spree/notifications_controller.rb +10 -0
- data/app/helpers/base_helper_decorator.rb +16 -0
- data/app/models/spree/notification.rb +17 -0
- data/app/overrides/admin_notification_link.rb +5 -0
- data/app/overrides/frontend_notifications.rb +6 -0
- data/app/views/spree/admin/notifications/_form.html.erb +28 -0
- data/app/views/spree/admin/notifications/edit.html.erb +12 -0
- data/app/views/spree/admin/notifications/index.html.erb +28 -0
- data/app/views/spree/admin/notifications/new.html.erb +9 -0
- data/app/views/spree/notifications/_notifications.html.erb +14 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20140210083923_add_spree_notifications.rb +12 -0
- data/lib/generators/spree_custom_notifications/install/install_generator.rb +31 -0
- data/lib/spree_custom_notifications.rb +2 -0
- data/lib/spree_custom_notifications/engine.rb +22 -0
- data/lib/spree_custom_notifications/factories.rb +6 -0
- data/spec/spec_helper.rb +82 -0
- data/spree_custom_notifications.gemspec +30 -0
- metadata +231 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
//= require admin/spree_backend
|
2
|
+
//= require admin/jquery-timer
|
3
|
+
|
4
|
+
$(document).ready(function(){
|
5
|
+
// show datetimepicker
|
6
|
+
$("#start_date").focusin(function () {
|
7
|
+
var currentTime = new Date(),
|
8
|
+
currrnt_hours = currentTime.getHours(),
|
9
|
+
current_minutes = currentTime.getMinutes();
|
10
|
+
$(this).datetimepicker({ dateFormat: "yy-mm-dd",
|
11
|
+
hour: currrnt_hours,
|
12
|
+
minute: current_minutes});
|
13
|
+
});
|
14
|
+
|
15
|
+
$("#end_date").focusin(function () {
|
16
|
+
var currentTime = new Date(),
|
17
|
+
currrnt_hours = currentTime.getHours(),
|
18
|
+
current_minutes = currentTime.getMinutes();
|
19
|
+
$(this).datetimepicker({ dateFormat: "yy-mm-dd",
|
20
|
+
hour: currrnt_hours,
|
21
|
+
minute: current_minutes});
|
22
|
+
|
23
|
+
});
|
24
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
//= require store/spree_frontend
|
2
|
+
// code to close notification div on click of close image
|
3
|
+
$(document).ready(function(){
|
4
|
+
$("#close_img").click(function() {
|
5
|
+
$.ajax({
|
6
|
+
async: "false",
|
7
|
+
url: '/destroy_notification',
|
8
|
+
type: "GET",
|
9
|
+
data: {},
|
10
|
+
dataType: "json",
|
11
|
+
success: function (result) {
|
12
|
+
}
|
13
|
+
});
|
14
|
+
|
15
|
+
$("ul#notification_list").slideUp();
|
16
|
+
});
|
17
|
+
});
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/*
|
2
|
+
*= require admin/spree_backend
|
3
|
+
*/
|
4
|
+
|
5
|
+
.create_btn{
|
6
|
+
float: right;
|
7
|
+
margin-right: 40px;
|
8
|
+
position: relative;
|
9
|
+
}
|
10
|
+
#index_table {
|
11
|
+
margin-top: 62px;
|
12
|
+
}
|
13
|
+
#notification-content-header{
|
14
|
+
padding-bottom: 25px;
|
15
|
+
}
|
16
|
+
.input-width{
|
17
|
+
width: 50%
|
18
|
+
}
|
19
|
+
|
20
|
+
/* time picker css*/
|
21
|
+
.ui-timepicker-div{
|
22
|
+
padding-left: 10px;
|
23
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/*
|
2
|
+
*= require store/spree_frontend
|
3
|
+
*/
|
4
|
+
|
5
|
+
#notification_div{
|
6
|
+
background-color: #9FC820;
|
7
|
+
font-size: larger;
|
8
|
+
height: auto;
|
9
|
+
padding: 10px;
|
10
|
+
color: #ffffff;
|
11
|
+
}
|
12
|
+
|
13
|
+
#notification_div li{
|
14
|
+
list-style: none outside none;
|
15
|
+
}
|
16
|
+
|
17
|
+
#close_img{
|
18
|
+
float: right;
|
19
|
+
margin-left: -3px;
|
20
|
+
margin-right: -5px;
|
21
|
+
margin-top: -12px;
|
22
|
+
width: 26px;
|
23
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Spree
|
2
|
+
# Class NotificationController
|
3
|
+
class Admin::NotificationsController < Admin::ResourceController
|
4
|
+
before_filter :auth_user
|
5
|
+
|
6
|
+
def index
|
7
|
+
@notifications =
|
8
|
+
Spree::Notification.order('created_at desc')
|
9
|
+
.page(params[:page]).per(Spree::Config[:orders_per_page])
|
10
|
+
end
|
11
|
+
|
12
|
+
def new
|
13
|
+
@spree_notification = Spree::Notification.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
@notification_params = _set_notification(params)
|
18
|
+
@spree_notification = Spree::Notification.new(@notification_params)
|
19
|
+
if @spree_notification.save
|
20
|
+
redirect_to admin_notifications_path,
|
21
|
+
notice: 'Notification has been created Succefully.'
|
22
|
+
else
|
23
|
+
_date_time_string(@spree_notification)
|
24
|
+
render :new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def edit
|
29
|
+
@spree_notification = Spree::Notification.find(params[:id])
|
30
|
+
_date_time_string(@spree_notification)
|
31
|
+
end
|
32
|
+
|
33
|
+
def update
|
34
|
+
@spree_notification = Spree::Notification.find(params[:id])
|
35
|
+
@notification_params = _set_notification(params)
|
36
|
+
|
37
|
+
if @spree_notification.update_attributes(@notification_params)
|
38
|
+
redirect_to admin_notifications_path,
|
39
|
+
notice: 'Notification has been updated Successfully'
|
40
|
+
else
|
41
|
+
_date_time_string(@spree_notification)
|
42
|
+
render :edit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def _set_notification(params)
|
47
|
+
@notification = {}
|
48
|
+
@start_date = params[:notification][:start_date]
|
49
|
+
@start_date = Time.zone.parse(params[:notification][:start_date]).getutc unless @start_date.blank?
|
50
|
+
|
51
|
+
@end_date = params[:notification][:end_date]
|
52
|
+
@end_date = Time.zone.parse(params[:notification][:end_date]).getutc unless @end_date.blank?
|
53
|
+
@message = params[:notification][:notification]
|
54
|
+
@notification = { notification: @message,
|
55
|
+
start_date: @start_date,
|
56
|
+
end_date: @end_date }
|
57
|
+
end
|
58
|
+
|
59
|
+
def _date_time_string(notification)
|
60
|
+
notification.start_date =
|
61
|
+
notification.start_date.strftime('%Y-%m-%d %H:%M') if notification.start_date?
|
62
|
+
notification.end_date =
|
63
|
+
notification.end_date.strftime('%Y-%m-%d %H:%M') if notification.end_date?
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def notification_params
|
69
|
+
params.require(:notification).permit!
|
70
|
+
end
|
71
|
+
|
72
|
+
def auth_user
|
73
|
+
redirect_to login_url unless spree_current_user.present?
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# get Notifications
|
2
|
+
Spree::BaseHelper.class_eval do
|
3
|
+
def get_notification
|
4
|
+
notifications = []
|
5
|
+
session['show_notification'] = true if session['show_notification'].nil?
|
6
|
+
if session['show_notification']
|
7
|
+
session['show_notification'] = true
|
8
|
+
current_time = Time.zone.now.getutc
|
9
|
+
notifications =
|
10
|
+
Spree::Notification.where('start_date <= :start_date_cond AND
|
11
|
+
end_date >= :end_date_cond',
|
12
|
+
{start_date_cond: current_time, end_date_cond: current_time})
|
13
|
+
end
|
14
|
+
notifications
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Spree
|
2
|
+
# Notification class
|
3
|
+
class Notification < ActiveRecord::Base
|
4
|
+
validates_presence_of :notification
|
5
|
+
validate :end_date_greater_than_start_date
|
6
|
+
|
7
|
+
def end_date_greater_than_start_date
|
8
|
+
if start_date.blank?
|
9
|
+
errors.add(:start_date, 'is required')
|
10
|
+
elsif end_date.blank?
|
11
|
+
errors.add(:end_date, 'is required')
|
12
|
+
elsif end_date < start_date
|
13
|
+
errors.add(:end_date, 'should be greater than start date')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @spree_notification } %>
|
2
|
+
<div class="field">
|
3
|
+
<%= f.fields_for :notification do %>
|
4
|
+
<div class='label-div'><%= f.label :notification %></div>
|
5
|
+
<div class='input-div'>
|
6
|
+
<%= f.text_area :notification, :rows => "4", :class => 'input-width' %>
|
7
|
+
</div>
|
8
|
+
<% end %>
|
9
|
+
</div>
|
10
|
+
<div class="field">
|
11
|
+
<%= f.fields_for :start_date do %>
|
12
|
+
<div class='label-div'><%= f.label :start_date %></div>
|
13
|
+
<div class='input-div'>
|
14
|
+
<%= f.text_field :start_date, :id => "start_date", :class => 'input-width'%>
|
15
|
+
</div>
|
16
|
+
<% end %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.fields_for :end_date do %>
|
20
|
+
<div class='label-div'><%= f.label :end_date %></div>
|
21
|
+
<div class='input-div'>
|
22
|
+
<%= f.text_field :end_date, :id => "end_date", :class => 'input-width'%>
|
23
|
+
</div>
|
24
|
+
<% end %>
|
25
|
+
</div>
|
26
|
+
<div class="field">
|
27
|
+
<%= f.submit :id => "notification_btn" %>
|
28
|
+
</div>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%= render :partial => 'spree/admin/shared/configuration_menu' %>
|
2
|
+
<div id='notification-content-header'>
|
3
|
+
<h4>Edit Notification</h4>
|
4
|
+
<div class='page-actions table-cell.toolbar'>
|
5
|
+
<%= link_to "Add Notification", "/admin/notifications/new", :class => "button icon-plus create_btn", :id => "notification_add_btn"%>
|
6
|
+
</div>
|
7
|
+
</div>
|
8
|
+
<div class='container'>
|
9
|
+
<%= form_for @spree_notification , :url => "/admin/notifications/#{@spree_notification.id}", :html => {:method => :put} do |f| %>
|
10
|
+
<%= render partial: 'form', :locals => {f: f}%>
|
11
|
+
<% end %>
|
12
|
+
</div>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<%= render :partial => 'spree/admin/shared/configuration_menu' %>
|
2
|
+
<h3> Notifications </h3>
|
3
|
+
<div class='page-actions table-cell.toolbar'>
|
4
|
+
<%= link_to "Add Notification", "/admin/notifications/new", :class => "button icon-plus create_btn", :id => "notification_add_btn"%>
|
5
|
+
</div>
|
6
|
+
<table class='index' id = 'index_table'>
|
7
|
+
<thead>
|
8
|
+
<tr>
|
9
|
+
<th> Notification Message </th>
|
10
|
+
<th> Start Date </th>
|
11
|
+
<th> End Date </th>
|
12
|
+
</tr>
|
13
|
+
</thead>
|
14
|
+
<tbody>
|
15
|
+
<% @notifications.each do |notification| %>
|
16
|
+
<tr>
|
17
|
+
<td><%= notification.notification %></td>
|
18
|
+
<td><%= notification.start_date.strftime('%Y-%m-%d %H:%M') %></td>
|
19
|
+
<td><%= notification.end_date.strftime('%Y-%m-%d %H:%M') %></td>
|
20
|
+
<td class='actions'>
|
21
|
+
<%= link_to '', edit_admin_notification_path(notification), :class => "icon_link with-tip icon-edit no-text", :title => 'edit'%>
|
22
|
+
<%= link_to '', "/admin/notifications/#{notification.id}", method: :delete, data: { confirm: 'Are you sure?' }, :class => "delete-resource icon_link with-tip icon-trash no-text", :title => 'delete'%>
|
23
|
+
</td>
|
24
|
+
</tr>
|
25
|
+
<% end %>
|
26
|
+
</tbody>
|
27
|
+
</table>
|
28
|
+
<%= paginate @notifications %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<%= render :partial => 'spree/admin/shared/configuration_menu' %>
|
2
|
+
<div id='notification-content-header'>
|
3
|
+
<h4>New Notification</h4>
|
4
|
+
</div>
|
5
|
+
<div class='container'>
|
6
|
+
<%= form_for @spree_notification , :url => "/admin/notifications", :html => {:method => :post} do |f| %>
|
7
|
+
<%= render partial: 'form', :locals => {f: f}%>
|
8
|
+
<% end %>
|
9
|
+
</div>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<% if get_notification.present? %>
|
2
|
+
<ul id='notification_list'>
|
3
|
+
<img id="close_img" src="/assets/close.png">
|
4
|
+
<% get_notification.each do |notification|%>
|
5
|
+
<div id="notification_contents">
|
6
|
+
<div id="notification_div">
|
7
|
+
<li>
|
8
|
+
<%= notification.notification%>
|
9
|
+
</li>
|
10
|
+
</div>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
</ul>
|
14
|
+
<% end %>
|
data/bin/rails
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
2
|
+
|
3
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
4
|
+
ENGINE_PATH = File.expand_path('../../lib/spree_custom_notifications/engine', __FILE__)
|
5
|
+
|
6
|
+
require 'rails/all'
|
7
|
+
require 'rails/engine/commands'
|
data/config/routes.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module SpreeCustomNotifications
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
class_option :auto_run_migrations, :type => :boolean, :default => false
|
6
|
+
|
7
|
+
def add_javascripts
|
8
|
+
append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_custom_notifications\n"
|
9
|
+
append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_custom_notifications\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_stylesheets
|
13
|
+
inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_custom_notifications\n", :before => /\*\//, :verbose => true
|
14
|
+
inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_custom_notifications\n", :before => /\*\//, :verbose => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_migrations
|
18
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_custom_notifications'
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_migrations
|
22
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
|
23
|
+
if run_migrations
|
24
|
+
run 'bundle exec rake db:migrate'
|
25
|
+
else
|
26
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SpreeCustomNotifications
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_custom_notifications'
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
8
|
+
|
9
|
+
# use rspec for tests
|
10
|
+
config.generators do |g|
|
11
|
+
g.test_framework :rspec
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.activate
|
15
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
16
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
config.to_prepare &method(:activate).to_proc
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
|
3
|
+
#
|
4
|
+
# Example adding this to your spec_helper will load these Factories for use:
|
5
|
+
# require 'spree_custom_notifications/factories'
|
6
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Run Coverage report
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter 'spec/dummy'
|
5
|
+
add_group 'Controllers', 'app/controllers'
|
6
|
+
add_group 'Helpers', 'app/helpers'
|
7
|
+
add_group 'Mailers', 'app/mailers'
|
8
|
+
add_group 'Models', 'app/models'
|
9
|
+
add_group 'Views', 'app/views'
|
10
|
+
add_group 'Libraries', 'lib'
|
11
|
+
end
|
12
|
+
|
13
|
+
# Configure Rails Environment
|
14
|
+
ENV['RAILS_ENV'] = 'test'
|
15
|
+
|
16
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
17
|
+
|
18
|
+
require 'rspec/rails'
|
19
|
+
require 'database_cleaner'
|
20
|
+
require 'ffaker'
|
21
|
+
|
22
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
23
|
+
# in spec/support/ and its subdirectories.
|
24
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
25
|
+
|
26
|
+
# Requires factories defined in spree_core
|
27
|
+
require 'spree/testing_support/factories'
|
28
|
+
require 'spree/testing_support/controller_requests'
|
29
|
+
require 'spree/testing_support/authorization_helpers'
|
30
|
+
require 'spree/testing_support/url_helpers'
|
31
|
+
|
32
|
+
# Requires factories defined in lib/spree_custom_notifications/factories.rb
|
33
|
+
require 'spree_custom_notifications/factories'
|
34
|
+
|
35
|
+
RSpec.configure do |config|
|
36
|
+
config.include FactoryGirl::Syntax::Methods
|
37
|
+
|
38
|
+
# == URL Helpers
|
39
|
+
#
|
40
|
+
# Allows access to Spree's routes in specs:
|
41
|
+
#
|
42
|
+
# visit spree.admin_path
|
43
|
+
# current_path.should eql(spree.products_path)
|
44
|
+
config.include Spree::TestingSupport::UrlHelpers
|
45
|
+
|
46
|
+
# == Mock Framework
|
47
|
+
#
|
48
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
49
|
+
#
|
50
|
+
# config.mock_with :mocha
|
51
|
+
# config.mock_with :flexmock
|
52
|
+
# config.mock_with :rr
|
53
|
+
config.mock_with :rspec
|
54
|
+
config.color = true
|
55
|
+
|
56
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
57
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
58
|
+
|
59
|
+
# Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
|
60
|
+
# to cleanup after each test instead. Without transactional fixtures set to false the records created
|
61
|
+
# to setup a test will be unavailable to the browser, which runs under a seperate server instance.
|
62
|
+
config.use_transactional_fixtures = false
|
63
|
+
|
64
|
+
# Ensure Suite is set to use transactions for speed.
|
65
|
+
config.before :suite do
|
66
|
+
DatabaseCleaner.strategy = :transaction
|
67
|
+
DatabaseCleaner.clean_with :truncation
|
68
|
+
end
|
69
|
+
|
70
|
+
# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
|
71
|
+
config.before :each do
|
72
|
+
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
|
73
|
+
DatabaseCleaner.start
|
74
|
+
end
|
75
|
+
|
76
|
+
# After each spec clean the database.
|
77
|
+
config.after :each do
|
78
|
+
DatabaseCleaner.clean
|
79
|
+
end
|
80
|
+
|
81
|
+
config.fail_fast = ENV['FAIL_FAST'] || false
|
82
|
+
end
|