diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d763c225da7..e905731a07c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,7 +10,6 @@ //= require services/miq_db_backup_service //= require directives/scheduler/updateDropdownForFilter //= require directives/scheduler/updateDropdownForTimer -//= require directives/miq_calendar //= require directives/miqrequired //= require directives/checkchange //= require directives/verifypasswd @@ -18,6 +17,8 @@ //= require directives/repository/valid_unc_path //= require services/miq_service //= require services/timer_option_service +//= require controllers/angular-bootstrap/DatepickerCtrl +//= require controllers/host/host_form_controller //= require controllers/provider_foreman/provider_foreman_form_controller //= require controllers/repository/repository_form_controller //= require controllers/retirement/retirement_form_controller diff --git a/app/controllers/host_controller.rb b/app/controllers/host_controller.rb index 00554fffd9a..1d379c9ce2a 100644 --- a/app/controllers/host_controller.rb +++ b/app/controllers/host_controller.rb @@ -250,34 +250,31 @@ def start def new assert_privileges("host_new") @host = Host.new - set_form_vars @in_a_form = true drop_breadcrumb( {:name=>"Add New Host", :url=>"/host/new"} ) end def create assert_privileges("host_new") - return unless load_edit("host_edit__new") - get_form_vars case params[:button] when "cancel" render :update do |page| page.redirect_to :action=>'show_list', :flash_msg=>_("Add of new %s was cancelled by the user") % ui_lookup(:model=>"Host") end when "add" - add_host = Host.new - set_record_vars(add_host, :validate) # Set the record variables, but don't save - add_host.vmm_vendor = "unknown" - if valid_record?(add_host) && add_host.save - set_record_vars(add_host) # Save the authentication records for this host - AuditEvent.success(build_created_audit(add_host, @edit)) + @host = Host.new + set_record_vars(@host, :validate) # Set the record variables, but don't save + @host.vmm_vendor = "unknown" + if valid_record?(@host) && @host.save + set_record_vars(@host) # Save the authentication records for this host + AuditEvent.success(build_created_audit(@host, @edit)) render :update do |page| - page.redirect_to :action=>'show_list', :flash_msg=>_("%{model} \"%{name}\" was added") % {:model=>ui_lookup(:model=>"Host"), :name=>add_host.name} + page.redirect_to :action=>'show_list', :flash_msg=>_("%{model} \"%{name}\" was added") % {:model=>ui_lookup(:model=>"Host"), :name=>@host.name} end else @in_a_form = true - @edit[:errors].each { |msg| add_flash(msg, :error) } - add_host.errors.each do |field,msg| + @errors.each { |msg| add_flash(msg, :error) } + @host.errors.each do |field,msg| add_flash("#{field.to_s.capitalize} #{msg}", :error) end drop_breadcrumb( {:name=>"Add New Host", :url=>"/host/new"} ) @@ -306,7 +303,6 @@ def edit assert_privileges("host_edit") if session[:host_items].nil? @host = find_by_id_filtered(Host, params[:id]) - set_form_vars @in_a_form = true session[:changed] = false drop_breadcrumb( {:name=>"Edit Host '#{@host.name}'", :url=>"/host/edit/#{@host.id}"} ) @@ -318,16 +314,15 @@ def edit else @host = Host.new end - set_form_vars @changed = true @showlinks = true @in_a_form = true - @edit[:hostitems] = Array.new - hostitems = Host.find(session[:host_items]).sort_by(&:name) # Get the db records that are being tagged - @edit[:selected_hosts] = { nil => "" } + @hostitems = Array.new + hostitems = Host.find(session[:host_items]).sort{|a,b| a.name <=> b.name} # Get the db records that are being tagged + @selected_hosts = { nil => "" } hostitems.each do |h| - @edit[:selected_hosts][h.id] = h.name - @edit[:hostitems].push(h.id) + @selected_hosts[h.id] = h.name + @hostitems.push(h.id) end build_targets_hash(hostitems) @view = get_db_view(Host) # Instantiate the MIQ Report view object @@ -335,63 +330,9 @@ def edit end end - # AJAX driven routine to check for changes in ANY field on the form - def form_field_changed - return unless load_edit("host_edit__#{params[:id]}") - get_form_vars - changed = (@edit[:new] != @edit[:current]) - - render :update do |page| # Use JS to update the display - if changed != session[:changed] - session[:changed] = changed - unless params[:id] == "new" - page << javascript_for_miq_button_visibility(changed) - end - end - unless session[:host_items].nil? - page << "miqButtons('show');" - end - if @edit[:default_verify_status] != session[:host_default_verify_status] - session[:host_default_verify_status] = @edit[:default_verify_status] - if @edit[:default_verify_status] - page << "miqValidateButtons('show', 'default_');" - else - page << "miqValidateButtons('hide', 'default_');" - end - end - if @edit[:remote_verify_status] != session[:host_remote_verify_status] - session[:host_remote_verify_status] = @edit[:remote_verify_status] - if @edit[:remote_verify_status] - page << "miqValidateButtons('show', 'remote_');" - else - page << "miqValidateButtons('hide', 'remote_');" - end - end - if @edit[:ws_verify_status] != session[:host_ws_verify_status] - session[:host_ws_verify_status] = @edit[:ws_verify_status] - if @edit[:ws_verify_status] - page << "miqValidateButtons('show', 'ws_');" - else - page << "miqValidateButtons('hide', 'ws_');" - end - end - if @edit[:ipmi_verify_status] != session[:host_ipmi_verify_status] - session[:host_ipmi_verify_status] = @edit[:ipmi_verify_status] - if @edit[:ipmi_verify_status] - page << "miqValidateButtons('show', 'ipmi_');" - else - page << "miqValidateButtons('hide', 'ipmi_');" - end - end - end - end - def update assert_privileges("host_edit") - id = params[:id] || "new" - return unless load_edit("host_edit__#{id}") - get_form_vars - changed = (@edit[:new] != @edit[:current]) + @host = find_by_id_filtered(Host, params[:id]) case params[:button] when "cancel" session[:edit] = nil # clean out the saved info @@ -412,13 +353,15 @@ def update when "save" if session[:host_items].nil? - update_host = find_by_id_filtered(Host, params[:id]) + @host = find_by_id_filtered(Host, params[:id]) valid_host = find_by_id_filtered(Host, params[:id]) + edit = {:current => @host.attributes.clone } set_record_vars(valid_host, :validate) # Set the record variables, but don't save - if valid_record?(valid_host) && set_record_vars(update_host) && update_host.save - add_flash(_("%{model} \"%{name}\" was saved") % {:model=>ui_lookup(:model=>"host"), :name=>update_host.name}) + edit[:new] = @host.attributes.clone + if valid_record?(valid_host) && set_record_vars(@host) && @host.save + add_flash(_("%{model} \"%{name}\" was saved") % {:model=>ui_lookup(:model=>"host"), :name=>@host.name}) @breadcrumbs.pop if @breadcrumbs - AuditEvent.success(build_saved_audit(update_host, @edit)) + AuditEvent.success(build_saved_audit(@host, edit)) session[:edit] = nil # clean out the saved info session[:flash_msgs] = @flash_array.dup # Put msgs in session for next transaction render :update do |page| @@ -426,14 +369,12 @@ def update end return else - @edit[:errors].each { |msg| add_flash(msg, :error) } - update_host.errors.each do |field,msg| + @errors.each { |msg| add_flash(msg, :error) } + @host.errors.each do |field,msg| add_flash("#{field.to_s.capitalize} #{msg}", :error) end drop_breadcrumb( {:name=>"Edit Host '#{@host.name}'", :url=>"/host/edit/#{@host.id}"} ) @in_a_form = true - session[:changed] = changed - @changed = true render :update do |page| page.replace("flash_msg_div", :partial=>"layouts/flash_msg") end @@ -452,8 +393,6 @@ def update else drop_breadcrumb( {:name=>"Edit Host '#{@host.name}'", :url=>"/host/edit/#{@host.id}"} ) @in_a_form = true - session[:changed] = changed - @changed = true #redirect_to :action => 'edit', :flash_msg=>@error, :flash_error =>true render :update do |page| page.replace("flash_msg_div", :partial=>"layouts/flash_msg") @@ -469,8 +408,8 @@ def update page.redirect_to :action=>'edit', :id=>@host.id.to_s end when "validate" - if @edit[:validate_against] #if editing credentials for multi host - verify_host = find_by_id_filtered(Host, @edit[:validate_against].to_i) + if @validate_against #if editing credentials for multi host + verify_host = find_by_id_filtered(Host, @validate_against.to_i) else verify_host = find_by_id_filtered(Host, params[:id]) end @@ -627,6 +566,50 @@ def button end end + def host_form_fields + assert_privileges("host_edit") + host = find_by_id_filtered(Host, params[:id]) + + host_hash = { + :name => host.name, + :hostname => host.hostname, + :ipaddress => host.ipaddress, + :ipmi_address => host.ipmi_address, + :custom_1 => host.custom_1, + :user_assigned_os => host.user_assigned_os, + :mac_address => host.mac_address, + :default_userid => host.authentication_userid.to_s, + :default_password => host.authentication_password.to_s, + :default_verify => host.authentication_password.to_s, + :remote_userid => host.has_authentication_type?(:remote) ? host.authentication_userid(:remote).to_s : "", + :remote_password => host.has_authentication_type?(:remote) ? host.authentication_password(:remote).to_s : "", + :remote_verify => host.has_authentication_type?(:remote) ? host.authentication_password(:remote).to_s : "", + :ws_userid => host.has_authentication_type?(:ws) ? host.authentication_userid(:ws).to_s : "", + :ws_password => host.has_authentication_type?(:ws) ? host.authentication_password(:ws).to_s : "", + :ws_verify => host.has_authentication_type?(:ws) ? host.authentication_password(:ws).to_s : "", + :ipmi_userid => host.has_authentication_type?(:ipmi) ? host.authentication_userid(:ipmi).to_s : "", + :ipmi_password => host.has_authentication_type?(:ipmi) ? host.authentication_password(:ipmi).to_s : "", + :ipmi_verify => host.has_authentication_type?(:ipmi) ? host.authentication_password(:ipmi).to_s : "", + } + + # # Clear saved verify status flags + session[:host_default_verify_status] = nil + session[:host_remote_verify_status] = nil + session[:host_ws_verify_status] = nil + session[:host_ipmi_verify_status] = nil + @validate_against = session[:edit][:validate_against] if session[:edit] && session[:edit][:validate_against] && params[:button] != "reset" #if editing credentials for multi host + + if session[:host_items].nil? + set_verify_status(host_hash) + else + set_credentials_verify_status(@validate_against, host_hash) if @validate_against + end + + # @edit[:current] = @edit[:new].dup + # @edit[:edittype] = params[:edittype] == nil ? "basic" : params[:edittype] + render :json => host_hash + end + private ############################ def breadcrumb_name(_model) @@ -772,38 +755,38 @@ def add_miq_scsi_luns_nodes(target) # Validate the host record fields def valid_record?(host) valid = true - @edit[:errors] = Array.new - if !host.authentication_userid.blank? && @edit[:new][:password] != @edit[:new][:verify] - @edit[:errors].push("Default Password and Verify Password fields do not match") + @errors = Array.new + if !host.authentication_userid.blank? && params[:password] != params[:verify] + @errors.push("Default Password and Verify Password fields do not match") valid = false @tabnum = "1" end if host.authentication_userid.blank? && (!host.authentication_userid(:remote).blank? || !host.authentication_userid(:ws).blank?) - @edit[:errors].push("Default Username must be entered if a Remote Login or Web Services Username is entered") + @errors.push("Default User ID must be entered if a Remote Login or Web Services User ID is entered") valid = false @tabnum = "1" end - if !host.authentication_userid(:remote).blank? && @edit[:new][:remote_password] != @edit[:new][:remote_verify] - @edit[:errors].push("Remote Login Password and Verify Password fields do not match") + if !host.authentication_userid(:remote).blank? && params[:remote_password] != params[:remote_verify] + @errors.push("Remote Login Password and Verify Password fields do not match") valid = false @tabnum ||= "2" end - if !host.authentication_userid(:ws).blank? && @edit[:new][:ws_password] != @edit[:new][:ws_verify] - @edit[:errors].push("Web Services Password and Verify Password fields do not match") + if !host.authentication_userid(:ws).blank? && params[:ws_password] != params[:ws_verify] + @errors.push("Web Services Password and Verify Password fields do not match") valid = false @tabnum ||= "3" end if !host.authentication_userid(:ipmi).blank? && @edit[:new][:ipmi_password] != @edit[:new][:ipmi_verify] - @edit[:errors].push("IPMI Password and Verify Password fields do not match") + @errors.push("IPMI Password and Verify Password fields do not match") valid = false @tabnum ||= "4" end if params[:ws_port] && !(params[:ws_port] =~ /^\d+$/) - @edit[:errors].push("Web Services Listen Port must be numeric") + @errors.push("Web Services Listen Port must be numeric") valid = false end if params[:log_wrapsize] && (!(params[:log_wrapsize] =~ /^\d+$/) || params[:log_wrapsize].to_i == 0) - @edit[:errors].push("Log Wrap Size must be numeric and greater than zero") + @errors.push("Log Wrap Size must be numeric and greater than zero") valid = false end return valid @@ -858,122 +841,85 @@ def set_form_vars @edit[:edittype] = params[:edittype] == nil ? "basic" : params[:edittype] end - # Get variables from edit form - def get_form_vars - @host = @edit[:host_id] ? Host.find_by_id(@edit[:host_id]) : Host.new - - @edit[:new][:name] = params[:name] if params[:name] - @edit[:new][:hostname] = params[:hostname] if params[:hostname] - @edit[:new][:ipmi_address] = params[:ipmi_address] if params[:ipmi_address] - @edit[:new][:mac_address] = params[:mac_address] if params[:mac_address] - @edit[:new][:custom_1] = params[:custom_1] if params[:custom_1] - @edit[:new][:user_assigned_os] = params[:user_assigned_os] if params[:user_assigned_os] - @edit[:new][:user_assigned_os] = nil if @edit[:new][:user_assigned_os] == "" - -# @edit[:new][:scan_frequency] = params[:scan_frequency][:days] .to_i * 3600 * 24 + params[:scan_frequency][:hours].to_i * 3600 if params[:scan_frequency] -# Replaced above line in Sprint 34 to remove hours setting - @edit[:new][:scan_frequency] = params[:scan_frequency][:days] .to_i * 3600 * 24 if params[:scan_frequency] - - @edit[:new][:default_userid] = params[:default_userid] if params[:default_userid] - @edit[:new][:default_password] = params[:default_password] if params[:default_password] - @edit[:new][:default_verify] = params[:default_verify] if params[:default_verify] - - @edit[:new][:remote_userid] = params[:remote_userid] if params[:remote_userid] - @edit[:new][:remote_password] = params[:remote_password] if params[:remote_password] - @edit[:new][:remote_verify] = params[:remote_verify] if params[:remote_verify] - - @edit[:new][:ws_userid] = params[:ws_userid] if params[:ws_userid] - @edit[:new][:ws_password] = params[:ws_password] if params[:ws_password] - @edit[:new][:ws_verify] = params[:ws_verify] if params[:ws_verify] - - @edit[:new][:ipmi_userid] = params[:ipmi_userid] if params[:ipmi_userid] - @edit[:new][:ipmi_password] = params[:ipmi_password] if params[:ipmi_password] - @edit[:new][:ipmi_verify] = params[:ipmi_verify] if params[:ipmi_verify] - - @edit[:validate_against] = params[:validate_id] if params[:validate_id] #if editing credentials for multi host - if session[:host_items].nil? - set_verify_status - else - set_credentials_verify_status(@edit[:validate_against]) if @edit[:validate_against] - end - end - - def set_verify_status - if @edit[:new][:default_userid].blank? || @edit[:new][:hostname].blank? - @edit[:default_verify_status] = false + def set_verify_status(host) + if host[:default_userid].blank? || host[:hostname].blank? + host[:default_verify_status] = false else - @edit[:default_verify_status] = (@edit[:new][:default_password] == @edit[:new][:default_verify]) + host[:default_verify_status] = (host[:default_password] == host[:default_verify]) end - if @edit[:new][:remote_userid].blank? || @edit[:new][:hostname].blank? - @edit[:remote_verify_status] = false + if host[:remote_userid].blank? || host[:hostname].blank? + host[:remote_verify_status] = false else - @edit[:remote_verify_status] = (@edit[:new][:remote_password] == @edit[:new][:remote_verify]) + host[:remote_verify_status] = (host[:remote_password] == host[:remote_verify]) end - if @edit[:new][:ws_userid].blank? || @edit[:new][:hostname].blank? - @edit[:ws_verify_status] = false + if host[:ws_userid].blank? || host[:hostname].blank? + host[:ws_verify_status] = false else - @edit[:ws_verify_status] = (@edit[:new][:ws_password] == @edit[:new][:ws_verify]) + host[:ws_verify_status] = (host[:ws_password] == host[:ws_verify]) end - if @edit[:new][:ipmi_userid].blank? || @edit[:new][:ipmi_address].blank? - @edit[:ipmi_verify_status] = false + if host[:ipmi_userid].blank? || host[:ipmi_address].blank? + host[:ipmi_verify_status] = false else - @edit[:ipmi_verify_status] = (@edit[:new][:ipmi_password] == @edit[:new][:ipmi_verify]) + host[:ipmi_verify_status] = (host[:ipmi_password] == host[:ipmi_verify]) end end - def set_credentials_verify_status(id) + def set_credentials_verify_status(id, host_hash) if id.to_i == 0 - @edit[:default_verify_status] = @edit[:ws_verify_status] = @edit[:remote_verify_status]= @edit[:ipmi_verify_status] = false + host_hash[:default_verify_status] = + host_hash[:ws_verify_status] = + host_hash[:remote_verify_status] = + host_hash[:ipmi_verify_status] = false else host = find_by_id_filtered(Host, id.to_i) - if @edit[:new][:default_userid].blank? || host.hostname.blank? - @edit[:default_verify_status] = false + if host_hash[:default_userid].blank? || host.hostname.blank? + host_hash[:default_verify_status] = false else - @edit[:default_verify_status] = (@edit[:new][:default_password] == @edit[:new][:default_verify]) + host_hash[:default_verify_status] = (host_hash[:default_password] == host_hash[:default_verify]) end - if @edit[:new][:remote_userid].blank? || host.hostname.blank? - @edit[:remote_verify_status] = false + if host_hash[:remote_userid].blank? || host.hostname.blank? + host_hash[:remote_verify_status] = false else - @edit[:remote_verify_status] = (@edit[:new][:remote_password] == @edit[:new][:remote_verify]) + host_hash[:remote_verify_status] = (host_hash[:remote_password] == host_hash[:remote_verify]) end - if @edit[:new][:ws_userid].blank? || host.hostname.blank? - @edit[:ws_verify_status] = false + if host_hash[:ws_userid].blank? || host.hostname.blank? + host_hash[:ws_verify_status] = false else - @edit[:ws_verify_status] = (@edit[:new][:ws_password] == @edit[:new][:ws_verify]) + host_hash[:ws_verify_status] = (host_hash[:ws_password] == host_hash[:ws_verify]) end - if @edit[:new][:ipmi_userid].blank? || host.ipmi_address.blank? - @edit[:ipmi_verify_status] = false + if host_hash[:ipmi_userid].blank? || host.ipmi_address.blank? + host_hash[:ipmi_verify_status] = false else - @edit[:ipmi_verify_status] = (@edit[:new][:ipmi_password] == @edit[:new][:ipmi_verify]) + host_hash[:ipmi_verify_status] = (host_hash[:ipmi_password] == host_hash[:ipmi_verify]) end end end # Set record variables to new values def set_record_vars(host, mode = nil) - host.name = @edit[:new][:name] - host.hostname = @edit[:new][:hostname].to_s.strip - host.ipmi_address = @edit[:new][:ipmi_address] - host.mac_address = @edit[:new][:mac_address] - host.custom_1 = @edit[:new][:custom_1] unless mode == :validate - host.user_assigned_os = @edit[:new][:user_assigned_os] - host.scan_frequency = @edit[:new][:scan_frequency] + host.name = params[:name] + host.hostname = params[:hostname] + host.ipaddress = params[:ipaddress] + host.ipmi_address = params[:ipmi_address] + host.mac_address = params[:mac_address] + host.custom_1 = params[:custom_1] + host.user_assigned_os = params[:user_assigned_os] # creds = {:default=>{:userid=>nil, :password=>nil}, # :remote=>{:userid=>nil, :password=>nil}, # :ws=>{:userid=>nil, :password=>nil}, # :ipmi=>{:userid=>nil, :password=>nil}} creds = Hash.new - creds[:default] = {:userid => @edit[:new][:default_userid], :password => @edit[:new][:default_password]} - creds[:remote] = {:userid => @edit[:new][:remote_userid], :password => @edit[:new][:remote_password]} - creds[:ws] = {:userid => @edit[:new][:ws_userid], :password => @edit[:new][:ws_password]} - creds[:ipmi] = {:userid => @edit[:new][:ipmi_userid], :password => @edit[:new][:ipmi_password]} + creds[:default] = {:userid => params[:default_userid], :password => params[:default_password]} + creds[:remote] = {:userid => params[:remote_userid], :password => params[:remote_password]} + creds[:ws] = {:userid => params[:ws_userid], :password => params[:ws_password]} + creds[:ipmi] = {:userid => params[:ipmi_userid], :password => params[:ipmi_password]} host.update_authentication(creds, {:save=>(mode != :validate)}) return true end diff --git a/config/environments/development.rb b/config/environments/development.rb index fcd1caf5c28..568c42d3d32 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,6 +1,6 @@ Vmdb::Application.configure do # Settings specified here will take precedence over those in config/application.rb - + config.eager_load = false # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. diff --git a/config/routes.rb b/config/routes.rb index 018e6786a91..4970a5303f9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -772,6 +772,7 @@ timeline_data groups guest_applications + host_form_fields host_services index list diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml index cf80a32d13c..86b0509681d 100644 --- a/spec/javascripts/support/jasmine.yml +++ b/spec/javascripts/support/jasmine.yml @@ -19,6 +19,7 @@ src_files: - javascripts/services/miq_service.js - javascripts/services/miq_db_backup_service.js - javascripts/services/timer_option_service.js + - javascripts/controllers/host/host_form_controller.js - javascripts/controllers/ops/diagnostics_database_form_controller.js - javascripts/controllers/ops/log_collection_form_controller.js - javascripts/controllers/schedule/schedule_form_controller.js diff --git a/vmdb/app/assets/javascripts/controllers/host/host_form_controller.js b/vmdb/app/assets/javascripts/controllers/host/host_form_controller.js new file mode 100644 index 00000000000..a19ea8ec8bb --- /dev/null +++ b/vmdb/app/assets/javascripts/controllers/host/host_form_controller.js @@ -0,0 +1,121 @@ +miqAngularApplication.controller('hostFormController', ['$http', '$scope', 'hostFormId', 'miqService', function($http, $scope, hostFormId, miqService) { + $scope.hostModel = { + name: '', + ipaddress: '', + hostname: '', + ipmi_address: '', + custom_1: '', + user_assigned_os: '', + mac_address: '', + default_userid: '', + default_password: '', + default_verify: '', + remote_userid: '', + remote_password: '', + remote_verify: '', + ws_userid: '', + ws_password: '', + ws_verify: '', + ipmi_userid: '', + ipmi_password: '', + ipmi_verify: '' + + }; + + $scope.modelCopy = angular.copy( $scope.hostModel ); + $scope.afterGet = false; + $scope.formId = hostFormId; + miqAngularApplication.$scope = $scope; + + if (hostFormId == 'new') { + $scope.hostModel.name = ""; + $scope.hostModel.ipaddress = ""; + $scope.hostModel.hostname = ""; + $scope.hostModel.ipmi_address = ""; + $scope.hostModel.custom_1 = ""; + $scope.hostModel.user_assigned_os = ""; + $scope.hostModel.mac_address = ""; + $scope.hostModel.default_userid = ""; + $scope.hostModel.default_password = ""; + $scope.hostModel.default_verify = ""; + $scope.hostModel.remote_userid = ""; + $scope.hostModel.remote_password = ""; + $scope.hostModel.remote_verify = ""; + $scope.hostModel.ws_userid = ""; + $scope.hostModel.ws_password = ""; + $scope.hostModel.ws_verify = ""; + $scope.hostModel.ipmi_userid = ""; + $scope.hostModel.ipmi_password = ""; + $scope.hostModel.ipmi_verify = ""; + + } else { + miqService.sparkleOn(); + + $http.get('/host/host_form_fields/' + hostFormId).success(function(data) { + $scope.hostModel.name = data.name; + $scope.hostModel.ipaddress = data.ipaddress; + $scope.hostModel.hostname = data.hostname; + $scope.hostModel.ipmi_address = data.ipmi_address; + $scope.hostModel.custom_1 = data.custom_1; + $scope.hostModel.user_assigned_os = data.user_assigned_os; + $scope.hostModel.mac_address = data.mac_address; + $scope.hostModel.default_userid = data.default_userid; + $scope.hostModel.default_password = data.default_password; + $scope.hostModel.default_verify = data.default_verify; + $scope.hostModel.remote_userid = data.remote_userid; + $scope.hostModel.remote_password = data.remote_password; + $scope.hostModel.remote_verify = data.remote_verify; + $scope.hostModel.ws_userid = data.ws_userid; + $scope.hostModel.ws_password = data.ws_password; + $scope.hostModel.ws_verify = data.ws_verify; + $scope.hostModel.ipmi_userid = data.ipmi_userid; + $scope.hostModel.ipmi_password = data.ipmi_password; + $scope.hostModel.ipmi_verify = data.ipmi_verify; + + $scope.modelCopy = angular.copy( $scope.hostModel ); + miqService.sparkleOff(); + }); + } + + $scope.$watch("hostModel.name", function() { + $scope.form = $scope.hostForm; + $scope.miqService = miqService; + }); + + $scope.addClicked = function() { + miqService.sparkleOn(); + var url = 'create/new' + '?button=add'; + miqService.miqAjaxButton(url, true); + }; + + $scope.cancelClicked = function() { + miqService.sparkleOn(); + if (hostFormId == 'new') { + var url = '/host/create/new' + '?button=cancel'; + } + else { + var url = '/host/update/' + hostFormId + '?button=cancel'; + } + miqService.miqAjaxButton(url); + }; + + $scope.saveClicked = function() { + miqService.sparkleOn(); + var url = '/host/update/' + hostFormId + '?button=save'; + miqService.miqAjaxButton(url, true); + }; + + $scope.resetClicked = function() { + $scope.hostModel = angular.copy( $scope.modelCopy ); + $scope.hostForm.$setPristine(true); + setFormToValid(); + miqService.miqFlash("warn", "All changes have been reset"); + }; + + var setFormToValid = function() { + for (var name in $scope.hostForm) { + if($scope.hostForm[name].$name == name) + $scope.hostForm[name].$setValidity('miqrequired', true); + } + } +}]); diff --git a/vmdb/app/assets/javascripts/directives/host/multiple_tabs.js b/vmdb/app/assets/javascripts/directives/host/multiple_tabs.js new file mode 100644 index 00000000000..db814993e99 --- /dev/null +++ b/vmdb/app/assets/javascripts/directives/host/multiple_tabs.js @@ -0,0 +1,37 @@ +miqAngularApplication.directive('checkpath', function (){ + return { + require: 'ngModel', + link: function (scope, elem, attrs, ctrl) { + ctrl.$parsers.unshift(function() { + if(validPath(scope, ctrl.$viewValue)) { + ctrl.$setValidity('checkpath', true); + } + else { + ctrl.$setValidity('checkpath', false); + } + }); + + validPath = function(scope, path) { + modified_path = path.replace(/\\/g, "/"); + if(new RegExp("^//[^/].*/.+$").test(modified_path)) { + $j('#flash_msg_div').text(""); + scope.path_type = "NAS"; + return true; + } + else if(/^\[[^\]].+\].*$/.test(modified_path)) { + $j('#flash_msg_div').text(""); + scope.path_type = "VMFS"; + return true; + } + else { + if(scope.formId == "new") { + scope.miqService.miqFlash("warn", "Need a valid UNC path"); + } else { + scope.miqService.miqFlash("error", "Incorrect UNC path"); + } + return false; + } + }; + } + } +}); diff --git a/vmdb/app/views/host/_form.html (copy).haml b/vmdb/app/views/host/_form.html (copy).haml new file mode 100644 index 00000000000..b5ff08a58fe --- /dev/null +++ b/vmdb/app/views/host/_form.html (copy).haml @@ -0,0 +1,86 @@ +%form#form_div(name="hostForm" ng-controller="hostFormController") + = render :partial => "layouts/flash_msg" + - if session[:host_items].nil? + %p.legend=_('Basic Information') + %table.style1 + %tr + %td.key=_('Name') + %td.wide + %input(type="text" name="host_name" ng-model="hostModel.host_name" ng-maxlength=10 miqrequired checkchange) + + - if false + %tr + %td.key=_('Host Name') + %td.wide + #= text_field_tag("hostname", + @edit[:new][:hostname], + :maxlength => MAX_HOSTNAME_LEN, + "data-miq_observe" => observe) + %tr + %td.key=_('IP Address') + %td.wide + #= text_field_tag("ipaddress", + @edit[:new][:ipaddress], + :maxlength => 15, + "data-miq_observe" => observe) + %tr + %td.key=_('Custom Identifier') + %td.wide + #= text_field_tag("custom_1", + @edit[:new][:custom_1], + :maxlength => 50, + "data-miq_observe" => observe) + - if @host.operating_system.nil? || @host.operating_system.product_name.nil? + %tr + %td.key=_('Host platform') + %td.wide + #= select_tag("user_assigned_os", + options_for_select([["<#{_('not specified')}>", nil]] + Host.host_platforms.to_a, + @edit[:new][:user_assigned_os]), + "data-miq_observe" => { :url => url }.to_json) + %tr + %td.key=_('IPMI IP Address') + %td.wide + #= text_field_tag("ipmi_address", + @edit[:new][:ipmi_address], + :maxlength => 15, + "data-miq_observe" => observe) + %tr + %td.key=_('MAC Address') + %td.wide + #= text_field_tag("mac_address", + @edit[:new][:mac_address], + :maxlength => MAX_NAME_LEN, + "data-miq_observe" => observe) + %hr + + #= render(:partial => "/layouts/multi_auth_credentials", :locals => {:record => @host}) + %table{:width => '100%'} + %tr + %td{:align => 'right'} + #buttons_on + - if @host.id.nil? + = button_tag("Add", :class => "btn btn-primary", "ng-class" => "{'btn-disabled': !hostForm.$valid}", "ng-click" => "addClicked()", "ng-disabled" => "!hostForm.$valid") + - else + = button_tag("Save", :class => "btn btn-primary", "ng-click" => "saveClicked()", "ng-disabled" => "hostForm.$pristine || hostForm.$invalid", "ng-class" => "{'btn-disabled': hostForm.$pristine || hostForm.$invalid}") + = button_tag("Reset", :class => "btn btn-primary", "ng-click" => "resetClicked()", "ng-disabled" => "hostForm.$pristine", "ng-class" => "{'btn-disabled': hostForm.$pristine}") + = button_tag("Cancel", :class => "btn btn-default", "ng-click" => "cancelClicked()") + + - unless session[:host_items].nil? + %p.legend + = pluralize(session[:host_items].length,Dictionary::gettext(Host.to_s, :type => :model, :notfound => :titleize)) + | + =_('Selected') + | + =_('Click on a Host to fetch its settings') + %table.admittable{:height => '75'} + %tbody + %tr + %td + - if session[:host_items] + - @embedded = true + - @gtl_type = @settings[:views][:host] + = render :partial => 'layouts/gtl' +:javascript + cfmeAngularApplication.value('hostFormId', '#{@host.id || "new"}'); + angular.bootstrap(jQuery('#form_div'), ['cfmeAngularApplication']); diff --git a/vmdb/app/views/layouts/_auth_credentials_form.html.haml b/vmdb/app/views/layouts/_auth_credentials_form.html.haml new file mode 100644 index 00000000000..567eafb7e1c --- /dev/null +++ b/vmdb/app/views/layouts/_auth_credentials_form.html.haml @@ -0,0 +1,42 @@ +- validate_url ||= %w(new create).include?(controller.action_name) ? "create" : "update" +- change_url ||= "form_field_changed" +- pfx ||= "" +- record ||= nil +- rec_id = record && record.id ? "#{record.id}" : "new" +- uid_label ||= "User ID" +- pwd_label ||= "Password" + +%tr + %td{:class => "key"} + = uid_label + %td + %input(type="text" name="#{pfx}_userid" ng-model="hostModel.#{pfx}_userid" ng-maxlength=50 checkchange) + +%tr + %td{:class => "key"} + = pwd_label + %td + %input(type="password" name="#{pfx}_password" ng-model="hostModel.#{pfx}_password" ng-maxlength=50 checkchange) + -#= password_field_tag("#{pfx}_password", '', + :maxlength => 50, + :placeholder => placeholder_if_present(@edit[:new]["#{pfx}_password".to_sym]), + "data-miq_observe" => url_json) +%tr + %td{:class => "key"} + Verify #{pwd_label} + %td + %input(type="password" name="#{pfx}_verify" ng-model="hostModel.#{pfx}_verify" ng-maxlength=50 checkchange) + -#= password_field_tag("#{pfx}_verify", '', + :maxlength => 50, + :placeholder => placeholder_if_present(@edit[:new]["#{pfx}_verify".to_sym]), + "data-miq_observe" => url_json) +%tr + %td + %td + = render(:partial => "/layouts/form_buttons_verify", + :locals => {:validate_url => validate_url, + :valtype => "#{pfx}", + :record_hash => "test", + :ujs_button => ujs_button, + :record => record}) + diff --git a/vmdb/app/views/layouts/_multi_auth_credentials_form.html.haml b/vmdb/app/views/layouts/_multi_auth_credentials_form.html.haml new file mode 100644 index 00000000000..a70d79d338f --- /dev/null +++ b/vmdb/app/views/layouts/_multi_auth_credentials_form.html.haml @@ -0,0 +1,142 @@ +- validate_url ||= (record.id || @hostitems) ? "update" : "create" +- change_url ||= "form_field_changed" +- settab = @tabnum == nil ? "" : "a_tabbar.setTabActive('a#{@tabnum}');" +- legendtext ||= "Credentials" + +%p.legend=_("#{legendtext}") +%div{:id => "auth_tabs", :style => "display:none;"} + %ul{:class => "tab"} + %li + %a{:href => "#default"}=_('Default') + -# Special tabs for EMS edit + - if ["ems_cloud","ems_infra"].include?(params[:controller]) + - display = @emstype == "rhevm" ? "" : "none" + %li{:id => "metrics_li", :style => "display:#{display};"} + %a{:href => "#metrics"}=_('C & U Database') + - display = @emstype == "openstack" ? "" : "none" + %li{:id => "amqp_li", :style => "display:#{display};"} + %a{:href => "#amqp"}=_('AMQP') + - else + %li + %a{:href => "#remote"}=_('Remote Login') + %li + %a{:href => "#web"}=_('Web Services') + %li + %a{:href => "#ipmi"}=_('IPMI') + + %div{:id => "default", :name => "Default"} + %table{:class => "style1"} + %tbody + = render(:partial => "/layouts/auth_credentials_form", + :locals => {:pfx => "default", + :change_url => change_url, + :validate_url => validate_url, + :ujs_button => true, + :uid_label => @emstype == "ec2" ? "Access Key ID" : nil, + :pwd_label => @emstype == "ec2" ? "Secret Access Key" : nil, + :record => record}) + %span{:style => "color:black"} + Required. Should have privileged access, such as root or administrator. + + - if ["ems_cloud","ems_infra"].include?(params[:controller]) + %div{:id => "metrics", :name => "C & U Database"} + %table{:class => "style1"} + %tbody + = render(:partial => "/layouts/auth_credentials_form", + :locals => {:pfx => "metrics", + :change_url => change_url, + :validate_url => validate_url, + :ujs_button => true, + :uid_label => @edit[:new][:emstype] == "ec2" ? "Access Key ID" : nil, + :pwd_label => @edit[:new][:emstype] == "ec2" ? "Secret Access Key" : nil, + :record => record}) + %span{:style => "color:black"} + Used to gather Capacity & Utilization metrics. + %div{:id => "amqp", :name => "AMQP Messaging"} + %table{:class => "style1"} + %tbody + = render(:partial => "/layouts/auth_credentials_form", + :locals => {:pfx => "amqp", + :change_url => change_url, + :validate_url => validate_url, + :ujs_button => true, + :record => record}) + %span{:style => "color:black"} + Used to authenticate with OpenStack AMQP Messaging Bus for event handling. + - else + %div{:id => "remote", :name => "Remote Login"} + %table{:class => "style1"} + %tbody + = render(:partial => "/layouts/auth_credentials_form", + :locals => {:pfx => "remote", + :change_url => change_url, + :validate_url => validate_url, + :ujs_button => true, + :record => record}) + %span{:style => "color:black"} + Required if SSH login is disabled for the Default account. + %div{:id => "web", :name => "Web Services"} + %table{:class => "style1"} + %tbody + = render(:partial => "/layouts/auth_credentials_form", + :locals => {:pfx => "ws", + :change_url => change_url, + :validate_url => validate_url, + :ujs_button => true, + :record => record}) + %span{:style => "color:black"} + Used for access to Web Services. + %div{:id => "ipmi", :name => "IPMI"} + %table{:class => "style1"} + %tbody + = render(:partial => "/layouts/auth_credentials_form", + :locals => {:pfx => "ipmi", + :change_url => change_url, + :validate_url => validate_url, + :ujs_button => true, + :record => record}) + %span{:style => "color:black"} + Used for access to IPMI. + - if !session[:host_items].nil? + %table{:class => "admintable"} + %tbody + %tr + %td{:class => "key"}Select Host to validate against + %td + = select_tag('validate_id', + options_for_select(@selected_hosts.invert.sort, @validate_against.to_i), + "data-miq_observe" => {:url => url_for(:action => 'form_field_changed', + :id => "#{record.id || "new"}")}.to_json) + + + +-#
+-# +-#
+-# <% if ["ems_cloud","ems_infra"].include?(params[:controller]) %><%# Special tab contents for EMS edit %> +-#
+-# +-#
+-#
+-# +-#
+-# <% else %> +-#
+-# +-#
+-#
+-# +-#
+-#
+-# +-#
+-# +-# <% end %> +-# +-# <% end %> +-#
+ +:javascript + //method takes hash that can have 4 keys: tabs div id, active_tab label, + //url to go to when tab is changed, and whether to check for abandon changes or not + miq_jquery_tabs_init({tabs_div: "auth_tabs"}) diff --git a/vmdb/app/views/report/_widget_form_report.html.erb b/vmdb/app/views/report/_widget_form_report.html.erb new file mode 100644 index 00000000000..1e7339fb874 --- /dev/null +++ b/vmdb/app/views/report/_widget_form_report.html.erb @@ -0,0 +1,43 @@ +<% url = url_for(:action=>'widget_form_field_changed', :id=>"#{@widget.id || "new"}") %> +

