2013-12-10 06:38:05 +00:00
|
|
|
var TEAM_PATTERN = '^[a-zA-Z][a-zA-Z0-9]+$';
|
2015-09-08 14:10:00 +00:00
|
|
|
var ROBOT_PATTERN = '^[a-zA-Z][a-zA-Z0-9_]{3,29}$';
|
2014-10-01 18:23:15 +00:00
|
|
|
var USER_PATTERN = '^[a-z0-9_]{4,30}$';
|
2013-12-10 06:38:05 +00:00
|
|
|
|
2015-02-20 23:15:48 +00:00
|
|
|
// Define the pages module.
|
|
|
|
quayPages = angular.module('quayPages', [], function(){});
|
|
|
|
|
|
|
|
// Define a constant for creating pages.
|
|
|
|
quayPages.constant('pages', {
|
|
|
|
'_pages': {},
|
|
|
|
|
|
|
|
'create': function(pageName, templateName, opt_controller, opt_flags, opt_profiles) {
|
|
|
|
var profiles = opt_profiles || ['old-layout', 'layout'];
|
|
|
|
for (var i = 0; i < profiles.length; ++i) {
|
|
|
|
this._pages[profiles[i] + ':' + pageName] = {
|
|
|
|
'name': pageName,
|
|
|
|
'controller': opt_controller,
|
|
|
|
'templateName': templateName,
|
|
|
|
'flags': opt_flags || {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'get': function(pageName, profiles) {
|
|
|
|
for (var i = 0; i < profiles.length; ++i) {
|
|
|
|
var current = profiles[i];
|
|
|
|
var key = current.id + ':' + pageName;
|
|
|
|
var page = this._pages[key];
|
|
|
|
if (page) {
|
|
|
|
return [current, page];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-08 18:39:52 +00:00
|
|
|
quayDependencies = ['ngRoute', 'chieffancypants.loadingBar', 'cfp.hotkeys', 'angular-tour', 'restangular', 'angularMoment',
|
2015-04-08 20:40:22 +00:00
|
|
|
'mgcrea.ngStrap', 'ngCookies', 'ngSanitize', 'angular-md5', 'pasvaz.bindonce', 'ansiToHtml', 'debounce',
|
2015-07-31 17:38:02 +00:00
|
|
|
'core-ui', 'core-config-setup', 'quayPages', 'infinite-scroll'];
|
2014-04-09 01:10:33 +00:00
|
|
|
|
|
|
|
if (window.__config && window.__config.MIXPANEL_KEY) {
|
|
|
|
quayDependencies.push('angulartics');
|
|
|
|
quayDependencies.push('angulartics.mixpanel');
|
|
|
|
}
|
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
// Define the application.
|
2014-04-09 01:10:33 +00:00
|
|
|
quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoadingBarProvider) {
|
2015-02-19 21:21:54 +00:00
|
|
|
cfpLoadingBarProvider.includeSpinner = false;
|
|
|
|
});
|
|
|
|
|
2015-04-21 18:56:48 +00:00
|
|
|
// Disable tooltips on touch devices.
|
|
|
|
quayApp.config(['$tooltipProvider', function ($tooltipProvider) {
|
|
|
|
var tooltipFactory = $tooltipProvider.$get[$tooltipProvider.$get.length - 1];
|
|
|
|
|
|
|
|
// decorate the tooltip getter
|
|
|
|
$tooltipProvider.$get[$tooltipProvider.$get.length - 1] = function($window) {
|
|
|
|
if ('ontouchstart' in $window) {
|
2015-04-21 19:06:12 +00:00
|
|
|
var existing = tooltipFactory.apply(this, arguments);
|
|
|
|
return function(element) {
|
|
|
|
// Note: We only disable bs-tooltip's themselves. $tooltip is used for other things
|
|
|
|
// (such as the datepicker), so we need to be specific when canceling it.
|
|
|
|
if (element.attr('bs-tooltip') == null) {
|
|
|
|
return existing.apply(this, arguments);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
2015-04-21 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tooltipFactory.apply(this, arguments);
|
|
|
|
};
|
|
|
|
}]);
|
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
// Configure the routes.
|
2015-02-20 23:15:48 +00:00
|
|
|
quayApp.config(['$routeProvider', '$locationProvider', 'pages', function($routeProvider, $locationProvider, pages) {
|
2015-02-19 21:21:54 +00:00
|
|
|
$locationProvider.html5Mode(true);
|
|
|
|
|
|
|
|
// WARNING WARNING WARNING
|
|
|
|
// If you add a route here, you must add a corresponding route in thr endpoints/web.py
|
|
|
|
// index rule to make sure that deep links directly deep into the app continue to work.
|
|
|
|
// WARNING WARNING WARNING
|
2015-02-20 23:15:48 +00:00
|
|
|
|
2015-05-04 01:36:06 +00:00
|
|
|
var layoutProfile = 'layout';
|
2015-02-23 19:48:33 +00:00
|
|
|
window.console.log('Using layout profile: ' + layoutProfile);
|
|
|
|
|
2015-02-20 23:15:48 +00:00
|
|
|
var routeBuilder = new AngularRouteBuilder($routeProvider, pages, [
|
|
|
|
// Start with the old pages (if we asked for it).
|
|
|
|
{id: 'old-layout', templatePath: '/static/partials/'},
|
|
|
|
|
|
|
|
// Fallback back combined new/existing pages.
|
|
|
|
{id: 'layout', templatePath: '/static/partials/'}
|
|
|
|
], layoutProfile);
|
|
|
|
|
|
|
|
routeBuilder
|
|
|
|
// Repository View
|
|
|
|
.route('/repository/:namespace/:name', 'repo-view')
|
2015-02-23 19:55:55 +00:00
|
|
|
.route('/repository/:namespace/:name/tag/:tag', 'repo-view')
|
2015-02-20 23:15:48 +00:00
|
|
|
|
|
|
|
// Image View
|
|
|
|
.route('/repository/:namespace/:name/image/:image', 'image-view')
|
|
|
|
|
2015-02-26 22:45:28 +00:00
|
|
|
// Repo Build View
|
|
|
|
.route('/repository/:namespace/:name/build/:buildid', 'build-view')
|
|
|
|
|
2015-02-20 23:15:48 +00:00
|
|
|
// Repo List
|
|
|
|
.route('/repository/', 'repo-list')
|
|
|
|
|
|
|
|
// Organizations
|
|
|
|
.route('/organizations/', 'organizations')
|
|
|
|
|
|
|
|
// New Organization
|
|
|
|
.route('/organizations/new/', 'new-organization')
|
|
|
|
|
|
|
|
// View Organization
|
|
|
|
.route('/organization/:orgname', 'org-view')
|
|
|
|
|
|
|
|
// View Organization Team
|
|
|
|
.route('/organization/:orgname/teams/:teamname', 'team-view')
|
|
|
|
|
|
|
|
// Organization View Application
|
|
|
|
.route('/organization/:orgname/application/:clientid', 'manage-application')
|
|
|
|
|
2016-04-25 19:17:18 +00:00
|
|
|
// View Organization Billing
|
|
|
|
.route('/organization/:orgname/billing', 'billing')
|
|
|
|
|
|
|
|
// View Organization Billing Invoices
|
|
|
|
.route('/organization/:orgname/billing/invoices', 'invoices')
|
|
|
|
|
2015-04-02 20:34:41 +00:00
|
|
|
// View User
|
|
|
|
.route('/user/:username', 'user-view')
|
|
|
|
|
2016-04-25 19:17:18 +00:00
|
|
|
// View User Billing
|
|
|
|
.route('/user/:username/billing', 'billing')
|
|
|
|
|
|
|
|
// View User Billing Invoices
|
|
|
|
.route('/user/:username/billing/invoices', 'invoices')
|
|
|
|
|
2015-02-20 23:15:48 +00:00
|
|
|
// Sign In
|
|
|
|
.route('/signin/', 'signin')
|
|
|
|
|
|
|
|
// New Repository
|
|
|
|
.route('/new/', 'new-repo')
|
|
|
|
|
|
|
|
// ER Management
|
|
|
|
.route('/superuser/', 'superuser')
|
|
|
|
|
|
|
|
// ER Setup
|
|
|
|
.route('/setup/', 'setup')
|
|
|
|
|
|
|
|
// Plans
|
|
|
|
.route('/plans/', 'plans')
|
|
|
|
|
|
|
|
// Tutorial
|
|
|
|
.route('/tutorial/', 'tutorial')
|
|
|
|
|
|
|
|
// Contact
|
|
|
|
.route('/contact/', 'contact')
|
|
|
|
|
|
|
|
// About
|
2015-02-23 16:51:07 +00:00
|
|
|
.route('/about/', 'about')
|
2015-02-20 23:15:48 +00:00
|
|
|
|
|
|
|
// Security
|
2015-02-23 16:51:07 +00:00
|
|
|
.route('/security/', 'security')
|
2015-02-20 23:15:48 +00:00
|
|
|
|
|
|
|
// Landing Page
|
|
|
|
.route('/', 'landing')
|
|
|
|
|
|
|
|
// Tour
|
|
|
|
.route('/tour/', 'tour')
|
|
|
|
.route('/tour/features', 'tour')
|
|
|
|
.route('/tour/organizations', 'tour')
|
|
|
|
.route('/tour/enterprise', 'tour')
|
|
|
|
|
|
|
|
// Confirm Invite
|
|
|
|
.route('/confirminvite', 'confirm-invite')
|
|
|
|
|
2016-04-25 18:16:35 +00:00
|
|
|
// Enterprise marketing page
|
|
|
|
.route('/enterprise', 'enterprise')
|
|
|
|
|
2015-02-20 23:15:48 +00:00
|
|
|
// Default: Redirect to the landing page
|
|
|
|
.otherwise({redirectTo: '/'});
|
2015-02-19 21:21:54 +00:00
|
|
|
}]);
|
2014-01-14 21:01:37 +00:00
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
// Configure compile provider to add additional URL prefixes to the sanitization list. We use
|
|
|
|
// these on the Contact page.
|
|
|
|
quayApp.config(function($compileProvider) {
|
|
|
|
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|irc):/);
|
|
|
|
});
|
2014-01-14 21:01:37 +00:00
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
// Configure the API provider.
|
|
|
|
quayApp.config(function(RestangularProvider) {
|
|
|
|
RestangularProvider.setBaseUrl('/api/v1/');
|
|
|
|
});
|
2014-04-05 03:26:10 +00:00
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
// Configure analytics.
|
|
|
|
if (window.__config && window.__config.MIXPANEL_KEY) {
|
|
|
|
quayApp.config(['$analyticsProvider', function($analyticsProvider) {
|
|
|
|
$analyticsProvider.virtualPageviews(true);
|
|
|
|
}]);
|
|
|
|
}
|
2014-04-05 03:26:10 +00:00
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
// Configure sentry.
|
|
|
|
if (window.__config && window.__config.SENTRY_PUBLIC_DSN) {
|
|
|
|
quayApp.config(function($provide) {
|
|
|
|
$provide.decorator("$exceptionHandler", function($delegate) {
|
|
|
|
return function(ex, cause) {
|
|
|
|
$delegate(ex, cause);
|
|
|
|
Raven.captureException(ex, {extra: {cause: cause}});
|
2014-04-05 03:26:10 +00:00
|
|
|
};
|
2013-11-05 22:20:43 +00:00
|
|
|
});
|
2015-02-19 21:21:54 +00:00
|
|
|
});
|
|
|
|
}
|
2014-10-22 18:49:33 +00:00
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
// Run the application.
|
2015-04-22 17:16:10 +00:00
|
|
|
quayApp.run(['$location', '$rootScope', 'Restangular', 'UserService', 'PlanService', '$http', '$timeout', 'CookieService', 'Features', '$anchorScroll', 'UtilService', 'MetaService', 'UIService',
|
|
|
|
function($location, $rootScope, Restangular, UserService, PlanService, $http, $timeout, CookieService, Features, $anchorScroll, UtilService, MetaService, UIService) {
|
2013-12-28 19:07:44 +00:00
|
|
|
|
2015-11-02 19:16:04 +00:00
|
|
|
var defaultTitle = window.__config['REGISTRY_TITLE'] || 'Quay';
|
2015-02-23 19:48:33 +00:00
|
|
|
|
2013-12-28 19:07:44 +00:00
|
|
|
// Handle session security.
|
2014-01-27 18:58:12 +00:00
|
|
|
Restangular.setDefaultRequestParams(['post', 'put', 'remove', 'delete'], {'_csrf_token': window.__token || ''});
|
2013-12-28 19:07:44 +00:00
|
|
|
|
2013-12-11 22:50:48 +00:00
|
|
|
// Handle session expiration.
|
2013-11-12 00:26:56 +00:00
|
|
|
Restangular.setErrorInterceptor(function(response) {
|
2016-04-11 21:28:49 +00:00
|
|
|
//TODO: remove check for error_type (old style errors)
|
2016-04-11 18:51:58 +00:00
|
|
|
var invalid_token = response.data['title'] == 'invalid_token' || response.data['error_type'] == 'invalid_token';
|
|
|
|
if (response.status == 401 && invalid_token && response.data['session_required'] !== false) {
|
2014-09-04 18:24:20 +00:00
|
|
|
$('#sessionexpiredModal').modal({});
|
|
|
|
return false;
|
2013-11-12 00:03:18 +00:00
|
|
|
}
|
2013-11-12 00:26:56 +00:00
|
|
|
|
2014-08-25 19:30:29 +00:00
|
|
|
if (response.status == 503) {
|
|
|
|
$('#cannotContactService').modal({});
|
2014-05-28 19:22:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-10 21:01:36 +00:00
|
|
|
if (response.status == 500) {
|
|
|
|
document.location = '/500';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-12 00:26:56 +00:00
|
|
|
return true;
|
2013-11-12 00:03:18 +00:00
|
|
|
});
|
|
|
|
|
2013-12-11 22:50:48 +00:00
|
|
|
// Check if we need to redirect based on a previously chosen plan.
|
2014-03-19 18:27:33 +00:00
|
|
|
var result = PlanService.handleNotedPlan();
|
|
|
|
|
|
|
|
// Check to see if we need to show a redirection page.
|
|
|
|
var redirectUrl = CookieService.get('quay.redirectAfterLoad');
|
|
|
|
CookieService.clear('quay.redirectAfterLoad');
|
|
|
|
|
|
|
|
if (!result && redirectUrl && redirectUrl.indexOf(window.location.href) == 0) {
|
|
|
|
window.location = redirectUrl;
|
|
|
|
return;
|
|
|
|
}
|
2013-12-11 22:50:48 +00:00
|
|
|
|
2014-04-11 21:15:03 +00:00
|
|
|
$rootScope.$watch('description', function(description) {
|
|
|
|
if (!description) {
|
|
|
|
description = 'Hosted private docker repositories. Includes full user management and history. Free for public repositories.';
|
|
|
|
}
|
2014-11-24 21:07:38 +00:00
|
|
|
|
2014-04-11 21:15:03 +00:00
|
|
|
// Note: We set the content of the description tag manually here rather than using Angular binding
|
|
|
|
// because we need the <meta> tag to have a default description that is not of the form "{{ description }}",
|
|
|
|
// we read by tools that do not properly invoke the Angular code.
|
2014-11-24 21:07:38 +00:00
|
|
|
$('#descriptionTag').attr('content', description);
|
2014-04-11 21:15:03 +00:00
|
|
|
});
|
|
|
|
|
2015-04-22 17:16:10 +00:00
|
|
|
// Listen for scope changes and update the title and description accordingly.
|
|
|
|
$rootScope.$watch(function() {
|
|
|
|
var title = MetaService.getTitle($rootScope.currentPage) || defaultTitle;
|
|
|
|
if ($rootScope.title != title) {
|
|
|
|
$rootScope.title = title;
|
|
|
|
}
|
|
|
|
|
|
|
|
var description = MetaService.getDescription($rootScope.currentPage) || '';
|
|
|
|
if ($rootScope.description != description) {
|
|
|
|
$rootScope.description = description;
|
2013-12-10 04:33:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-26 23:07:25 +00:00
|
|
|
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
|
2014-04-30 03:48:06 +00:00
|
|
|
$rootScope.current = current.$$route;
|
2015-02-27 21:52:56 +00:00
|
|
|
$rootScope.currentPage = current;
|
2014-04-30 03:48:06 +00:00
|
|
|
|
2015-02-27 21:52:56 +00:00
|
|
|
$rootScope.pageClass = '';
|
2013-11-19 00:03:35 +00:00
|
|
|
|
2015-02-27 21:52:56 +00:00
|
|
|
if (!current.$$route) { return; }
|
2014-04-24 04:40:01 +00:00
|
|
|
|
2016-04-06 19:57:40 +00:00
|
|
|
var pageClass = current.$$route.pageClass || '';
|
|
|
|
if (typeof pageClass != 'string') {
|
|
|
|
pageClass = pageClass(Features);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$rootScope.pageClass = pageClass;
|
2014-12-22 20:13:23 +00:00
|
|
|
$rootScope.newLayout = !!current.$$route.newLayout;
|
2015-02-27 21:52:56 +00:00
|
|
|
$rootScope.fixFooter = !!current.$$route.fixFooter;
|
2014-12-22 20:13:23 +00:00
|
|
|
|
2014-05-21 19:28:38 +00:00
|
|
|
$anchorScroll();
|
2013-12-10 04:33:28 +00:00
|
|
|
});
|
|
|
|
|
2013-11-18 22:11:06 +00:00
|
|
|
var initallyChecked = false;
|
|
|
|
window.__isLoading = function() {
|
|
|
|
if (!initallyChecked) {
|
|
|
|
initallyChecked = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return $http.pendingRequests.length > 0;
|
|
|
|
};
|
2013-09-27 20:12:51 +00:00
|
|
|
}]);
|