2015-02-19 21:21:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The application header bar.
|
|
|
|
*/
|
|
|
|
angular.module('quay').directive('headerBar', function () {
|
|
|
|
var number = 0;
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
|
|
|
templateUrl: '/static/directives/header-bar.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: false,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
},
|
2015-04-08 18:39:52 +00:00
|
|
|
controller: function($rootScope, $scope, $element, $location, $timeout, hotkeys, UserService, PlanService, ApiService, NotificationService, Config, CreateService) {
|
2015-04-08 19:15:21 +00:00
|
|
|
$scope.isNewLayout = Config.isNewLayout();
|
2015-04-08 18:39:52 +00:00
|
|
|
|
2015-04-08 19:15:21 +00:00
|
|
|
if ($scope.isNewLayout) {
|
|
|
|
// Register hotkeys:
|
|
|
|
hotkeys.add({
|
|
|
|
combo: '/',
|
|
|
|
description: 'Show search',
|
|
|
|
callback: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
$scope.toggleSearch();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
hotkeys.add({
|
|
|
|
combo: 'alt+c',
|
|
|
|
description: 'Create new repository',
|
|
|
|
callback: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
$location.url('/new');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-04-08 18:39:52 +00:00
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
$scope.notificationService = NotificationService;
|
2015-04-06 23:17:18 +00:00
|
|
|
$scope.searchVisible = false;
|
|
|
|
$scope.currentSearchQuery = null;
|
|
|
|
$scope.searchResultState = null;
|
2015-04-07 22:38:58 +00:00
|
|
|
$scope.showBuildDialogCounter = 0;
|
2015-02-19 21:21:54 +00:00
|
|
|
|
|
|
|
// Monitor any user changes and place the current user into the scope.
|
|
|
|
UserService.updateUserIn($scope);
|
|
|
|
|
2015-04-03 21:56:08 +00:00
|
|
|
|
2015-04-07 22:33:43 +00:00
|
|
|
$scope.currentPageContext = {};
|
|
|
|
|
|
|
|
$rootScope.$watch('currentPage.scope.viewuser', function(u) {
|
|
|
|
$scope.currentPageContext['viewuser'] = u;
|
|
|
|
});
|
|
|
|
|
|
|
|
$rootScope.$watch('currentPage.scope.organization', function(o) {
|
|
|
|
$scope.currentPageContext['organization'] = o;
|
|
|
|
});
|
|
|
|
|
|
|
|
$rootScope.$watch('currentPage.scope.repository', function(r) {
|
|
|
|
$scope.currentPageContext['repository'] = r;
|
|
|
|
});
|
2015-04-06 23:17:18 +00:00
|
|
|
|
|
|
|
var conductSearch = function(query) {
|
|
|
|
if (!query) { $scope.searchResultState = null; return; }
|
|
|
|
|
|
|
|
$scope.searchResultState = {
|
|
|
|
'state': 'loading'
|
|
|
|
};
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
'query': query
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.conductSearch(null, params).then(function(resp) {
|
|
|
|
if (!$scope.searchVisible) { return; }
|
|
|
|
|
|
|
|
$scope.searchResultState = {
|
|
|
|
'state': resp.results.length ? 'results' : 'no-results',
|
|
|
|
'results': resp.results,
|
|
|
|
'current': -1
|
|
|
|
};
|
2015-04-07 22:33:43 +00:00
|
|
|
}, function(resp) {
|
|
|
|
$scope.searchResultState = null;
|
2015-04-06 23:17:18 +00:00
|
|
|
}, /* background */ true);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$watch('currentSearchQuery', conductSearch);
|
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
$scope.signout = function() {
|
|
|
|
ApiService.logout().then(function() {
|
|
|
|
UserService.load();
|
|
|
|
$location.path('/');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.appLinkTarget = function() {
|
|
|
|
if ($("div[ng-view]").length === 0) {
|
|
|
|
return "_self";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getEnterpriseLogo = function() {
|
|
|
|
if (!Config.ENTERPRISE_LOGO_URL) {
|
|
|
|
return '/static/img/quay-logo.png';
|
|
|
|
}
|
|
|
|
|
|
|
|
return Config.ENTERPRISE_LOGO_URL;
|
|
|
|
};
|
2015-04-06 23:17:18 +00:00
|
|
|
|
|
|
|
$scope.toggleSearch = function() {
|
|
|
|
$scope.searchVisible = !$scope.searchVisible;
|
|
|
|
if ($scope.searchVisible) {
|
|
|
|
$('#search-box-input').focus();
|
|
|
|
if ($scope.currentSearchQuery) {
|
|
|
|
conductSearch($scope.currentSearchQuery);
|
|
|
|
}
|
|
|
|
} else {
|
2015-04-08 18:39:52 +00:00
|
|
|
$('#search-box-input').blur()
|
2015-04-06 23:17:18 +00:00
|
|
|
$scope.searchResultState = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getSearchBoxClasses = function(searchVisible, searchResultState) {
|
|
|
|
var classes = searchVisible ? 'search-visible ' : '';
|
|
|
|
if (searchResultState) {
|
|
|
|
classes += 'results-visible';
|
|
|
|
}
|
|
|
|
return classes;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.handleSearchKeyDown = function(e) {
|
2015-04-07 16:11:16 +00:00
|
|
|
if (e.keyCode == 27) {
|
|
|
|
$scope.toggleSearch();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-08 18:39:52 +00:00
|
|
|
var state = $scope.searchResultState;
|
|
|
|
if (!state || !state['results']) { return; }
|
2015-04-06 23:17:18 +00:00
|
|
|
|
|
|
|
if (e.keyCode == 40) {
|
2015-04-08 18:39:52 +00:00
|
|
|
state['current']++;
|
2015-04-06 23:17:18 +00:00
|
|
|
e.preventDefault();
|
|
|
|
} else if (e.keyCode == 38) {
|
2015-04-08 18:39:52 +00:00
|
|
|
state['current']--;
|
2015-04-06 23:17:18 +00:00
|
|
|
e.preventDefault();
|
|
|
|
} else if (e.keyCode == 13) {
|
2015-04-08 18:39:52 +00:00
|
|
|
var current = state['current'];
|
|
|
|
if (current >= 0 && current < state['results'].length) {
|
|
|
|
$scope.showResult(state['results'][current]);
|
2015-04-06 23:17:18 +00:00
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
2015-04-08 18:39:52 +00:00
|
|
|
if (state['current'] < -1) {
|
|
|
|
state['current'] = state['results'].length - 1;
|
|
|
|
} else if (state['current'] >= state['results'].length) {
|
|
|
|
state['current'] = 0;
|
2015-04-06 23:17:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.showResult = function(result) {
|
|
|
|
$scope.toggleSearch();
|
|
|
|
$timeout(function() {
|
2015-04-08 18:39:52 +00:00
|
|
|
$scope.currentSearchQuery = '';
|
2015-04-06 23:17:18 +00:00
|
|
|
$location.url(result['href'])
|
|
|
|
}, 500);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.setCurrentResult = function(result) {
|
|
|
|
if (!$scope.searchResultState) { return; }
|
|
|
|
$scope.searchResultState['current'] = result;
|
|
|
|
};
|
2015-04-07 22:33:43 +00:00
|
|
|
|
|
|
|
$scope.getNamespace = function(context) {
|
|
|
|
if (!context) { return null; }
|
|
|
|
|
|
|
|
if (context.repository && context.repository.namespace) {
|
|
|
|
return context.repository.namespace;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context.organization && context.organization.name) {
|
|
|
|
return context.organization.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context.viewuser && context.viewuser.username) {
|
|
|
|
return context.viewuser.username;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.canAdmin = function(namespace) {
|
|
|
|
if (!namespace) { return false; }
|
|
|
|
return UserService.isNamespaceAdmin(namespace);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.isOrganization = function(namespace) {
|
|
|
|
if (!namespace) { return false; }
|
|
|
|
return UserService.isOrganization(namespace);
|
|
|
|
};
|
|
|
|
|
2015-04-07 22:38:58 +00:00
|
|
|
$scope.startBuild = function(context) {
|
|
|
|
$scope.showBuildDialogCounter++;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.handleBuildStarted = function(build, context) {
|
|
|
|
$location.url('/repository/' + context.repository.namespace + '/' + context.repository.name + '/build/' + build.id);
|
|
|
|
};
|
|
|
|
|
2015-04-07 22:33:43 +00:00
|
|
|
$scope.createRobot = function(context) {
|
|
|
|
var namespace = $scope.getNamespace(context);
|
2015-04-08 15:54:04 +00:00
|
|
|
CreateService.askCreateRobot(function(created) {
|
|
|
|
if (isorg) {
|
|
|
|
$location.url('/organization/' + namespace + '?tab=robots');
|
|
|
|
} else {
|
|
|
|
$location.url('/user/' + namespace + '?tab=robots');
|
2015-04-07 22:33:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.createTeam = function(context) {
|
|
|
|
var namespace = $scope.getNamespace(context);
|
|
|
|
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { return; }
|
|
|
|
|
2015-04-08 15:54:04 +00:00
|
|
|
CreateService.askCreateTeam(function(created) {
|
2015-04-07 22:33:43 +00:00
|
|
|
$location.url('/organization/' + namespace + '/teams/' + teamname);
|
|
|
|
});
|
|
|
|
};
|
2015-02-19 21:21:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|