Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added improved logic to start/stop/uninstall so we enable start when …
…one of the selections is stopped; and can stop if one is started; but can only uninstall if they are all stopped (to make it less likely folks hit it by accident)
  • Loading branch information
jstrachan committed Apr 18, 2013
1 parent 99ce04a commit f2bd6b0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
8 changes: 5 additions & 3 deletions hawtio-web/src/main/webapp/app/jetty/html/applications.html
Expand Up @@ -6,9 +6,11 @@
<fieldset>
<div class="controls control-group inline-block controls-row">
<div class="btn-group">
<button ng-disabled="selected.length == 0" class="btn" ng-click="stop()" title="Stop"><i class="icon-stop"></i></button>
<button ng-disabled="selected.length == 0" class="btn" ng-click="start()" title="Start"><i class="icon-play"></i></button>
<button ng-disabled="selected.length == 0" class="btn" ng-click="uninstall()" title="Uninstall"><i class="icon-eject"></i></button>
<button ng-disabled="selected.length == 0 || !anySelectionHasState('start')" class="btn" ng-click="stop()" title="Stop">
<i class="icon-stop"></i></button>
<button ng-disabled="selected.length == 0 || !anySelectionHasState('stop')" class="btn" ng-click="start()" title="Start">
<i class="icon-play"></i></button>
<button ng-disabled="selected.length == 0 || !everySelectionHasState('stop')" class="btn" ng-click="uninstall()" title="Uninstall"><i class="icon-eject"></i></button>
</div>
</div>
</fieldset>
Expand Down
14 changes: 14 additions & 0 deletions hawtio-web/src/main/webapp/app/jetty/js/helpers.ts
Expand Up @@ -12,4 +12,18 @@ module Jetty {
return "red icon-stop";
}

/**
* Returns true if the state of the item begins with the given state - or one of the given states
*
* @param item the item which has a State
* @param state a value or an array of states
*/
export function isState(item, state) {
var value = (item.state || "").toLowerCase();
if (angular.isArray(state)) {
return state.any((stateText) => value.startsWith(stateText));
} else {
return value.startsWith(state);
}
}
}
10 changes: 10 additions & 0 deletions hawtio-web/src/main/webapp/app/jetty/js/jetty.ts
Expand Up @@ -82,6 +82,16 @@ module Jetty {
$scope.controlWebApps('destroy');
};

$scope.anySelectionHasState = (state) => {
var selected = $scope.selected || [];
return selected.length && selected.any((s) => isState(s, state));
};

$scope.everySelectionHasState = (state) => {
var selected = $scope.selected || [];
return selected.length && selected.every((s) => isState(s, state));
};

// function to trigger reloading page
$scope.onLastResponse = function (response) {
$scope.onResponse(response);
Expand Down

0 comments on commit f2bd6b0

Please sign in to comment.