Commit 0be5d3e8655d19ea7e1359429cdeff48c47cb722

Authored by Daniela Feitosa
2 parents 90e56099 fa1b55b8

Merge commit 'refs/merge-requests/229' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/229
Showing 38 changed files with 1033 additions and 382 deletions   Show diff stats
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
@@ -2,7 +2,15 @@ class MezuroPluginMyprofileController < ProfileController @@ -2,7 +2,15 @@ class MezuroPluginMyprofileController < ProfileController
2 2
3 append_view_path File.join(File.dirname(__FILE__) + '/../views') 3 append_view_path File.join(File.dirname(__FILE__) + '/../views')
4 4
5 - 5 + rescue_from Exception do |exception|
  6 + message = URI.escape(CGI.escape(exception.message),'.')
  7 + redirect_to_error_page message
  8 + end
  9 +
  10 + def error_page
  11 + @message = params[:message]
  12 + end
  13 +
6 def choose_base_tool 14 def choose_base_tool
7 @configuration_content = profile.articles.find(params[:id]) 15 @configuration_content = profile.articles.find(params[:id])
8 @base_tools = Kalibro::BaseTool.all_names 16 @base_tools = Kalibro::BaseTool.all_names
@@ -11,19 +19,23 @@ class MezuroPluginMyprofileController < ProfileController @@ -11,19 +19,23 @@ class MezuroPluginMyprofileController < ProfileController
11 def choose_metric 19 def choose_metric
12 @configuration_content = profile.articles.find(params[:id]) 20 @configuration_content = profile.articles.find(params[:id])
13 @base_tool = params[:base_tool] 21 @base_tool = params[:base_tool]
14 - @supported_metrics = Kalibro::BaseTool.find_by_name(@base_tool).supported_metrics 22 + base_tool = Kalibro::BaseTool.find_by_name(@base_tool)
  23 + @supported_metrics = base_tool.nil? ? [] : base_tool.supported_metrics
15 end 24 end
16 - 25 +
17 def new_metric_configuration 26 def new_metric_configuration
18 @configuration_content = profile.articles.find(params[:id]) 27 @configuration_content = profile.articles.find(params[:id])
19 @metric = Kalibro::BaseTool.find_by_name(params[:base_tool]).metric params[:metric_name] 28 @metric = Kalibro::BaseTool.find_by_name(params[:base_tool]).metric params[:metric_name]
20 end 29 end
21 - 30 +
22 def new_compound_metric_configuration 31 def new_compound_metric_configuration
23 @configuration_content = profile.articles.find(params[:id]) 32 @configuration_content = profile.articles.find(params[:id])
24 @metric_configurations = @configuration_content.metric_configurations 33 @metric_configurations = @configuration_content.metric_configurations
  34 + if configuration_content_has_errors?
  35 + redirect_to_error_page @configuration_content.errors[:base]
  36 + end
25 end 37 end
26 - 38 +
27 def edit_metric_configuration 39 def edit_metric_configuration
28 @configuration_content = profile.articles.find(params[:id]) 40 @configuration_content = profile.articles.find(params[:id])
29 @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, params[:metric_name]) 41 @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, params[:metric_name])
@@ -36,19 +48,29 @@ class MezuroPluginMyprofileController < ProfileController @@ -36,19 +48,29 @@ class MezuroPluginMyprofileController < ProfileController
36 @metric_configurations = @configuration_content.metric_configurations 48 @metric_configurations = @configuration_content.metric_configurations
37 @metric = @metric_configuration.metric 49 @metric = @metric_configuration.metric
38 end 50 end
39 - 51 +
40 def create_metric_configuration 52 def create_metric_configuration
41 id = params[:id] 53 id = params[:id]
42 metric_name = params[:metric_configuration][:metric][:name] 54 metric_name = params[:metric_configuration][:metric][:name]
43 - (Kalibro::MetricConfiguration.new(params[:metric_configuration])).save  
44 - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}" 55 + metric_configuration = Kalibro::MetricConfiguration.new(params[:metric_configuration])
  56 + metric_configuration.save
  57 + if metric_configuration_has_errors? metric_configuration
  58 + redirect_to_error_page metric_configuration.errors[0].message
  59 + else
  60 + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}"
  61 + end
45 end 62 end
46 - 63 +
47 def create_compound_metric_configuration 64 def create_compound_metric_configuration
48 id = params[:id] 65 id = params[:id]
49 metric_name = params[:metric_configuration][:metric][:name] 66 metric_name = params[:metric_configuration][:metric][:name]
50 - Kalibro::MetricConfiguration.new(params[:metric_configuration]).save  
51 - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}" 67 + metric_configuration = Kalibro::MetricConfiguration.new(params[:metric_configuration])
  68 + metric_configuration.save
  69 + if metric_configuration_has_errors? metric_configuration
  70 + redirect_to_error_page metric_configuration.errors[0].message
  71 + else
  72 + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}"
  73 + end
52 end 74 end
53 75
54 def update_metric_configuration 76 def update_metric_configuration
@@ -56,7 +78,11 @@ class MezuroPluginMyprofileController < ProfileController @@ -56,7 +78,11 @@ class MezuroPluginMyprofileController < ProfileController
56 metric_name = params[:metric_configuration][:metric][:name] 78 metric_name = params[:metric_configuration][:metric][:name]
57 metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) 79 metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name)
58 metric_configuration.update_attributes params[:metric_configuration] 80 metric_configuration.update_attributes params[:metric_configuration]
59 - redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" 81 + if metric_configuration_has_errors? metric_configuration
  82 + redirect_to_error_page metric_configuration.errors[0].message
  83 + else
  84 + redirect_to "/#{profile.identifier}/#{@configuration_content.slug}"
  85 + end
60 end 86 end
61 87
62 def update_compound_metric_configuration 88 def update_compound_metric_configuration
@@ -64,7 +90,11 @@ class MezuroPluginMyprofileController < ProfileController @@ -64,7 +90,11 @@ class MezuroPluginMyprofileController < ProfileController
64 metric_name = params[:metric_configuration][:metric][:name] 90 metric_name = params[:metric_configuration][:metric][:name]
65 metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) 91 metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name)
66 metric_configuration.update_attributes params[:metric_configuration] 92 metric_configuration.update_attributes params[:metric_configuration]
67 - redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" 93 + if metric_configuration_has_errors? metric_configuration
  94 + redirect_to_error_page metric_configuration.errors[0].message
  95 + else
  96 + redirect_to "/#{profile.identifier}/#{@configuration_content.slug}"
  97 + end
68 end 98 end
69 99
70 def remove_metric_configuration 100 def remove_metric_configuration
@@ -72,32 +102,41 @@ class MezuroPluginMyprofileController < ProfileController @@ -72,32 +102,41 @@ class MezuroPluginMyprofileController < ProfileController
72 metric_name = params[:metric_name] 102 metric_name = params[:metric_name]
73 metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) 103 metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name)
74 metric_configuration.destroy 104 metric_configuration.destroy
75 - redirect_to "/#{profile.identifier}/#{configuration_content.slug}" 105 + if metric_configuration_has_errors? metric_configuration
  106 + redirect_to_error_page metric_configuration.errors[0].message
  107 + else
  108 + redirect_to "/#{profile.identifier}/#{configuration_content.slug}"
  109 + end
76 end 110 end
77 - 111 +
78 def new_range 112 def new_range
79 @configuration_content = profile.articles.find(params[:id]) 113 @configuration_content = profile.articles.find(params[:id])
80 @metric_name = params[:metric_name] 114 @metric_name = params[:metric_name]
81 @range = Kalibro::Range.new 115 @range = Kalibro::Range.new
  116 + @range_color = "#000000"
82 end 117 end
83 - 118 +
84 def edit_range 119 def edit_range
85 @configuration_content = profile.articles.find(params[:id]) 120 @configuration_content = profile.articles.find(params[:id])
86 @metric_name = params[:metric_name] 121 @metric_name = params[:metric_name]
87 @beginning_id = params[:beginning_id] 122 @beginning_id = params[:beginning_id]
88 metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name) 123 metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name)
89 @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" } 124 @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" }
  125 + @range_color = "#" + @range.color.to_s.gsub(/^ff/, "")
90 end 126 end
91 127
92 def create_range 128 def create_range
93 @configuration_content = profile.articles.find(params[:id]) 129 @configuration_content = profile.articles.find(params[:id])
94 @range = Kalibro::Range.new params[:range] 130 @range = Kalibro::Range.new params[:range]
95 metric_name = params[:metric_name] 131 metric_name = params[:metric_name]
96 - metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) 132 + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name)
97 metric_configuration.add_range(@range) 133 metric_configuration.add_range(@range)
98 metric_configuration.save 134 metric_configuration.save
  135 + if metric_configuration_has_errors? metric_configuration
  136 + redirect_to_error_page metric_configuration.errors[0].message
  137 + end
99 end 138 end
100 - 139 +
101 def update_range 140 def update_range
102 configuration_content = profile.articles.find(params[:id]) 141 configuration_content = profile.articles.find(params[:id])
103 metric_name = params[:metric_name] 142 metric_name = params[:metric_name]
@@ -106,8 +145,11 @@ class MezuroPluginMyprofileController < ProfileController @@ -106,8 +145,11 @@ class MezuroPluginMyprofileController < ProfileController
106 index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } 145 index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" }
107 metric_configuration.ranges[index] = Kalibro::Range.new params[:range] 146 metric_configuration.ranges[index] = Kalibro::Range.new params[:range]
108 metric_configuration.save 147 metric_configuration.save
  148 + if metric_configuration_has_errors? metric_configuration
  149 + redirect_to_error_page metric_configuration.errors[0].message
  150 + end
109 end 151 end
110 - 152 +
111 def remove_range 153 def remove_range
112 configuration_content = profile.articles.find(params[:id]) 154 configuration_content = profile.articles.find(params[:id])
113 metric_name = params[:metric_name] 155 metric_name = params[:metric_name]
@@ -115,12 +157,31 @@ class MezuroPluginMyprofileController < ProfileController @@ -115,12 +157,31 @@ class MezuroPluginMyprofileController < ProfileController
115 metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) 157 metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name)
116 metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } 158 metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" }
117 metric_configuration.save 159 metric_configuration.save
118 - formatted_metric_name = metric_name.gsub(/\s/, '+')  
119 - if metric_configuration.metric.class == Kalibro::CompoundMetric  
120 - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" 160 + if metric_configuration_has_errors? metric_configuration
  161 + redirect_to_error_page metric_configuration.errors[0].message
121 else 162 else
122 - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" 163 + formatted_metric_name = metric_name.gsub(/\s/, '+')
  164 + if metric_configuration.metric.class == Kalibro::CompoundMetric
  165 + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}"
  166 + else
  167 + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}"
  168 + end
123 end 169 end
124 end 170 end
125 171
  172 + private
  173 +
  174 + def redirect_to_error_page(message)
  175 + message = URI.escape(CGI.escape(message),'.')
  176 + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/error_page?message=#{message}"
  177 + end
  178 +
  179 + def configuration_content_has_errors?
  180 + not @configuration_content.errors[:base].nil?
  181 + end
  182 +
  183 + def metric_configuration_has_errors? metric_configuration
  184 + not metric_configuration.errors.empty?
  185 + end
  186 +
126 end 187 end
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
1 class MezuroPluginProfileController < ProfileController 1 class MezuroPluginProfileController < ProfileController
2 2
3 append_view_path File.join(File.dirname(__FILE__) + '/../views') 3 append_view_path File.join(File.dirname(__FILE__) + '/../views')
4 - 4 +
  5 + def error_page
  6 + @message = params[:message]
  7 + end
  8 +
5 def project_state 9 def project_state
6 @content = profile.articles.find(params[:id]) 10 @content = profile.articles.find(params[:id])
7 project = @content.project 11 project = @content.project
8 - state = project.error.nil? ? project.state : "ERROR"  
9 - render :text => state 12 + if project_content_has_errors?
  13 + redirect_to_error_page(@content.errors[:base])
  14 + else
  15 + state = project.kalibro_error.nil? ? project.state : "ERROR"
  16 + render :text => state
  17 + end
10 end 18 end
11 19
12 def project_error 20 def project_error
13 @content = profile.articles.find(params[:id]) 21 @content = profile.articles.find(params[:id])
14 @project = @content.project 22 @project = @content.project
15 - render :partial => 'content_viewer/project_error' 23 + if project_content_has_errors?
  24 + redirect_to_error_page(@content.errors[:base])
  25 + else
  26 + render :partial => 'content_viewer/project_error'
  27 + end
16 end 28 end
17 29
18 def project_result 30 def project_result
19 @content = profile.articles.find(params[:id]) 31 @content = profile.articles.find(params[:id])
20 date = params[:date] 32 date = params[:date]
21 @project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) 33 @project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date)
22 - render :partial => 'content_viewer/project_result'  
23 - end 34 + if project_content_has_errors?
  35 + redirect_to_error_page(@content.errors[:base])
  36 + else
  37 + render :partial => 'content_viewer/project_result'
  38 + end
  39 + end
