Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First cut of #534 with shameless copypasta
  • Loading branch information
gashcrumb committed Sep 10, 2013
1 parent 9731123 commit 7c4e0a6
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 3 deletions.
33 changes: 32 additions & 1 deletion hawtio-web/src/main/webapp/app/fabric/html/containerList.html
@@ -1 +1,32 @@
<div>Hi!</div>
<div>

<div ng-repeat="container in containers">
<div class="box" ng-class="getSelectedClass(container)">

<div class="box-left">

<i ng-show="!container.selected" class="icon-circle-blank clickable" title="Not Selected" ng-click="container.selected = true"></i>
<i ng-show="container.selected" class="icon-circle clickable" title="Selected" ng-click="container.selected = false"></i>

<div ng-click="setActiveContainer(container)">
{{container.id}} / {{container.versionId}}
</div>
</div>

<div class="box-right">

<i class="icon-plus clickable" ng-show="container.root && container.alive" title="Create a new child container" ng-click="createChildContainer(container)"></i>

<i class="icon-cloud clickable" title="Ensemble member" ng-click="showContainer(container)" ng-show="isEnsembleContainer(container.id)"></i>

<i class="clickable" title="{{getStatusTitle(container)}}" ng-class='statusIcon(container)' ng-click="showContainer(container)"></i>

<i class="icon-signin clickable" ng-show="container.jolokiaUrl && container.alive" title="Open a new window and connect to this container" ng-click="doConnect(container)"></i>

<i class="clickable icon-info-sign" title="Show Details" ng-click="showContainer(container)"></i>
</div>

</div>
</div>

</div>
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/fabric/html/test.html
Expand Up @@ -6,7 +6,7 @@ <h3>Container List</h3>
<script type="text/ng-template" id="containerListTemplate">
<div fabric-container-list></div>
</script>
<div hawtio-editpr="containerList"></div>
<div hawtio-editor="containerList" mode="html"></div>
<div class="directive-example">
<div compile="containerList"></div>
</div>
Expand Down
189 changes: 188 additions & 1 deletion hawtio-web/src/main/webapp/app/fabric/js/containerDirective.ts
Expand Up @@ -10,7 +10,194 @@ module Fabric {

};

