2013-10-01 20:42:20 +00:00
|
|
|
// Start the application code itself.
|
2013-10-26 20:03:11 +00:00
|
|
|
quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics', 'angulartics.mixpanel', '$strap.directives'], function($provide) {
|
2013-09-26 23:59:58 +00:00
|
|
|
$provide.factory('UserService', ['Restangular', function(Restangular) {
|
|
|
|
var userResponse = {
|
|
|
|
verified: false,
|
|
|
|
anonymous: true,
|
|
|
|
username: null,
|
2013-10-10 17:44:34 +00:00
|
|
|
email: null,
|
|
|
|
askForPassword: false,
|
2013-09-26 23:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var userService = {}
|
|
|
|
|
|
|
|
userService.load = function() {
|
|
|
|
var userFetch = Restangular.one('user/');
|
|
|
|
userFetch.get().then(function(loadedUser) {
|
|
|
|
userResponse = loadedUser;
|
2013-10-03 19:46:22 +00:00
|
|
|
|
2013-10-03 20:16:10 +00:00
|
|
|
if (!userResponse.anonymous) {
|
|
|
|
mixpanel.identify(userResponse.username);
|
|
|
|
mixpanel.people.set({
|
|
|
|
'$email': userResponse.email,
|
|
|
|
'$username': userResponse.username,
|
|
|
|
'verified': userResponse.verified
|
|
|
|
});
|
2013-10-10 20:34:59 +00:00
|
|
|
mixpanel.people.set_once({
|
|
|
|
'$created': new Date()
|
|
|
|
})
|
2013-10-03 20:16:10 +00:00
|
|
|
}
|
2013-09-26 23:59:58 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
userService.currentUser = function() {
|
|
|
|
return userResponse;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the user the first time.
|
|
|
|
userService.load();
|
|
|
|
|
|
|
|
return userService;
|
2013-10-04 18:35:51 +00:00
|
|
|
}]);
|
|
|
|
|
2013-10-08 17:57:48 +00:00
|
|
|
$provide.factory('KeyService', ['$location', function($location) {
|
|
|
|
var keyService = {}
|
|
|
|
|
|
|
|
if ($location.host() === 'quay.io') {
|
|
|
|
keyService['stripePublishableKey'] = 'pk_live_P5wLU0vGdHnZGyKnXlFG4oiu';
|
2013-10-10 18:42:14 +00:00
|
|
|
keyService['githubClientId'] = '5a8c08b06c48d89d4d1e';
|
2013-10-08 17:57:48 +00:00
|
|
|
} else {
|
|
|
|
keyService['stripePublishableKey'] = 'pk_test_uEDHANKm9CHCvVa2DLcipGRh';
|
2013-10-10 18:42:14 +00:00
|
|
|
keyService['githubClientId'] = 'cfbc4aca88e5c1b40679';
|
2013-10-08 17:57:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return keyService;
|
|
|
|
}]);
|
|
|
|
|
2013-10-28 21:08:26 +00:00
|
|
|
$provide.factory('PlanService', ['Restangular', 'KeyService', function(Restangular, KeyService) {
|
2013-10-04 18:35:51 +00:00
|
|
|
var plans = [
|
|
|
|
{
|
|
|
|
title: 'Open Source',
|
|
|
|
price: 0,
|
|
|
|
privateRepos: 0,
|
|
|
|
stripeId: 'free',
|
|
|
|
audience: 'Share with the world',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Micro',
|
|
|
|
price: 700,
|
|
|
|
privateRepos: 5,
|
|
|
|
stripeId: 'micro',
|
|
|
|
audience: 'For smaller teams',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Basic',
|
|
|
|
price: 1200,
|
|
|
|
privateRepos: 10,
|
|
|
|
stripeId: 'small',
|
|
|
|
audience: 'For your basic team',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Medium',
|
|
|
|
price: 2200,
|
|
|
|
privateRepos: 20,
|
|
|
|
stripeId: 'medium',
|
|
|
|
audience: 'For medium-sized teams',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
var planDict = {};
|
|
|
|
var i;
|
|
|
|
for(i = 0; i < plans.length; i++) {
|
|
|
|
planDict[plans[i].stripeId] = plans[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
var planService = {}
|
|
|
|
|
|
|
|
planService.planList = function() {
|
|
|
|
return plans;
|
2013-10-28 21:08:26 +00:00
|
|
|
};
|
2013-10-04 18:35:51 +00:00
|
|
|
|
|
|
|
planService.getPlan = function(planId) {
|
|
|
|
return planDict[planId];
|
2013-10-28 21:08:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
planService.getMinimumPlan = function(privateCount) {
|
|
|
|
for (var i = 0; i < plans.length; i++) {
|
|
|
|
var plan = plans[i];
|
|
|
|
if (plan.privateRepos >= privateCount) {
|
|
|
|
return plan;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
planService.showSubscribeDialog = function($scope, planId, started, success, failed) {
|
|
|
|
var submitToken = function(token) {
|
|
|
|
$scope.$apply(function() {
|
|
|
|
started();
|
|
|
|
});
|
|
|
|
|
|
|
|
mixpanel.track('plan_subscribe');
|
|
|
|
|
|
|
|
var subscriptionDetails = {
|
|
|
|
token: token.id,
|
|
|
|
plan: planId,
|
|
|
|
};
|
|
|
|
|
|
|
|
var createSubscriptionRequest = Restangular.one('user/plan');
|
|
|
|
$scope.$apply(function() {
|
|
|
|
createSubscriptionRequest.customPUT(subscriptionDetails).then(success, failed);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var planDetails = planService.getPlan(planId)
|
|
|
|
StripeCheckout.open({
|
|
|
|
key: KeyService.stripePublishableKey,
|
|
|
|
address: false, // TODO change to true
|
|
|
|
amount: planDetails.price,
|
|
|
|
currency: 'usd',
|
|
|
|
name: 'Quay ' + planDetails.title + ' Subscription',
|
|
|
|
description: 'Up to ' + planDetails.privateRepos + ' private repositories',
|
|
|
|
panelLabel: 'Subscribe',
|
|
|
|
token: submitToken
|
|
|
|
});
|
|
|
|
};
|
2013-10-04 18:35:51 +00:00
|
|
|
|
|
|
|
return planService;
|
|
|
|
}]);
|
2013-09-26 23:59:58 +00:00
|
|
|
}).
|
2013-10-01 23:37:33 +00:00
|
|
|
directive('match', function($parse) {
|
|
|
|
return {
|
|
|
|
require: 'ngModel',
|
|
|
|
link: function(scope, elem, attrs, ctrl) {
|
|
|
|
scope.$watch(function() {
|
|
|
|
return $parse(attrs.match)(scope) === ctrl.$modelValue;
|
|
|
|
}, function(currentValue) {
|
|
|
|
ctrl.$setValidity('mismatch', currentValue);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}).
|
2013-10-17 18:29:47 +00:00
|
|
|
directive('onresize', function ($window, $parse) {
|
|
|
|
return function (scope, element, attr) {
|
|
|
|
var fn = $parse(attr.onresize);
|
|
|
|
|
|
|
|
var notifyResized = function() {
|
|
|
|
scope.$apply(function () {
|
|
|
|
fn(scope);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
angular.element($window).on('resize', null, notifyResized);
|
|
|
|
|
|
|
|
scope.$on('$destroy', function() {
|
|
|
|
angular.element($window).off('resize', null, notifyResized);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}).
|
2013-10-03 19:46:22 +00:00
|
|
|
config(['$routeProvider', '$locationProvider', '$analyticsProvider',
|
|
|
|
function($routeProvider, $locationProvider, $analyticsProvider) {
|
|
|
|
|
2013-10-03 20:16:10 +00:00
|
|
|
$analyticsProvider.virtualPageviews(true);
|
|
|
|
|
2013-10-10 23:06:04 +00:00
|
|
|
$locationProvider.html5Mode(true);
|
|
|
|
|
2013-10-14 02:06:31 +00:00
|
|
|
// 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
|
2013-10-03 20:16:10 +00:00
|
|
|
$routeProvider.
|
2013-10-17 03:09:43 +00:00
|
|
|
when('/repository/:namespace/:name', {templateUrl: '/static/partials/view-repo.html', controller: RepoCtrl, reloadOnSearch: false}).
|
2013-10-03 20:16:10 +00:00
|
|
|
when('/repository/:namespace/:name/tag/:tag', {templateUrl: '/static/partials/view-repo.html', controller: RepoCtrl}).
|
2013-10-19 02:28:46 +00:00
|
|
|
when('/repository/:namespace/:name/image/:image', {templateUrl: '/static/partials/image-view.html', controller: ImageViewCtrl}).
|
2013-10-03 20:16:10 +00:00
|
|
|
when('/repository/:namespace/:name/admin', {templateUrl: '/static/partials/repo-admin.html', controller:RepoAdminCtrl}).
|
|
|
|
when('/repository/', {title: 'Repositories', templateUrl: '/static/partials/repo-list.html', controller: RepoListCtrl}).
|
2013-10-14 02:06:31 +00:00
|
|
|
when('/user/', {title: 'User Admin', templateUrl: '/static/partials/user-admin.html', controller: UserAdminCtrl}).
|
2013-10-17 21:45:08 +00:00
|
|
|
when('/guide/', {title: 'User Guide', templateUrl: '/static/partials/guide.html', controller: GuideCtrl}).
|
2013-10-09 22:33:25 +00:00
|
|
|
when('/plans/', {title: 'Plans and Pricing', templateUrl: '/static/partials/plans.html', controller: PlansCtrl}).
|
2013-10-14 21:50:07 +00:00
|
|
|
when('/signin/', {title: 'Signin', templateUrl: '/static/partials/signin.html', controller: SigninCtrl}).
|
2013-10-24 21:41:55 +00:00
|
|
|
when('/new/', {title: 'Create new repository', templateUrl: '/static/partials/new-repo.html', controller: NewRepoCtrl}).
|
2013-10-17 21:45:08 +00:00
|
|
|
|
|
|
|
when('/v1/', {title: 'Activation information', templateUrl: '/static/partials/v1-page.html', controller: V1Ctrl}).
|
|
|
|
|
2013-10-09 22:33:25 +00:00
|
|
|
when('/', {title: 'Hosted Private Docker Registry', templateUrl: '/static/partials/landing.html', controller: LandingCtrl}).
|
2013-10-03 20:16:10 +00:00
|
|
|
otherwise({redirectTo: '/'});
|
|
|
|
}]).
|
2013-09-24 22:21:14 +00:00
|
|
|
config(function(RestangularProvider) {
|
|
|
|
RestangularProvider.setBaseUrl('/api/');
|
2013-09-26 21:59:20 +00:00
|
|
|
});
|
|
|
|
|
2013-10-22 05:26:14 +00:00
|
|
|
quayApp.directive('repoCircle', function () {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
|
|
|
templateUrl: '/static/directives/repo-circle.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: false,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
'repo': '=repo'
|
|
|
|
},
|
|
|
|
controller: function($scope, $element) {
|
2013-10-26 20:03:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
quayApp.directive('buildStatus', function () {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
|
|
|
templateUrl: '/static/directives/build-status.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: false,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
'build': '=build'
|
|
|
|
},
|
|
|
|
controller: function($scope, $element) {
|
|
|
|
$scope.getBuildProgress = function(buildInfo) {
|
|
|
|
switch (buildInfo.status) {
|
|
|
|
case 'building':
|
|
|
|
return (buildInfo.current_command / buildInfo.total_commands) * 100;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'pushing':
|
2013-10-28 17:31:43 +00:00
|
|
|
var imagePercentDecimal = (buildInfo.image_completion_percent / 100);
|
2013-10-28 17:33:19 +00:00
|
|
|
return ((buildInfo.current_image + imagePercentDecimal) / buildInfo.total_images) * 100;
|
2013-10-26 20:03:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'complete':
|
|
|
|
return 100;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'initializing':
|
|
|
|
case 'starting':
|
|
|
|
case 'waiting':
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getBuildMessage = function(buildInfo) {
|
|
|
|
switch (buildInfo.status) {
|
|
|
|
case 'initializing':
|
|
|
|
return 'Starting Dockerfile build';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'starting':
|
|
|
|
case 'waiting':
|
|
|
|
case 'building':
|
|
|
|
return 'Building image from Dockerfile';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'pushing':
|
|
|
|
return 'Pushing image built from Dockerfile';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'complete':
|
|
|
|
return 'Dockerfile build completed and pushed';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'error':
|
|
|
|
return 'Dockerfile build failed: ' + buildInfo.message;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
2013-10-22 05:26:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|
|
|
|
|
2013-09-26 21:59:20 +00:00
|
|
|
quayApp.run(['$location', '$rootScope', function($location, $rootScope) {
|
2013-09-26 23:07:25 +00:00
|
|
|
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
|
|
|
|
if (current.$$route.title) {
|
|
|
|
$rootScope.title = current.$$route.title;
|
|
|
|
}
|
|
|
|
});
|
2013-09-27 20:12:51 +00:00
|
|
|
}]);
|