Skip to content

Commit

Permalink
Host Angular editor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
h-kataria authored and AparnaKarve committed Aug 19, 2015
1 parent 876cf97 commit aad7338
Show file tree
Hide file tree
Showing 13 changed files with 702 additions and 177 deletions.
3 changes: 2 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
//= 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
//= require directives/selectpickerForSelectTag
//= 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
Expand Down
296 changes: 121 additions & 175 deletions app/controllers/host_controller.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@
timeline_data
groups
guest_applications
host_form_fields
host_services
index
list
Expand Down
1 change: 1 addition & 0 deletions spec/javascripts/support/jasmine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
121 changes: 121 additions & 0 deletions vmdb/app/assets/javascripts/controllers/host/host_form_controller.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
}]);
37 changes: 37 additions & 0 deletions vmdb/app/assets/javascripts/directives/host/multiple_tabs.js
Original file line number Diff line number Diff line change
@@ -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;
}
};
}
}
});
86 changes: 86 additions & 0 deletions vmdb/app/views/host/_form.html (copy).haml
Original file line number Diff line number Diff line change
@@ -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']);
42 changes: 42 additions & 0 deletions vmdb/app/views/layouts/_auth_credentials_form.html.haml
Original file line number Diff line number Diff line change
@@ -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})

Loading

0 comments on commit aad7338

Please sign in to comment.