Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #309 from ammendonca/HAWKULAR-400
Browse files Browse the repository at this point in the history
HAWKULAR-400 : Redirect to URL/App Server list when resource not found
  • Loading branch information
mtho11 committed Jul 9, 2015
2 parents 2fecffe + 064c935 commit 03868a1
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h1>No application servers set up.</h1>
<p ng-hide="res.state"><span class="spinner spinner-sm spinner-inline"></span> <span class="fetching">Fetching state...</span></p>
{{res.state | firstUpper}}
</td>
<td><a href="/hawkular-ui/app/app-details/{{res.id | limitTo14 : res.id.length-4 : 1}}/jvm">{{res.id | limitTo14 : res.id.length-4 : 1}}</a> <a href="/hawkular-ui/app/app-details/{{res.id | urlEncode}}/jvm" class="pull-right"><span class="label label-danger label-alert" tooltip-trigger tooltip-placement="top" tooltip="Server alerts" ng-show="res.alerts.length > 0">{{res.alerts.length}}</span></a></td>
<td><a href="/hawkular-ui/app/app-details/{{res.id | limitTo14 : res.id.length-4 : 1}}/jvm">{{res.id | limitTo14 : res.id.length-4 : 1}}</a> <a href="/hawkular-ui/app/app-details/{{res.id}}/jvm" class="pull-right"><span class="label label-danger label-alert" tooltip-trigger tooltip-placement="top" tooltip="Server alerts" ng-show="res.alerts.length > 0">{{res.alerts.length}}</span></a></td>
<td>{{res.type.id}}</td>
<td>{{(res.properties.resourceConfiguration | filter:'Hostname':true)[0].value || 'n/a'}}</td>
<!-- <td class="center"><span class="label label-primary" ng-repeat="tag in res.tags">{{tag}}</span><span ng-hide="res.tags.length > 0">--</span></td> -->
Expand Down
3 changes: 3 additions & 0 deletions console/src/main/scripts/plugins/metrics/ts/metricsGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ module HawkularMetrics {

export var globalEnvironmentId = 'test';

/// This will be set when accessing a feed resource
export var globalFeedId = undefined;

}
287 changes: 163 additions & 124 deletions console/src/main/scripts/plugins/metrics/ts/metricsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,135 +20,174 @@

module HawkularMetrics {

export var _module = angular.module(HawkularMetrics.pluginName, ['ngResource', 'ui.select', 'hawkular.charts',
'hawkular.services', 'ui.bootstrap', 'topbar', 'patternfly.select', 'angular-momentjs', 'angular-md5']);

var metricsTab:any;

_module.config(['$httpProvider', '$locationProvider', '$routeProvider', 'HawtioNavBuilderProvider',
($httpProvider, $locationProvider, $routeProvider:ng.route.IRouteProvider,
navBuilder:HawtioMainNav.BuilderFactory) => {

metricsTab = navBuilder.create()
.id(HawkularMetrics.pluginName)
.title(() => 'Metrics')
.href(() => '/metrics')
.subPath('Add Url', 'add-url', navBuilder.join(HawkularMetrics.templatePath, 'add-url.html'))
.subPath('Response Time', 'response-time', navBuilder.join(HawkularMetrics.templatePath,
'response-time.html'))
.subPath('Availability', 'availability', navBuilder.join(HawkularMetrics.templatePath, 'availability.html'))
.subPath('Alerts', 'alerts', navBuilder.join(HawkularMetrics.templatePath, 'alerts.html'))
.build();

navBuilder.configureRouting($routeProvider, metricsTab);

$locationProvider.html5Mode(true);
}]);

_module.run(['HawtioNav', (HawtioNav:HawtioMainNav.Registry) => {
HawtioNav.add(metricsTab);
log.debug('loaded Metrics Plugin');
}]);

_module.directive('hkEnter', () => {
return function (scope, element, attrs) {
element.bind('keydown keypress', (event) => {
if (event.which === 13) {
scope.$apply(() => {
scope.$eval(attrs.hkEnter);
});

event.preventDefault();
}
});
};
});

_module.filter('firstUpper', function () {
return function (input, all) {
return (!!input) ? input.replace(/([^\W_]+[^\s-]*) */g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1);
}) : '';
};
});

