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