From 60e11e2ca28bde89ad6de1126fd742e926c8b997 Mon Sep 17 00:00:00 2001 From: Diego Araújo + João M. M. da Silva + Pedro Leal Date: Thu, 30 Aug 2012 15:56:40 -0300 Subject: [PATCH] [Mezuro] Fixed color picker. --- plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb | 2 -- plugins/mezuro/lib/kalibro/range.rb | 8 ++++++++ plugins/mezuro/public/javascripts/validations.js | 18 +++--------------- plugins/mezuro/test/unit/kalibro/range_test.rb | 12 ++++++++++++ plugins/mezuro/views/mezuro_plugin_myprofile/_range_form.html.erb | 11 +++++------ 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb b/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb index c5caa21..736b01c 100644 --- a/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb +++ b/plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb @@ -113,7 +113,6 @@ class MezuroPluginMyprofileController < ProfileController @configuration_content = profile.articles.find(params[:id]) @metric_name = params[:metric_name] @range = Kalibro::Range.new - @range_color = "#000000" end def edit_range @@ -122,7 +121,6 @@ class MezuroPluginMyprofileController < ProfileController @beginning_id = params[:beginning_id] metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name) @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" } - @range_color = "#" + @range.color.to_s.gsub(/^ff/, "") end def create_range diff --git a/plugins/mezuro/lib/kalibro/range.rb b/plugins/mezuro/lib/kalibro/range.rb index 806713f..c96f707 100644 --- a/plugins/mezuro/lib/kalibro/range.rb +++ b/plugins/mezuro/lib/kalibro/range.rb @@ -34,4 +34,12 @@ class Kalibro::Range < Kalibro::Model @grade = value.to_f end + def mezuro_color + @color.nil? ? "#e4ca2d" : @color.gsub(/^ff/, "#") + end + + def color=(new_color) + @color = new_color.gsub(/^#/, "ff") + end + end diff --git a/plugins/mezuro/public/javascripts/validations.js b/plugins/mezuro/public/javascripts/validations.js index cc126d1..df80021 100644 --- a/plugins/mezuro/public/javascripts/validations.js +++ b/plugins/mezuro/public/javascripts/validations.js @@ -39,14 +39,6 @@ function IsNotInfinite(value){ return true; } -function IsNotHexadecimal(value){ - if(value.match(/^[0-9a-fA-F]{1,8}$/)) - { - return false; - } - return true; -} - function validate_new_range_configuration(event){ var label = jQuery("#range_label").val(); var beginning = jQuery("#range_beginning").val(); @@ -56,24 +48,20 @@ function validate_new_range_configuration(event){ if (is_null(label) || is_null(beginning) || is_null(end) || is_null(color) || is_null(grade)) { - alert("Please fill all fields marked with (*)"); + alert("Please fill all fields marked with (*)."); return false; } if ( (IsNotNumeric(beginning) && IsNotInfinite(beginning)) || (IsNotNumeric(end) && IsNotInfinite(end)) || IsNotNumeric(grade)) { - alert("Beginning, End and Grade must be numeric values"); + alert("Beginning, End and Grade must be numeric values."); return false; } if (parseInt(beginning) > parseInt(end)) { if(IsNotInfinite(beginning) && IsNotInfinite(end)){ - alert("End must be greater than Beginning"); + alert("End must be greater than Beginning."); return false; } } - if (IsNotHexadecimal(color)){ - alert("Color must be an hexadecimal value"); - return false; - } return true; } diff --git a/plugins/mezuro/test/unit/kalibro/range_test.rb b/plugins/mezuro/test/unit/kalibro/range_test.rb index 4ec7d10..cb63680 100644 --- a/plugins/mezuro/test/unit/kalibro/range_test.rb +++ b/plugins/mezuro/test/unit/kalibro/range_test.rb @@ -17,4 +17,16 @@ class RangeTest < ActiveSupport::TestCase assert_equal @hash, @range.to_hash end + should 'create a default color for new range' do + assert_equal "#e4ca2d", Kalibro::Range.new.mezuro_color + end + + should "convert color from 'ff' to '#'" do + assert_equal "#ff0000", @range.mezuro_color + end + + should "convert color from '#' to 'ff' when creating a new range" do + assert_equal "ffff0000", Kalibro::Range.new({:color => '#ff0000'}).color + end + end diff --git a/plugins/mezuro/views/mezuro_plugin_myprofile/_range_form.html.erb b/plugins/mezuro/views/mezuro_plugin_myprofile/_range_form.html.erb index 4e9769a..3ab3a72 100644 --- a/plugins/mezuro/views/mezuro_plugin_myprofile/_range_form.html.erb +++ b/plugins/mezuro/views/mezuro_plugin_myprofile/_range_form.html.erb @@ -38,7 +38,7 @@ <%= f.label :color, "(*) Color:" %> - <%= f.text_field(:color, :id => "range_color", :value => @range_color) %> + <%= f.text_field(:color, :id => "range_color", :value => @range.mezuro_color) %> @@ -53,10 +53,9 @@ <%= f.submit "Save Range" %> -- libgit2 0.21.2