/**
* Replicates AngularJS 1.4 limitTo filter
*/
_module.filter('limitTo14', function () {
return function(input, limit, begin) {
if (Math.abs(Number(limit)) === Infinity) {
limit = Number(limit);
export var _module = angular.module(HawkularMetrics.pluginName, ['ngResource', 'ui.select', 'hawkular.charts',
'hawkular.services', 'ui.bootstrap', 'topbar', 'patternfly.select', 'angular-momentjs', 'angular-md5']);

_module.config(['$httpProvider', '$locationProvider', '$routeProvider', ($httpProvider, $locationProvider, $routeProvider:ng.route.IRouteProvider) => {
$locationProvider.html5Mode(true);
}]);

_module.filter('firstUpper', function () {
return function (input, all) {
return (!!input) ? input.replace(/([^\W_]+[^\s-]*) */g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1);
}) : '';
};
});

/**
* Replicates AngularJS 1.4 limitTo filter
*/
_module.filter('limitTo14', function () {
return function(input, limit, begin) {
if (Math.abs(Number(limit)) === Infinity) {
limit = Number(limit);
} else {
limit = parseInt(limit, 10);
}
if (isNaN(limit)) { return input; }

if (typeof input === 'number') { input = input.toString(); }
if (!Array.isArray(input) && !(typeof input === 'string')) { return input; }

begin = (!begin || isNaN(begin)) ? 0 : parseInt(begin, 10);
begin = (begin < 0 && begin >= -input.length) ? input.length + begin : begin;

if (limit >= 0) {
return input.slice(begin, begin + limit);
} else {
if (begin === 0) {
return input.slice(limit, input.length);
} else {
limit = parseInt(limit, 10);
return input.slice(Math.max(0, begin + limit), begin);
}
if (isNaN(limit)) { return input; }

if (typeof input === 'number') { input = input.toString(); }
if (!Array.isArray(input) && !(typeof input === 'string')) { return input; }

begin = (!begin || isNaN(begin)) ? 0 : parseInt(begin, 10);
begin = (begin < 0 && begin >= -input.length) ? input.length + begin : begin;
}
};
});

_module.config(['$routeProvider', ($routeProvider) => {
$routeProvider.
// this was for single page.. remove ?
when('/hawkular/:resourceId/:timeOffset?/:endTime?', {templateUrl: 'plugins/metrics/html/single-page.html'}).
when('/metrics/response-time', {
templateUrl: 'plugins/metrics/html/response-time.html',
resolve: {
hkResourceList: function ($filter, $location, $rootScope, $q, HawkularInventory) {
var resPromise = HawkularInventory.Resource.query({
environmentId: globalEnvironmentId
}).$promise;
resPromise.then(function (hkResourceList) {
$location.path('/metrics/response-time/' + hkResourceList[0].id);
}, function () {
$location.url('/error');
});

if (limit >= 0) {
return input.slice(begin, begin + limit);
} else {
if (begin === 0) {
return input.slice(limit, input.length);
} else {
return input.slice(Math.max(0, begin + limit), begin);
// Returning a promise which would never be resolved, so that the page would not render.
// The page will be redirected before rendering based on the resource list loaded above.
return $q.defer().promise;
}
}
};
});

_module.filter('urlEncode', function () {
return window['encodeURIComponent'];
});

_module.config(['$routeProvider', ($routeProvider) => {
$routeProvider.
// this was for single page.. remove ?
when('/hawkular/:resourceId/:timeOffset?/:endTime?',
{templateUrl: 'plugins/metrics/html/single-page.html'}).
when('/metrics/response-time', {
templateUrl: 'plugins/metrics/html/response-time.html',
resolve: {
hkResourceList: function ($filter, $location, $rootScope, $q, HawkularInventory) {
var resPromise = HawkularInventory.Resource.query({
environmentId: globalEnvironmentId
}).$promise;
resPromise.then(function (hkResourceList) {
$location.path('/metrics/response-time/' + hkResourceList[0].id);
}, function () {
$location.url('/error');
});

// Returning a promise which would never be resolved, so that the page would not render.
// The page will be redirected before rendering based on the resource list loaded above.
return $q.defer().promise;
}
}
}).
when('/hawkular-ui/url/url-list', {templateUrl: 'plugins/metrics/html/add-url.html'}).
when('/hawkular-ui/url/response-time/:resourceId/:timeOffset?/:endTime?',
{templateUrl: 'plugins/metrics/html/response-time.html'}).
when('/hawkular-ui/url/availability/:resourceId/:timeOffset?/:endTime?',
{templateUrl: 'plugins/metrics/html/availability.html'}).
when('/hawkular-ui/url/alerts/:resourceId/:timeOffset?/:endTime?',
{templateUrl: 'plugins/metrics/html/alerts.html'}).

when('/hawkular-ui/app/app-list', {templateUrl: 'plugins/metrics/html/app-server-list.html'}).
when('/hawkular-ui/app/app-details/:resourceId/:tabId/:timeOffset?/:endTime?', {
templateUrl: 'plugins/metrics/html/app-details/app-server-details.html',
resolve: {
hideSubNav: function () {
return true;
}).
when('/hawkular-ui/url/url-list', {templateUrl: 'plugins/metrics/html/add-url.html'}).
when('/hawkular-ui/url/response-time/:resourceId/:timeOffset?/:endTime?', {
templateUrl: 'plugins/metrics/html/response-time.html',
reloadOnSearch: false,
resolve: {
resource: function ($route, $location, HawkularInventory) {
var p = HawkularInventory.Resource.get({environmentId: globalEnvironmentId,
resourceId: $route.current.params.resourceId}).$promise;
p.then((response) => {
return response.properties.url;
},
(error) => {
toastr.info('You were redirected to this page because you requested an invalid URL.');
$location.path('/');
});
return p;
}
}
}).
when('/hawkular-ui/url/availability/:resourceId/:timeOffset?/:endTime?', {
templateUrl: 'plugins/metrics/html/availability.html',
reloadOnSearch: false,
resolve: {
resource: function ($route, $location, HawkularInventory) {
var p = HawkularInventory.Resource.get({environmentId: globalEnvironmentId,
resourceId: $route.current.params.resourceId}).$promise;
p.then((response) => {
return response.properties.url;
},
(error) => {
toastr.info('You were redirected to this page because you requested an invalid URL.');
$location.path('/');
});
return p;
}
}
}).
when('/hawkular-ui/url/alerts/:resourceId/:timeOffset?/:endTime?', {
templateUrl: 'plugins/metrics/html/alerts.html',
reloadOnSearch: false,
resolve: {
resource: function ($route, $location, HawkularInventory) {
var p = HawkularInventory.Resource.get({environmentId: globalEnvironmentId,
resourceId: $route.current.params.resourceId}).$promise;
p.then((response) => {
return response.properties.url;
},
(error) => {
toastr.info('You were redirected to this page because you requested an invalid URL.');
$location.path('/');
});
return p;
}
}
}).
when('/hawkular-ui/app/app-list', {templateUrl: 'plugins/metrics/html/app-server-list.html'}).
when('/hawkular-ui/app/app-details/:resourceId/:tabId/:timeOffset?/:endTime?', {
templateUrl: 'plugins/metrics/html/app-details/app-server-details.html',
reloadOnSearch: false,
resolve: {
resource: function ($route, $location, HawkularInventory) {
var redirectMissingAppServer = function() {
toastr.info('You were redirected to this page because you requested an invalid Application Server.');
$location.path('/hawkular-ui/app/app-list');
};
var checkAppServerExists = function() {
var p = HawkularInventory.FeedResource.get({
environmentId: globalEnvironmentId,
feedId: globalFeedId,
resourceId: '[' + $route.current.params.resourceId + '~/]'
}).$promise;
p.then((response) => {
return response;
},
(error) => redirectMissingAppServer()
);
return p;
};
var isValidAppServer = function() {
if (!globalFeedId) {
return HawkularInventory.Feed.query({environmentId: globalEnvironmentId}).$promise
.then((response) => {
globalFeedId = response.length && response[0].id;
if (globalFeedId) {
return checkAppServerExists();
}
}
}).
otherwise({redirectTo: '/hawkular-ui/url/url-list'});
}]);
}
/*,
(error) => redirectMissingAppServer()*/
);
} else {
return checkAppServerExists();
}
};
return isValidAppServer();
}
}
}).
otherwise({redirectTo: '/hawkular-ui/url/url-list'});
}]);

hawtioPluginLoader.addModule(HawkularMetrics.pluginName);
hawtioPluginLoader.addModule(HawkularMetrics.pluginName);
}

0 comments on commit 03868a1

Please sign in to comment.