Commit 60e11e2ca28bde89ad6de1126fd742e926c8b997
Committed by
Diego Camarinha
1 parent
aca22dd2
Exists in
master
and in
29 other branches
[Mezuro] Fixed color picker.
Showing
5 changed files
with
28 additions
and
23 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
@@ -113,7 +113,6 @@ class MezuroPluginMyprofileController < ProfileController | @@ -113,7 +113,6 @@ class MezuroPluginMyprofileController < ProfileController | ||
113 | @configuration_content = profile.articles.find(params[:id]) | 113 | @configuration_content = profile.articles.find(params[:id]) |
114 | @metric_name = params[:metric_name] | 114 | @metric_name = params[:metric_name] |
115 | @range = Kalibro::Range.new | 115 | @range = Kalibro::Range.new |
116 | - @range_color = "#000000" | ||
117 | end | 116 | end |
118 | 117 | ||
119 | def edit_range | 118 | def edit_range |
@@ -122,7 +121,6 @@ class MezuroPluginMyprofileController < ProfileController | @@ -122,7 +121,6 @@ class MezuroPluginMyprofileController < ProfileController | ||
122 | @beginning_id = params[:beginning_id] | 121 | @beginning_id = params[:beginning_id] |
123 | metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name) | 122 | metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name) |
124 | @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" } | 123 | @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" } |
125 | - @range_color = "#" + @range.color.to_s.gsub(/^ff/, "") | ||
126 | end | 124 | end |
127 | 125 | ||
128 | def create_range | 126 | def create_range |
plugins/mezuro/lib/kalibro/range.rb
@@ -34,4 +34,12 @@ class Kalibro::Range < Kalibro::Model | @@ -34,4 +34,12 @@ class Kalibro::Range < Kalibro::Model | ||
34 | @grade = value.to_f | 34 | @grade = value.to_f |
35 | end | 35 | end |
36 | 36 | ||
37 | + def mezuro_color | ||
38 | + @color.nil? ? "#e4ca2d" : @color.gsub(/^ff/, "#") | ||
39 | + end | ||
40 | + | ||
41 | + def color=(new_color) | ||
42 | + @color = new_color.gsub(/^#/, "ff") | ||
43 | + end | ||
44 | + | ||
37 | end | 45 | end |
plugins/mezuro/public/javascripts/validations.js
@@ -39,14 +39,6 @@ function IsNotInfinite(value){ | @@ -39,14 +39,6 @@ function IsNotInfinite(value){ | ||
39 | return true; | 39 | return true; |
40 | } | 40 | } |
41 | 41 | ||
42 | -function IsNotHexadecimal(value){ | ||
43 | - if(value.match(/^[0-9a-fA-F]{1,8}$/)) | ||
44 | - { | ||
45 | - return false; | ||
46 | - } | ||
47 | - return true; | ||
48 | -} | ||
49 | - | ||
50 | function validate_new_range_configuration(event){ | 42 | function validate_new_range_configuration(event){ |
51 | var label = jQuery("#range_label").val(); | 43 | var label = jQuery("#range_label").val(); |
52 | var beginning = jQuery("#range_beginning").val(); | 44 | var beginning = jQuery("#range_beginning").val(); |
@@ -56,24 +48,20 @@ function validate_new_range_configuration(event){ | @@ -56,24 +48,20 @@ function validate_new_range_configuration(event){ | ||
56 | 48 | ||
57 | 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)) |
58 | { | 50 | { |
59 | - alert("Please fill all fields marked with (*)"); | 51 | + alert("Please fill all fields marked with (*)."); |
60 | return false; | 52 | return false; |
61 | } | 53 | } |
62 | if ( (IsNotNumeric(beginning) && IsNotInfinite(beginning)) || (IsNotNumeric(end) && IsNotInfinite(end)) || IsNotNumeric(grade)) | 54 | if ( (IsNotNumeric(beginning) && IsNotInfinite(beginning)) || (IsNotNumeric(end) && IsNotInfinite(end)) || IsNotNumeric(grade)) |
63 | { | 55 | { |
64 | - alert("Beginning, End and Grade must be numeric values"); | 56 | + alert("Beginning, End and Grade must be numeric values."); |
65 | return false; | 57 | return false; |
66 | } | 58 | } |
67 | if (parseInt(beginning) > parseInt(end)) | 59 | if (parseInt(beginning) > parseInt(end)) |
68 | { | 60 | { |
69 | if(IsNotInfinite(beginning) && IsNotInfinite(end)){ | 61 | if(IsNotInfinite(beginning) && IsNotInfinite(end)){ |
70 | - alert("End must be greater than Beginning"); | 62 | + alert("End must be greater than Beginning."); |
71 | return false; | 63 | return false; |
72 | } | 64 | } |
73 | } | 65 | } |
74 | - if (IsNotHexadecimal(color)){ | ||
75 | - alert("Color must be an hexadecimal value"); | ||
76 | - return false; | ||
77 | - } | ||
78 | return true; | 66 | return true; |
79 | } | 67 | } |
plugins/mezuro/test/unit/kalibro/range_test.rb
@@ -17,4 +17,16 @@ class RangeTest < ActiveSupport::TestCase | @@ -17,4 +17,16 @@ class RangeTest < ActiveSupport::TestCase | ||
17 | assert_equal @hash, @range.to_hash | 17 | assert_equal @hash, @range.to_hash |
18 | end | 18 | end |
19 | 19 | ||
20 | + should 'create a default color for new range' do | ||
21 | + assert_equal "#e4ca2d", Kalibro::Range.new.mezuro_color | ||
22 | + end | ||
23 | + | ||
24 | + should "convert color from 'ff' to '#'" do | ||
25 | + assert_equal "#ff0000", @range.mezuro_color | ||
26 | + end | ||
27 | + | ||
28 | + should "convert color from '#' to 'ff' when creating a new range" do | ||
29 | + assert_equal "ffff0000", Kalibro::Range.new({:color => '#ff0000'}).color | ||
30 | + end | ||
31 | + | ||
20 | end | 32 | end |
plugins/mezuro/views/mezuro_plugin_myprofile/_range_form.html.erb
@@ -38,7 +38,7 @@ | @@ -38,7 +38,7 @@ | ||
38 | <%= f.label :color, "(*) Color:" %> | 38 | <%= f.label :color, "(*) Color:" %> |
39 | </td> | 39 | </td> |
40 | <td> | 40 | <td> |
41 | - <%= f.text_field(:color, :id => "range_color", :value => @range_color) %> | 41 | + <%= f.text_field(:color, :id => "range_color", :value => @range.mezuro_color) %> |
42 | </td> | 42 | </td> |
43 | </tr> | 43 | </tr> |
44 | <tr> | 44 | <tr> |
@@ -53,10 +53,9 @@ | @@ -53,10 +53,9 @@ | ||
53 | <%= f.submit "Save Range" %> | 53 | <%= f.submit "Save Range" %> |
54 | 54 | ||
55 | <script>jQuery(document).ready(function($) { | 55 | <script>jQuery(document).ready(function($) { |
56 | - $('#range_color').colorPicker({ | ||
57 | - onColorChange : function(id, newValue) { | ||
58 | - newValue = newValue.replace(/#/gi, "ff"); | ||
59 | - jQuery('#range_color').val(newValue); | ||
60 | - } | 56 | + $('#range_color').colorPicker({ |
57 | + onColorChange : function(id, newValue) { | ||
58 | + jQuery('#range_color').val(newValue); | ||
59 | + } | ||
61 | }); | 60 | }); |
62 | });</script> | 61 | });</script> |