2019-07-07 11:18:12 +05:30
< script >
/ * *
* Render modal to confirm rollback / redeploy .
* /
import _ from 'underscore' ;
import { GlModal } from '@gitlab/ui' ;
import { s _ _ , sprintf } from '~/locale' ;
import eventHub from '../event_hub' ;
export default {
name : 'ConfirmRollbackModal' ,
components : {
GlModal ,
} ,
props : {
environment : {
type : Object ,
required : true ,
} ,
} ,
computed : {
modalTitle ( ) {
const title = this . environment . isLastDeployment
? s _ _ ( 'Environments|Re-deploy environment %{name}?' )
: s _ _ ( 'Environments|Rollback environment %{name}?' ) ;
return sprintf ( title , {
name : _ . escape ( this . environment . name ) ,
} ) ;
} ,
commitShortSha ( ) {
const { last _deployment } = this . environment ;
return this . commitData ( last _deployment , 'short_id' ) ;
} ,
commitUrl ( ) {
const { last _deployment } = this . environment ;
return this . commitData ( last _deployment , 'commit_path' ) ;
} ,
commitTitle ( ) {
const { last _deployment } = this . environment ;
return this . commitData ( last _deployment , 'title' ) ;
} ,
modalText ( ) {
2019-07-31 22:56:46 +05:30
const linkStart = ` <a class="commit-sha mr-0" href=" ${ _ . escape ( this . commitUrl ) } "> ` ;
2019-07-07 11:18:12 +05:30
const commitId = _ . escape ( this . commitShortSha ) ;
const linkEnd = '</a>' ;
const name = _ . escape ( this . name ) ;
const body = this . environment . isLastDeployment
? s _ _ (
'Environments|This action will relaunch the job for commit %{linkStart}%{commitId}%{linkEnd}, putting the environment in a previous version. Are you sure you want to continue?' ,
)
: s _ _ (
'Environments|This action will run the job defined by %{name} for commit %{linkStart}%{commitId}%{linkEnd} putting the environment in a previous version. You can revert it by re-deploying the latest version of your application. Are you sure you want to continue?' ,
) ;
return sprintf (
body ,
{
commitId ,
linkStart ,
linkEnd ,
name ,
} ,
false ,
) ;
} ,
modalActionText ( ) {
return this . environment . isLastDeployment
? s _ _ ( 'Environments|Re-deploy' )
: s _ _ ( 'Environments|Rollback' ) ;
} ,
} ,
methods : {
onOk ( ) {
eventHub . $emit ( 'rollbackEnvironment' , this . environment ) ;
} ,
commitData ( lastDeployment , key ) {
if ( lastDeployment && lastDeployment . commit ) {
return lastDeployment . commit [ key ] ;
}
return '' ;
} ,
} ,
} ;
< / script >
< template >
< gl-modal
: title = "modalTitle"
modal - id = "confirm-rollback-modal"
: ok - title = "modalActionText"
ok - variant = "danger"
@ ok = "onOk"
>
< p v-html = "modalText" > < / p >
< / gl-modal >
< / template >