2017-07-25 09:18:45 -04:00
|
|
|
<script>
|
2017-10-02 08:32:53 -04:00
|
|
|
import Flash from '../../flash';
|
2017-08-02 15:09:26 -04:00
|
|
|
import Store from '../stores/repo_store';
|
|
|
|
import RepoMixin from '../mixins/repo_mixin';
|
2017-08-06 14:29:38 -04:00
|
|
|
import Service from '../services/repo_service';
|
2017-07-25 09:18:45 -04:00
|
|
|
|
2017-08-15 14:16:42 -04:00
|
|
|
export default {
|
2017-07-25 09:18:45 -04:00
|
|
|
data: () => Store,
|
2017-07-26 08:39:32 -04:00
|
|
|
|
2017-07-28 13:36:07 -04:00
|
|
|
mixins: [RepoMixin],
|
2017-08-01 09:41:24 -04:00
|
|
|
|
2017-07-28 19:33:56 -04:00
|
|
|
computed: {
|
2017-08-15 15:53:41 -04:00
|
|
|
showCommitable() {
|
|
|
|
return this.isCommitable && this.changedFiles.length;
|
|
|
|
},
|
|
|
|
|
2017-07-28 19:33:56 -04:00
|
|
|
branchPaths() {
|
2017-08-15 15:53:41 -04:00
|
|
|
return this.changedFiles.map(f => f.path);
|
2017-07-28 23:08:05 -04:00
|
|
|
},
|
|
|
|
|
2017-08-06 11:12:29 -04:00
|
|
|
cantCommitYet() {
|
2017-08-06 14:29:38 -04:00
|
|
|
return !this.commitMessage || this.submitCommitsLoading;
|
2017-08-06 11:12:29 -04:00
|
|
|
},
|
|
|
|
|
2017-07-28 23:08:05 -04:00
|
|
|
filePluralize() {
|
2017-08-01 09:41:24 -04:00
|
|
|
return this.changedFiles.length > 1 ? 'files' : 'file';
|
2017-07-28 23:08:05 -04:00
|
|
|
},
|
2017-07-28 19:33:56 -04:00
|
|
|
},
|
2017-07-28 13:36:07 -04:00
|
|
|
|
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
|
|
|
|
const commitMessage = this.commitMessage;
|
2017-08-01 11:38:00 -04:00
|
|
|
const actions = this.changedFiles.map(f => ({
|
|
|
|
action: 'update',
|
2017-08-15 15:53:41 -04:00
|
|
|
file_path: f.path,
|
2017-08-01 11:38:00 -04:00
|
|
|
content: f.newContent,
|
|
|
|
}));
|
2017-07-25 10:54:27 -04:00
|
|
|
const payload = {
|
2017-09-28 10:05:38 -04:00
|
|
|
branch: Store.currentBranch,
|
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-08-09 09:24:48 -04:00
|
|
|
Service.commitFiles(payload)
|
2017-08-17 14:05:09 -04:00
|
|
|
.then(this.resetCommitState)
|
2017-09-25 16:02:08 -04:00
|
|
|
.catch(() => Flash('An error occurred while committing your changes'));
|
2017-08-07 08:08:12 -04:00
|
|
|
},
|
|
|
|
|
2017-08-17 14:05:09 -04:00
|
|
|
resetCommitState() {
|
2017-08-07 08:08:12 -04:00
|
|
|
this.submitCommitsLoading = false;
|
|
|
|
this.changedFiles = [];
|
|
|
|
this.commitMessage = '';
|
|
|
|
this.editMode = false;
|
2017-08-15 15:53:41 -04:00
|
|
|
window.scrollTo(0, 0);
|
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
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2017-08-15 15:53:41 -04:00
|
|
|
<div
|
|
|
|
v-if="showCommitable"
|
|
|
|
id="commit-area">
|
|
|
|
<form
|
|
|
|
class="form-horizontal"
|
|
|
|
@submit.prevent="makeCommit">
|
2017-07-25 09:18:45 -04:00
|
|
|
<fieldset>
|
|
|
|
<div class="form-group">
|
2017-08-15 15:53:41 -04:00
|
|
|
<label class="col-md-4 control-label staged-files">
|
|
|
|
Staged files ({{changedFiles.length}})
|
|
|
|
</label>
|
|
|
|
<div class="col-md-6">
|
2017-07-27 10:49:25 -04:00
|
|
|
<ul class="list-unstyled changed-files">
|
2017-08-15 15:53:41 -04:00
|
|
|
<li
|
|
|
|
v-for="branchPath in branchPaths"
|
|
|
|
:key="branchPath">
|
|
|
|
<span class="help-block">
|
|
|
|
{{branchPath}}
|
|
|
|
</span>
|
2017-07-25 09:18:45 -04:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
2017-08-15 15:53:41 -04:00
|
|
|
<label
|
|
|
|
class="col-md-4 control-label"
|
|
|
|
for="commit-message">
|
|
|
|
Commit message
|
|
|
|
</label>
|
|
|
|
<div class="col-md-6">
|
|
|
|
<textarea
|
|
|
|
id="commit-message"
|
|
|
|
class="form-control"
|
|
|
|
name="commit-message"
|
|
|
|
v-model="commitMessage">
|
|
|
|
</textarea>
|
2017-07-25 09:18:45 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-08-02 10:18:29 -04:00
|
|
|
<div class="form-group target-branch">
|
2017-08-15 15:53:41 -04:00
|
|
|
<label
|
|
|
|
class="col-md-4 control-label"
|
|
|
|
for="target-branch">
|
|
|
|
Target branch
|
|
|
|
</label>
|
|
|
|
<div class="col-md-6">
|
|
|
|
<span class="help-block">
|
2017-09-28 10:05:38 -04:00
|
|
|
{{currentBranch}}
|
2017-08-15 15:53:41 -04:00
|
|
|
</span>
|
2017-07-25 09:18:45 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-08-15 15:53:41 -04:00
|
|
|
<div class="col-md-offset-4 col-md-6">
|
|
|
|
<button
|
|
|
|
ref="submitCommit"
|
|
|
|
type="submit"
|
|
|
|
:disabled="cantCommitYet"
|
|
|
|
class="btn btn-success">
|
|
|
|
<i
|
|
|
|
v-if="submitCommitsLoading"
|
|
|
|
class="fa fa-spinner fa-spin"
|
|
|
|
aria-hidden="true"
|
|
|
|
aria-label="loading">
|
|
|
|
</i>
|
|
|
|
<span class="commit-summary">
|
|
|
|
Commit {{changedFiles.length}} {{filePluralize}}
|
|
|
|
</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>
|