Commit 62bff3591eebf05d920c3254e64ba5e685a1dbd8
Committed by
Alessandro Palmeira
1 parent
88490e5c
Exists in
staging
and in
42 other branches
[Mezuro] Refactoring ranges and metric configuration saving
Showing
1 changed file
with
15 additions
and
17 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
| ... | ... | @@ -64,14 +64,14 @@ class MezuroPluginProfileController < ProfileController |
| 64 | 64 | |
| 65 | 65 | def create_metric_configuration |
| 66 | 66 | @configuration_name = params[:configuration_name] |
| 67 | - metric_configuration = set_metric_configuration(params) | |
| 67 | + metric_configuration = new_metric_configuration_instance | |
| 68 | 68 | Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name) |
| 69 | 69 | redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" |
| 70 | 70 | end |
| 71 | 71 | |
| 72 | 72 | def update_metric_configuration |
| 73 | 73 | @configuration_name = params[:configuration_name] |
| 74 | - metric_configuration = set_metric_configuration(params) | |
| 74 | + metric_configuration = new_metric_configuration_instance | |
| 75 | 75 | Kalibro::Client::MetricConfigurationClient.new.save(metric_configuration, @configuration_name) |
| 76 | 76 | redirect_to "/#{profile.identifier}/#{@configuration_name.downcase.gsub(/\s/, '-')}" |
| 77 | 77 | end |
| ... | ... | @@ -82,24 +82,13 @@ class MezuroPluginProfileController < ProfileController |
| 82 | 82 | end |
| 83 | 83 | |
| 84 | 84 | def create_range |
| 85 | - @range = Kalibro::Entities::Range.new | |
| 86 | - @range.beginning = params[:range][:beginning] | |
| 87 | - @range.end = params[:range][:end] | |
| 88 | - @range.label = params[:range][:label] | |
| 89 | - @range.grade = params[:range][:grade] | |
| 90 | - @range.color = params[:range][:color] | |
| 91 | - @range.comments = params[:range][:comments] | |
| 92 | - | |
| 85 | + @range = new_range_instance | |
| 93 | 86 | configuration_name = params[:configuration_name] |
| 94 | 87 | metric_name = params[:metric_name] |
| 95 | - | |
| 96 | 88 | metric_configuration_client = Kalibro::Client::MetricConfigurationClient.new |
| 97 | 89 | metric_configuration = metric_configuration_client.metric_configuration(configuration_name, metric_name) |
| 98 | - | |
| 99 | 90 | metric_configuration.add_range(@range) |
| 100 | - | |
| 101 | - metric_configuration_client.save(metric_configuration, configuration_name) | |
| 102 | - | |
| 91 | + #metric_configuration_client.save(metric_configuration, configuration_name) | |
| 103 | 92 | end |
| 104 | 93 | |
| 105 | 94 | def remove_metric_configuration |
| ... | ... | @@ -111,7 +100,7 @@ class MezuroPluginProfileController < ProfileController |
| 111 | 100 | |
| 112 | 101 | private |
| 113 | 102 | |
| 114 | - def set_metric_configuration(params) #FIXME isso foi feito para evitar duplicar o codigo de create e update metric configuration, faça de um jeito melhor | |
| 103 | + def new_metric_configuration_instance | |
| 115 | 104 | metric_configuration = Kalibro::Entities::MetricConfiguration.new |
| 116 | 105 | metric_configuration.metric = Kalibro::Entities::NativeMetric.new |
| 117 | 106 | metric_configuration.metric.name = params[:metric][:name] |
| ... | ... | @@ -122,9 +111,18 @@ class MezuroPluginProfileController < ProfileController |
| 122 | 111 | metric_configuration.code = params[:metric_configuration][:code] |
| 123 | 112 | metric_configuration.weight = params[:metric_configuration][:weight] |
| 124 | 113 | metric_configuration.aggregation_form = params[:metric_configuration][:aggregation] |
| 125 | - | |
| 126 | 114 | metric_configuration |
| 127 | 115 | end |
| 128 | 116 | |
| 117 | + def new_range_instance | |
| 118 | + range = Kalibro::Entities::Range.new | |
| 119 | + range.beginning = params[:range][:beginning] | |
| 120 | + range.end = params[:range][:end] | |
| 121 | + range.label = params[:range][:label] | |
| 122 | + range.grade = params[:range][:grade] | |
| 123 | + range.color = params[:range][:color] | |
| 124 | + range.comments = params[:range][:comments] | |
| 125 | + range | |
| 126 | + end | |
| 129 | 127 | end |
| 130 | 128 | ... | ... |