refactor(dashboard): Restructured front-end dashboard code.
This commit is contained in:
@ -1,31 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('etcdBrowser', ['ngRoute', 'etcd', 'timeRelative'])
|
||||
|
||||
.constant('keyPrefix', '/v2/keys/')
|
||||
|
||||
.config(['$routeProvider', 'keyPrefix', function ($routeProvider, keyPrefix) {
|
||||
//read localstorage
|
||||
var previousPath = localStorage.getItem('etcd_path');
|
||||
|
||||
$routeProvider
|
||||
.when('/', {
|
||||
redirectTo: keyPrefix
|
||||
})
|
||||
.otherwise({
|
||||
templateUrl: 'views/browser.html',
|
||||
controller: 'MainCtrl'
|
||||
});
|
||||
}])
|
||||
|
||||
.controller('MainCtrl', ['$scope', '$location', 'EtcdV2', 'keyPrefix', function ($scope, $location, EtcdV2, keyPrefix) {
|
||||
angular.module('etcdControlPanel')
|
||||
.controller('BrowserCtrl', function ($scope, $location, $window, EtcdV2, keyPrefix, $, _, moment) {
|
||||
$scope.save = 'etcd-save-hide';
|
||||
$scope.preview = 'etcd-preview-hide';
|
||||
$scope.enableBack = true;
|
||||
$scope.writingNew = false;
|
||||
$scope.key = '';
|
||||
$scope.list = [];
|
||||
|
||||
// etcdPath is the path to the key that is currenly being looked at.
|
||||
$scope.etcdPath = $location.path();
|
||||
$scope.etcdPath = keyPrefix;
|
||||
|
||||
$scope.setActiveKey = function(key) {
|
||||
$scope.etcdPath = keyPrefix + _.str.trim(key, '/');
|
||||
};
|
||||
|
||||
$scope.$watch('etcdPath', function() {
|
||||
function etcdPathKey() {
|
||||
@ -44,7 +33,7 @@ angular.module('etcdBrowser', ['ngRoute', 'etcd', 'timeRelative'])
|
||||
localStorage.setItem('etcdPath', $scope.etcdPath);
|
||||
$scope.enableBack = true;
|
||||
//disable back button if at root (/v2/keys/)
|
||||
if($scope.etcdPath === keyPrefix) {
|
||||
if ($scope.etcdPath === keyPrefix) {
|
||||
$scope.enableBack = false;
|
||||
}
|
||||
|
||||
@ -63,7 +52,7 @@ angular.module('etcdBrowser', ['ngRoute', 'etcd', 'timeRelative'])
|
||||
$scope.list = data.node.nodes;
|
||||
$scope.preview = 'etcd-preview-hide';
|
||||
} else {
|
||||
$scope.singleValue = data.value;
|
||||
$scope.singleValue = data.node.value;
|
||||
$scope.preview = 'etcd-preview-reveal';
|
||||
$scope.key.getParent().get().success(function(data) {
|
||||
$scope.list = data.node.nodes;
|
||||
@ -79,14 +68,14 @@ angular.module('etcdBrowser', ['ngRoute', 'etcd', 'timeRelative'])
|
||||
//back button click
|
||||
$scope.back = function() {
|
||||
$scope.etcdPath = $scope.key.getParent().path();
|
||||
$scope.syncLocation();
|
||||
//$scope.syncLocation();
|
||||
$scope.preview = 'etcd-preview-hide';
|
||||
$scope.writingNew = false;
|
||||
};
|
||||
|
||||
$scope.syncLocation = function() {
|
||||
$location.path($scope.etcdPath);
|
||||
};
|
||||
//$scope.syncLocation = function() {
|
||||
//$location.path($scope.etcdPath);
|
||||
//};
|
||||
|
||||
$scope.showSave = function() {
|
||||
$scope.save = 'etcd-save-reveal';
|
||||
@ -136,56 +125,15 @@ angular.module('etcdBrowser', ['ngRoute', 'etcd', 'timeRelative'])
|
||||
};
|
||||
|
||||
$scope.getHeight = function() {
|
||||
return $(window).height();
|
||||
return $($window).height();
|
||||
};
|
||||
|
||||
$scope.$watch($scope.getHeight, function() {
|
||||
$('.etcd-body').css('height', $scope.getHeight()-45);
|
||||
});
|
||||
window.onresize = function(){
|
||||
|
||||
$window.onresize = function(){
|
||||
$scope.$apply();
|
||||
};
|
||||
|
||||
}])
|
||||
|
||||
.directive('ngEnter', function() {
|
||||
return function(scope, element, attrs) {
|
||||
element.bind('keydown keypress', function(event) {
|
||||
if(event.which === 13) {
|
||||
scope.$apply(function(){
|
||||
scope.$eval(attrs.ngEnter);
|
||||
});
|
||||
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
};
|
||||
})
|
||||
|
||||
.directive('highlight', function() {
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function(scope, element, attrs) {
|
||||
if('#' + scope.etcdPath === attrs.href) {
|
||||
element.parent().parent().addClass('etcd-selected');
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
moment.lang('en', {
|
||||
relativeTime : {
|
||||
future: 'Expires in %s',
|
||||
past: 'Expired %s ago',
|
||||
s: 'seconds',
|
||||
m: 'a minute',
|
||||
mm: '%d minutes',
|
||||
h: 'an hour',
|
||||
hh: '%d hours',
|
||||
d: 'a day',
|
||||
dd: '%d days',
|
||||
M: 'a month',
|
||||
MM: '%d months',
|
||||
y: 'a year',
|
||||
yy: '%d years'
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user