2018-06-21 08:22:40 -04:00
|
|
|
<script>
|
|
|
|
import { mapState, mapGetters, mapActions } from 'vuex';
|
|
|
|
import Icon from '~/vue_shared/components/icon.vue';
|
|
|
|
import { __ } from '~/locale';
|
|
|
|
import createFlash from '~/flash';
|
2018-11-16 14:29:11 -05:00
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2018-06-29 03:22:07 -04:00
|
|
|
import eventHub from '../../notes/event_hub';
|
2018-06-21 08:22:40 -04:00
|
|
|
import CompareVersions from './compare_versions.vue';
|
|
|
|
import DiffFile from './diff_file.vue';
|
|
|
|
import NoChanges from './no_changes.vue';
|
|
|
|
import HiddenFilesWarning from './hidden_files_warning.vue';
|
2018-09-26 04:28:50 -04:00
|
|
|
import CommitWidget from './commit_widget.vue';
|
2018-10-03 05:05:43 -04:00
|
|
|
import TreeList from './tree_list.vue';
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'DiffsApp',
|
|
|
|
components: {
|
|
|
|
Icon,
|
|
|
|
CompareVersions,
|
|
|
|
DiffFile,
|
|
|
|
NoChanges,
|
|
|
|
HiddenFilesWarning,
|
2018-09-26 04:28:50 -04:00
|
|
|
CommitWidget,
|
2018-10-03 05:05:43 -04:00
|
|
|
TreeList,
|
2018-11-07 05:06:15 -05:00
|
|
|
GlLoadingIcon,
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
endpoint: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-06-26 14:49:22 -04:00
|
|
|
projectPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
shouldShow: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
currentUser: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2018-10-19 09:09:16 -04:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
assignedDiscussions: false,
|
|
|
|
};
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
isLoading: state => state.diffs.isLoading,
|
|
|
|
diffFiles: state => state.diffs.diffFiles,
|
|
|
|
diffViewType: state => state.diffs.diffViewType,
|
|
|
|
mergeRequestDiffs: state => state.diffs.mergeRequestDiffs,
|
|
|
|
mergeRequestDiff: state => state.diffs.mergeRequestDiff,
|
|
|
|
latestVersionPath: state => state.diffs.latestVersionPath,
|
|
|
|
startVersion: state => state.diffs.startVersion,
|
|
|
|
commit: state => state.diffs.commit,
|
|
|
|
targetBranchName: state => state.diffs.targetBranchName,
|
|
|
|
renderOverflowWarning: state => state.diffs.renderOverflowWarning,
|
|
|
|
numTotalFiles: state => state.diffs.realSize,
|
|
|
|
numVisibleFiles: state => state.diffs.size,
|
|
|
|
plainDiffPath: state => state.diffs.plainDiffPath,
|
|
|
|
emailPatchPath: state => state.diffs.emailPatchPath,
|
|
|
|
}),
|
2018-10-25 07:04:34 -04:00
|
|
|
...mapState('diffs', ['showTreeList', 'isLoading']),
|
2018-07-06 12:26:18 -04:00
|
|
|
...mapGetters('diffs', ['isParallelView']),
|
2018-10-19 09:09:16 -04:00
|
|
|
...mapGetters(['isNotesFetched', 'getNoteableData']),
|
2018-06-21 08:22:40 -04:00
|
|
|
targetBranch() {
|
|
|
|
return {
|
|
|
|
branchName: this.targetBranchName,
|
|
|
|
versionIndex: -1,
|
|
|
|
path: '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
notAllCommentsDisplayed() {
|
|
|
|
if (this.commit) {
|
|
|
|
return __('Only comments from the following commit are shown below');
|
|
|
|
} else if (this.startVersion) {
|
|
|
|
return __(
|
|
|
|
"Not all comments are displayed because you're comparing two versions of the diff.",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return __(
|
|
|
|
"Not all comments are displayed because you're viewing an old version of the diff.",
|
|
|
|
);
|
|
|
|
},
|
|
|
|
showLatestVersion() {
|
|
|
|
if (this.commit) {
|
|
|
|
return __('Show latest version of the diff');
|
|
|
|
}
|
|
|
|
return __('Show latest version');
|
|
|
|
},
|
2018-07-17 11:47:02 -04:00
|
|
|
canCurrentUserFork() {
|
2018-11-09 14:48:41 -05:00
|
|
|
return this.currentUser.can_fork === true && this.currentUser.can_create_merge_request;
|
2018-07-17 11:47:02 -04:00
|
|
|
},
|
2018-10-03 05:05:43 -04:00
|
|
|
showCompareVersions() {
|
|
|
|
return this.mergeRequestDiffs && this.mergeRequestDiff;
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
diffViewType() {
|
|
|
|
this.adjustView();
|
|
|
|
},
|
|
|
|
shouldShow() {
|
2018-06-29 03:22:07 -04:00
|
|
|
// When the shouldShow property changed to true, the route is rendered for the first time
|
|
|
|
// and if we have the isLoading as true this means we didn't fetch the data
|
|
|
|
if (this.isLoading) {
|
|
|
|
this.fetchData();
|
|
|
|
}
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
this.adjustView();
|
|
|
|
},
|
2018-10-03 05:05:43 -04:00
|
|
|
isLoading: 'adjustView',
|
|
|
|
showTreeList: 'adjustView',
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
|
|
|
mounted() {
|
2018-06-26 14:49:22 -04:00
|
|
|
this.setBaseConfig({ endpoint: this.endpoint, projectPath: this.projectPath });
|
2018-06-29 03:22:07 -04:00
|
|
|
|
|
|
|
if (this.shouldShow) {
|
|
|
|
this.fetchData();
|
|
|
|
}
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.adjustView();
|
2018-09-05 04:28:49 -04:00
|
|
|
eventHub.$once('fetchedNotesData', this.setDiscussions);
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
|
|
|
methods: {
|
2018-10-25 11:51:00 -04:00
|
|
|
...mapActions(['startTaskList']),
|
2018-08-13 04:47:54 -04:00
|
|
|
...mapActions('diffs', [
|
|
|
|
'setBaseConfig',
|
|
|
|
'fetchDiffFiles',
|
|
|
|
'startRenderDiffsQueue',
|
|
|
|
'assignDiscussionsToDiff',
|
|
|
|
]),
|
2018-06-29 03:22:07 -04:00
|
|
|
fetchData() {
|
2018-08-07 05:14:00 -04:00
|
|
|
this.fetchDiffFiles()
|
|
|
|
.then(() => {
|
2018-08-13 04:47:54 -04:00
|
|
|
requestIdleCallback(
|
|
|
|
() => {
|
2018-09-06 19:27:21 -04:00
|
|
|
this.setDiscussions();
|
|
|
|
this.startRenderDiffsQueue();
|
2018-08-13 04:47:54 -04:00
|
|
|
},
|
|
|
|
{ timeout: 1000 },
|
|
|
|
);
|
2018-08-07 05:14:00 -04:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
createFlash(__('Something went wrong on our end. Please try again!'));
|
|
|
|
});
|
2018-06-29 03:22:07 -04:00
|
|
|
|
|
|
|
if (!this.isNotesFetched) {
|
|
|
|
eventHub.$emit('fetchNotesData');
|
|
|
|
}
|
|
|
|
},
|
2018-09-05 04:28:49 -04:00
|
|
|
setDiscussions() {
|
2018-10-25 07:04:34 -04:00
|
|
|
if (this.isNotesFetched && !this.assignedDiscussions && !this.isLoading) {
|
2018-10-30 06:41:25 -04:00
|
|
|
this.assignedDiscussions = true;
|
|
|
|
|
2018-10-25 11:51:00 -04:00
|
|
|
requestIdleCallback(
|
|
|
|
() =>
|
|
|
|
this.assignDiscussionsToDiff()
|
|
|
|
.then(this.$nextTick)
|
|
|
|
.then(this.startTaskList),
|
|
|
|
{ timeout: 1000 },
|
|
|
|
);
|
2018-09-05 04:28:49 -04:00
|
|
|
}
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
adjustView() {
|
2018-10-03 05:05:43 -04:00
|
|
|
if (this.shouldShow) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
window.mrTabs.resetViewContainer();
|
|
|
|
window.mrTabs.expandViewContainer(this.showTreeList);
|
|
|
|
});
|
2018-06-21 08:22:40 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2018-06-30 09:17:46 -04:00
|
|
|
<div v-show="shouldShow">
|
2018-06-21 08:22:40 -04:00
|
|
|
<div
|
|
|
|
v-if="isLoading"
|
|
|
|
class="loading"
|
|
|
|
>
|
2018-09-11 18:19:21 -04:00
|
|
|
<gl-loading-icon />
|
2018-06-21 08:22:40 -04:00
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-else
|
|
|
|
id="diffs"
|
|
|
|
:class="{ active: shouldShow }"
|
|
|
|
class="diffs tab-pane"
|
|
|
|
>
|
|
|
|
<compare-versions
|
2018-10-03 05:05:43 -04:00
|
|
|
v-if="showCompareVersions"
|
2018-06-21 08:22:40 -04:00
|
|
|
:merge-request-diffs="mergeRequestDiffs"
|
|
|
|
:merge-request-diff="mergeRequestDiff"
|
|
|
|
:start-version="startVersion"
|
|
|
|
:target-branch="targetBranch"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<hidden-files-warning
|
|
|
|
v-if="renderOverflowWarning"
|
|
|
|
:visible="numVisibleFiles"
|
|
|
|
:total="numTotalFiles"
|
|
|
|
:plain-diff-path="plainDiffPath"
|
|
|
|
:email-patch-path="emailPatchPath"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div
|
|
|
|
v-if="commit || startVersion || (mergeRequestDiff && !mergeRequestDiff.latest)"
|
|
|
|
class="mr-version-controls"
|
|
|
|
>
|
|
|
|
<div class="content-block comments-disabled-notif clearfix">
|
|
|
|
<i class="fa fa-info-circle"></i>
|
|
|
|
{{ notAllCommentsDisplayed }}
|
|
|
|
<div class="pull-right">
|
|
|
|
<a
|
|
|
|
:href="latestVersionPath"
|
|
|
|
class="btn btn-sm"
|
|
|
|
>
|
|
|
|
{{ showLatestVersion }}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2018-09-26 04:28:50 -04:00
|
|
|
<commit-widget
|
|
|
|
v-if="commit"
|
|
|
|
:commit="commit"
|
|
|
|
/>
|
|
|
|
|
2018-10-18 03:50:38 -04:00
|
|
|
<div
|
|
|
|
:data-can-create-note="getNoteableData.current_user.can_create_note"
|
|
|
|
class="files d-flex prepend-top-default"
|
|
|
|
>
|
2018-10-03 05:05:43 -04:00
|
|
|
<div
|
|
|
|
v-show="showTreeList"
|
|
|
|
class="diff-tree-list"
|
|
|
|
>
|
|
|
|
<tree-list />
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-if="diffFiles.length > 0"
|
|
|
|
class="diff-files-holder"
|
|
|
|
>
|
|
|
|
<diff-file
|
|
|
|
v-for="file in diffFiles"
|
|
|
|
:key="file.newPath"
|
|
|
|
:file="file"
|
|
|
|
:can-current-user-fork="canCurrentUserFork"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<no-changes v-else />
|
2018-06-21 08:22:40 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|