public controller = ($scope, $element, $attrs, jolokia) => {
public controller = ($scope, $element, $attrs, jolokia, $location) => {

$scope.containerArgs = ["id", "alive", "parentId", "profileIds", "versionId", "provisionResult", "jolokiaUrl", "root"];
$scope.containersOp = 'containers(java.util.List)';
$scope.ensembleContainerIdListOp = 'EnsembleContainers';

$scope.containers = [];
$scope.activeProfiles = [];
$scope.selectedContainers = [];
$scope.selectedContainerIds = [];
$scope.connectToContainerDialog = new Core.Dialog();
$scope.targetContainer = {};



$scope.updateContainers = (newContainers) => {

var response = angular.toJson(newContainers);

if ($scope.containersResponse !== response) {
$scope.containersResponse = response;

var rootContainers = newContainers.exclude((c) => { return !c.root; });
var childContainers = newContainers.exclude((c) => { return c.root; });

if (childContainers.length > 0) {
var tmp = [];
rootContainers = rootContainers.sortBy('id');
rootContainers.each((c) => {
tmp.add(c);
var children = childContainers.exclude((child) => { return child.parentId !== c.id });
tmp.add(children.sortBy('id'));
});
newContainers = tmp;
}

newContainers.each((container) => {
var c = $scope.containers.find((c) => { return c.id === container.id; });
if (c) {
container['selected'] = c.selected;
} else {
container['selected'] = false;
}
if ($scope.selectedContainerIds.any(container.id)) {
container.selected = true;
}
});

$scope.containers = newContainers;
var activeProfiles = $scope.activeProfiles;
$scope.activeProfiles = $scope.currentActiveProfiles();
$scope.activeProfiles.each((activeProfile) => {

var ap = activeProfiles.find((ap) => { return ap.id === activeProfile.id && ap.versionId === activeProfile.versionId });
if (ap) {
activeProfile['selected'] = ap.selected;
} else {
activeProfile['selected'] = false;
}

});
Core.$apply($scope);
}
};


$scope.showContainer = (container) => {
$location.path('/fabric/container/' + container.id);
};


$scope.createChildContainer = (container) => {
$location.url('/fabric/containers/createContainer').search({ 'tab': 'child', 'parentId': container.id });
};


$scope.createChildContainer = (container) => {
$location.url('/fabric/containers/createContainer').search({ 'tab': 'child', 'parentId': container.id });
};


$scope.statusIcon = (row) => {
if (row) {
if (row.alive) {
switch(row.provisionResult) {
case 'success':
return "green icon-play-circle";
case 'downloading':
return "icon-download-alt";
case 'installing':
return "icon-hdd";
case 'analyzing':
case 'finalizing':
return "icon-refresh icon-spin";
case 'resolving':
return "icon-sitemap";
case 'error':
return "red icon-warning-sign";
}
} else {
return "orange icon-off";
}
}
return "icon-refresh icon-spin";
};


$scope.isEnsembleContainer = (containerId) => {
return $scope.ensembleContainerIds.any(containerId);
}


$scope.doConnect = (container) => {
$scope.targetContainer = container;
$scope.connectToContainerDialog.open();
}

$scope.connect = (row) => {
if ($scope.saveCredentials) {
$scope.saveCredentials = false;
localStorage['fabric.userName'] = $scope.userName;
localStorage['fabric.password'] = $scope.password;
}
Fabric.connect(localStorage, $scope.targetContainer, $scope.userName, $scope.password, true);
$scope.targetContainer = {};
$scope.connectToContainerDialog.close();
};



$scope.currentActiveProfiles = () => {
var answer = [];

$scope.containers.each((container) => {
container.profileIds.each((profile) => {

var activeProfile = answer.find((o) => { return o.versionId === container.versionId && o.id === profile });

if (activeProfile) {
activeProfile.count++;
activeProfile.containers = activeProfile.containers.include(container.id).unique();
} else {
answer.push({
id: profile,
count: 1,
versionId: container.versionId,
containers: [container.id],
selected: false
});
}
});
});

return answer;
};


$scope.updateEnsembleContainerIdList = (ids) => {
var response = angular.toJson(ids);
if ($scope.ensembleContainerIdsResponse !== response) {
$scope.ensembleContainerIdsResponse = response;
$scope.ensembleContainerIds = ids;
console.log("updated to: ", $scope.ensembleContainerIds);
Core.$apply($scope);
}
}


$scope.dispatch = (response) => {
switch (response.request.operation) {
case($scope.containersOp):
$scope.updateContainers(response.value);
return;
}
switch (response.request.attribute) {
case($scope.ensembleContainerIdListOp):
$scope.updateEnsembleContainerIdList(response.value);
return;
}
};


Core.register(jolokia, $scope, [
{type: 'exec', mbean: Fabric.managerMBean, operation: $scope.containersOp, arguments: [$scope.containerArgs]},
{type: 'read', mbean: Fabric.clusterManagerMBean, attribute: $scope.ensembleContainerIdListOp}
], onSuccess($scope.dispatch));





Expand Down
1 change: 1 addition & 0 deletions hawtio-web/src/main/webapp/app/fabric/js/test.ts
Expand Up @@ -9,6 +9,7 @@ module Fabric {
$scope.versionSelector = $templateCache.get("versionSelectorTemplate");
$scope.profileIncludes = $templateCache.get("profile-includes");
$scope.profileExcludes = $templateCache.get("profile-excludes");
$scope.containerList = $templateCache.get("containerListTemplate");

$scope.version = {};
$scope.versionId = '';
Expand Down

0 comments on commit 7c4e0a6

Please sign in to comment.