Skip to content

Commit

Permalink
Merge pull request #876 from mtho11/jdbc_driver_defaults
Browse files Browse the repository at this point in the history
Add Smart Jdbc driver defaults
  • Loading branch information
martinpovolny authored Apr 5, 2017
2 parents 021a839 + a6ca0d2 commit a63ff3c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ManageIQ.angular.app.controller('mwServerController', MwServerController);
ManageIQ.angular.app.controller('mwServerGroupController', MwServerGroupController);

MwServerController.$inject = ['$scope', 'miqService' ];
MwServerController.$inject = ['$scope', 'miqService', 'mwAddDatasourceService'];
MwServerGroupController.$inject = ['$scope', 'miqService' ];

/**
Expand All @@ -25,26 +25,27 @@ MwServerGroupController.$inject = ['$scope', 'miqService' ];
* parent/child controller relationships.
* @param $scope
* @param miqService
* @param mwAddDatasourceService
* @constructor
*/
function MwServerController($scope, miqService) {
return MwServerControllerFactory($scope, miqService, false);
function MwServerController($scope, miqService, mwAddDatasourceService) {
return MwServerControllerFactory($scope, miqService, mwAddDatasourceService, false);
}

function MwServerGroupController($scope, miqService) {
return MwServerControllerFactory($scope, miqService, true);
function MwServerGroupController($scope, miqService, mwAddDatasourceService) {
return MwServerControllerFactory($scope, miqService, mwAddDatasourceService, true);
}

function MwServerControllerFactory($scope, miqService, isGroupDeployment) {
function MwServerControllerFactory($scope, miqService, mwAddDatasourceService, isGroupDeployment) {
ManageIQ.angular.scope = $scope;

ManageIQ.angular.rxSubject.subscribe(function(event) {
var eventType = event.type,
operation = event.operation,
timeout = event.timeout;
operation = event.operation,
timeout = event.timeout;

$scope.paramsModel = $scope.paramsModel || {};
if (eventType == 'mwServerOps' && operation) {
if (eventType === 'mwServerOps' && operation) {
$scope.paramsModel.serverId = angular.element('#mw_param_server_id').val();
$scope.paramsModel.operation = operation;
$scope.paramsModel.operationTitle = formatOpDisplayName(operation) + ' ' + _('Server');
Expand All @@ -58,8 +59,7 @@ function MwServerControllerFactory($scope, miqService, isGroupDeployment) {
// Server Ops
/////////////////////////////////////////////////////////////////////////

$scope.runOperation = function () {
//$scope.$broadcast('mwSeverOpsEvent', $scope.paramsModel);
$scope.runOperation = function() {
var newMwServerOpsEvent = {},
mwServerTypePart = {type: 'mwSeverOpsEvent'};
angular.extend(newMwServerOpsEvent, mwServerTypePart, $scope.paramsModel);
Expand All @@ -85,11 +85,11 @@ function MwServerControllerFactory($scope, miqService, isGroupDeployment) {
$scope.resetDeployForm();
};

$scope.showDatasourceListener = function () {
$scope.showDatasourceListener = function() {
// just here to 'Button not implemented'
};

$scope.resetDeployForm = function () {
$scope.resetDeployForm = function() {
$scope.deployAddModel.enableDeployment = true;
$scope.deployAddModel.forceDeploy = false;
$scope.deployAddModel.runtimeName = undefined;
Expand All @@ -104,7 +104,7 @@ function MwServerControllerFactory($scope, miqService, isGroupDeployment) {
}
});

$scope.addDeployment = function () {
$scope.addDeployment = function() {
miqService.sparkleOn();
$scope.$broadcast('mwAddDeploymentEvent', $scope.deployAddModel);
};
Expand All @@ -113,26 +113,47 @@ function MwServerControllerFactory($scope, miqService, isGroupDeployment) {
// Add JDBC Driver
/////////////////////////////////////////////////////////////////////////

$scope.showJdbcDriverListener = function () {
$scope.showJdbcDriverListener = function() {
$scope.resetJdbcDriverForm();
$scope.jdbcDriverModel.showDeployModal = true;
};

$scope.resetJdbcDriverForm = function () {
$scope.resetJdbcDriverForm = function() {
$scope.jdbcDriverModel = {};
$scope.jdbcDriverModel.serverId = angular.element('#server_id').val();
$scope.jdbcDriverModel.xaDatasource = true;
$scope.jdbcDriverModel.datasources = mwAddDatasourceService.getXaDatasources();
$scope.jdbcDriverModel.selectedDatasource = undefined;
angular.element('#jdbc_add_div :file#jdbc_driver_file').val('');
angular.element('#jdbc_add_div input[type="text"]:disabled').val('');
$scope.$broadcast('mwAddJdbcDriverReset');
};

$scope.onDriverXaChange = function() {
if ($scope.jdbcDriverModel) {
if ($scope.jdbcDriverModel.xaDatasource) {
$scope.jdbcDriverModel.datasources = mwAddDatasourceService.getXaDatasources();
} else {
$scope.jdbcDriverModel.datasources = mwAddDatasourceService.getDatasources();
}
}
};

$scope.$watch('jdbcDriverModel.selectedDatasource', function(newValue) {
if (newValue) {
$scope.jdbcDriverModel.driverName = newValue.driverName;
$scope.jdbcDriverModel.moduleName = newValue.driverModuleName;
$scope.jdbcDriverModel.driverClass = newValue.driverClass;
}
});

$scope.$watch('jdbcDriverModel.filePath', function(newValue) {
if (newValue) {
$scope.jdbcDriverModel.driverJarName = newValue.name;
}
});

$scope.addJdbcDriver = function () {
$scope.addJdbcDriver = function() {
miqService.sparkleOn();
$scope.$broadcast('mwAddJdbcDriverEvent', $scope.jdbcDriverModel);
};
Expand Down Expand Up @@ -160,23 +181,20 @@ function MwServerGroupOpsController(miqService, serverGroupOpsService) {

function MwServerOpsControllerFactory(miqService, serverOpsService) {

ManageIQ.angular.rxSubject.subscribe(function(event) {

if(event.type == 'mwSeverOpsEvent') {
miqService.sparkleOn();

serverOpsService.runOperation(event.serverId, event.operation, event.timeout)
.then(function (response) {
miqService.miqFlash('success', response);
},
function (error) {
miqService.miqFlash('error', error);

}).finally(function () {

ManageIQ.angular.rxSubject.subscribe(function(event) {
if (event.type === 'mwSeverOpsEvent') {
miqService.sparkleOn();

serverOpsService.runOperation(event.serverId, event.operation, event.timeout)
.then(function(response) {
miqService.miqFlash('success', response);
},
function(error) {
miqService.miqFlash('error', error);
}).finally(function() {
miqService.sparkleOff();
});
}
}
});
}

Expand All @@ -195,19 +213,19 @@ function ServerGroupOpsService($http, $q) {

function ServerOpsServiceFactory($http, $q, isGroup) {
var runOperation = function runOperation(id, operation, timeout) {
var errorMsg = isGroup ? _('Error running operation on this server.')
var errorMsg = isGroup ? _('Error running operation on this server.')
: _('Error running operation on this server group.');
var deferred = $q.defer();
var payload = {
'id': id,
'operation': operation,
'timeout': timeout
'timeout': timeout,
};

var url = '/middleware_server' + (isGroup ? '_group' : '') + '/run_operation'
$http.post(url, angular.toJson(payload))
.then(
function (response) { // success
function(response) { // success
var data = response.data;

if (data.status === 'ok') {
Expand All @@ -216,18 +234,18 @@ function ServerOpsServiceFactory($http, $q, isGroup) {
deferred.reject(data.msg);
}
})
.catch(function () {
.catch(function() {
deferred.reject(errorMsg);
})
.finally(function () {
.finally(function() {
angular.element("#modal_param_div").modal('hide');
// we should already be resolved and promises can only fire once
deferred.resolve(data.msg);
});
return deferred.promise;
}
};
return {
runOperation: runOperation
runOperation: runOperation,
};
}

20 changes: 20 additions & 0 deletions app/views/middleware_server/_add_jdbc_driver.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@
= render :partial => "shared/file_chooser",
:locals => {:object_name => "jdbc_driver", :method => "file", :custom_options => {"ng-required" => "true", "ng-model" => "jdbcDriverModel.filePath", "require-file" => "handle"}}
.form-group
%label.col-md-4.control-label{:for => "xa_driver_ds_cb"}
= _("XA Datasource:")
.col-md-8
%input#xa_driver_ds_cb{:type => "checkbox",
"bs-switch" => "",
"switch-on-text" => _("Yes"),
"switch-off-text" => _("No"),
"switch-change" => "onDriverXaChange()",
"ng-model" => "jdbcDriverModel.xaDatasource"}
.form-group
%label.col-md-4.control-label{:for => "choose_datasource_input"}
= _("Datasource:")
.col-md-8
%select.form-control#chooose_driver_ds{"name" => "choose_driver_ds_input",
"ng-model" => "jdbcDriverModel.selectedDatasource",
"ng-options" => "c.label for c in jdbcDriverModel.datasources track by c.id",
"ng-required" => "false"}
.form-group
%label.col-md-4.control-label{:for => "jdbc_driver_name_input"}
= _("Driver Name")
Expand Down

0 comments on commit a63ff3c

Please sign in to comment.