Commit d3db6fc31ef9748faa05e9ae4136230770dfb977
1 parent
abab689d
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
site_tour: added configuration for environments at plugin settings
Showing
7 changed files
with
114 additions
and
17 deletions
Show diff stats
plugins/site_tour/controllers/site_tour_plugin_admin_controller.rb
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +require 'csv' | |
2 | + | |
3 | +class SiteTourPluginAdminController < AdminController | |
4 | + | |
5 | + no_design_blocks | |
6 | + | |
7 | + def index | |
8 | + settings = params[:settings] | |
9 | + settings ||= {} | |
10 | + | |
11 | + @settings = Noosfero::Plugin::Settings.new(environment, SiteTourPlugin, settings) | |
12 | + @settings.actions_csv = convert_to_csv(@settings.actions) | |
13 | + | |
14 | + if request.post? | |
15 | + @settings.actions = convert_from_csv(settings[:actions_csv]) | |
16 | + @settings.settings.delete(:actions_csv) | |
17 | + | |
18 | + @settings.save! | |
19 | + session[:notice] = 'Settings succefully saved.' | |
20 | + redirect_to :action => 'index' | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + protected | |
25 | + | |
26 | + def convert_to_csv(actions) | |
27 | + CSV.generate do |csv| | |
28 | + (@settings.actions||[]).each { |action| csv << action.values } | |
29 | + end | |
30 | + end | |
31 | + | |
32 | + def convert_from_csv(actions_csv) | |
33 | + CSV.parse(actions_csv).map do |action| | |
34 | + {:language => action[0], :group_name => action[1], :selector => action[2], :description => action[3]} | |
35 | + end | |
36 | + end | |
37 | + | |
38 | +end | ... | ... |
plugins/site_tour/lib/site_tour_plugin.rb
... | ... | @@ -25,11 +25,11 @@ class SiteTourPlugin < Noosfero::Plugin |
25 | 25 | def body_ending |
26 | 26 | proc do |
27 | 27 | tour_file = "/plugins/site_tour/tour/#{language}/tour.js" |
28 | - if File.exists?(Rails.root.join("public#{tour_file}").to_s) | |
29 | - javascript_include_tag(tour_file) | |
30 | - else | |
31 | - "" | |
32 | - end | |
28 | + js_file = File.exists?(Rails.root.join("public#{tour_file}").to_s) ? tour_file : "" | |
29 | + settings = Noosfero::Plugin::Settings.new(environment, SiteTourPlugin) | |
30 | + actions = (settings.actions||[]).select {|action| action[:language] == language} | |
31 | + | |
32 | + render(:file => 'tour_actions', :locals => { :actions => actions, :js_file => js_file}) | |
33 | 33 | end |
34 | 34 | end |
35 | 35 | |
... | ... | @@ -37,4 +37,8 @@ class SiteTourPlugin < Noosfero::Plugin |
37 | 37 | { SiteTourPlugin::TourBlock => {} } |
38 | 38 | end |
39 | 39 | |
40 | + def self.actions_csv_default_setting | |
41 | + 'en,tour_plugin,.site-tour-plugin_tour-block .tour-button,"Click to start tour!"' | |
42 | + end | |
43 | + | |
40 | 44 | end | ... | ... |
plugins/site_tour/test/functional/site_tour_plugin_admin_controller_test.rb
0 → 100644
... | ... | @@ -0,0 +1,36 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class SiteTourPluginAdminControllerTest < ActionController::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @environment = Environment.default | |
7 | + @profile = create_user('profile').person | |
8 | + login_as(@profile.identifier) | |
9 | + end | |
10 | + | |
11 | + attr_reader :environment | |
12 | + | |
13 | + should 'parse csv and save actions array in plugin settings' do | |
14 | + actions_csv = "en,tour_plugin,.tour-button,Click" | |
15 | + post :index, :settings => {"actions_csv" => actions_csv} | |
16 | + @settings = Noosfero::Plugin::Settings.new(environment.reload, SiteTourPlugin) | |
17 | + assert_equal [{:language => 'en', :group_name => 'tour_plugin', :selector => '.tour-button', :description => 'Click'}], @settings.actions | |
18 | + end | |
19 | + | |
20 | + should 'do not store actions_csv' do | |
21 | + actions_csv = "en,tour_plugin,.tour-button,Click" | |
22 | + post :index, :settings => {"actions_csv" => actions_csv} | |
23 | + @settings = Noosfero::Plugin::Settings.new(environment.reload, SiteTourPlugin) | |
24 | + assert_equal nil, @settings.settings[:actions_csv] | |
25 | + end | |
26 | + | |
27 | + should 'convert actions array to csv to enable user edition' do | |
28 | + @settings = Noosfero::Plugin::Settings.new(environment.reload, SiteTourPlugin) | |
29 | + @settings.actions = [{:language => 'en', :group_name => 'tour_plugin', :selector => '.tour-button', :description => 'Click'}] | |
30 | + @settings.save! | |
31 | + | |
32 | + get :index | |
33 | + assert_tag :tag => 'textarea', :content => "\nen,tour_plugin,.tour-button,Click\n" | |
34 | + end | |
35 | + | |
36 | +end | ... | ... |
plugins/site_tour/test/unit/site_tour_plugin_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | -class SiteTourPluginTest < ActiveSupport::TestCase | |
3 | +class SiteTourPluginTest < ActionView::TestCase | |
4 | 4 | |
5 | 5 | def setup |
6 | 6 | @plugin = SiteTourPlugin.new |
... | ... | @@ -26,15 +26,16 @@ class SiteTourPluginTest < ActiveSupport::TestCase |
26 | 26 | file = '/plugins/site_tour/tour/pt/tour.js' |
27 | 27 | expects(:language).returns('pt') |
28 | 28 | File.expects(:exists?).with(Rails.root.join("public#{file}").to_s).returns(true) |
29 | - expects(:javascript_include_tag).with(file) | |
30 | - instance_exec(&plugin.body_ending) | |
29 | + expects(:environment).returns(Environment.default) | |
30 | + assert_tag_in_string instance_exec(&plugin.body_ending), :tag => 'script' | |
31 | 31 | end |
32 | 32 | |
33 | - should 'not include javascript file do not exists' do | |
33 | + should 'not include javascript file that not exists' do | |
34 | 34 | file = '/plugins/site_tour/tour/pt/tour.js' |
35 | 35 | expects(:language).returns('pt') |
36 | 36 | File.expects(:exists?).with(Rails.root.join("public#{file}").to_s).returns(false) |
37 | - assert_equal "", instance_exec(&plugin.body_ending) | |
37 | + expects(:environment).returns(Environment.default) | |
38 | + assert_no_tag_in_string instance_exec(&plugin.body_ending), :tag => "script" | |
38 | 39 | end |
39 | 40 | |
40 | 41 | end | ... | ... |
plugins/site_tour/views/blocks/tour.html.erb
... | ... | @@ -7,11 +7,5 @@ |
7 | 7 | <% edit_mode = controller.send(:boxes_editor?) && controller.send(:uses_design_blocks?) %> |
8 | 8 | |
9 | 9 | <% unless edit_mode %> |
10 | - <script> | |
11 | - jQuery( document ).ready(function( $ ) { | |
12 | - <% block.actions.each_with_index do |action, index| %> | |
13 | - <%= "siteTourPlugin.add('#{j action[:group_name]}','#{j action[:selector]}', '#{j action[:description]}', #{index + 1});" %> | |
14 | - <% end %> | |
15 | - }); | |
16 | - </script> | |
10 | + <%= render :file => 'tour_actions', :locals => {:actions => block.actions} %> | |
17 | 11 | <% end %> | ... | ... |
plugins/site_tour/views/site_tour_plugin_admin/index.html.erb
0 → 100644
... | ... | @@ -0,0 +1,12 @@ |
1 | +<h1><%= _('Site Tour Settings')%></h1> | |
2 | + | |
3 | +<%= form_for(:settings) do |f| %> | |
4 | + | |
5 | + <%= labelled_form_field _('Tooltips (CSV format: language, group name, selector, description)'), f.text_area(:actions_csv, :style => 'width: 100%', :class => 'actions-csv') %> | |
6 | + | |
7 | + <% button_bar do %> | |
8 | + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> | |
9 | + <% end %> | |
10 | + | |
11 | +<% end %> | |
12 | + | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +<% js_file = defined?(:js_file) ? js_file : nil %> | |
2 | +<%= javascript_include_tag(js_file) if js_file.present? %> | |
3 | + | |
4 | +<% if actions.present? %> | |
5 | +<script> | |
6 | + jQuery( document ).ready(function( $ ) { | |
7 | + <% actions.each_with_index do |action, index| %> | |
8 | + <%= "siteTourPlugin.add('#{j action[:group_name]}','#{j action[:selector]}', '#{j action[:description]}', #{index + 1});" %> | |
9 | + <% end %> | |
10 | + }); | |
11 | +</script> | |
12 | +<% end %> | ... | ... |