2013-12-10 06:38:05 +00:00
var TEAM _PATTERN = '^[a-zA-Z][a-zA-Z0-9]+$' ;
2014-05-20 21:58:39 +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
2014-11-24 21:07:38 +00:00
$ . fn . clipboardCopy = function ( ) {
2014-08-22 19:24:56 +00:00
if ( zeroClipboardSupported ) {
2014-08-25 19:59:50 +00:00
( new ZeroClipboard ( $ ( this ) ) ) ;
2014-08-22 19:24:56 +00:00
return true ;
}
this . hide ( ) ;
return false ;
} ;
var zeroClipboardSupported = true ;
2014-08-25 19:59:50 +00:00
ZeroClipboard . config ( {
'swfPath' : 'static/lib/ZeroClipboard.swf'
} ) ;
2014-08-22 19:24:56 +00:00
ZeroClipboard . on ( "error" , function ( e ) {
2014-11-24 21:07:38 +00:00
zeroClipboardSupported = false ;
2014-08-22 19:24:56 +00:00
} ) ;
ZeroClipboard . on ( 'aftercopy' , function ( e ) {
var container = e . target . parentNode . parentNode . parentNode ;
var message = $ ( container ) . find ( '.clipboard-copied-message' ) [ 0 ] ;
// Resets the animation.
var elem = message ;
elem . style . display = 'none' ;
elem . classList . remove ( 'animated' ) ;
// Show the notification.
setTimeout ( function ( ) {
elem . style . display = 'inline-block' ;
elem . classList . add ( 'animated' ) ;
} , 10 ) ;
// Reset the notification.
setTimeout ( function ( ) {
elem . style . display = 'none' ;
} , 5000 ) ;
} ) ;
2013-12-26 22:45:16 +00:00
function getRestUrl ( args ) {
var url = '' ;
for ( var i = 0 ; i < arguments . length ; ++ i ) {
if ( i > 0 ) {
url += '/' ;
}
url += encodeURI ( arguments [ i ] )
}
return url ;
}
2014-01-10 01:17:28 +00:00
function clickElement ( el ) {
// From: http://stackoverflow.com/questions/16802795/click-not-working-in-mocha-phantomjs-on-certain-elements
var ev = document . createEvent ( "MouseEvent" ) ;
ev . initMouseEvent (
"click" ,
true /* bubble */ , true /* cancelable */ ,
window , null ,
0 , 0 , 0 , 0 , /* coordinates */
false , false , false , false , /* modifier keys */
0 /*left*/ , null ) ;
el . dispatchEvent ( ev ) ;
}
2013-12-26 22:45:16 +00:00
2013-11-05 00:36:56 +00:00
function getFirstTextLine ( commentString ) {
if ( ! commentString ) { return '' ; }
2014-11-24 21:07:38 +00:00
2013-11-05 00:36:56 +00:00
var lines = commentString . split ( '\n' ) ;
var MARKDOWN _CHARS = {
'#' : true ,
'-' : true ,
'>' : true ,
'`' : true
} ;
for ( var i = 0 ; i < lines . length ; ++ i ) {
// Skip code lines.
if ( lines [ i ] . indexOf ( ' ' ) == 0 ) {
continue ;
}
// Skip empty lines.
if ( $ . trim ( lines [ i ] ) . length == 0 ) {
continue ;
}
// Skip control lines.
if ( MARKDOWN _CHARS [ $ . trim ( lines [ i ] ) [ 0 ] ] ) {
continue ;
}
return getMarkedDown ( lines [ i ] ) ;
}
return '' ;
}
2013-12-26 22:45:16 +00:00
function createRobotAccount ( ApiService , is _org , orgname , name , callback ) {
2014-08-18 22:21:53 +00:00
ApiService . createRobot ( is _org ? orgname : null , null , { 'robot_shortname' : name } )
. then ( callback , ApiService . errorDisplay ( 'Cannot create robot account' ) ) ;
2013-12-10 06:38:05 +00:00
}
2013-12-26 22:45:16 +00:00
function createOrganizationTeam ( ApiService , orgname , teamname , callback ) {
2013-12-10 06:38:05 +00:00
var data = {
'name' : teamname ,
'role' : 'member'
} ;
2013-12-26 22:45:16 +00:00
var params = {
'orgname' : orgname ,
'teamname' : teamname
} ;
2014-11-24 21:07:38 +00:00
2014-08-18 22:21:53 +00:00
ApiService . updateOrganizationTeam ( data , params )
. then ( callback , ApiService . errorDisplay ( 'Cannot create team' ) ) ;
2013-12-10 06:38:05 +00:00
}
2013-11-05 00:36:56 +00:00
function getMarkedDown ( string ) {
return Markdown . getSanitizingConverter ( ) . makeHtml ( string || '' ) ;
}
2014-04-09 01:10:33 +00:00
quayDependencies = [ 'ngRoute' , 'chieffancypants.loadingBar' , 'angular-tour' , 'restangular' , 'angularMoment' ,
'mgcrea.ngStrap' , 'ngCookies' , 'ngSanitize' , 'angular-md5' , 'pasvaz.bindonce' , 'ansiToHtml' ,
'ngAnimate' ] ;
if ( window . _ _config && window . _ _config . MIXPANEL _KEY ) {
quayDependencies . push ( 'angulartics' ) ;
quayDependencies . push ( 'angulartics.mixpanel' ) ;
}
quayApp = angular . module ( 'quay' , quayDependencies , function ( $provide , cfpLoadingBarProvider ) {
2013-12-17 18:19:59 +00:00
cfpLoadingBarProvider . includeSpinner = false ;
2013-12-26 22:45:16 +00:00
2014-03-18 19:08:46 +00:00
/ * *
* Specialized wrapper around array which provides a toggle ( ) method for viewing the contents of the
* array in a manner that is asynchronously filled in over a short time period . This prevents long
* pauses in the UI for ngRepeat ' s when the array is significant in size .
* /
$provide . factory ( 'AngularViewArray' , [ '$interval' , function ( $interval ) {
2014-08-12 21:09:51 +00:00
var ADDTIONAL _COUNT = 20 ;
2014-03-18 19:08:46 +00:00
function _ViewArray ( ) {
this . isVisible = false ;
this . visibleEntries = null ;
this . hasEntries = false ;
this . entries = [ ] ;
this . timerRef _ = null ;
this . currentIndex _ = 0 ;
}
2014-08-19 00:34:39 +00:00
_ViewArray . prototype . length = function ( ) {
return this . entries . length ;
} ;
_ViewArray . prototype . get = function ( index ) {
return this . entries [ index ] ;
} ;
2014-03-18 19:08:46 +00:00
_ViewArray . prototype . push = function ( elem ) {
this . entries . push ( elem ) ;
this . hasEntries = true ;
if ( this . isVisible ) {
this . setVisible ( true ) ;
}
} ;
_ViewArray . prototype . toggle = function ( ) {
this . setVisible ( ! this . isVisible ) ;
} ;
_ViewArray . prototype . setVisible = function ( newState ) {
this . isVisible = newState ;
this . visibleEntries = [ ] ;
this . currentIndex _ = 0 ;
if ( newState ) {
this . showAdditionalEntries _ ( ) ;
this . startTimer _ ( ) ;
} else {
this . stopTimer _ ( ) ;
}
} ;
_ViewArray . prototype . showAdditionalEntries _ = function ( ) {
var i = 0 ;
for ( i = this . currentIndex _ ; i < ( this . currentIndex _ + ADDTIONAL _COUNT ) && i < this . entries . length ; ++ i ) {
this . visibleEntries . push ( this . entries [ i ] ) ;
}
this . currentIndex _ = i ;
if ( this . currentIndex _ >= this . entries . length ) {
this . stopTimer _ ( ) ;
}
} ;
_ViewArray . prototype . startTimer _ = function ( ) {
var that = this ;
this . timerRef _ = $interval ( function ( ) {
that . showAdditionalEntries _ ( ) ;
} , 10 ) ;
} ;
2014-11-24 21:07:38 +00:00
2014-03-18 19:08:46 +00:00
_ViewArray . prototype . stopTimer _ = function ( ) {
if ( this . timerRef _ ) {
$interval . cancel ( this . timerRef _ ) ;
this . timerRef _ = null ;
}
} ;
var service = {
'create' : function ( ) {
return new _ViewArray ( ) ;
}
} ;
return service ;
} ] ) ;
2014-02-25 23:22:55 +00:00
2014-09-11 23:59:44 +00:00
/ * *
* Specialized class for conducting an HTTP poll , while properly preventing multiple calls .
* /
$provide . factory ( 'AngularPollChannel' , [ 'ApiService' , '$timeout' , function ( ApiService , $timeout ) {
var _PollChannel = function ( scope , requester , opt _sleeptime ) {
this . scope _ = scope ;
this . requester _ = requester ;
this . sleeptime _ = opt _sleeptime || ( 60 * 1000 /* 60s */ ) ;
this . timer _ = null ;
this . working = false ;
this . polling = false ;
var that = this ;
scope . $on ( '$destroy' , function ( ) {
that . stop ( ) ;
} ) ;
} ;
_PollChannel . prototype . stop = function ( ) {
if ( this . timer _ ) {
$timeout . cancel ( this . timer _ ) ;
this . timer _ = null ;
this . polling _ = false ;
}
this . working = false ;
} ;
_PollChannel . prototype . start = function ( ) {
// Make sure we invoke call outside the normal digest cycle, since
// we'll call $scope.$apply ourselves.
var that = this ;
setTimeout ( function ( ) { that . call _ ( ) ; } , 0 ) ;
} ;
_PollChannel . prototype . call _ = function ( ) {
if ( this . working ) { return ; }
var that = this ;
this . working = true ;
this . scope _ . $apply ( function ( ) {
that . requester _ ( function ( status ) {
if ( status ) {
that . working = false ;
that . setupTimer _ ( ) ;
} else {
that . stop ( ) ;
}
} ) ;
} ) ;
} ;
_PollChannel . prototype . setupTimer _ = function ( ) {
if ( this . timer _ ) { return ; }
var that = this ;
this . polling = true ;
this . timer _ = $timeout ( function ( ) {
that . timer _ = null ;
that . call _ ( ) ;
} , this . sleeptime _ )
} ;
2014-11-24 21:07:38 +00:00
2014-09-11 23:59:44 +00:00
var service = {
'create' : function ( scope , requester , opt _sleeptime ) {
return new _PollChannel ( scope , requester , opt _sleeptime ) ;
}
} ;
return service ;
} ] ) ;
2014-04-01 04:23:53 +00:00
$provide . factory ( 'DataFileService' , [ function ( ) {
var dataFileService = { } ;
dataFileService . getName _ = function ( filePath ) {
var parts = filePath . split ( '/' ) ;
return parts [ parts . length - 1 ] ;
} ;
dataFileService . tryAsZip _ = function ( buf , success , failure ) {
var zip = null ;
var zipFiles = null ;
2014-11-24 21:07:38 +00:00
try {
2014-04-01 04:23:53 +00:00
var zip = new JSZip ( buf ) ;
zipFiles = zip . files ;
} catch ( e ) {
failure ( ) ;
return ;
}
var files = [ ] ;
for ( var filePath in zipFiles ) {
if ( zipFiles . hasOwnProperty ( filePath ) ) {
files . push ( {
'name' : dataFileService . getName _ ( filePath ) ,
'path' : filePath ,
'canRead' : true ,
'toBlob' : ( function ( fp ) {
return function ( ) {
return new Blob ( [ zip . file ( fp ) . asArrayBuffer ( ) ] ) ;
} ;
} ( filePath ) )
} ) ;
}
}
success ( files ) ;
} ;
dataFileService . tryAsTarGz _ = function ( buf , success , failure ) {
2014-05-01 05:48:39 +00:00
var gunzip = new Zlib . Gunzip ( buf ) ;
var plain = null ;
try {
plain = gunzip . decompress ( ) ;
} catch ( e ) {
failure ( ) ;
return ;
}
2014-07-14 20:26:20 +00:00
dataFileService . tryAsTar _ ( plain , success , failure ) ;
2014-05-01 05:48:39 +00:00
} ;
2014-07-14 20:26:20 +00:00
dataFileService . tryAsTar _ = function ( buf , success , failure ) {
2014-04-01 17:00:26 +00:00
var collapsePath = function ( originalPath ) {
// Tar files can contain entries of the form './', so we need to collapse
// those paths down.
var parts = originalPath . split ( '/' ) ;
for ( var i = parts . length - 1 ; i >= 0 ; i -- ) {
var part = parts [ i ] ;
if ( part == '.' ) {
parts . splice ( i , 1 ) ;
}
}
return parts . join ( '/' ) ;
} ;
2014-07-14 20:26:20 +00:00
var handler = new Untar ( buf ) ;
handler . process ( function ( status , read , files , err ) {
switch ( status ) {
case 'error' :
failure ( err ) ;
break ;
case 'done' :
var processed = [ ] ;
for ( var i = 0 ; i < files . length ; ++ i ) {
var currentFile = files [ i ] ;
var path = collapsePath ( currentFile . meta . filename ) ;
if ( path == '' || path == 'pax_global_header' ) { continue ; }
processed . push ( {
'name' : dataFileService . getName _ ( path ) ,
'path' : path ,
'canRead' : true ,
'toBlob' : ( function ( currentFile ) {
return function ( ) {
return new Blob ( [ currentFile . buffer ] , { type : 'application/octet-binary' } ) ;
} ;
} ( currentFile ) )
} ) ;
}
success ( processed ) ;
break ;
}
2014-11-24 21:07:38 +00:00
} ) ;
2014-04-01 04:23:53 +00:00
} ;
dataFileService . blobToString = function ( blob , callback ) {
var reader = new FileReader ( ) ;
reader . onload = function ( event ) {
callback ( reader . result ) ;
} ;
reader . readAsText ( blob ) ;
} ;
2014-05-01 05:48:39 +00:00
dataFileService . arrayToString = function ( buf , callback ) {
var bb = new Blob ( [ buf ] , { type : 'application/octet-binary' } ) ;
var f = new FileReader ( ) ;
f . onload = function ( e ) {
callback ( e . target . result ) ;
} ;
f . onerror = function ( e ) {
callback ( null ) ;
} ;
f . onabort = function ( e ) {
callback ( null ) ;
} ;
f . readAsText ( bb ) ;
2014-04-01 04:23:53 +00:00
} ;
dataFileService . readDataArrayAsPossibleArchive = function ( buf , success , failure ) {
dataFileService . tryAsZip _ ( buf , success , function ( ) {
dataFileService . tryAsTarGz _ ( buf , success , failure ) ;
} ) ;
} ;
dataFileService . downloadDataFileAsArrayBuffer = function ( $scope , url , progress , error , loaded ) {
var request = new XMLHttpRequest ( ) ;
request . open ( 'GET' , url , true ) ;
request . responseType = 'arraybuffer' ;
request . onprogress = function ( e ) {
$scope . $apply ( function ( ) {
var percentLoaded ;
if ( e . lengthComputable ) {
progress ( e . loaded / e . total ) ;
}
} ) ;
} ;
request . onerror = function ( ) {
$scope . $apply ( function ( ) {
error ( ) ;
} ) ;
} ;
request . onload = function ( ) {
if ( this . status == 200 ) {
$scope . $apply ( function ( ) {
var uint8array = new Uint8Array ( request . response ) ;
loaded ( uint8array ) ;
} ) ;
return ;
}
} ;
request . send ( ) ;
} ;
return dataFileService ;
} ] ) ;
2014-04-07 22:55:39 +00:00
$provide . factory ( 'UIService' , [ function ( ) {
var uiService = { } ;
2014-11-24 21:07:38 +00:00
2014-04-07 22:55:39 +00:00
uiService . hidePopover = function ( elem ) {
2014-09-03 19:41:25 +00:00
var popover = $ ( elem ) . data ( 'bs.popover' ) ;
2014-04-07 22:55:39 +00:00
if ( popover ) {
popover . hide ( ) ;
}
} ;
uiService . showPopover = function ( elem , content ) {
var popover = $ ( elem ) . data ( 'bs.popover' ) ;
if ( ! popover ) {
$ ( elem ) . popover ( { 'content' : '-' , 'placement' : 'left' } ) ;
}
setTimeout ( function ( ) {
var popover = $ ( elem ) . data ( 'bs.popover' ) ;
popover . options . content = content ;
popover . show ( ) ;
} , 500 ) ;
} ;
2014-11-24 21:07:38 +00:00
2014-04-07 22:55:39 +00:00
uiService . showFormError = function ( elem , result ) {
var message = result . data [ 'message' ] || result . data [ 'error_description' ] || '' ;
if ( message ) {
uiService . showPopover ( elem , message ) ;
} else {
uiService . hidePopover ( elem ) ;
}
} ;
2014-11-24 21:07:38 +00:00
2014-04-07 22:55:39 +00:00
return uiService ;
} ] ) ;
2014-01-14 21:01:37 +00:00
$provide . factory ( 'UtilService' , [ '$sanitize' , function ( $sanitize ) {
var utilService = { } ;
2014-08-12 18:30:59 +00:00
2014-08-29 00:49:11 +00:00
utilService . isEmailAddress = function ( val ) {
var emailRegex = /^[a-zA-Z0-9.!#$%&’ *+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/ ;
return emailRegex . test ( val ) ;
} ;
2014-08-12 18:30:59 +00:00
utilService . escapeHtmlString = function ( text ) {
2014-01-14 21:01:37 +00:00
var adjusted = text . replace ( /&/g , "&" )
2014-04-01 04:23:53 +00:00
. replace ( /</g , "<" )
. replace ( />/g , ">" )
. replace ( /"/g , """ )
. replace ( /'/g , "'" ) ;
2014-11-24 21:07:38 +00:00
2014-08-12 18:30:59 +00:00
return adjusted ;
} ;
2014-11-24 21:07:38 +00:00
2014-08-12 18:30:59 +00:00
utilService . textToSafeHtml = function ( text ) {
return $sanitize ( utilService . escapeHtmlString ( text ) ) ;
2014-01-14 21:01:37 +00:00
} ;
2014-11-24 21:07:38 +00:00
2014-01-14 21:01:37 +00:00
return utilService ;
} ] ) ;
2014-02-25 23:22:55 +00:00
2014-07-03 21:55:53 +00:00
$provide . factory ( 'PingService' , [ function ( ) {
var pingService = { } ;
var pingCache = { } ;
2014-08-29 20:25:11 +00:00
var invokeCallback = function ( $scope , pings , callback ) {
if ( pings [ 0 ] == - 1 ) {
setTimeout ( function ( ) {
$scope . $apply ( function ( ) {
callback ( - 1 , false , - 1 ) ;
} ) ;
} , 0 ) ;
return ;
}
var sum = 0 ;
for ( var i = 0 ; i < pings . length ; ++ i ) {
sum += pings [ i ] ;
}
// Report the average ping.
setTimeout ( function ( ) {
$scope . $apply ( function ( ) {
callback ( Math . floor ( sum / pings . length ) , true , pings . length ) ;
} ) ;
} , 0 ) ;
} ;
2014-07-03 21:55:53 +00:00
var reportPingResult = function ( $scope , url , ping , callback ) {
// Lookup the cached ping data, if any.
var cached = pingCache [ url ] ;
if ( ! cached ) {
cached = pingCache [ url ] = {
'pings' : [ ]
} ;
}
// If an error occurred, report it and done.
if ( ping < 0 ) {
cached [ 'pings' ] = [ - 1 ] ;
2014-09-15 15:27:33 +00:00
invokeCallback ( $scope , [ - 1 ] , callback ) ;
2014-07-03 21:55:53 +00:00
return ;
}
// Otherwise, add the current ping and determine the average.
cached [ 'pings' ] . push ( ping ) ;
2014-08-29 20:25:11 +00:00
// Invoke the callback.
invokeCallback ( $scope , cached [ 'pings' ] , callback ) ;
2014-07-03 21:55:53 +00:00
// Schedule another check if we've done less than three.
if ( cached [ 'pings' ] . length < 3 ) {
setTimeout ( function ( ) {
pingUrlInternal ( $scope , url , callback ) ;
} , 1000 ) ;
}
} ;
2014-11-24 21:07:38 +00:00
2014-07-03 21:55:53 +00:00
var pingUrlInternal = function ( $scope , url , callback ) {
var path = url + '?cb=' + ( Math . random ( ) * 100 ) ;
var start = new Date ( ) ;
var xhr = new XMLHttpRequest ( ) ;
xhr . onerror = function ( ) {
2014-07-14 21:24:25 +00:00
reportPingResult ( $scope , url , - 1 , callback ) ;
2014-07-03 21:55:53 +00:00
} ;
xhr . onreadystatechange = function ( ) {
if ( xhr . readyState === xhr . HEADERS _RECEIVED ) {
if ( xhr . status != 200 ) {
reportPingResult ( $scope , url , - 1 , callback ) ;
return ;
}
var ping = ( new Date ( ) - start ) ;
reportPingResult ( $scope , url , ping , callback ) ;
}
} ;
xhr . open ( "GET" , path ) ;
xhr . send ( null ) ;
} ;
pingService . pingUrl = function ( $scope , url , callback ) {
if ( pingCache [ url ] ) {
2014-11-24 21:07:38 +00:00
invokeCallback ( $scope , pingCache [ url ] [ 'pings' ] , callback ) ;
2014-07-03 21:55:53 +00:00
return ;
}
// Note: We do each in a callback after 1s to prevent it running when other code
// runs (which can skew the results).
setTimeout ( function ( ) {
pingUrlInternal ( $scope , url , callback ) ;
} , 1000 ) ;
} ;
2014-11-24 21:07:38 +00:00
2014-07-03 21:55:53 +00:00
return pingService ;
} ] ) ;
2014-11-25 00:25:13 +00:00
$provide . factory ( 'AvatarService' , [ 'Config' , '$sanitize' , 'md5' ,
function ( Config , $sanitize , md5 ) {
var avatarService = { } ;
var cache = { } ;
avatarService . getAvatar = function ( hash , opt _size ) {
var size = opt _size || 16 ;
switch ( Config [ 'AVATAR_KIND' ] ) {
case 'local' :
return '/avatar/' + hash + '?size=' + size ;
break ;
case 'gravatar' :
return '//www.gravatar.com/avatar/' + hash + '?d=identicon&size=' + size ;
break ;
}
} ;
avatarService . computeHash = function ( opt _email , opt _name ) {
var email = opt _email || '' ;
var name = opt _name || '' ;
var cacheKey = email + ':' + name ;
if ( ! cacheKey ) { return '-' ; }
if ( cache [ cacheKey ] ) {
return cache [ cacheKey ] ;
}
var hash = md5 . createHash ( email . toString ( ) . toLowerCase ( ) ) ;
switch ( Config [ 'AVATAR_KIND' ] ) {
case 'local' :
if ( name ) {
hash = name [ 0 ] + hash ;
} else if ( email ) {
hash = email [ 0 ] + hash ;
}
break ;
}
return cache [ cacheKey ] = hash ;
} ;
return avatarService ;
} ] ) ;
2014-07-03 21:55:53 +00:00
2014-11-24 21:07:38 +00:00
$provide . factory ( 'TriggerService' , [ 'UtilService' , '$sanitize' , 'KeyService' ,
2014-11-05 21:43:37 +00:00
function ( UtilService , $sanitize , KeyService ) {
2014-09-30 20:29:32 +00:00
var triggerService = { } ;
2014-02-25 23:22:55 +00:00
2014-09-30 20:29:32 +00:00
var triggerTypes = {
'github' : {
'description' : function ( config ) {
2014-05-01 17:59:25 +00:00
var source = UtilService . textToSafeHtml ( config [ 'build_source' ] ) ;
2014-02-25 23:22:55 +00:00
var desc = '<i class="fa fa-github fa-lg" style="margin-left: 2px; margin-right: 2px"></i> Push to Github Repository ' ;
desc += '<a href="https://github.com/' + source + '" target="_blank">' + source + '</a>' ;
2014-02-26 00:53:41 +00:00
desc += '<br>Dockerfile folder: //' + UtilService . textToSafeHtml ( config [ 'subdir' ] ) ;
2014-02-25 23:22:55 +00:00
return desc ;
2014-09-30 20:29:32 +00:00
} ,
'run_parameters' : [
{
'title' : 'Branch' ,
'type' : 'option' ,
'name' : 'branch_name'
}
2014-11-05 21:43:37 +00:00
] ,
'get_redirect_url' : function ( namespace , repository ) {
2014-11-24 21:07:38 +00:00
var redirect _uri = KeyService [ 'githubRedirectUri' ] + '/trigger/' +
2014-11-05 21:43:37 +00:00
namespace + '/' + repository ;
var authorize _url = KeyService [ 'githubTriggerAuthorizeUrl' ] ;
var client _id = KeyService [ 'githubTriggerClientId' ] ;
2014-11-24 21:07:38 +00:00
return authorize _url + 'client_id=' + client _id +
2014-11-05 21:43:37 +00:00
'&scope=repo,user:email&redirect_uri=' + redirect _uri ;
}
2014-09-30 20:29:32 +00:00
}
}
2014-02-25 23:22:55 +00:00
2014-11-05 21:43:37 +00:00
triggerService . getRedirectUrl = function ( name , namespace , repository ) {
var type = triggerTypes [ name ] ;
if ( ! type ) {
return '' ;
}
return type [ 'get_redirect_url' ] ( namespace , repository ) ;
} ;
2014-09-30 20:29:32 +00:00
triggerService . getDescription = function ( name , config ) {
var type = triggerTypes [ name ] ;
if ( ! type ) {
return 'Unknown' ;
2014-02-25 23:22:55 +00:00
}
2014-09-30 20:29:32 +00:00
return type [ 'description' ] ( config ) ;
2014-02-25 23:22:55 +00:00
} ;
2014-09-30 20:29:32 +00:00
triggerService . getRunParameters = function ( name , config ) {
var type = triggerTypes [ name ] ;
if ( ! type ) {
return [ ] ;
}
return type [ 'run_parameters' ] ;
}
return triggerService ;
2014-02-25 23:22:55 +00:00
} ] ) ;
2014-08-12 18:30:59 +00:00
$provide . factory ( 'StringBuilderService' , [ '$sce' , 'UtilService' , function ( $sce , UtilService ) {
2014-03-12 04:49:46 +00:00
var stringBuilderService = { } ;
2014-08-19 21:40:36 +00:00
stringBuilderService . buildUrl = function ( value _or _func , metadata ) {
var url = value _or _func ;
if ( typeof url != 'string' ) {
url = url ( metadata ) ;
}
// Find the variables to be replaced.
var varNames = [ ] ;
for ( var i = 0 ; i < url . length ; ++ i ) {
var c = url [ i ] ;
if ( c == '{' ) {
for ( var j = i + 1 ; j < url . length ; ++ j ) {
var d = url [ j ] ;
if ( d == '}' ) {
varNames . push ( url . substring ( i + 1 , j ) ) ;
i = j ;
break ;
}
}
}
}
// Replace all variables found.
for ( var i = 0 ; i < varNames . length ; ++ i ) {
var varName = varNames [ i ] ;
if ( ! metadata [ varName ] ) {
return null ;
}
url = url . replace ( '{' + varName + '}' , metadata [ varName ] ) ;
}
return url ;
} ;
2014-03-12 04:49:46 +00:00
stringBuilderService . buildString = function ( value _or _func , metadata ) {
var fieldIcons = {
2014-08-18 21:24:00 +00:00
'inviter' : 'user' ,
2014-03-12 04:49:46 +00:00
'username' : 'user' ,
2014-09-08 21:20:01 +00:00
'user' : 'user' ,
'email' : 'envelope' ,
2014-03-12 04:49:46 +00:00
'activating_username' : 'user' ,
'delegate_user' : 'user' ,
'delegate_team' : 'group' ,
'team' : 'group' ,
'token' : 'key' ,
'repo' : 'hdd-o' ,
'robot' : 'wrench' ,
'tag' : 'tag' ,
'role' : 'th-large' ,
2014-03-20 19:46:13 +00:00
'original_role' : 'th-large' ,
'application_name' : 'cloud' ,
2014-03-26 23:42:29 +00:00
'image' : 'archive' ,
'original_image' : 'archive' ,
2014-03-20 19:46:13 +00:00
'client_id' : 'chain'
2014-03-12 04:49:46 +00:00
} ;
2014-08-05 21:45:40 +00:00
var filters = {
'obj' : function ( value ) {
if ( ! value ) { return [ ] ; }
return Object . getOwnPropertyNames ( value ) ;
} ,
'updated_tags' : function ( value ) {
if ( ! value ) { return [ ] ; }
return Object . getOwnPropertyNames ( value ) ;
}
} ;
2014-03-12 04:49:46 +00:00
var description = value _or _func ;
if ( typeof description != 'string' ) {
description = description ( metadata ) ;
}
2014-11-24 21:07:38 +00:00
2014-03-12 04:49:46 +00:00
for ( var key in metadata ) {
if ( metadata . hasOwnProperty ( key ) ) {
2014-08-05 21:45:40 +00:00
var value = metadata [ key ] != null ? metadata [ key ] : '(Unknown)' ;
if ( filters [ key ] ) {
value = filters [ key ] ( value ) ;
}
if ( Array . isArray ( value ) ) {
value = value . join ( ', ' ) ;
}
value = value . toString ( ) ;
2014-03-26 23:42:29 +00:00
if ( key . indexOf ( 'image' ) >= 0 ) {
value = value . substr ( 0 , 12 ) ;
}
2014-08-12 18:30:59 +00:00
var safe = UtilService . escapeHtmlString ( value ) ;
2014-03-12 04:49:46 +00:00
var markedDown = getMarkedDown ( value ) ;
markedDown = markedDown . substr ( '<p>' . length , markedDown . length - '<p></p>' . length ) ;
var icon = fieldIcons [ key ] ;
if ( icon ) {
markedDown = '<i class="fa fa-' + icon + '"></i>' + markedDown ;
}
2014-08-12 18:30:59 +00:00
description = description . replace ( '{' + key + '}' , '<code title="' + safe + '">' + markedDown + '</code>' ) ;
2014-03-12 04:49:46 +00:00
}
}
return $sce . trustAsHtml ( description . replace ( '\n' , '<br>' ) ) ;
} ;
return stringBuilderService ;
} ] ) ;
2014-02-25 23:22:55 +00:00
2014-01-14 21:01:37 +00:00
$provide . factory ( 'ImageMetadataService' , [ 'UtilService' , function ( UtilService ) {
var metadataService = { } ;
metadataService . getFormattedCommand = function ( image ) {
if ( ! image || ! image . command || ! image . command . length ) {
return '' ;
}
var getCommandStr = function ( command ) {
// Handle /bin/sh commands specially.
if ( command . length > 2 && command [ 0 ] == '/bin/sh' && command [ 1 ] == '-c' ) {
return command [ 2 ] ;
}
2014-11-24 21:07:38 +00:00
2014-01-14 21:01:37 +00:00
return command . join ( ' ' ) ;
} ;
return getCommandStr ( image . command ) ;
} ;
metadataService . getEscapedFormattedCommand = function ( image ) {
return UtilService . textToSafeHtml ( metadataService . getFormattedCommand ( image ) ) ;
} ;
return metadataService ;
} ] ) ;
2014-04-05 03:26:10 +00:00
$provide . factory ( 'Features' , [ function ( ) {
if ( ! window . _ _features ) {
return { } ;
}
var features = window . _ _features ;
features . getFeature = function ( name , opt _defaultValue ) {
var value = features [ name ] ;
if ( value == null ) {
return opt _defaultValue ;
}
return value ;
} ;
features . hasFeature = function ( name ) {
return ! ! features . getFeature ( name ) ;
} ;
2014-11-24 21:07:38 +00:00
2014-04-05 03:26:10 +00:00
features . matchesFeatures = function ( list ) {
for ( var i = 0 ; i < list . length ; ++ i ) {
var value = features . getFeature ( list [ i ] ) ;
if ( ! value ) {
return false ;
}
}
return true ;
} ;
return features ;
} ] ) ;
2014-04-08 23:14:24 +00:00
$provide . factory ( 'Config' , [ function ( ) {
if ( ! window . _ _config ) {
return { } ;
}
var config = window . _ _config ;
2014-04-09 00:33:20 +00:00
config . getDomain = function ( ) {
2014-04-11 15:17:45 +00:00
return config [ 'SERVER_HOSTNAME' ] ;
2014-04-09 00:33:20 +00:00
} ;
2014-09-18 19:56:59 +00:00
config . getHost = function ( opt _auth ) {
var auth = opt _auth ;
if ( auth ) {
auth = auth + '@' ;
}
return config [ 'PREFERRED_URL_SCHEME' ] + '://' + auth + config [ 'SERVER_HOSTNAME' ] ;
} ;
2014-04-09 00:33:20 +00:00
config . getUrl = function ( opt _path ) {
var path = opt _path || '' ;
2014-04-11 15:17:45 +00:00
return config [ 'PREFERRED_URL_SCHEME' ] + '://' + config [ 'SERVER_HOSTNAME' ] + path ;
2014-04-09 00:33:20 +00:00
} ;
2014-04-08 23:14:24 +00:00
config . getValue = function ( name , opt _defaultValue ) {
var value = config [ name ] ;
if ( value == null ) {
return opt _defaultValue ;
}
return value ;
} ;
return config ;
} ] ) ;
2014-09-04 18:24:20 +00:00
$provide . factory ( 'ApiService' , [ 'Restangular' , '$q' , function ( Restangular , $q ) {
2013-12-26 22:45:16 +00:00
var apiService = { } ;
2014-02-11 03:43:48 +00:00
var getResource = function ( path , opt _background ) {
2013-12-26 22:45:16 +00:00
var resource = { } ;
resource . url = path ;
resource . withOptions = function ( options ) {
this . options = options ;
return this ;
} ;
resource . get = function ( processor , opt _errorHandler ) {
var options = this . options ;
var performer = Restangular . one ( this . url ) ;
var result = {
'loading' : true ,
'value' : null ,
'hasError' : false
} ;
2014-02-11 03:43:48 +00:00
if ( opt _background ) {
performer . withHttpConfig ( {
'ignoreLoadingBar' : true
} ) ;
}
2013-12-26 22:45:16 +00:00
performer . get ( options ) . then ( function ( resp ) {
result . value = processor ( resp ) ;
result . loading = false ;
} , function ( resp ) {
result . hasError = true ;
result . loading = false ;
if ( opt _errorHandler ) {
opt _errorHandler ( resp ) ;
}
} ) ;
return result ;
} ;
return resource ;
} ;
var buildUrl = function ( path , parameters ) {
2014-03-15 03:40:41 +00:00
// We already have /api/v1/ on the URLs, so remove them from the paths.
path = path . substr ( '/api/v1/' . length , path . length ) ;
2013-12-26 22:45:16 +00:00
2014-08-15 21:47:43 +00:00
// Build the path, adjusted with the inline parameters.
var used = { } ;
2013-12-26 22:45:16 +00:00
var url = '' ;
for ( var i = 0 ; i < path . length ; ++ i ) {
var c = path [ i ] ;
2014-03-15 03:40:41 +00:00
if ( c == '{' ) {
var end = path . indexOf ( '}' , i ) ;
2013-12-26 22:45:16 +00:00
var varName = path . substr ( i + 1 , end - i - 1 ) ;
if ( ! parameters [ varName ] ) {
throw new Error ( 'Missing parameter: ' + varName ) ;
}
2014-08-15 21:47:43 +00:00
used [ varName ] = true ;
2014-03-15 03:40:41 +00:00
url += parameters [ varName ] ;
2013-12-26 22:45:16 +00:00
i = end ;
continue ;
}
url += c ;
}
2014-08-15 21:47:43 +00:00
// Append any query parameters.
var isFirst = true ;
for ( var paramName in parameters ) {
if ( ! parameters . hasOwnProperty ( paramName ) ) { continue ; }
if ( used [ paramName ] ) { continue ; }
var value = parameters [ paramName ] ;
if ( value ) {
url += isFirst ? '?' : '&' ;
url += paramName + '=' + encodeURIComponent ( value )
isFirst = false ;
}
}
2013-12-26 22:45:16 +00:00
return url ;
} ;
2014-03-15 03:40:41 +00:00
var getGenericOperationName = function ( userOperationName ) {
return userOperationName . replace ( 'User' , '' ) ;
2013-12-26 22:45:16 +00:00
} ;
2014-03-15 03:40:41 +00:00
var getMatchingUserOperationName = function ( orgOperationName , method , userRelatedResource ) {
if ( userRelatedResource ) {
var operations = userRelatedResource [ 'operations' ] ;
for ( var i = 0 ; i < operations . length ; ++ i ) {
2014-11-24 21:07:38 +00:00
var operation = operations [ i ] ;
2014-03-15 03:40:41 +00:00
if ( operation [ 'method' ] . toLowerCase ( ) == method ) {
return operation [ 'nickname' ] ;
}
}
}
throw new Error ( 'Could not find user operation matching org operation: ' + orgOperationName ) ;
} ;
var buildMethodsForEndpointResource = function ( endpointResource , resourceMap ) {
var name = endpointResource [ 'name' ] ;
var operations = endpointResource [ 'operations' ] ;
for ( var i = 0 ; i < operations . length ; ++ i ) {
2014-11-24 21:07:38 +00:00
var operation = operations [ i ] ;
2014-03-15 03:40:41 +00:00
buildMethodsForOperation ( operation , endpointResource , resourceMap ) ;
}
} ;
2014-09-04 18:24:20 +00:00
var freshLoginFailCheck = function ( opName , opArgs ) {
return function ( resp ) {
var deferred = $q . defer ( ) ;
2014-11-24 21:07:38 +00:00
2014-09-04 18:24:20 +00:00
// If the error is a fresh login required, show the dialog.
if ( resp . status == 401 && resp . data [ 'error_type' ] == 'fresh_login_required' ) {
2014-09-05 00:04:49 +00:00
var verifyNow = function ( ) {
var info = {
'password' : $ ( '#freshPassword' ) . val ( )
} ;
$ ( '#freshPassword' ) . val ( '' ) ;
// Conduct the sign in of the user.
apiService . verifyUser ( info ) . then ( function ( ) {
// On success, retry the operation. if it succeeds, then resolve the
// deferred promise with the result. Otherwise, reject the same.
apiService [ opName ] . apply ( apiService , opArgs ) . then ( function ( resp ) {
deferred . resolve ( resp ) ;
} , function ( resp ) {
deferred . reject ( resp ) ;
} ) ;
} , function ( resp ) {
// Reject with the sign in error.
deferred . reject ( { 'data' : { 'message' : 'Invalid verification credentials' } } ) ;
} ) ;
} ;
2014-11-24 21:07:38 +00:00
2014-09-05 00:04:49 +00:00
var box = bootbox . dialog ( {
2014-09-04 18:24:20 +00:00
"message" : 'It has been more than a few minutes since you last logged in, ' +
2014-11-24 21:07:38 +00:00
'so please verify your password to perform this sensitive operation:' +
2014-09-04 18:24:20 +00:00
'<form style="margin-top: 10px" action="javascript:void(0)">' +
2014-11-24 21:07:38 +00:00
'<input id="freshPassword" class="form-control" type="password" placeholder="Current Password">' +
2014-09-04 18:24:20 +00:00
'</form>' ,
"title" : 'Please Verify' ,
"buttons" : {
"verify" : {
"label" : "Verify" ,
"className" : "btn-success" ,
2014-09-05 00:04:49 +00:00
"callback" : verifyNow
2014-09-04 18:24:20 +00:00
} ,
"close" : {
"label" : "Cancel" ,
"className" : "btn-default" ,
"callback" : function ( ) {
2014-09-05 00:04:49 +00:00
deferred . reject ( { 'data' : { 'message' : 'Verification canceled' } } ) ;
2014-09-04 18:24:20 +00:00
}
}
}
} ) ;
2014-09-05 00:04:49 +00:00
box . bind ( 'shown.bs.modal' , function ( ) {
box . find ( "input" ) . focus ( ) ;
box . find ( "form" ) . submit ( function ( ) {
2014-09-05 00:05:21 +00:00
if ( ! $ ( '#freshPassword' ) . val ( ) ) { return ; }
2014-11-24 21:07:38 +00:00
2014-09-05 00:04:49 +00:00
box . modal ( 'hide' ) ;
verifyNow ( ) ;
} ) ;
} ) ;
2014-09-04 18:24:20 +00:00
// Return a new promise. We'll accept or reject it based on the result
// of the login.
return deferred . promise ;
}
// Otherwise, we just 'raise' the error via the reject method on the promise.
return $q . reject ( resp ) ;
} ;
} ;
2014-03-15 03:40:41 +00:00
var buildMethodsForOperation = function ( operation , resource , resourceMap ) {
var method = operation [ 'method' ] . toLowerCase ( ) ;
var operationName = operation [ 'nickname' ] ;
var path = resource [ 'path' ] ;
// Add the operation itself.
apiService [ operationName ] = function ( opt _options , opt _parameters , opt _background ) {
var one = Restangular . one ( buildUrl ( path , opt _parameters ) ) ;
2014-02-11 03:43:48 +00:00
if ( opt _background ) {
one . withHttpConfig ( {
'ignoreLoadingBar' : true
} ) ;
}
2014-11-24 21:07:38 +00:00
2014-09-04 18:24:20 +00:00
var opObj = one [ 'custom' + method . toUpperCase ( ) ] ( opt _options ) ;
// If the operation requires_fresh_login, then add a specialized error handler that
// will defer the operation's result if sudo is requested.
if ( operation [ 'requires_fresh_login' ] ) {
opObj = opObj . catch ( freshLoginFailCheck ( operationName , arguments ) ) ;
}
return opObj ;
2013-12-26 22:45:16 +00:00
} ;
2014-03-15 03:40:41 +00:00
// If the method for the operation is a GET, add an operationAsResource method.
2013-12-26 22:45:16 +00:00
if ( method == 'get' ) {
2014-03-15 03:40:41 +00:00
apiService [ operationName + 'AsResource' ] = function ( opt _parameters , opt _background ) {
return getResource ( buildUrl ( path , opt _parameters ) , opt _background ) ;
2013-12-26 22:45:16 +00:00
} ;
}
2014-03-15 03:40:41 +00:00
// If the resource has a user-related resource, then make a generic operation for this operation
// that can call both the user and the organization versions of the operation, depending on the
// parameters given.
if ( resource [ 'quayUserRelated' ] ) {
var userOperationName = getMatchingUserOperationName ( operationName , method , resourceMap [ resource [ 'quayUserRelated' ] ] ) ;
var genericOperationName = getGenericOperationName ( userOperationName ) ;
apiService [ genericOperationName ] = function ( orgname , opt _options , opt _parameters , opt _background ) {
2013-12-26 22:45:16 +00:00
if ( orgname ) {
if ( orgname . name ) {
orgname = orgname . name ;
}
2014-02-11 03:43:48 +00:00
var params = jQuery . extend ( { 'orgname' : orgname } , opt _parameters || { } , opt _background ) ;
2014-03-15 03:40:41 +00:00
return apiService [ operationName ] ( opt _options , params ) ;
2013-12-26 22:45:16 +00:00
} else {
2014-03-15 03:40:41 +00:00
return apiService [ userOperationName ] ( opt _options , opt _parameters , opt _background ) ;
2013-12-26 22:45:16 +00:00
}
} ;
}
} ;
if ( ! window . _ _endpoints ) {
return apiService ;
}
2014-03-15 03:40:41 +00:00
var resourceMap = { } ;
// Build the map of resource names to their objects.
for ( var i = 0 ; i < window . _ _endpoints . length ; ++ i ) {
var endpointResource = window . _ _endpoints [ i ] ;
resourceMap [ endpointResource [ 'name' ] ] = endpointResource ;
}
// Construct the methods for each API endpoint.
2013-12-26 22:45:16 +00:00
for ( var i = 0 ; i < window . _ _endpoints . length ; ++ i ) {
2014-03-15 03:40:41 +00:00
var endpointResource = window . _ _endpoints [ i ] ;
buildMethodsForEndpointResource ( endpointResource , resourceMap ) ;
2013-12-26 22:45:16 +00:00
}
2014-08-18 22:21:53 +00:00
apiService . getErrorMessage = function ( resp , defaultMessage ) {
var message = defaultMessage ;
if ( resp [ 'data' ] ) {
message = resp [ 'data' ] [ 'error_message' ] || resp [ 'data' ] [ 'message' ] || resp [ 'data' ] [ 'error_description' ] || message ;
}
return message ;
} ;
apiService . errorDisplay = function ( defaultMessage , opt _handler ) {
return function ( resp ) {
var message = apiService . getErrorMessage ( resp , defaultMessage ) ;
if ( opt _handler ) {
var handlerMessage = opt _handler ( resp ) ;
if ( handlerMessage ) {
message = handlerMessage ;
}
}
bootbox . dialog ( {
"message" : message ,
"title" : defaultMessage ,
"buttons" : {
"close" : {
"label" : "Close" ,
"className" : "btn-primary"
}
}
} ) ;
} ;
} ;
2013-12-26 22:45:16 +00:00
return apiService ;
} ] ) ;
2014-11-24 21:07:38 +00:00
2013-12-17 20:03:34 +00:00
$provide . factory ( 'CookieService' , [ '$cookies' , '$cookieStore' , function ( $cookies , $cookieStore ) {
var cookieService = { } ;
cookieService . putPermanent = function ( name , value ) {
document . cookie = escape ( name ) + "=" + escape ( value ) + "; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/" ;
} ;
cookieService . putSession = function ( name , value ) {
$cookies [ name ] = value ;
} ;
cookieService . clear = function ( name ) {
$cookies [ name ] = '' ;
} ;
cookieService . get = function ( name ) {
return $cookies [ name ] ;
} ;
return cookieService ;
} ] ) ;
2014-04-09 01:10:33 +00:00
$provide . factory ( 'UserService' , [ 'ApiService' , 'CookieService' , '$rootScope' , 'Config' ,
function ( ApiService , CookieService , $rootScope , Config ) {
2013-09-26 23:59:58 +00:00
var userResponse = {
verified : false ,
anonymous : true ,
username : null ,
2013-10-10 17:44:34 +00:00
email : null ,
2014-01-14 20:23:44 +00:00
organizations : [ ] ,
logins : [ ]
2013-09-26 23:59:58 +00:00
}
var userService = { }
2013-12-11 23:27:35 +00:00
userService . hasEverLoggedIn = function ( ) {
2013-12-17 20:03:34 +00:00
return CookieService . get ( 'quay.loggedin' ) == 'true' ;
2013-12-11 23:27:35 +00:00
} ;
2013-12-17 18:19:59 +00:00
userService . updateUserIn = function ( scope , opt _callback ) {
scope . $watch ( function ( ) { return userService . currentUser ( ) ; } , function ( currentUser ) {
scope . user = currentUser ;
if ( opt _callback ) {
2014-11-24 21:07:38 +00:00
opt _callback ( currentUser ) ;
2013-12-17 18:19:59 +00:00
}
} , true ) ;
2013-12-11 23:27:35 +00:00
} ;
2013-11-12 00:26:56 +00:00
userService . load = function ( opt _callback ) {
2014-03-19 18:04:42 +00:00
var handleUserResponse = function ( loadedUser ) {
2013-09-26 23:59:58 +00:00
userResponse = loadedUser ;
2013-10-03 19:46:22 +00:00
2013-10-03 20:16:10 +00:00
if ( ! userResponse . anonymous ) {
2014-04-09 01:10:33 +00:00
if ( Config . MIXPANEL _KEY ) {
mixpanel . identify ( userResponse . username ) ;
mixpanel . people . set ( {
'$email' : userResponse . email ,
'$username' : userResponse . username ,
'verified' : userResponse . verified
} ) ;
mixpanel . people . set _once ( {
'$created' : new Date ( )
} )
}
2013-12-11 23:27:35 +00:00
2014-01-10 19:29:18 +00:00
if ( window . olark !== undefined ) {
olark ( 'api.visitor.getDetails' , function ( details ) {
if ( details . fullName === null ) {
olark ( 'api.visitor.updateFullName' , { fullName : userResponse . username } ) ;
}
} ) ;
olark ( 'api.visitor.updateEmailAddress' , { emailAddress : userResponse . email } ) ;
olark ( 'api.chat.updateVisitorStatus' , { snippet : 'username: ' + userResponse . username } ) ;
}
2014-04-28 22:59:22 +00:00
if ( window . Raven !== undefined ) {
Raven . setUser ( {
email : userResponse . email ,
id : userResponse . username
} ) ;
}
2013-12-17 20:03:34 +00:00
CookieService . putPermanent ( 'quay.loggedin' , 'true' ) ;
2014-04-28 22:59:22 +00:00
} else {
if ( window . Raven !== undefined ) {
Raven . setUser ( ) ;
}
2013-10-03 20:16:10 +00:00
}
2013-11-12 00:26:56 +00:00
if ( opt _callback ) {
opt _callback ( ) ;
}
2014-03-19 18:04:42 +00:00
} ;
ApiService . getLoggedInUser ( ) . then ( function ( loadedUser ) {
handleUserResponse ( loadedUser ) ;
} , function ( ) {
2014-11-24 21:07:38 +00:00
handleUserResponse ( { 'anonymous' : true } ) ;
2013-09-26 23:59:58 +00:00
} ) ;
} ;
2013-11-08 22:50:42 +00:00
userService . getOrganization = function ( name ) {
if ( ! userResponse || ! userResponse . organizations ) { return null ; }
for ( var i = 0 ; i < userResponse . organizations . length ; ++ i ) {
var org = userResponse . organizations [ i ] ;
if ( org . name == name ) {
return org ;
}
}
2013-11-01 23:13:58 +00:00
2013-11-08 22:50:42 +00:00
return null ;
2013-11-01 23:13:58 +00:00
} ;
2013-12-10 20:22:22 +00:00
userService . isNamespaceAdmin = function ( namespace ) {
if ( namespace == userResponse . username ) {
return true ;
}
var org = userService . getOrganization ( namespace ) ;
if ( ! org ) {
return false ;
}
return org . is _org _admin ;
} ;
2014-01-31 18:52:35 +00:00
userService . isKnownNamespace = function ( namespace ) {
if ( namespace == userResponse . username ) {
return true ;
}
var org = userService . getOrganization ( namespace ) ;
return ! ! org ;
} ;
2014-11-24 21:07:38 +00:00
2013-09-26 23:59:58 +00:00
userService . currentUser = function ( ) {
return userResponse ;
2013-11-08 22:50:42 +00:00
} ;
2013-09-26 23:59:58 +00:00
2014-03-19 18:27:33 +00:00
// Update the user in the root scope.
userService . updateUserIn ( $rootScope ) ;
2013-09-26 23:59:58 +00:00
// Load the user the first time.
userService . load ( ) ;
return userService ;
2013-10-04 18:35:51 +00:00
} ] ) ;
2014-09-22 23:11:48 +00:00
$provide . factory ( 'ExternalNotificationData' , [ 'Config' , 'Features' , function ( Config , Features ) {
2014-07-17 17:32:39 +00:00
var externalNotificationData = { } ;
var events = [
{
'id' : 'repo_push' ,
'title' : 'Push to Repository' ,
'icon' : 'fa-upload'
}
] ;
2014-11-03 22:12:39 +00:00
if ( Features . BUILD _SUPPORT ) {
var buildEvents = [
2014-11-24 21:07:38 +00:00
{
2014-11-03 22:12:39 +00:00
'id' : 'build_queued' ,
'title' : 'Dockerfile Build Queued' ,
'icon' : 'fa-tasks'
} ,
2014-11-24 21:07:38 +00:00
{
2014-11-03 22:12:39 +00:00
'id' : 'build_start' ,
'title' : 'Dockerfile Build Started' ,
'icon' : 'fa-circle-o-notch'
} ,
2014-11-24 21:07:38 +00:00
{
2014-11-03 22:12:39 +00:00
'id' : 'build_success' ,
'title' : 'Dockerfile Build Successfully Completed' ,
'icon' : 'fa-check-circle-o'
} ,
2014-11-24 21:07:38 +00:00
{
2014-11-03 22:12:39 +00:00
'id' : 'build_failure' ,
'title' : 'Dockerfile Build Failed' ,
'icon' : 'fa-times-circle-o'
} ] ;
for ( var i = 0 ; i < buildEvents . length ; ++ i ) {
events . push ( buildEvents [ i ] ) ;
}
}
2014-07-17 17:32:39 +00:00
var methods = [
{
'id' : 'quay_notification' ,
2014-08-08 17:50:04 +00:00
'title' : Config . REGISTRY _TITLE + ' Notification' ,
2014-07-18 17:45:08 +00:00
'icon' : 'quay-icon' ,
'fields' : [
{
'name' : 'target' ,
'type' : 'entity' ,
'title' : 'Recipient'
}
]
2014-07-17 17:32:39 +00:00
} ,
2014-11-24 21:07:38 +00:00
{
2014-07-17 17:32:39 +00:00
'id' : 'email' ,
2014-07-22 17:39:41 +00:00
'title' : 'E-mail' ,
2014-07-17 17:32:39 +00:00
'icon' : 'fa-envelope' ,
'fields' : [
{
'name' : 'email' ,
'type' : 'email' ,
'title' : 'E-mail address'
}
2014-09-22 23:11:48 +00:00
] ,
'enabled' : Features . MAILING
2014-07-17 17:32:39 +00:00
} ,
{
'id' : 'webhook' ,
2014-07-22 17:39:41 +00:00
'title' : 'Webhook POST' ,
2014-07-17 17:32:39 +00:00
'icon' : 'fa-link' ,
'fields' : [
{
'name' : 'url' ,
'type' : 'url' ,
'title' : 'Webhook URL'
}
]
2014-08-19 18:33:33 +00:00
} ,
{
'id' : 'flowdock' ,
'title' : 'Flowdock Team Notification' ,
'icon' : 'flowdock-icon' ,
'fields' : [
{
'name' : 'flow_api_token' ,
'type' : 'string' ,
'title' : 'Flow API Token' ,
'help_url' : 'https://www.flowdock.com/account/tokens'
}
]
2014-08-19 21:40:36 +00:00
} ,
{
'id' : 'hipchat' ,
'title' : 'HipChat Room Notification' ,
'icon' : 'hipchat-icon' ,
'fields' : [
{
'name' : 'room_id' ,
'type' : 'string' ,
'title' : 'Room ID #'
} ,
{
'name' : 'notification_token' ,
'type' : 'string' ,
2014-10-06 16:17:05 +00:00
'title' : 'Room Notification Token' ,
'help_url' : 'https://hipchat.com/rooms/tokens/{room_id}'
2014-08-19 21:40:36 +00:00
}
]
2014-08-27 02:09:56 +00:00
} ,
{
'id' : 'slack' ,
'title' : 'Slack Room Notification' ,
'icon' : 'slack-icon' ,
'fields' : [
{
2014-12-16 12:34:43 +00:00
'name' : 'url' ,
'type' : 'regex' ,
'title' : 'Webhook URL' ,
'regex' : '^https://hooks\\.slack\\.com/services/[A-Z0-9]+/[A-Z0-9]+/[a-zA-Z0-9]+$' ,
'help_url' : 'https://slack.com/services/new/incoming-webhook' ,
'placeholder' : 'https://hooks.slack.com/service/{some}/{token}/{here}'
2014-08-27 02:09:56 +00:00
}
]
2014-07-17 17:32:39 +00:00
}
] ;
var methodMap = { } ;
var eventMap = { } ;
for ( var i = 0 ; i < methods . length ; ++ i ) {
methodMap [ methods [ i ] . id ] = methods [ i ] ;
}
for ( var i = 0 ; i < events . length ; ++ i ) {
eventMap [ events [ i ] . id ] = events [ i ] ;
}
externalNotificationData . getSupportedEvents = function ( ) {
return events ;
} ;
externalNotificationData . getSupportedMethods = function ( ) {
2014-09-22 23:11:48 +00:00
var filtered = [ ] ;
for ( var i = 0 ; i < methods . length ; ++ i ) {
if ( methods [ i ] . enabled !== false ) {
filtered . push ( methods [ i ] ) ;
}
}
return filtered ;
2014-07-17 17:32:39 +00:00
} ;
externalNotificationData . getEventInfo = function ( event ) {
return eventMap [ event ] ;
} ;
externalNotificationData . getMethodInfo = function ( method ) {
return methodMap [ method ] ;
} ;
return externalNotificationData ;
} ] ) ;
2014-08-18 21:24:00 +00:00
$provide . factory ( 'NotificationService' , [ '$rootScope' , '$interval' , 'UserService' , 'ApiService' , 'StringBuilderService' , 'PlanService' , 'UserService' , 'Config' , '$location' ,
function ( $rootScope , $interval , UserService , ApiService , StringBuilderService , PlanService , UserService , Config , $location ) {
2014-03-12 04:49:46 +00:00
var notificationService = {
'user' : null ,
'notifications' : [ ] ,
'notificationClasses' : [ ] ,
2014-08-26 19:19:39 +00:00
'notificationSummaries' : [ ] ,
'additionalNotifications' : false
2014-03-12 04:49:46 +00:00
} ;
var pollTimerHandle = null ;
var notificationKinds = {
'test_notification' : {
'level' : 'primary' ,
2014-08-05 21:45:40 +00:00
'message' : 'This notification is a long message for testing: {obj}' ,
2014-07-28 22:23:46 +00:00
'page' : '/about/' ,
'dismissable' : true
2014-03-12 20:05:32 +00:00
} ,
2014-08-16 01:56:29 +00:00
'org_team_invite' : {
'level' : 'primary' ,
2014-08-18 21:24:00 +00:00
'message' : '{inviter} is inviting you to join team {team} under organization {org}' ,
2014-08-16 01:56:29 +00:00
'actions' : [
{
'title' : 'Join team' ,
'kind' : 'primary' ,
'handler' : function ( notification ) {
2014-08-18 21:24:00 +00:00
window . location = '/confirminvite?code=' + notification . metadata [ 'code' ] ;
2014-08-16 01:56:29 +00:00
}
} ,
2014-08-18 21:24:00 +00:00
{
'title' : 'Decline' ,
'kind' : 'default' ,
'handler' : function ( notification ) {
ApiService . declineOrganizationTeamInvite ( null , { 'code' : notification . metadata [ 'code' ] } ) . then ( function ( ) {
notificationService . update ( ) ;
} ) ;
}
}
2014-08-16 01:56:29 +00:00
]
} ,
2014-03-12 20:05:32 +00:00
'password_required' : {
'level' : 'error' ,
2014-08-08 17:50:04 +00:00
'message' : 'In order to begin pushing and pulling repositories, a password must be set for your account' ,
2014-03-12 20:05:32 +00:00
'page' : '/user?tab=password'
2014-03-12 23:19:39 +00:00
} ,
'over_private_usage' : {
'level' : 'error' ,
'message' : 'Namespace {namespace} is over its allowed private repository count. ' +
'<br><br>Please upgrade your plan to avoid disruptions in service.' ,
'page' : function ( metadata ) {
var organization = UserService . getOrganization ( metadata [ 'namespace' ] ) ;
if ( organization ) {
return '/organization/' + metadata [ 'namespace' ] + '/admin' ;
} else {
return '/user' ;
}
}
2014-05-29 15:24:10 +00:00
} ,
'expiring_license' : {
'level' : 'error' ,
'message' : 'Your license will expire at: {expires_at} ' +
2014-08-08 17:50:04 +00:00
'<br><br>Please contact support to purchase a new license.' ,
2014-05-29 15:24:10 +00:00
'page' : '/contact/'
2014-06-27 23:18:27 +00:00
} ,
'maintenance' : {
'level' : 'warning' ,
'message' : 'We will be down for schedule maintenance from {from_date} to {to_date} ' +
'for {reason}. We are sorry about any inconvenience.' ,
'page' : 'http://status.quay.io/'
2014-07-18 18:12:20 +00:00
} ,
'repo_push' : {
'level' : 'info' ,
2014-08-05 21:45:40 +00:00
'message' : function ( metadata ) {
if ( metadata . updated _tags && Object . getOwnPropertyNames ( metadata . updated _tags ) . length ) {
return 'Repository {repository} has been pushed with the following tags updated: {updated_tags}' ;
} else {
2014-10-29 19:42:44 +00:00
return 'Repository {repository} fhas been pushed' ;
2014-08-05 21:45:40 +00:00
}
} ,
2014-07-18 18:12:20 +00:00
'page' : function ( metadata ) {
return '/repository/' + metadata . repository ;
2014-07-28 22:23:46 +00:00
} ,
'dismissable' : true
2014-07-18 19:58:18 +00:00
} ,
'build_queued' : {
'level' : 'info' ,
'message' : 'A build has been queued for repository {repository}' ,
'page' : function ( metadata ) {
return '/repository/' + metadata . repository + '/build?current=' + metadata . build _id ;
2014-07-28 22:23:46 +00:00
} ,
'dismissable' : true
2014-07-18 19:58:18 +00:00
} ,
'build_start' : {
'level' : 'info' ,
'message' : 'A build has been started for repository {repository}' ,
'page' : function ( metadata ) {
return '/repository/' + metadata . repository + '/build?current=' + metadata . build _id ;
2014-07-28 22:23:46 +00:00
} ,
2014-08-10 22:51:06 +00:00
'dismissable' : true
} ,
'build_success' : {
'level' : 'info' ,
'message' : 'A build has succeeded for repository {repository}' ,
'page' : function ( metadata ) {
return '/repository/' + metadata . repository + '/build?current=' + metadata . build _id ;
} ,
2014-07-28 22:23:46 +00:00
'dismissable' : true
2014-07-18 19:58:18 +00:00
} ,
'build_failure' : {
'level' : 'error' ,
'message' : 'A build has failed for repository {repository}' ,
'page' : function ( metadata ) {
return '/repository/' + metadata . repository + '/build?current=' + metadata . build _id ;
2014-07-28 22:23:46 +00:00
} ,
'dismissable' : true
2014-03-12 04:49:46 +00:00
}
} ;
2014-07-28 22:23:46 +00:00
notificationService . dismissNotification = function ( notification ) {
notification . dismissed = true ;
var params = {
'uuid' : notification . id
} ;
2014-11-24 21:07:38 +00:00
2014-08-26 19:19:39 +00:00
ApiService . updateUserNotification ( notification , params , function ( ) {
notificationService . update ( ) ;
} , ApiService . errorDisplay ( 'Could not update notification' ) ) ;
2014-07-28 22:23:46 +00:00
var index = $ . inArray ( notification , notificationService . notifications ) ;
if ( index >= 0 ) {
notificationService . notifications . splice ( index , 1 ) ;
}
} ;
2014-08-16 01:56:29 +00:00
notificationService . getActions = function ( notification ) {
var kindInfo = notificationKinds [ notification [ 'kind' ] ] ;
if ( ! kindInfo ) {
return [ ] ;
}
return kindInfo [ 'actions' ] || [ ] ;
} ;
2014-07-28 22:23:46 +00:00
notificationService . canDismiss = function ( notification ) {
2014-08-05 22:20:04 +00:00
var kindInfo = notificationKinds [ notification [ 'kind' ] ] ;
if ( ! kindInfo ) {
return false ;
}
return ! ! kindInfo [ 'dismissable' ] ;
2014-07-28 22:23:46 +00:00
} ;
2014-03-12 20:05:32 +00:00
notificationService . getPage = function ( notification ) {
2014-09-15 15:27:33 +00:00
var kindInfo = notificationKinds [ notification [ 'kind' ] ] ;
if ( ! kindInfo ) {
return null ;
}
var page = kindInfo [ 'page' ] ;
2014-09-23 18:13:55 +00:00
if ( page != null && typeof page != 'string' ) {
2014-03-12 23:19:39 +00:00
page = page ( notification [ 'metadata' ] ) ;
}
2014-09-23 18:13:55 +00:00
return page || '' ;
2014-03-12 20:05:32 +00:00
} ;
notificationService . getMessage = function ( notification ) {
var kindInfo = notificationKinds [ notification [ 'kind' ] ] ;
2014-08-05 22:20:04 +00:00
if ( ! kindInfo ) {
return '(Unknown notification kind: ' + notification [ 'kind' ] + ')' ;
}
2014-03-12 20:05:32 +00:00
return StringBuilderService . buildString ( kindInfo [ 'message' ] , notification [ 'metadata' ] ) ;
} ;
notificationService . getClass = function ( notification ) {
2014-08-05 22:20:04 +00:00
var kindInfo = notificationKinds [ notification [ 'kind' ] ] ;
if ( ! kindInfo ) {
return 'notification-info' ;
}
return 'notification-' + kindInfo [ 'level' ] ;
2014-03-12 20:05:32 +00:00
} ;
2014-03-12 04:49:46 +00:00
notificationService . getClasses = function ( notifications ) {
var classes = [ ] ;
for ( var i = 0 ; i < notifications . length ; ++ i ) {
var notification = notifications [ i ] ;
2014-03-12 20:05:32 +00:00
classes . push ( notificationService . getClass ( notification ) ) ;
2014-03-12 04:49:46 +00:00
}
return classes . join ( ' ' ) ;
} ;
notificationService . update = function ( ) {
2014-03-12 20:05:32 +00:00
var user = UserService . currentUser ( ) ;
if ( ! user || user . anonymous ) {
return ;
}
2014-03-12 04:49:46 +00:00
ApiService . listUserNotifications ( ) . then ( function ( resp ) {
notificationService . notifications = resp [ 'notifications' ] ;
2014-08-26 19:19:39 +00:00
notificationService . additionalNotifications = resp [ 'additional' ] ;
2014-03-12 04:49:46 +00:00
notificationService . notificationClasses = notificationService . getClasses ( notificationService . notifications ) ;
} ) ;
} ;
notificationService . reset = function ( ) {
$interval . cancel ( pollTimerHandle ) ;
pollTimerHandle = $interval ( notificationService . update , 5 * 60 * 1000 /* five minutes */ ) ;
} ;
2014-03-12 23:19:39 +00:00
// Watch for plan changes and update.
PlanService . registerListener ( this , function ( plan ) {
notificationService . reset ( ) ;
notificationService . update ( ) ;
} ) ;
2014-03-12 04:49:46 +00:00
// Watch for user changes and update.
$rootScope . $watch ( function ( ) { return UserService . currentUser ( ) ; } , function ( currentUser ) {
notificationService . reset ( ) ;
notificationService . update ( ) ;
} ) ;
return notificationService ;
} ] ) ;
2014-11-17 19:54:07 +00:00
$provide . factory ( 'OAuthService' , [ '$location' , 'Config' , function ( $location , Config ) {
var oauthService = { } ;
oauthService . SCOPES = window . _ _auth _scopes ;
return oauthService ;
} ] ) ;
2014-04-08 23:14:24 +00:00
$provide . factory ( 'KeyService' , [ '$location' , 'Config' , function ( $location , Config ) {
2013-10-08 17:57:48 +00:00
var keyService = { }
2014-11-05 21:43:37 +00:00
var oauth = window . _ _oauth ;
2013-10-08 17:57:48 +00:00
2014-04-08 23:14:24 +00:00
keyService [ 'stripePublishableKey' ] = Config [ 'STRIPE_PUBLISHABLE_KEY' ] ;
2014-08-11 19:47:44 +00:00
2014-11-05 21:43:37 +00:00
keyService [ 'githubTriggerClientId' ] = oauth [ 'GITHUB_TRIGGER_CONFIG' ] [ 'CLIENT_ID' ] ;
keyService [ 'githubLoginClientId' ] = oauth [ 'GITHUB_LOGIN_CONFIG' ] [ 'CLIENT_ID' ] ;
keyService [ 'googleLoginClientId' ] = oauth [ 'GOOGLE_LOGIN_CONFIG' ] [ 'CLIENT_ID' ] ;
2013-10-08 17:57:48 +00:00
2014-11-05 21:43:37 +00:00
keyService [ 'githubRedirectUri' ] = Config . getUrl ( '/oauth2/github/callback' ) ;
2014-08-11 19:47:44 +00:00
keyService [ 'googleRedirectUri' ] = Config . getUrl ( '/oauth2/google/callback' ) ;
2014-11-05 21:43:37 +00:00
keyService [ 'githubLoginUrl' ] = oauth [ 'GITHUB_LOGIN_CONFIG' ] [ 'AUTHORIZE_ENDPOINT' ] ;
keyService [ 'googleLoginUrl' ] = oauth [ 'GOOGLE_LOGIN_CONFIG' ] [ 'AUTHORIZE_ENDPOINT' ] ;
2014-11-07 01:35:52 +00:00
keyService [ 'githubEndpoint' ] = oauth [ 'GITHUB_LOGIN_CONFIG' ] [ 'GITHUB_ENDPOINT' ] ;
2014-11-26 17:54:02 +00:00
keyService [ 'githubTriggerEndpoint' ] = oauth [ 'GITHUB_TRIGGER_CONFIG' ] [ 'GITHUB_ENDPOINT' ] ;
2014-11-26 17:37:20 +00:00
keyService [ 'githubTriggerAuthorizeUrl' ] = oauth [ 'GITHUB_TRIGGER_CONFIG' ] [ 'AUTHORIZE_ENDPOINT' ] ;
2014-08-11 19:47:44 +00:00
keyService [ 'githubLoginScope' ] = 'user:email' ;
2014-11-05 21:43:37 +00:00
keyService [ 'googleLoginScope' ] = 'openid email' ;
keyService . isEnterprise = function ( service ) {
2014-11-26 17:54:02 +00:00
switch ( service ) {
case 'github' :
return keyService [ 'githubLoginUrl' ] . indexOf ( 'https://github.com/' ) < 0 ;
case 'github-trigger' :
return keyService [ 'githubTriggerAuthorizeUrl' ] . indexOf ( 'https://github.com/' ) < 0 ;
}
return false ;
2014-11-05 21:43:37 +00:00
} ;
2014-08-11 19:47:44 +00:00
keyService . getExternalLoginUrl = function ( service , action ) {
var state _clause = '' ;
if ( Config . MIXPANEL _KEY && window . mixpanel ) {
if ( mixpanel . get _distinct _id !== undefined ) {
state _clause = "&state=" + encodeURIComponent ( mixpanel . get _distinct _id ( ) ) ;
}
}
var client _id = keyService [ service + 'LoginClientId' ] ;
var scope = keyService [ service + 'LoginScope' ] ;
var redirect _uri = keyService [ service + 'RedirectUri' ] ;
if ( action == 'attach' ) {
redirect _uri += '/attach' ;
}
var url = keyService [ service + 'LoginUrl' ] + 'client_id=' + client _id + '&scope=' + scope +
'&redirect_uri=' + redirect _uri + state _clause ;
return url ;
} ;
2013-10-08 17:57:48 +00:00
return keyService ;
} ] ) ;
2014-11-24 21:07:38 +00:00
2014-04-09 01:10:33 +00:00
$provide . factory ( 'PlanService' , [ 'KeyService' , 'UserService' , 'CookieService' , 'ApiService' , 'Features' , 'Config' ,
function ( KeyService , UserService , CookieService , ApiService , Features , Config ) {
2013-11-01 23:13:58 +00:00
var plans = null ;
2013-10-04 18:35:51 +00:00
var planDict = { } ;
2013-11-15 23:17:12 +00:00
var planService = { } ;
var listeners = [ ] ;
2013-10-04 18:35:51 +00:00
2014-02-03 23:18:33 +00:00
var previousSubscribeFailure = false ;
2013-12-20 02:51:46 +00:00
planService . getFreePlan = function ( ) {
return 'free' ;
} ;
2013-11-15 23:17:12 +00:00
planService . registerListener = function ( obj , callback ) {
listeners . push ( { 'obj' : obj , 'callback' : callback } ) ;
} ;
planService . unregisterListener = function ( obj ) {
for ( var i = 0 ; i < listeners . length ; ++ i ) {
if ( listeners [ i ] . obj == obj ) {
listeners . splice ( i , 1 ) ;
break ;
}
}
} ;
2013-12-11 22:50:48 +00:00
planService . notePlan = function ( planId ) {
2014-04-06 04:36:19 +00:00
if ( Features . BILLING ) {
CookieService . putSession ( 'quay.notedplan' , planId ) ;
}
2013-12-11 22:50:48 +00:00
} ;
2013-12-20 02:51:46 +00:00
planService . isOrgCompatible = function ( plan ) {
return plan [ 'stripeId' ] == planService . getFreePlan ( ) || plan [ 'bus_features' ] ;
} ;
planService . getMatchingBusinessPlan = function ( callback ) {
planService . getPlans ( function ( ) {
planService . getSubscription ( null , function ( sub ) {
var plan = planDict [ sub . plan ] ;
if ( ! plan ) {
planService . getMinimumPlan ( 0 , true , callback ) ;
return ;
}
var count = Math . max ( sub . usedPrivateRepos , plan . privateRepos ) ;
planService . getMinimumPlan ( count , true , callback ) ;
} , function ( ) {
planService . getMinimumPlan ( 0 , true , callback ) ;
} ) ;
} ) ;
2013-12-11 22:50:48 +00:00
} ;
planService . handleNotedPlan = function ( ) {
var planId = planService . getAndResetNotedPlan ( ) ;
2014-04-06 04:36:19 +00:00
if ( ! planId || ! Features . BILLING ) { return false ; }
2013-12-11 22:50:48 +00:00
2013-12-11 23:20:24 +00:00
UserService . load ( function ( ) {
if ( UserService . currentUser ( ) . anonymous ) {
return ;
2013-12-11 22:50:48 +00:00
}
2013-12-18 23:16:32 +00:00
planService . getPlan ( planId , function ( plan ) {
2013-12-20 02:51:46 +00:00
if ( planService . isOrgCompatible ( plan ) ) {
2013-12-11 23:20:24 +00:00
document . location = '/organizations/new/?plan=' + planId ;
} else {
document . location = '/user?plan=' + planId ;
}
} ) ;
2013-12-11 22:50:48 +00:00
} ) ;
2014-03-19 18:27:33 +00:00
return true ;
2013-12-11 22:50:48 +00:00
} ;
planService . getAndResetNotedPlan = function ( ) {
2013-12-17 20:03:34 +00:00
var planId = CookieService . get ( 'quay.notedplan' ) ;
CookieService . clear ( 'quay.notedplan' ) ;
2013-12-11 22:50:48 +00:00
return planId ;
} ;
2014-11-24 21:07:38 +00:00
2013-11-19 22:06:17 +00:00
planService . handleCardError = function ( resp ) {
if ( ! planService . isCardError ( resp ) ) { return ; }
bootbox . dialog ( {
"message" : resp . data . carderror ,
"title" : "Credit card issue" ,
"buttons" : {
"close" : {
"label" : "Close" ,
"className" : "btn-primary"
}
}
} ) ;
} ;
planService . isCardError = function ( resp ) {
return resp && resp . data && resp . data . carderror ;
} ;
2013-11-01 23:13:58 +00:00
planService . verifyLoaded = function ( callback ) {
2014-04-06 04:36:19 +00:00
if ( ! Features . BILLING ) { return ; }
2014-06-04 20:27:45 +00:00
if ( plans && plans . length ) {
2013-11-01 23:13:58 +00:00
callback ( plans ) ;
return ;
}
2013-12-26 22:45:16 +00:00
ApiService . listPlans ( ) . then ( function ( data ) {
2014-06-04 20:27:45 +00:00
plans = data . plans || [ ] ;
for ( var i = 0 ; i < plans . length ; i ++ ) {
planDict [ plans [ i ] . stripeId ] = plans [ i ] ;
2014-05-05 16:54:54 +00:00
}
2014-06-04 20:27:45 +00:00
callback ( plans ) ;
2013-11-01 23:13:58 +00:00
} , function ( ) { callback ( [ ] ) ; } ) ;
} ;
2013-12-20 02:51:46 +00:00
planService . getPlans = function ( callback , opt _includePersonal ) {
2013-12-11 22:50:48 +00:00
planService . verifyLoaded ( function ( ) {
2013-12-20 02:51:46 +00:00
var filtered = [ ] ;
for ( var i = 0 ; i < plans . length ; ++ i ) {
var plan = plans [ i ] ;
if ( plan [ 'deprecated' ] ) { continue ; }
if ( ! opt _includePersonal && ! planService . isOrgCompatible ( plan ) ) { continue ; }
filtered . push ( plan ) ;
2013-12-11 22:50:48 +00:00
}
2013-12-20 02:51:46 +00:00
callback ( filtered ) ;
2013-12-11 22:50:48 +00:00
} ) ;
} ;
2013-12-20 02:51:46 +00:00
planService . getPlan = function ( planId , callback ) {
planService . getPlanIncludingDeprecated ( planId , function ( plan ) {
if ( ! plan [ 'deprecated' ] ) {
callback ( plan ) ;
}
} ) ;
2013-10-28 21:08:26 +00:00
} ;
2013-10-04 18:35:51 +00:00
2013-12-20 02:51:46 +00:00
planService . getPlanIncludingDeprecated = function ( planId , callback ) {
2013-11-01 23:13:58 +00:00
planService . verifyLoaded ( function ( ) {
2014-11-24 21:07:38 +00:00
if ( planDict [ planId ] ) {
2013-11-06 23:14:22 +00:00
callback ( planDict [ planId ] ) ;
}
2013-11-01 23:13:58 +00:00
} ) ;
2013-10-28 21:08:26 +00:00
} ;
2013-11-05 19:40:45 +00:00
planService . getMinimumPlan = function ( privateCount , isBusiness , callback ) {
2014-11-24 21:07:38 +00:00
planService . getPlans ( function ( plans ) {
2013-12-20 02:51:46 +00:00
for ( var i = 0 ; i < plans . length ; i ++ ) {
var plan = plans [ i ] ;
2013-11-01 23:13:58 +00:00
if ( plan . privateRepos >= privateCount ) {
callback ( plan ) ;
return ;
}
2013-10-28 21:08:26 +00:00
}
2013-11-01 23:13:58 +00:00
callback ( null ) ;
2014-03-06 23:36:52 +00:00
} , /* include personal */ ! isBusiness ) ;
2013-10-28 21:08:26 +00:00
} ;
2013-11-15 23:17:12 +00:00
planService . getSubscription = function ( orgname , success , failure ) {
2014-04-06 04:36:19 +00:00
if ( ! Features . BILLING ) { return ; }
ApiService . getSubscription ( orgname ) . then ( success , failure ) ;
2013-11-06 22:30:20 +00:00
} ;
planService . setSubscription = function ( orgname , planId , success , failure , opt _token ) {
2014-04-06 04:36:19 +00:00
if ( ! Features . BILLING ) { return ; }
2013-11-06 22:30:20 +00:00
var subscriptionDetails = {
plan : planId
} ;
2013-10-28 21:08:26 +00:00
2013-11-06 22:30:20 +00:00
if ( opt _token ) {
subscriptionDetails [ 'token' ] = opt _token . id ;
}
2013-12-26 22:45:16 +00:00
ApiService . updateSubscription ( orgname , subscriptionDetails ) . then ( function ( resp ) {
2013-11-15 23:17:12 +00:00
success ( resp ) ;
planService . getPlan ( planId , function ( plan ) {
for ( var i = 0 ; i < listeners . length ; ++ i ) {
listeners [ i ] [ 'callback' ] ( plan ) ;
}
} ) ;
} , failure ) ;
2013-11-06 22:30:20 +00:00
} ;
2013-11-15 23:58:47 +00:00
planService . getCardInfo = function ( orgname , callback ) {
2014-04-06 04:36:19 +00:00
if ( ! Features . BILLING ) { return ; }
2013-12-26 22:45:16 +00:00
ApiService . getCard ( orgname ) . then ( function ( resp ) {
2013-11-15 23:58:47 +00:00
callback ( resp . card ) ;
} , function ( ) {
callback ( { 'is_valid' : false } ) ;
} ) ;
} ;
2014-08-28 20:10:06 +00:00
planService . changePlan = function ( $scope , orgname , planId , callbacks , opt _async ) {
2014-04-06 04:36:19 +00:00
if ( ! Features . BILLING ) { return ; }
2013-11-09 01:32:56 +00:00
if ( callbacks [ 'started' ] ) {
2013-11-15 23:58:47 +00:00
callbacks [ 'started' ] ( ) ;
2013-11-09 01:32:56 +00:00
}
2013-11-15 23:58:47 +00:00
planService . getPlan ( planId , function ( plan ) {
2013-12-20 02:51:46 +00:00
if ( orgname && ! planService . isOrgCompatible ( plan ) ) { return ; }
2013-11-15 23:58:47 +00:00
planService . getCardInfo ( orgname , function ( cardInfo ) {
2014-02-03 23:18:33 +00:00
if ( plan . price > 0 && ( previousSubscribeFailure || ! cardInfo . last4 ) ) {
2014-05-03 01:42:36 +00:00
var title = cardInfo . last4 ? 'Subscribe' : 'Start Trial ({{amount}} plan)' ;
2014-08-28 20:10:06 +00:00
planService . showSubscribeDialog ( $scope , orgname , planId , callbacks , title , /* async */ true ) ;
2013-11-15 23:58:47 +00:00
return ;
}
2014-11-24 21:07:38 +00:00
2014-02-03 23:18:33 +00:00
previousSubscribeFailure = false ;
2013-11-19 22:06:17 +00:00
planService . setSubscription ( orgname , planId , callbacks [ 'success' ] , function ( resp ) {
2014-02-03 23:18:33 +00:00
previousSubscribeFailure = true ;
2013-11-19 22:06:17 +00:00
planService . handleCardError ( resp ) ;
callbacks [ 'failure' ] ( resp ) ;
} ) ;
2013-11-15 23:58:47 +00:00
} ) ;
} ) ;
2013-11-06 22:30:20 +00:00
} ;
2013-11-15 23:17:12 +00:00
planService . changeCreditCard = function ( $scope , orgname , callbacks ) {
2014-04-06 04:36:19 +00:00
if ( ! Features . BILLING ) { return ; }
2013-11-15 23:17:12 +00:00
if ( callbacks [ 'opening' ] ) {
callbacks [ 'opening' ] ( ) ;
}
2013-11-19 22:06:17 +00:00
var submitted = false ;
2013-11-15 23:17:12 +00:00
var submitToken = function ( token ) {
2013-11-19 22:06:17 +00:00
if ( submitted ) { return ; }
submitted = true ;
2014-11-24 21:07:38 +00:00
$scope . $apply ( function ( ) {
2013-11-15 23:17:12 +00:00
if ( callbacks [ 'started' ] ) {
callbacks [ 'started' ] ( ) ;
}
2014-11-24 21:07:38 +00:00
2013-11-15 23:17:12 +00:00
var cardInfo = {
'token' : token . id
} ;
2013-12-26 22:45:16 +00:00
ApiService . setCard ( orgname , cardInfo ) . then ( callbacks [ 'success' ] , function ( resp ) {
planService . handleCardError ( resp ) ;
callbacks [ 'failure' ] ( resp ) ;
} ) ;
2013-11-15 23:17:12 +00:00
} ) ;
} ;
var email = planService . getEmail ( orgname ) ;
StripeCheckout . open ( {
key : KeyService . stripePublishableKey ,
address : false ,
email : email ,
currency : 'usd' ,
name : 'Update credit card' ,
description : 'Enter your credit card number' ,
panelLabel : 'Update' ,
token : submitToken ,
image : 'static/img/quay-icon-stripe.png' ,
opened : function ( ) { $scope . $apply ( function ( ) { callbacks [ 'opened' ] ( ) } ) ; } ,
closed : function ( ) { $scope . $apply ( function ( ) { callbacks [ 'closed' ] ( ) } ) ; }
} ) ;
} ;
planService . getEmail = function ( orgname ) {
var email = null ;
if ( UserService . currentUser ( ) ) {
email = UserService . currentUser ( ) . email ;
if ( orgname ) {
org = UserService . getOrganization ( orgname ) ;
if ( org ) {
emaiil = org . email ;
}
}
}
return email ;
} ;
2014-08-28 20:10:06 +00:00
planService . showSubscribeDialog = function ( $scope , orgname , planId , callbacks , opt _title , opt _async ) {
2014-04-06 04:36:19 +00:00
if ( ! Features . BILLING ) { return ; }
2014-08-28 20:10:06 +00:00
// If the async parameter is true and this is a browser that does not allow async popup of the
// Stripe dialog (such as Mobile Safari or IE), show a bootbox to show the dialog instead.
var isIE = navigator . appName . indexOf ( "Internet Explorer" ) != - 1 ;
var isMobileSafari = navigator . userAgent . match ( /(iPod|iPhone|iPad)/ ) && navigator . userAgent . match ( /AppleWebKit/ ) ;
if ( opt _async && ( isIE || isMobileSafari ) ) {
bootbox . dialog ( {
"message" : "Please click 'Subscribe' to continue" ,
"buttons" : {
"subscribe" : {
"label" : "Subscribe" ,
"className" : "btn-primary" ,
"callback" : function ( ) {
planService . showSubscribeDialog ( $scope , orgname , planId , callbacks , opt _title , false ) ;
}
} ,
"close" : {
"label" : "Cancel" ,
"className" : "btn-default"
}
}
2014-11-24 21:07:38 +00:00
} ) ;
2014-08-28 20:10:06 +00:00
return ;
}
2013-11-09 01:32:56 +00:00
if ( callbacks [ 'opening' ] ) {
callbacks [ 'opening' ] ( ) ;
}
2013-11-19 22:06:17 +00:00
var submitted = false ;
2013-11-06 22:30:20 +00:00
var submitToken = function ( token ) {
2013-11-19 22:06:17 +00:00
if ( submitted ) { return ; }
submitted = true ;
2014-04-09 01:10:33 +00:00
if ( Config . MIXPANEL _KEY ) {
mixpanel . track ( 'plan_subscribe' ) ;
}
2013-10-28 21:08:26 +00:00
$scope . $apply ( function ( ) {
2013-11-09 01:32:56 +00:00
if ( callbacks [ 'started' ] ) {
callbacks [ 'started' ] ( ) ;
}
2013-11-15 20:31:05 +00:00
planService . setSubscription ( orgname , planId , callbacks [ 'success' ] , callbacks [ 'failure' ] , token ) ;
2013-10-28 21:08:26 +00:00
} ) ;
} ;
2013-11-01 23:13:58 +00:00
planService . getPlan ( planId , function ( planDetails ) {
2013-11-15 23:17:12 +00:00
var email = planService . getEmail ( orgname ) ;
2013-11-01 23:13:58 +00:00
StripeCheckout . open ( {
key : KeyService . stripePublishableKey ,
address : false ,
2013-11-08 22:50:42 +00:00
email : email ,
2013-11-01 23:13:58 +00:00
amount : planDetails . price ,
currency : 'usd' ,
2014-04-09 00:33:20 +00:00
name : 'Quay.io ' + planDetails . title + ' Subscription' ,
2013-11-01 23:13:58 +00:00
description : 'Up to ' + planDetails . privateRepos + ' private repositories' ,
2014-04-23 17:01:27 +00:00
panelLabel : opt _title || 'Subscribe' ,
2013-11-06 19:55:40 +00:00
token : submitToken ,
2013-11-09 01:32:56 +00:00
image : 'static/img/quay-icon-stripe.png' ,
opened : function ( ) { $scope . $apply ( function ( ) { callbacks [ 'opened' ] ( ) } ) ; } ,
closed : function ( ) { $scope . $apply ( function ( ) { callbacks [ 'closed' ] ( ) } ) ; }
2013-11-01 23:13:58 +00:00
} ) ;
2013-10-28 21:08:26 +00:00
} ) ;
} ;
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 ) {
2014-11-24 21:07:38 +00:00
scope . $watch ( function ( ) {
2013-10-01 23:37:33 +00:00
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 ) ;
} ) ;
} ;
} ) .
2014-08-08 17:50:04 +00:00
config ( [ '$routeProvider' , '$locationProvider' ,
2014-04-09 01:10:33 +00:00
function ( $routeProvider , $locationProvider ) {
2014-08-08 17:50:04 +00:00
var title = window . _ _config [ 'REGISTRY_TITLE' ] || 'Quay.io' ;
2013-10-03 20:16:10 +00:00
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-11-20 21:17:47 +00:00
when ( '/repository/:namespace/:name' , { templateUrl : '/static/partials/view-repo.html' , controller : RepoCtrl ,
2013-12-18 03:56:28 +00:00
fixFooter : false , reloadOnSearch : false } ) .
2013-11-20 21:17:47 +00:00
when ( '/repository/:namespace/:name/tag/:tag' , { templateUrl : '/static/partials/view-repo.html' , controller : RepoCtrl ,
2013-12-18 03:56:28 +00:00
fixFooter : false } ) .
2013-12-17 18:19:59 +00:00
when ( '/repository/:namespace/:name/image/:image' , { templateUrl : '/static/partials/image-view.html' , controller : ImageViewCtrl , reloadOnSearch : false } ) .
when ( '/repository/:namespace/:name/admin' , { templateUrl : '/static/partials/repo-admin.html' , controller : RepoAdminCtrl , reloadOnSearch : false } ) .
2014-02-10 20:15:23 +00:00
when ( '/repository/:namespace/:name/build' , { templateUrl : '/static/partials/repo-build.html' , controller : RepoBuildCtrl , reloadOnSearch : false } ) .
2014-02-17 22:28:20 +00:00
when ( '/repository/:namespace/:name/build/:buildid/buildpack' , { templateUrl : '/static/partials/build-package.html' , controller : BuildPackageCtrl , reloadOnSearch : false } ) .
2013-11-19 00:03:35 +00:00
when ( '/repository/' , { title : 'Repositories' , description : 'Public and private docker repositories list' ,
2014-08-29 19:46:43 +00:00
templateUrl : '/static/partials/repo-list.html' , controller : RepoListCtrl , reloadOnSearch : false } ) .
2014-08-08 17:50:04 +00:00
when ( '/user/' , { title : 'Account Settings' , description : 'Account settings for ' + title , templateUrl : '/static/partials/user-admin.html' ,
2013-12-10 04:33:28 +00:00
reloadOnSearch : false , controller : UserAdminCtrl } ) .
2014-08-08 17:50:04 +00:00
when ( '/superuser/' , { title : 'Superuser Admin Panel' , description : 'Admin panel for ' + title , templateUrl : '/static/partials/super-user.html' ,
2014-04-10 04:26:55 +00:00
reloadOnSearch : false , controller : SuperUserAdminCtrl } ) .
2014-08-08 17:50:04 +00:00
when ( '/guide/' , { title : 'Guide' , description : 'Guide to using private docker repositories on ' + title ,
templateUrl : '/static/partials/guide.html' ,
2013-12-10 04:33:28 +00:00
controller : GuideCtrl } ) .
2014-08-08 17:50:04 +00:00
when ( '/tutorial/' , { title : 'Tutorial' , description : 'Interactive tutorial for using ' + title , templateUrl : '/static/partials/tutorial.html' ,
2014-02-06 02:00:04 +00:00
controller : TutorialCtrl } ) .
2013-12-17 22:02:37 +00:00
when ( '/contact/' , { title : 'Contact Us' , description : 'Different ways for you to get a hold of us when you need us most.' , templateUrl : '/static/partials/contact.html' ,
controller : ContactCtrl } ) .
2014-02-07 00:20:19 +00:00
when ( '/about/' , { title : 'About Us' , description : 'Information about the Quay.io team and the company.' , templateUrl : '/static/partials/about.html' } ) .
2013-11-22 20:54:23 +00:00
when ( '/plans/' , { title : 'Plans and Pricing' , description : 'Plans and pricing for private docker repositories on Quay.io' ,
2013-11-19 00:03:35 +00:00
templateUrl : '/static/partials/plans.html' , controller : PlansCtrl } ) .
2013-11-22 20:54:23 +00:00
when ( '/security/' , { title : 'Security' , description : 'Security features used when transmitting and storing data' ,
2014-02-07 00:20:19 +00:00
templateUrl : '/static/partials/security.html' } ) .
2014-08-18 21:24:00 +00:00
when ( '/signin/' , { title : 'Sign In' , description : 'Sign into ' + title , templateUrl : '/static/partials/signin.html' , controller : SignInCtrl , reloadOnSearch : false } ) .
2013-11-19 00:03:35 +00:00
when ( '/new/' , { title : 'Create new repository' , description : 'Create a new public or private docker repository, optionally constructing from a dockerfile' ,
templateUrl : '/static/partials/new-repo.html' , controller : NewRepoCtrl } ) .
when ( '/organizations/' , { title : 'Organizations' , description : 'Private docker repository hosting for businesses and organizations' ,
templateUrl : '/static/partials/organizations.html' , controller : OrgsCtrl } ) .
2014-08-08 17:50:04 +00:00
when ( '/organizations/new/' , { title : 'New Organization' , description : 'Create a new organization on ' + title ,
2013-11-19 00:03:35 +00:00
templateUrl : '/static/partials/new-organization.html' , controller : NewOrgCtrl } ) .
2013-10-31 22:17:26 +00:00
when ( '/organization/:orgname' , { templateUrl : '/static/partials/org-view.html' , controller : OrgViewCtrl } ) .
2013-12-10 04:33:28 +00:00
when ( '/organization/:orgname/admin' , { templateUrl : '/static/partials/org-admin.html' , controller : OrgAdminCtrl , reloadOnSearch : false } ) .
2013-10-31 22:17:26 +00:00
when ( '/organization/:orgname/teams/:teamname' , { templateUrl : '/static/partials/team-view.html' , controller : TeamViewCtrl } ) .
2013-12-07 00:25:27 +00:00
when ( '/organization/:orgname/logs/:membername' , { templateUrl : '/static/partials/org-member-logs.html' , controller : OrgMemberLogsCtrl } ) .
2014-03-20 19:46:13 +00:00
when ( '/organization/:orgname/application/:clientid' , { templateUrl : '/static/partials/manage-application.html' ,
controller : ManageApplicationCtrl , reloadOnSearch : false } ) .
2013-10-17 21:45:08 +00:00
when ( '/v1/' , { title : 'Activation information' , templateUrl : '/static/partials/v1-page.html' , controller : V1Ctrl } ) .
2014-04-29 04:45:42 +00:00
2014-08-08 17:50:04 +00:00
when ( '/tour/' , { title : title + ' Tour' , templateUrl : '/static/partials/tour.html' , controller : TourCtrl } ) .
2014-04-29 04:45:42 +00:00
when ( '/tour/organizations' , { title : 'Teams and Organizations Tour' , templateUrl : '/static/partials/tour.html' , controller : TourCtrl } ) .
2014-08-08 17:50:04 +00:00
when ( '/tour/features' , { title : title + ' Features' , templateUrl : '/static/partials/tour.html' , controller : TourCtrl } ) .
when ( '/tour/enterprise' , { title : 'Enterprise Edition' , templateUrl : '/static/partials/tour.html' , controller : TourCtrl } ) .
2014-04-29 04:45:42 +00:00
2014-09-11 19:45:41 +00:00
when ( '/confirminvite' , { title : 'Confirm Invite' , templateUrl : '/static/partials/confirm-invite.html' , controller : ConfirmInviteCtrl , reloadOnSearch : false } ) .
2014-08-18 21:24:00 +00:00
2014-04-24 04:40:01 +00:00
when ( '/' , { title : 'Hosted Private Docker Registry' , templateUrl : '/static/partials/landing.html' , controller : LandingCtrl ,
pageClass : 'landing-page' } ) .
2013-10-03 20:16:10 +00:00
otherwise ( { redirectTo : '/' } ) ;
} ] ) .
2013-09-24 22:21:14 +00:00
config ( function ( RestangularProvider ) {
2014-03-15 03:40:41 +00:00
RestangularProvider . setBaseUrl ( '/api/v1/' ) ;
2013-09-26 21:59:20 +00:00
} ) ;
2014-04-09 01:10:33 +00:00
if ( window . _ _config && window . _ _config . MIXPANEL _KEY ) {
quayApp . config ( [ '$analyticsProvider' , function ( $analyticsProvider ) {
2014-11-24 21:07:38 +00:00
$analyticsProvider . virtualPageviews ( true ) ;
2014-04-09 01:10:33 +00:00
} ] ) ;
}
2014-04-28 22:59:22 +00:00
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 } } ) ;
} ;
} ) ;
} ) ;
}
2013-11-05 00:36:56 +00:00
2014-04-05 03:26:10 +00:00
function buildConditionalLinker ( $animate , name , evaluator ) {
// Based off of a solution found here: http://stackoverflow.com/questions/20325480/angularjs-whats-the-best-practice-to-add-ngif-to-a-directive-programmatically
return function ( $scope , $element , $attr , ctrl , $transclude ) {
var block ;
var childScope ;
var roles ;
$attr . $observe ( name , function ( value ) {
if ( evaluator ( $scope . $eval ( value ) ) ) {
if ( ! childScope ) {
childScope = $scope . $new ( ) ;
$transclude ( childScope , function ( clone ) {
block = {
startNode : clone [ 0 ] ,
endNode : clone [ clone . length ++ ] = document . createComment ( ' end ' + name + ': ' + $attr [ name ] + ' ' )
} ;
$animate . enter ( clone , $element . parent ( ) , $element ) ;
} ) ;
}
} else {
if ( childScope ) {
childScope . $destroy ( ) ;
childScope = null ;
}
if ( block ) {
$animate . leave ( getBlockElements ( block ) ) ;
block = null ;
}
}
} ) ;
}
}
quayApp . directive ( 'quayRequire' , function ( $animate , Features ) {
return {
transclude : 'element' ,
priority : 600 ,
terminal : true ,
restrict : 'A' ,
link : buildConditionalLinker ( $animate , 'quayRequire' , function ( value ) {
return Features . matchesFeatures ( value ) ;
} )
} ;
} ) ;
2014-04-08 23:14:24 +00:00
quayApp . directive ( 'quayShow' , function ( $animate , Features , Config ) {
2014-04-05 03:26:10 +00:00
return {
priority : 590 ,
restrict : 'A' ,
link : function ( $scope , $element , $attr , ctrl , $transclude ) {
$scope . Features = Features ;
2014-04-08 23:14:24 +00:00
$scope . Config = Config ;
2014-04-05 03:26:10 +00:00
$scope . $watch ( $attr . quayShow , function ( result ) {
$animate [ ! ! result ? 'removeClass' : 'addClass' ] ( $element , 'ng-hide' ) ;
} ) ;
}
} ;
} ) ;
2014-08-16 01:09:02 +00:00
quayApp . directive ( 'ngIfMedia' , function ( $animate ) {
return {
transclude : 'element' ,
priority : 600 ,
terminal : true ,
restrict : 'A' ,
link : buildConditionalLinker ( $animate , 'ngIfMedia' , function ( value ) {
return window . matchMedia ( value ) . matches ;
} )
} ;
} ) ;
2014-08-12 01:47:04 +00:00
quayApp . directive ( 'quaySection' , function ( $animate , $location , $rootScope ) {
return {
priority : 590 ,
restrict : 'A' ,
link : function ( $scope , $element , $attr , ctrl , $transclude ) {
var update = function ( ) {
var result = $location . path ( ) . indexOf ( '/' + $attr . quaySection ) == 0 ;
$animate [ ! result ? 'removeClass' : 'addClass' ] ( $element , 'active' ) ;
} ;
$scope . $watch ( function ( ) {
return $location . path ( ) ;
} , update ) ;
$scope . $watch ( $attr . quaySection , update ) ;
}
} ;
} ) ;
2014-04-08 23:14:24 +00:00
quayApp . directive ( 'quayClasses' , function ( Features , Config ) {
2014-04-05 03:26:10 +00:00
return {
priority : 580 ,
restrict : 'A' ,
link : function ( $scope , $element , $attr , ctrl , $transclude ) {
2014-11-24 21:07:38 +00:00
2014-04-05 03:26:10 +00:00
// Borrowed from ngClass.
function flattenClasses ( classVal ) {
if ( angular . isArray ( classVal ) ) {
return classVal . join ( ' ' ) ;
} else if ( angular . isObject ( classVal ) ) {
var classes = [ ] , i = 0 ;
angular . forEach ( classVal , function ( v , k ) {
if ( v ) {
classes . push ( k ) ;
}
} ) ;
return classes . join ( ' ' ) ;
}
2014-11-24 21:07:38 +00:00
2014-04-05 03:26:10 +00:00
return classVal ;
}
2014-11-24 21:07:38 +00:00
2014-04-05 03:26:10 +00:00
function removeClass ( classVal ) {
$attr . $removeClass ( flattenClasses ( classVal ) ) ;
}
function addClass ( classVal ) {
$attr . $addClass ( flattenClasses ( classVal ) ) ;
}
$scope . $watch ( $attr . quayClasses , function ( result ) {
2014-04-08 23:14:24 +00:00
var scopeVals = {
'Features' : Features ,
'Config' : Config
} ;
2014-04-05 03:26:10 +00:00
for ( var expr in result ) {
if ( ! result . hasOwnProperty ( expr ) ) { continue ; }
// Evaluate the expression with the entire features list added.
2014-04-08 23:14:24 +00:00
var value = $scope . $eval ( expr , scopeVals ) ;
2014-04-05 03:26:10 +00:00
if ( value ) {
addClass ( result [ expr ] ) ;
} else {
removeClass ( result [ expr ] ) ;
}
}
} ) ;
}
} ;
} ) ;
2014-04-08 23:14:24 +00:00
quayApp . directive ( 'quayInclude' , function ( $compile , $templateCache , $http , Features , Config ) {
2014-04-06 18:48:58 +00:00
return {
priority : 595 ,
restrict : 'A' ,
link : function ( $scope , $element , $attr , ctrl ) {
var getTemplate = function ( templateName ) {
var templateUrl = '/static/partials/' + templateName ;
return $http . get ( templateUrl , { cache : $templateCache } ) ;
} ;
var result = $scope . $eval ( $attr . quayInclude ) ;
if ( ! result ) {
return ;
}
2014-04-08 23:14:24 +00:00
var scopeVals = {
'Features' : Features ,
'Config' : Config
} ;
2014-04-06 18:48:58 +00:00
var templatePath = null ;
for ( var expr in result ) {
if ( ! result . hasOwnProperty ( expr ) ) { continue ; }
// Evaluate the expression with the entire features list added.
2014-04-08 23:14:24 +00:00
var value = $scope . $eval ( expr , scopeVals ) ;
2014-04-06 18:48:58 +00:00
if ( value ) {
templatePath = result [ expr ] ;
break ;
}
}
if ( ! templatePath ) {
return ;
}
2014-11-24 21:07:38 +00:00
2014-04-06 18:48:58 +00:00
var promise = getTemplate ( templatePath ) . success ( function ( html ) {
$element . html ( html ) ;
} ) . then ( function ( response ) {
$element . replaceWith ( $compile ( $element . html ( ) ) ( $scope ) ) ;
if ( $attr . onload ) {
$scope . $eval ( $attr . onload ) ;
}
} ) ;
}
} ;
} ) ;
2013-11-26 19:37:55 +00:00
quayApp . directive ( 'entityReference' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/entity-reference.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
2014-01-21 21:23:00 +00:00
'entity' : '=entity' ,
2014-08-16 00:51:31 +00:00
'namespace' : '=namespace' ,
2014-11-25 00:25:13 +00:00
'showAvatar' : '@showAvatar' ,
'avatarSize' : '@avatarSize'
2013-11-26 19:37:55 +00:00
} ,
2014-05-01 17:59:25 +00:00
controller : function ( $scope , $element , UserService , UtilService ) {
2014-01-21 21:23:00 +00:00
$scope . getIsAdmin = function ( namespace ) {
return UserService . isNamespaceAdmin ( namespace ) ;
2013-12-10 20:22:22 +00:00
} ;
2014-02-25 17:32:56 +00:00
$scope . getRobotUrl = function ( name ) {
var namespace = $scope . getPrefix ( name ) ;
if ( ! namespace ) {
return '' ;
}
if ( ! $scope . getIsAdmin ( namespace ) ) {
return '' ;
}
var org = UserService . getOrganization ( namespace ) ;
if ( ! org ) {
// This robot is owned by the user.
2014-05-01 17:59:25 +00:00
return '/user/?tab=robots&showRobot=' + UtilService . textToSafeHtml ( name ) ;
2014-02-25 17:32:56 +00:00
}
2014-05-01 17:59:25 +00:00
return '/organization/' + org [ 'name' ] + '/admin?tab=robots&showRobot=' + UtilService . textToSafeHtml ( name ) ;
2014-02-25 17:32:56 +00:00
} ;
2013-11-26 19:37:55 +00:00
$scope . getPrefix = function ( name ) {
if ( ! name ) { return '' ; }
var plus = name . indexOf ( '+' ) ;
2014-02-25 17:32:56 +00:00
return name . substr ( 0 , plus ) ;
2013-11-26 19:37:55 +00:00
} ;
$scope . getShortenedName = function ( name ) {
if ( ! name ) { return '' ; }
var plus = name . indexOf ( '+' ) ;
return name . substr ( plus + 1 ) ;
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-03-20 16:06:29 +00:00
quayApp . directive ( 'applicationInfo' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/application-info.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'application' : '=application'
} ,
controller : function ( $scope , $element , ApiService ) {
2014-11-24 21:07:38 +00:00
2014-03-20 16:06:29 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-03-18 20:45:18 +00:00
quayApp . directive ( 'applicationReference' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/application-reference.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'title' : '=title' ,
'clientId' : '=clientId'
} ,
controller : function ( $scope , $element , ApiService , $modal ) {
$scope . showAppDetails = function ( ) {
var params = {
'client_id' : $scope . clientId
} ;
ApiService . getApplicationInformation ( null , params ) . then ( function ( resp ) {
2014-03-20 16:06:29 +00:00
$scope . applicationInfo = resp ;
$modal ( {
title : 'Application Information' ,
scope : $scope ,
template : '/static/directives/application-reference-dialog.html' ,
show : true
} ) ;
2014-08-18 22:21:53 +00:00
} , ApiService . errorDisplay ( 'Application could not be found' ) ) ;
2014-03-18 20:45:18 +00:00
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-05 00:36:56 +00:00
quayApp . directive ( 'markdownView' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/markdown-view.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'content' : '=content' ,
'firstLineOnly' : '=firstLineOnly'
} ,
2013-11-19 00:03:35 +00:00
controller : function ( $scope , $element , $sce ) {
2013-11-05 00:36:56 +00:00
$scope . getMarkedDown = function ( content , firstLineOnly ) {
if ( firstLineOnly ) {
content = getFirstTextLine ( content ) ;
}
2013-11-19 00:03:35 +00:00
return $sce . trustAsHtml ( getMarkedDown ( content ) ) ;
2013-11-05 00:36:56 +00:00
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-01-31 18:52:35 +00:00
quayApp . directive ( 'repoBreadcrumb' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/repo-breadcrumb.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'repo' : '=repo' ,
2014-02-13 23:58:28 +00:00
'image' : '=image' ,
'subsection' : '=subsection' ,
'subsectionIcon' : '=subsectionIcon'
2014-01-31 18:52:35 +00:00
} ,
2014-11-24 21:07:38 +00:00
controller : function ( $scope , $element ) {
2014-01-31 18:52:35 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-09-11 19:45:41 +00:00
quayApp . directive ( 'focusablePopoverContent' , [ '$timeout' , '$popover' , function ( $timeout , $popover ) {
return {
restrict : "A" ,
link : function ( scope , element , attrs ) {
$body = $ ( 'body' ) ;
var hide = function ( ) {
$body . off ( 'click' ) ;
2014-11-10 16:37:52 +00:00
2014-11-24 21:07:38 +00:00
if ( ! scope ) { return ; }
2014-09-11 19:45:41 +00:00
scope . $apply ( function ( ) {
2015-01-12 17:37:01 +00:00
if ( ! scope || ! $scope . $hide ) { return ; }
2014-09-11 19:45:41 +00:00
scope . $hide ( ) ;
} ) ;
} ;
scope . $on ( '$destroy' , function ( ) {
2014-11-24 21:07:38 +00:00
$body . off ( 'click' ) ;
2014-09-11 19:45:41 +00:00
} ) ;
$timeout ( function ( ) {
$body . on ( 'click' , function ( evt ) {
var target = evt . target ;
var isPanelMember = $ ( element ) . has ( target ) . length > 0 || target == element ;
if ( ! isPanelMember ) {
hide ( ) ;
}
} ) ;
$ ( element ) . find ( 'input' ) . focus ( ) ;
} , 100 ) ;
}
} ;
} ] ) ;
2014-01-31 18:52:35 +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 ;
} ) ;
2014-02-28 21:23:36 +00:00
quayApp . directive ( 'copyBox' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/copy-box.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'value' : '=value' ,
2014-09-18 19:56:59 +00:00
'hoveringMessage' : '=hoveringMessage' ,
2014-02-28 21:23:36 +00:00
} ,
controller : function ( $scope , $element , $rootScope ) {
2014-08-22 19:24:56 +00:00
$scope . disabled = false ;
2014-02-28 21:23:36 +00:00
var number = $rootScope . _ _copyBoxIdCounter || 0 ;
$rootScope . _ _copyBoxIdCounter = number + 1 ;
$scope . inputId = "copy-box-input-" + number ;
2014-11-24 21:07:38 +00:00
2014-09-18 19:56:59 +00:00
var button = $ ( $element ) . find ( '.copy-icon' ) ;
2014-02-28 21:23:36 +00:00
var input = $ ( $element ) . find ( 'input' ) ;
input . attr ( 'id' , $scope . inputId ) ;
button . attr ( 'data-clipboard-target' , $scope . inputId ) ;
2014-08-22 19:24:56 +00:00
$scope . disabled = ! button . clipboardCopy ( ) ;
2014-02-28 21:23:36 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-12-11 23:20:24 +00:00
quayApp . directive ( 'userSetup' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/user-setup.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
'redirectUrl' : '=redirectUrl' ,
2014-09-11 19:45:41 +00:00
'inviteCode' : '=inviteCode' ,
2013-12-11 23:20:24 +00:00
'signInStarted' : '&signInStarted' ,
2014-09-11 19:45:41 +00:00
'signedIn' : '&signedIn' ,
'userRegistered' : '&userRegistered'
2013-12-11 23:20:24 +00:00
} ,
2013-12-26 22:45:16 +00:00
controller : function ( $scope , $location , $timeout , ApiService , KeyService , UserService ) {
2013-12-11 23:20:24 +00:00
$scope . sendRecovery = function ( ) {
2014-09-22 23:11:48 +00:00
$scope . sendingRecovery = true ;
2013-12-26 22:45:16 +00:00
ApiService . requestRecoveryEmail ( $scope . recovery ) . then ( function ( ) {
2014-01-10 18:30:17 +00:00
$scope . invalidRecovery = false ;
$scope . errorMessage = '' ;
2013-12-11 23:20:24 +00:00
$scope . sent = true ;
2014-09-22 23:11:48 +00:00
$scope . sendingRecovery = false ;
2014-10-28 16:10:44 +00:00
} , function ( resp ) {
2014-01-10 18:30:17 +00:00
$scope . invalidRecovery = true ;
2014-10-28 16:10:44 +00:00
$scope . errorMessage = ApiService . getErrorMessage ( resp , 'Cannot send recovery email' ) ;
2013-12-11 23:20:24 +00:00
$scope . sent = false ;
2014-09-22 23:11:48 +00:00
$scope . sendingRecovery = false ;
2013-12-11 23:20:24 +00:00
} ) ;
} ;
2013-12-11 23:27:35 +00:00
2014-09-11 19:45:41 +00:00
$scope . handleUserRegistered = function ( username ) {
$scope . userRegistered ( { 'username' : username } ) ;
} ;
2013-12-11 23:27:35 +00:00
$scope . hasSignedIn = function ( ) {
return UserService . hasEverLoggedIn ( ) ;
} ;
2013-12-11 23:20:24 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-08-11 19:47:44 +00:00
quayApp . directive ( 'externalLoginButton' , function ( ) {
2013-11-07 20:19:52 +00:00
var directiveDefinitionObject = {
priority : 0 ,
2014-08-11 19:47:44 +00:00
templateUrl : '/static/directives/external-login-button.html' ,
2013-11-07 20:19:52 +00:00
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
2013-12-11 22:50:48 +00:00
'signInStarted' : '&signInStarted' ,
2014-08-11 19:47:44 +00:00
'redirectUrl' : '=redirectUrl' ,
'provider' : '@provider' ,
'action' : '@action'
2013-11-07 20:19:52 +00:00
} ,
2014-09-04 22:08:18 +00:00
controller : function ( $scope , $timeout , $interval , ApiService , KeyService , CookieService , Features , Config ) {
2014-09-16 04:23:56 +00:00
$scope . signingIn = false ;
2014-11-05 21:43:37 +00:00
$scope . isEnterprise = KeyService . isEnterprise ;
2014-08-11 19:47:44 +00:00
$scope . startSignin = function ( service ) {
$scope . signInStarted ( { 'service' : service } ) ;
2013-12-11 22:50:48 +00:00
2014-08-11 19:47:44 +00:00
var url = KeyService . getExternalLoginUrl ( service , $scope . action || 'login' ) ;
2014-11-24 21:07:38 +00:00
2014-08-11 19:47:44 +00:00
// Save the redirect URL in a cookie so that we can redirect back after the service returns to us.
2014-09-16 04:23:56 +00:00
var redirectURL = $scope . redirectUrl || window . location . toString ( ) ;
2014-03-19 18:27:33 +00:00
CookieService . putPermanent ( 'quay.redirectAfterLoad' , redirectURL ) ;
2014-08-11 19:47:44 +00:00
2013-12-11 22:50:48 +00:00
// Needed to ensure that UI work done by the started callback is finished before the location
// changes.
2014-09-16 04:23:56 +00:00
$scope . signingIn = true ;
2013-12-11 22:50:48 +00:00
$timeout ( function ( ) {
document . location = url ;
} , 250 ) ;
2013-11-07 20:19:52 +00:00
} ;
2014-08-11 19:47:44 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-07 20:19:52 +00:00
2014-08-11 19:47:44 +00:00
quayApp . directive ( 'signinForm' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/signin-form.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
'redirectUrl' : '=redirectUrl' ,
'signInStarted' : '&signInStarted' ,
'signedIn' : '&signedIn'
} ,
2014-09-04 22:08:18 +00:00
controller : function ( $scope , $location , $timeout , $interval , ApiService , KeyService , UserService , CookieService , Features , Config ) {
$scope . tryAgainSoon = 0 ;
$scope . tryAgainInterval = null ;
2014-09-16 04:23:56 +00:00
$scope . signingIn = false ;
2013-11-07 20:19:52 +00:00
2013-12-11 22:50:48 +00:00
$scope . markStarted = function ( ) {
2014-09-16 04:23:56 +00:00
$scope . signingIn = true ;
2013-12-11 22:50:48 +00:00
if ( $scope . signInStarted != null ) {
$scope . signInStarted ( ) ;
}
} ;
2013-11-07 20:19:52 +00:00
2014-09-03 16:10:36 +00:00
$scope . cancelInterval = function ( ) {
2014-09-02 19:28:56 +00:00
$scope . tryAgainSoon = 0 ;
if ( $scope . tryAgainInterval ) {
$interval . cancel ( $scope . tryAgainInterval ) ;
}
2014-09-03 16:10:36 +00:00
$scope . tryAgainInterval = null ;
} ;
$scope . $watch ( 'user.username' , function ( ) {
$scope . cancelInterval ( ) ;
2014-09-02 19:28:56 +00:00
} ) ;
2014-09-02 18:26:35 +00:00
$scope . $on ( '$destroy' , function ( ) {
2014-09-03 16:10:36 +00:00
$scope . cancelInterval ( ) ;
2014-09-02 18:26:35 +00:00
} ) ;
2013-11-07 20:19:52 +00:00
$scope . signin = function ( ) {
2014-09-02 18:26:35 +00:00
if ( $scope . tryAgainSoon > 0 ) { return ; }
2013-12-11 22:50:48 +00:00
$scope . markStarted ( ) ;
2014-09-03 16:10:36 +00:00
$scope . cancelInterval ( ) ;
2013-12-11 22:50:48 +00:00
2013-12-26 22:45:16 +00:00
ApiService . signinUser ( $scope . user ) . then ( function ( ) {
2014-09-16 04:23:56 +00:00
$scope . signingIn = false ;
2013-11-07 20:19:52 +00:00
$scope . needsEmailVerification = false ;
$scope . invalidCredentials = false ;
2013-12-11 22:50:48 +00:00
if ( $scope . signedIn != null ) {
$scope . signedIn ( ) ;
}
2014-08-18 21:24:00 +00:00
// Load the newly created user.
2013-11-07 20:19:52 +00:00
UserService . load ( ) ;
2013-12-11 22:50:48 +00:00
// Redirect to the specified page or the landing page
// Note: The timeout of 500ms is needed to ensure dialogs containing sign in
// forms get removed before the location changes.
$timeout ( function ( ) {
2014-09-16 04:23:56 +00:00
var redirectUrl = $scope . redirectUrl ;
2014-09-08 21:20:01 +00:00
if ( redirectUrl == $location . path ( ) || redirectUrl == null ) {
2014-08-18 21:24:00 +00:00
return ;
}
window . location = ( redirectUrl ? redirectUrl : '/' ) ;
2013-12-11 22:50:48 +00:00
} , 500 ) ;
2013-11-07 20:19:52 +00:00
} , function ( result ) {
2014-09-16 04:23:56 +00:00
$scope . signingIn = false ;
2014-09-02 18:26:35 +00:00
if ( result . status == 429 /* try again later */ ) {
2014-09-03 16:10:36 +00:00
$scope . needsEmailVerification = false ;
$scope . invalidCredentials = false ;
2014-09-02 18:26:35 +00:00
2014-09-03 16:10:36 +00:00
$scope . cancelInterval ( ) ;
2014-09-02 18:26:35 +00:00
2014-09-03 16:10:36 +00:00
$scope . tryAgainSoon = result . headers ( 'Retry-After' ) ;
2014-11-24 21:07:38 +00:00
$scope . tryAgainInterval = $interval ( function ( ) {
2014-09-02 18:26:35 +00:00
$scope . tryAgainSoon -- ;
if ( $scope . tryAgainSoon <= 0 ) {
2014-09-03 16:10:36 +00:00
$scope . cancelInterval ( ) ;
2014-09-02 18:26:35 +00:00
}
} , 1000 , $scope . tryAgainSoon ) ;
} else {
$scope . needsEmailVerification = result . data . needsEmailVerification ;
$scope . invalidCredentials = result . data . invalidCredentials ;
}
2013-11-07 20:19:52 +00:00
} ) ;
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-12-11 21:50:10 +00:00
quayApp . directive ( 'signupForm' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/signup-form.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
2014-09-11 19:45:41 +00:00
'inviteCode' : '=inviteCode' ,
2013-12-11 21:50:10 +00:00
2014-09-11 19:45:41 +00:00
'userRegistered' : '&userRegistered'
2013-12-11 21:50:10 +00:00
} ,
2014-11-24 21:07:38 +00:00
controller : function ( $scope , $location , $timeout , ApiService , KeyService , UserService , Config , UIService ) {
2013-12-11 21:50:10 +00:00
$ ( '.form-signup' ) . popover ( ) ;
2014-11-24 21:07:38 +00:00
$scope . awaitingConfirmation = false ;
2013-12-11 21:50:10 +00:00
$scope . registering = false ;
2014-04-07 22:55:39 +00:00
2013-12-11 21:50:10 +00:00
$scope . register = function ( ) {
2014-04-07 22:55:39 +00:00
UIService . hidePopover ( '#signupButton' ) ;
2013-12-11 21:50:10 +00:00
$scope . registering = true ;
2014-09-11 19:45:41 +00:00
if ( $scope . inviteCode ) {
2014-10-03 19:05:34 +00:00
$scope . newUser [ 'invite_code' ] = $scope . inviteCode ;
2014-09-11 19:45:41 +00:00
}
2014-09-22 23:11:48 +00:00
ApiService . createNewUser ( $scope . newUser ) . then ( function ( resp ) {
2013-12-11 21:50:10 +00:00
$scope . registering = false ;
2014-09-22 23:11:48 +00:00
$scope . awaitingConfirmation = ! ! resp [ 'awaiting_verification' ] ;
2014-11-24 21:07:38 +00:00
2014-04-09 01:10:33 +00:00
if ( Config . MIXPANEL _KEY ) {
mixpanel . alias ( $scope . newUser . username ) ;
}
2014-09-11 19:45:41 +00:00
$scope . userRegistered ( { 'username' : $scope . newUser . username } ) ;
2014-09-22 23:11:48 +00:00
if ( ! $scope . awaitingConfirmation ) {
document . location = '/' ;
}
2013-12-11 21:50:10 +00:00
} , function ( result ) {
$scope . registering = false ;
2014-04-07 22:55:39 +00:00
UIService . showFormError ( '#signupButton' , result ) ;
2013-12-11 21:50:10 +00:00
} ) ;
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-04-29 04:45:42 +00:00
quayApp . directive ( 'tourContent' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/tour-content.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'kind' : '=kind'
} ,
controller : function ( $scope , $element , $timeout , UserService ) {
// Monitor any user changes and place the current user into the scope.
UserService . updateUserIn ( $scope ) ;
$scope . chromify = function ( ) {
browserchrome . update ( ) ;
} ;
$scope . $watch ( 'kind' , function ( kind ) {
2014-05-07 17:37:13 +00:00
$timeout ( function ( ) {
$scope . chromify ( ) ;
} ) ;
2014-04-29 04:45:42 +00:00
} ) ;
} ,
link : function ( $scope , $element , $attr , ctrl ) {
$scope . chromify ( ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-08 03:08:23 +00:00
quayApp . directive ( 'plansTable' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/plans-table.html' ,
replace : false ,
2013-11-23 01:14:44 +00:00
transclude : false ,
2013-11-08 03:08:23 +00:00
restrict : 'C' ,
scope : {
'plans' : '=plans' ,
'currentPlan' : '=currentPlan'
} ,
controller : function ( $scope , $element ) {
$scope . setPlan = function ( plan ) {
$scope . currentPlan = plan ;
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-04-09 00:33:20 +00:00
quayApp . directive ( 'dockerAuthDialog' , function ( Config ) {
2013-11-23 01:14:44 +00:00
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/docker-auth-dialog.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
'username' : '=username' ,
'token' : '=token' ,
'shown' : '=shown' ,
2014-08-25 21:19:23 +00:00
'counter' : '=counter' ,
'supportsRegenerate' : '@supportsRegenerate' ,
'regenerate' : '®enerate'
2013-11-23 01:14:44 +00:00
} ,
2014-08-22 20:54:53 +00:00
controller : function ( $scope , $element ) {
var updateCommand = function ( ) {
2014-09-02 20:45:25 +00:00
var escape = function ( v ) {
2014-09-03 19:35:29 +00:00
if ( ! v ) { return v ; }
2014-09-02 20:45:25 +00:00
return v . replace ( '$' , '\\$' ) ;
} ;
$scope . command = 'docker login -e="." -u="' + escape ( $scope . username ) +
2014-08-22 20:54:53 +00:00
'" -p="' + $scope . token + '" ' + Config [ 'SERVER_HOSTNAME' ] ;
} ;
$scope . $watch ( 'username' , updateCommand ) ;
$scope . $watch ( 'token' , updateCommand ) ;
2014-08-25 21:19:23 +00:00
$scope . regenerating = true ;
$scope . askRegenerate = function ( ) {
bootbox . confirm ( 'Are you sure you want to regenerate the token? All existing login credentials will become invalid' , function ( resp ) {
2014-08-27 17:04:31 +00:00
if ( resp ) {
$scope . regenerating = true ;
$scope . regenerate ( { 'username' : $scope . username , 'token' : $scope . token } ) ;
}
2014-08-25 21:19:23 +00:00
} ) ;
} ;
2013-11-23 01:14:44 +00:00
$scope . isDownloadSupported = function ( ) {
2014-08-22 19:24:56 +00:00
var isSafari = /^((?!chrome).)*safari/i . test ( navigator . userAgent ) ;
if ( isSafari ) {
// Doesn't work properly in Safari, sadly.
return false ;
}
try { return ! ! new Blob ( ) ; } catch ( e ) { }
2013-11-23 01:14:44 +00:00
return false ;
} ;
$scope . downloadCfg = function ( ) {
var auth = $ . base64 . encode ( $scope . username + ":" + $scope . token ) ;
2014-04-09 00:33:20 +00:00
config = { }
2014-09-17 22:20:44 +00:00
config [ Config [ 'SERVER_HOSTNAME' ] ] = {
2014-04-09 00:33:20 +00:00
"auth" : auth ,
"email" : ""
2013-11-23 01:14:44 +00:00
} ;
var file = JSON . stringify ( config , null , ' ' ) ;
var blob = new Blob ( [ file ] ) ;
saveAs ( blob , '.dockercfg' ) ;
} ;
var show = function ( r ) {
2014-08-25 21:19:23 +00:00
$scope . regenerating = false ;
2013-11-23 01:14:44 +00:00
if ( ! $scope . shown || ! $scope . username || ! $scope . token ) {
$ ( '#dockerauthmodal' ) . modal ( 'hide' ) ;
return ;
}
2014-11-24 21:07:38 +00:00
2013-11-23 01:14:44 +00:00
$ ( '#copyClipboard' ) . clipboardCopy ( ) ;
$ ( '#dockerauthmodal' ) . modal ( { } ) ;
} ;
$scope . $watch ( 'counter' , show ) ;
$scope . $watch ( 'shown' , show ) ;
$scope . $watch ( 'username' , show ) ;
$scope . $watch ( 'token' , show ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-22 23:20:51 +00:00
2014-10-14 19:46:35 +00:00
quayApp . filter ( 'regex' , function ( ) {
return function ( input , regex ) {
if ( ! regex ) { return [ ] ; }
try {
var patt = new RegExp ( regex ) ;
} catch ( ex ) {
return [ ] ;
}
var out = [ ] ;
for ( var i = 0 ; i < input . length ; ++ i ) {
var m = input [ i ] . match ( patt ) ;
if ( m && m [ 0 ] . length == input [ i ] . length ) {
out . push ( input [ i ] ) ;
}
2014-11-24 21:07:38 +00:00
}
2014-10-14 19:46:35 +00:00
return out ;
} ;
} ) ;
2014-02-14 23:46:20 +00:00
quayApp . filter ( 'reverse' , function ( ) {
return function ( items ) {
return items . slice ( ) . reverse ( ) ;
} ;
} ) ;
2014-01-03 21:32:00 +00:00
quayApp . filter ( 'bytes' , function ( ) {
return function ( bytes , precision ) {
2014-01-03 21:42:38 +00:00
if ( ! bytes || isNaN ( parseFloat ( bytes ) ) || ! isFinite ( bytes ) ) return 'Unknown' ;
2014-01-03 21:32:00 +00:00
if ( typeof precision === 'undefined' ) precision = 1 ;
var units = [ 'bytes' , 'kB' , 'MB' , 'GB' , 'TB' , 'PB' ] ,
number = Math . floor ( Math . log ( bytes ) / Math . log ( 1024 ) ) ;
return ( bytes / Math . pow ( 1024 , Math . floor ( number ) ) ) . toFixed ( precision ) + ' ' + units [ number ] ;
}
} ) ;
2013-11-27 07:29:31 +00:00
quayApp . filter ( 'visibleLogFilter' , function ( ) {
return function ( logs , allowed ) {
if ( ! allowed ) {
return logs ;
}
2014-11-24 21:07:38 +00:00
2013-11-27 07:29:31 +00:00
var filtered = [ ] ;
angular . forEach ( logs , function ( log ) {
if ( allowed [ log . kind ] ) {
filtered . push ( log ) ;
}
} ) ;
return filtered ;
} ;
} ) ;
2013-12-21 03:38:53 +00:00
quayApp . directive ( 'billingInvoices' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/billing-invoices.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'organization' : '=organization' ,
'user' : '=user' ,
2014-07-15 18:17:57 +00:00
'makevisible' : '=makevisible'
2013-12-21 03:38:53 +00:00
} ,
2013-12-26 22:45:16 +00:00
controller : function ( $scope , $element , $sce , ApiService ) {
2013-12-21 03:38:53 +00:00
$scope . loading = false ;
$scope . invoiceExpanded = { } ;
$scope . toggleInvoice = function ( id ) {
$scope . invoiceExpanded [ id ] = ! $scope . invoiceExpanded [ id ] ;
} ;
var update = function ( ) {
var hasValidUser = ! ! $scope . user ;
var hasValidOrg = ! ! $scope . organization ;
var isValid = hasValidUser || hasValidOrg ;
2014-07-15 18:17:57 +00:00
if ( ! $scope . makevisible || ! isValid ) {
2013-12-21 03:38:53 +00:00
return ;
}
2014-11-24 21:07:38 +00:00
2013-12-21 03:38:53 +00:00
$scope . loading = true ;
2013-12-26 22:45:16 +00:00
ApiService . listInvoices ( $scope . organization ) . then ( function ( resp ) {
2013-12-21 03:38:53 +00:00
$scope . invoices = resp . invoices ;
$scope . loading = false ;
} ) ;
} ;
$scope . $watch ( 'organization' , update ) ;
$scope . $watch ( 'user' , update ) ;
2014-07-15 18:17:57 +00:00
$scope . $watch ( 'makevisible' , update ) ;
2013-12-21 03:38:53 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-27 07:29:31 +00:00
quayApp . directive ( 'logsView' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/logs-view.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'organization' : '=organization' ,
'user' : '=user' ,
2014-07-15 18:17:57 +00:00
'makevisible' : '=makevisible' ,
2013-12-07 00:25:27 +00:00
'repository' : '=repository' ,
2014-10-01 17:55:09 +00:00
'performer' : '=performer' ,
'allLogs' : '@allLogs'
2013-11-27 07:29:31 +00:00
} ,
2014-09-30 20:29:32 +00:00
controller : function ( $scope , $element , $sce , Restangular , ApiService , TriggerService ,
2014-07-18 02:51:58 +00:00
StringBuilderService , ExternalNotificationData ) {
2013-11-27 07:29:31 +00:00
$scope . loading = true ;
$scope . logs = null ;
$scope . kindsAllowed = null ;
$scope . chartVisible = true ;
2013-12-06 20:59:59 +00:00
$scope . logsPath = '' ;
2014-11-24 21:07:38 +00:00
2013-12-09 22:28:23 +00:00
var datetime = new Date ( ) ;
$scope . logStartDate = new Date ( datetime . getUTCFullYear ( ) , datetime . getUTCMonth ( ) , datetime . getUTCDate ( ) - 7 ) ;
$scope . logEndDate = new Date ( datetime . getUTCFullYear ( ) , datetime . getUTCMonth ( ) , datetime . getUTCDate ( ) ) ;
2014-01-21 23:39:42 +00:00
var defaultPermSuffix = function ( metadata ) {
if ( metadata . activating _username ) {
return ', when creating user is {activating_username}' ;
}
return '' ;
} ;
2013-11-29 05:04:50 +00:00
var logDescriptions = {
'account_change_plan' : 'Change plan' ,
'account_change_cc' : 'Update credit card' ,
'account_change_password' : 'Change password' ,
'account_convert' : 'Convert account to organization' ,
'create_robot' : 'Create Robot Account: {robot}' ,
'delete_robot' : 'Delete Robot Account: {robot}' ,
'create_repo' : 'Create Repository: {repo}' ,
'push_repo' : 'Push to repository: {repo}' ,
2014-10-29 19:42:44 +00:00
'repo_verb' : function ( metadata ) {
var prefix = '' ;
if ( metadata . verb == 'squash' ) {
prefix = 'Pull of squashed tag {tag}'
}
if ( metadata . token ) {
prefix += ' via token {token}' ;
} else if ( metadata . username ) {
prefix += ' by {username}' ;
} else {
prefix += ' by {_ip}' ;
}
return prefix ;
} ,
2013-11-29 05:04:50 +00:00
'pull_repo' : function ( metadata ) {
2013-12-02 19:55:04 +00:00
if ( metadata . token ) {
return 'Pull repository {repo} via token {token}' ;
} else if ( metadata . username ) {
return 'Pull repository {repo} by {username}' ;
} else {
return 'Public pull of repository {repo} by {_ip}' ;
}
2013-11-29 05:04:50 +00:00
} ,
'delete_repo' : 'Delete repository: {repo}' ,
2013-12-02 19:55:04 +00:00
'change_repo_permission' : function ( metadata ) {
if ( metadata . username ) {
return 'Change permission for user {username} in repository {repo} to {role}' ;
} else if ( metadata . team ) {
return 'Change permission for team {team} in repository {repo} to {role}' ;
} else if ( metadata . token ) {
return 'Change permission for token {token} in repository {repo} to {role}' ;
}
} ,
'delete_repo_permission' : function ( metadata ) {
if ( metadata . username ) {
return 'Remove permission for user {username} from repository {repo}' ;
} else if ( metadata . team ) {
return 'Remove permission for team {team} from repository {repo}' ;
} else if ( metadata . token ) {
return 'Remove permission for token {token} from repository {repo}' ;
}
} ,
2014-01-21 22:04:00 +00:00
'delete_tag' : 'Tag {tag} deleted in repository {repo} by user {username}' ,
2014-02-28 05:12:09 +00:00
'create_tag' : 'Tag {tag} created in repository {repo} on image {image} by user {username}' ,
'move_tag' : 'Tag {tag} moved from image {original_image} to image {image} in repository {repo} by user {username}' ,
2013-11-29 05:04:50 +00:00
'change_repo_visibility' : 'Change visibility for repository {repo} to {visibility}' ,
'add_repo_accesstoken' : 'Create access token {token} in repository {repo}' ,
'delete_repo_accesstoken' : 'Delete access token {token} in repository {repo}' ,
'set_repo_description' : 'Change description for repository {repo}: {description}' ,
2014-02-25 23:22:55 +00:00
'build_dockerfile' : function ( metadata ) {
if ( metadata . trigger _id ) {
2014-09-30 20:29:32 +00:00
var triggerDescription = TriggerService . getDescription (
2014-02-25 23:22:55 +00:00
metadata [ 'service' ] , metadata [ 'config' ] ) ;
return 'Build image from Dockerfile for repository {repo} triggered by ' + triggerDescription ;
}
return 'Build image from Dockerfile for repository {repo}' ;
} ,
2013-11-29 05:04:50 +00:00
'org_create_team' : 'Create team: {team}' ,
'org_delete_team' : 'Delete team: {team}' ,
'org_add_team_member' : 'Add member {member} to team {team}' ,
'org_remove_team_member' : 'Remove member {member} from team {team}' ,
2014-09-08 21:20:01 +00:00
'org_invite_team_member' : function ( metadata ) {
if ( metadata . user ) {
return 'Invite {user} to team {team}' ;
} else {
return 'Invite {email} to team {team}' ;
}
} ,
'org_delete_team_member_invite' : function ( metadata ) {
if ( metadata . user ) {
return 'Rescind invite of {user} to team {team}' ;
} else {
return 'Rescind invite of {email} to team {team}' ;
}
} ,
2014-08-18 21:24:00 +00:00
2014-08-28 23:07:22 +00:00
'org_team_member_invite_accepted' : 'User {member}, invited by {inviter}, joined team {team}' ,
2014-08-18 21:24:00 +00:00
'org_team_member_invite_declined' : 'User {member}, invited by {inviter}, declined to join team {team}' ,
2013-11-29 05:04:50 +00:00
'org_set_team_description' : 'Change description of team {team}: {description}' ,
2014-01-21 22:04:00 +00:00
'org_set_team_role' : 'Change permission of team {team} to {role}' ,
'create_prototype_permission' : function ( metadata ) {
if ( metadata . delegate _user ) {
2014-01-21 23:39:42 +00:00
return 'Create default permission: {role} for {delegate_user}' + defaultPermSuffix ( metadata ) ;
2014-01-21 22:04:00 +00:00
} else if ( metadata . delegate _team ) {
2014-01-21 23:39:42 +00:00
return 'Create default permission: {role} for {delegate_team}' + defaultPermSuffix ( metadata ) ;
2014-01-21 22:04:00 +00:00
}
} ,
2014-11-24 21:07:38 +00:00
'modify_prototype_permission' : function ( metadata ) {
2014-01-21 22:04:00 +00:00
if ( metadata . delegate _user ) {
2014-01-21 23:39:42 +00:00
return 'Modify default permission: {role} (from {original_role}) for {delegate_user}' + defaultPermSuffix ( metadata ) ;
2014-01-21 22:04:00 +00:00
} else if ( metadata . delegate _team ) {
2014-01-21 23:39:42 +00:00
return 'Modify default permission: {role} (from {original_role}) for {delegate_team}' + defaultPermSuffix ( metadata ) ;
2014-01-21 22:04:00 +00:00
}
} ,
'delete_prototype_permission' : function ( metadata ) {
if ( metadata . delegate _user ) {
2014-01-21 23:39:42 +00:00
return 'Delete default permission: {role} for {delegate_user}' + defaultPermSuffix ( metadata ) ;
2014-01-21 22:04:00 +00:00
} else if ( metadata . delegate _team ) {
2014-01-21 23:39:42 +00:00
return 'Delete default permission: {role} for {delegate_team}' + defaultPermSuffix ( metadata ) ;
2014-01-21 22:04:00 +00:00
}
2014-02-25 23:22:55 +00:00
} ,
'setup_repo_trigger' : function ( metadata ) {
2014-09-30 20:29:32 +00:00
var triggerDescription = TriggerService . getDescription (
2014-02-25 23:22:55 +00:00
metadata [ 'service' ] , metadata [ 'config' ] ) ;
return 'Setup build trigger - ' + triggerDescription ;
} ,
'delete_repo_trigger' : function ( metadata ) {
2014-09-30 20:29:32 +00:00
var triggerDescription = TriggerService . getDescription (
2014-02-25 23:22:55 +00:00
metadata [ 'service' ] , metadata [ 'config' ] ) ;
return 'Delete build trigger - ' + triggerDescription ;
2014-03-20 19:46:13 +00:00
} ,
'create_application' : 'Create application {application_name} with client ID {client_id}' ,
'update_application' : 'Update application to {application_name} for client ID {client_id}' ,
'delete_application' : 'Delete application {application_name} with client ID {client_id}' ,
'reset_application_client_secret' : 'Reset the Client Secret of application {application_name} ' +
2014-07-18 02:51:58 +00:00
'with client ID {client_id}' ,
'add_repo_notification' : function ( metadata ) {
var eventData = ExternalNotificationData . getEventInfo ( metadata . event ) ;
return 'Add notification of event "' + eventData [ 'title' ] + '" for repository {repo}' ;
} ,
'delete_repo_notification' : function ( metadata ) {
var eventData = ExternalNotificationData . getEventInfo ( metadata . event ) ;
return 'Delete notification of event "' + eventData [ 'title' ] + '" for repository {repo}' ;
} ,
2014-08-25 21:19:23 +00:00
'regenerate_robot_token' : 'Regenerated token for robot {robot}' ,
2014-07-18 02:51:58 +00:00
// Note: These are deprecated.
'add_repo_webhook' : 'Add webhook in repository {repo}' ,
'delete_repo_webhook' : 'Delete webhook in repository {repo}'
2013-11-29 05:04:50 +00:00
} ;
2013-11-27 07:29:31 +00:00
var logKinds = {
2014-02-25 23:22:55 +00:00
'account_change_plan' : 'Change plan' ,
'account_change_cc' : 'Update credit card' ,
'account_change_password' : 'Change password' ,
'account_convert' : 'Convert account to organization' ,
'create_robot' : 'Create Robot Account' ,
'delete_robot' : 'Delete Robot Account' ,
'create_repo' : 'Create Repository' ,
'push_repo' : 'Push to repository' ,
2014-10-29 19:42:44 +00:00
'repo_verb' : 'Pull Repo Verb' ,
2014-02-25 23:22:55 +00:00
'pull_repo' : 'Pull repository' ,
'delete_repo' : 'Delete repository' ,
'change_repo_permission' : 'Change repository permission' ,
'delete_repo_permission' : 'Remove user permission from repository' ,
'change_repo_visibility' : 'Change repository visibility' ,
'add_repo_accesstoken' : 'Create access token' ,
'delete_repo_accesstoken' : 'Delete access token' ,
'set_repo_description' : 'Change repository description' ,
'build_dockerfile' : 'Build image from Dockerfile' ,
'delete_tag' : 'Delete Tag' ,
2014-02-28 05:12:09 +00:00
'create_tag' : 'Create Tag' ,
'move_tag' : 'Move Tag' ,
2014-02-25 23:22:55 +00:00
'org_create_team' : 'Create team' ,
'org_delete_team' : 'Delete team' ,
'org_add_team_member' : 'Add team member' ,
2014-08-16 01:25:41 +00:00
'org_invite_team_member' : 'Invite team member' ,
2014-09-08 21:20:01 +00:00
'org_delete_team_member_invite' : 'Rescind team member invitation' ,
2014-02-25 23:22:55 +00:00
'org_remove_team_member' : 'Remove team member' ,
2014-08-18 21:24:00 +00:00
'org_team_member_invite_accepted' : 'Team invite accepted' ,
'org_team_member_invite_declined' : 'Team invite declined' ,
2014-02-25 23:22:55 +00:00
'org_set_team_description' : 'Change team description' ,
'org_set_team_role' : 'Change team permission' ,
'create_prototype_permission' : 'Create default permission' ,
'modify_prototype_permission' : 'Modify default permission' ,
'delete_prototype_permission' : 'Delete default permission' ,
'setup_repo_trigger' : 'Setup build trigger' ,
2014-03-20 19:46:13 +00:00
'delete_repo_trigger' : 'Delete build trigger' ,
'create_application' : 'Create Application' ,
'update_application' : 'Update Application' ,
'delete_application' : 'Delete Application' ,
2014-07-18 02:51:58 +00:00
'reset_application_client_secret' : 'Reset Client Secret' ,
'add_repo_notification' : 'Add repository notification' ,
'delete_repo_notification' : 'Delete repository notification' ,
2014-08-25 21:19:23 +00:00
'regenerate_robot_token' : 'Regenerate Robot Token' ,
2014-07-18 02:51:58 +00:00
// Note: these are deprecated.
'add_repo_webhook' : 'Add webhook' ,
'delete_repo_webhook' : 'Delete webhook'
2013-11-27 07:29:31 +00:00
} ;
2013-12-09 22:28:23 +00:00
var getDateString = function ( date ) {
return ( date . getMonth ( ) + 1 ) + '/' + date . getDate ( ) + '/' + date . getFullYear ( ) ;
} ;
var getOffsetDate = function ( date , days ) {
return new Date ( date . getFullYear ( ) , date . getMonth ( ) , date . getDate ( ) + days ) ;
} ;
2013-11-27 07:29:31 +00:00
var update = function ( ) {
2013-12-10 04:33:28 +00:00
var hasValidUser = ! ! $scope . user ;
var hasValidOrg = ! ! $scope . organization ;
var hasValidRepo = $scope . repository && $scope . repository . namespace ;
2014-10-01 17:55:09 +00:00
var isValid = hasValidUser || hasValidOrg || hasValidRepo || $scope . allLogs ;
2013-12-10 04:33:28 +00:00
2014-07-15 18:17:57 +00:00
if ( ! $scope . makevisible || ! isValid ) {
2013-11-27 07:29:31 +00:00
return ;
}
2013-12-09 22:28:23 +00:00
var twoWeeksAgo = getOffsetDate ( $scope . logEndDate , - 14 ) ;
2013-12-10 02:13:21 +00:00
if ( $scope . logStartDate > $scope . logEndDate || $scope . logStartDate < twoWeeksAgo ) {
2013-12-09 22:28:23 +00:00
$scope . logStartDate = twoWeeksAgo ;
}
2013-11-27 21:56:07 +00:00
$scope . loading = true ;
2013-11-27 07:29:31 +00:00
2013-12-26 22:45:16 +00:00
// Note: We construct the URLs here manually because we also use it for the download
// path.
2013-12-02 19:55:04 +00:00
var url = getRestUrl ( 'user/logs' ) ;
if ( $scope . organization ) {
url = getRestUrl ( 'organization' , $scope . organization . name , 'logs' ) ;
}
if ( $scope . repository ) {
url = getRestUrl ( 'repository' , $scope . repository . namespace , $scope . repository . name , 'logs' ) ;
}
2013-12-07 00:25:27 +00:00
2014-10-01 17:55:09 +00:00
if ( $scope . allLogs ) {
url = getRestUrl ( 'superuser' , 'logs' )
}
2013-12-09 22:28:23 +00:00
url += '?starttime=' + encodeURIComponent ( getDateString ( $scope . logStartDate ) ) ;
url += '&endtime=' + encodeURIComponent ( getDateString ( $scope . logEndDate ) ) ;
2013-12-07 00:25:27 +00:00
if ( $scope . performer ) {
2014-09-29 18:08:16 +00:00
url += '&performer=' + encodeURIComponent ( $scope . performer . name ) ;
2013-12-07 00:25:27 +00:00
}
2013-12-09 22:28:23 +00:00
2013-11-27 07:29:31 +00:00
var loadLogs = Restangular . one ( url ) ;
loadLogs . customGET ( ) . then ( function ( resp ) {
2014-03-15 03:40:41 +00:00
$scope . logsPath = '/api/v1/' + url ;
2013-12-06 20:59:59 +00:00
2013-11-27 07:29:31 +00:00
if ( ! $scope . chart ) {
2013-11-27 21:56:07 +00:00
$scope . chart = new LogUsageChart ( logKinds ) ;
2013-11-27 07:29:31 +00:00
$ ( $scope . chart ) . bind ( 'filteringChanged' , function ( e ) {
$scope . $apply ( function ( ) { $scope . kindsAllowed = e . allowed ; } ) ;
} ) ;
2014-07-15 18:17:57 +00:00
}
2013-11-27 07:29:31 +00:00
2013-12-09 22:28:23 +00:00
$scope . chart . draw ( 'bar-chart' , resp . logs , $scope . logStartDate , $scope . logEndDate ) ;
2013-11-29 05:04:50 +00:00
$scope . kindsAllowed = null ;
2013-11-27 07:29:31 +00:00
$scope . logs = resp . logs ;
$scope . loading = false ;
} ) ;
} ;
$scope . toggleChart = function ( ) {
$scope . chartVisible = ! $scope . chartVisible ;
} ;
$scope . isVisible = function ( allowed , kind ) {
return allowed == null || allowed . hasOwnProperty ( kind ) ;
} ;
$scope . getColor = function ( kind ) {
return $scope . chart . getColor ( kind ) ;
} ;
2014-11-24 21:07:38 +00:00
$scope . getDescription = function ( log ) {
2014-01-08 23:44:50 +00:00
log . metadata [ '_ip' ] = log . ip ? log . ip : null ;
2014-03-12 04:49:46 +00:00
return StringBuilderService . buildString ( logDescriptions [ log . kind ] || log . kind , log . metadata ) ;
2013-11-27 07:29:31 +00:00
} ;
$scope . $watch ( 'organization' , update ) ;
$scope . $watch ( 'user' , update ) ;
2013-12-02 19:55:04 +00:00
$scope . $watch ( 'repository' , update ) ;
2014-07-15 18:17:57 +00:00
$scope . $watch ( 'makevisible' , update ) ;
2013-12-07 00:25:27 +00:00
$scope . $watch ( 'performer' , update ) ;
2013-12-09 22:28:23 +00:00
$scope . $watch ( 'logStartDate' , update ) ;
$scope . $watch ( 'logEndDate' , update ) ;
2013-11-27 07:29:31 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-03-20 19:46:13 +00:00
quayApp . directive ( 'applicationManager' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/application-manager.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'organization' : '=organization' ,
2014-07-15 18:17:57 +00:00
'makevisible' : '=makevisible'
2014-03-20 19:46:13 +00:00
} ,
2014-11-24 21:07:38 +00:00
controller : function ( $scope , $element , ApiService ) {
2014-03-20 19:46:13 +00:00
$scope . loading = false ;
2014-07-15 15:57:46 +00:00
$scope . applications = [ ] ;
2014-11-24 21:07:38 +00:00
2014-03-20 19:46:13 +00:00
$scope . createApplication = function ( appName ) {
if ( ! appName ) { return ; }
var params = {
'orgname' : $scope . organization . name
} ;
var data = {
'name' : appName
} ;
ApiService . createOrganizationApplication ( data , params ) . then ( function ( resp ) {
$scope . applications . push ( resp ) ;
2014-08-18 22:21:53 +00:00
} , ApiService . errorDisplay ( 'Cannot create application' ) ) ;
2014-03-20 19:46:13 +00:00
} ;
var update = function ( ) {
2014-07-15 18:17:57 +00:00
if ( ! $scope . organization || ! $scope . makevisible ) { return ; }
2014-03-20 19:46:13 +00:00
if ( $scope . loading ) { return ; }
$scope . loading = true ;
var params = {
'orgname' : $scope . organization . name
} ;
ApiService . getOrganizationApplications ( null , params ) . then ( function ( resp ) {
$scope . loading = false ;
2014-07-15 15:57:46 +00:00
$scope . applications = resp [ 'applications' ] || [ ] ;
2014-03-20 19:46:13 +00:00
} ) ;
} ;
$scope . $watch ( 'organization' , update ) ;
2014-07-15 18:17:57 +00:00
$scope . $watch ( 'makevisible' , update ) ;
2014-03-20 19:46:13 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-22 23:20:51 +00:00
quayApp . directive ( 'robotsManager' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/robots-manager.html' ,
replace : false ,
2013-11-23 01:14:44 +00:00
transclude : false ,
2013-11-22 23:20:51 +00:00
restrict : 'C' ,
scope : {
'organization' : '=organization' ,
'user' : '=user'
} ,
2014-02-25 17:32:56 +00:00
controller : function ( $scope , $element , ApiService , $routeParams ) {
2013-12-10 06:38:05 +00:00
$scope . ROBOT _PATTERN = ROBOT _PATTERN ;
2013-11-22 23:20:51 +00:00
$scope . robots = null ;
$scope . loading = false ;
2013-11-23 01:14:44 +00:00
$scope . shownRobot = null ;
$scope . showRobotCounter = 0 ;
2014-08-25 21:19:23 +00:00
$scope . regenerateToken = function ( username ) {
if ( ! username ) { return ; }
var shortName = $scope . getShortenedName ( username ) ;
ApiService . regenerateRobotToken ( $scope . organization , null , { 'robot_shortname' : shortName } ) . then ( function ( updated ) {
var index = $scope . findRobotIndexByName ( username ) ;
if ( index >= 0 ) {
$scope . robots . splice ( index , 1 ) ;
$scope . robots . push ( updated ) ;
}
$scope . shownRobot = updated ;
} , ApiService . errorDisplay ( 'Cannot regenerate robot account token' ) ) ;
} ;
2013-11-23 01:14:44 +00:00
$scope . showRobot = function ( info ) {
$scope . shownRobot = info ;
$scope . showRobotCounter ++ ;
} ;
2014-11-24 21:07:38 +00:00
2014-02-25 17:32:56 +00:00
$scope . findRobotIndexByName = function ( name ) {
for ( var i = 0 ; i < $scope . robots . length ; ++ i ) {
if ( $scope . robots [ i ] . name == name ) {
return i ;
}
}
return - 1 ;
} ;
2013-11-22 23:20:51 +00:00
$scope . getShortenedName = function ( name ) {
var plus = name . indexOf ( '+' ) ;
return name . substr ( plus + 1 ) ;
} ;
$scope . getPrefix = function ( name ) {
var plus = name . indexOf ( '+' ) ;
return name . substr ( 0 , plus ) ;
} ;
2013-11-23 01:14:44 +00:00
$scope . createRobot = function ( name ) {
if ( ! name ) { return ; }
2013-12-26 22:45:16 +00:00
createRobotAccount ( ApiService , ! ! $scope . organization , $scope . organization ? $scope . organization . name : '' , name ,
2013-12-10 06:38:05 +00:00
function ( created ) {
$scope . robots . push ( created ) ;
} ) ;
2013-11-23 01:14:44 +00:00
} ;
2013-11-22 23:20:51 +00:00
$scope . deleteRobot = function ( info ) {
var shortName = $scope . getShortenedName ( info . name ) ;
2013-12-26 22:45:16 +00:00
ApiService . deleteRobot ( $scope . organization , null , { 'robot_shortname' : shortName } ) . then ( function ( resp ) {
2014-02-25 17:32:56 +00:00
var index = $scope . findRobotIndexByName ( info . name ) ;
if ( index >= 0 ) {
$scope . robots . splice ( index , 1 ) ;
2013-11-22 23:20:51 +00:00
}
2014-08-18 22:21:53 +00:00
} , ApiService . errorDisplay ( 'Cannot delete robot account' ) ) ;
2013-11-22 23:20:51 +00:00
} ;
var update = function ( ) {
if ( ! $scope . user && ! $scope . organization ) { return ; }
if ( $scope . loading ) { return ; }
$scope . loading = true ;
2013-12-26 22:45:16 +00:00
ApiService . getRobots ( $scope . organization ) . then ( function ( resp ) {
2013-11-22 23:20:51 +00:00
$scope . robots = resp . robots ;
$scope . loading = false ;
2014-02-25 17:32:56 +00:00
if ( $routeParams . showRobot ) {
var index = $scope . findRobotIndexByName ( $routeParams . showRobot ) ;
if ( index >= 0 ) {
$scope . showRobot ( $scope . robots [ index ] ) ;
}
}
2013-11-22 23:20:51 +00:00
} ) ;
} ;
$scope . $watch ( 'organization' , update ) ;
$scope . $watch ( 'user' , update ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-01-21 19:18:20 +00:00
quayApp . directive ( 'prototypeManager' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/prototype-manager.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'organization' : '=organization'
} ,
controller : function ( $scope , $element , ApiService ) {
$scope . loading = false ;
2014-01-21 20:09:47 +00:00
$scope . activatingForNew = null ;
$scope . delegateForNew = null ;
$scope . clearCounter = 0 ;
2014-01-21 23:34:54 +00:00
$scope . newForWholeOrg = true ;
2014-01-21 19:18:20 +00:00
$scope . roles = [
{ 'id' : 'read' , 'title' : 'Read' , 'kind' : 'success' } ,
{ 'id' : 'write' , 'title' : 'Write' , 'kind' : 'success' } ,
{ 'id' : 'admin' , 'title' : 'Admin' , 'kind' : 'primary' }
] ;
$scope . setRole = function ( role , prototype ) {
var params = {
'orgname' : $scope . organization . name ,
'prototypeid' : prototype . id
} ;
var data = {
'id' : prototype . id ,
'role' : role
} ;
ApiService . updateOrganizationPrototypePermission ( data , params ) . then ( function ( resp ) {
prototype . role = role ;
2014-08-18 22:21:53 +00:00
} , ApiService . errorDisplay ( 'Cannot modify permission' ) ) ;
2014-01-21 19:18:20 +00:00
} ;
2014-01-21 23:34:54 +00:00
$scope . comparePrototypes = function ( p ) {
return p . activating _user ? p . activating _user . name : ' ' ;
} ;
2014-01-21 20:09:47 +00:00
$scope . setRoleForNew = function ( role ) {
$scope . newRole = role ;
} ;
2014-01-21 23:34:54 +00:00
$scope . setNewForWholeOrg = function ( value ) {
$scope . newForWholeOrg = value ;
} ;
2014-01-21 20:09:47 +00:00
$scope . showAddDialog = function ( ) {
$scope . activatingForNew = null ;
$scope . delegateForNew = null ;
$scope . newRole = 'read' ;
$scope . clearCounter ++ ;
2014-01-21 23:34:54 +00:00
$scope . newForWholeOrg = true ;
2014-01-21 20:09:47 +00:00
$ ( '#addPermissionDialogModal' ) . modal ( { } ) ;
} ;
$scope . createPrototype = function ( ) {
$scope . loading = true ;
var params = {
'orgname' : $scope . organization . name
} ;
var data = {
'delegate' : $scope . delegateForNew ,
'role' : $scope . newRole
} ;
2014-03-17 19:04:12 +00:00
if ( ! $scope . newForWholeOrg ) {
data [ 'activating_user' ] = $scope . activatingForNew ;
}
2014-08-18 22:21:53 +00:00
var errorHandler = ApiService . errorDisplay ( 'Cannot create permission' ,
function ( resp ) {
$ ( '#addPermissionDialogModal' ) . modal ( 'hide' ) ;
} ) ;
2014-01-21 20:09:47 +00:00
ApiService . createOrganizationPrototypePermission ( data , params ) . then ( function ( resp ) {
$scope . prototypes . push ( resp ) ;
$scope . loading = false ;
$ ( '#addPermissionDialogModal' ) . modal ( 'hide' ) ;
2014-08-18 22:21:53 +00:00
} , errorHandler ) ;
2014-01-21 20:09:47 +00:00
} ;
2014-01-21 19:18:20 +00:00
$scope . deletePrototype = function ( prototype ) {
$scope . loading = true ;
var params = {
'orgname' : $scope . organization . name ,
'prototypeid' : prototype . id
} ;
ApiService . deleteOrganizationPrototypePermission ( null , params ) . then ( function ( resp ) {
$scope . prototypes . splice ( $scope . prototypes . indexOf ( prototype ) , 1 ) ;
$scope . loading = false ;
2014-08-18 22:21:53 +00:00
} , ApiService . errorDisplay ( 'Cannot delete permission' ) ) ;
2014-01-21 19:18:20 +00:00
} ;
var update = function ( ) {
if ( ! $scope . organization ) { return ; }
if ( $scope . loading ) { return ; }
var params = { 'orgname' : $scope . organization . name } ;
$scope . loading = true ;
ApiService . getOrganizationPrototypePermissions ( null , params ) . then ( function ( resp ) {
$scope . prototypes = resp . prototypes ;
$scope . loading = false ;
} ) ;
} ;
$scope . $watch ( 'organization' , update ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-03-12 04:49:46 +00:00
quayApp . directive ( 'deleteUi' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/delete-ui.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
'deleteTitle' : '=deleteTitle' ,
'buttonTitle' : '=buttonTitle' ,
'performDelete' : '&performDelete'
} ,
controller : function ( $scope , $element ) {
$scope . buttonTitleInternal = $scope . buttonTitle || 'Delete' ;
$element . children ( ) . attr ( 'tabindex' , 0 ) ;
$scope . focus = function ( ) {
$element [ 0 ] . firstChild . focus ( ) ;
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-23 01:14:44 +00:00
quayApp . directive ( 'popupInputButton' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/popup-input-button.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
'placeholder' : '=placeholder' ,
'pattern' : '=pattern' ,
'submitted' : '&submitted'
} ,
controller : function ( $scope , $element ) {
$scope . popupShown = function ( ) {
setTimeout ( function ( ) {
var box = $ ( '#input-box' ) ;
box [ 0 ] . value = '' ;
box . focus ( ) ;
2014-03-12 04:49:46 +00:00
} , 40 ) ;
2013-11-23 01:14:44 +00:00
} ;
$scope . getRegexp = function ( pattern ) {
if ( ! pattern ) {
pattern = '.*' ;
}
return new RegExp ( pattern ) ;
} ;
$scope . inputSubmit = function ( ) {
var box = $ ( '#input-box' ) ;
if ( box . hasClass ( 'ng-invalid' ) ) { return ; }
var entered = box [ 0 ] . value ;
if ( ! entered ) {
return ;
}
if ( $scope . submitted ) {
$scope . submitted ( { 'value' : entered } ) ;
}
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-22 23:20:51 +00:00
2013-12-17 18:19:59 +00:00
quayApp . directive ( 'resourceView' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/resource-view.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
'resource' : '=resource' ,
'errorMessage' : '=errorMessage'
} ,
controller : function ( $scope , $element ) {
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-12-18 03:56:28 +00:00
quayApp . directive ( 'quaySpinner' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/spinner.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : { } ,
controller : function ( $scope , $element ) {
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-08-08 17:50:04 +00:00
quayApp . directive ( 'registryName' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/registry-name.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : { } ,
controller : function ( $scope , $element , Config ) {
$scope . name = Config . REGISTRY _TITLE ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-04 19:56:54 +00:00
quayApp . directive ( 'organizationHeader' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/organization-header.html' ,
replace : false ,
2013-11-05 21:15:04 +00:00
transclude : true ,
2013-11-04 19:56:54 +00:00
restrict : 'C' ,
scope : {
'organization' : '=organization' ,
2013-12-02 22:19:19 +00:00
'teamName' : '=teamName' ,
'clickable' : '=clickable'
2013-11-04 19:56:54 +00:00
} ,
controller : function ( $scope , $element ) {
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-05 00:59:28 +00:00
quayApp . directive ( 'markdownInput' , function ( ) {
var counter = 0 ;
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/markdown-input.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'content' : '=content' ,
'canWrite' : '=canWrite' ,
'contentChanged' : '=contentChanged' ,
'fieldTitle' : '=fieldTitle'
} ,
controller : function ( $scope , $element ) {
var elm = $element [ 0 ] ;
$scope . id = ( counter ++ ) ;
$scope . editContent = function ( ) {
if ( ! $scope . canWrite ) { return ; }
if ( ! $scope . markdownDescriptionEditor ) {
var converter = Markdown . getSanitizingConverter ( ) ;
var editor = new Markdown . Editor ( converter , '-description-' + $scope . id ) ;
editor . run ( ) ;
$scope . markdownDescriptionEditor = editor ;
}
$ ( '#wmd-input-description-' + $scope . id ) [ 0 ] . value = $scope . content ;
$ ( elm ) . find ( '.modal' ) . modal ( { } ) ;
} ;
$scope . saveContent = function ( ) {
$scope . content = $ ( '#wmd-input-description-' + $scope . id ) [ 0 ] . value ;
$ ( elm ) . find ( '.modal' ) . modal ( 'hide' ) ;
if ( $scope . contentChanged ) {
$scope . contentChanged ( $scope . content ) ;
}
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-19 00:03:35 +00:00
quayApp . directive ( 'repoSearch' , function ( ) {
var number = 0 ;
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/repo-search.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
} ,
controller : function ( $scope , $element , $location , UserService , Restangular ) {
var searchToken = 0 ;
$scope . $watch ( function ( ) { return UserService . currentUser ( ) ; } , function ( currentUser ) {
++ searchToken ;
} , true ) ;
2014-11-24 21:07:38 +00:00
2014-03-08 02:06:31 +00:00
var repoHound = new Bloodhound ( {
2013-11-19 00:03:35 +00:00
name : 'repositories' ,
remote : {
2014-03-15 03:40:41 +00:00
url : '/api/v1/find/repository?query=%QUERY' ,
2013-11-19 00:03:35 +00:00
replace : function ( url , uriEncodedQuery ) {
2014-11-24 21:07:38 +00:00
url = url . replace ( '%QUERY' , uriEncodedQuery ) ;
2013-11-19 00:03:35 +00:00
url += '&cb=' + searchToken ;
return url ;
} ,
filter : function ( data ) {
var datums = [ ] ;
for ( var i = 0 ; i < data . repositories . length ; ++ i ) {
var repo = data . repositories [ i ] ;
datums . push ( {
'value' : repo . name ,
'tokens' : [ repo . name , repo . namespace ] ,
'repo' : repo
} ) ;
}
return datums ;
}
} ,
2014-11-24 21:07:38 +00:00
datumTokenizer : function ( d ) {
return Bloodhound . tokenizers . whitespace ( d . val ) ;
2014-03-08 02:06:31 +00:00
} ,
queryTokenizer : Bloodhound . tokenizers . whitespace
} ) ;
repoHound . initialize ( ) ;
var element = $ ( $element [ 0 ] . childNodes [ 0 ] ) ;
element . typeahead ( { 'highlight' : true } , {
2014-11-24 21:07:38 +00:00
source : repoHound . ttAdapter ( ) ,
2014-03-08 02:06:31 +00:00
templates : {
'suggestion' : function ( datum ) {
template = '<div class="repo-mini-listing">' ;
template += '<i class="fa fa-hdd-o fa-lg"></i>'
template += '<span class="name">' + datum . repo . namespace + '/' + datum . repo . name + '</span>'
if ( datum . repo . description ) {
template += '<span class="description">' + getFirstTextLine ( datum . repo . description ) + '</span>'
}
2013-11-19 00:03:35 +00:00
2014-03-08 02:06:31 +00:00
template += '</div>'
return template ;
}
2013-11-19 00:03:35 +00:00
}
} ) ;
element . on ( 'typeahead:selected' , function ( e , datum ) {
2014-03-08 02:06:31 +00:00
element . typeahead ( 'val' , '' ) ;
$scope . $apply ( function ( ) {
$location . path ( '/repository/' + datum . repo . namespace + '/' + datum . repo . name ) ;
} ) ;
2013-11-19 00:03:35 +00:00
} ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
quayApp . directive ( 'headerBar' , function ( ) {
var number = 0 ;
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/header-bar.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
} ,
2014-12-12 23:25:30 +00:00
controller : function ( $scope , $element , $location , UserService , PlanService , ApiService , NotificationService , Config ) {
2014-03-12 04:49:46 +00:00
$scope . notificationService = NotificationService ;
2014-11-24 21:07:38 +00:00
2013-12-19 04:03:19 +00:00
// Monitor any user changes and place the current user into the scope.
2014-03-12 04:49:46 +00:00
UserService . updateUserIn ( $scope ) ;
2014-11-24 21:07:38 +00:00
2013-11-19 00:03:35 +00:00
$scope . signout = function ( ) {
2013-12-26 22:45:16 +00:00
ApiService . logout ( ) . then ( function ( ) {
UserService . load ( ) ;
$location . path ( '/' ) ;
2013-11-19 00:03:35 +00:00
} ) ;
} ;
2014-11-24 21:07:38 +00:00
2013-11-19 00:03:35 +00:00
$scope . appLinkTarget = function ( ) {
if ( $ ( "div[ng-view]" ) . length === 0 ) {
return "_self" ;
}
return "" ;
2014-11-24 21:07:38 +00:00
} ;
2014-12-12 23:25:30 +00:00
$scope . getEnterpriseLogo = function ( ) {
if ( ! Config . ENTERPRISE _LOGO _URL ) {
return '/static/img/quay-logo.png' ;
}
return Config . ENTERPRISE _LOGO _URL ;
} ;
2013-11-19 00:03:35 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-02 01:48:10 +00:00
quayApp . directive ( 'entitySearch' , function ( ) {
var number = 0 ;
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/entity-search.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
2014-07-18 17:45:08 +00:00
require : '?ngModel' ,
link : function ( scope , element , attr , ctrl ) {
scope . ngModel = ctrl ;
} ,
2013-11-02 01:48:10 +00:00
scope : {
2013-11-20 23:23:59 +00:00
'namespace' : '=namespace' ,
2014-07-18 17:45:08 +00:00
'placeholder' : '=placeholder' ,
// Default: ['user', 'team', 'robot']
'allowedEntities' : '=allowedEntities' ,
2014-01-21 20:09:47 +00:00
'currentEntity' : '=currentEntity' ,
2014-08-29 00:49:11 +00:00
2014-07-18 17:45:08 +00:00
'entitySelected' : '&entitySelected' ,
2014-08-29 00:49:11 +00:00
'emailSelected' : '&emailSelected' ,
2014-07-18 17:45:08 +00:00
// When set to true, the contents of the control will be cleared as soon
// as an entity is selected.
'autoClear' : '=autoClear' ,
// Set this property to immediately clear the contents of the control.
'clearValue' : '=clearValue' ,
2014-08-16 00:51:31 +00:00
2014-08-29 00:49:11 +00:00
// Whether e-mail addresses are allowed.
2014-09-23 15:19:50 +00:00
'allowEmails' : '=allowEmails' ,
2014-08-29 00:49:11 +00:00
'emailMessage' : '@emailMessage' ,
// True if the menu should pull right.
2014-08-16 00:51:31 +00:00
'pullRight' : '@pullRight'
2013-11-02 01:48:10 +00:00
} ,
2014-08-29 00:49:11 +00:00
controller : function ( $rootScope , $scope , $element , Restangular , UserService , ApiService , UtilService , Config ) {
2013-12-10 06:38:05 +00:00
$scope . lazyLoading = true ;
2014-07-18 17:45:08 +00:00
$scope . teams = null ;
$scope . robots = null ;
2013-12-10 06:38:05 +00:00
$scope . isAdmin = false ;
2014-07-18 17:45:08 +00:00
$scope . isOrganization = false ;
$scope . includeTeams = true ;
$scope . includeRobots = true ;
2014-07-22 17:39:41 +00:00
$scope . includeOrgs = false ;
2014-07-18 17:45:08 +00:00
2014-04-03 03:33:58 +00:00
$scope . currentEntityInternal = $scope . currentEntity ;
2013-12-10 06:38:05 +00:00
2014-07-18 17:45:08 +00:00
var isSupported = function ( kind , opt _array ) {
return $ . inArray ( kind , opt _array || $scope . allowedEntities || [ 'user' , 'team' , 'robot' ] ) >= 0 ;
} ;
2013-12-10 06:38:05 +00:00
$scope . lazyLoad = function ( ) {
if ( ! $scope . namespace || ! $scope . lazyLoading ) { return ; }
2014-07-18 17:45:08 +00:00
// Reset the cached teams and robots.
$scope . teams = null ;
$scope . robots = null ;
2014-11-24 21:07:38 +00:00
2014-07-18 17:45:08 +00:00
// Load the organization's teams (if applicable).
if ( $scope . isOrganization && isSupported ( 'team' ) ) {
// Note: We load the org here again so that we always have the fully up-to-date
// teams list.
2013-12-26 22:45:16 +00:00
ApiService . getOrganization ( null , { 'orgname' : $scope . namespace } ) . then ( function ( resp ) {
2013-12-10 06:38:05 +00:00
$scope . teams = resp . teams ;
} ) ;
}
2014-07-18 17:45:08 +00:00
// Load the user/organization's robots (if applicable).
if ( $scope . isAdmin && isSupported ( 'robot' ) ) {
ApiService . getRobots ( $scope . isOrganization ? $scope . namespace : null ) . then ( function ( resp ) {
$scope . robots = resp . robots ;
$scope . lazyLoading = false ;
} , function ( ) {
$scope . lazyLoading = false ;
} ) ;
} else {
2013-12-10 20:49:34 +00:00
$scope . lazyLoading = false ;
2014-07-18 17:45:08 +00:00
}
2013-12-10 06:38:05 +00:00
} ;
$scope . createTeam = function ( ) {
2013-12-10 20:49:34 +00:00
if ( ! $scope . isAdmin ) { return ; }
2013-12-10 06:38:05 +00:00
bootbox . prompt ( 'Enter the name of the new team' , function ( teamname ) {
if ( ! teamname ) { return ; }
2014-11-24 21:07:38 +00:00
2013-12-10 06:38:05 +00:00
var regex = new RegExp ( TEAM _PATTERN ) ;
if ( ! regex . test ( teamname ) ) {
bootbox . alert ( 'Invalid team name' ) ;
return ;
}
2013-12-26 22:45:16 +00:00
createOrganizationTeam ( ApiService , $scope . namespace , teamname , function ( created ) {
2013-12-10 06:38:05 +00:00
$scope . setEntity ( created . name , 'team' , false ) ;
$scope . teams [ teamname ] = created ;
2014-11-24 21:07:38 +00:00
} ) ;
2013-12-10 06:38:05 +00:00
} ) ;
} ;
$scope . createRobot = function ( ) {
2013-12-10 20:49:34 +00:00
if ( ! $scope . isAdmin ) { return ; }
2013-12-10 06:38:05 +00:00
bootbox . prompt ( 'Enter the name of the new robot account' , function ( robotname ) {
if ( ! robotname ) { return ; }
var regex = new RegExp ( ROBOT _PATTERN ) ;
if ( ! regex . test ( robotname ) ) {
bootbox . alert ( 'Invalid robot account name' ) ;
return ;
}
2013-12-26 22:45:16 +00:00
createRobotAccount ( ApiService , $scope . isOrganization , $scope . namespace , robotname , function ( created ) {
2013-12-10 06:38:05 +00:00
$scope . setEntity ( created . name , 'user' , true ) ;
$scope . robots . push ( created ) ;
2014-11-24 21:07:38 +00:00
} ) ;
2013-12-10 06:38:05 +00:00
} ) ;
} ;
$scope . setEntity = function ( name , kind , is _robot ) {
var entity = {
'name' : name ,
'kind' : kind ,
'is_robot' : is _robot
} ;
2014-07-18 17:45:08 +00:00
if ( $scope . isOrganization ) {
2013-12-10 06:38:05 +00:00
entity [ 'is_org_member' ] = true ;
}
2014-04-01 23:33:11 +00:00
$scope . setEntityInternal ( entity , false ) ;
2013-12-10 06:38:05 +00:00
} ;
2014-01-21 20:09:47 +00:00
$scope . clearEntityInternal = function ( ) {
2014-04-03 03:33:58 +00:00
$scope . currentEntityInternal = null ;
2014-01-21 20:09:47 +00:00
$scope . currentEntity = null ;
2014-07-18 17:45:08 +00:00
$scope . entitySelected ( { 'entity' : null } ) ;
if ( $scope . ngModel ) {
$scope . ngModel . $setValidity ( 'entity' , false ) ;
2014-01-21 20:09:47 +00:00
}
} ;
2014-04-01 23:33:11 +00:00
$scope . setEntityInternal = function ( entity , updateTypeahead ) {
if ( updateTypeahead ) {
2014-07-18 17:45:08 +00:00
$ ( input ) . typeahead ( 'val' , $scope . autoClear ? '' : entity . name ) ;
2014-04-01 23:33:11 +00:00
} else {
2014-07-18 17:45:08 +00:00
$ ( input ) . val ( $scope . autoClear ? '' : entity . name ) ;
2014-04-01 23:33:11 +00:00
}
2014-01-21 20:09:47 +00:00
2014-07-18 17:45:08 +00:00
if ( ! $scope . autoClear ) {
2014-04-03 03:33:58 +00:00
$scope . currentEntityInternal = entity ;
2014-01-21 20:09:47 +00:00
$scope . currentEntity = entity ;
}
2014-07-18 17:45:08 +00:00
$scope . entitySelected ( { 'entity' : entity } ) ;
if ( $scope . ngModel ) {
$scope . ngModel . $setValidity ( 'entity' , ! ! entity ) ;
2014-01-21 20:09:47 +00:00
}
} ;
2013-11-02 01:48:10 +00:00
2014-07-18 17:45:08 +00:00
// Setup the typeahead.
var input = $element [ 0 ] . firstChild . firstChild ;
( function ( ) {
// Create the bloodhound search query system.
$rootScope . _ _entity _search _counter = ( ( $rootScope . _ _entity _search _counter || 0 ) + 1 ) ;
var entitySearchB = new Bloodhound ( {
name : 'entities' + $rootScope . _ _entity _search _counter ,
remote : {
url : '/api/v1/entities/%QUERY' ,
replace : function ( url , uriEncodedQuery ) {
var namespace = $scope . namespace || '' ;
url = url . replace ( '%QUERY' , uriEncodedQuery ) ;
url += '?namespace=' + encodeURIComponent ( namespace ) ;
if ( $scope . isOrganization && isSupported ( 'team' ) ) {
url += '&includeTeams=true'
}
2014-07-22 17:39:41 +00:00
if ( isSupported ( 'org' ) ) {
url += '&includeOrgs=true'
}
2014-07-18 17:45:08 +00:00
return url ;
} ,
filter : function ( data ) {
var datums = [ ] ;
for ( var i = 0 ; i < data . results . length ; ++ i ) {
var entity = data . results [ i ] ;
2013-11-02 01:48:10 +00:00
2014-03-27 22:33:13 +00:00
var found = 'user' ;
if ( entity . kind == 'user' ) {
found = entity . is _robot ? 'robot' : 'user' ;
} else if ( entity . kind == 'team' ) {
found = 'team' ;
2014-07-22 17:39:41 +00:00
} else if ( entity . kind == 'org' ) {
found = 'org' ;
2014-03-27 22:33:13 +00:00
}
2014-07-18 17:45:08 +00:00
if ( ! isSupported ( found ) ) {
2014-03-27 22:33:13 +00:00
continue ;
}
2014-07-18 17:45:08 +00:00
datums . push ( {
'value' : entity . name ,
'tokens' : [ entity . name ] ,
'entity' : entity
} ) ;
}
return datums ;
2013-11-02 01:48:10 +00:00
}
2014-07-18 17:45:08 +00:00
} ,
2014-11-24 21:07:38 +00:00
datumTokenizer : function ( d ) {
return Bloodhound . tokenizers . whitespace ( d . val ) ;
2014-07-18 17:45:08 +00:00
} ,
queryTokenizer : Bloodhound . tokenizers . whitespace
} ) ;
entitySearchB . initialize ( ) ;
// Setup the typeahead.
$ ( input ) . typeahead ( {
'highlight' : true
} , {
source : entitySearchB . ttAdapter ( ) ,
templates : {
'empty' : function ( info ) {
// Only display the empty dialog if the server load has finished.
if ( info . resultKind == 'remote' ) {
var val = $ ( input ) . val ( ) ;
if ( ! val ) {
return null ;
}
2013-11-02 01:48:10 +00:00
2014-08-29 00:49:11 +00:00
if ( UtilService . isEmailAddress ( val ) ) {
if ( $scope . allowEmails ) {
return '<div class="tt-message">' + $scope . emailMessage + '</div>' ;
} else {
return '<div class="tt-empty">A ' + Config . REGISTRY _TITLE _SHORT + ' username (not an e-mail address) must be specified</div>' ;
}
2014-07-18 17:45:08 +00:00
}
2013-11-02 01:48:10 +00:00
2014-07-18 17:45:08 +00:00
var classes = [ ] ;
2014-03-08 02:06:31 +00:00
2014-07-18 17:45:08 +00:00
if ( isSupported ( 'user' ) ) { classes . push ( 'users' ) ; }
2014-07-22 17:39:41 +00:00
if ( isSupported ( 'org' ) ) { classes . push ( 'organizations' ) ; }
2014-07-18 17:45:08 +00:00
if ( $scope . isAdmin && isSupported ( 'robot' ) ) { classes . push ( 'robot accounts' ) ; }
if ( $scope . isOrganization && isSupported ( 'team' ) ) { classes . push ( 'teams' ) ; }
2014-03-08 02:06:31 +00:00
2014-07-18 17:45:08 +00:00
if ( classes . length > 1 ) {
classes [ classes . length - 1 ] = 'or ' + classes [ classes . length - 1 ] ;
2015-01-16 22:01:14 +00:00
} else if ( classes . length == 0 ) {
return '<div class="tt-empty">No matching entities found</div>' ;
2014-07-18 17:45:08 +00:00
}
2014-03-08 02:06:31 +00:00
2014-07-18 17:45:08 +00:00
var class _string = '' ;
for ( var i = 0 ; i < classes . length ; ++ i ) {
2014-11-24 21:07:38 +00:00
if ( i > 0 ) {
2014-07-18 17:45:08 +00:00
if ( i == classes . length - 1 ) {
class _string += ' or ' ;
} else {
class _string += ', ' ;
}
}
class _string += classes [ i ] ;
}
2014-03-08 02:06:31 +00:00
2014-08-08 17:50:04 +00:00
return '<div class="tt-empty">No matching ' + Config . REGISTRY _TITLE _SHORT + ' ' + class _string + ' found</div>' ;
2014-07-18 17:45:08 +00:00
}
2013-11-02 01:48:10 +00:00
2014-07-18 17:45:08 +00:00
return null ;
2014-11-24 21:07:38 +00:00
} ,
2014-07-18 17:45:08 +00:00
'suggestion' : function ( datum ) {
template = '<div class="entity-mini-listing">' ;
if ( datum . entity . kind == 'user' && ! datum . entity . is _robot ) {
template += '<i class="fa fa-user fa-lg"></i>' ;
} else if ( datum . entity . kind == 'user' && datum . entity . is _robot ) {
2014-11-24 21:07:38 +00:00
template += '<i class="fa fa-wrench fa-lg"></i>' ;
2014-07-18 17:45:08 +00:00
} else if ( datum . entity . kind == 'team' ) {
template += '<i class="fa fa-group fa-lg"></i>' ;
2014-07-22 17:39:41 +00:00
} else if ( datum . entity . kind == 'org' ) {
2014-11-25 00:25:13 +00:00
template += '<i class="fa">' + AvatarService . getAvatar ( datum . entity . avatar , 16 ) + '</i>' ;
2014-07-18 17:45:08 +00:00
}
2014-07-22 17:39:41 +00:00
2014-07-18 17:45:08 +00:00
template += '<span class="name">' + datum . value + '</span>' ;
if ( datum . entity . is _org _member === false && datum . entity . kind == 'user' ) {
template += '<i class="fa fa-exclamation-triangle" title="User is outside the organization"></i>' ;
}
template += '</div>' ;
return template ;
} }
} ) ;
2014-08-29 00:49:11 +00:00
$ ( input ) . on ( 'keypress' , function ( e ) {
var val = $ ( input ) . val ( ) ;
var code = e . keyCode || e . which ;
if ( code == 13 && $scope . allowEmails && UtilService . isEmailAddress ( val ) ) {
$scope . $apply ( function ( ) {
$scope . emailSelected ( { 'email' : val } ) ;
} ) ;
}
} ) ;
2014-07-18 17:45:08 +00:00
$ ( input ) . on ( 'input' , function ( e ) {
$scope . $apply ( function ( ) {
2014-01-21 20:09:47 +00:00
$scope . clearEntityInternal ( ) ;
2014-07-18 17:45:08 +00:00
} ) ;
2014-01-21 20:09:47 +00:00
} ) ;
2014-07-18 17:45:08 +00:00
$ ( input ) . on ( 'typeahead:selected' , function ( e , datum ) {
$scope . $apply ( function ( ) {
$scope . setEntityInternal ( datum . entity , true ) ;
} ) ;
2013-12-10 06:38:05 +00:00
} ) ;
2014-07-18 17:45:08 +00:00
} ) ( ) ;
$scope . $watch ( 'clearValue' , function ( ) {
if ( ! input ) { return ; }
2013-11-02 01:48:10 +00:00
2014-03-08 02:06:31 +00:00
$ ( input ) . typeahead ( 'val' , '' ) ;
2014-11-24 21:07:38 +00:00
$scope . clearEntityInternal ( ) ;
2014-01-21 20:09:47 +00:00
} ) ;
2014-07-18 17:45:08 +00:00
$scope . $watch ( 'placeholder' , function ( title ) {
2013-11-02 01:48:10 +00:00
input . setAttribute ( 'placeholder' , title ) ;
} ) ;
2014-04-03 03:33:58 +00:00
2014-07-18 17:45:08 +00:00
$scope . $watch ( 'allowedEntities' , function ( allowed ) {
if ( ! allowed ) { return ; }
$scope . includeTeams = isSupported ( 'team' , allowed ) ;
$scope . includeRobots = isSupported ( 'robot' , allowed ) ;
} ) ;
$scope . $watch ( 'namespace' , function ( namespace ) {
if ( ! namespace ) { return ; }
$scope . isAdmin = UserService . isNamespaceAdmin ( namespace ) ;
$scope . isOrganization = ! ! UserService . getOrganization ( namespace ) ;
} ) ;
2014-04-03 03:33:58 +00:00
$scope . $watch ( 'currentEntity' , function ( entity ) {
if ( $scope . currentEntityInternal != entity ) {
if ( entity ) {
$scope . setEntityInternal ( entity , false ) ;
} else {
$scope . clearEntityInternal ( ) ;
}
}
} ) ;
2013-11-02 01:48:10 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-05 19:47:46 +00:00
quayApp . directive ( 'roleGroup' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/role-group.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'roles' : '=roles' ,
'currentRole' : '=currentRole' ,
'roleChanged' : '&roleChanged'
} ,
controller : function ( $scope , $element ) {
$scope . setRole = function ( role ) {
2013-11-08 04:35:27 +00:00
if ( $scope . currentRole == role ) { return ; }
2014-11-24 21:07:38 +00:00
if ( $scope . roleChanged ) {
2013-11-05 19:47:46 +00:00
$scope . roleChanged ( { 'role' : role } ) ;
2013-11-08 04:35:27 +00:00
} else {
$scope . currentRole = role ;
2013-11-05 19:47:46 +00:00
}
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-15 19:42:31 +00:00
quayApp . directive ( 'billingOptions' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/billing-options.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'user' : '=user' ,
'organization' : '=organization'
} ,
2013-12-26 22:45:16 +00:00
controller : function ( $scope , $element , PlanService , ApiService ) {
2013-11-15 19:42:31 +00:00
$scope . invoice _email = false ;
2013-11-15 23:17:12 +00:00
$scope . currentCard = null ;
// Listen to plan changes.
PlanService . registerListener ( this , function ( plan ) {
if ( plan && plan . price > 0 ) {
update ( ) ;
}
} ) ;
$scope . $on ( '$destroy' , function ( ) {
PlanService . unregisterListener ( this ) ;
} ) ;
2014-05-22 20:52:51 +00:00
$scope . isExpiringSoon = function ( cardInfo ) {
var current = new Date ( ) ;
var expires = new Date ( cardInfo . exp _year , cardInfo . exp _month , 1 ) ;
var difference = expires - current ;
return difference < ( 60 * 60 * 24 * 60 * 1000 /* 60 days */ ) ;
} ;
2013-11-15 23:17:12 +00:00
$scope . changeCard = function ( ) {
2013-11-19 22:06:17 +00:00
var previousCard = $scope . currentCard ;
2013-11-15 23:17:12 +00:00
$scope . changingCard = true ;
var callbacks = {
'opened' : function ( ) { $scope . changingCard = true ; } ,
'closed' : function ( ) { $scope . changingCard = false ; } ,
'started' : function ( ) { $scope . currentCard = null ; } ,
'success' : function ( resp ) {
$scope . currentCard = resp . card ;
$scope . changingCard = false ;
} ,
2013-11-19 22:06:17 +00:00
'failure' : function ( resp ) {
2013-11-15 23:17:12 +00:00
$scope . changingCard = false ;
2013-11-19 22:06:17 +00:00
$scope . currentCard = previousCard ;
if ( ! PlanService . isCardError ( resp ) ) {
$ ( '#cannotchangecardModal' ) . modal ( { } ) ;
}
2013-11-15 23:17:12 +00:00
}
} ;
PlanService . changeCreditCard ( $scope , $scope . organization ? $scope . organization . name : null , callbacks ) ;
} ;
$scope . getCreditImage = function ( creditInfo ) {
2013-11-15 23:34:54 +00:00
if ( ! creditInfo || ! creditInfo . type ) { return 'credit.png' ; }
2013-11-15 23:17:12 +00:00
var kind = creditInfo . type . toLowerCase ( ) || 'credit' ;
var supported = {
'american express' : 'amex' ,
'credit' : 'credit' ,
'diners club' : 'diners' ,
'discover' : 'discover' ,
'jcb' : 'jcb' ,
2014-11-24 21:07:38 +00:00
'mastercard' : 'mastercard' ,
2013-11-15 23:17:12 +00:00
'visa' : 'visa'
} ;
2014-11-24 21:07:38 +00:00
2013-11-15 23:17:12 +00:00
kind = supported [ kind ] || 'credit' ;
return kind + '.png' ;
} ;
2013-11-15 19:42:31 +00:00
var update = function ( ) {
if ( ! $scope . user && ! $scope . organization ) { return ; }
$scope . obj = $scope . user ? $scope . user : $scope . organization ;
$scope . invoice _email = $scope . obj . invoice _email ;
2013-11-15 23:17:12 +00:00
// Load the credit card information.
2013-11-15 23:58:47 +00:00
PlanService . getCardInfo ( $scope . organization ? $scope . organization . name : null , function ( card ) {
$scope . currentCard = card ;
2013-11-15 23:17:12 +00:00
} ) ;
2013-11-15 19:42:31 +00:00
} ;
var save = function ( ) {
$scope . working = true ;
2014-09-04 18:24:20 +00:00
var errorHandler = ApiService . errorDisplay ( 'Could not change user details' ) ;
2013-12-26 22:45:16 +00:00
ApiService . changeDetails ( $scope . organization , $scope . obj ) . then ( function ( resp ) {
2013-11-15 19:42:31 +00:00
$scope . working = false ;
2014-09-04 18:24:20 +00:00
} , errorHandler ) ;
2013-11-15 19:42:31 +00:00
} ;
var checkSave = function ( ) {
if ( ! $scope . obj ) { return ; }
if ( $scope . obj . invoice _email != $scope . invoice _email ) {
$scope . obj . invoice _email = $scope . invoice _email ;
save ( ) ;
}
} ;
2014-11-24 21:07:38 +00:00
2013-11-15 19:42:31 +00:00
$scope . $watch ( 'invoice_email' , checkSave ) ;
$scope . $watch ( 'organization' , update ) ;
$scope . $watch ( 'user' , update ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-11-24 21:07:38 +00:00
2013-11-06 22:30:20 +00:00
quayApp . directive ( 'planManager' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/plan-manager.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'user' : '=user' ,
2013-11-06 23:14:22 +00:00
'organization' : '=organization' ,
2013-11-15 23:17:12 +00:00
'readyForPlan' : '&readyForPlan' ,
'planChanged' : '&planChanged'
2013-11-06 22:30:20 +00:00
} ,
2013-12-26 22:45:16 +00:00
controller : function ( $scope , $element , PlanService , ApiService ) {
2014-04-23 05:17:34 +00:00
$scope . isExistingCustomer = false ;
2014-11-24 21:07:38 +00:00
2014-04-23 05:10:31 +00:00
$scope . parseDate = function ( timestamp ) {
return new Date ( timestamp * 1000 ) ;
} ;
2013-12-20 02:51:46 +00:00
$scope . isPlanVisible = function ( plan , subscribedPlan ) {
if ( plan [ 'deprecated' ] ) {
return plan == subscribedPlan ;
}
if ( $scope . organization && ! PlanService . isOrgCompatible ( plan ) ) {
return false ;
}
return true ;
2013-11-06 22:30:20 +00:00
} ;
2014-08-28 20:10:06 +00:00
$scope . changeSubscription = function ( planId , opt _async ) {
2013-11-06 22:30:20 +00:00
if ( $scope . planChanging ) { return ; }
2013-11-09 01:32:56 +00:00
var callbacks = {
'opening' : function ( ) { $scope . planChanging = true ; } ,
'started' : function ( ) { $scope . planChanging = true ; } ,
'opened' : function ( ) { $scope . planChanging = true ; } ,
'closed' : function ( ) { $scope . planChanging = false ; } ,
'success' : subscribedToPlan ,
2014-11-24 21:07:38 +00:00
'failure' : function ( resp ) {
2013-11-19 22:06:17 +00:00
$scope . planChanging = false ;
}
2013-11-09 01:32:56 +00:00
} ;
2014-08-28 20:10:06 +00:00
PlanService . changePlan ( $scope , $scope . organization , planId , callbacks , opt _async ) ;
2013-11-06 22:30:20 +00:00
} ;
$scope . cancelSubscription = function ( ) {
2013-12-20 02:51:46 +00:00
$scope . changeSubscription ( PlanService . getFreePlan ( ) ) ;
2013-11-06 22:30:20 +00:00
} ;
var subscribedToPlan = function ( sub ) {
$scope . subscription = sub ;
2014-04-23 05:17:34 +00:00
$scope . isExistingCustomer = ! ! sub [ 'isExistingCustomer' ] ;
2013-11-06 22:30:20 +00:00
2013-12-20 02:51:46 +00:00
PlanService . getPlanIncludingDeprecated ( sub . plan , function ( subscribedPlan ) {
2013-11-06 22:30:20 +00:00
$scope . subscribedPlan = subscribedPlan ;
$scope . planUsagePercent = sub . usedPrivateRepos * 100 / $scope . subscribedPlan . privateRepos ;
2014-11-24 21:07:38 +00:00
2013-11-15 23:17:12 +00:00
if ( $scope . planChanged ) {
$scope . planChanged ( { 'plan' : subscribedPlan } ) ;
}
2013-11-06 22:30:20 +00:00
$scope . planChanging = false ;
$scope . planLoading = false ;
} ) ;
} ;
var update = function ( ) {
$scope . planLoading = true ;
if ( ! $scope . plans ) { return ; }
PlanService . getSubscription ( $scope . organization , subscribedToPlan , function ( ) {
2014-04-23 05:17:34 +00:00
$scope . isExistingCustomer = false ;
2013-12-20 02:51:46 +00:00
subscribedToPlan ( { 'plan' : PlanService . getFreePlan ( ) } ) ;
2013-11-06 22:30:20 +00:00
} ) ;
} ;
var loadPlans = function ( ) {
2013-11-07 20:33:56 +00:00
if ( $scope . plans || $scope . loadingPlans ) { return ; }
2013-11-06 22:59:16 +00:00
if ( ! $scope . user && ! $scope . organization ) { return ; }
2013-11-06 23:14:22 +00:00
2013-11-07 20:33:56 +00:00
$scope . loadingPlans = true ;
2013-12-20 02:51:46 +00:00
PlanService . verifyLoaded ( function ( plans ) {
$scope . plans = plans ;
2013-11-06 22:30:20 +00:00
update ( ) ;
2014-11-24 21:07:38 +00:00
2013-11-06 23:14:22 +00:00
if ( $scope . readyForPlan ) {
var planRequested = $scope . readyForPlan ( ) ;
2013-12-20 02:51:46 +00:00
if ( planRequested && planRequested != PlanService . getFreePlan ( ) ) {
2014-08-28 20:10:06 +00:00
$scope . changeSubscription ( planRequested , /* async */ true ) ;
2013-11-06 23:14:22 +00:00
}
}
2013-11-06 22:30:20 +00:00
} ) ;
} ;
// Start the initial download.
2013-11-06 22:59:16 +00:00
$scope . planLoading = true ;
loadPlans ( ) ;
2013-11-06 22:30:20 +00:00
2013-11-07 00:19:21 +00:00
$scope . $watch ( 'organization' , loadPlans ) ;
$scope . $watch ( 'user' , loadPlans ) ;
2013-11-06 22:30:20 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-11-01 21:35:26 +00:00
quayApp . directive ( 'namespaceSelector' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/namespace-selector.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'user' : '=user' ,
2013-11-07 05:49:13 +00:00
'namespace' : '=namespace' ,
'requireCreate' : '=requireCreate'
2013-11-01 21:35:26 +00:00
} ,
2014-08-29 19:46:43 +00:00
controller : function ( $scope , $element , $routeParams , $location , CookieService ) {
2013-11-07 05:49:13 +00:00
$scope . namespaces = { } ;
$scope . initialize = function ( user ) {
2014-01-16 00:15:38 +00:00
var preferredNamespace = user . username ;
2013-11-07 05:49:13 +00:00
var namespaces = { } ;
namespaces [ user . username ] = user ;
2013-11-07 06:48:58 +00:00
if ( user . organizations ) {
for ( var i = 0 ; i < user . organizations . length ; ++ i ) {
namespaces [ user . organizations [ i ] . name ] = user . organizations [ i ] ;
2014-01-16 00:15:38 +00:00
if ( user . organizations [ i ] . preferred _namespace ) {
preferredNamespace = user . organizations [ i ] . name ;
}
2013-11-07 06:48:58 +00:00
}
2013-11-07 05:49:13 +00:00
}
2014-01-16 00:15:38 +00:00
var initialNamespace = $routeParams [ 'namespace' ] || CookieService . get ( 'quay.namespace' ) ||
preferredNamespace || $scope . user . username ;
2013-11-07 05:49:13 +00:00
$scope . namespaces = namespaces ;
$scope . setNamespace ( $scope . namespaces [ initialNamespace ] ) ;
} ;
2013-11-01 21:35:26 +00:00
$scope . setNamespace = function ( namespaceObj ) {
if ( ! namespaceObj ) {
2013-11-07 05:49:13 +00:00
namespaceObj = $scope . namespaces [ $scope . user . username ] ;
}
if ( $scope . requireCreate && ! namespaceObj . can _create _repo ) {
namespaceObj = $scope . namespaces [ $scope . user . username ] ;
2013-11-01 21:35:26 +00:00
}
2013-11-07 05:49:13 +00:00
2014-11-24 21:07:38 +00:00
var newNamespace = namespaceObj . name || namespaceObj . username ;
2013-11-01 21:35:26 +00:00
$scope . namespaceObj = namespaceObj ;
2013-11-07 05:49:13 +00:00
$scope . namespace = newNamespace ;
2013-12-17 20:03:34 +00:00
if ( newNamespace ) {
CookieService . putPermanent ( 'quay.namespace' , newNamespace ) ;
2014-08-29 19:46:43 +00:00
if ( $routeParams [ 'namespace' ] && $routeParams [ 'namespace' ] != newNamespace ) {
$location . search ( { 'namespace' : newNamespace } ) ;
}
2013-12-17 20:03:34 +00:00
}
2013-11-01 21:35:26 +00:00
} ;
2014-01-16 00:15:38 +00:00
$scope . $watch ( 'namespace' , function ( namespace ) {
if ( $scope . namespaceObj && namespace && namespace != $scope . namespaceObj . username ) {
$scope . setNamespace ( $scope . namespaces [ namespace ] ) ;
}
} ) ;
2013-11-01 21:35:26 +00:00
$scope . $watch ( 'user' , function ( user ) {
2013-11-07 05:49:13 +00:00
$scope . user = user ;
$scope . initialize ( user ) ;
2013-11-01 21:35:26 +00:00
} ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-02-13 02:16:11 +00:00
quayApp . directive ( 'buildLogPhase' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/build-log-phase.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'phase' : '=phase'
} ,
controller : function ( $scope , $element ) {
}
} ;
return directiveDefinitionObject ;
} ) ;
quayApp . directive ( 'buildLogError' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/build-log-error.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
2014-08-19 00:34:39 +00:00
'error' : '=error' ,
'entries' : '=entries'
2014-02-13 02:16:11 +00:00
} ,
2014-08-19 00:34:39 +00:00
controller : function ( $scope , $element , Config ) {
2014-11-21 19:27:06 +00:00
$scope . isInternalError = function ( ) {
var entry = $scope . entries [ $scope . entries . length - 1 ] ;
return entry && entry . data && entry . data [ 'internal_error' ] ;
} ;
2014-08-19 00:34:39 +00:00
$scope . getLocalPullInfo = function ( ) {
if ( $scope . entries . _ _localpull !== undefined ) {
return $scope . entries . _ _localpull ;
}
var localInfo = {
'isLocal' : false
} ;
// Find the 'pulling' phase entry, and then extra any metadata found under
// it.
for ( var i = 0 ; i < $scope . entries . length ; ++ i ) {
var entry = $scope . entries [ i ] ;
if ( entry . type == 'phase' && entry . message == 'pulling' ) {
for ( var j = 0 ; j < entry . logs . length ( ) ; ++ j ) {
var log = entry . logs . get ( j ) ;
if ( log . data && log . data . phasestep == 'login' ) {
localInfo [ 'login' ] = log . data ;
}
if ( log . data && log . data . phasestep == 'pull' ) {
var repo _url = log . data [ 'repo_url' ] ;
var repo _and _tag = repo _url . substring ( Config . SERVER _HOSTNAME . length + 1 ) ;
var tagIndex = repo _and _tag . lastIndexOf ( ':' ) ;
var repo = repo _and _tag . substring ( 0 , tagIndex ) ;
localInfo [ 'repo_url' ] = repo _url ;
2014-11-24 21:07:38 +00:00
localInfo [ 'repo' ] = repo ;
2014-08-19 00:34:39 +00:00
localInfo [ 'isLocal' ] = repo _url . indexOf ( Config . SERVER _HOSTNAME + '/' ) == 0 ;
}
}
break ;
}
}
return $scope . entries . _ _localpull = localInfo ;
} ;
2014-02-13 02:16:11 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-02-20 18:27:59 +00:00
quayApp . directive ( 'triggerDescription' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/trigger-description.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
2014-03-05 21:27:56 +00:00
'trigger' : '=trigger' ,
'short' : '=short'
2014-02-20 18:27:59 +00:00
} ,
2014-11-26 17:54:02 +00:00
controller : function ( $scope , $element , KeyService , TriggerService ) {
$scope . KeyService = KeyService ;
$scope . TriggerService = TriggerService ;
2014-02-20 18:27:59 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-10-14 19:46:35 +00:00
quayApp . directive ( 'stepView' , function ( $compile ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/step-view.html' ,
replace : true ,
transclude : true ,
restrict : 'C' ,
scope : {
'nextStepCounter' : '=nextStepCounter' ,
'currentStepValid' : '=currentStepValid' ,
'stepsCompleted' : '&stepsCompleted'
} ,
controller : function ( $scope , $element , $rootScope ) {
this . currentStepIndex = - 1 ;
this . steps = [ ] ;
this . watcher = null ;
this . getCurrentStep = function ( ) {
return this . steps [ this . currentStepIndex ] ;
} ;
this . reset = function ( ) {
this . currentStepIndex = - 1 ;
for ( var i = 0 ; i < this . steps . length ; ++ i ) {
this . steps [ i ] . element . hide ( ) ;
}
$scope . currentStepValid = false ;
} ;
this . next = function ( ) {
if ( this . currentStepIndex >= 0 ) {
2014-11-10 16:37:52 +00:00
var currentStep = this . getCurrentStep ( ) ;
if ( ! currentStep || ! currentStep . scope ) { return ; }
if ( ! currentStep . scope . completeCondition ) {
2014-10-14 19:46:35 +00:00
return ;
}
2014-11-10 16:37:52 +00:00
currentStep . element . hide ( ) ;
2014-10-14 19:46:35 +00:00
if ( this . unwatch ) {
this . unwatch ( ) ;
this . unwatch = null ;
}
}
this . currentStepIndex ++ ;
if ( this . currentStepIndex < this . steps . length ) {
var currentStep = this . getCurrentStep ( ) ;
currentStep . element . show ( ) ;
currentStep . scope . load ( )
this . unwatch = currentStep . scope . $watch ( 'completeCondition' , function ( cc ) {
$scope . currentStepValid = ! ! cc ;
} ) ;
} else {
$scope . stepsCompleted ( ) ;
}
} ;
this . register = function ( scope , element ) {
element . hide ( ) ;
this . steps . push ( {
'scope' : scope ,
'element' : element
} ) ;
} ;
var that = this ;
$scope . $watch ( 'nextStepCounter' , function ( nsc ) {
if ( nsc >= 0 ) {
that . next ( ) ;
} else {
that . reset ( ) ;
}
} ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
quayApp . directive ( 'stepViewStep' , function ( ) {
var directiveDefinitionObject = {
priority : 1 ,
require : '^stepView' ,
templateUrl : '/static/directives/step-view-step.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
'completeCondition' : '=completeCondition' ,
'loadCallback' : '&loadCallback' ,
'loadMessage' : '@loadMessage'
} ,
link : function ( scope , element , attrs , controller ) {
controller . register ( scope , element ) ;
} ,
controller : function ( $scope , $element ) {
$scope . load = function ( ) {
$scope . loading = true ;
$scope . loadCallback ( { 'callback' : function ( ) {
$scope . loading = false ;
} } ) ;
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-02-25 01:36:54 +00:00
quayApp . directive ( 'dropdownSelect' , function ( $compile ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/dropdown-select.html' ,
replace : true ,
transclude : true ,
restrict : 'C' ,
scope : {
'selectedItem' : '=selectedItem' ,
'placeholder' : '=placeholder' ,
'lookaheadItems' : '=lookaheadItems' ,
2014-09-08 16:17:00 +00:00
'allowCustomInput' : '@allowCustomInput' ,
2014-02-25 01:36:54 +00:00
'handleItemSelected' : '&handleItemSelected' ,
2014-07-18 20:51:05 +00:00
'handleInput' : '&handleInput' ,
'clearValue' : '=clearValue'
2014-02-25 01:36:54 +00:00
} ,
controller : function ( $scope , $element , $rootScope ) {
if ( ! $rootScope . _ _dropdownSelectCounter ) {
$rootScope . _ _dropdownSelectCounter = 1 ;
}
$scope . placeholder = $scope . placeholder || '' ;
$scope . internalItem = null ;
// Setup lookahead.
var input = $ ( $element ) . find ( '.lookahead-input' ) ;
2014-11-24 21:07:38 +00:00
2014-07-18 20:51:05 +00:00
$scope . $watch ( 'clearValue' , function ( cv ) {
if ( cv ) {
$scope . selectedItem = null ;
$ ( input ) . val ( '' ) ;
}
} ) ;
2014-02-25 01:36:54 +00:00
$scope . $watch ( 'selectedItem' , function ( item ) {
if ( $scope . selectedItem == $scope . internalItem ) {
// The item has already been set due to an internal action.
return ;
}
if ( $scope . selectedItem != null ) {
$ ( input ) . val ( item . toString ( ) ) ;
} else {
$ ( input ) . val ( '' ) ;
}
} ) ;
$scope . $watch ( 'lookaheadItems' , function ( items ) {
$ ( input ) . off ( ) ;
if ( ! items ) {
return ;
}
2014-03-08 02:06:31 +00:00
var formattedItems = [ ] ;
for ( var i = 0 ; i < items . length ; ++ i ) {
var formattedItem = items [ i ] ;
if ( typeof formattedItem == 'string' ) {
formattedItem = {
'value' : formattedItem
} ;
}
formattedItems . push ( formattedItem ) ;
}
var dropdownHound = new Bloodhound ( {
2014-02-25 01:36:54 +00:00
name : 'dropdown-items-' + $rootScope . _ _dropdownSelectCounter ,
2014-03-08 02:06:31 +00:00
local : formattedItems ,
datumTokenizer : function ( d ) {
return Bloodhound . tokenizers . whitespace ( d . val || d . value || '' ) ;
} ,
2014-11-24 21:07:38 +00:00
queryTokenizer : Bloodhound . tokenizers . whitespace
2014-03-08 02:06:31 +00:00
} ) ;
dropdownHound . initialize ( ) ;
$ ( input ) . typeahead ( { } , {
source : dropdownHound . ttAdapter ( ) ,
templates : {
'suggestion' : function ( datum ) {
template = datum [ 'template' ] ? datum [ 'template' ] ( datum ) : datum [ 'value' ] ;
return template ;
}
2014-02-25 01:36:54 +00:00
}
} ) ;
$ ( input ) . on ( 'input' , function ( e ) {
$scope . $apply ( function ( ) {
$scope . internalItem = null ;
$scope . selectedItem = null ;
if ( $scope . handleInput ) {
$scope . handleInput ( { 'input' : $ ( input ) . val ( ) } ) ;
}
} ) ;
} ) ;
$ ( input ) . on ( 'typeahead:selected' , function ( e , datum ) {
$scope . $apply ( function ( ) {
$scope . internalItem = datum [ 'item' ] || datum [ 'value' ] ;
$scope . selectedItem = datum [ 'item' ] || datum [ 'value' ] ;
if ( $scope . handleItemSelected ) {
$scope . handleItemSelected ( { 'datum' : datum } ) ;
}
} ) ;
} ) ;
$rootScope . _ _dropdownSelectCounter ++ ;
} ) ;
} ,
link : function ( scope , element , attrs ) {
var transcludedBlock = element . find ( 'div.transcluded' ) ;
var transcludedElements = transcludedBlock . children ( ) ;
var iconContainer = element . find ( 'div.dropdown-select-icon-transclude' ) ;
var menuContainer = element . find ( 'div.dropdown-select-menu-transclude' ) ;
2014-11-24 21:07:38 +00:00
2014-02-25 01:36:54 +00:00
angular . forEach ( transcludedElements , function ( elem ) {
if ( angular . element ( elem ) . hasClass ( 'dropdown-select-icon' ) ) {
iconContainer . append ( elem ) ;
} else if ( angular . element ( elem ) . hasClass ( 'dropdown-select-menu' ) ) {
menuContainer . replaceWith ( elem ) ;
}
} ) ;
2014-11-24 21:07:38 +00:00
transcludedBlock . remove ( ) ;
2014-02-25 01:36:54 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
quayApp . directive ( 'dropdownSelectIcon' , function ( ) {
var directiveDefinitionObject = {
priority : 1 ,
require : '^dropdownSelect' ,
templateUrl : '/static/directives/dropdown-select-icon.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
} ,
controller : function ( $scope , $element ) {
}
} ;
return directiveDefinitionObject ;
} ) ;
quayApp . directive ( 'dropdownSelectMenu' , function ( ) {
var directiveDefinitionObject = {
priority : 1 ,
require : '^dropdownSelect' ,
templateUrl : '/static/directives/dropdown-select-menu.html' ,
replace : true ,
transclude : true ,
restrict : 'C' ,
scope : {
} ,
controller : function ( $scope , $element ) {
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-09-30 20:29:32 +00:00
quayApp . directive ( 'manualTriggerBuildDialog' , function ( ) {
var directiveDefinitionObject = {
templateUrl : '/static/directives/manual-trigger-build-dialog.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'repository' : '=repository' ,
'counter' : '=counter' ,
'trigger' : '=trigger' ,
'startBuild' : '&startBuild'
} ,
controller : function ( $scope , $element , ApiService , TriggerService ) {
$scope . parameters = { } ;
$scope . fieldOptions = { } ;
$scope . startTrigger = function ( ) {
$ ( '#startTriggerDialog' ) . modal ( 'hide' ) ;
$scope . startBuild ( {
'trigger' : $scope . trigger ,
'parameters' : $scope . parameters
} ) ;
} ;
$scope . show = function ( ) {
$scope . parameters = { } ;
$scope . fieldOptions = { } ;
var parameters = TriggerService . getRunParameters ( $scope . trigger . service ) ;
for ( var i = 0 ; i < parameters . length ; ++ i ) {
var parameter = parameters [ i ] ;
if ( parameter [ 'type' ] == 'option' ) {
// Load the values for this parameter.
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name ,
'trigger_uuid' : $scope . trigger . id ,
'field_name' : parameter [ 'name' ]
} ;
ApiService . listTriggerFieldValues ( null , params ) . then ( function ( resp ) {
$scope . fieldOptions [ parameter [ 'name' ] ] = resp [ 'values' ] ;
} ) ;
}
}
$scope . runParameters = parameters ;
$ ( '#startTriggerDialog' ) . modal ( 'show' ) ;
} ;
$scope . $watch ( 'counter' , function ( counter ) {
if ( counter ) {
$scope . show ( ) ;
}
} ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-04-03 03:33:58 +00:00
quayApp . directive ( 'setupTriggerDialog' , function ( ) {
var directiveDefinitionObject = {
templateUrl : '/static/directives/setup-trigger-dialog.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'repository' : '=repository' ,
'trigger' : '=trigger' ,
'counter' : '=counter' ,
'canceled' : '&canceled' ,
'activated' : '&activated'
} ,
controller : function ( $scope , $element , ApiService , UserService ) {
2014-04-16 21:50:25 +00:00
var modalSetup = false ;
2014-10-14 19:46:35 +00:00
$scope . state = { } ;
$scope . nextStepCounter = - 1 ;
$scope . currentView = 'config' ;
2014-04-03 03:33:58 +00:00
$scope . show = function ( ) {
2014-05-19 16:35:16 +00:00
if ( ! $scope . trigger || ! $scope . repository ) { return ; }
2014-10-14 19:46:35 +00:00
$scope . currentView = 'config' ;
2014-04-03 03:33:58 +00:00
$ ( '#setupTriggerModal' ) . modal ( { } ) ;
2014-04-16 21:50:25 +00:00
if ( ! modalSetup ) {
$ ( '#setupTriggerModal' ) . on ( 'hidden.bs.modal' , function ( ) {
2014-05-19 16:35:16 +00:00
if ( ! $scope . trigger || $scope . trigger [ 'is_active' ] ) { return ; }
2014-04-16 21:50:25 +00:00
2014-10-14 19:46:35 +00:00
$scope . nextStepCounter = - 1 ;
2014-04-16 21:50:25 +00:00
$scope . $apply ( function ( ) {
$scope . cancelSetupTrigger ( ) ;
} ) ;
2014-04-03 03:33:58 +00:00
} ) ;
2014-10-14 19:46:35 +00:00
2014-04-16 21:50:25 +00:00
modalSetup = true ;
2014-10-14 19:46:35 +00:00
$scope . nextStepCounter = 0 ;
2014-04-16 21:50:25 +00:00
}
2014-04-03 03:33:58 +00:00
} ;
$scope . isNamespaceAdmin = function ( namespace ) {
return UserService . isNamespaceAdmin ( namespace ) ;
} ;
$scope . cancelSetupTrigger = function ( ) {
$scope . canceled ( { 'trigger' : $scope . trigger } ) ;
} ;
$scope . hide = function ( ) {
$ ( '#setupTriggerModal' ) . modal ( 'hide' ) ;
} ;
$scope . checkAnalyze = function ( isValid ) {
2014-10-14 19:46:35 +00:00
$scope . currentView = 'analyzing' ;
$scope . pullInfo = {
'is_public' : true
} ;
2014-04-03 03:33:58 +00:00
if ( ! isValid ) {
2014-10-14 19:46:35 +00:00
$scope . currentView = 'analyzed' ;
2014-04-03 03:33:58 +00:00
return ;
}
2014-11-24 21:07:38 +00:00
2014-04-03 03:33:58 +00:00
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name ,
'trigger_uuid' : $scope . trigger . id
} ;
var data = {
'config' : $scope . trigger . config
} ;
ApiService . analyzeBuildTrigger ( data , params ) . then ( function ( resp ) {
2014-10-14 19:46:35 +00:00
$scope . currentView = 'analyzed' ;
2014-04-03 03:33:58 +00:00
2014-10-14 19:46:35 +00:00
if ( resp [ 'status' ] == 'analyzed' ) {
2014-04-03 03:33:58 +00:00
if ( resp [ 'robots' ] && resp [ 'robots' ] . length > 0 ) {
2014-10-14 19:46:35 +00:00
$scope . pullInfo [ 'pull_entity' ] = resp [ 'robots' ] [ 0 ] ;
} else {
$scope . pullInfo [ 'pull_entity' ] = null ;
2014-04-03 03:33:58 +00:00
}
2014-10-14 19:46:35 +00:00
$scope . pullInfo [ 'is_public' ] = false ;
2014-04-03 03:33:58 +00:00
}
2014-10-14 19:46:35 +00:00
$scope . pullInfo [ 'analysis' ] = resp ;
} , ApiService . errorDisplay ( 'Cannot load Dockerfile information' ) ) ;
2014-04-03 03:33:58 +00:00
} ;
$scope . activate = function ( ) {
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name ,
'trigger_uuid' : $scope . trigger . id
} ;
var data = {
'config' : $scope . trigger [ 'config' ]
} ;
2014-10-20 21:41:48 +00:00
if ( $scope . pullInfo [ 'pull_entity' ] ) {
data [ 'pull_robot' ] = $scope . pullInfo [ 'pull_entity' ] [ 'name' ] ;
2014-04-03 03:33:58 +00:00
}
2014-10-14 19:46:35 +00:00
$scope . currentView = 'activating' ;
2014-04-16 21:50:25 +00:00
2014-08-18 22:21:53 +00:00
var errorHandler = ApiService . errorDisplay ( 'Cannot activate build trigger' , function ( resp ) {
$scope . hide ( ) ;
$scope . canceled ( { 'trigger' : $scope . trigger } ) ;
} ) ;
2014-04-03 03:33:58 +00:00
ApiService . activateBuildTrigger ( data , params ) . then ( function ( resp ) {
2014-04-16 21:50:25 +00:00
$scope . hide ( ) ;
$scope . trigger [ 'is_active' ] = true ;
$scope . trigger [ 'pull_robot' ] = resp [ 'pull_robot' ] ;
2014-04-03 03:33:58 +00:00
$scope . activated ( { 'trigger' : $scope . trigger } ) ;
2014-08-18 22:21:53 +00:00
} , errorHandler ) ;
2014-04-03 03:33:58 +00:00
} ;
var check = function ( ) {
if ( $scope . counter && $scope . trigger && $scope . repository ) {
$scope . show ( ) ;
}
} ;
$scope . $watch ( 'trigger' , check ) ;
$scope . $watch ( 'counter' , check ) ;
$scope . $watch ( 'repository' , check ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-02-20 23:57:49 +00:00
quayApp . directive ( 'triggerSetupGithub' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/trigger-setup-github.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'repository' : '=repository' ,
2014-04-03 03:33:58 +00:00
'trigger' : '=trigger' ,
2014-10-14 19:46:35 +00:00
'nextStepCounter' : '=nextStepCounter' ,
'currentStepValid' : '=currentStepValid' ,
2014-04-03 03:33:58 +00:00
'analyze' : '&analyze'
2014-02-20 23:57:49 +00:00
} ,
controller : function ( $scope , $element , ApiService ) {
2014-04-03 03:33:58 +00:00
$scope . analyzeCounter = 0 ;
2014-02-20 23:57:49 +00:00
$scope . setupReady = false ;
2014-10-23 20:39:10 +00:00
$scope . refs = null ;
2014-10-14 19:46:35 +00:00
$scope . branchNames = null ;
2014-10-23 20:39:10 +00:00
$scope . tagNames = null ;
2014-10-14 19:46:35 +00:00
$scope . state = {
2014-10-27 21:05:16 +00:00
'currentRepo' : null ,
2014-10-23 20:39:10 +00:00
'branchTagFilter' : '' ,
'hasBranchTagFilter' : false ,
2014-10-14 19:46:35 +00:00
'isInvalidLocation' : true ,
'currentLocation' : null
} ;
2014-10-23 20:39:10 +00:00
$scope . isMatching = function ( kind , name , filter ) {
2014-10-14 19:46:35 +00:00
try {
var patt = new RegExp ( filter ) ;
} catch ( ex ) {
return false ;
}
2014-10-23 20:39:10 +00:00
var fullname = ( kind + '/' + name ) ;
var m = fullname . match ( patt ) ;
return m && m [ 0 ] . length == fullname . length ;
}
$scope . addRef = function ( kind , name ) {
if ( $scope . isMatching ( kind , name , $scope . state . branchTagFilter ) ) {
return ;
}
2014-11-24 21:07:38 +00:00
2014-10-23 20:39:10 +00:00
var newFilter = kind + '/' + name ;
var existing = $scope . state . branchTagFilter ;
if ( existing ) {
$scope . state . branchTagFilter = '(' + existing + ')|(' + newFilter + ')' ;
} else {
$scope . state . branchTagFilter = newFilter ;
}
2014-10-14 19:46:35 +00:00
}
$scope . stepsCompleted = function ( ) {
$scope . analyze ( { 'isValid' : ! $scope . state . isInvalidLocation } ) ;
} ;
$scope . loadRepositories = function ( callback ) {
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name ,
'trigger_uuid' : $scope . trigger . id
} ;
ApiService . listTriggerBuildSources ( null , params ) . then ( function ( resp ) {
$scope . orgs = resp [ 'sources' ] ;
setupTypeahead ( ) ;
callback ( ) ;
} , ApiService . errorDisplay ( 'Cannot load repositories' ) ) ;
} ;
2014-10-23 20:39:10 +00:00
$scope . loadBranchesAndTags = function ( callback ) {
2014-10-14 19:46:35 +00:00
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name ,
'trigger_uuid' : $scope . trigger [ 'id' ] ,
2014-10-23 20:39:10 +00:00
'field_name' : 'refs'
2014-10-14 19:46:35 +00:00
} ;
ApiService . listTriggerFieldValues ( $scope . trigger [ 'config' ] , params ) . then ( function ( resp ) {
2014-10-23 20:39:10 +00:00
$scope . refs = resp [ 'values' ] ;
$scope . branchNames = [ ] ;
$scope . tagNames = [ ] ;
for ( var i = 0 ; i < $scope . refs . length ; ++ i ) {
var ref = $scope . refs [ i ] ;
if ( ref . kind == 'branch' ) {
$scope . branchNames . push ( ref . name ) ;
} else {
2014-11-24 21:07:38 +00:00
$scope . tagNames . push ( ref . name ) ;
2014-10-23 20:39:10 +00:00
}
}
2014-10-14 19:46:35 +00:00
callback ( ) ;
2014-10-23 20:39:10 +00:00
} , ApiService . errorDisplay ( 'Cannot load branch and tag names' ) ) ;
2014-10-14 19:46:35 +00:00
} ;
$scope . loadLocations = function ( callback ) {
$scope . locations = null ;
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name ,
'trigger_uuid' : $scope . trigger . id
} ;
ApiService . listBuildTriggerSubdirs ( $scope . trigger [ 'config' ] , params ) . then ( function ( resp ) {
if ( resp [ 'status' ] == 'error' ) {
callback ( resp [ 'message' ] || 'Could not load Dockerfile locations' ) ;
return ;
}
$scope . locations = resp [ 'subdir' ] || [ ] ;
// Select a default location (if any).
if ( $scope . locations . length > 0 ) {
$scope . setLocation ( $scope . locations [ 0 ] ) ;
} else {
$scope . state . currentLocation = null ;
$scope . state . isInvalidLocation = resp [ 'subdir' ] . indexOf ( '' ) < 0 ;
$scope . trigger . $ready = true ;
}
callback ( ) ;
2014-11-24 21:07:38 +00:00
} , ApiService . errorDisplay ( 'Cannot load locations' ) ) ;
2014-10-14 19:46:35 +00:00
}
2014-11-24 21:07:38 +00:00
2014-02-25 05:19:38 +00:00
$scope . handleLocationInput = function ( location ) {
2014-10-14 19:46:35 +00:00
$scope . state . isInvalidLocation = $scope . locations . indexOf ( location ) < 0 ;
2014-02-25 05:19:38 +00:00
$scope . trigger [ 'config' ] [ 'subdir' ] = location || '' ;
2014-10-14 19:46:35 +00:00
$scope . trigger . $ready = true ;
2014-02-25 05:19:38 +00:00
} ;
2014-03-08 02:06:31 +00:00
$scope . handleLocationSelected = function ( datum ) {
$scope . setLocation ( datum [ 'value' ] ) ;
} ;
2014-02-25 01:36:54 +00:00
$scope . setLocation = function ( location ) {
2014-10-14 19:46:35 +00:00
$scope . state . currentLocation = location ;
$scope . state . isInvalidLocation = false ;
2014-02-25 01:36:54 +00:00
$scope . trigger [ 'config' ] [ 'subdir' ] = location || '' ;
2014-10-14 19:46:35 +00:00
$scope . trigger . $ready = true ;
2014-02-20 23:57:49 +00:00
} ;
2014-11-24 21:07:38 +00:00
2014-02-20 23:57:49 +00:00
$scope . selectRepo = function ( repo , org ) {
2014-10-27 21:05:16 +00:00
$scope . state . currentRepo = {
2014-02-25 01:36:54 +00:00
'repo' : repo ,
'avatar_url' : org [ 'info' ] [ 'avatar_url' ] ,
'toString' : function ( ) {
return this . repo ;
}
} ;
2014-02-20 23:57:49 +00:00
} ;
2014-02-25 01:36:54 +00:00
$scope . selectRepoInternal = function ( currentRepo ) {
2014-10-14 19:46:35 +00:00
$scope . trigger . $ready = false ;
2014-02-25 01:36:54 +00:00
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name ,
'trigger_uuid' : $scope . trigger [ 'id' ]
2014-02-20 23:57:49 +00:00
} ;
2014-02-25 01:36:54 +00:00
var repo = currentRepo [ 'repo' ] ;
2014-02-20 23:57:49 +00:00
$scope . trigger [ 'config' ] = {
2014-02-25 01:36:54 +00:00
'build_source' : repo ,
'subdir' : ''
2014-02-20 23:57:49 +00:00
} ;
} ;
2014-11-24 21:07:38 +00:00
var setupTypeahead = function ( ) {
2014-02-20 23:57:49 +00:00
var repos = [ ] ;
for ( var i = 0 ; i < $scope . orgs . length ; ++ i ) {
var org = $scope . orgs [ i ] ;
var orepos = org [ 'repos' ] ;
for ( var j = 0 ; j < orepos . length ; ++ j ) {
2014-02-25 01:36:54 +00:00
var repoValue = {
'repo' : orepos [ j ] ,
'avatar_url' : org [ 'info' ] [ 'avatar_url' ] ,
'toString' : function ( ) {
return this . repo ;
}
} ;
var datum = {
'name' : orepos [ j ] ,
'org' : org ,
'value' : orepos [ j ] ,
'title' : orepos [ j ] ,
'item' : repoValue
} ;
repos . push ( datum ) ;
2014-02-20 23:57:49 +00:00
}
}
2014-02-25 01:36:54 +00:00
$scope . repoLookahead = repos ;
2014-02-20 23:57:49 +00:00
} ;
2014-10-27 21:05:16 +00:00
$scope . $watch ( 'state.currentRepo' , function ( repo ) {
2014-11-24 21:07:38 +00:00
if ( repo ) {
2014-10-14 19:46:35 +00:00
$scope . selectRepoInternal ( repo ) ;
2014-04-03 03:33:58 +00:00
}
2014-10-14 19:46:35 +00:00
} ) ;
2014-04-03 03:33:58 +00:00
2014-10-23 20:39:10 +00:00
$scope . $watch ( 'state.branchTagFilter' , function ( bf ) {
2014-10-14 19:46:35 +00:00
if ( ! $scope . trigger ) { return ; }
2014-02-20 23:57:49 +00:00
2014-10-23 20:39:10 +00:00
if ( $scope . state . hasBranchTagFilter ) {
$scope . trigger [ 'config' ] [ 'branchtag_regex' ] = bf ;
2014-10-14 19:46:35 +00:00
} else {
2014-10-23 20:39:10 +00:00
delete $scope . trigger [ 'config' ] [ 'branchtag_regex' ] ;
2014-10-14 19:46:35 +00:00
}
2014-02-20 23:57:49 +00:00
} ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-02-13 02:16:11 +00:00
quayApp . directive ( 'buildLogCommand' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/build-log-command.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'command' : '=command'
} ,
2014-02-17 23:31:45 +00:00
controller : function ( $scope , $element ) {
$scope . getWithoutStep = function ( fullTitle ) {
var colon = fullTitle . indexOf ( ':' ) ;
if ( colon <= 0 ) {
return '' ;
}
2014-11-24 21:07:38 +00:00
2014-02-17 23:31:45 +00:00
return $ . trim ( fullTitle . substring ( colon + 1 ) ) ;
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
quayApp . directive ( 'dockerfileCommand' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/dockerfile-command.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'command' : '=command'
} ,
2014-05-01 17:59:25 +00:00
controller : function ( $scope , $element , UtilService , Config ) {
2014-02-13 02:16:11 +00:00
var registryHandlers = {
'quay.io' : function ( pieces ) {
var rnamespace = pieces [ pieces . length - 2 ] ;
2014-02-17 23:31:45 +00:00
var rname = pieces [ pieces . length - 1 ] . split ( ':' ) [ 0 ] ;
2014-11-24 21:07:38 +00:00
return '/repository/' + rnamespace + '/' + rname + '/' ;
2014-02-13 02:16:11 +00:00
} ,
'' : function ( pieces ) {
2014-07-17 18:36:06 +00:00
var rnamespace = pieces . length == 1 ? '_' : 'u/' + pieces [ 0 ] ;
2014-02-17 23:31:45 +00:00
var rname = pieces [ pieces . length - 1 ] . split ( ':' ) [ 0 ] ;
2014-07-14 20:34:21 +00:00
return 'https://registry.hub.docker.com/' + rnamespace + '/' + rname + '/' ;
2014-02-13 02:16:11 +00:00
}
} ;
2014-04-09 00:33:20 +00:00
registryHandlers [ Config . getDomain ( ) ] = registryHandlers [ 'quay.io' ] ;
2014-02-13 02:16:11 +00:00
var kindHandlers = {
'FROM' : function ( title ) {
var pieces = title . split ( '/' ) ;
2014-02-13 02:32:46 +00:00
var registry = pieces . length < 3 ? '' : pieces [ 0 ] ;
2014-02-13 02:16:11 +00:00
if ( ! registryHandlers [ registry ] ) {
return title ;
}
2014-11-24 21:07:38 +00:00
2014-02-13 20:08:10 +00:00
return '<i class="fa fa-hdd-o"></i> <a href="' + registryHandlers [ registry ] ( pieces ) + '" target="_blank">' + title + '</a>' ;
2014-02-13 02:16:11 +00:00
}
} ;
2014-11-24 21:07:38 +00:00
2014-02-17 23:31:45 +00:00
$scope . getCommandKind = function ( title ) {
2014-02-13 02:16:11 +00:00
var space = title . indexOf ( ' ' ) ;
return title . substring ( 0 , space ) ;
} ;
2014-02-17 23:31:45 +00:00
$scope . getCommandTitleHtml = function ( title ) {
2014-02-13 02:16:11 +00:00
var space = title . indexOf ( ' ' ) ;
if ( space <= 0 ) {
2014-05-01 17:59:25 +00:00
return UtilService . textToSafeHtml ( title ) ;
2014-02-13 02:16:11 +00:00
}
2014-11-24 21:07:38 +00:00
2014-02-17 23:31:45 +00:00
var kind = $scope . getCommandKind ( title ) ;
2014-05-01 17:59:25 +00:00
var sanitized = UtilService . textToSafeHtml ( title . substring ( space + 1 ) ) ;
2014-11-24 21:07:38 +00:00
2014-02-13 02:16:11 +00:00
var handler = kindHandlers [ kind || '' ] ;
if ( handler ) {
return handler ( sanitized ) ;
} else {
return sanitized ;
}
2014-11-24 21:07:38 +00:00
} ;
2014-02-17 23:31:45 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-02-13 02:16:11 +00:00
2014-02-17 23:31:45 +00:00
quayApp . directive ( 'dockerfileView' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/dockerfile-view.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'contents' : '=contents'
} ,
2014-05-01 17:59:25 +00:00
controller : function ( $scope , $element , UtilService ) {
2014-02-17 23:31:45 +00:00
$scope . $watch ( 'contents' , function ( contents ) {
$scope . lines = [ ] ;
var lines = contents ? contents . split ( '\n' ) : [ ] ;
for ( var i = 0 ; i < lines . length ; ++ i ) {
var line = $ . trim ( lines [ i ] ) ;
var kind = 'text' ;
if ( line && line [ 0 ] == '#' ) {
kind = 'comment' ;
} else if ( line . match ( /^([A-Z]+\s)/ ) ) {
kind = 'command' ;
}
var lineInfo = {
2014-07-16 20:47:59 +00:00
'text' : line ,
2014-02-17 23:31:45 +00:00
'kind' : kind
} ;
$scope . lines . push ( lineInfo ) ;
2014-02-13 02:16:11 +00:00
}
2014-02-17 23:31:45 +00:00
} ) ;
2014-02-13 02:16:11 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-02-17 23:31:45 +00:00
2013-10-26 20:03:11 +00:00
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 ) {
2014-02-10 20:15:23 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
quayApp . directive ( 'buildMessage' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/build-message.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
2014-02-13 02:16:11 +00:00
'phase' : '=phase'
2014-02-10 20:15:23 +00:00
} ,
controller : function ( $scope , $element ) {
2014-02-13 02:16:11 +00:00
$scope . getBuildMessage = function ( phase ) {
switch ( phase ) {
2014-03-25 17:29:06 +00:00
case 'cannot_load' :
return 'Cannot load build status - Please report this error' ;
2014-02-10 20:15:23 +00:00
case 'starting' :
case 'initializing' :
return 'Starting Dockerfile build' ;
2014-11-24 21:07:38 +00:00
2014-02-10 20:15:23 +00:00
case 'waiting' :
2014-02-13 02:16:11 +00:00
return 'Waiting for available build worker' ;
2014-04-30 22:48:36 +00:00
2014-08-15 21:58:11 +00:00
case 'unpacking' :
return 'Unpacking build package' ;
2014-04-30 22:48:36 +00:00
case 'pulling' :
return 'Pulling base image' ;
2014-11-24 21:07:38 +00:00
2014-02-10 20:15:23 +00:00
case 'building' :
return 'Building image from Dockerfile' ;
2014-11-24 21:07:38 +00:00
2014-11-14 00:41:17 +00:00
case 'priming-cache' :
return 'Priming cache for build' ;
2014-11-23 20:45:55 +00:00
2014-02-10 20:15:23 +00:00
case 'pushing' :
return 'Pushing image built from Dockerfile' ;
2014-11-24 21:07:38 +00:00
2014-02-10 20:15:23 +00:00
case 'complete' :
return 'Dockerfile build completed and pushed' ;
2014-11-24 21:07:38 +00:00
2014-02-10 20:15:23 +00:00
case 'error' :
2014-02-13 02:16:11 +00:00
return 'Dockerfile build failed' ;
2014-11-21 19:27:06 +00:00
case 'internalerror' :
2014-11-23 20:45:55 +00:00
return 'An internal system error occurred while building; the build will be retried in the next few minutes.' ;
2014-02-10 20:15:23 +00:00
}
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2013-10-26 20:03:11 +00:00
2014-02-10 20:15:23 +00:00
quayApp . directive ( 'buildProgress' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/build-progress.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'build' : '=build'
} ,
controller : function ( $scope , $element ) {
$scope . getPercentage = function ( buildInfo ) {
2014-02-06 00:59:57 +00:00
switch ( buildInfo . phase ) {
2014-04-30 22:48:36 +00:00
case 'pulling' :
return buildInfo . status . pull _completion * 100 ;
break ;
2014-02-06 00:59:57 +00:00
case 'building' :
return ( buildInfo . status . current _command / buildInfo . status . total _commands ) * 100 ;
break ;
2014-04-30 22:48:36 +00:00
2014-02-06 00:59:57 +00:00
case 'pushing' :
return buildInfo . status . push _completion * 100 ;
break ;
2013-10-26 20:03:11 +00:00
2014-11-14 00:41:17 +00:00
case 'priming-cache' :
return buildInfo . status . cache _completion * 100 ;
break ;
2014-02-06 00:59:57 +00:00
case 'complete' :
return 100 ;
break ;
case 'initializing' :
case 'starting' :
case 'waiting' :
2014-03-25 17:29:06 +00:00
case 'cannot_load' :
2014-08-15 21:58:11 +00:00
case 'unpacking' :
2014-02-06 00:59:57 +00:00
return 0 ;
break ;
}
2014-11-24 21:07:38 +00:00
2014-02-06 00:59:57 +00:00
return - 1 ;
} ;
2013-10-22 05:26:14 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-02-15 03:59:44 +00:00
2014-07-17 17:32:39 +00:00
quayApp . directive ( 'externalNotificationView' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/external-notification-view.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'repository' : '=repository' ,
'notification' : '=notification' ,
'notificationDeleted' : '¬ificationDeleted'
} ,
controller : function ( $scope , $element , ExternalNotificationData , ApiService ) {
$scope . deleteNotification = function ( ) {
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name ,
'uuid' : $scope . notification . uuid
} ;
ApiService . deleteRepoNotification ( null , params ) . then ( function ( ) {
$scope . notificationDeleted ( { 'notification' : $scope . notification } ) ;
} ) ;
} ;
$scope . testNotification = function ( ) {
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name ,
'uuid' : $scope . notification . uuid
} ;
ApiService . testRepoNotification ( null , params ) . then ( function ( ) {
bootbox . dialog ( {
2014-07-18 18:12:20 +00:00
"title" : "Test Notification Queued" ,
"message" : "A test version of this notification has been queued and should appear shortly" ,
2014-07-17 17:32:39 +00:00
"buttons" : {
"close" : {
"label" : "Close" ,
"className" : "btn-primary"
}
}
2014-11-24 21:07:38 +00:00
} ) ;
2014-07-17 17:32:39 +00:00
} ) ;
} ;
$scope . $watch ( 'notification' , function ( notification ) {
if ( notification ) {
$scope . eventInfo = ExternalNotificationData . getEventInfo ( notification . event ) ;
$scope . methodInfo = ExternalNotificationData . getMethodInfo ( notification . method ) ;
$scope . config = notification . config ;
}
} ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
quayApp . directive ( 'createExternalNotificationDialog' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/create-external-notification-dialog.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'repository' : '=repository' ,
'counter' : '=counter' ,
'notificationCreated' : '¬ificationCreated'
} ,
2014-08-19 21:40:36 +00:00
controller : function ( $scope , $element , ExternalNotificationData , ApiService , $timeout , StringBuilderService ) {
2014-07-17 17:32:39 +00:00
$scope . currentEvent = null ;
$scope . currentMethod = null ;
2014-07-28 18:58:12 +00:00
$scope . status = '' ;
2014-07-17 17:32:39 +00:00
$scope . currentConfig = { } ;
2014-07-18 20:51:05 +00:00
$scope . clearCounter = 0 ;
2014-07-28 18:58:12 +00:00
$scope . unauthorizedEmail = false ;
2014-07-17 17:32:39 +00:00
$scope . events = ExternalNotificationData . getSupportedEvents ( ) ;
$scope . methods = ExternalNotificationData . getSupportedMethods ( ) ;
2014-11-24 21:07:38 +00:00
2014-12-16 12:34:43 +00:00
$scope . getPattern = function ( field ) {
return new RegExp ( field . regex ) ;
} ;
2014-07-17 17:32:39 +00:00
$scope . setEvent = function ( event ) {
$scope . currentEvent = event ;
} ;
$scope . setMethod = function ( method ) {
$scope . currentConfig = { } ;
$scope . currentMethod = method ;
2014-07-28 18:58:12 +00:00
$scope . unauthorizedEmail = false ;
2014-07-17 17:32:39 +00:00
} ;
$scope . createNotification = function ( ) {
2014-07-28 18:58:12 +00:00
if ( ! $scope . currentConfig . email ) {
$scope . performCreateNotification ( ) ;
return ;
}
$scope . status = 'checking-email' ;
$scope . checkEmailAuthorization ( ) ;
} ;
$scope . checkEmailAuthorization = function ( ) {
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name ,
'email' : $scope . currentConfig . email
} ;
ApiService . checkRepoEmailAuthorized ( null , params ) . then ( function ( resp ) {
$scope . handleEmailCheck ( resp . confirmed ) ;
} , function ( resp ) {
$scope . handleEmailCheck ( false ) ;
} ) ;
} ;
$scope . performCreateNotification = function ( ) {
$scope . status = 'creating' ;
2014-07-17 17:32:39 +00:00
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name
} ;
var data = {
'event' : $scope . currentEvent . id ,
'method' : $scope . currentMethod . id ,
'config' : $scope . currentConfig
} ;
ApiService . createRepoNotification ( data , params ) . then ( function ( resp ) {
2014-07-28 18:58:12 +00:00
$scope . status = '' ;
2014-07-17 17:32:39 +00:00
$scope . notificationCreated ( { 'notification' : resp } ) ;
$ ( '#createNotificationModal' ) . modal ( 'hide' ) ;
} ) ;
} ;
2014-07-28 18:58:12 +00:00
$scope . handleEmailCheck = function ( isAuthorized ) {
if ( isAuthorized ) {
$scope . performCreateNotification ( ) ;
2014-11-24 21:07:38 +00:00
return ;
2014-07-28 18:58:12 +00:00
}
if ( $scope . status == 'authorizing-email-sent' ) {
$scope . watchEmail ( ) ;
} else {
$scope . status = 'unauthorized-email' ;
}
$scope . unauthorizedEmail = true ;
} ;
$scope . sendAuthEmail = function ( ) {
$scope . status = 'authorizing-email' ;
var params = {
'repository' : $scope . repository . namespace + '/' + $scope . repository . name ,
'email' : $scope . currentConfig . email
} ;
ApiService . sendAuthorizeRepoEmail ( null , params ) . then ( function ( resp ) {
$scope . status = 'authorizing-email-sent' ;
$scope . watchEmail ( ) ;
} ) ;
} ;
$scope . watchEmail = function ( ) {
// TODO: change this to SSE?
$timeout ( function ( ) {
$scope . checkEmailAuthorization ( ) ;
} , 1000 ) ;
} ;
2014-08-19 21:40:36 +00:00
$scope . getHelpUrl = function ( field , config ) {
var helpUrl = field [ 'help_url' ] ;
if ( ! helpUrl ) {
return null ;
}
return StringBuilderService . buildUrl ( helpUrl , config ) ;
} ;
2014-07-17 17:32:39 +00:00
$scope . $watch ( 'counter' , function ( counter ) {
if ( counter ) {
2014-07-18 20:51:05 +00:00
$scope . clearCounter ++ ;
2014-07-28 18:58:12 +00:00
$scope . status = '' ;
2014-07-17 17:32:39 +00:00
$scope . currentEvent = null ;
$scope . currentMethod = null ;
2014-07-28 18:58:12 +00:00
$scope . unauthorizedEmail = false ;
2014-07-17 17:32:39 +00:00
$ ( '#createNotificationModal' ) . modal ( { } ) ;
}
2014-11-24 21:07:38 +00:00
} ) ;
2014-07-17 17:32:39 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-05-08 23:52:21 +00:00
quayApp . directive ( 'twitterView' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/twitter-view.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
'avatarUrl' : '@avatarUrl' ,
'authorName' : '@authorName' ,
'authorUser' : '@authorUser' ,
'messageUrl' : '@messageUrl' ,
'messageDate' : '@messageDate'
} ,
controller : function ( $scope , $element ) {
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-08-26 19:19:39 +00:00
quayApp . directive ( 'notificationsBubble' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/notifications-bubble.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
} ,
controller : function ( $scope , UserService , NotificationService ) {
$scope . notificationService = NotificationService ;
}
} ;
2014-05-08 23:52:21 +00:00
return directiveDefinitionObject ;
} ) ;
2014-10-28 20:33:13 +00:00
quayApp . directive ( 'usageChart' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/usage-chart.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'current' : '=current' ,
'total' : '=total' ,
'limit' : '=limit' ,
'usageTitle' : '@usageTitle'
} ,
controller : function ( $scope , $element ) {
$scope . limit = "" ;
var chart = null ;
var update = function ( ) {
if ( $scope . current == null || $scope . total == null ) { return ; }
if ( ! chart ) {
chart = new UsageChart ( ) ;
chart . draw ( 'usage-chart-element' ) ;
}
var current = $scope . current || 0 ;
var total = $scope . total || 0 ;
if ( current > total ) {
$scope . limit = 'over' ;
} else if ( current == total ) {
$scope . limit = 'at' ;
} else if ( current >= total * 0.7 ) {
$scope . limit = 'near' ;
} else {
$scope . limit = 'none' ;
}
chart . update ( $scope . current , $scope . total ) ;
} ;
$scope . $watch ( 'current' , update ) ;
$scope . $watch ( 'total' , update ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-03-12 20:05:32 +00:00
quayApp . directive ( 'notificationView' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/notification-view.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'notification' : '=notification' ,
'parent' : '=parent'
} ,
2014-07-28 22:23:46 +00:00
controller : function ( $scope , $element , $window , $location , UserService , NotificationService , ApiService ) {
2014-06-27 23:18:27 +00:00
var stringStartsWith = function ( str , prefix ) {
return str . slice ( 0 , prefix . length ) == prefix ;
} ;
2014-03-12 20:05:32 +00:00
$scope . getMessage = function ( notification ) {
return NotificationService . getMessage ( notification ) ;
} ;
2014-11-25 00:25:13 +00:00
$scope . getAvatar = function ( orgname ) {
2014-03-12 23:00:24 +00:00
var organization = UserService . getOrganization ( orgname ) ;
2014-11-25 00:25:13 +00:00
return organization [ 'avatar' ] || '' ;
2014-03-12 23:00:24 +00:00
} ;
2014-03-12 20:05:32 +00:00
$scope . parseDate = function ( dateString ) {
return Date . parse ( dateString ) ;
} ;
$scope . showNotification = function ( ) {
var url = NotificationService . getPage ( $scope . notification ) ;
if ( url ) {
2014-06-27 23:18:27 +00:00
if ( stringStartsWith ( url , 'http://' ) || stringStartsWith ( url , 'https://' ) ) {
$window . location . href = url ;
} else {
var parts = url . split ( '?' )
$location . path ( parts [ 0 ] ) ;
2014-11-24 21:07:38 +00:00
2014-06-27 23:18:27 +00:00
if ( parts . length > 1 ) {
$location . search ( parts [ 1 ] ) ;
}
2014-03-12 20:05:32 +00:00
2014-06-27 23:18:27 +00:00
$scope . parent . $hide ( ) ;
}
2014-03-12 20:05:32 +00:00
}
} ;
2014-07-28 22:23:46 +00:00
$scope . dismissNotification = function ( notification ) {
NotificationService . dismissNotification ( notification ) ;
} ;
$scope . canDismiss = function ( notification ) {
return NotificationService . canDismiss ( notification ) ;
} ;
2014-03-12 20:05:32 +00:00
$scope . getClass = function ( notification ) {
return NotificationService . getClass ( notification ) ;
} ;
2014-08-16 01:56:29 +00:00
$scope . getActions = function ( notification ) {
return NotificationService . getActions ( notification ) ;
} ;
2014-03-12 20:05:32 +00:00
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-02-15 03:59:44 +00:00
quayApp . directive ( 'dockerfileBuildDialog' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/dockerfile-build-dialog.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'repository' : '=repository' ,
'showNow' : '=showNow' ,
'buildStarted' : '&buildStarted'
} ,
controller : function ( $scope , $element ) {
$scope . building = false ;
$scope . uploading = false ;
$scope . startCounter = 0 ;
$scope . handleBuildStarted = function ( build ) {
$ ( '#dockerfilebuildModal' ) . modal ( 'hide' ) ;
if ( $scope . buildStarted ) {
$scope . buildStarted ( { 'build' : build } ) ;
}
} ;
$scope . handleBuildFailed = function ( message ) {
$scope . errorMessage = message ;
} ;
$scope . startBuild = function ( ) {
$scope . errorMessage = null ;
$scope . startCounter ++ ;
} ;
2014-11-24 21:07:38 +00:00
2014-02-15 03:59:44 +00:00
$scope . $watch ( 'showNow' , function ( sn ) {
if ( sn && $scope . repository ) {
$ ( '#dockerfilebuildModal' ) . modal ( { } ) ;
}
} ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
quayApp . directive ( 'dockerfileBuildForm' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/dockerfile-build-form.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'repository' : '=repository' ,
'startNow' : '=startNow' ,
2015-01-16 22:01:14 +00:00
'isReady' : '=isReady' ,
2014-02-15 03:59:44 +00:00
'uploadFailed' : '&uploadFailed' ,
'uploadStarted' : '&uploadStarted' ,
'buildStarted' : '&buildStarted' ,
'buildFailed' : '&buildFailed' ,
'missingFile' : '&missingFile' ,
'uploading' : '=uploading' ,
'building' : '=building'
} ,
controller : function ( $scope , $element , ApiService ) {
$scope . internal = { 'hasDockerfile' : false } ;
2015-01-16 22:01:14 +00:00
$scope . pull _entity = null ;
$scope . is _public = true ;
2014-02-15 03:59:44 +00:00
var handleBuildFailed = function ( message ) {
message = message || 'Dockerfile build failed to start' ;
var result = false ;
if ( $scope . buildFailed ) {
result = $scope . buildFailed ( { 'message' : message } ) ;
}
if ( ! result ) {
bootbox . dialog ( {
"message" : message ,
"title" : "Cannot start Dockerfile build" ,
"buttons" : {
"close" : {
"label" : "Close" ,
"className" : "btn-primary"
}
}
} ) ;
}
} ;
var handleUploadFailed = function ( message ) {
message = message || 'Error with file upload' ;
var result = false ;
if ( $scope . uploadFailed ) {
result = $scope . uploadFailed ( { 'message' : message } ) ;
}
if ( ! result ) {
bootbox . dialog ( {
"message" : message ,
"title" : "Cannot upload file for Dockerfile build" ,
"buttons" : {
"close" : {
"label" : "Close" ,
"className" : "btn-primary"
}
}
} ) ;
}
} ;
var handleMissingFile = function ( ) {
var result = false ;
if ( $scope . missingFile ) {
result = $scope . missingFile ( { } ) ;
}
if ( ! result ) {
bootbox . dialog ( {
"message" : 'A Dockerfile or an archive containing a Dockerfile is required' ,
"title" : "Missing Dockerfile" ,
"buttons" : {
"close" : {
"label" : "Close" ,
"className" : "btn-primary"
}
}
} ) ;
}
} ;
var startBuild = function ( fileId ) {
$scope . building = true ;
var repo = $scope . repository ;
var data = {
'file_id' : fileId
} ;
2015-01-16 22:01:14 +00:00
if ( ! $scope . is _public && $scope . pull _entity ) {
data [ 'pull_robot' ] = $scope . pull _entity [ 'name' ] ;
}
2014-02-15 03:59:44 +00:00
var params = {
2015-01-16 22:01:14 +00:00
'repository' : repo . namespace + '/' + repo . name ,
2014-02-15 03:59:44 +00:00
} ;
ApiService . requestRepoBuild ( data , params ) . then ( function ( resp ) {
$scope . building = false ;
$scope . uploading = false ;
if ( $scope . buildStarted ) {
$scope . buildStarted ( { 'build' : resp } ) ;
}
} , function ( resp ) {
$scope . building = false ;
$scope . uploading = false ;
handleBuildFailed ( resp . message ) ;
} ) ;
} ;
var conductUpload = function ( file , url , fileId , mimeType ) {
if ( $scope . uploadStarted ) {
$scope . uploadStarted ( { } ) ;
}
var request = new XMLHttpRequest ( ) ;
request . open ( 'PUT' , url , true ) ;
request . setRequestHeader ( 'Content-Type' , mimeType ) ;
request . onprogress = function ( e ) {
$scope . $apply ( function ( ) {
var percentLoaded ;
if ( e . lengthComputable ) {
$scope . upload _progress = ( e . loaded / e . total ) * 100 ;
}
} ) ;
} ;
request . onerror = function ( ) {
$scope . $apply ( function ( ) {
handleUploadFailed ( ) ;
} ) ;
} ;
request . onreadystatechange = function ( ) {
var state = request . readyState ;
if ( state == 4 ) {
$scope . $apply ( function ( ) {
startBuild ( fileId ) ;
$scope . uploading = false ;
} ) ;
return ;
}
} ;
request . send ( file ) ;
} ;
2014-11-24 21:07:38 +00:00
2014-02-15 03:59:44 +00:00
var startFileUpload = function ( repo ) {
$scope . uploading = true ;
$scope . uploading _progress = 0 ;
2014-11-24 21:07:38 +00:00
2014-02-15 03:59:44 +00:00
var uploader = $ ( '#file-drop' ) [ 0 ] ;
if ( uploader . files . length == 0 ) {
handleMissingFile ( ) ;
$scope . uploading = false ;
return ;
}
var file = uploader . files [ 0 ] ;
$scope . upload _file = file . name ;
2014-11-24 21:07:38 +00:00
2014-02-15 03:59:44 +00:00
var mimeType = file . type || 'application/octet-stream' ;
var data = {
'mimeType' : mimeType
} ;
2014-11-24 21:07:38 +00:00
2014-02-15 03:59:44 +00:00
var getUploadUrl = ApiService . getFiledropUrl ( data ) . then ( function ( resp ) {
conductUpload ( file , resp . url , resp . file _id , mimeType ) ;
} , function ( ) {
handleUploadFailed ( 'Could not retrieve upload URL' ) ;
} ) ;
2014-11-24 21:07:38 +00:00
} ;
2014-02-15 03:59:44 +00:00
2015-01-16 22:01:14 +00:00
var checkIsReady = function ( ) {
$scope . isReady = $scope . internal . hasDockerfile && ( $scope . is _public || $scope . pull _entity ) ;
} ;
$scope . $watch ( 'pull_entity' , checkIsReady ) ;
$scope . $watch ( 'is_public' , checkIsReady ) ;
$scope . $watch ( 'internal.hasDockerfile' , checkIsReady ) ;
2014-02-15 03:59:44 +00:00
$scope . $watch ( 'startNow' , function ( ) {
if ( $scope . startNow && $scope . repository && ! $scope . uploading && ! $scope . building ) {
startFileUpload ( ) ;
}
} ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-06-24 22:48:42 +00:00
quayApp . directive ( 'locationView' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/location-view.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
'location' : '=location'
} ,
2014-07-03 21:55:53 +00:00
controller : function ( $rootScope , $scope , $element , $http , PingService ) {
2014-06-24 22:48:42 +00:00
var LOCATIONS = {
'local_us' : { 'country' : 'US' , 'data' : 'quay-registry.s3.amazonaws.com' , 'title' : 'United States' } ,
'local_eu' : { 'country' : 'EU' , 'data' : 'quay-registry-eu.s3-eu-west-1.amazonaws.com' , 'title' : 'Europe' } ,
2014-08-15 19:02:26 +00:00
's3_us_east_1' : { 'country' : 'US' , 'data' : 'quay-registry.s3.amazonaws.com' , 'title' : 'United States (East)' } ,
's3_us_west_1' : { 'country' : 'US' , 'data' : 'quay-registry-cali.s3.amazonaws.com' , 'title' : 'United States (West)' } ,
2014-06-24 22:48:42 +00:00
's3_eu_west_1' : { 'country' : 'EU' , 'data' : 'quay-registry-eu.s3-eu-west-1.amazonaws.com' , 'title' : 'Europe' } ,
's3_ap_southeast_1' : { 'country' : 'SG' , 'data' : 'quay-registry-singapore.s3-ap-southeast-1.amazonaws.com' , 'title' : 'Singapore' } ,
's3_ap_southeast_2' : { 'country' : 'AU' , 'data' : 'quay-registry-sydney.s3-ap-southeast-2.amazonaws.com' , 'title' : 'Australia' } ,
// 's3_ap_northeast-1': { 'country': 'JP', 'data': 's3-ap-northeast-1.amazonaws.com', 'title': 'Japan' },
// 's3_sa_east1': { 'country': 'BR', 'data': 's3-east-1.amazonaws.com', 'title': 'Sao Paulo' }
} ;
$scope . locationPing = null ;
$scope . locationPingClass = null ;
$scope . getLocationTooltip = function ( location , ping ) {
var tip = $scope . getLocationTitle ( location ) + '<br>' ;
2014-08-29 20:25:11 +00:00
if ( ping == null ) {
tip += '(Loading)' ;
} else if ( ping < 0 ) {
2014-06-24 22:48:42 +00:00
tip += '<br><b>Note: Could not contact server</b>' ;
} else {
tip += 'Estimated Ping: ' + ( ping ? ping + 'ms' : '(Loading)' ) ;
}
return tip ;
} ;
$scope . getLocationTitle = function ( location ) {
if ( ! LOCATIONS [ location ] ) {
return '(Unknown)' ;
}
return 'Image data is located in ' + LOCATIONS [ location ] [ 'title' ] ;
} ;
$scope . getLocationImage = function ( location ) {
if ( ! LOCATIONS [ location ] ) {
return 'unknown.png' ;
}
return LOCATIONS [ location ] [ 'country' ] + '.png' ;
} ;
$scope . getLocationPing = function ( location ) {
2014-08-13 22:48:24 +00:00
var url = 'https://' + LOCATIONS [ location ] [ 'data' ] + '/okay.txt' ;
2014-07-03 21:55:53 +00:00
PingService . pingUrl ( $scope , url , function ( ping , success , count ) {
if ( count == 3 || ! success ) {
$scope . locationPing = success ? ping : - 1 ;
}
} ) ;
2014-06-24 22:48:42 +00:00
} ;
$scope . $watch ( 'location' , function ( location ) {
if ( ! location ) { return ; }
$scope . getLocationPing ( location ) ;
} ) ;
$scope . $watch ( 'locationPing' , function ( locationPing ) {
if ( locationPing == null ) {
$scope . locationPingClass = null ;
return ;
}
if ( locationPing < 0 ) {
$scope . locationPingClass = 'error' ;
return ;
}
if ( locationPing < 100 ) {
$scope . locationPingClass = 'good' ;
return ;
}
if ( locationPing < 250 ) {
$scope . locationPingClass = 'fair' ;
return ;
}
if ( locationPing < 500 ) {
$scope . locationPingClass = 'barely' ;
return ;
}
$scope . locationPingClass = 'poor' ;
} ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2015-01-28 22:12:33 +00:00
quayApp . directive ( 'realtimeAreaChart' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/realtime-area-chart.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'data' : '=data' ,
'labels' : '=labels' ,
'colors' : '=colors' ,
'counter' : '=counter'
} ,
controller : function ( $scope , $element ) {
var graph = null ;
var series = [ ] ;
var palette = new Rickshaw . Color . Palette ( { scheme : 'spectrum14' } ) ;
var colors = $scope . colors || [ ] ;
var setupGraph = function ( ) {
for ( var i = 0 ; i < $scope . labels . length ; ++ i ) {
series . push ( {
name : $scope . labels [ i ] ,
color : i >= colors . length ? palette . color ( ) : $scope . colors [ i ] ,
stroke : 'rgba(0,0,0,0.15)' ,
data : [ ]
} ) ;
}
graph = new Rickshaw . Graph ( {
element : $element . find ( '.chart' ) [ 0 ] ,
renderer : 'area' ,
stroke : true ,
series : series ,
min : 0
} ) ;
} ;
var refresh = function ( data ) {
if ( ! data || $scope . counter < 0 ) { return ; }
if ( ! graph ) {
setupGraph ( ) ;
}
for ( var i = 0 ; i < $scope . data . length ; ++ i ) {
series [ i ] . data . push (
{ 'x' : $scope . counter , 'y' : $scope . data [ i ] }
) ;
}
hoverDetail = new Rickshaw . Graph . HoverDetail ( {
graph : graph ,
xFormatter : function ( x ) {
return x . toString ( ) ;
}
} ) ;
graph . renderer . unstack = true ;
graph . render ( ) ;
} ;
$scope . $watch ( 'counter' , function ( ) {
refresh ( $scope . data _raw ) ;
} ) ;
$scope . $watch ( 'data' , function ( data ) {
$scope . data _raw = data ;
refresh ( $scope . data _raw ) ;
} ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2015-01-28 17:35:01 +00:00
quayApp . directive ( 'realtimeLineChart' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/realtime-line-chart.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
'data' : '=data' ,
'labels' : '=labels' ,
'counter' : '=counter' ,
'labelTemplate' : '@labelTemplate'
} ,
controller : function ( $scope , $element ) {
var graph = null ;
var hoverDetail = null ;
var series = [ ] ;
var counter = 0 ;
var palette = new Rickshaw . Color . Palette ( { scheme : 'spectrum14' } ) ;
var setupGraph = function ( ) {
graph = new Rickshaw . Graph ( {
element : $element . find ( '.chart' ) [ 0 ] ,
renderer : 'line' ,
series : series ,
min : 'auto' ,
padding : {
'top' : 0.1 ,
'left' : 0.01 ,
'right' : 0.01 ,
'bottom' : 0.1
}
} ) ;
hoverDetail = new Rickshaw . Graph . HoverDetail ( {
graph : graph ,
xFormatter : function ( x ) {
return x . toString ( ) ;
}
} ) ;
} ;
var refresh = function ( data ) {
if ( ! data ) { return ; }
if ( ! graph ) {
setupGraph ( ) ;
}
if ( typeof data == 'number' ) {
data = [ data ] ;
}
if ( $scope . labels ) {
data = data . slice ( 0 , $scope . labels . length ) ;
}
if ( series . length == 0 ) {
for ( var i = 0 ; i < data . length ; ++ i ) {
var title = $scope . labels ? $scope . labels [ i ] : $scope . labelTemplate . replace ( '{x}' , i + 1 ) ;
series . push ( {
'color' : palette . color ( ) ,
'data' : [ ] ,
'name' : title
} )
}
}
counter ++ ;
for ( var i = 0 ; i < data . length ; ++ i ) {
var arr = series [ i ] . data ;
arr . push ( {
'x' : counter ,
'y' : data [ i ]
} )
if ( arr . length > 10 ) {
series [ i ] . data = arr . slice ( arr . length - 10 , arr . length ) ;
}
}
graph . render ( ) ;
} ;
$scope . $watch ( 'counter' , function ( counter ) {
refresh ( $scope . data _raw ) ;
} ) ;
$scope . $watch ( 'data' , function ( data ) {
$scope . data _raw = data ;
} ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
quayApp . directive ( 'psUsageGraph' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/ps-usage-graph.html' ,
replace : false ,
transclude : false ,
restrict : 'C' ,
scope : {
} ,
controller : function ( $scope , $element ) {
$scope . counter = - 1 ;
$scope . data = null ;
var source = new EventSource ( '/realtime/ps' ) ;
source . onmessage = function ( e ) {
$scope . $apply ( function ( ) {
$scope . counter ++ ;
$scope . data = JSON . parse ( e . data ) ;
} ) ;
} ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-11-25 00:25:13 +00:00
quayApp . directive ( 'avatar' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/avatar.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
'hash' : '=hash' ,
'email' : '=email' ,
'name' : '=name' ,
'size' : '=size'
} ,
controller : function ( $scope , $element , AvatarService ) {
$scope . AvatarService = AvatarService ;
var refreshHash = function ( ) {
if ( ! $scope . name && ! $scope . email ) { return ; }
$scope . _hash = AvatarService . computeHash ( $scope . email , $scope . name ) ;
} ;
$scope . $watch ( 'hash' , function ( hash ) {
$scope . _hash = hash ;
} ) ;
2014-12-01 20:30:09 +00:00
$scope . $watch ( 'name' , refreshHash ) ;
2014-11-25 00:25:13 +00:00
$scope . $watch ( 'email' , refreshHash ) ;
}
2014-06-24 22:48:42 +00:00
} ;
return directiveDefinitionObject ;
} ) ;
2014-02-28 05:12:09 +00:00
quayApp . directive ( 'tagSpecificImagesView' , function ( ) {
var directiveDefinitionObject = {
priority : 0 ,
templateUrl : '/static/directives/tag-specific-images-view.html' ,
replace : false ,
transclude : true ,
restrict : 'C' ,
scope : {
'repository' : '=repository' ,
'tag' : '=tag' ,
2014-08-13 22:47:07 +00:00
'images' : '=images' ,
'imageCutoff' : '=imageCutoff'
2014-02-28 05:12:09 +00:00
} ,
controller : function ( $scope , $element ) {
$scope . getFirstTextLine = getFirstTextLine ;
$scope . hasImages = false ;
$scope . tagSpecificImages = [ ] ;
$scope . getImageListingClasses = function ( image ) {
var classes = '' ;
if ( image . ancestors . length > 1 ) {
classes += 'child ' ;
}
2014-11-24 21:07:38 +00:00
2014-02-28 05:12:09 +00:00
var currentTag = $scope . repository . tags [ $scope . tag ] ;
2014-09-18 21:16:10 +00:00
if ( image . id == currentTag . image _id ) {
2014-02-28 05:12:09 +00:00
classes += 'tag-image ' ;
}
2014-11-24 21:07:38 +00:00
2014-02-28 05:12:09 +00:00
return classes ;
} ;
2014-08-13 22:47:07 +00:00
var forAllTagImages = function ( tag , callback , opt _cutoff ) {
2014-02-28 05:12:09 +00:00
if ( ! tag ) { return ; }
2014-09-18 21:16:10 +00:00
if ( ! $scope . imageByDockerId ) {
$scope . imageByDockerId = [ ] ;
2014-02-28 05:12:09 +00:00
for ( var i = 0 ; i < $scope . images . length ; ++ i ) {
var currentImage = $scope . images [ i ] ;
2014-09-18 21:16:10 +00:00
$scope . imageByDockerId [ currentImage . id ] = currentImage ;
2014-02-28 05:12:09 +00:00
}
}
2014-09-18 21:16:10 +00:00
var tag _image = $scope . imageByDockerId [ tag . image _id ] ;
2014-07-18 02:59:17 +00:00
if ( ! tag _image ) {
return ;
}
2014-11-24 21:07:38 +00:00
2014-07-18 02:59:17 +00:00
callback ( tag _image ) ;
2014-08-13 22:47:07 +00:00
var ancestors = tag _image . ancestors . split ( '/' ) . reverse ( ) ;
2014-02-28 05:12:09 +00:00
for ( var i = 0 ; i < ancestors . length ; ++ i ) {
2014-09-18 21:16:10 +00:00
var image = $scope . imageByDockerId [ ancestors [ i ] ] ;
2014-02-28 05:12:09 +00:00
if ( image ) {
2014-08-13 22:47:07 +00:00
if ( image == opt _cutoff ) {
return ;
}
2014-11-24 21:07:38 +00:00
2014-02-28 05:12:09 +00:00
callback ( image ) ;
}
}
} ;
var refresh = function ( ) {
if ( ! $scope . repository || ! $scope . tag || ! $scope . images ) {
$scope . tagSpecificImages = [ ] ;
return ;
}
var tag = $scope . repository . tags [ $scope . tag ] ;
if ( ! tag ) {
$scope . tagSpecificImages = [ ] ;
return ;
}
2014-11-24 21:07:38 +00:00
2014-02-28 05:12:09 +00:00
var getIdsForTag = function ( currentTag ) {
var ids = { } ;
forAllTagImages ( currentTag , function ( image ) {
2014-09-18 21:16:10 +00:00
ids [ image . id ] = true ;
2014-08-13 22:47:07 +00:00
} , $scope . imageCutoff ) ;
2014-02-28 05:12:09 +00:00
return ids ;
} ;
// Remove any IDs that match other tags.
var toDelete = getIdsForTag ( tag ) ;
for ( var currentTagName in $scope . repository . tags ) {
var currentTag = $scope . repository . tags [ currentTagName ] ;
if ( currentTag != tag ) {
2014-09-18 21:16:10 +00:00
for ( var id in getIdsForTag ( currentTag ) ) {
delete toDelete [ id ] ;
2014-02-28 05:12:09 +00:00
}
}
}
// Return the matching list of images.
var images = [ ] ;
for ( var i = 0 ; i < $scope . images . length ; ++ i ) {
var image = $scope . images [ i ] ;
2014-09-18 21:16:10 +00:00
if ( toDelete [ image . id ] ) {
2014-02-28 05:12:09 +00:00
images . push ( image ) ;
}
}
2014-11-24 21:07:38 +00:00
2014-02-28 05:12:09 +00:00
images . sort ( function ( a , b ) {
var result = new Date ( b . created ) - new Date ( a . created ) ;
if ( result != 0 ) {
return result ;
}
2014-09-08 19:02:26 +00:00
return b . sort _index - a . sort _index ;
2014-02-28 05:12:09 +00:00
} ) ;
$scope . tagSpecificImages = images ;
} ;
$scope . $watch ( 'repository' , refresh ) ;
$scope . $watch ( 'tag' , refresh ) ;
$scope . $watch ( 'images' , refresh ) ;
}
} ;
return directiveDefinitionObject ;
} ) ;
2014-05-08 23:52:21 +00:00
quayApp . directive ( 'fallbackSrc' , function ( ) {
return {
restrict : 'A' ,
link : function postLink ( scope , element , attributes ) {
element . bind ( 'error' , function ( ) {
angular . element ( this ) . attr ( "src" , attributes . fallbackSrc ) ;
} ) ;
}
} ;
} ) ;
2013-11-05 22:20:43 +00:00
// Note: ngBlur is not yet in Angular stable, so we add it manaully here.
quayApp . directive ( 'ngBlur' , function ( ) {
return function ( scope , elem , attrs ) {
elem . bind ( 'blur' , function ( ) {
scope . $apply ( attrs . ngBlur ) ;
} ) ;
} ;
} ) ;
2014-02-15 03:59:44 +00:00
quayApp . directive ( "filePresent" , [ function ( ) {
return {
restrict : 'A' ,
scope : {
'filePresent' : "="
} ,
link : function ( scope , element , attributes ) {
element . bind ( "change" , function ( changeEvent ) {
scope . $apply ( function ( ) {
scope . filePresent = changeEvent . target . files . length > 0 ;
} ) ;
} ) ;
}
}
} ] ) ;
2014-02-10 06:18:14 +00:00
quayApp . directive ( 'ngVisible' , function ( ) {
return function ( scope , element , attr ) {
scope . $watch ( attr . ngVisible , function ( visible ) {
element . css ( 'visibility' , visible ? 'visible' : 'hidden' ) ;
} ) ;
} ;
} ) ;
2014-02-05 01:50:13 +00:00
2014-10-22 18:49:33 +00:00
quayApp . config ( [
'$compileProvider' ,
function ( $compileProvider )
2014-11-24 21:07:38 +00:00
{
2014-10-22 18:49:33 +00:00
$compileProvider . aHrefSanitizationWhitelist ( /^\s*(https?|ftp|mailto|tel|irc):/ ) ;
}
] ) ;
2014-06-03 17:22:26 +00:00
quayApp . run ( [ '$location' , '$rootScope' , 'Restangular' , 'UserService' , 'PlanService' , '$http' , '$timeout' , 'CookieService' , 'Features' , '$anchorScroll' ,
function ( $location , $rootScope , Restangular , UserService , PlanService , $http , $timeout , CookieService , Features , $anchorScroll ) {
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 ) {
2014-09-04 18:24:20 +00:00
if ( response . status == 401 && response . data [ 'error_type' ] == 'invalid_token' &&
response . data [ 'session_required' ] !== false ) {
$ ( '#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
2013-12-21 03:38:53 +00:00
var changeTab = function ( activeTab , opt _timeout ) {
var checkCount = 0 ;
2013-12-10 04:33:28 +00:00
$timeout ( function ( ) {
2013-12-21 03:38:53 +00:00
if ( checkCount > 5 ) { return ; }
checkCount ++ ;
2013-12-10 04:33:28 +00:00
$ ( 'a[data-toggle="tab"]' ) . each ( function ( index ) {
var tabName = this . getAttribute ( 'data-target' ) . substr ( 1 ) ;
2013-12-21 03:38:53 +00:00
if ( tabName != activeTab ) {
return ;
}
if ( this . clientWidth == 0 ) {
changeTab ( activeTab , 500 ) ;
return ;
2013-12-10 04:33:28 +00:00
}
2013-12-21 03:38:53 +00:00
2014-01-10 01:17:28 +00:00
clickElement ( this ) ;
2013-12-10 04:33:28 +00:00
} ) ;
2013-12-21 03:38:53 +00:00
} , opt _timeout ) ;
2013-12-10 04:33:28 +00:00
} ;
var resetDefaultTab = function ( ) {
$timeout ( function ( ) {
$ ( 'a[data-toggle="tab"]' ) . each ( function ( index ) {
if ( index == 0 ) {
2014-01-10 01:17:28 +00:00
clickElement ( this ) ;
2013-12-10 04:33:28 +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
} ) ;
2013-12-10 04:33:28 +00:00
$rootScope . $on ( '$routeUpdate' , function ( ) {
if ( $location . search ( ) [ 'tab' ] ) {
changeTab ( $location . search ( ) [ 'tab' ] ) ;
} else {
resetDefaultTab ( ) ;
}
} ) ;
2013-09-26 23:07:25 +00:00
$rootScope . $on ( '$routeChangeSuccess' , function ( event , current , previous ) {
2014-04-24 04:40:01 +00:00
$rootScope . pageClass = '' ;
2014-04-30 03:48:06 +00:00
$rootScope . current = current . $$route ;
if ( ! current . $$route ) { return ; }
2013-09-26 23:07:25 +00:00
if ( current . $$route . title ) {
$rootScope . title = current . $$route . title ;
}
2013-11-19 00:03:35 +00:00
2014-04-24 04:40:01 +00:00
if ( current . $$route . pageClass ) {
$rootScope . pageClass = current . $$route . pageClass ;
}
2013-11-19 00:03:35 +00:00
if ( current . $$route . description ) {
$rootScope . description = current . $$route . description ;
} else {
2014-04-11 21:15:03 +00:00
$rootScope . description = '' ;
2013-11-19 00:03:35 +00:00
}
2013-11-20 21:17:47 +00:00
2013-11-24 01:03:08 +00:00
$rootScope . fixFooter = ! ! current . $$route . fixFooter ;
2014-05-21 19:28:38 +00:00
$anchorScroll ( ) ;
2013-12-10 04:33:28 +00:00
} ) ;
$rootScope . $on ( '$viewContentLoaded' , function ( event , current ) {
var activeTab = $location . search ( ) [ 'tab' ] ;
// Setup deep linking of tabs. This will change the search field of the URL whenever a tab
// is changed in the UI.
$ ( 'a[data-toggle="tab"]' ) . on ( 'shown.bs.tab' , function ( e ) {
var tabName = e . target . getAttribute ( 'data-target' ) . substr ( 1 ) ;
$rootScope . $apply ( function ( ) {
var isDefaultTab = $ ( 'a[data-toggle="tab"]' ) [ 0 ] == e . target ;
2014-02-20 23:57:49 +00:00
var newSearch = $ . extend ( $location . search ( ) , { } ) ;
if ( isDefaultTab ) {
delete newSearch [ 'tab' ] ;
} else {
newSearch [ 'tab' ] = tabName ;
}
$location . search ( newSearch ) ;
2013-12-10 04:33:28 +00:00
} ) ;
2014-11-24 21:07:38 +00:00
e . preventDefault ( ) ;
2013-12-10 04:33:28 +00:00
} ) ;
if ( activeTab ) {
changeTab ( activeTab ) ;
}
2013-09-26 23:07:25 +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
} ] ) ;