24 40
25 def module_result 41 def module_result
26 @content = profile.articles.find(params[:id]) 42 @content = profile.articles.find(params[:id])
27 @module_result = @content.module_result(params) 43 @module_result = @content.module_result(params)
28 - render :partial => 'content_viewer/module_result' 44 + @module = @module_result.module
  45 + @module_label = "#{@module.name} (#{@module.granularity})"
  46 + if project_content_has_errors?
  47 + redirect_to_error_page(@content.errors[:base])
  48 + else
  49 + render :partial => 'content_viewer/module_result'
  50 + end
29 end 51 end
30 52
31 def project_tree 53 def project_tree
32 @content = profile.articles.find(params[:id]) 54 @content = profile.articles.find(params[:id])
33 date = params[:date] 55 date = params[:date]
34 project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) 56 project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date)
35 - @project_name = @content.project.name  
36 - @source_tree = project_result.node_of(params[:module_name])  
37 - render :partial =>'content_viewer/source_tree' 57 + @project_name = @content.project.name if not @content.project.nil?
  58 + if project_content_has_errors?
  59 + redirect_to_error_page(@content.errors[:base])
  60 + else
  61 + @source_tree = project_result.node(params[:module_name])
  62 + render :partial =>'content_viewer/source_tree'
  63 + end
38 end 64 end
39 65
40 def module_metrics_history 66 def module_metrics_history
41 metric_name = params[:metric_name] 67 metric_name = params[:metric_name]
42 @content = profile.articles.find(params[:id]) 68 @content = profile.articles.find(params[:id])
43 module_history = @content.result_history(params[:module_name]) 69 module_history = @content.result_history(params[:module_name])
44 - @score_history = filtering_metric_history(metric_name, module_history)  
45 - render :partial => 'content_viewer/score_history' 70 + if project_content_has_errors?
  71 + redirect_to_error_page(@content.errors[:base])
  72 + else
  73 + @score_history = filtering_metric_history(metric_name, module_history)
  74 + render :partial => 'content_viewer/score_history'
  75 + end
46 end 76 end
47 77
48 def module_grade_history 78 def module_grade_history
49 @content = profile.articles.find(params[:id]) 79 @content = profile.articles.find(params[:id])
50 modules_results = @content.result_history(params[:module_name]) 80 modules_results = @content.result_history(params[:module_name])
51 - @score_history = modules_results.collect { |module_result| module_result.grade }  
52 - render :partial => 'content_viewer/score_history' 81 + if project_content_has_errors?
  82 + redirect_to_error_page(@content.errors[:base])
  83 + else
  84 + @score_history = modules_results.map do |module_result|
  85 + [module_result.grade, format_date_to_simple_form(module_result.date)]
  86 + end
  87 + render :partial => 'content_viewer/score_history'
  88 + end
53 end 89 end
54 - 90 +
55 private 91 private
56 - 92 +
57 def filtering_metric_history(metric_name, module_history) 93 def filtering_metric_history(metric_name, module_history)
58 metrics_history = module_history.map do |module_result| 94 metrics_history = module_history.map do |module_result|
59 - module_result.metric_results 95 + [module_result.metric_results, format_date_to_simple_form(module_result.date)]
60 end 96 end
61 - metric_history = metrics_history.map do |array_of_metric_result|  
62 - (array_of_metric_result.select do |metric_result| 97 + metric_history = metrics_history.map do |metric_results_with_date|
  98 + [(metric_results_with_date.first.select do |metric_result|
63 metric_result.metric.name.delete("() ") == metric_name 99 metric_result.metric.name.delete("() ") == metric_name
64 - end).first 100 + end).first, metric_results_with_date.last]
65 end 101 end
66 - metric_history.map do |metric_result|  
67 - metric_result.value 102 + metric_history.map do |metric_result_with_date|
  103 + [metric_result_with_date.first.value, metric_result_with_date.last]
68 end 104 end
69 end 105 end
  106 +
  107 + def redirect_to_error_page(message)
  108 + message = URI.escape(CGI.escape(message),'.')
  109 + redirect_to "/profile/#{profile.identifier}/plugins/mezuro/error_page?message=#{message}"
  110 + end
  111 +
  112 + def project_content_has_errors?
  113 + not @content.errors[:base].nil?
  114 + end
  115 +
  116 + def format_date_to_simple_form date
  117 + date.to_s[0..9]
  118 + end
  119 +
70 end 120 end
plugins/mezuro/lib/kalibro/configuration.rb
@@ -7,11 +7,7 @@ class Kalibro::Configuration &lt; Kalibro::Model @@ -7,11 +7,7 @@ class Kalibro::Configuration &lt; Kalibro::Model
7 end 7 end
8 8
9 def metric_configurations 9 def metric_configurations
10 - if @metric_configuration != nil  
11 - @metric_configuration  
12 - else  
13 - []  
14 - end 10 + @metric_configuration.nil? ? [] : @metric_configuration
15 end 11 end
16 12
17 def metric_configurations=(metric_configurations) 13 def metric_configurations=(metric_configurations)
@@ -19,19 +15,11 @@ class Kalibro::Configuration &lt; Kalibro::Model @@ -19,19 +15,11 @@ class Kalibro::Configuration &lt; Kalibro::Model
19 end 15 end
20 16
21 def self.find_by_name(configuration_name) 17 def self.find_by_name(configuration_name)
22 - begin  
23 - new request("Configuration", :get_configuration, {:configuration_name => configuration_name})[:configuration]  
24 - rescue Exception => error  
25 - nil  
26 - end 18 + new request("Configuration", :get_configuration, {:configuration_name => configuration_name})[:configuration]
27 end 19 end
28 20
29 def self.all_names 21 def self.all_names
30 - begin  
31 - request("Configuration", :get_configuration_names)[:configuration_name]  
32 - rescue Exception  
33 - []  
34 - end 22 + request("Configuration", :get_configuration_names)[:configuration_name]
35 end 23 end
36 24
37 def update_attributes(attributes={}) 25 def update_attributes(attributes={})
plugins/mezuro/lib/kalibro/metric_configuration.rb
@@ -49,10 +49,14 @@ class Kalibro::MetricConfiguration &lt; Kalibro::Model @@ -49,10 +49,14 @@ class Kalibro::MetricConfiguration &lt; Kalibro::Model
49 end 49 end
50 50
51 def destroy 51 def destroy
52 - self.class.request("MetricConfiguration", :remove_metric_configuration, { 52 + begin
  53 + self.class.request("MetricConfiguration", :remove_metric_configuration, {
53 :configuration_name => configuration_name, 54 :configuration_name => configuration_name,
54 :metric_name=> metric.name 55 :metric_name=> metric.name
55 }) 56 })
  57 + rescue Exception => exception
  58 + add_error exception
  59 + end
56 end 60 end
57 61
58 def to_hash 62 def to_hash
plugins/mezuro/lib/kalibro/model.rb
1 class Kalibro::Model 1 class Kalibro::Model
2 2
  3 + attr_accessor :errors
  4 +
3 def initialize(attributes={}) 5 def initialize(attributes={})
4 attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } 6 attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) }
  7 + @errors = []
5 end 8 end
6 9
7 def to_hash(options={}) 10 def to_hash(options={})
8 hash = Hash.new 11 hash = Hash.new
9 excepts = !options[:except].nil? ? options[:except] : [] 12 excepts = !options[:except].nil? ? options[:except] : []
  13 + excepts << :errors
10 fields.each do |field| 14 fields.each do |field|
11 if(!excepts.include?(field)) 15 if(!excepts.include?(field))
12 field_value = send(field) 16 field_value = send(field)
@@ -46,15 +50,17 @@ class Kalibro::Model @@ -46,15 +50,17 @@ class Kalibro::Model
46 begin 50 begin
47 self.class.request(save_endpoint, save_action, save_params) 51 self.class.request(save_endpoint, save_action, save_params)
48 true 52 true
49 - rescue Exception => error  
50 - false 53 + rescue Exception => exception
  54 + add_error exception
  55 + false
51 end 56 end
52 end 57 end
53 58
54 def destroy 59 def destroy
55 begin 60 begin
56 self.class.request(destroy_endpoint, destroy_action, destroy_params) 61 self.class.request(destroy_endpoint, destroy_action, destroy_params)
57 - rescue Exception 62 + rescue Exception => exception
  63 + add_error exception
58 end 64 end
59 end 65 end
60 66
@@ -123,4 +129,9 @@ class Kalibro::Model @@ -123,4 +129,9 @@ class Kalibro::Model
123 {"#{class_name.underscore}_name".to_sym => self.name} 129 {"#{class_name.underscore}_name".to_sym => self.name}
124 end 130 end
125 131
  132 + def add_error(exception)
  133 + @errors << exception
  134 + end
  135 +
126 end 136 end
  137 +
plugins/mezuro/lib/kalibro/project.rb
1 class Kalibro::Project < Kalibro::Model 1 class Kalibro::Project < Kalibro::Model
2 2
3 - attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :error 3 + attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :kalibro_error
4 4
5 def self.all_names 5 def self.all_names
6 request("Project", :get_project_names)[:project_name] 6 request("Project", :get_project_names)[:project_name]
@@ -15,23 +15,35 @@ class Kalibro::Project &lt; Kalibro::Model @@ -15,23 +15,35 @@ class Kalibro::Project &lt; Kalibro::Model
15 end 15 end
16 16
17 def error=(value) 17 def error=(value)
18 - @error = Kalibro::Error.to_object value 18 + @kalibro_error = Kalibro::Error.to_object value
19 end 19 end
20 20
21 def process_project(days = '0') 21 def process_project(days = '0')
22 - if days.to_i.zero?  
23 - self.class.request("Kalibro", :process_project, {:project_name => name})  
24 - else  
25 - self.class.request("Kalibro", :process_periodically, {:project_name => name, :period_in_days => days})  
26 - end 22 + begin
  23 + if days.to_i.zero?
  24 + self.class.request("Kalibro", :process_project, {:project_name => name})
  25 + else
  26 + self.class.request("Kalibro", :process_periodically, {:project_name => name, :period_in_days => days})
  27 + end
  28 + rescue Exception => exception
  29 + add_error exception
  30 + end
27 end 31 end
28 32
29 def process_period 33 def process_period
30 - self.class.request("Kalibro", :get_process_period, {:project_name => name})[:period] 34 + begin
  35 + self.class.request("Kalibro", :get_process_period, {:project_name => name})[:period]
  36 + rescue Exception => exception
  37 + add_error exception
  38 + end
31 end 39 end
32 40
33 def cancel_periodic_process 41 def cancel_periodic_process
34 - self.class.request("Kalibro", :cancel_periodic_process, {:project_name => name}) 42 + begin
  43 + self.class.request("Kalibro", :cancel_periodic_process, {:project_name => name})
  44 + rescue Exception => exception
  45 + add_error exception
  46 + end
35 end 47 end
36 48
37 end 49 end
plugins/mezuro/lib/kalibro/project_result.rb
@@ -75,21 +75,17 @@ class Kalibro::ProjectResult &lt; Kalibro::Model @@ -75,21 +75,17 @@ class Kalibro::ProjectResult &lt; Kalibro::Model
75 ('%2d' % amount).sub(/\s/, '0') 75 ('%2d' % amount).sub(/\s/, '0')
76 end 76 end
77 77
78 - def node_of(module_name) 78 + def node(module_name)
79 if module_name.nil? or module_name == project.name 79 if module_name.nil? or module_name == project.name
80 node = source_tree 80 node = source_tree
81 else 81 else
82 - node = get_node(module_name)  
83 - end  
84 - end  
85 -  
86 - def get_node(module_name)  
87 - path = Kalibro::Module.parent_names(module_name)  
88 - parent = @source_tree  
89 - path.each do |node_name|  
90 - parent = get_leaf_from(parent, node_name)  
91 - end  
92 - return parent 82 + path = Kalibro::Module.parent_names(module_name)
  83 + parent = @source_tree
  84 + path.each do |node_name|
  85 + parent = get_leaf_from(parent, node_name)
  86 + end
  87 + parent
  88 + end
93 end 89 end
94 90
95 private 91 private
plugins/mezuro/lib/kalibro/range.rb
@@ -34,4 +34,12 @@ class Kalibro::Range &lt; Kalibro::Model @@ -34,4 +34,12 @@ class Kalibro::Range &lt; 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/lib/mezuro_plugin/configuration_content.rb
@@ -3,8 +3,8 @@ class MezuroPlugin::ConfigurationContent &lt; Article @@ -3,8 +3,8 @@ class MezuroPlugin::ConfigurationContent &lt; Article
3 3
4 settings_items :description, :configuration_to_clone_name 4 settings_items :description, :configuration_to_clone_name
5 5
6 - after_save :send_configuration_to_service  
7 - after_destroy :remove_configuration_from_service 6 + after_save :send_kalibro_configuration_to_service
  7 + after_destroy :remove_kalibro_configuration_from_service
