Commit de980e6a3f829912aaad604c42c60e1800d7f829
Committed by
Paulo Meireles
1 parent
9aeb6dc2
Exists in
master
and in
28 other branches
[Mezuro] Draft to cloning configuration.
Showing
2 changed files
with
29 additions
and
28 deletions
Show diff stats
plugins/mezuro/lib/mezuro_plugin/configuration_content.rb
| ... | ... | @@ -26,6 +26,7 @@ class MezuroPlugin::ConfigurationContent < Article |
| 26 | 26 | @configuration ||= Kalibro::Configuration.find(self.configuration_id) |
| 27 | 27 | rescue Exception => exception |
| 28 | 28 | errors.add_to_base(exception.message) |
| 29 | + @configuration = nil | |
| 29 | 30 | end |
| 30 | 31 | @configuration |
| 31 | 32 | end |
| ... | ... | @@ -58,7 +59,19 @@ class MezuroPlugin::ConfigurationContent < Article |
| 58 | 59 | end |
| 59 | 60 | @description |
| 60 | 61 | end |
| 61 | - | |
| 62 | + | |
| 63 | + def configuration_to_clone_name | |
| 64 | + begin | |
| 65 | + @configuration_to_clone_name | |
| 66 | + rescue Exception => exception | |
| 67 | + nil | |
| 68 | + end | |
| 69 | + end | |
| 70 | + | |
| 71 | + def configuration_to_clone_name=(value) | |
| 72 | + @configuration_to_clone_name = (value == "None") ? nil : value | |
| 73 | + end | |
| 74 | + | |
| 62 | 75 | def metric_configurations |
| 63 | 76 | begin |
| 64 | 77 | @metric_configurations ||= Kalibro::MetricConfiguration.metric_configurations_of(configuration_id) |
| ... | ... | @@ -90,30 +103,25 @@ class MezuroPlugin::ConfigurationContent < Article |
| 90 | 103 | |
| 91 | 104 | def send_configuration_to_service |
| 92 | 105 | attributes = {:id => configuration_id, :name => name, :description => description} |
| 93 | -# if cloning_configuration? | |
| 94 | -# attributes[:metric_configuration] = configuration_to_clone.metric_configurations_hash | |
| 95 | -# end | |
| 96 | 106 | created_configuration = Kalibro::Configuration.create attributes |
| 97 | 107 | self.configuration_id = created_configuration.id |
| 108 | + clone_configuration if cloning_configuration? | |
| 98 | 109 | end |
| 99 | 110 | |
| 100 | 111 | def remove_configuration_from_service |
| 101 | - puts "aqui tem #{@configuration.inspect}" | |
| 102 | 112 | kalibro_configuration.destroy unless kalibro_configuration.nil? |
| 103 | 113 | end |
| 104 | 114 | |
| 105 | -=begin | |
| 106 | - def configuration_to_clone | |
| 107 | - @configuration_to_clone ||= find_configuration_to_clone | |
| 108 | - end | |
| 109 | - | |
| 110 | - def find_configuration_to_clone | |
| 111 | - (configuration_to_clone_name == "None") ? nil : Kalibro::Configuration.find_by_name(configuration_to_clone_name) | |
| 115 | + def configuration_to_clone_id | |
| 116 | + (configuration_to_clone_name.nil?) ? nil : configuration_names_and_ids.index(configuration_to_clone_name) | |
| 112 | 117 | end |
| 113 | 118 | |
| 114 | 119 | def cloning_configuration? |
| 115 | - configuration_to_clone.present? | |
| 120 | + configuration_to_clone_id.present? | |
| 121 | + end | |
| 122 | + | |
| 123 | + def clone_configuration | |
| 124 | + #por enquanto não clona | |
| 116 | 125 | end |
| 117 | -=end | |
| 118 | 126 | |
| 119 | 127 | end | ... | ... |
plugins/mezuro/views/cms/mezuro_plugin/_configuration_content.html.erb
| ... | ... | @@ -7,24 +7,17 @@ |
| 7 | 7 | |
| 8 | 8 | <%= error_messages_for 'kalibro_configuration' %> |
| 9 | 9 | |
| 10 | -<%= hidden_field_tag 'kalibro_configuration[profile_id]', profile.id %> | |
| 11 | -<%= hidden_field_tag 'id', @article.id %> | |
| 12 | 10 | |
| 13 | -<% # selected = (kalibro_configuration.nil? ? "None" : @article.configuration_to_clone_name) | |
| 14 | - %> | |
| 11 | +<%= hidden_field_tag 'configuration_content[profile_id]', profile.id %> | |
| 12 | +<%= hidden_field_tag 'id', @article.id %> | |
| 13 | +<%= hidden_field_tag 'configuration_id', @article.configuration_id %> | |
| 15 | 14 | |
| 16 | 15 | <%= required_fields_message %> |
| 17 | 16 | |
| 18 | -<% | |
| 19 | -=begin | |
| 20 | -required labelled_form_field _('Clone Configuration'), | |
| 21 | -if !kalibro_configuration.nil? && !@article.id.nil? | |
| 22 | - f.select(:configuration_to_clone_name, kalibro_configuration_names, {:selected => selected}, :disabled => 'true') | |
| 23 | -else | |
| 24 | - f.select(:configuration_to_clone_name, kalibro_configuration_names, {:selected => selected}) | |
| 25 | -end | |
| 26 | -=end | |
| 27 | -%> | |
| 17 | +<%= if kalibro_configuration.nil? | |
| 18 | + required labelled_form_field _('Clone Configuration'), | |
| 19 | + f.select(:configuration_to_clone_name, kalibro_configuration_names) | |
| 20 | +end %> | |
| 28 | 21 | <br/> |
| 29 | 22 | |
| 30 | 23 | <%= required f.text_field(:name) %> | ... | ... |