Skip to content

Commit

Permalink
Create a global app config object - for now store base URL informatio…
Browse files Browse the repository at this point in the history
…n. (#384)

This means we no longer have to manually edit services js files if using
grunt or if the server is bound to some other IP/port that the grunt server is not.
  • Loading branch information
jmazzitelli authored and jshaughn committed Jul 11, 2017
1 parent a149a7e commit 208c49b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
15 changes: 4 additions & 11 deletions ui/src/main/ui/src/actions/actions-service.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
angular.module('hwk.actionsModule').service('hwk.actionsService', ['$resource',
function ($resource) {
angular.module('hwk.actionsModule').service('hwk.actionsService', ['$resource', '$rootScope',
function ($resource, $rootScope) {
'use strict';

var host = '';

// [lponce] TODO Enable this for testing
// host = 'http://localhost:8080';

var baseUrl = host + '/hawkular/alerts';

this.Actions = function (tenantId) {
return $resource(baseUrl + '/actions', {}, {
return $resource($rootScope.appConfig.server.baseUrl + '/actions', {}, {
get: {
method: 'GET',
headers: {'Hawkular-Tenant': tenantId}
Expand All @@ -19,7 +12,7 @@ angular.module('hwk.actionsModule').service('hwk.actionsService', ['$resource',
};

this.ActionDefinition = function (tenantId, actionPlugin, actionId) {
return $resource(baseUrl + '/actions/:actionPlugin/:actionId', {
return $resource($rootScope.appConfig.server.baseUrl + '/actions/:actionPlugin/:actionId', {
actionPlugin: actionPlugin,
actionId: actionId
}, {
Expand Down
36 changes: 34 additions & 2 deletions ui/src/main/ui/src/app/controllers/app-controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
angular.module('hwk.appModule').controller( 'hwk.appController', ['$scope', '$rootScope', '$resource',
function ($scope, $rootScope, $resource ) {
angular.module('hwk.appModule').controller( 'hwk.appController', ['$scope', '$rootScope', '$resource', '$location',
function ($scope, $rootScope, $resource, $location ) {
'use strict';

//
// Global Application Configuration - in root scope so services and controllers can use it
//
// [mazz] developers can change host and port if the server is running somewhere that can't be guessed
$rootScope.appConfig = {};
$rootScope.appConfig.server = {};
$rootScope.appConfig.server.protocol = $location.protocol();
$rootScope.appConfig.server.host = $location.host();
$rootScope.appConfig.server.port = $location.port();

// if the location is 0.0.0.0 set the host to the loopback address - this assumes the server is bound there
if ($rootScope.appConfig.server.host === '0.0.0.0') {
$rootScope.appConfig.server.host = '127.0.0.1';
}
// if port is 8003, assume this is running in a grunt development environment in which the server is at 8080
if ($rootScope.appConfig.server.port === 8003) {
$rootScope.appConfig.server.port = 8080;
}

$rootScope.appConfig.server.baseUrl = $rootScope.appConfig.server.protocol
+ "://"
+ $rootScope.appConfig.server.host
+ ":"
+ $rootScope.appConfig.server.port
+ "/hawkular/alerts";
console.log('[App Config] ' + angular.toJson($rootScope.appConfig));

//
// Hawkular Alerting Navigation
// [lponce] Perhaps in the future is better to have it in the template itself
//
$scope.navigationItems = [
{
title: "Dashboard",
Expand All @@ -22,6 +51,9 @@ angular.module('hwk.appModule').controller( 'hwk.appController', ['$scope', '$ro
}
];

//
// Global tenant setting
//
$scope.newTenant = {};

// [lponce] comment if you don't want a pre-filled tenant
Expand Down
15 changes: 4 additions & 11 deletions ui/src/main/ui/src/dashboard/dashboard-service.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
angular.module('hwk.dashboardModule').service('hwk.dashboardService', ['$resource',
function ($resource) {
angular.module('hwk.dashboardModule').service('hwk.dashboardService', ['$resource', '$rootScope',
function ($resource, $rootScope) {
'use strict';

var host = '';

// [lponce] TODO Enable this for testing
// host = 'http://localhost:8080';

var baseUrl = host + '/hawkular/alerts';

this.Alert = function (tenantId) {
return $resource(baseUrl, {}, {
return $resource($rootScope.appConfig.server.baseUrl, {}, {
query: {
method: 'GET',
isArray: true,
Expand All @@ -20,7 +13,7 @@ angular.module('hwk.dashboardModule').service('hwk.dashboardService', ['$resourc
};

this.Event = function (tenantId) {
return $resource(baseUrl + '/events', {eventType: 'EVENT'}, {
return $resource($rootScope.appConfig.server.baseUrl + '/events', {eventType: 'EVENT'}, {
query: {
method: 'GET',
isArray: true,
Expand Down
15 changes: 4 additions & 11 deletions ui/src/main/ui/src/triggers/triggers-service.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
angular.module('hwk.triggersModule').service('hwk.triggersService', ['$resource',
function ($resource) {
angular.module('hwk.triggersModule').service('hwk.triggersService', ['$resource', '$rootScope',
function ($resource, $rootScope) {
'use strict';

var host = '';

// [lponce] TODO Enable this for testing
// host = 'http://localhost:8080';

var baseUrl = host + '/hawkular/alerts';

this.Trigger = function (tenantId) {
return $resource(baseUrl + '/triggers', {}, {
return $resource($rootScope.appConfig.server.baseUrl + '/triggers', {}, {
query: {
method: 'GET',
isArray: true,
Expand All @@ -20,7 +13,7 @@ angular.module('hwk.triggersModule').service('hwk.triggersService', ['$resource'
};

this.FullTrigger = function (tenantId, triggerId) {
return $resource(baseUrl + '/triggers/trigger/:triggerId', {
return $resource($rootScope.appConfig.server.baseUrl + '/triggers/trigger/:triggerId', {
triggerId: triggerId
}, {
get: {
Expand Down

0 comments on commit 208c49b

Please sign in to comment.