8 8
9 def self.short_description 9 def self.short_description
10 'Kalibro configuration' 10 'Kalibro configuration'
@@ -21,54 +21,60 @@ class MezuroPlugin::ConfigurationContent &lt; Article @@ -21,54 +21,60 @@ class MezuroPlugin::ConfigurationContent &lt; Article
21 end 21 end
22 end 22 end
23 23
24 - def configuration  
25 - @configuration ||= Kalibro::Configuration.find_by_name(self.name)  
26 - if @configuration.nil?  
27 - errors.add_to_base("Kalibro Configuration not found") 24 + def kalibro_configuration
  25 + begin
  26 + @kalibro_configuration ||= Kalibro::Configuration.find_by_name(self.name)
  27 + rescue Exception => exception
  28 + errors.add_to_base(exception.message)
28 end 29 end
29 - @configuration 30 + @kalibro_configuration
30 end 31 end
31 32
32 def metric_configurations 33 def metric_configurations
33 - configuration.metric_configurations 34 + kalibro_configuration.metric_configurations
34 end 35 end
35 36
36 - def configuration_names  
37 - ["None"] + Kalibro::Configuration.all_names.sort 37 + def kalibro_configuration_names
  38 + begin
  39 + ["None"] + Kalibro::Configuration.all_names.sort
  40 + rescue Exception => exception
  41 + errors.add_to_base(exception.message)
  42 + ["None"]
  43 + end
38 end 44 end
39 45
40 private 46 private
41 47
42 def validate_kalibro_configuration_name 48 def validate_kalibro_configuration_name
43 - existing = configuration_names.map { |a| a.downcase} 49 + existing = kalibro_configuration_names.map { |a| a.downcase}
44 50
45 if existing.include?(name.downcase) 51 if existing.include?(name.downcase)
46 errors.add_to_base("Configuration name already exists in Kalibro") 52 errors.add_to_base("Configuration name already exists in Kalibro")
47 end 53 end
48 end 54 end
49 55
50 - def send_configuration_to_service  
51 - if editing_configuration?  
52 - configuration.update_attributes({:description => description}) 56 + def send_kalibro_configuration_to_service
  57 + if editing_kalibro_configuration?
  58 + kalibro_configuration.update_attributes({:description => description})
53 else 59 else
54 create_kalibro_configuration 60 create_kalibro_configuration
55 end 61 end
56 end 62 end
57 63
58 - def remove_configuration_from_service  
59 - configuration.destroy 64 + def remove_kalibro_configuration_from_service
  65 + kalibro_configuration.destroy unless kalibro_configuration.nil?
60 end 66 end
61 67
62 def create_kalibro_configuration 68 def create_kalibro_configuration
63 attributes = {:name => name, :description => description} 69 attributes = {:name => name, :description => description}
64 - if cloning_configuration? 70 + if cloning_kalibro_configuration?
65 attributes[:metric_configuration] = configuration_to_clone.metric_configurations_hash 71 attributes[:metric_configuration] = configuration_to_clone.metric_configurations_hash
66 end 72 end
67 Kalibro::Configuration.create attributes 73 Kalibro::Configuration.create attributes
68 end 74 end
69 75
70 - def editing_configuration?  
71 - configuration.present? 76 + def editing_kalibro_configuration?
  77 + kalibro_configuration.present?
72 end 78 end
73 79
74 def configuration_to_clone 80 def configuration_to_clone
@@ -76,10 +82,10 @@ class MezuroPlugin::ConfigurationContent &lt; Article @@ -76,10 +82,10 @@ class MezuroPlugin::ConfigurationContent &lt; Article
76 end 82 end
77 83
78 def find_configuration_to_clone 84 def find_configuration_to_clone
79 - configuration_to_clone_name.nil? ? nil : Kalibro::Configuration.find_by_name(configuration_to_clone_name) 85 + (configuration_to_clone_name == "None") ? nil : Kalibro::Configuration.find_by_name(configuration_to_clone_name)
80 end 86 end
81 87
82 - def cloning_configuration? 88 + def cloning_kalibro_configuration?
83 configuration_to_clone.present? 89 configuration_to_clone.present?
84 end 90 end
85 91
plugins/mezuro/lib/mezuro_plugin/helpers/content_viewer_helper.rb
1 class MezuroPlugin::Helpers::ContentViewerHelper 1 class MezuroPlugin::Helpers::ContentViewerHelper
  2 +
  3 + MAX_NUMBER_OF_LABELS = 5
  4 +
2 def self.format_grade(grade) 5 def self.format_grade(grade)
3 sprintf("%.2f", grade.to_f) 6 sprintf("%.2f", grade.to_f)
4 end 7 end
@@ -6,15 +9,31 @@ class MezuroPlugin::Helpers::ContentViewerHelper @@ -6,15 +9,31 @@ class MezuroPlugin::Helpers::ContentViewerHelper
6 def self.create_periodicity_options 9 def self.create_periodicity_options
7 [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]] 10 [["Not Periodically", 0], ["1 day", 1], ["2 days", 2], ["Weekly", 7], ["Biweeky", 15], ["Monthly", 30]]
8 end 11 end
9 -  
10 - def self.generate_chart(values)  
11 - Gchart.line( 12 +
  13 + def self.create_license_options
  14 + options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yaml")
  15 + options = options.split(";")
  16 + formated_options = []
  17 + options.each { |option| formated_options << [option, option] }
  18 + formated_options
  19 + end
  20 +
  21 + def self.generate_chart(score_history)
  22 + values = []
  23 + labels = []
  24 + score_history.each do |score_data|
  25 + values << score_data.first
  26 + labels << score_data.last
  27 + end
  28 + labels = discretize_array labels
  29 + Gchart.line(
12 :title_color => 'FF0000', 30 :title_color => 'FF0000',
13 :size => '600x180', 31 :size => '600x180',
14 :bg => {:color => 'efefef', :type => 'stripes'}, 32 :bg => {:color => 'efefef', :type => 'stripes'},
15 :line_colors => 'c4a000', 33 :line_colors => 'c4a000',
16 :data => values, 34 :data => values,
17 - :axis_with_labels => 'y', 35 + :labels => labels,
  36 + :axis_with_labels => ['y','x'],
18 :max_value => values.max, 37 :max_value => values.max,
19 :min_value => values.min 38 :min_value => values.min
20 ) 39 )
@@ -25,8 +44,33 @@ class MezuroPlugin::Helpers::ContentViewerHelper @@ -25,8 +44,33 @@ class MezuroPlugin::Helpers::ContentViewerHelper
25 selected_option = options.find { |option| option.last == index.to_i } 44 selected_option = options.find { |option| option.last == index.to_i }
26 selected_option.first 45 selected_option.first
27 end 46 end
28 - 47 +
29 def self.format_name(metric_result) 48 def self.format_name(metric_result)
30 metric_result.metric.name.delete("() ") 49 metric_result.metric.name.delete("() ")
31 end 50 end
  51 +
  52 + def self.get_license_option(selected)
  53 + options = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/licenses.yaml")
  54 + options.split(";")
  55 + selected_option = options.find { |license| license == selected }
  56 + end
  57 +
  58 + private
  59 +
  60 + def self.discretize_array(array)
  61 + if array.size > MAX_NUMBER_OF_LABELS
  62 + range_array.map { |i| discrete_element(array, i)}
  63 + else
  64 + array
  65 + end
  66 + end
  67 +
  68 + def self.range_array
  69 + (0..(MAX_NUMBER_OF_LABELS - 1)).to_a
  70 + end
  71 +
  72 + def self.discrete_element(array, i)
  73 + array[(i*(array.size - 1))/(MAX_NUMBER_OF_LABELS - 1)]
  74 + end
  75 +
32 end 76 end
plugins/mezuro/lib/mezuro_plugin/project_content.rb
1 class MezuroPlugin::ProjectContent < Article 1 class MezuroPlugin::ProjectContent < Article
2 include ActionView::Helpers::TagHelper 2 include ActionView::Helpers::TagHelper
3 3
4 - settings_items :license, :description, :repository_type, :repository_url, :configuration_name, :periodicity_in_days 4 + settings_items :project_license, :description, :repository_type, :repository_url, :configuration_name, :periodicity_in_days
5 5
6 validate_on_create :validate_kalibro_project_name 6 validate_on_create :validate_kalibro_project_name
7 validate_on_create :validate_repository_url 7 validate_on_create :validate_repository_url
@@ -26,6 +26,7 @@ class MezuroPlugin::ProjectContent &lt; Article @@ -26,6 +26,7 @@ class MezuroPlugin::ProjectContent &lt; Article
26 rescue Exception => error 26 rescue Exception => error
27 errors.add_to_base(error.message) 27 errors.add_to_base(error.message)
28 end 28 end
  29 + @project
29 end 30 end
30 31
31 def project_result 32 def project_result
@@ -34,6 +35,7 @@ class MezuroPlugin::ProjectContent &lt; Article @@ -34,6 +35,7 @@ class MezuroPlugin::ProjectContent &lt; Article
34 rescue Exception => error 35 rescue Exception => error
35 errors.add_to_base(error.message) 36 errors.add_to_base(error.message)
36 end 37 end
  38 + @project_result
37 end 39 end
38 40
39 def project_result_with_date(date) 41 def project_result_with_date(date)
@@ -43,6 +45,7 @@ Kalibro::ProjectResult.first_result_after(name, date) @@ -43,6 +45,7 @@ Kalibro::ProjectResult.first_result_after(name, date)
43 rescue Exception => error 45 rescue Exception => error
44 errors.add_to_base(error.message) 46 errors.add_to_base(error.message)
45 end 47 end
  48 + @project_result
46 end 49 end
47 50
48 def module_result(attributes) 51 def module_result(attributes)
@@ -53,6 +56,7 @@ Kalibro::ProjectResult.first_result_after(name, date) @@ -53,6 +56,7 @@ Kalibro::ProjectResult.first_result_after(name, date)
53 rescue Exception => error 56 rescue Exception => error
54 errors.add_to_base(error.message) 57 errors.add_to_base(error.message)
55 end 58 end
  59 + @module_result
56 end 60 end
57 61
58 def result_history(module_name) 62 def result_history(module_name)
@@ -73,6 +77,7 @@ Kalibro::ProjectResult.first_result_after(name, date) @@ -73,6 +77,7 @@ Kalibro::ProjectResult.first_result_after(name, date)
73 existing = Kalibro::Project.all_names 77 existing = Kalibro::Project.all_names
74 rescue Exception => error 78 rescue Exception => error
75 errors.add_to_base(error.message) 79 errors.add_to_base(error.message)
  80 + existing = []
