2017-07-25 09:18:45 -04:00
< script >
2017-07-26 08:56:31 -04:00
/* global Flash */
2017-07-25 09:18:45 -04:00
import Store from './repo_store' ;
2017-07-26 08:56:31 -04:00
import Api from '../api' ;
2017-07-28 13:36:07 -04:00
import RepoMixin from './repo_mixin'
2017-07-25 09:18:45 -04:00
const RepoCommitSection = {
data : ( ) => Store ,
2017-07-26 08:39:32 -04:00
2017-07-28 13:36:07 -04:00
mixins : [ RepoMixin ] ,
2017-07-25 09:18:45 -04:00
methods : {
makeCommit ( ) {
// see https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
2017-07-26 08:56:31 -04:00
const branch = $ ( 'button.dropdown-menu-toggle' ) . attr ( 'data-ref' ) ;
2017-07-25 09:18:45 -04:00
const commitMessage = this . commitMessage ;
2017-07-26 08:56:31 -04:00
const actions = this . changedFiles . map ( ( f ) => {
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 = {
2017-07-26 08:56:31 -04:00
branch ,
2017-07-25 10:54:27 -04:00
commit _message : commitMessage ,
2017-07-26 08:56:31 -04:00
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' ) ;
this . changedFiles = [ ] ;
this . openedFiles = [ ] ;
this . commitMessage = '' ;
this . editMode = false ;
$ ( 'html, body' ) . animate ( { scrollTop : 0 } , 'fast' ) ;
2017-07-28 10:24:01 -04:00
} ) ;
2017-07-26 08:56:31 -04:00
} ,
2017-07-25 09:18:45 -04:00
} ,
2017-07-26 08:56:31 -04:00
} ;
2017-07-25 09:18:45 -04:00
export default RepoCommitSection ;
< / script >
< template >
< div id = "commit-area" v-if = "isCommitable && changedFiles.length" >
< form class = "form-horizontal" >
< fieldset >
< div class = "form-group" >
2017-07-27 10:49:25 -04:00
< label class = "col-md-4 control-label staged-files" > Staged files ( { { changedFiles . length } } ) < / label >
2017-07-25 09:18:45 -04:00
< div class = "col-md-4" >
2017-07-27 10:49:25 -04:00
< ul class = "list-unstyled changed-files" >
2017-07-26 08:39:32 -04:00
< li v-for = "file in changedFiles" :key="file.id" >
2017-07-27 10:49:25 -04:00
< span class = "help-block" > { { file . url } } < / span >
2017-07-25 09:18:45 -04:00
< / 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" >
2017-07-27 10:49:25 -04:00
< div class = "input-group-btn branch-dropdown" >
2017-07-25 09:18:45 -04:00
< 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" >
2017-07-27 10:49:25 -04:00
< div class = "checkbox new-merge-request" >
2017-07-25 09:18:45 -04:00
< 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-27 10:49:25 -04:00
< button type = "submit" : disabled = "!commitMessage || submitCommitsLoading" class = "btn btn-success submit-commit" @click.prevent ="makeCommit" >
2017-07-25 22:06:12 -04:00
< i class = "fa fa-spinner fa-spin" v-if = "submitCommitsLoading" > < / i >
2017-07-27 10:49:25 -04:00
< span class = "commit-summary" > Commit { { changedFiles . length } } Files < / span >
2017-07-25 22:06:12 -04:00
< / button >
2017-07-25 09:18:45 -04:00
< / div >
< / fieldset >
< / form >
< / div >
2017-07-26 08:39:32 -04:00
< / template >