Skip to content

Commit

Permalink
Further tweaks to the fabric schemas, relocate them all to schemaConf…
Browse files Browse the repository at this point in the history
…igure and do it once when the fabric plugin is initialized
  • Loading branch information
gashcrumb committed Jul 30, 2013
1 parent 53f2225 commit 5971c23
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 63 deletions.
33 changes: 1 addition & 32 deletions hawtio-web/src/main/webapp/app/fabric/js/createContainer.ts
Expand Up @@ -2,8 +2,6 @@ module Fabric {

export function CreateContainerController($scope, $window, $location, workspace, jolokia, localStorage) {

Fabric.schemaConfigure();

$scope.versionsOp = 'versions()';

$scope.activeTab = 'org_fusesource_fabric_api_CreateChildContainerOptions';
Expand Down Expand Up @@ -114,53 +112,24 @@ module Fabric {

$scope.entity['number'] = 1;

// clean up form
delete $scope.schema.properties['metadataMap'];
delete $scope.schema.properties['zookeeperUrl'];
delete $scope.schema.properties['zookeeperPassword'];
delete $scope.schema.properties['globalResolver'];
delete $scope.schema.properties['zooKeeperServerPort'];
delete $scope.schema.properties['agentEnabled'];
delete $scope.schema.properties['autoImportEnabled'];
delete $scope.schema.properties['importPath'];
delete $scope.schema.properties['users'];


$scope.schema.properties['providerType']['type'] = 'hidden';
$scope.schema.properties['profiles']['type'] = 'hidden';
$scope.schema.properties['version']['type'] = 'hidden';

switch($scope.activeTab) {

case 'org_fusesource_fabric_api_CreateChildContainerOptions':
$scope.entity['providerType'] = 'child';
$scope.entity['jmxUser'] = localStorage['fabric.userName'];
$scope.entity['jmxPassword'] = localStorage['fabric.password'];
$scope.schema.properties['jmxPassword']['type'] = 'password';

$scope.schema.properties['saveJmxCredentials'] = {
'type': 'boolean'
};

delete $scope.schema.properties['manualIp'];
delete $scope.schema.properties['preferredAddress'];
delete $scope.schema.properties['resolver'];
delete $scope.schema.properties['ensembleServer'];
delete $scope.schema.properties['proxyUri'];
delete $scope.schema.properties['adminAccess'];

$location.search('tab', 'child');

break;

case 'org_fusesource_fabric_api_CreateSshContainerOptions':
$scope.entity['providerType'] = 'ssh';
delete $scope.schema.properties['parent'];
$location.search('tab', 'ssh');
break;

case 'org_fusesource_fabric_api_CreateJCloudsContainerOptions':
$scope.entity['providerType'] = 'jclouds';
delete $scope.schema.properties['parent'];
$location.search('tab', 'cloud');
break;
}
Expand Down
6 changes: 1 addition & 5 deletions hawtio-web/src/main/webapp/app/fabric/js/createFabric.ts
Expand Up @@ -2,9 +2,7 @@ module Fabric {

export function CreateFabricController($scope, jolokia, $location) {

Fabric.schemaConfigure();

$scope.schema = (<any>window).org_fusesource_fabric_api_CreateEnsembleOptions;
$scope.schema = Fabric.createEnsembleOptions;

$scope.entity = {
zooKeeperServerPort: 2181,
Expand Down Expand Up @@ -35,8 +33,6 @@ module Fabric {
});
}


console.log("window: ", (<any>window).org_fusesource_fabric_api_CreateEnsembleOptions);
}

}
4 changes: 3 additions & 1 deletion hawtio-web/src/main/webapp/app/fabric/js/fabricPlugin.ts
Expand Up @@ -29,7 +29,9 @@ module Fabric {

run(($location: ng.ILocationService, workspace: Workspace, jolokia, viewRegistry, pageTitle) => {

viewRegistry['fabric'] = templatePath + 'layoutFabric.html';
Fabric.schemaConfigure();

viewRegistry['fabric'] = templatePath + 'layoutFabric.html';

try {
var id = jolokia.getAttribute(Fabric.managerMBean, 'CurrentContainerName', {timeout: 1});
Expand Down
114 changes: 89 additions & 25 deletions hawtio-web/src/main/webapp/app/fabric/js/schemaConfigure.ts
@@ -1,49 +1,113 @@
module Fabric {


export var createChildContainerOptions = (<any>window).org_fusesource_fabric_api_CreateChildContainerOptions;
export var createJCloudsContainerOptions = (<any>window).org_fusesource_fabric_api_CreateJCloudsContainerOptions;
export var createSshContainerOptions = (<any>window).org_fusesource_fabric_api_CreateSshContainerOptions;
export var createEnsembleOptions = (<any>window).org_fusesource_fabric_api_CreateEnsembleOptions;

export var createContainerSchemas:any = [Fabric.createChildContainerOptions, Fabric.createJCloudsContainerOptions, Fabric.createSshContainerOptions];

export var createEnsembleSchemas:any = [Fabric.createEnsembleOptions];

export var allFabricSchemas:any = [Fabric.createChildContainerOptions, Fabric.createJCloudsContainerOptions, Fabric.createSshContainerOptions, Fabric.createEnsembleOptions];



function configureResolverSchema() {
var resolverEnum = ['localip', 'localhostname', 'publicip', 'publichostname'];

Core.pathSet(createEnsembleOptions, ['properties', 'globalResolver', 'enum'], resolverEnum.clone());

resolverEnum.push('manualip');

(<any>[Fabric.createJCloudsContainerOptions,
Fabric.createSshContainerOptions,
Fabric.createEnsembleOptions]).each( (schema) => {

Core.pathSet(schema, ['properties', 'resolver', 'enum'], resolverEnum.clone());
});
}

/**
* Configures the JSON schemas to improve the UI models
*/
export function schemaConfigure() {
angular.forEach(["name", "jmxUser", "jmxPassword"], (name) => {
Core.pathSet(org_fusesource_fabric_api_CreateChildContainerOptions, ["properties", name, "required"], true);
});
angular.forEach(["name", "user", "password"], (name) => {
Core.pathSet(org_fusesource_fabric_api_CreateJCloudsContainerOptions, ["properties", name, "required"], true);
});
angular.forEach(["name", "user", "password"], (name) => {
Core.pathSet(org_fusesource_fabric_api_CreateSshContainerOptions, ["properties", name, "required"], true);

delete createChildContainerOptions.properties['manualIp'];
delete createChildContainerOptions.properties['preferredAddress'];
delete createChildContainerOptions.properties['resolver'];
delete createChildContainerOptions.properties['ensembleServer'];
delete createChildContainerOptions.properties['proxyUri'];
delete createChildContainerOptions.properties['adminAccess'];

createChildContainerOptions.properties['jmxPassword']['type'] = 'password';

createChildContainerOptions.properties['saveJmxCredentials'] = {
'type': 'boolean'
};


(<any>[createJCloudsContainerOptions, createSshContainerOptions]).each((schema) => {
delete schema.properties['parent'];
});

var tmp = (<any>window).org_fusesource_fabric_api_CreateEnsembleOptions;

angular.forEach(["username", "password", "role"], (name) => {
Core.pathSet(tmp, ["properties", name, "type"], 'string');
Core.pathSet(tmp, ["properties", name, "required"], true);
Fabric.createContainerSchemas.each((schema) => {
Core.pathSet(schema, ["properties", "name", "required"], true);

// clean up form
delete schema.properties['metadataMap'];
delete schema.properties['zookeeperUrl'];
delete schema.properties['zookeeperPassword'];
delete schema.properties['globalResolver'];
delete schema.properties['zooKeeperServerPort'];
delete schema.properties['agentEnabled'];
delete schema.properties['autoImportEnabled'];
delete schema.properties['importPath'];
delete schema.properties['users'];

Core.pathSet(schema, ['properties','providerType', 'type'], 'hidden');
Core.pathSet(schema, ['properties','profiles', 'type'], 'hidden');
Core.pathSet(schema, ['properties','version', 'type'], 'hidden');
});

var resolverEnum = ['localip', 'localhostname', 'publicip', 'publichostname', 'manualip'];
angular.forEach(["jmxUser", "jmxPassword", "parent"], (name) => {
Core.pathSet(Fabric.createChildContainerOptions, ["properties", name, "required"], true);
});

angular.forEach([org_fusesource_fabric_api_CreateChildContainerOptions, org_fusesource_fabric_api_CreateJCloudsContainerOptions, org_fusesource_fabric_api_CreateSshContainerOptions, tmp], (schema) => {
angular.forEach(['globalResolver', 'resolver'], (name) => {
Core.pathSet(tmp, ['properties', name, 'enum'], resolverEnum);
});
/*
angular.forEach(["name", "user", "password"], (name) => {
Core.pathSet(CreateJCloudsContainerOptions, ["properties", name, "required"], true);
});
Core.pathSet(tmp, ['properties', 'password', 'password'], true);
delete tmp['properties']['users'];
angular.forEach(["name", "user", "password"], (name) => {
Core.pathSet(CreateSshContainerOptions, ["properties", name, "required"], true);
});
*/

angular.forEach(["username", "password", "role"], (name) => {
Core.pathSet(Fabric.createEnsembleOptions, ["properties", name, "type"], 'string');
Core.pathSet(Fabric.createEnsembleOptions, ["properties", name, "required"], true);
});

configureResolverSchema();

Core.pathSet(Fabric.createEnsembleOptions, ['properties', 'password', 'password'], true);
delete Fabric.createEnsembleOptions['properties']['users'];

// use tabs to reorder the fields
org_fusesource_fabric_api_CreateChildContainerOptions["tabs"] = {
'Default': ['name', '*']
Fabric.createChildContainerOptions["tabs"] = {
'Default': ['name', 'parent', 'jmxUser', 'jmxPassword', 'saveJmxCredentials', 'number', '*']
};
org_fusesource_fabric_api_CreateJCloudsContainerOptions["tabs"] = {
Fabric.createJCloudsContainerOptions["tabs"] = {
'Default': ['name', '*']
};
org_fusesource_fabric_api_CreateJCloudsContainerOptions["tabs"] = {
'Default': ['name', '*']
Fabric.createSshContainerOptions["tabs"] = {
'Default': ['name', 'host', 'port', 'userName', 'password', 'privateKeyFile', 'passPhrase', '*']
};

tmp['tabs'] = {
Fabric.createEnsembleOptions['tabs'] = {
'Basic': ['username', 'password', 'role', 'zookeeperPassword', 'zooKeeperServerPort', 'globalResolver', 'resolver', 'manualIp'],
'Advanced': ['*']
};
Expand Down

0 comments on commit 5971c23

Please sign in to comment.