76 end 81 end
77 82
78 if existing.any?{|existing_name| existing_name.casecmp(name)==0} # existing.include?(name) + case insensitive 83 if existing.any?{|existing_name| existing_name.casecmp(name)==0} # existing.include?(name) + case insensitive
@@ -94,7 +99,7 @@ Kalibro::ProjectResult.first_result_after(name, date) @@ -94,7 +99,7 @@ Kalibro::ProjectResult.first_result_after(name, date)
94 def create_kalibro_project 99 def create_kalibro_project
95 Kalibro::Project.create( 100 Kalibro::Project.create(
96 :name => name, 101 :name => name,
97 - :license => license, 102 + :license => project_license,
98 :description => description, 103 :description => description,
99 :repository => { 104 :repository => {
100 :type => repository_type, 105 :type => repository_type,
@@ -105,7 +110,7 @@ Kalibro::ProjectResult.first_result_after(name, date) @@ -105,7 +110,7 @@ Kalibro::ProjectResult.first_result_after(name, date)
105 end 110 end
106 111
107 def destroy_project_from_service 112 def destroy_project_from_service
108 - project.destroy 113 + project.destroy unless project.nil?
109 end 114 end
110 115
111 end 116 end
plugins/mezuro/licenses.yaml.example 0 → 100644
@@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
  1 +Academic Free License 3.0 (AFL-3.0);
  2 +Affero GNU Public License (AGPL-3.0);
  3 +Adaptive Public License (APL-1.0);
  4 +Apache License 2.0 (Apache-2.0);
  5 +Apple Public Source License (APSL-2.0);
  6 +Artistic license 2.0 (Artistic-2.0);
  7 +Attribution Assurance Licenses (AAL);
  8 +BSD 3-Clause "New" or "Revised" License (BSD-3-Clause);
  9 +BSD 2-Clause "Simplified" or "FreeBSD" License (BSD-2-Clause);
  10 +Boost Software License (BSL-1.0);
  11 +Computer Associates Trusted Open Source License 1.1 (CATOSL-1.1);
  12 +Common Development and Distribution License 1.0 (CDDL-1.0);
  13 +Common Public Attribution License 1.0 (CPAL-1.0);
  14 +CUA Office Public License Version 1.0 (CUA-OPL-1.0);
  15 +EU DataGrid Software License (EUDatagrid);
  16 +Eclipse Public License 1.0 (EPL-1.0);
  17 +Educational Community License, Version 2.0 (ECL-2.0);
  18 +Eiffel Forum License V2.0 (EFL-2.0);
  19 +Entessa Public License (Entessa);
  20 +European Union Public License, Version 1.1 (EUPL-1.1);
  21 +Fair License (FAIR);
  22 +Frameworx License (Frameworx-1.0);
  23 +GNU Affero General Public License v3 (AGPL-3.0);
  24 +GNU General Public License version 2.0 (GPL-2.0);
  25 +GNU General Public License version 3.0 (GPL-3.0);
  26 +GNU Library or "Lesser" General Public License version 2.1 (LGPL-2.1);
  27 +GNU Library or "Lesser" General Public License version 3.0 (LGPL-3.0);
  28 +Historical Permission Notice and Disclaimer (HPND);
  29 +IBM Public License 1.0 (IPL-1.0);
  30 +IPA Font License (IPA);
  31 +ISC License (ISC);
  32 +LaTeX Project Public License 1.3c (LPPL-1.3c);
  33 +Lucent Public License Version 1.02 (LPL-1.02);
  34 +MirOS Licence (MirOS);
  35 +Microsoft Public License (Ms-PL);
  36 +Microsoft Reciprocal License (Ms-RL);
  37 +MIT license (MIT);
  38 +Motosoto License (Motosoto);
  39 +Mozilla Public License 2.0 (MPL-2.0);
  40 +Multics License (Multics);
  41 +NASA Open Source Agreement 1.3 (NASA 1.3);
  42 +NTP License (NTP);
  43 +Naumen Public License (Naumen);
  44 +Nethack General Public License (NGPL);
  45 +Nokia Open Source License (Nokia);
  46 +Non-Profit Open Software License 3.0 (NPOSL-3.0);
  47 +OCLC Research Public License 2.0 (OCLC-2.0);
  48 +Open Font License 1.1 (OFL 1.1);
  49 +Open Group Test Suite License (OGTSL);
  50 +Open Software License 3.0 (OSL-3.0);
  51 +PHP License 3.0 (PHP-3.0);
  52 +The PostgreSQL License (PostgreSQL);
  53 +Python License (Python-2.0);
  54 +CNRI Python license (CNRI-Python);
  55 +Q Public License (QPL-1.0);
  56 +RealNetworks Public Source License V1.0 (RPSL-1.0);
  57 +Reciprocal Public License 1.5 (RPL-1.5);
  58 +Ricoh Source Code Public License (RSCPL);
  59 +Simple Public License 2.0 (SimPL-2.0);
  60 +Sleepycat License (Sleepycat);
  61 +Sun Public License 1.0 (SPL-1.0);
  62 +Sybase Open Watcom Public License 1.0 (Watcom-1.0);
  63 +University of Illinois/NCSA Open Source License (NCSA);
  64 +Vovida Software License v. 1.0 (VSL-1.0);
  65 +W3C License (W3C);
  66 +wxWindows Library License (WXwindows);
  67 +X.Net License (Xnet);
  68 +Zope Public License 2.0 (ZPL-2.0);
  69 +zlib/libpng license (Zlib);
plugins/mezuro/public/colorPicker.css 0 → 100644
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
  1 +div.colorPicker-picker {
  2 + height: 16px;
  3 + width: 16px;
  4 + padding: 0 !important;
  5 + border: 1px solid #ccc;
  6 + background: url(arrow.gif) no-repeat top right;
  7 + cursor: pointer;
  8 + line-height: 16px;
  9 +}
  10 +
  11 +div.colorPicker-palette {
  12 + width: 110px;
  13 + position: absolute;
  14 + border: 1px solid #598FEF;
  15 + background-color: #EFEFEF;
  16 + padding: 2px;
  17 + z-index: 9999;
  18 +}
  19 + div.colorPicker_hexWrap {width: 100%; float:left }
  20 + div.colorPicker_hexWrap label {font-size: 95%; color: #2F2F2F; margin: 5px 2px; width: 25%}
  21 + div.colorPicker_hexWrap input {margin: 5px 2px; padding: 0; font-size: 95%; border: 1px solid #000; width: 65%; }
  22 +
  23 +div.colorPicker-swatch {
  24 + height: 12px;
  25 + width: 12px;
  26 + border: 1px solid #000;
  27 + margin: 2px;
  28 + float: left;
  29 + cursor: pointer;
  30 + line-height: 12px;
  31 +}
plugins/mezuro/public/javascripts/colorPicker/LICENSE 0 → 100644
@@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
  1 +Copyright (c) 2012 Lakshan Perera
  2 +
  3 +Permission is hereby granted, free of charge, to any person
  4 +obtaining a copy of this software and associated documentation
  5 +files (the "Software"), to deal in the Software without
  6 +restriction, including without limitation the rights to use,
  7 +copy, modify, merge, publish, distribute, sublicense, and/or sell
  8 +copies of the Software, and to permit persons to whom the
  9 +Software is furnished to do so, subject to the following
  10 +conditions:
  11 +
  12 +The above copyright notice and this permission notice shall be
  13 +included in all copies or substantial portions of the Software.
  14 +
  15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  17 +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18 +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  19 +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20 +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21 +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22 +OTHER DEALINGS IN THE SOFTWARE.
plugins/mezuro/public/javascripts/colorPicker/jquery.colorPicker.js 0 → 100644
@@ -0,0 +1,328 @@ @@ -0,0 +1,328 @@
  1 +/**
  2 + * Really Simple Color Picker in jQuery
  3 + *
  4 + * Licensed under the MIT (MIT-LICENSE.txt) licenses.
  5 + *
  6 + * Copyright (c) 2008-2012
  7 + * Lakshan Perera (www.laktek.com) & Daniel Lacy (daniellacy.com)
  8 + *
  9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  10 + * of this software and associated documentation files (the "Software"), to
  11 + * deal in the Software without restriction, including without limitation the
  12 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  13 + * sell copies of the Software, and to permit persons to whom the Software is
  14 + * furnished to do so, subject to the following conditions:
  15 + *
  16 + * The above copyright notice and this permission notice shall be included in
  17 + * all copies or substantial portions of the Software.
  18 + *
  19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  25 + * IN THE SOFTWARE.
  26 + */
  27 +
  28 +(function ($) {
  29 + /**
  30 + * Create a couple private variables.
  31 + **/
  32 + var selectorOwner,
  33 + activePalette,
  34 + cItterate = 0,
  35 + templates = {
  36 + control : $('<div class="colorPicker-picker">&nbsp;</div>'),
  37 + palette : $('<div id="colorPicker_palette" class="colorPicker-palette" />'),
  38 + swatch : $('<div class="colorPicker-swatch">&nbsp;</div>'),
  39 + hexLabel: $('<label for="colorPicker_hex">Hex</label>'),
  40 + hexField: $('<input type="text" id="colorPicker_hex" />')
  41 + },
  42 + transparent = "transparent",
  43 + lastColor;
  44 +
  45 + /**
  46 + * Create our colorPicker function
  47 + **/
  48 + $.fn.colorPicker = function (options) {
  49 +
  50 + return this.each(function () {
  51 + // Setup time. Clone new elements from our templates, set some IDs, make shortcuts, jazzercise.
  52 + var element = $(this),
  53 + opts = $.extend({}, $.fn.colorPicker.defaults, options),
  54 + defaultColor = $.fn.colorPicker.toHex(
  55 + (element.val().length > 0) ? element.val() : opts.pickerDefault
  56 + ),
  57 + newControl = templates.control.clone(),
  58 + newPalette = templates.palette.clone().attr('id', 'colorPicker_palette-' + cItterate),
  59 + newHexLabel = templates.hexLabel.clone(),
  60 + newHexField = templates.hexField.clone(),
  61 + paletteId = newPalette[0].id,
  62 + swatch;
  63 +
  64 +
  65 + /**
  66 + * Build a color palette.
  67 + **/
  68 + $.each(opts.colors, function (i) {
  69 + swatch = templates.swatch.clone();
  70 +
  71 + if (opts.colors[i] === transparent) {
  72 + swatch.addClass(transparent).text('X');
  73 + $.fn.colorPicker.bindPalette(newHexField, swatch, transparent);
  74 + } else {
  75 + swatch.css("background-color", "#" + this);
  76 + $.fn.colorPicker.bindPalette(newHexField, swatch);
  77 + }
  78 + swatch.appendTo(newPalette);
  79 + });
  80 +
  81 + newHexLabel.attr('for', 'colorPicker_hex-' + cItterate);
  82 +
  83 + newHexField.attr({
  84 + 'id' : 'colorPicker_hex-' + cItterate,
  85 + 'value' : defaultColor
  86 + });
  87 +
  88 + newHexField.bind("keydown", function (event) {
  89 + if (event.keyCode === 13) {
  90 + var hexColor = $.fn.colorPicker.toHex($(this).val());
  91 + $.fn.colorPicker.changeColor(hexColor ? hexColor : element.val());
  92 + }
  93 + if (event.keyCode === 27) {
  94 + $.fn.colorPicker.hidePalette();
  95 + }
  96 + });
  97 +
  98 + newHexField.bind("keyup", function (event) {
  99 + var hexColor = $.fn.colorPicker.toHex($(event.target).val());
  100 + $.fn.colorPicker.previewColor(hexColor ? hexColor : element.val());
  101 + });
  102 +
  103 + $('<div class="colorPicker_hexWrap" />').append(newHexLabel).appendTo(newPalette);
  104 +
  105 + newPalette.find('.colorPicker_hexWrap').append(newHexField);
  106 +
  107 + $("body").append(newPalette);
  108 +
  109 + newPalette.hide();
  110 +
  111 +
  112 + /**
  113 + * Build replacement interface for original color input.
  114 + **/
  115 + newControl.css("background-color", defaultColor);
  116 +
  117 + newControl.bind("click", function () {
  118 + $.fn.colorPicker.togglePalette($('#' + paletteId), $(this));
  119 + });
  120 +
  121 + if( options && options.onColorChange ) {
  122 + newControl.data('onColorChange', options.onColorChange);
  123 + } else {
  124 + newControl.data('onColorChange', function() {} );
  125 + }
  126 + element.after(newControl);
  127 +
  128 + element.bind("change", function () {
  129 + element.next(".colorPicker-picker").css(
  130 + "background-color", $.fn.colorPicker.toHex($(this).val())
  131 + );
  132 + });
  133 +
  134 + // Hide the original input.
  135 + element.val(defaultColor).hide();
  136 +
  137 + cItterate++;
  138 + });
  139 + };
  140 +
  141 + /**
  142 + * Extend colorPicker with... all our functionality.
  143 + **/
  144 + $.extend(true, $.fn.colorPicker, {
  145 + /**
  146 + * Return a Hex color, convert an RGB value and return Hex, or return false.
  147 + *
  148 + * Inspired by http://code.google.com/p/jquery-color-utils
  149 + **/
  150 + toHex : function (color) {
  151 + // If we have a standard or shorthand Hex color, return that value.
  152 + if (color.match(/[0-9A-F]{6}|[0-9A-F]{3}$/i)) {
  153 + return (color.charAt(0) === "#") ? color : ("#" + color);
  154 +
  155 + // Alternatively, check for RGB color, then convert and return it as Hex.
  156 + } else if (color.match(/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/)) {
  157 + var c = ([parseInt(RegExp.$1, 10), parseInt(RegExp.$2, 10), parseInt(RegExp.$3, 10)]),
  158 + pad = function (str) {
  159 + if (str.length < 2) {
  160 + for (var i = 0, len = 2 - str.length; i < len; i++) {
  161 + str = '0' + str;
  162 + }
  163 + }
  164 +
  165 + return str;
  166 + };
  167 +
  168 + if (c.length === 3) {
  169 + var r = pad(c[0].toString(16)),
  170 + g = pad(c[1].toString(16)),
  171 + b = pad(c[2].toString(16));
  172 +
  173 + return '#' + r + g + b;
  174 + }
  175 +
  176 + // Otherwise we wont do anything.
  177 + } else {
  178 + return false;
  179 +
  180 + }
  181 + },
  182 +
  183 + /**
  184 + * Check whether user clicked on the selector or owner.
  185 + **/
  186 + checkMouse : function (event, paletteId) {
  187 + var selector = activePalette,
  188 + selectorParent = $(event.target).parents("#" + selector.attr('id')).length;
  189 +
  190 + if (event.target === $(selector)[0] || event.target === selectorOwner[0] || selectorParent > 0) {
  191 + return;
  192 + }
  193 +
  194 + $.fn.colorPicker.hidePalette();
  195 + },
  196 +
  197 + /**
  198 + * Hide the color palette modal.
  199 + **/
  200 + hidePalette : function () {
  201 + $(document).unbind("mousedown", $.fn.colorPicker.checkMouse);
  202 +
  203 + $('.colorPicker-palette').hide();
  204 + },
  205 +
  206 + /**
  207 + * Show the color palette modal.
  208 + **/
  209 + showPalette : function (palette) {
  210 + var hexColor = selectorOwner.prev("input").val();
  211 +
  212 + palette.css({
  213 + top: selectorOwner.offset().top + (selectorOwner.outerHeight()),
  214 + left: selectorOwner.offset().left
  215 + });
  216 +
  217 + $("#color_value").val(hexColor);
  218 +
  219 + palette.show();
  220 +
  221 + $(document).bind("mousedown", $.fn.colorPicker.checkMouse);
  222 + },
  223 +
  224 + /**
  225 + * Toggle visibility of the colorPicker palette.
  226 + **/
  227 + togglePalette : function (palette, origin) {
  228 + // selectorOwner is the clicked .colorPicker-picker.
  229 + if (origin) {
  230 + selectorOwner = origin;
  231 + }
  232 +
  233 + activePalette = palette;
  234 +
  235 + if (activePalette.is(':visible')) {
  236 + $.fn.colorPicker.hidePalette();
  237 +
  238 + } else {
  239 + $.fn.colorPicker.showPalette(palette);
  240 +
  241 + }
  242 + },
  243 +
  244 + /**
  245 + * Update the input with a newly selected color.
  246 + **/
  247 + changeColor : function (value) {
  248 + selectorOwner.css("background-color", value);
  249 + selectorOwner.prev("input").val(value).change();
  250 +
  251 + $.fn.colorPicker.hidePalette();
  252 +
  253 + selectorOwner.data('onColorChange').call(selectorOwner, $(selectorOwner).prev("input").attr("id"), value);
  254 + },
  255 +
  256 +
  257 + /**
  258 + * Preview the input with a newly selected color.
  259 + **/
  260 + previewColor : function (value) {
  261 + selectorOwner.css("background-color", value);
  262 + },
  263 +
  264 + /**
  265 + * Bind events to the color palette swatches.
  266 + */
  267 + bindPalette : function (paletteInput, element, color) {
  268 + color = color ? color : $.fn.colorPicker.toHex(element.css("background-color"));
  269 +
  270 + element.bind({
  271 + click : function (ev) {
  272 + lastColor = color;
  273 +
  274 + $.fn.colorPicker.changeColor(color);
  275 + },
  276 + mouseover : function (ev) {
  277 + lastColor = paletteInput.val();
  278 +
  279 + $(this).css("border-color", "#598FEF");
  280 +
  281 + paletteInput.val(color);
  282 +
  283 + $.fn.colorPicker.previewColor(color);
  284 + },
  285 + mouseout : function (ev) {
  286 + $(this).css("border-color", "#000");
  287 +
  288 + paletteInput.val(selectorOwner.css("background-color"));
  289 +
  290 + paletteInput.val(lastColor);
  291 +
  292 + $.fn.colorPicker.previewColor(lastColor);
  293 + }
  294 + });
  295 + }
  296 + });
  297 +
  298 + /**
  299 + * Default colorPicker options.
  300 + *
  301 + * These are publibly available for global modification using a setting such as:
  302 + *
  303 + * $.fn.colorPicker.defaults.colors = ['151337', '111111']
  304 + *
  305 + * They can also be applied on a per-bound element basis like so:
  306 + *
  307 + * $('#element1').colorPicker({pickerDefault: 'efefef', transparency: true});
  308 + * $('#element2').colorPicker({pickerDefault: '333333', colors: ['333333', '111111']});
  309 + *
  310 + **/
  311 + $.fn.colorPicker.defaults = {
  312 + // colorPicker default selected color.
  313 + pickerDefault : "FFFFFF",
  314 +
  315 + // Default color set.
  316 + colors : [
  317 + '000000', '993300', '333300', '000080', '333399', '333333', '800000', 'FF6600',
  318 + '808000', '008000', '008080', '0000FF', '666699', '808080', 'FF0000', 'FF9900',
  319 + '99CC00', '339966', '33CCCC', '3366FF', '800080', '999999', 'FF00FF', 'FFCC00',
  320 + 'FFFF00', '00FF00', '00FFFF', '00CCFF', '993366', 'C0C0C0', 'FF99CC', 'FFCC99',
  321 + 'FFFF99', 'CCFFFF', '99CCFF', 'FFFFFF'
  322 + ],
  323 +
  324 + // If we want to simply add more colors to the default set, use addColors.
  325 + addColors : []
  326 + };
  327 +
  328 +})(jQuery);
plugins/mezuro/public/javascripts/colorPicker/jquery.colorPicker.min.js 0 → 100644
@@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
  1 +/**
  2 + * Really Simple Color Picker in jQuery
  3 + *
  4 + * Licensed under the MIT (MIT-LICENSE.txt) licenses.
  5 + *
  6 + * Copyright (c) 2008-2012
  7 + * Lakshan Perera (www.laktek.com) & Daniel Lacy (daniellacy.com)
  8 + *
  9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  10 + * of this software and associated documentation files (the "Software"), to
  11 + * deal in the Software without restriction, including without limitation the
  12 + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  13 + * sell copies of the Software, and to permit persons to whom the Software is
  14 + * furnished to do so, subject to the following conditions:
  15 + *
  16 + * The above copyright notice and this permission notice shall be included in
  17 + * all copies or substantial portions of the Software.
  18 + *
  19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  25 + * IN THE SOFTWARE.
  26 + */(function(a){var b,c,d=0,e={control:a('<div class="colorPicker-picker">&nbsp;</div>'),palette:a('<div id="colorPicker_palette" class="colorPicker-palette" />'),swatch:a('<div class="colorPicker-swatch">&nbsp;</div>'),hexLabel:a('<label for="colorPicker_hex">Hex</label>'),hexField:a('<input type="text" id="colorPicker_hex" />')},f="transparent",g;a.fn.colorPicker=function(b){return this.each(function(){var c=a(this),g=a.extend({},a.fn.colorPicker.defaults,b),h=a.fn.colorPicker.toHex(c.val().length>0?c.val():g.pickerDefault),i=e.control.clone(),j=e.palette.clone().attr("id","colorPicker_palette-"+d),k=e.hexLabel.clone(),l=e.hexField.clone(),m=j[0].id,n;a.each(g.colors,function(b){n=e.swatch.clone(),g.colors[b]===f?(n.addClass(f).text("X"),a.fn.colorPicker.bindPalette(l,n,f)):(n.css("background-color","#"+this),a.fn.colorPicker.bindPalette(l,n)),n.appendTo(j)}),k.attr("for","colorPicker_hex-"+d),l.attr({id:"colorPicker_hex-"+d,value:h}),l.bind("keydown",function(b){if(b.keyCode===13){var d=a.fn.colorPicker.toHex(a(this).val());a.fn.colorPicker.changeColor(d?d:c.val())}b.keyCode===27&&a.fn.colorPicker.hidePalette()}),l.bind("keyup",function(b){var d=a.fn.colorPicker.toHex(a(b.target).val());a.fn.colorPicker.previewColor(d?d:c.val())}),a('<div class="colorPicker_hexWrap" />').append(k).appendTo(j),j.find(".colorPicker_hexWrap").append(l),a("body").append(j),j.hide(),i.css("background-color",h),i.bind("click",function(){a.fn.colorPicker.togglePalette(a("#"+m),a(this))}),b&&b.onColorChange?i.data("onColorChange",b.onColorChange):i.data("onColorChange",function(){}),c.after(i),c.bind("change",function(){c.next(".colorPicker-picker").css("background-color",a.fn.colorPicker.toHex(a(this).val()))}),c.val(h).hide(),d++})},a.extend(!0,a.fn.colorPicker,{toHex:function(a){if(a.match(/[0-9A-F]{6}|[0-9A-F]{3}$/i))return a.charAt(0)==="#"?a:"#"+a;if(!a.match(/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/))return!1;var b=[parseInt(RegExp.$1,10),parseInt(RegExp.$2,10),parseInt(RegExp.$3,10)],c=function(a){if(a.length<2)for(var b=0,c=2-a.length;b<c;b++)a="0"+a;return a};if(b.length===3){var d=c(b[0].toString(16)),e=c(b[1].toString(16)),f=c(b[2].toString(16));return"#"+d+e+f}},checkMouse:function(d,e){var f=c,g=a(d.target).parents("#"+f.attr("id")).length;if(d.target===a(f)[0]||d.target===b[0]||g>0)return;a.fn.colorPicker.hidePalette()},hidePalette:function(){a(document).unbind("mousedown",a.fn.colorPicker.checkMouse),a(".colorPicker-palette").hide()},showPalette:function(c){var d=b.prev("input").val();c.css({top:b.offset().top+b.outerHeight(),left:b.offset().left}),a("#color_value").val(d),c.show(),a(document).bind("mousedown",a.fn.colorPicker.checkMouse)},togglePalette:function(d,e){e&&(b=e),c=d,c.is(":visible")?a.fn.colorPicker.hidePalette():a.fn.colorPicker.showPalette(d)},changeColor:function(c){b.css("background-color",c),b.prev("input").val(c).change(),a.fn.colorPicker.hidePalette(),b.data("onColorChange").call(b,a(b).prev("input").attr("id"),c)},previewColor:function(a){b.css("background-color",a)},bindPalette:function(c,d,e){e=e?e:a.fn.colorPicker.toHex(d.css("background-color")),d.bind({click:function(b){g=e,a.fn.colorPicker.changeColor(e)},mouseover:function(b){g=c.val(),a(this).css("border-color","#598FEF"),c.val(e),a.fn.colorPicker.previewColor(e)},mouseout:function(d){a(this).css("border-color","#000"),c.val(b.css("background-color")),c.val(g),a.fn.colorPicker.previewColor(g)}})}}),a.fn.colorPicker.defaults={pickerDefault:"FFFFFF",colors:["000000","993300","333300","000080","333399","333333","800000","FF6600","808000","008000","008080","0000FF","666699","808080","FF0000","FF9900","99CC00","339966","33CCCC","3366FF","800080","999999","FF00FF","FFCC00","FFFF00","00FF00","00FFFF","00CCFF","993366","C0C0C0","FF99CC","FFCC99","FFFF99","CCFFFF","99CCFF","FFFFFF"],addColors:[]}})(jQuery)
0 \ No newline at end of file 27 \ No newline at end of file
plugins/mezuro/public/javascripts/project_content.js
@@ -2,7 +2,6 @@ var processingTree = false; @@ -2,7 +2,6 @@ var processingTree = false;
2 var metricName; 2 var metricName;
3 jQuery(function (){ 3 jQuery(function (){
4 jQuery('.source-tree-link').live("click", reloadModule); 4 jQuery('.source-tree-link').live("click", reloadModule);
5 - jQuery('[data-show]').live("click", toggle_mezuro);  
6 jQuery('[show-metric-history]').live("click", display_metric_history); 5 jQuery('[show-metric-history]').live("click", display_metric_history);
7 jQuery('[show-grade-history]').live("click", display_grade_history); 6 jQuery('[show-grade-history]').live("click", display_grade_history);
8 jQuery('#project_date_submit').live("click", reloadProjectWithDate); 7 jQuery('#project_date_submit').live("click", reloadProjectWithDate);
@@ -16,7 +15,8 @@ function showProjectContent() { @@ -16,7 +15,8 @@ function showProjectContent() {
16 15
17 function display_metric_history() { 16 function display_metric_history() {
18 var module_name = jQuery(this).attr('data-module-name'); 17 var module_name = jQuery(this).attr('data-module-name');
19 - var metric_name = jQuery(this).attr('data-metric-name'); 18 + var metric_name = jQuery(this).attr('show-metric-history');
  19 + toggle_mezuro("." + metric_name);
20 metricName = metric_name; 20 metricName = metric_name;
21 callAction('module_metrics_history', {module_name: module_name, metric_name: metric_name}, show_metrics); 21 callAction('module_metrics_history', {module_name: module_name, metric_name: metric_name}, show_metrics);
22 return false; 22 return false;
@@ -24,6 +24,7 @@ function display_metric_history() { @@ -24,6 +24,7 @@ function display_metric_history() {
24 24
25 function display_grade_history() { 25 function display_grade_history() {
26 var module_name = jQuery(this).attr('data-module-name'); 26 var module_name = jQuery(this).attr('data-module-name');
  27 + toggle_mezuro("#historical-grade");
27 callAction('module_grade_history', {module_name: module_name}, show_grades); 28 callAction('module_grade_history', {module_name: module_name}, show_grades);
28 return false; 29 return false;
29 } 30 }
@@ -36,8 +37,7 @@ function show_grades(content) { @@ -36,8 +37,7 @@ function show_grades(content) {
36 jQuery('#historical-grade').html(content); 37 jQuery('#historical-grade').html(content);
37 } 38 }
38 39
39 -function toggle_mezuro(){  
40 - var element = jQuery(this).attr('data-show'); 40 +function toggle_mezuro(element){
41 jQuery(element).toggle(); 41 jQuery(element).toggle();
42 return false; 42 return false;
43 } 43 }
@@ -51,23 +51,8 @@ function reloadModule(){ @@ -51,23 +51,8 @@ function reloadModule(){
51 return false; 51 return false;
52 } 52 }
53 53
54 -function reloadProjectWithDate(){  
55 - var day = jQuery("#project_date_day").val();  
56 - var month = jQuery("#project_date_month").val();  
57 - var year = jQuery("#project_date_year").val();  
58 -  
59 - if(day.length == 1)  
60 - day = "0" + day;  
61 - if(month.length == 1)  
62 - month = "0" + month;  
63 -  
64 - var date = new Date(year + "-" + month + "-" + day + "T00:00:00+00:00");  
65 -  
66 - if(isNaN(date)){  
67 - alert("Invalid date! " + date);  
68 - return false;  
69 - }  
70 - reloadProject(date); 54 +function reloadProjectWithDate(date){
  55 + reloadProject(date + "T00:00:00+00:00");
71 return false; 56 return false;
72 } 57 }
73 58
plugins/mezuro/public/javascripts/validations.js
@@ -3,7 +3,9 @@ jQuery(function (){ @@ -3,7 +3,9 @@ jQuery(function (){
3 jQuery('#metric_configuration_submit').live("click", validate_metric_configuration); 3 jQuery('#metric_configuration_submit').live("click", validate_metric_configuration);
4 }); 4 });
5 5
6 - 6 +function validate_code(code){
  7 + return true;
  8 +}
7 9
8 function validate_metric_configuration(){ 10 function validate_metric_configuration(){
9 var code = jQuery('#metric_configuration_code').val(); 11 var code = jQuery('#metric_configuration_code').val();
@@ -37,14 +39,6 @@ function IsNotInfinite(value){ @@ -37,14 +39,6 @@ function IsNotInfinite(value){
37 return true; 39 return true;
38 } 40 }
39 41
40 -function IsNotHexadecimal(value){  
41 - if(value.match(/^[0-9a-fA-F]{1,8}$/))  
42 - {  
43 - return false;  
44 - }  
45 - return true;  
46 -}  
47 -  
48 function validate_new_range_configuration(event){ 42 function validate_new_range_configuration(event){
49 var label = jQuery("#range_label").val(); 43 var label = jQuery("#range_label").val();
50 var beginning = jQuery("#range_beginning").val(); 44 var beginning = jQuery("#range_beginning").val();
@@ -54,24 +48,20 @@ function validate_new_range_configuration(event){ @@ -54,24 +48,20 @@ function validate_new_range_configuration(event){
54 48
55 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))
56 { 50 {
57 - alert("Please fill all fields marked with (*)"); 51 + alert("Please fill all fields marked with (*).");
58 return false; 52 return false;
59 } 53 }
60 if ( (IsNotNumeric(beginning) && IsNotInfinite(beginning)) || (IsNotNumeric(end) && IsNotInfinite(end)) || IsNotNumeric(grade)) 54 if ( (IsNotNumeric(beginning) && IsNotInfinite(beginning)) || (IsNotNumeric(end) && IsNotInfinite(end)) || IsNotNumeric(grade))
61 { 55 {
62 - alert("Beginning, End and Grade must be numeric values"); 56 + alert("Beginning, End and Grade must be numeric values.");
63 return false; 57 return false;
64 } 58 }
65 if (parseInt(beginning) > parseInt(end)) 59 if (parseInt(beginning) > parseInt(end))
66 { 60 {
67 if(IsNotInfinite(beginning) && IsNotInfinite(end)){ 61 if(IsNotInfinite(beginning) && IsNotInfinite(end)){
68 - alert("End must be greater than Beginning"); 62 + alert("End must be greater than Beginning.");
69 return false; 63 return false;
70 } 64 }
71 } 65 }
72 - if (IsNotHexadecimal(color)){  
73 - alert("Color must be an hexadecimal value");  
74 - return false;  
75 - }  
76 return true; 66 return true;
77 } 67 }
plugins/mezuro/public/style.css
  1 +@import url('colorPicker.css');
  2 +
1 .link { 3 .link {
2 cursor: pointer; 4 cursor: pointer;
3 } 5 }
plugins/mezuro/test/fixtures/project_fixtures.rb
@@ -28,7 +28,7 @@ class ProjectFixtures @@ -28,7 +28,7 @@ class ProjectFixtures
28 def self.project_content 28 def self.project_content
29 content = MezuroPlugin::ProjectContent.new 29 content = MezuroPlugin::ProjectContent.new
30 content.name = 'Qt-Calculator' 30 content.name = 'Qt-Calculator'
31 - content.license = 'GPL' 31 + content.project_license = 'GPL'
32 content.description = 'Calculator for Qt' 32 content.description = 'Calculator for Qt'
33 content.repository_type = RepositoryFixtures.repository_hash[:type] 33 content.repository_type = RepositoryFixtures.repository_hash[:type]
34 content.repository_url = RepositoryFixtures.repository_hash[:address] 34 content.repository_url = RepositoryFixtures.repository_hash[:address]
plugins/mezuro/test/functional/mezuro_plugin_myprofile_controller_test.rb
@@ -27,7 +27,7 @@ class MezuroPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -27,7 +27,7 @@ class MezuroPluginMyprofileControllerTest &lt; ActionController::TestCase
27 27
28 Kalibro::Configuration.expects(:all_names).returns([]) 28 Kalibro::Configuration.expects(:all_names).returns([])
29 @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name) 29 @content = MezuroPlugin::ConfigurationContent.new(:profile => @profile, :name => @configuration.name)
30 - @content.expects(:send_configuration_to_service).returns(nil) 30 + @content.expects(:send_kalibro_configuration_to_service).returns(nil)
31 @content.stubs(:solr_save) 31 @content.stubs(:solr_save)
32 @content.save 32 @content.save
33 33
@@ -39,7 +39,7 @@ class MezuroPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -39,7 +39,7 @@ class MezuroPluginMyprofileControllerTest &lt; ActionController::TestCase
39 @range = RangeFixtures.range_excellent 39 @range = RangeFixtures.range_excellent
40 @range_hash = RangeFixtures.range_excellent_hash 40 @range_hash = RangeFixtures.range_excellent_hash
41 end 41 end
42 - 42 +
43 should 'test choose base tool' do 43 should 'test choose base tool' do
44 Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => @base_tool.name}) 44 Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => @base_tool.name})
45 get :choose_base_tool, :profile => @profile.identifier, :id => @content.id 45 get :choose_base_tool, :profile => @profile.identifier, :id => @content.id
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
@@ -25,14 +25,14 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase @@ -25,14 +25,14 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase
25 @content.save 25 @content.save
26 end 26 end
27 27
28 - should 'test project state without error' do 28 + should 'test project state without kalibro_error' do
29 Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) 29 Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash})
30 get :project_state, :profile => @profile.identifier, :id => @content.id 30 get :project_state, :profile => @profile.identifier, :id => @content.id
31 assert_response 200 31 assert_response 200
32 assert_equal @content, assigns(:content) 32 assert_equal @content, assigns(:content)
33 end 33 end
34 34
35 - should 'test project state with error' do 35 + should 'test project state with kalibro_error' do
36 Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ErrorFixtures.error_hash})}) 36 Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ErrorFixtures.error_hash})})
37 get :project_state, :profile => @profile.identifier, :id => @content.id 37 get :project_state, :profile => @profile.identifier, :id => @content.id
38 assert_response 200 38 assert_response 200
@@ -126,7 +126,7 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase @@ -126,7 +126,7 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase
126 get :module_metrics_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name, 126 get :module_metrics_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name,
127 :metric_name => @module_result.metric_result.first.metric.name.delete("() ") 127 :metric_name => @module_result.metric_result.first.metric.name.delete("() ")
128 assert_equal @content, assigns(:content) 128 assert_equal @content, assigns(:content)
129 - assert_equal [@module_result.metric_result[0].value], assigns(:score_history) 129 + assert_equal [[@module_result.metric_result[0].value, @module_result.date.to_s[0..9]]], assigns(:score_history)
130 assert_response 200 130 assert_response 200
131 end 131 end
132 132
@@ -134,7 +134,7 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase @@ -134,7 +134,7 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase
134 Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result}) 134 Kalibro::ModuleResult.expects(:request).with("ModuleResult", :get_result_history, {:project_name => @project.name, :module_name => @project.name}).returns({:module_result => @module_result})
135 get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name 135 get :module_grade_history, :profile => @profile.identifier, :id => @content.id, :module_name => @project.name
136 assert_equal @content, assigns(:content) 136 assert_equal @content, assigns(:content)
137 - assert_equal [@module_result.grade], assigns(:score_history) 137 + assert_equal [[@module_result.grade, @module_result.date.to_s[0..9]]], assigns(:score_history)
138 assert_response 200 138 assert_response 200
139 end 139 end
140 140
plugins/mezuro/test/unit/kalibro/configuration_test.rb
@@ -44,7 +44,9 @@ class ConfigurationTest &lt; ActiveSupport::TestCase @@ -44,7 +44,9 @@ class ConfigurationTest &lt; ActiveSupport::TestCase
44 should 'return nil when configuration doesnt exist' do 44 should 'return nil when configuration doesnt exist' do
45 request_body = {:configuration_name => @configuration.name} 45 request_body = {:configuration_name => @configuration.name}
46 Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, request_body).raises(Exception.new) 46 Kalibro::Configuration.expects(:request).with("Configuration", :get_configuration, request_body).raises(Exception.new)
47 - assert_nil Kalibro::Configuration.find_by_name(@configuration.name) 47 + assert_raise Exception do
  48 + Kalibro::Configuration.find_by_name(@configuration.name)
  49 + end
