Commit d3cf2f059ff820adbb5bb45bc7051d2f7fdbf854

Authored by João M. M. da Silva + Alessandro Palmeira + Diego Araújo
Committed by Paulo Meireles
1 parent 3307129f

[Mezuro] refactored and fixed range views and javascript.

plugins/mezuro/controllers/myprofile/mezuro_plugin_range_controller.rb
... ... @@ -3,17 +3,18 @@ class MezuroPluginRangeController < MezuroPluginMyprofileController
3 3 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
4 4  
5 5 def new_range
6   - @configuration_content = profile.articles.find(params[:id])
  6 + @content_id = params[:id]
7 7 @metric_name = params[:metric_name]
8 8 @range = Kalibro::Range.new
9 9 @range_color = "#000000"
10 10 end
11 11  
12 12 def edit_range
13   - @configuration_content = profile.articles.find(params[:id])
14   - @metric_name = params[:metric_name]
15 13 @beginning_id = params[:beginning_id]
16   - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name)
  14 + @content_id = params[:id]
  15 + configuration_name = profile.articles.find(@content_id).name
  16 + @metric_name = params[:metric_name]
  17 + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_name, @metric_name)
17 18 @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" }
18 19 @range_color = "#" + @range.color.to_s.gsub(/^ff/, "")
19 20 end
... ...
plugins/mezuro/public/javascripts/validations.js
... ... @@ -45,7 +45,7 @@ function validate_new_range_configuration(event){
45 45 var end = jQuery("#range_end").val();
46 46 var color = jQuery("#range_color").val();
47 47 var grade = jQuery("#range_grade").val();
48   -
  48 +
49 49 if (is_null(label) || is_null(beginning) || is_null(end) || is_null(color) || is_null(grade))
50 50 {
51 51 alert("Please fill all fields marked with (*).");
... ...
plugins/mezuro/test/functional/myprofile/mezuro_plugin_range_controller_test.rb
... ... @@ -30,7 +30,7 @@ class MezuroPluginRangeControllerTest < ActionController::TestCase
30 30  
31 31 should 'test new range' do
32 32 get :new_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name
33   - assert_equal @content, assigns(:configuration_content)
  33 + assert_equal @content.id.to_s, assigns(:content_id)
34 34 assert_equal @metric.name, assigns(:metric_name)
35 35 assert_response 200
36 36 end
... ... @@ -40,7 +40,7 @@ class MezuroPluginRangeControllerTest < ActionController::TestCase
40 40 :configuration_name => @content.name,
41 41 :metric_name => @metric.name}).returns({:metric_configuration => @metric_configuration_hash})
42 42 get :edit_range, :profile => @profile.identifier, :id => @content.id, :metric_name => @metric.name, :beginning_id => @range.beginning
43   - assert_equal @content, assigns(:configuration_content)
  43 + assert_equal @content.id.to_s, assigns(:content_id)
44 44 assert_equal @metric.name, assigns(:metric_name)
45 45 assert_equal @range.beginning, assigns(:beginning_id)
46 46 assert_equal @range.end, assigns(:range).end
... ...
plugins/mezuro/views/mezuro_plugin_range/_edit_range.html.erb
1 1 <% remote_form_for :range, :url => {:action =>"update_range", :controller => "mezuro_plugin_range"}, :method => :get do |f| %>
2   - <%= hidden_field_tag :beginning_id, beginning_id %>
3   - <%= render :partial => "range_form", :locals => {:f => f, :metric_name => metric_name, :id => id, :beginning_id => beginning_id, :range => range } %>
  2 + <%= hidden_field_tag :beginning_id, @beginning_id %>
  3 + <%= render :partial => "range_form", :locals => {:f => f} %>
4 4 <% end %>
... ...
plugins/mezuro/views/mezuro_plugin_range/_new_range.html.erb
1 1 <% remote_form_for :range, :url => {:action =>"create_range", :controller => "mezuro_plugin_range"}, :method => :get do |f| %>
2   - <%= render :partial => "range_form", :locals => {:f => f, :metric_name => metric_name, :id => id } %>
  2 + <%= render :partial => "range_form", :locals => {:f => f} %>
3 3 <% end %>
... ...
plugins/mezuro/views/mezuro_plugin_range/_range_form.html.erb
1   -<%= hidden_field_tag :id, id %>
2   -<%= hidden_field_tag :metric_name, metric_name %>
  1 +<%= hidden_field_tag :id, @content_id %>
  2 +<%= hidden_field_tag :metric_name, @metric_name %>
  3 +
3 4 <table>
4 5 <tr>
5 6 <td>
... ... @@ -14,7 +15,7 @@
14 15 <%= f.label :beginning, "(*) Beginning:" %>
15 16 </td>
16 17 <td>
17   - <%= f.text_field :beginning, :value => @range.beginning , :id => 'beginning' %>&nbsp;<%= link_to('-&#8734', 'javascript:void(0)', :onClick => "jQuery( '#beginning' ).val('-INF');") %>
  18 + <%= f.text_field :beginning, :id => "range_beginning" %>&nbsp;<%= link_to('-&#8734', 'javascript:void(0)', :onClick => "jQuery( '#range_beginning' ).val('-INF');") %>
18 19 </td>
19 20 </tr>
20 21 <tr>
... ... @@ -22,7 +23,7 @@
22 23 <%= f.label :end, "(*) End:" %>
23 24 </td>
24 25 <td>
25   - <%= f.text_field :end, :value => @range.end, :id => "end" %>&nbsp;<%= link_to('+&#8734', 'javascript:void(0)', :onClick => "jQuery( '#end' ).val('+INF');") %>
  26 + <%= f.text_field(:end, :id => "range_end") %>&nbsp;<%= link_to('+&#8734', 'javascript:void(0)', :onClick => "jQuery( '#range_end' ).val('+INF');") %>
26 27 </td>
27 28 </tr>
28 29 <tr>
... ...
plugins/mezuro/views/mezuro_plugin_range/create_range.rjs
1   -page.alert @message
2 1 page.visual_effect :toggle_slide, "range_form"
3 2 page.insert_html :bottom, "ranges", :partial => "range", :locals => {:range => @range}
... ...
plugins/mezuro/views/mezuro_plugin_range/edit_range.rjs
1   -page.replace_html 'range_form', :partial => "edit_range", :locals => {:metric_name => @metric_name, :id => @configuration_content.id, :beginning_id => @beginning_id, :range => @range }
  1 +page.replace_html 'range_form', :partial => "edit_range", :locals => {:range => @range}
2 2 page.visual_effect :slide_down, "range_form"
3 3  
... ...
plugins/mezuro/views/mezuro_plugin_range/new_range.rjs
1   -page.replace_html 'range_form', :partial => "new_range", :locals => {:metric_name => @metric_name, :id => @configuration_content.id }
  1 +page.replace_html 'range_form', :partial => "new_range"
2 2 page.visual_effect :slide_down, "range_form"
3 3  
... ...