Skip to content

Commit

Permalink
Allow Jirafe analytics data to be edited after registration
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Nov 29, 2012
1 parent a74f177 commit a29eb28
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 9 deletions.
18 changes: 16 additions & 2 deletions dash/app/controllers/spree/admin/analytics_controller.rb
Original file line number Diff line number Diff line change
@@ -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 => '',
Expand All @@ -15,6 +15,7 @@ def sign_up
end

def register
redirect_if_registered and return
@store = params[:store]
@store[:url] = format_url(@store[:url])

Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions dash/app/overrides/analytics_header.rb
Original file line number Diff line number Diff line change
@@ -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')
26 changes: 26 additions & 0 deletions dash/app/views/spree/admin/analytics/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h2><%= t(:header, :scope => "spree.dash.jirafe") %></h2>

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

<%= form_tag admin_analytics_path, :method => :put do %>
<div class="field">
<%= label_tag 'app_id', t(:app_id, :scope => "spree.dash.jirafe") %><br>
<%= text_field_tag 'app_id', Spree::Dash::Config.app_id %>
</div>
<div class="field">
<%= label_tag 'app_token', t(:app_token, :scope => "spree.dash.jirafe") %><br>
<%= text_field_tag 'app_token', Spree::Dash::Config.app_token, :size => 40 %>
</div>
<div class="field">
<%= label_tag 'site_id', t(:site_id, :scope => "spree.dash.jirafe") %><br>
<%= text_field_tag 'site_id', Spree::Dash::Config.site_id %>
</div>
<div class="field">
<%= label_tag 'token', t(:token, :scope => "spree.dash.jirafe") %><br>
<%= text_field_tag 'token', Spree::Dash::Config.token, :size => 40 %>
</div>
<div class="form-buttons" data-hook="buttons">
<%= submit_tag "Update" %>
</div>
<% end %>

13 changes: 12 additions & 1 deletion dash/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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!
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.
3 changes: 3 additions & 0 deletions dash/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 20 additions & 1 deletion dash/spec/requests/admin/analytics_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions dash/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down

0 comments on commit a29eb28

Please sign in to comment.