48 end 50 end
49 51
50 should 'destroy configuration by name' do 52 should 'destroy configuration by name' do
plugins/mezuro/test/unit/kalibro/project_result_test.rb
@@ -69,26 +69,20 @@ class ProjectResultTest &lt; ActiveSupport::TestCase @@ -69,26 +69,20 @@ class ProjectResultTest &lt; ActiveSupport::TestCase
69 assert_equal '00:00:01', @project_result.formatted_analysis_time 69 assert_equal '00:00:01', @project_result.formatted_analysis_time
70 end 70 end
71 71
72 - should 'retrieve module node' do  
73 - node = @project_result.get_node("main")  
74 - assert_equal @hash[:source_tree][:child][2], node.to_hash  
75 - end  
76 -  
77 should 'retrive complex module' do 72 should 'retrive complex module' do
78 - node = @project_result.get_node("org.Window")  
79 - assert_equal @hash[:source_tree][:child][0][:child].first, node.to_hash 73 + assert_equal @hash[:source_tree][:child][0][:child].first, @project_result.node("org.Window").to_hash
80 end 74 end
81 75
82 should 'return source tree node when nil is given' do 76 should 'return source tree node when nil is given' do
83 - assert_equal @hash[:source_tree], @project_result.node_of(nil).to_hash 77 + assert_equal @hash[:source_tree], @project_result.node(nil).to_hash
84 end 78 end
85 79
86 should 'return source tree node when project name is given' do 80 should 'return source tree node when project name is given' do
87 - assert_equal @hash[:source_tree], @project_result.node_of(@project_result.project.name).to_hash 81 + assert_equal @hash[:source_tree], @project_result.node(@project_result.project.name).to_hash
88 end 82 end
89 83
90 should 'return correct node when module name is given' do 84 should 'return correct node when module name is given' do
91 - assert_equal @hash[:source_tree][:child][2], @project_result.node_of("main").to_hash 85 + assert_equal @hash[:source_tree][:child][2], @project_result.node("main").to_hash
92 end 86 end
93 87
94 end 88 end
plugins/mezuro/test/unit/kalibro/range_test.rb
@@ -17,4 +17,16 @@ class RangeTest &lt; ActiveSupport::TestCase @@ -17,4 +17,16 @@ class RangeTest &lt; 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/test/unit/mezuro_plugin/configuration_content_test.rb
@@ -6,9 +6,7 @@ class ConfigurationContentTest &lt; ActiveSupport::TestCase @@ -6,9 +6,7 @@ class ConfigurationContentTest &lt; ActiveSupport::TestCase
6 6
7 def setup 7 def setup
8 @configuration = ConfigurationFixtures.configuration 8 @configuration = ConfigurationFixtures.configuration
9 - @content = MezuroPlugin::ConfigurationContent.new  
10 - @content.name = @configuration.name  
11 - @content.description = @configuration.description 9 + @content = ConfigurationFixtures.configuration_content("None")
12 end 10 end
13 11
14 should 'be an article' do 12 should 'be an article' do
@@ -35,19 +33,19 @@ class ConfigurationContentTest &lt; ActiveSupport::TestCase @@ -35,19 +33,19 @@ class ConfigurationContentTest &lt; ActiveSupport::TestCase
35 33
36 should 'get configuration from service' do 34 should 'get configuration from service' do
37 Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) 35 Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration)
38 - assert_equal @configuration, @content.configuration 36 + assert_equal @configuration, @content.kalibro_configuration
39 end 37 end
40 38
41 should 'send configuration to service after saving' do 39 should 'send configuration to service after saving' do
42 - @content.expects :send_configuration_to_service 40 + @content.expects :send_kalibro_configuration_to_service
43 @content.stubs(:solr_save) 41 @content.stubs(:solr_save)
44 @content.run_callbacks :after_save 42 @content.run_callbacks :after_save
45 end 43 end
46 44
47 should 'create new configuration' do 45 should 'create new configuration' do
48 Kalibro::Configuration.expects(:create).with(:name => @content.name, :description => @content.description) 46 Kalibro::Configuration.expects(:create).with(:name => @content.name, :description => @content.description)
49 - Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(nil)  
50 - @content.send :send_configuration_to_service 47 + Kalibro::Configuration.expects(:find_by_name).with(@content.name)
  48 + @content.send :send_kalibro_configuration_to_service
