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

Commit

Permalink
Refactor Sidebar to Subtab to better reflect its purpose. Cleanup var…
Browse files Browse the repository at this point in the history
…ious things to ES6.
  • Loading branch information
mtho11 committed Sep 29, 2015
1 parent 09e76a3 commit 9681de7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,20 @@ module Subtab {
public templateUrl = templatePath;
}

export var SubtabController = _module.controller('Subtab.SubtabController',
//@todo: Change to controller class and controllerAs style
export let SubtabController = _module.controller('Subtab.SubtabController',
['$scope', '$rootScope', '$location', 'HawkularNav', 'HawkularInventory', ($scope, $rootScope, $location,
HawkularNav, HawkularInventory) => {

$scope.isSinglePage = function () {
return $location.path().indexOf('/metrics') !== 0;
};

$scope.isAlertsPage = function () {
$scope.isAlertsPage = () => {
return $location.path().indexOf('/hawkular/ui/alert-center') !== 0;
};

$scope.isAppServerPage = function () {
$scope.isAppServerPage = () => {
return $location.path().indexOf('/hawkular-ui/app/') === 0;
};

$scope.getClass = function (path) {
$scope.getClass = (path) => {
return $location.path().indexOf(path) === 0 ? 'active' : '';
};

Expand All @@ -56,18 +53,18 @@ module Subtab {
'31536000000': 'Last Year'
};

$scope.getFormattedDate = function () {
var diff = $scope.hkParams.timeOffset;
$scope.getFormattedDate = () => {
let diff = $scope.hkParams.timeOffset;

// FIXME: Use moment ?
$scope.offsetName = $scope.rangeNames[$scope.hkParams.timeOffset] || 'Custom';

// TODO: Use this for custom
// var momStart = moment($scope.hkStartTimestamp);
// var momEnd = moment($scope.hkEndTimestamp);
// let momStart = moment($scope.hkStartTimestamp);
// let momEnd = moment($scope.hkEndTimestamp);

var momStart = moment().subtract($scope.hkParams.timeOffset, 'milliseconds');
var momEnd = moment();
let momStart = moment().subtract($scope.hkParams.timeOffset, 'milliseconds');
let momEnd = moment();

if (diff < 24 * 60 * 60 * 1000) {
return momStart.format('D MMM YYYY') + ' ' + momStart.format('HH:mm') + ' - ' +
Expand All @@ -77,22 +74,22 @@ module Subtab {
}
};

$scope.setRange = function (range) {
$scope.setRange = (range) => {
HawkularNav.setTimestamp(moment.duration(range).valueOf());
};

$scope.getUrlFromId = function (id) {
$scope.getUrlFromId = (id) => {
if (!$scope.resource) {
$scope.resource = HawkularInventory.Resource.get({environmentId: globalEnvironmentId, resourcePath: id},
function (data) {
(data) => {
$scope.resourceName = data.properties.url;
});
}
return $scope.resource;
};

// FIXME: Mock data.. remove when we have real app servers
$scope.getAppServerFromId = function (id) {
$scope.getAppServerFromId = (id) => {
$scope.resourceName = id;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/// <reference path='topbarPlugin.ts'/>
module Topbar {

var log:Logging.Logger = Logger.get('Topbar');

export class TopbarDirective {

Expand All @@ -30,12 +29,12 @@ module Topbar {
}

export var TopbarController = _module.controller('Topbar.TopbarController',
['$scope', '$rootScope', '$location', '$route', '$routeParams', 'HawkularNav',
($scope, $rootScope, $location, $route, $routeParams, HawkularNav) => {
['$scope', '$rootScope', '$location',
($scope, $rootScope, $location) => {

$scope.getClass = function(path) {
$scope.getClass = function (path) {
return $location.path().indexOf(path) === 0 ? 'active' : '';
};
};

}]);
}]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ module Topbar {

export var pluginName = 'topbar';

export var log:Logging.Logger = Logger.get(pluginName);

export var templatePath = 'plugins/directives/topbar/html/topbar.html';

export var globalEnvironmentId = 'test';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Topbar {

export var _module = angular.module(pluginName, ['ngResource', 'hawkular.services', 'ui.bootstrap']);

_module.directive('hawkularTopbar', function () {
_module.directive('hawkularTopbar', () => {
return new Topbar.TopbarDirective();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,37 @@ module Topbar {
public static $inject = ['$rootScope', '$route', '$routeParams', 'HawkularInventory'];


constructor(private $rootScope: any, private $route: any, private $routeParams: any,
private HawkularInventory: any) {
constructor(private $rootScope:any,
private $route:any,
private $routeParams:any,
private HawkularInventory:any) {
$rootScope.hkParams = $routeParams || [];

// default time period set to 24 hours
var defaultOffset = 1 * 60 * 60 * 1000;
var defaultOffset = 1 * 60 * 60 * 1000;

var init = (tenantId: TenantId) => {
var init = (tenantId:string) => {
HawkularInventory.Resource.query({environmentId: globalEnvironmentId}, (resourceList) => {
$rootScope.hkResources = resourceList;
for (var i = 0; i < resourceList.length; i++) {
if(resourceList[i].id === $rootScope.hkParams.resourceId) {
if (resourceList[i].id === $rootScope.hkParams.resourceId) {
$rootScope.selectedResource = resourceList[i];
}
}
});

$rootScope.hkParams.timeOffset = $routeParams.timeOffset || defaultOffset;
$rootScope.hkEndTimestamp = $routeParams.endTimestamp || moment().valueOf();
$rootScope.hkStartTimestamp = moment().subtract($rootScope.hkParams.timeOffset, 'milliseconds').valueOf();
$rootScope.hkStartTimestamp = moment().subtract($rootScope.hkParams.timeOffset, 'milliseconds').valueOf();

$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
$rootScope.hkParams = current.params;

$rootScope.hkParams.timeOffset = $routeParams.timeOffset || defaultOffset;
$rootScope.hkEndTimestamp = $routeParams.endTimestamp || moment().valueOf();
$rootScope.hkStartTimestamp = moment().subtract($rootScope.hkParams.timeOffset, 'milliseconds').valueOf();
$rootScope.hkStartTimestamp = moment().subtract($rootScope.hkParams.timeOffset, 'milliseconds').valueOf();

/* not used anymore, was for topbar dropdown
HawkularInventory.Resource.query({environmentId: globalEnvironmentId}, (resourceList) => {
$rootScope.hkResources = resourceList;
for (var i = 0; i < resourceList.length; i++) {
if(resourceList[i].id === $rootScope.hkParams.resourceId) {
$rootScope.selectedResource = resourceList[i];
}
}
});
*/

}, this);
}, this);
};
var tenantId = this.$rootScope.currentPersona && this.$rootScope.currentPersona.id;
if (tenantId) {
Expand Down

This file was deleted.

0 comments on commit 9681de7

Please sign in to comment.