Skip to content

Commit

Permalink
use a combo box for the openshift domains and gears
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrachan committed Oct 1, 2013
1 parent a5b50a1 commit 9527d52
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 23 deletions.
34 changes: 34 additions & 0 deletions hawtio-web/src/main/webapp/app/fabric/js/createContainer.ts
Expand Up @@ -8,6 +8,7 @@ module Fabric {
number: 1
};


// the form properties stored in local storage
// which we then default when creating a new container
var localStorageProperties = {
Expand Down Expand Up @@ -51,6 +52,9 @@ module Fabric {
$scope.selectedVersionId = '';
$scope.profileIdFilter = '';

$scope.openShiftDomains = [];
$scope.openShiftGearProfiles = [];

// holds all the form objects from nested child scopes
$scope.forms = {};

Expand Down Expand Up @@ -145,6 +149,36 @@ module Fabric {
return Fabric.getRootContainers(jolokia);
};

function updateOpenShift() {
var serverUrl = Core.pathGet($scope.entity, ["serverUrl"]) || "openshift.redhat.com";
var login = Core.pathGet($scope.entity, ["login"]);
var password = Core.pathGet($scope.entity, ["password"]);

var params = [serverUrl, login, password];
if (!Object.equal(params, $scope.openShiftParams)) {
$scope.openShiftParams = params;

Fabric.getOpenShiftDomains(workspace, jolokia, serverUrl, login, password, (results) => {
$scope.openShiftDomains = results;
console.log("found openshift domains: " + $scope.openShiftDomains);
});
Fabric.getOpenShiftGearProfiles(workspace, jolokia, serverUrl, login, password, (results) => {
$scope.openShiftGearProfiles = results;
console.log("found openshift gears: " + $scope.openShiftGearProfiles);
});
}
}

$scope.$watch('entity.serverUrl', updateOpenShift);
$scope.$watch('entity.login', updateOpenShift);
$scope.$watch('entity.password', updateOpenShift);

$scope.openShiftDomains = () => {
};

$scope.openShiftGearProfiles = () => {
};

$scope.init = () => {

var tab = $location.search()['tab'];
Expand Down
27 changes: 27 additions & 0 deletions hawtio-web/src/main/webapp/app/fabric/js/helpers.ts
Expand Up @@ -3,6 +3,7 @@ module Fabric {
export var managerMBean = "org.fusesource.fabric:type=Fabric";
export var clusterManagerMBean = "org.fusesource.fabric:type=ClusterServiceManager";
export var clusterBootstrapManagerMBean = "org.fusesource.fabric:type=ClusterBootstrapManager";
export var openShiftFabricMBean = "org.fusesource.fabric:type=OpenShift";

export var useDirectoriesInGit = true;
var fabricTopLevel = "fabric/profiles/";
Expand All @@ -17,6 +18,10 @@ module Fabric {
return workspace.treeContainsDomainAndProperties(Fabric.jmxDomain, {type: "ClusterBootstrapManager"});
}

export function hasOpenShiftFabric(workspace) {
return workspace.treeContainsDomainAndProperties(Fabric.jmxDomain, {type: "OpenShift"});
}


export function hasFabric(workspace) {
// lets make sure we only have a fabric if we have the ClusterBootstrapManager available
Expand Down Expand Up @@ -461,6 +466,28 @@ module Fabric {
return answer.filter({root: true}).map(v => v["id"]);
}

export function getOpenShiftDomains(workspace ,jolokia, serverUrl, login, password, fn = null) {
if (hasOpenShiftFabric(workspace) && serverUrl && login && password) {
return jolokia.execute(Fabric.openShiftFabricMBean, "getDomains", serverUrl, login, password, onSuccess(fn));
} else {
if (fn) {
fn([]);
}
return [];
}
}

export function getOpenShiftGearProfiles(workspace ,jolokia, serverUrl, login, password, fn = null) {
if (hasOpenShiftFabric(workspace) && serverUrl && login && password) {
return jolokia.execute(Fabric.openShiftFabricMBean, "getGearProfiles", serverUrl, login, password, onSuccess(fn));
} else {
if (fn) {
fn([]);
}
return [];
}
}


export function filterProfiles(jolokia, versionId, profileIds) {
var profiles = jolokia.execute(Fabric.managerMBean, "getProfiles(java.lang.String, java.util.List)", versionId, ['id', 'hidden', 'abstract'], { method: 'POST' });
Expand Down
4 changes: 4 additions & 0 deletions hawtio-web/src/main/webapp/app/fabric/js/schemaConfigure.ts
Expand Up @@ -100,7 +100,11 @@ module Fabric {

Core.pathSet(schema.properties, ['domain', 'label'], 'OpenShift Domain');
Core.pathSet(schema.properties, ['domain', 'tooltip'], 'What is your unique domain name used for applications you create on OpenShift. Often this is your own user name or group name');
Core.pathSet(schema.properties, ['domain', 'enumModel'], "openShiftDomains");

Core.pathSet(schema.properties, ['gearProfile', 'tooltip'], 'Which kind of gear to create');
Core.pathSet(schema.properties, ['gearProfile', 'enumModel'], "openShiftGearProfiles");

Core.pathSet(schema.properties, ['number', 'tooltip'], 'The number of containers to create');


Expand Down
52 changes: 29 additions & 23 deletions hawtio-web/src/main/webapp/app/forms/js/mappingRegistry.ts
Expand Up @@ -166,32 +166,38 @@ module Forms {
if (custom) {
return null;
}
var enumModelValues = Core.pathGet(property, ["enumModel"]);
var enumValues = Core.pathGet(property, ["enum"]);
if (enumValues) {
// calculate from input attributes...
if (enumValues || enumModelValues) {
var required = true;
var scope = config.scope;
var data = config.data;
var valuesScopeName = enumModelValues;
var attributes = "";
if (data && scope) {
// this is a big ugly - would be nice to expose this a bit easier...
// maybe nested objects should expose the model easily...
var fullSchema = scope[config.schemaName];
var model = angular.isString(data) ? scope[data] : data;
// now we need to keep walking the model to find the enum values
var paths = id.split(".");
var property = null;
angular.forEach(paths, (path) => {
property = Core.pathGet(model, ["properties", path]);
var typeName = Core.pathGet(property, ["type"]);
var alias = Forms.lookupDefinition(typeName, fullSchema);
if (alias) {
model = alias;
}
});
var values = Core.pathGet(property, ["enum"]);
var valuesScopeName = "$values_" + id.replace(/\./g, "_");
scope[valuesScopeName] = values;
if (enumValues) {
// calculate from input attributes...
var scope = config.scope;
var data = config.data;
if (data && scope) {
// this is a big ugly - would be nice to expose this a bit easier...
// maybe nested objects should expose the model easily...
var fullSchema = scope[config.schemaName];
var model = angular.isString(data) ? scope[data] : data;
// now we need to keep walking the model to find the enum values
var paths = id.split(".");
var property = null;
angular.forEach(paths, (path) => {
property = Core.pathGet(model, ["properties", path]);
var typeName = Core.pathGet(property, ["type"]);
var alias = Forms.lookupDefinition(typeName, fullSchema);
if (alias) {
model = alias;
}
});
var values = Core.pathGet(property, ["enum"]);
var valuesScopeName = "$values_" + id.replace(/\./g, "_");
scope[valuesScopeName] = values;
}
}
if (valuesScopeName) {
attributes += ' ng-options="value for value in ' + valuesScopeName + '"';
}
var defaultOption = required ? "" : '<option value=""></option>';
Expand Down

0 comments on commit 9527d52

Please sign in to comment.