51 end 49 end
52 50
53 should 'clone configuration' do 51 should 'clone configuration' do
@@ -55,25 +53,25 @@ class ConfigurationContentTest &lt; ActiveSupport::TestCase @@ -55,25 +53,25 @@ class ConfigurationContentTest &lt; ActiveSupport::TestCase
55 Kalibro::Configuration.expects(:create).with(:name => @content.name, :description => @content.description, :metric_configuration => @configuration.metric_configurations_hash) 53 Kalibro::Configuration.expects(:create).with(:name => @content.name, :description => @content.description, :metric_configuration => @configuration.metric_configurations_hash)
56 Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(nil) 54 Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(nil)
57 Kalibro::Configuration.expects(:find_by_name).with('clone name').returns(@configuration) 55 Kalibro::Configuration.expects(:find_by_name).with('clone name').returns(@configuration)
58 - @content.send :send_configuration_to_service 56 + @content.send :send_kalibro_configuration_to_service
59 end 57 end
60 58
61 should 'edit configuration' do 59 should 'edit configuration' do
62 Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) 60 Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration)
63 @configuration.expects(:update_attributes).with(:description => @content.description) 61 @configuration.expects(:update_attributes).with(:description => @content.description)
64 - @content.send :send_configuration_to_service 62 + @content.send :send_kalibro_configuration_to_service
65 end 63 end
66 64
67 should 'send correct configuration to service but comunication fails' do 65 should 'send correct configuration to service but comunication fails' do
68 Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) 66 Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration)
69 @configuration.expects(:save).returns(false) 67 @configuration.expects(:save).returns(false)
70 - @content.send :send_configuration_to_service 68 + @content.send :send_kalibro_configuration_to_service
71 end 69 end
72 70
73 should 'remove configuration from service' do 71 should 'remove configuration from service' do
74 Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration) 72 Kalibro::Configuration.expects(:find_by_name).with(@content.name).returns(@configuration)
75 @configuration.expects(:destroy) 73 @configuration.expects(:destroy)
76 - @content.send :remove_configuration_from_service 74 + @content.send :remove_kalibro_configuration_from_service
77 end 75 end
78 76
79 end 77 end
plugins/mezuro/views/cms/mezuro_plugin/_configuration_content.html.erb
1 <h1> <%= _(MezuroPlugin::ConfigurationContent.short_description) %> </h1> 1 <h1> <%= _(MezuroPlugin::ConfigurationContent.short_description) %> </h1>
2 2
3 <% 3 <%
4 - begin  
5 - configuration = @article.title.nil? ? nil : @article.configuration  
6 - rescue  
7 - configuration = nil  
8 - end 4 + kalibro_configuration = @article.title.nil? ? nil : @article.kalibro_configuration
  5 + kalibro_configuration_names = @article.kalibro_configuration_names
