2017-07-25 09:18:45 -04:00
|
|
|
<script>
|
2017-10-26 06:14:31 -04:00
|
|
|
import { mapGetters, mapState, mapActions } from 'vuex';
|
2017-11-23 12:16:01 -05:00
|
|
|
import tooltip from '../../vue_shared/directives/tooltip';
|
|
|
|
import icon from '../../vue_shared/components/icon.vue';
|
2017-12-11 13:43:28 -05:00
|
|
|
import modal from '../../vue_shared/components/modal.vue';
|
2017-11-23 12:16:01 -05:00
|
|
|
import commitFilesList from './commit_sidebar/list.vue';
|
2017-07-25 09:18:45 -04:00
|
|
|
|
2017-08-15 14:16:42 -04:00
|
|
|
export default {
|
2017-10-12 17:04:17 -04:00
|
|
|
components: {
|
2017-12-11 13:43:28 -05:00
|
|
|
modal,
|
2017-11-23 12:16:01 -05:00
|
|
|
icon,
|
|
|
|
commitFilesList,
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
tooltip,
|
2017-10-12 17:04:17 -04:00
|
|
|
},
|
2017-10-26 06:14:31 -04:00
|
|
|
data() {
|
|
|
|
return {
|
2017-12-11 13:43:28 -05:00
|
|
|
showNewBranchModal: false,
|
2017-10-26 06:14:31 -04:00
|
|
|
submitCommitsLoading: false,
|
|
|
|
startNewMR: false,
|
|
|
|
commitMessage: '',
|
|
|
|
};
|
|
|
|
},
|
2017-07-28 19:33:56 -04:00
|
|
|
computed: {
|
2017-10-26 06:14:31 -04:00
|
|
|
...mapState([
|
2017-12-21 10:05:47 -05:00
|
|
|
'currentProjectId',
|
|
|
|
'currentBranchId',
|
|
|
|
'rightPanelCollapsed',
|
2017-10-26 06:14:31 -04:00
|
|
|
]),
|
|
|
|
...mapGetters([
|
|
|
|
'changedFiles',
|
|
|
|
]),
|
|
|
|
commitButtonDisabled() {
|
2017-11-24 08:12:04 -05:00
|
|
|
return this.commitMessage === '' || this.submitCommitsLoading || !this.changedFiles.length;
|
2017-08-06 11:12:29 -04:00
|
|
|
},
|
2017-11-23 12:16:01 -05:00
|
|
|
commitMessageCount() {
|
|
|
|
return this.commitMessage.length;
|
2017-07-28 23:08:05 -04:00
|
|
|
},
|
2017-07-28 19:33:56 -04:00
|
|
|
},
|
2017-07-25 09:18:45 -04:00
|
|
|
methods: {
|
2017-10-26 06:14:31 -04:00
|
|
|
...mapActions([
|
|
|
|
'checkCommitStatus',
|
|
|
|
'commitChanges',
|
2017-10-30 10:36:24 -04:00
|
|
|
'getTreeData',
|
2017-12-21 10:05:47 -05:00
|
|
|
'setPanelCollapsedStatus',
|
2017-10-26 06:14:31 -04:00
|
|
|
]),
|
|
|
|
makeCommit(newBranch = false) {
|
|
|
|
const createNewBranch = newBranch || this.startNewMR;
|
2017-10-12 17:04:17 -04:00
|
|
|
|
2017-07-25 10:54:27 -04:00
|
|
|
const payload = {
|
2017-12-21 10:05:47 -05:00
|
|
|
branch: createNewBranch ? `${this.currentBranchId}-${new Date().getTime().toString()}` : this.currentBranchId,
|
2017-10-26 06:14:31 -04:00
|
|
|
commit_message: this.commitMessage,
|
|
|
|
actions: this.changedFiles.map(f => ({
|
|
|
|
action: f.tempFile ? 'create' : 'update',
|
|
|
|
file_path: f.path,
|
|
|
|
content: f.content,
|
2017-10-31 08:13:29 -04:00
|
|
|
encoding: f.base64 ? 'base64' : 'text',
|
2017-10-26 06:14:31 -04:00
|
|
|
})),
|
2017-12-21 10:05:47 -05:00
|
|
|
start_branch: createNewBranch ? this.currentBranchId : undefined,
|
2017-07-26 08:56:31 -04:00
|
|
|
};
|
2017-10-26 06:14:31 -04:00
|
|
|
|
2017-12-11 13:43:28 -05:00
|
|
|
this.showNewBranchModal = false;
|
2017-10-26 06:14:31 -04:00
|
|
|
this.submitCommitsLoading = true;
|
|
|
|
|
|
|
|
this.commitChanges({ payload, newMr: this.startNewMR })
|
2017-10-12 17:04:17 -04:00
|
|
|
.then(() => {
|
2017-10-26 06:14:31 -04:00
|
|
|
this.submitCommitsLoading = false;
|
2017-12-21 10:05:47 -05:00
|
|
|
this.$store.dispatch('getTreeData', {
|
|
|
|
projectId: this.currentProjectId,
|
|
|
|
branch: this.currentBranchId,
|
|
|
|
endpoint: `/tree/${this.currentBranchId}`,
|
|
|
|
force: true,
|
|
|
|
});
|
2017-10-12 17:04:17 -04:00
|
|
|
})
|
|
|
|
.catch(() => {
|
2017-10-26 06:14:31 -04:00
|
|
|
this.submitCommitsLoading = false;
|
2017-10-12 17:04:17 -04:00
|
|
|
});
|
|
|
|
},
|
2017-10-26 06:14:31 -04:00
|
|
|
tryCommit() {
|
2017-10-19 11:24:00 -04:00
|
|
|
this.submitCommitsLoading = true;
|
|
|
|
|
2017-10-26 06:14:31 -04:00
|
|
|
this.checkCommitStatus()
|
|
|
|
.then((branchChanged) => {
|
|
|
|
if (branchChanged) {
|
2017-12-11 13:43:28 -05:00
|
|
|
this.showNewBranchModal = true;
|
2017-10-26 06:14:31 -04:00
|
|
|
} else {
|
|
|
|
this.makeCommit();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.submitCommitsLoading = false;
|
|
|
|
});
|
2017-07-26 08:56:31 -04:00
|
|
|
},
|
2017-11-23 12:16:01 -05:00
|
|
|
toggleCollapsed() {
|
2017-12-21 10:05:47 -05:00
|
|
|
this.setPanelCollapsedStatus({
|
|
|
|
side: 'right',
|
|
|
|
collapsed: !this.rightPanelCollapsed,
|
|
|
|
});
|
2017-11-23 12:16:01 -05: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-12-21 10:05:47 -05:00
|
|
|
<div class="multi-file-commit-panel-section">
|
2017-12-11 13:43:28 -05:00
|
|
|
<modal
|
|
|
|
v-if="showNewBranchModal"
|
2017-10-12 17:04:17 -04:00
|
|
|
:primary-button-label="__('Create new branch')"
|
|
|
|
kind="primary"
|
|
|
|
:title="__('Branch has changed')"
|
|
|
|
:text="__('This branch has changed since you started editing. Would you like to create a new branch?')"
|
2018-01-03 04:21:17 -05:00
|
|
|
@cancel="showNewBranchModal = false"
|
2017-10-26 06:14:31 -04:00
|
|
|
@submit="makeCommit(true)"
|
2017-10-12 17:04:17 -04:00
|
|
|
/>
|
2017-11-23 12:16:01 -05:00
|
|
|
<commit-files-list
|
|
|
|
title="Staged"
|
|
|
|
:file-list="changedFiles"
|
2017-12-21 10:05:47 -05:00
|
|
|
:collapsed="rightPanelCollapsed"
|
2017-11-23 12:16:01 -05:00
|
|
|
@toggleCollapsed="toggleCollapsed"
|
|
|
|
/>
|
2017-08-15 15:53:41 -04:00
|
|
|
<form
|
2017-11-23 12:16:01 -05:00
|
|
|
class="form-horizontal multi-file-commit-form"
|
|
|
|
@submit.prevent="tryCommit"
|
2017-12-21 10:05:47 -05:00
|
|
|
v-if="!rightPanelCollapsed"
|
2017-11-23 12:16:01 -05:00
|
|
|
>
|
|
|
|
<div class="multi-file-commit-fieldset">
|
|
|
|
<textarea
|
|
|
|
class="form-control multi-file-commit-message"
|
|
|
|
name="commit-message"
|
|
|
|
v-model="commitMessage"
|
|
|
|
placeholder="Commit message"
|
|
|
|
>
|
|
|
|
</textarea>
|
|
|
|
</div>
|
|
|
|
<div class="multi-file-commit-fieldset">
|
|
|
|
<label
|
|
|
|
v-tooltip
|
|
|
|
title="Create a new merge request with these changes"
|
|
|
|
data-container="body"
|
|
|
|
data-placement="top"
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
v-model="startNewMR"
|
|
|
|
/>
|
|
|
|
Merge Request
|
|
|
|
</label>
|
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
:disabled="commitButtonDisabled"
|
|
|
|
class="btn btn-default btn-sm append-right-10 prepend-left-10"
|
|
|
|
>
|
|
|
|
<i
|
|
|
|
v-if="submitCommitsLoading"
|
|
|
|
class="js-commit-loading-icon fa fa-spinner fa-spin"
|
|
|
|
aria-hidden="true"
|
|
|
|
aria-label="loading"
|
|
|
|
>
|
|
|
|
</i>
|
|
|
|
Commit
|
|
|
|
</button>
|
|
|
|
<div
|
|
|
|
class="multi-file-commit-message-count"
|
|
|
|
>
|
|
|
|
{{ commitMessageCount }}
|
2017-10-12 17:04:17 -04:00
|
|
|
</div>
|
2017-11-23 12:16:01 -05:00
|
|
|
</div>
|
2017-07-25 09:18:45 -04:00
|
|
|
</form>
|
|
|
|
</div>
|
2017-07-26 08:39:32 -04:00
|
|
|
</template>
|