From a29eb288c64a2ab397e043c63332f050c5d41af4 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Thu, 29 Nov 2012 13:15:41 +1100 Subject: [PATCH] Allow Jirafe analytics data to be edited after registration Fixes #2238 --- .../spree/admin/analytics_controller.rb | 18 +++++++++++-- dash/app/overrides/analytics_header.rb | 10 +++---- .../views/spree/admin/analytics/edit.html.erb | 26 +++++++++++++++++++ dash/config/locales/en.yml | 13 +++++++++- dash/config/routes.rb | 3 +++ dash/spec/requests/admin/analytics_spec.rb | 21 ++++++++++++++- dash/spec/spec_helper.rb | 1 + 7 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 dash/app/views/spree/admin/analytics/edit.html.erb diff --git a/dash/app/controllers/spree/admin/analytics_controller.rb b/dash/app/controllers/spree/admin/analytics_controller.rb index f1ea148ff55..27f8f091102 100644 --- a/dash/app/controllers/spree/admin/analytics_controller.rb +++ b/dash/app/controllers/spree/admin/analytics_controller.rb @@ -1,8 +1,8 @@ module Spree class Admin::AnalyticsController < Admin::BaseController - before_filter :redirect_if_registered def sign_up + redirect_if_registered and return @store = { :first_name => '', :last_name => '', @@ -15,6 +15,7 @@ def sign_up end def register + redirect_if_registered and return @store = params[:store] @store[:url] = format_url(@store[:url]) @@ -42,12 +43,25 @@ def register end end + def edit + + end + + def update + Spree::Dash::Config.app_id = params[:app_id] + Spree::Dash::Config.app_token = params[:app_token] + Spree::Dash::Config.site_id = params[:site_id] + Spree::Dash::Config.token = params[:token] + flash[:success] = t(:jirafe_settings_updated, :scope => "spree.dash") + redirect_to admin_analytics_path + end + private def redirect_if_registered if Spree::Dash::Config.configured? flash[:success] = t(:already_signed_up_for_analytics) - redirect_to admin_path + redirect_to admin_path and return true end end diff --git a/dash/app/overrides/analytics_header.rb b/dash/app/overrides/analytics_header.rb index af580f245c6..6dd7a4d9ffd 100644 --- a/dash/app/overrides/analytics_header.rb +++ b/dash/app/overrides/analytics_header.rb @@ -1,5 +1,5 @@ -Deface::Override.new(:virtual_path => Spree::Config[:layout], - :name => "add_analytics_header", - :insert_bottom => "head", - :partial => "spree/analytics/header", - :original => '6f23c8af6e863d0499835c00b3f2763cb98e1d75') +Deface::Override.new(:virtual_path => "spree/admin/shared/_configuration_menu", + :name => "add_dashboard_sidebar_link", + :insert_bottom => ".sidebar", + :text => "<%= configurations_sidebar_menu_item t(:jirafe), admin_analytics_path %>", + :original => 'a74f177275dc303c9cd5994b2e24e027434c3cbb') diff --git a/dash/app/views/spree/admin/analytics/edit.html.erb b/dash/app/views/spree/admin/analytics/edit.html.erb new file mode 100644 index 00000000000..631427add1b --- /dev/null +++ b/dash/app/views/spree/admin/analytics/edit.html.erb @@ -0,0 +1,26 @@ +

<%= t(:header, :scope => "spree.dash.jirafe") %>

+ +

<%= t(:explanation, :scope => "spree.dash.jirafe") %>

+ +<%= form_tag admin_analytics_path, :method => :put do %> +
+ <%= label_tag 'app_id', t(:app_id, :scope => "spree.dash.jirafe") %>
+ <%= text_field_tag 'app_id', Spree::Dash::Config.app_id %> +
+
+ <%= label_tag 'app_token', t(:app_token, :scope => "spree.dash.jirafe") %>
+ <%= text_field_tag 'app_token', Spree::Dash::Config.app_token, :size => 40 %> +
+
+ <%= label_tag 'site_id', t(:site_id, :scope => "spree.dash.jirafe") %>
+ <%= text_field_tag 'site_id', Spree::Dash::Config.site_id %> +
+
+ <%= label_tag 'token', t(:token, :scope => "spree.dash.jirafe") %>
+ <%= text_field_tag 'token', Spree::Dash::Config.token, :size => 40 %> +
+
+ <%= submit_tag "Update" %> +
+<% end %> + diff --git a/dash/config/locales/en.yml b/dash/config/locales/en.yml index 745258cf2d4..704b5b8b413 100644 --- a/dash/config/locales/en.yml +++ b/dash/config/locales/en.yml @@ -8,4 +8,15 @@ en: analytics_desc_list_1: Get live sales information as it happens analytics_desc_list_2: Requires only a free Spree account to activate analytics_desc_list_3: Absolutely no code to install - analytics_desc_list_4: It's completely free! \ No newline at end of file + analytics_desc_list_4: It's completely free! + + spree: + dash: + jirafe: + header: Jirafe Analytics Settings + app_id: App ID + app_token: App Token + site_id: Site ID + token: Token + explanation: The fields below may already be populated if you chose to register with Jirafe from the admin dashboard. + jirafe_settings_updated: Jirafe Settings have been updated. diff --git a/dash/config/routes.rb b/dash/config/routes.rb index 21a83850289..0143cfa6d51 100644 --- a/dash/config/routes.rb +++ b/dash/config/routes.rb @@ -3,4 +3,7 @@ get '/admin/analytics/sign_up' => 'admin/analytics#sign_up', :as => :admin_analytics_sign_up post '/admin/analytics/register' => 'admin/analytics#register', :as => :admin_analytics_register + + get '/jirafe' => 'admin/analytics#edit', :as => :admin_analytics + put '/jirafe' => 'admin/analytics#update', :as => :admin_analytics end diff --git a/dash/spec/requests/admin/analytics_spec.rb b/dash/spec/requests/admin/analytics_spec.rb index c25c875483f..81f519f2474 100644 --- a/dash/spec/requests/admin/analytics_spec.rb +++ b/dash/spec/requests/admin/analytics_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper' describe "Analytics Activation" do + stub_authorization! + before(:each) do @user = create(:admin_user) - Spree::Admin::AnalyticsController.any_instance.stub :spree_current_user => @user Spree::Dash::Config.app_id = nil Spree::Dash::Config.app_token = nil @@ -30,4 +31,22 @@ Spree::Dash::Config.site_id.should eq '3' Spree::Dash::Config.token.should eq '4' end + + it "can edit anayltics information" do + visit spree.admin_path + click_link "Configuration" + click_link "Jirafe" + fill_in 'app_id', :with => "1" + fill_in 'app_token', :with => "token" + fill_in 'site_id', :with => "test.com" + fill_in 'token', :with => "other_token" + click_button "Update" + + page.should have_content("Jirafe Settings have been updated.") + + Spree::Dash::Config.app_id.should eq '1' + Spree::Dash::Config.app_token.should eq 'token' + Spree::Dash::Config.site_id.should eq 'test.com' + Spree::Dash::Config.token.should eq 'other_token' + end end diff --git a/dash/spec/spec_helper.rb b/dash/spec/spec_helper.rb index 5667cb90ace..b708cbc5ea7 100644 --- a/dash/spec/spec_helper.rb +++ b/dash/spec/spec_helper.rb @@ -13,6 +13,7 @@ require 'spree/core/testing_support/factories' require 'spree/core/testing_support/controller_requests' +require 'spree/core/testing_support/authorization_helpers' require 'active_record/fixtures' fixtures_dir = File.expand_path('../../../core/db/default', __FILE__)