9 %> 6 %>
10 7
11 <%= error_messages_for 'kalibro_configuration' %> 8 <%= error_messages_for 'kalibro_configuration' %>
@@ -13,20 +10,19 @@ @@ -13,20 +10,19 @@
13 <%= hidden_field_tag 'kalibro_configuration[profile_id]', profile.id %> 10 <%= hidden_field_tag 'kalibro_configuration[profile_id]', profile.id %>
14 <%= hidden_field_tag 'id', @article.id %> 11 <%= hidden_field_tag 'id', @article.id %>
15 12
16 -<% configuration_names = @article.configuration_names %>  
17 -  
18 -<% selected = (configuration.nil? ? "None" : @article.configuration_to_clone_name) %> 13 +
  14 +<% selected = (kalibro_configuration.nil? ? "None" : @article.configuration_to_clone_name) %>
19 15
20 <%= required_fields_message %> 16 <%= required_fields_message %>
21 17
22 <%= required labelled_form_field _('Clone Configuration'), 18 <%= required labelled_form_field _('Clone Configuration'),
23 -if !configuration.nil? && !@article.id.nil?  
24 - f.select(:configuration_to_clone_name, configuration_names, {:selected => selected}, :disabled => 'true') 19 +if !kalibro_configuration.nil? && !@article.id.nil?
  20 + f.select(:configuration_to_clone_name, kalibro_configuration_names, {:selected => selected}, :disabled => 'true')
25 else 21 else
26 - f.select(:configuration_to_clone_name, configuration_names, {:selected => selected}) 22 + f.select(:configuration_to_clone_name, kalibro_configuration_names, {:selected => selected})
27 end %> 23 end %>
28 <br/> 24 <br/>
29 25
30 -<%= required f.text_field(:name, :disabled => !(configuration.nil? || @article.id.nil?)) %> 26 +<%= required f.text_field(:name, :disabled => !(kalibro_configuration.nil? || @article.id.nil?)) %>
31 27
32 <%= f.text_field :description %><br/> 28 <%= f.text_field :description %><br/>
plugins/mezuro/views/cms/mezuro_plugin/_project_content.html.erb
1 <h1> <%= _(MezuroPlugin::ProjectContent.short_description) %> </h1> 1 <h1> <%= _(MezuroPlugin::ProjectContent.short_description) %> </h1>
2 2
3 <% 3 <%
  4 + @project = @article.title.nil? ? nil : @article.project
4 begin 5 begin
5 - @project = @article.title.nil? ? nil : Kalibro::Project.find_by_name(@article.title)  
6 - rescue  
7 - @project = nil 6 + @repository_types = Kalibro::Repository.repository_types.sort
  7 + @configuration_names = Kalibro::Configuration.all_names.sort
  8 + rescue Exception => exception
  9 + @article.errors.add_to_base(exception.message)
  10 + @repository_types = []
  11 + @configuration_names = []
8 end 12 end
9 %> 13 %>
10 14
@@ -20,18 +24,18 @@ @@ -20,18 +24,18 @@
20 <%= required f.text_field(:name) %> 24 <%= required f.text_field(:name) %>
21 <% end %> 25 <% end %>
22 26
23 -<%= f.text_field :license %><br/> 27 +<% selected = (@project.nil? ? "" : @project.license) %>
  28 +<%= required labelled_form_field _('License'),
  29 + f.select(:project_license, MezuroPlugin::Helpers::ContentViewerHelper.create_license_options ,{:selected => selected}) %><br/>
24 30
25 <%= f.text_field :description %><br/> 31 <%= f.text_field :description %><br/>
26 32
27 -<% @repository_types = Kalibro::Repository.repository_types.sort %>  
28 <% @selected = (@project.nil? ? @repository_types : @project.repository.type) %> 33 <% @selected = (@project.nil? ? @repository_types : @project.repository.type) %>
29 <%= required labelled_form_field _('Repository type'), 34 <%= required labelled_form_field _('Repository type'),
30 f.select(:repository_type, @repository_types, {:selected => @selected}) %><br/> 35 f.select(:repository_type, @repository_types, {:selected => @selected}) %><br/>
31 36
32 <%= required f.text_field(:repository_url) %><br/> 37 <%= required f.text_field(:repository_url) %><br/>
33 38
34 -<% @configuration_names = Kalibro::Configuration.all_names.sort %>  
35 <% @selected = (@project.nil? ? @configuration_names[0] : @project.configuration_name) %> 39 <% @selected = (@project.nil? ? @configuration_names[0] : @project.configuration_name) %>
36 40
37 <% if !@project.nil? && !@article.id.nil? %> 41 <% if !@project.nil? && !@article.id.nil? %>
plugins/mezuro/views/content_viewer/_module_result.rhtml
1 -<% unless @content.errors[:base].nil? %>  
2 - <%= @content.errors[:base] %>  
3 -<% else %>  
4 - <% the_module = @module_result.module %>  
5 - <% module_label = "#{the_module.name} (#{the_module.granularity})" %> 1 +<h5><%= _('Metric results for: ') + @module_label %> </h5>
6 2
7 - <h5><%= _('Metric results for: ') + module_label %> </h5>  
8 -  
9 - <hr/>  
10 - <div class="zoomable-image">  
11 - <table>  
12 - <thead>  
13 - <tr>  
14 - <th>Metric</th>  
15 - <th>Value</th>  
16 - <th>Weight</th>  
17 - <th>Threshold</th>  
18 - </tr>  
19 - </thead>  
20 - <tbody>  
21 - <% @module_result.metric_results.each do |metric_result| %>  
22 - <% range = metric_result.range %>  
23 - <% if !range.nil? %>  
24 - <tr>  
25 - <td><a href="#" data-show=".<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>"><%= metric_result.metric.name %></a></td>  
26 - <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td>  
27 - <td><%= metric_result.weight %></td>  
28 - <td style="background-color: #<%= range.color[2..-1] %>"><%= range.label %></td>  
29 - </tr>  
30 - <tr class="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" style="display: none;">  
31 - <td colspan="3">  
32 - <div id='historical-<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>'>  
33 - <a href="#" show-metric-history="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" data-module-name="<%= the_module.name %>" data-metric-name="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>"> <p style="text-indent: 3em;"> Get Historical Values </p> </a>  
34 - </div>  
35 - </td>  
36 - <td align="right">  
37 - <%= range.comments.nil? ? '' : range.comments %>  
38 - </td>  
39 - </tr>  
40 - <% end %> 3 +<hr/>
  4 +<div class="zoomable-image">
  5 +<table>
  6 + <thead>
  7 + <tr>
  8 + <th>Metric</th>
  9 + <th>Value</th>
  10 + <th>Weight</th>
  11 + <th>Threshold</th>
  12 + </tr>
  13 + </thead>
  14 + <tbody>
  15 + <% @module_result.metric_results.each do |metric_result| %>
  16 + <% range = metric_result.range %>
  17 + <% if !range.nil? %>
  18 + <tr>
  19 + <td><a href="#" show-metric-history="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" data-module-name="<%= @module.name %>"><%= metric_result.metric.name %></a></td>
  20 + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.format_grade(metric_result.value) %></td>
  21 + <td><%= metric_result.weight %></td>
  22 + <td style="background-color: #<%= range.color[2..-1] %>"><%= range.label %></td>
  23 + </tr>
  24 + <tr class="<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>" style="display: none;">
  25 + <td colspan="3">
  26 + <div id='historical-<%= MezuroPlugin::Helpers::ContentViewerHelper.format_name(metric_result) %>'>
  27 + </div>
  28 + </td>
  29 + <td align="right">
  30 + <%= range.comments.nil? ? '' : range.comments %>
  31 + </td>
  32 + </tr>
41 <% end %> 33 <% end %>
42 - </tbody>  
43 - <tfoot>  
44 - <tr>  
45 - <td colspan = "3">  
46 - <div id='historical-grade'></div>  
47 - </td>  
48 - <td align = "right">  
49 - <a href="#" show-grade-history="<%= @module_result.module.name %>" data-module-name="<%= the_module.name%>" >  
50 - <strong>  
51 - <%= _('Grade:') %>  
52 - <%= "%.02f" % @module_result.grade %>  
53 - </strong>  
54 - </a>  
55 - </td>  
56 - </tr>  
57 - </tfoot>  
58 - </table>  
59 - </div>  
60 -<% end %> 34 + <% end %>
  35 + </tbody>
  36 + <tfoot>
  37 + <tr>
  38 + <td colspan = "3">
  39 + <div id='historical-grade' style="display: none;"></div>
  40 + </td>
  41 + <td align = "right">
  42 + <a href="#" show-grade-history="<%= @module_result.module.name %>" data-module-name="<%= @module.name%>" >
  43 + <strong>
  44 + <%= _('Grade:') %>
  45 + <%= "%.02f" % @module_result.grade %>
  46 + </strong>
  47 + </a>
  48 + </td>
  49 + </tr>
  50 + </tfoot>
  51 +</table>
  52 +</div>
plugins/mezuro/views/content_viewer/_project_error.rhtml
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <p> 2 <p>
3 <%= "State when error ocurred: #{@project.state}" %> 3 <%= "State when error ocurred: #{@project.state}" %>
4 <br/> 4 <br/>
5 - <% error = @project.error %> 5 + <% error = @project.kalibro_error %>
6 <%= error.message %> 6 <%= error.message %>
7 <ul> 7 <ul>
8 <% error.stack_trace.each do |trace| %> 8 <% error.stack_trace.each do |trace| %>
plugins/mezuro/views/content_viewer/_project_result.rhtml
1 <% unless @content.errors[:base].nil? %> 1 <% unless @content.errors[:base].nil? %>
2 <%= @content.errors[:base] %> 2 <%= @content.errors[:base] %>
3 <% else %> 3 <% else %>
4 - <% form_for :project_date, :html=>{:id=>"project_history_date"} do |f| %>  
5 - <%= f.label :day, "Choose project date:" %>  
6 -  
7 - <table>  
8 - <tr>  
9 - <td>  
10 - Day  
11 - </td>  
12 - <td>  
13 - Month  
14 - </td>  
15 - <td>  
16 - Year  
17 - </td>  
18 - </tr>  
19 - <tr>  
20 - <td>  
21 - <%= f.text_field :day, :size => 1, :maxlength => 2, :placeholder =>"dd" %>  
22 - </td>  
23 - <td>  
24 - <%= f.text_field :month, :size => 1, :maxlength => 2, :placeholder =>"mm" %>  
25 - </td>  
26 - <td>  
27 - <%= f.text_field :year, :size => 1, :maxlength => 4, :placeholder =>"yyyy" %>  
28 - </td>  
29 - </tr>  
30 - </table>  
31 - <%= f.submit "Refresh" %>  
32 - <% end %>  
33 - 4 + <p> Choose a date to see specific project results: </p>
  5 + <div id="datepicker" data-date="<%= @project_result.date %>">
  6 + <input id="datepicker_field" style="display:none"/>
  7 + </div>
