From 5e3e482311d1cff0fad79670fd1c78a16956ebe2 Mon Sep 17 00:00:00 2001 From: hitman Date: Mon, 6 Mar 2017 22:04:09 +0530 Subject: [PATCH 1/6] add toastr for notifications --- Gemfile | 2 ++ Gemfile.lock | 5 +++- app/assets/javascripts/application.js | 31 ++++++++++++++++++++----- app/assets/stylesheets/application.css | 1 + app/helpers/application_helper.rb | 11 +++++++++ app/views/layouts/application.html.haml | 1 + 6 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index b1c5764f..4e1a85d9 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,8 @@ gem 'responders', '~> 2.0' # as the database for Active Record gem 'mysql2' +# for toastr notifications +gem 'toastr-rails' # for observing records gem 'rails-observers' diff --git a/Gemfile.lock b/Gemfile.lock index e73c9b5e..539589bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -497,6 +497,8 @@ GEM timecop (0.7.1) timers (1.1.0) tins (1.6.0) + toastr-rails (1.0.3) + railties (>= 3.1.0) transitions (0.1.12) ttfunk (1.1.1) turbolinks (2.5.3) @@ -628,6 +630,7 @@ DEPENDENCIES stripe stripe-ruby-mock timecop + toastr-rails transitions turbolinks uglifier (>= 1.3.0) @@ -637,4 +640,4 @@ DEPENDENCIES whenever BUNDLED WITH - 1.14.3 + 1.14.5 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 01cb83ee..0d341239 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -46,13 +46,32 @@ //= require unobtrusive_flash //= require unobtrusive_flash_bootstrap //= require countable +//= require toastr $(document).ready(function() { - $('a[disabled=disabled]').click(function(event){ - return false; - }); + $('a[disabled=disabled]').click(function(event){ + return false; + }); - $('body').smoothScroll({ - delegateSelector: 'a.smoothscroll' - }); + $('body').smoothScroll({ + delegateSelector: 'a.smoothscroll' + }); + + toastr.options = { + "closeButton": false, + "debug": false, + "newestOnTop": false, + "progressBar": true, + "positionClass": "toast-top-right", + "preventDuplicates": false, + "onclick": null, + "showDuration": "300", + "hideDuration": "1000", + "timeOut": "5000", + "extendedTimeOut": "1000", + "showEasing": "swing", + "hideEasing": "linear", + "showMethod": "fadeIn", + "hideMethod": "fadeOut" + } }); diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index ac01136f..da7d6276 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -15,4 +15,5 @@ *= require leaflet *= require bootstrap3-switch *= require osem-payments + *= require toastr */ diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 20c8eadb..d1136d3e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -148,6 +148,17 @@ module ApplicationHelper end end + def toast_bootstrap_flash + flash_messages = [] + flash.each do |type, message| + type = 'success' if type == 'notice' + type = 'error' if type == 'alert' + text = "" + flash_messages << text.html_safe if message + end + flash_messages.join("\n").html_safe + end + def label_for(event_state) result = '' case event_state diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 893198fa..c2c29072 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -22,6 +22,7 @@ = yield(:head) %body = render 'layouts/navigation' + = toast_bootstrap_flash -# Admin area - if controller.class.name.split("::").first=="Admin" = render 'layouts/admin' From 40b99cc2d6646c52bf4748078d5308d9ed89e84b Mon Sep 17 00:00:00 2001 From: hitman Date: Tue, 7 Mar 2017 02:45:29 +0530 Subject: [PATCH 2/6] add toastr cdn and modified toast function --- Gemfile | 2 -- Gemfile.lock | 3 --- app/assets/javascripts/application.js | 19 ------------------- app/assets/stylesheets/application.css | 1 - app/helpers/application_helper.rb | 21 ++++++++++++++++++++- app/views/layouts/application.html.haml | 3 ++- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/Gemfile b/Gemfile index 4e1a85d9..b1c5764f 100644 --- a/Gemfile +++ b/Gemfile @@ -20,8 +20,6 @@ gem 'responders', '~> 2.0' # as the database for Active Record gem 'mysql2' -# for toastr notifications -gem 'toastr-rails' # for observing records gem 'rails-observers' diff --git a/Gemfile.lock b/Gemfile.lock index 539589bd..b972eb0b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -497,8 +497,6 @@ GEM timecop (0.7.1) timers (1.1.0) tins (1.6.0) - toastr-rails (1.0.3) - railties (>= 3.1.0) transitions (0.1.12) ttfunk (1.1.1) turbolinks (2.5.3) @@ -630,7 +628,6 @@ DEPENDENCIES stripe stripe-ruby-mock timecop - toastr-rails transitions turbolinks uglifier (>= 1.3.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 0d341239..a3d05673 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -46,7 +46,6 @@ //= require unobtrusive_flash //= require unobtrusive_flash_bootstrap //= require countable -//= require toastr $(document).ready(function() { $('a[disabled=disabled]').click(function(event){ @@ -56,22 +55,4 @@ $(document).ready(function() { $('body').smoothScroll({ delegateSelector: 'a.smoothscroll' }); - - toastr.options = { - "closeButton": false, - "debug": false, - "newestOnTop": false, - "progressBar": true, - "positionClass": "toast-top-right", - "preventDuplicates": false, - "onclick": null, - "showDuration": "300", - "hideDuration": "1000", - "timeOut": "5000", - "extendedTimeOut": "1000", - "showEasing": "swing", - "hideEasing": "linear", - "showMethod": "fadeIn", - "hideMethod": "fadeOut" - } }); diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index da7d6276..ac01136f 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -15,5 +15,4 @@ *= require leaflet *= require bootstrap3-switch *= require osem-payments - *= require toastr */ diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d1136d3e..bd0935c7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -153,7 +153,26 @@ module ApplicationHelper flash.each do |type, message| type = 'success' if type == 'notice' type = 'error' if type == 'alert' - text = "" + text = "" flash_messages << text.html_safe if message end flash_messages.join("\n").html_safe diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index c2c29072..d043583b 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -6,6 +6,7 @@ %meta{:content => "", :name => "description"} %meta{:content => "", :name => "author"} = stylesheet_link_tag "application", :media => "all" + = stylesheet_link_tag "https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" = javascript_include_tag "application" = csrf_meta_tags @@ -18,7 +19,7 @@ }; = content_for(:script_head) = javascript_include_tag "//cdn.transifex.com/live.js" - + = javascript_include_tag "https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js" = yield(:head) %body = render 'layouts/navigation' From db1eedf51b234c9b8b4d153798ab0df5a7cff913 Mon Sep 17 00:00:00 2001 From: hitman Date: Tue, 7 Mar 2017 15:10:31 +0530 Subject: [PATCH 3/6] shift to toastr_rails and bundler version 1.14.3 --- Gemfile | 1 + Gemfile.lock | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index b1c5764f..3b7e7f7a 100644 --- a/Gemfile +++ b/Gemfile @@ -48,6 +48,7 @@ gem 'omniauth-github' # as authorization framework gem 'cancancan' +gem 'toastr_rails' # for roles gem 'rolify' diff --git a/Gemfile.lock b/Gemfile.lock index b972eb0b..36babd90 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -497,6 +497,7 @@ GEM timecop (0.7.1) timers (1.1.0) tins (1.6.0) + toastr_rails (2.1.3) transitions (0.1.12) ttfunk (1.1.1) turbolinks (2.5.3) @@ -628,6 +629,7 @@ DEPENDENCIES stripe stripe-ruby-mock timecop + toastr_rails transitions turbolinks uglifier (>= 1.3.0) @@ -637,4 +639,4 @@ DEPENDENCIES whenever BUNDLED WITH - 1.14.5 + 1.14.3 From 33b9a2b93bb3e6e4f72cb15c14b74332e5e6bfea Mon Sep 17 00:00:00 2001 From: hitman Date: Tue, 7 Mar 2017 15:13:38 +0530 Subject: [PATCH 4/6] use render for toast and remove helper function --- app/assets/javascripts/application.js | 18 +++++++++++++++ app/assets/stylesheets/application.css | 1 + app/helpers/application_helper.rb | 30 ------------------------- app/views/layouts/application.html.haml | 4 +--- 4 files changed, 20 insertions(+), 33 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index a3d05673..79f6b5fc 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -11,6 +11,7 @@ // GO AFTER THE REQUIRES BELOW. // //= require jquery +//= require toastr_rails //= require jquery_ujs //= require jquery.mobile.custom.min //= require jquery.ui.draggable @@ -52,6 +53,23 @@ $(document).ready(function() { return false; }); + toastr.options = { + 'closeButton': false, + 'debug': false, + 'newestOnTop': false, + 'progressBar': true, + 'positionClass': 'toast-bottom-center', + 'preventDuplicates': true, + 'onclick': null, + 'showDuration': '300', + 'hideDuration': '100', + 'timeOut': '5000', + 'extendedTimeOut': '1000', + 'showEasing': 'swing', + 'hideEasing': 'linear', + 'showMethod': 'fadeIn', + 'hideMethod': 'fadeOut' + }; $('body').smoothScroll({ delegateSelector: 'a.smoothscroll' }); diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index ac01136f..93c4d2ae 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -15,4 +15,5 @@ *= require leaflet *= require bootstrap3-switch *= require osem-payments + *= require toastr_rails */ diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bd0935c7..20c8eadb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -148,36 +148,6 @@ module ApplicationHelper end end - def toast_bootstrap_flash - flash_messages = [] - flash.each do |type, message| - type = 'success' if type == 'notice' - type = 'error' if type == 'alert' - text = "" - flash_messages << text.html_safe if message - end - flash_messages.join("\n").html_safe - end - def label_for(event_state) result = '' case event_state diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index d043583b..bb9f04fd 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -6,7 +6,6 @@ %meta{:content => "", :name => "description"} %meta{:content => "", :name => "author"} = stylesheet_link_tag "application", :media => "all" - = stylesheet_link_tag "https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" = javascript_include_tag "application" = csrf_meta_tags @@ -19,11 +18,10 @@ }; = content_for(:script_head) = javascript_include_tag "//cdn.transifex.com/live.js" - = javascript_include_tag "https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js" = yield(:head) %body = render 'layouts/navigation' - = toast_bootstrap_flash + = render 'toastr_rails/flash' -# Admin area - if controller.class.name.split("::").first=="Admin" = render 'layouts/admin' From 37fb336af7dfed4a3ca32fd1b7cb5e780f3f80dc Mon Sep 17 00:00:00 2001 From: hitman Date: Tue, 7 Mar 2017 16:06:22 +0530 Subject: [PATCH 5/6] remove bootstrap_class_for helper function and related usage --- app/helpers/application_helper.rb | 15 --------------- app/views/layouts/_messages.html.haml | 10 +--------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 20c8eadb..43f6fef0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -133,21 +133,6 @@ module ApplicationHelper result end - def bootstrap_class_for(flash_type) - case flash_type - when 'success' - 'alert-success' - when 'error' - 'alert-danger' - when 'alert' - 'alert-warning' - when 'notice' - 'alert-info' - else - 'alert-warning' - end - end - def label_for(event_state) result = '' case event_state diff --git a/app/views/layouts/_messages.html.haml b/app/views/layouts/_messages.html.haml index 406087d7..c953d224 100644 --- a/app/views/layouts/_messages.html.haml +++ b/app/views/layouts/_messages.html.haml @@ -6,12 +6,4 @@ %h2 JavaScript is not enabled %p - OSEM requires JavaScript to be enabled to function. Please turn on JavaScript in your browser's settings and reload the page to continue. -- flash.each do |type, message| - .row - .col-md-12 - %div{:class=>"alert alert-dismissable #{bootstrap_class_for(type)}", :id=>"flash"} - .button.close{"data-dismiss" => "alert", "aria-hidden"=>"true"} - × - %p - = message \ No newline at end of file + OSEM requires JavaScript to be enabled to function. Please turn on JavaScript in your browser's settings and reload the page to continue. \ No newline at end of file From 3427233057bc5c253f264d41a1d4f1d3e2c84c1b Mon Sep 17 00:00:00 2001 From: hitman Date: Tue, 7 Mar 2017 16:14:50 +0530 Subject: [PATCH 6/6] change toast position --- app/assets/javascripts/application.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 79f6b5fc..397b1dc5 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -58,7 +58,7 @@ $(document).ready(function() { 'debug': false, 'newestOnTop': false, 'progressBar': true, - 'positionClass': 'toast-bottom-center', + 'positionClass': 'toast-top-center', 'preventDuplicates': true, 'onclick': null, 'showDuration': '300',