Skip to content

Commit

Permalink
#833: Added preference to be able to select which plugin to select on…
Browse files Browse the repository at this point in the history
… startup.
  • Loading branch information
davsclaus committed Dec 12, 2013
1 parent e0a9e87 commit a224161
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
14 changes: 14 additions & 0 deletions hawtio-web/src/main/webapp/app/core/html/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
</div>
</div>

<div class="control-group">
<label class="control-label">Default Plugin</label>
<div class="controls">
<select id="updateDefaultPlugin" ng-model="defaultPlugin">
<option ng-selected="{{plugin.selected}}"
ng-repeat="plugin in plugins"
value="{{plugin.id}}">
{{plugin.displayName}}
</option>
</select>
<span class="help-block">The default plugin to select on startup</span>
</div>
</div>

<div class="control-group">
<label class="control-label" for="updateRate">Update Rate</label>
<div class="controls">
Expand Down
41 changes: 40 additions & 1 deletion hawtio-web/src/main/webapp/app/core/js/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
module Core {

export function PreferencesController($scope, localStorage, userDetails, jolokiaUrl, branding) {
export function PreferencesController($scope, $location, jolokia, workspace, localStorage, userDetails, jolokiaUrl, branding) {

$scope.branding = branding;

Expand Down Expand Up @@ -186,6 +186,45 @@ module Core {
} else {
logout(jolokiaUrl, userDetails, localStorage, $scope, doReset);
}
};

$scope.plugins = [];

// setup the plugin tabs
var topLevelTabs = Perspective.topLevelTabs($location, workspace, jolokia, localStorage);
// exclude invalid tabs at first
topLevelTabs = topLevelTabs.filter(tab => {
var href = tab.href();
return href && Perspective.isValidFunction(workspace, tab.isValid);
});

// now put those into the tabs, having the default first plugin in the top
$scope.plugins.push({id: "_first", displayName: "First Plugin", selected: false});
topLevelTabs.forEach(tab => {
$scope.plugins.push({id: tab.id, displayName: tab.content, selected: false});
});

// just try to select logs
var defaultPlugin = localStorage['defaultPlugin'];
var found = false;
if (defaultPlugin) {
$scope.plugins.forEach(plugin => {
if (plugin.id === defaultPlugin) {
plugin.selected = true;
found = true;
}
});
}
if (!found) {
$scope.plugins[0].selected = true;
}

$scope.$watch('defaultPlugin', (newValue, oldValue) => {
if (newValue === oldValue) {
return;
}
localStorage['defaultPlugin'] = newValue;
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ module Perspective {
function isMatchDefaultPlugin(id, localStorage) {
var value = localStorage["defaultPlugin"];
if (angular.isString(id) && angular.isString(value)) {
return id === value;
// if the default is the first then its a match
return value === "_first" || id === value;
}
// if no default plugin then match as a favorite
return true;
Expand All @@ -253,7 +254,7 @@ module Perspective {
* @param {Function} validFn
* @return {Boolean}
*/
function isValidFunction(workspace, validFn) {
export function isValidFunction(workspace, validFn) {
return !validFn || validFn(workspace);
}

Expand Down

0 comments on commit a224161

Please sign in to comment.