2017-07-25 09:18:45 -04:00
< script >
import Vue from 'vue' ;
import Store from './repo_store' ;
2017-07-25 13:52:46 -04:00
import Api from '../api'
2017-07-25 09:18:45 -04:00
const RepoCommitSection = {
data : ( ) => Store ,
methods : {
makeCommit ( ) {
// see https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
2017-07-25 10:54:27 -04:00
const branch = $ ( "button.dropdown-menu-toggle" ) . attr ( 'data-ref' ) ;
2017-07-25 09:18:45 -04:00
const commitMessage = this . commitMessage ;
const actions = this . changedFiles . map ( f => {
2017-07-25 10:54:27 -04:00
const filePath = f . url . split ( branch ) [ 1 ] ;
return {
action : 'update' ,
file _path : filePath ,
content : f . newContent ,
} ;
2017-07-25 09:18:45 -04:00
} ) ;
2017-07-25 10:54:27 -04:00
const payload = {
branch : branch ,
commit _message : commitMessage ,
actions : actions ,
}
2017-07-25 22:06:12 -04:00
Store . submitCommitsLoading = true ;
2017-07-25 13:52:46 -04:00
Api . commitMultiple ( Store . projectId , payload , ( data ) => {
2017-07-25 22:06:12 -04:00
Store . submitCommitsLoading = false ;
Flash ( ` Your changes have been committed. Commit ${ data . short _id } with ${ data . stats . additions } additions, ${ data . stats . deletions } deletions. ` , 'notice' ) ;
console . log ( 'this.changedFiles' , this . changedFiles ) ;
console . log ( 'this.files' , this . files ) ;
this . changedFiles = [ ] ;
this . openedFiles = [ ] ;
this . commitMessage = '' ;
this . editMode = false ;
$ ( 'html, body' ) . animate ( { scrollTop : 0 } , 'fast' ) ;
2017-07-25 18:33:29 -04:00
} , Store . tempPrivateToken ) ;
2017-07-25 09:18:45 -04:00
}
} ,
computed : {
changedFiles ( ) {
const changedFileList = this . openedFiles
. filter ( file => file . changed ) ;
return changedFileList ;
} ,
} ,
}
export default RepoCommitSection ;
< / script >
< template >
< div id = "commit-area" v-if = "isCommitable && changedFiles.length" >
< form class = "form-horizontal" >
< fieldset >
< div class = "form-group" >
< label class = "col-md-4 control-label" > Staged files ( { { changedFiles . length } } ) < / label >
< div class = "col-md-4" >
< ul class = "list-unstyled" >
< li v-for = "file in changedFiles" >
< span class = "help-block" >
{ { file . url } }
< / span >
< / li >
< / ul >
< / div >
< / div >
<!-- Textarea
-- >
< div class = "form-group" >
< label class = "col-md-4 control-label" for = "commit-message" > Commit message < / label >
< div class = "col-md-4" >
< textarea class = "form-control" id = "commit-message" name = "commit-message" v-model = "commitMessage" > < / textarea >
< / div >
< / div >
<!-- Button Drop Down
-- >
< div class = "form-group" >
< label class = "col-md-4 control-label" for = "target-branch" > Target branch < / label >
< div class = "col-md-4" >
< div class = "input-group" >
< div class = "input-group-btn" >
< button class = "btn btn-default dropdown-toggle" data -toggle = " dropdown " type = "button" >
Action
< i class = "fa fa-caret-down" > < / i >
< / button >
< ul class = "dropdown-menu pull-right" >
< li >
< a href = "#" > Target branch < / a >
< / li >
< li >
< a href = "#" > Create my own branch < / a >
< / li >
< / ul >
< / div >
< input class = "form-control" id = "target-branch" name = "target-branch" placeholder = "placeholder" type = "text" > < / input >
< / div >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-md-4 control-label" for = "checkboxes" > < / label >
< div class = "col-md-4" >
< div class = "checkbox" >
< label for = "checkboxes-0" >
< input id = "checkboxes-0" name = "checkboxes" type = "checkbox" value = "1" > < / input >
Start a new merge request with these changes
< / label >
< / div >
< / div >
< / div >
< div class = "col-md-offset-4 col-md-4" >
2017-07-25 22:06:12 -04:00
< button type = "submit" : disabled = "!commitMessage || submitCommitsLoading" class = "btn btn-success" @click.prevent ="makeCommit" >
< i class = "fa fa-spinner fa-spin" v-if = "submitCommitsLoading" > < / i >
< span > Commit { { changedFiles . length } } Files < / span >
< / button >
2017-07-25 09:18:45 -04:00
< / div >
< / fieldset >
< / form >
< / div >
< / template >