@ -1,6 +1,6 @@
angular . module ( 'templates' , [ ] )
angular . module ( 'templates' , [ ] )
. controller ( 'TemplatesController' , [ '$scope' , '$q' , '$state' , ' Config', 'Container' , 'Image' , 'Volume' , 'Network' , 'Templates' , 'Messages' , 'errorMsgFilter' ,
. controller ( 'TemplatesController' , [ '$scope' , '$q' , '$state' , ' $filter', ' Config', 'Container' , 'Image' , 'Volume' , 'Network' , 'Templates' , 'Messages' , 'errorMsgFilter' ,
function ( $scope , $q , $state , Config, Container , Image , Volume , Network , Templates , Messages , errorMsgFilter ) {
function ( $scope , $q , $state , $filter, Config, Container , Image , Volume , Network , Templates , Messages , errorMsgFilter ) {
$scope . templates = [ ] ;
$scope . templates = [ ] ;
$scope . selectedTemplate = null ;
$scope . selectedTemplate = null ;
$scope . formValues = {
$scope . formValues = {
@ -51,8 +51,8 @@ function pullImageAndCreateContainer(imageConfig, containerConfig) {
} ) ;
} ) ;
}
}
function createConfigFromTemplate( template ) {
function getInitialConfiguration( ) {
var containerConfig = {
return {
Env : [ ] ,
Env : [ ] ,
OpenStdin : false ,
OpenStdin : false ,
Tty : false ,
Tty : false ,
@ -63,17 +63,31 @@ function createConfigFromTemplate(template) {
} ,
} ,
PortBindings : { } ,
PortBindings : { } ,
Binds : [ ] ,
Binds : [ ] ,
NetworkMode : $scope . formValues . network ,
NetworkMode : $scope . formValues . network .Name ,
Privileged : false
Privileged : false
} ,
} ,
Image : template . image ,
Volumes : { } ,
Volumes : { } ,
name : $scope . formValues . name
name : $scope . formValues . name
} ;
} ;
}
function createConfigFromTemplate ( template ) {
var containerConfig = getInitialConfiguration ( ) ;
containerConfig . Image = template . image ;
if ( template . env ) {
if ( template . env ) {
template . env . forEach ( function ( v ) {
template . env . forEach ( function ( v ) {
if ( v . value || v . default ) {
if ( v . value || v . default ) {
var val = v . default ? v . default : v . value ;
var val ;
if ( v . type && v . type === 'container' ) {
if ( $scope . swarm && $scope . formValues . network . Scope === 'global' ) {
val = $filter ( 'swarmcontainername' ) ( v . value ) ;
} else {
var container = v . value ;
val = container . NetworkSettings . Networks [ Object . keys ( container . NetworkSettings . Networks ) [ 0 ] ] . IPAddress ;
}
} else {
val = v . default ? v . default : v . value ;
}
containerConfig . Env . push ( v . name + "=" + val ) ;
containerConfig . Env . push ( v . name + "=" + val ) ;
}
}
} ) ;
} ) ;
@ -146,26 +160,31 @@ function initTemplates() {
}
}
Config . $promise . then ( function ( c ) {
Config . $promise . then ( function ( c ) {
var swarm = c . swarm ;
$scope . swarm = c . swarm ;
Network . query ( { } , function ( d ) {
Network . query ( { } , function ( d ) {
var networks = d ;
var networks = d ;
if ( swarm) {
if ( $scope. swarm) {
networks = d . filter ( function ( network ) {
networks = d . filter ( function ( network ) {
if ( network . Scope === 'global' ) {
if ( network . Scope === 'global' ) {
return network ;
return network ;
}
}
} ) ;
} ) ;
$scope . globalNetworkCount = networks . length ;
$scope . globalNetworkCount = networks . length ;
networks . push ( { Name: "bridge" } ) ;
networks . push ( { Scope: "local" , Name: "bridge" } ) ;
networks . push ( { Name: "host" } ) ;
networks . push ( { Scope: "local" , Name: "host" } ) ;
networks . push ( { Name: "none" } ) ;
networks . push ( { Scope: "local" , Name: "none" } ) ;
} else {
} else {
$scope . formValues . network = "bridge" ;
$scope . formValues . network = _ . find ( networks , function ( o ) { return o . Name === "bridge" ; } ) ;
}
}
$scope . availableNetworks = networks ;
$scope . availableNetworks = networks ;
} , function ( e ) {
} , function ( e ) {
Messages . error ( "Unable to retrieve available networks" , e . data ) ;
Messages . error ( "Unable to retrieve available networks" , e . data ) ;
} ) ;
} ) ;
Container . query ( { all : 0 } , function ( d ) {
$scope . runningContainers = d ;
} , function ( e ) {
Messages . error ( "Unable to retrieve running containers" , e . data ) ;
} ) ;
initTemplates ( ) ;
initTemplates ( ) ;
} ) ;
} ) ;
} ] ) ;
} ] ) ;