From be644bdcc3dd16f124e248802e4176e4ecae2dab Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 6 Jun 2014 16:59:47 +1000 Subject: [PATCH] Revert "Reworking flash messages hooray" This reverts commit c9d0091cd91b4ae7c90b3a48ad17c2ea0ee8922f. --- .../javascripts/darkswarm/directives/flash.js.coffee | 8 +++----- .../javascripts/darkswarm/services/flash.js.coffee | 9 +++++++++ .../javascripts/darkswarm/services/map.js.coffee | 4 ++++ .../javascripts/darkswarm/services/order.js.coffee | 6 +++--- .../darkswarm/services/rails_flash_loader.js.coffee | 7 ------- app/assets/javascripts/templates/map_modal.html.haml | 3 +-- app/controllers/application_controller.rb | 2 +- app/controllers/checkout_controller.rb | 2 +- app/controllers/user_passwords_controller.rb | 2 +- app/controllers/user_registrations_controller.rb | 2 +- app/views/json/_flash.rabl | 2 -- app/views/layouts/darkswarm.html.haml | 2 +- spec/controllers/base_controller_spec.rb | 2 +- spec/features/consumer/shopping/checkout_spec.rb | 11 ----------- 14 files changed, 26 insertions(+), 36 deletions(-) create mode 100644 app/assets/javascripts/darkswarm/services/flash.js.coffee delete mode 100644 app/assets/javascripts/darkswarm/services/rails_flash_loader.js.coffee delete mode 100644 app/views/json/_flash.rabl diff --git a/app/assets/javascripts/darkswarm/directives/flash.js.coffee b/app/assets/javascripts/darkswarm/directives/flash.js.coffee index a302a2a891..454c3304bd 100644 --- a/app/assets/javascripts/darkswarm/directives/flash.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/flash.js.coffee @@ -1,11 +1,10 @@ -Darkswarm.directive "ofnFlash", (flash, $timeout, RailsFlashLoader)-> - # Mappings between flash types (left) and Foundation classes +Darkswarm.directive "ofnFlash", (flash, $timeout)-> typePairings = - info: "info" + info: "standard" error: "alert" success: "success" scope: {} - restrict: 'E' + restrict: 'AE' templateUrl: "flash.html" controller: ($scope)-> $scope.closeAlert = (index)-> @@ -22,4 +21,3 @@ Darkswarm.directive "ofnFlash", (flash, $timeout, RailsFlashLoader)-> $scope.flashes.shift() flash.subscribe(show) - RailsFlashLoader.initFlash() diff --git a/app/assets/javascripts/darkswarm/services/flash.js.coffee b/app/assets/javascripts/darkswarm/services/flash.js.coffee new file mode 100644 index 0000000000..2be131da1d --- /dev/null +++ b/app/assets/javascripts/darkswarm/services/flash.js.coffee @@ -0,0 +1,9 @@ +Darkswarm.factory 'Flash', (flash)-> + new class Flash + loadFlash: (rails_flash)-> + for type, message of rails_flash + switch type + when "notice" + flash.info = message + else + flash[type] = message diff --git a/app/assets/javascripts/darkswarm/services/map.js.coffee b/app/assets/javascripts/darkswarm/services/map.js.coffee index eb1a195490..a59631a741 100644 --- a/app/assets/javascripts/darkswarm/services/map.js.coffee +++ b/app/assets/javascripts/darkswarm/services/map.js.coffee @@ -6,7 +6,11 @@ Darkswarm.factory "OfnMap", (enterprisesForMap, MapModal)-> # Adding methods to each enterprise extend: (enterprise)-> new class MapMarker + icon: "/test.opng" constructor: -> @[k] = v for k, v of enterprise + reveal: => + + console.log @ MapModal.open @ diff --git a/app/assets/javascripts/darkswarm/services/order.js.coffee b/app/assets/javascripts/darkswarm/services/order.js.coffee index a90cec9e34..73a27012e5 100644 --- a/app/assets/javascripts/darkswarm/services/order.js.coffee +++ b/app/assets/javascripts/darkswarm/services/order.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.factory 'Order', ($resource, order, $http, Navigation, storage, CurrentHub, RailsFlashLoader)-> +Darkswarm.factory 'Order', ($resource, order, $http, flash, Navigation, storage, CurrentHub)-> new class Order errors: {} secrets: {} @@ -24,8 +24,8 @@ Darkswarm.factory 'Order', ($resource, order, $http, Navigation, storage, Curren Navigation.go data.path .error (response, status)=> @errors = response.errors - RailsFlashLoader.loadFlash(response.flash) - + flash.error = response.flash?.error + flash.success = response.flash?.notice # Rails wants our Spree::Address data to be provided with _attributes preprocess: -> diff --git a/app/assets/javascripts/darkswarm/services/rails_flash_loader.js.coffee b/app/assets/javascripts/darkswarm/services/rails_flash_loader.js.coffee deleted file mode 100644 index 9398b5f5cc..0000000000 --- a/app/assets/javascripts/darkswarm/services/rails_flash_loader.js.coffee +++ /dev/null @@ -1,7 +0,0 @@ -Darkswarm.factory 'RailsFlashLoader', (flash, railsFlash)-> - new class RailsFlashLoader - initFlash: -> - @loadFlash railsFlash - loadFlash: (rails_flash)-> - for type, message of rails_flash - flash[type] = message diff --git a/app/assets/javascripts/templates/map_modal.html.haml b/app/assets/javascripts/templates/map_modal.html.haml index 54c834253a..4e2067f7d0 100644 --- a/app/assets/javascripts/templates/map_modal.html.haml +++ b/app/assets/javascripts/templates/map_modal.html.haml @@ -2,8 +2,7 @@ .small-12.columns.producer-hero %h3.producer-name %i.ofn-i_036-producers - {{ enterprise.name }} - {{ enterprise.id }} + {{ producer.name }} %img.producer-hero-img{"ng-src" => "{{enterprise.promo_image}}"} .row diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 07e1029991..a19f92c918 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -37,7 +37,7 @@ class ApplicationController < ActionController::Base session[:expired_order_cycle_id] = current_order_cycle.id current_order.empty! current_order.set_order_cycle! nil - flash[:info] = "The order cycle you've selected has just closed. Please try again!" + flash[:notice] = "The order cycle you've selected has just closed. Please try again!" redirect_to root_url end end diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 998f0ceeea..b0cdeebba2 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -35,7 +35,7 @@ class CheckoutController < Spree::CheckoutController end end if @order.state == "complete" || @order.completed? - flash[:success] = t(:order_processed_successfully) + flash.notice = t(:order_processed_successfully) respond_to do |format| format.html do respond_with(@order, :location => order_path(@order)) diff --git a/app/controllers/user_passwords_controller.rb b/app/controllers/user_passwords_controller.rb index ed3be07f35..c46d294457 100644 --- a/app/controllers/user_passwords_controller.rb +++ b/app/controllers/user_passwords_controller.rb @@ -5,7 +5,7 @@ class UserPasswordsController < Spree::UserPasswordsController self.resource = resource_class.send_reset_password_instructions(params[resource_name]) if resource.errors.empty? - set_flash_message(:success, :send_instructions) if is_navigational_format? + set_flash_message(:notice, :send_instructions) if is_navigational_format? respond_with resource, :location => spree.login_path else respond_to do |format| diff --git a/app/controllers/user_registrations_controller.rb b/app/controllers/user_registrations_controller.rb index a6a0074553..3d106bbc96 100644 --- a/app/controllers/user_registrations_controller.rb +++ b/app/controllers/user_registrations_controller.rb @@ -4,7 +4,7 @@ class UserRegistrationsController < Spree::UserRegistrationsController def create @user = build_resource(params[:spree_user]) if resource.save - set_flash_message(:success, :signed_up) + set_flash_message(:notice, :signed_up) sign_in(:spree_user, @user) session[:spree_user_signup] = true associate_user diff --git a/app/views/json/_flash.rabl b/app/views/json/_flash.rabl deleted file mode 100644 index dce07f849a..0000000000 --- a/app/views/json/_flash.rabl +++ /dev/null @@ -1,2 +0,0 @@ -object OpenStruct.new(flash) -attributes :info, :success, :error diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index 1b1d97f85d..d34e63fa53 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -21,12 +21,12 @@ = inject_json "currentHub", "current_hub" = inject_json "currentOrder", "current_order" = inject_json "user", "current_user" - = inject_json "railsFlash", "flash" .off-canvas-wrap{offcanvas: true} .inner-wrap = render partial: "shared/menu/menu" + = display_flash_messages %ofn-flash %section{ role: "main" } diff --git a/spec/controllers/base_controller_spec.rb b/spec/controllers/base_controller_spec.rb index 8269c9374d..140259555a 100644 --- a/spec/controllers/base_controller_spec.rb +++ b/spec/controllers/base_controller_spec.rb @@ -16,6 +16,6 @@ describe BaseController do oc.stub(:closed?).and_return true get :index response.should redirect_to root_url - flash[:info].should == "The order cycle you've selected has just closed. Please try again!" + flash[:notice].should == "The order cycle you've selected has just closed. Please try again!" end end diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index f0c2590b1c..fddda4e199 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -146,17 +146,6 @@ feature "As a consumer I want to check out my cart", js: true do place_order page.should have_content "Your order has been processed successfully" end - - it "shows the payment processing failed message when submitted with an invalid credit card" do - toggle_payment - fill_in 'Card Number', with: "9999999988887777" - select 'February', from: 'secrets.card_month' - select (Date.today.year+1).to_s, from: 'secrets.card_year' - fill_in 'Security Code', with: '123' - - place_order - page.should have_content "Payment could not be processed, please check the details you entered" - end end end end