34 8
35 <h4><%= _('Last Result') %></h4> 9 <h4><%= _('Last Result') %></h4>
36 10
@@ -48,4 +22,18 @@ @@ -48,4 +22,18 @@
48 <td><%= @project_result.formatted_analysis_time %></td> 22 <td><%= @project_result.formatted_analysis_time %></td>
49 </tr> 23 </tr>
50 </table> 24 </table>
  25 +
  26 +
  27 + <script>
  28 + jQuery(document).ready(function($) {
  29 + $("#datepicker").datepicker({ altField: '#datepicker_field', showOn: 'button', dateFormat: "yy-mm-dd",
  30 + buttonImageOnly: true, buttonImage: '/images/calendar_date_select/calendar.png',
  31 + onSelect: function(dateText, inst) {
  32 + reloadProjectWithDate(dateText) } });
  33 + var date = jQuery("#datepicker").attr('data-date').substr(0,10);
  34 + $("#datepicker").datepicker( "setDate" , date );
  35 +
  36 + });
  37 + </script>
  38 +
51 <% end %> 39 <% end %>
plugins/mezuro/views/content_viewer/show_configuration.rhtml
1 <% @configuration_content = @page 1 <% @configuration_content = @page
2 -@configuration = @page.configuration %> 2 +@kalibro_configuration = @page.kalibro_configuration %>
  3 +<% unless @page.errors[:base].nil? %>
  4 + <% if @page.errors[:base] =~ /There is no configuration named/ %>
  5 + <h3>Warning:</h3>
  6 + <p>This Configuration doesn't exist on the Web Service. Do you want to <a href="/myprofile/<%= @page.profile.name %>/cms/destroy/<%= @page.id%>">delete</a> or <a href="/myprofile/<%= @page.profile.name %>/cms/edit/<%= @page.id%>">save it again</a>?</p>
  7 + <% else %>
  8 + <%= @page.errors[:base] %>
  9 + <% end %>
  10 +<% else %>
3 11
4 -<table id="project_info">  
5 - <tr>  
6 - <td><%= _('Name') %></td>  
7 - <td><%= @configuration.name %></td>  
8 - </tr>  
9 - <tr>  
10 - <td><%= _('Description') %></td>  
11 - <td><%= @configuration.description %></td>  
12 - </tr>  
13 -</table> 12 + <table id="project_info">
  13 + <tr>
  14 + <td><%= _('Name') %></td>
  15 + <td><%= @kalibro_configuration.name %></td>
  16 + </tr>
  17 + <tr>
  18 + <td><%= _('Description') %></td>
  19 + <td><%= @kalibro_configuration.description %></td>
  20 + </tr>
  21 + </table>
14 22
15 -<br/> 23 + <br/>
16 24
17 -<%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_myprofile",  
18 -:action => "choose_base_tool", :params => { :id => @configuration_content.id } %><br/> 25 + <%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_myprofile",
  26 + :action => "choose_base_tool", :params => { :id => @configuration_content.id } %><br/>
19 27
20 -<table>  
21 - <tr class="titles">  
22 - <td><h5>Metric Name</h5></td>  
23 - <td><h5>Collector Name</h5></td>  
24 - <td><h5>Metric Code</h5></td>  
25 - <td/><td/>  
26 - </tr>  
27 - <% @configuration.metric_configurations.each do |metric_configuration| %>  
28 - <tr class="metric">  
29 - <td><%= metric_configuration.metric.name %></td>  
30 - <% if metric_configuration.metric.instance_of? Kalibro::NativeMetric %>  
31 - <td>  
32 - <%= metric_configuration.metric.origin %>  
33 - </td>  
34 - <td><%= metric_configuration.code %></td>  
35 - <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_metric_configuration", :params =>  
36 - {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td>  
37 - <% else %>  
38 - <td>  
39 - Compound Metric  
40 - </td>  
41 - <td><%= metric_configuration.code %></td>  
42 - <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_compound_metric_configuration", :params =>  
43 - {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td>  
44 - <% end %>  
45 -  
46 - <td><%= link_to "Remove", :controller => "mezuro_plugin_myprofile", :action => "remove_metric_configuration", :params =>  
47 - {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td> 28 + <table>
  29 + <tr class="titles">
  30 + <td><h5>Metric Name</h5></td>
  31 + <td><h5>Collector Name</h5></td>
  32 + <td><h5>Metric Code</h5></td>
  33 + <td/><td/>
48 </tr> 34 </tr>
49 - <% end %>  
50 -</table> 35 + <% @kalibro_configuration.metric_configurations.each do |metric_configuration| %>
  36 + <tr class="metric">
  37 + <td><%= metric_configuration.metric.name %></td>
  38 + <% if metric_configuration.metric.instance_of? Kalibro::NativeMetric %>
  39 + <td>
  40 + <%= metric_configuration.metric.origin %>
  41 + </td>
  42 + <td><%= metric_configuration.code %></td>
  43 + <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_metric_configuration", :params =>
  44 + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td>
  45 + <% else %>
  46 + <td>
  47 + Compound Metric
  48 + </td>
  49 + <td><%= metric_configuration.code %></td>
  50 + <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_compound_metric_configuration", :params =>
  51 + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td>
  52 + <% end %>
  53 +
  54 + <td><%= link_to "Remove", :controller => "mezuro_plugin_myprofile", :action => "remove_metric_configuration", :params =>
  55 + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td>
  56 + </tr>
  57 + <% end %>
  58 + </table>
  59 +<% end %>
plugins/mezuro/views/content_viewer/show_project.rhtml
@@ -2,60 +2,58 @@ @@ -2,60 +2,58 @@
2 2
3 <% @project = @page.project %> 3 <% @project = @page.project %>
4 <% unless @page.errors[:base].nil? %> 4 <% unless @page.errors[:base].nil? %>
5 - <%= @page.errors[:base] %>  
6 -<% else %>  
7 -  
8 - <% if (@project==nil) %> 5 + <% if @page.errors[:base] =~ /There is no project named/ %>
9 <h3>Warning:</h3> 6 <h3>Warning:</h3>
10 <p>This project doesn't exist on the Web Service. Do you want to <a href="/myprofile/<%= @page.profile.name %>/cms/destroy/<%= @page.id%>">delete</a> or <a href="/myprofile/<%= @page.profile.name %>/cms/edit/<%= @page.id%>">save it again</a>?</p> 7 <p>This project doesn't exist on the Web Service. Do you want to <a href="/myprofile/<%= @page.profile.name %>/cms/destroy/<%= @page.id%>">delete</a> or <a href="/myprofile/<%= @page.profile.name %>/cms/edit/<%= @page.id%>">save it again</a>?</p>
11 <% else %> 8 <% else %>
  9 + <%= @page.errors[:base] %>
  10 + <% end %>
  11 +<% else %>
12 12
  13 + <table>
  14 + <tr>
  15 + <td><%= _('Name') %></td>
  16 + <td><%= @project.name %></td>
  17 + </tr>
  18 + <tr>
  19 + <td><%= _('License') %></td>
  20 + <td><%= @project.license %></td>
  21 + </tr>
  22 + <tr>
  23 + <td><%= _('Description') %></td>
  24 + <td><%= @project.description %></td>
  25 + </tr>
  26 + <tr>
  27 + <td><%= _('Repository type') %></td>
  28 + <td><%= @project.repository.type %></td>
  29 + </tr>
  30 + <tr>
  31 + <td><%= _('Repository address') %></td>
  32 + <td><%= @project.repository.address %></td>
  33 + </tr>
  34 + <tr>
  35 + <td><%= _('Configuration') %></td>
  36 + <td><%= @project.configuration_name %></td>
  37 + </tr>
  38 + <tr>
  39 + <td><%= _('Periodicity') %></td>
  40 + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@page.periodicity_in_days) %></td>
  41 + </tr>
  42 + <tr>
  43 + <td><%= _('Status')%></td>
  44 + <td>
  45 + <div id="project-state"><%= @project.state %></div>
  46 + <div id="msg-time"></div>
  47 + </td>
  48 + </tr>
  49 + </table>
13 50
14 - <table>  
15 - <tr>  
16 - <td><%= _('Name') %></td>  
17 - <td><%= @project.name %></td>  
18 - </tr>  
19 - <tr>  
20 - <td><%= _('License') %></td>  
21 - <td><%= @project.license %></td>  
22 - </tr>  
23 - <tr>  
24 - <td><%= _('Description') %></td>  
25 - <td><%= @project.description %></td>  
26 - </tr>  
27 - <tr>  
28 - <td><%= _('Repository type') %></td>  
29 - <td><%= @project.repository.type %></td>  
30 - </tr>  
31 - <tr>  
32 - <td><%= _('Repository address') %></td>  
33 - <td><%= @project.repository.address %></td>  
34 - </tr>  
35 - <tr>  
36 - <td><%= _('Configuration') %></td>  
37 - <td><%= @project.configuration_name %></td>  
38 - </tr>  
39 - <tr>  
40 - <td><%= _('Periodicity') %></td>  
41 - <td><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@page.periodicity_in_days) %></td>  
42 - </tr>  
43 - <tr>  
44 - <td><%= _('Status')%></td>  
45 - <td>  
46 - <div id="project-state"><%= @project.state %></div>  
47 - <div id="msg-time"></div>  
48 - </td>  
49 - </tr>  
50 - </table>  
51 -  
52 - <br /> 51 + <br />
53 52
54 - <div id="project-result" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>"  
55 - data-project-name="<%= @project.name %>">  
56 - </div>  
57 - <div id="project-tree"></div>  
58 - <div id="module-result">  
59 - </div>  
60 - <% end %> 53 + <div id="project-result" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>"
  54 + data-project-name="<%= @project.name %>">
  55 + </div>
  56 + <div id="project-tree"></div>
  57 + <div id="module-result">
  58 + </div>
61 <% end %> 59 <% 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 %> 41 + <%= f.text_field(:color, :id => "range_color", :value => @range.mezuro_color) %>
42 </td> 42 </td>
43 </tr> 43 </tr>
44 <tr> 44 <tr>
@@ -51,3 +51,11 @@ @@ -51,3 +51,11 @@
51 </tr> 51 </tr>
52 </table> 52 </table>
53 <%= f.submit "Save Range" %> 53 <%= f.submit "Save Range" %>
  54 +
  55 +<script>jQuery(document).ready(function($) {
  56 + $('#range_color').colorPicker({
  57 + onColorChange : function(id, newValue) {
  58 + jQuery('#range_color').val(newValue);
  59 + }
  60 + });
  61 +});</script>
plugins/mezuro/views/mezuro_plugin_myprofile/edit_compound_metric_configuration.html.erb
  1 +<script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script>
  2 +<script src="/plugins/mezuro/javascripts/colorPicker/jquery.colorPicker.min.js" type="text/javascript"></script>
  3 +<script src="/plugins/mezuro/javascripts/colorPicker/jquery.colorPicker.js" type="text/javascript"></script>
  4 +
1 <h2><%= @configuration_content.name %> Configuration</h2> 5 <h2><%= @configuration_content.name %> Configuration</h2>
2 6
3 <% form_for :metric_configuration, :url => {:action =>"update_compound_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %> 7 <% form_for :metric_configuration, :url => {:action =>"update_compound_metric_configuration", :controller => "mezuro_plugin_myprofile"}, :method => :get do |f| %>
plugins/mezuro/views/mezuro_plugin_myprofile/edit_metric_configuration.html.erb
1 <script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script> 1 <script src="/plugins/mezuro/javascripts/validations.js" type="text/javascript"></script>
  2 +<script src="/plugins/mezuro/javascripts/colorPicker/jquery.colorPicker.min.js" type="text/javascript"></script>
  3 +<script src="/plugins/mezuro/javascripts/colorPicker/jquery.colorPicker.js" type="text/javascript"></script>
2 4
3 <h2><%= @configuration_content.name %> Configuration</h2> 5 <h2><%= @configuration_content.name %> Configuration</h2>
4 6
@@ -84,3 +86,4 @@ @@ -84,3 +86,4 @@
84 <%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_myprofile", :id => @configuration_content.id, :metric_name => @metric.name} %> 86 <%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_myprofile", :id => @configuration_content.id, :metric_name => @metric.name} %>
85 <div id="range_form" style="display:none"></div> 87 <div id="range_form" style="display:none"></div>
86 88
  89 +
plugins/mezuro/views/mezuro_plugin_myprofile/error_page.html.erb 0 → 100644
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +<h2> An error occured: </h2>
  2 +<%= @message %>
  3 +<!-- The <%=h is for escaping the URL properly --!>
plugins/mezuro/views/mezuro_plugin_profile/error_page.html.erb 0 → 100644
@@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
  1 +<h2> An error occured: </h2>
  2 +<%= @message %>