Report Options

+ + + + + + <%= render :partial => "widget_columns", :locals=>{:read_only=>@edit[:read_only]} %> + + + + +
<% if @edit[:read_only] %>* <% end %>Filter + <%= select_tag("filter_typ", + options_for_select([""] + @folders, @edit[:new][:filter]), + :multiple=>false, :class=>"widthed", + :disabled=>@edit[:read_only], + "data-miq_sparkle_on"=>true, "data-miq_sparkle_off"=>true, + "data-miq_observe"=>{:url=>url}.to_json) %> + <% if @sub_folders && !@sub_folders.empty? %> + <%= select_tag("subfilter_typ", + options_for_select([""] + @sub_folders, @edit[:new][:subfilter]), + :multiple=>false, :class=>"widthed", + :disabled=>@edit[:read_only], + "data-miq_sparkle_on"=>true, "data-miq_sparkle_off"=>true, + "data-miq_observe"=>{:url=>url}.to_json) %> + <% end %> + <% if @reps && !@reps.empty? %> + <%= select_tag("repfilter_typ", + options_for_select([""] + @reps, @edit[:new][:repfilter]), + :multiple=>false, :class=>"widthed", + :disabled=>@edit[:read_only], + "data-miq_sparkle_on"=>true, "data-miq_sparkle_off"=>true, + "data-miq_observe"=>{:url=>url}.to_json) %> + <% elsif @edit[:new][:subfilter].present? %> + No Widget compatible Reports found + <% end %> +
Row Count + <%= select_tag("row_count", + options_for_select(Array.new(16) {|i| i+5}, @edit[:new][:row_count]), + "data-miq_observe"=>{:url=>url}.to_json) %> +
+
diff --git a/vmdb/certs/other_db_v2_keys b/vmdb/certs/other_db_v2_keys new file mode 100644 index 00000000000..ed20b7000bb --- /dev/null +++ b/vmdb/certs/other_db_v2_keys @@ -0,0 +1,29 @@ +xav_db_key + +--- +:EZCRYPTO KEY FILE: KEEP THIS SECURE ! +:created: 2014-02-28 09:59:47 -0500 +:algorithm: aes-256-cbc +:key: uXfIgSAUq5Oz8goc/zI8HOOo0SI++Sd9mfpgBanYIM4= + +vmdb_production_db_key +--- +:EZCRYPTO KEY FILE: KEEP THIS SECURE ! +:created: 2014-10-24 20:56:40 -0400 +:algorithm: aes-256-cbc +:key: qDdSgXfVFdjxQMes092UjYApAywwZYrjBkMm/P1ps5k= + + +bz_1160271_db_key +--- +:EZCRYPTO KEY FILE: KEEP THIS SECURE ! +:created: 2014-10-29 14:21:15 -0400 +:algorithm: aes-256-cbc +:key: FoBuTs4gqvwNNBS1bdpBb3oRoQR6oSobq+aoPOA2tCc= + +v2_key-bz-1170778 +--- +:EZCRYPTO KEY FILE: KEEP THIS SECURE ! +:created: 2014-10-24 20:56:40 -0400 +:algorithm: aes-256-cbc +:key: qDdSgXfVFdjxQMes092UjYApAywwZYrjBkMm/P1ps5k= \ No newline at end of file diff --git a/vmdb/spec/javascripts/controllers/host/host_form_controller_spec.js b/vmdb/spec/javascripts/controllers/host/host_form_controller_spec.js new file mode 100644 index 00000000000..f2d5b313384 --- /dev/null +++ b/vmdb/spec/javascripts/controllers/host/host_form_controller_spec.js @@ -0,0 +1,76 @@ +describe('hostFormController', function() { + var $scope, $controller, $httpBackend, miqService; + + beforeEach(module('miqAngularApplication')); + + beforeEach(inject(function($rootScope, _$controller_, _$httpBackend_, _miqService_) { + miqService = _miqService_; + spyOn(miqService, 'miqFlash'); + spyOn(miqService, 'miqAjaxButton'); + spyOn(miqService, 'sparkleOn'); + spyOn(miqService, 'sparkleOff'); + $scope = $rootScope.$new(); + $scope.hostModel = { name: 'name', ipaddress: 'ipaddress' }; + $scope.hostForm = { name: {}, + ipaddress: { + $dirty: false, + $name: 'ipaddress', + $setValidity: function (validationErrorKey, isValid){} + }, + $setPristine: function (){} + }; + //$scope.hostForm = { name: {}, + // ipaddress: {}, + // $setPristine: function (){} + //}; + + $scope.hostForm.$invalid = false; + $httpBackend = _$httpBackend_; + $httpBackend.whenGET('/host/host_form_fields/new').respond(); + $controller = _$controller_('hostFormController', { + $scope: $scope, + hostFormId: 'new', + miqService: miqService + }); + })); + + afterEach(function() { + $httpBackend.verifyNoOutstandingExpectation(); + $httpBackend.verifyNoOutstandingRequest(); + }); + + describe('initialization', function() { + describe('when the hostFormId is new', function() { + it('sets the name to blank', function () { + expect($scope.hostModel.name).toEqual(''); + }); + it('sets the ipaddress to blank', function () { + expect($scope.hostModel.ipaddress).toEqual(''); + }); + }); + + describe('when the hostFormId is an Id', function() { + var hostFormResponse = { + name: 'aaa', + ipaddress: '1.1.1.1' + }; + describe('when the filter type is all', function() { + beforeEach(inject(function(_$controller_) { + + $httpBackend.whenGET('/host/host_form_fields/12345').respond(hostFormResponse); + + $controller = _$controller_('hostFormController', {$scope: $scope, hostFormId: '12345'}); + $httpBackend.flush(); + })); + + it('sets the name to the value returned from the http request', function() { + expect($scope.hostModel.name).toEqual('aaa'); + }); + + it('sets the ipaddress to the value returned from the http request', function() { + expect($scope.hostModel.ipaddress).toEqual('1.1.1.1'); + }); + }); + }); + }); +});