Mohammed Morsi
2009-Sep-23 21:06 UTC
[Ovirt-devel] [PATCH server] consolidated network & routing info ui's
created/edit network information is all specified on one simpler form --- src/app/controllers/network_controller.rb | 27 +++++++++++++++---- src/app/models/bonding.rb | 2 +- src/app/models/network.rb | 2 +- src/app/models/nic.rb | 2 +- src/app/views/network/_form.rhtml | 15 +++++++++++ src/app/views/network/_ip_address_form.rhtml | 8 +++++- .../views/network/edit_network_ip_addresses.rhtml | 13 --------- src/app/views/network/show.rhtml | 4 --- 8 files changed, 46 insertions(+), 27 deletions(-) delete mode 100644 src/app/views/network/edit_network_ip_addresses.rhtml diff --git a/src/app/controllers/network_controller.rb b/src/app/controllers/network_controller.rb index c477c56..2f082a8 100644 --- a/src/app/controllers/network_controller.rb +++ b/src/app/controllers/network_controller.rb @@ -55,6 +55,12 @@ class NetworkController < ApplicationController end def create + # create the ip address if specified + address = params[:ip_address][:address] + unless address.nil? || address == "" + params[:network][:ip_addresses] = [ IpAddress.new(params[:ip_address]) ] + end + alert = svc_create(params[:network]) render :json => { :object => "network", :success => true, :alert => alert } end @@ -68,6 +74,21 @@ class NetworkController < ApplicationController def update alert = svc_update(params[:id], params[:network]) + + # create or update the ip address if specified + address = params[:ip_address][:address] + if !address.nil? && address != "" + if params[:ip_address][:id].nil? + svc_create_ip_address(params[:ip_address]) + else + svc_update_ip_address(params[:ip_address][:id], params[:ip_address]) + end + + # delete ip address if not specified + elsif params[:ip_address][:id] + svc_destroy_ip_address(params[:ip_address][:id]) + end + render :json => { :object => "network", :success => true, :alert => alert } end @@ -92,12 +113,6 @@ class NetworkController < ApplicationController :alert => "Networks were successfully deleted." } end - def edit_network_ip_addresses - svc_modify(params[:id]) - render :layout => 'popup' - end - - ########################## Ip Address related actions def ip_addresses_json diff --git a/src/app/models/bonding.rb b/src/app/models/bonding.rb index 2dd84fa..d63d5fe 100644 --- a/src/app/models/bonding.rb +++ b/src/app/models/bonding.rb @@ -35,7 +35,7 @@ class Bonding < ActiveRecord::Base belongs_to :host belongs_to :bonding_type belongs_to :vlan - has_many :ip_addresses, :dependent => :destroy + has_many :ip_addresses, :dependent => :destroy # FIXME should really be a has_one # FIXME bondings_nics table should just be replaced with # bonding_id column in nics table, and relationship changed diff --git a/src/app/models/network.rb b/src/app/models/network.rb index 89f9876..22e5692 100644 --- a/src/app/models/network.rb +++ b/src/app/models/network.rb @@ -18,7 +18,7 @@ class Network < ActiveRecord::Base belongs_to :boot_type - has_many :ip_addresses, :dependent => :destroy + has_many :ip_addresses, :dependent => :destroy # FIXME should really be a has_one has_and_belongs_to_many :usages, :join_table => 'networks_usages' diff --git a/src/app/models/nic.rb b/src/app/models/nic.rb index 51425bc..22304e9 100644 --- a/src/app/models/nic.rb +++ b/src/app/models/nic.rb @@ -23,7 +23,7 @@ class Nic < ActiveRecord::Base belongs_to :network - has_many :ip_addresses, :dependent => :destroy + has_many :ip_addresses, :dependent => :destroy # FIXME should really be a has_one # FIXME bondings_nics table should just be replaced with # bonding_id column in nics table, and relationship changed diff --git a/src/app/views/network/_form.rhtml b/src/app/views/network/_form.rhtml index 6c67a0e..f26dc24 100644 --- a/src/app/views/network/_form.rhtml +++ b/src/app/views/network/_form.rhtml @@ -34,6 +34,16 @@ {:style=>"width:250px;"} %> </div> +<br/> + +<div class="form_heading clickable closed">Routing Info</div> +<div class="network_form_section" style="display:none;"> +<% @parent_type = 'network' %> +<% @ip_address = @network.ip_addresses[0] if @network && @network.ip_addresses.size > 0 %> +<%= render :partial => 'ip_address_form', + :locals => { :parent_type => 'network' } %> +</div> + <script type="text/javascript"> $("#network_type").change(function () { @@ -43,4 +53,9 @@ $("#network_type").change(function () { $("#vlan_options").hide(); } }).trigger('change'); +$('#network_form .form_heading').bind('click', function(e){ + if(this === e.target){ + $(this).toggleClass('open').toggleClass('closed').next().slideToggle('slow'); + } +}); </script> diff --git a/src/app/views/network/_ip_address_form.rhtml b/src/app/views/network/_ip_address_form.rhtml index a3b3a95..0abc6d9 100644 --- a/src/app/views/network/_ip_address_form.rhtml +++ b/src/app/views/network/_ip_address_form.rhtml @@ -15,7 +15,13 @@ <div class="static_ip_common_options"> - <div class="selected_nic_bonding_left">IP Address</div> + <div class="selected_nic_bonding_left"> + <% if @parent_type == 'network' %> + Network Address + <% else %> + Ip Address + <% end %> + </div> <div class="selected_nic_bonding_right"> <%= text_field_with_label "", "ip_address", "address" %> </div> diff --git a/src/app/views/network/edit_network_ip_addresses.rhtml b/src/app/views/network/edit_network_ip_addresses.rhtml deleted file mode 100644 index 78d6ad1..0000000 --- a/src/app/views/network/edit_network_ip_addresses.rhtml +++ /dev/null @@ -1,13 +0,0 @@ -<%- content_for :title do -%> - Edit Network Routing Info -<%- end -%> -<%- content_for :description do -%> -<%- end -%> - -<%= render :partial => 'ip_addresses_form', - :locals => { :parent_type => 'network', - :parent_id => @network.id } %> - -<div id="ip_addresses_footer" class="popup-content-footer"> - <%= ok_footer %> -</div> diff --git a/src/app/views/network/show.rhtml b/src/app/views/network/show.rhtml index 02ad25e..d2f02f7 100644 --- a/src/app/views/network/show.rhtml +++ b/src/app/views/network/show.rhtml @@ -6,10 +6,6 @@ <%= link_to image_tag("icon_edit_11px.png") + "Edit", {:action => 'edit', :id => @network.id }, :rel=>"facebox[.bolder]", :class=>"selection_facebox" %> - - <%= link_to image_tag("icon_edit_11px.png") + "Edit Routing Info", - {:action => 'edit_network_ip_addresses', :id => @network.id }, - :rel=>"facebox[.bolder]", :class=>"selection_facebox" %> <%- end -%> <div class="selection_key"> -- 1.6.0.6
Possibly Parallel Threads
- [PATCH server] use service layer for Network controller.
- [PATCH server] add network QMF apis. (still in progress)
- [PATCH server] Add network QMF apis.
- [PATCH server] don't add nil key to failures hash for PartialSuccessError handling.
- [PATCH server] new host networking wui