Commit 05420006 authored by Phil Hughes's avatar Phil Hughes

Multi-file editor fetch log data from a different endpoint

Closes #38360
parent d4ceec9d
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
...mapGetters([ ...mapGetters([
'isCollapsed', 'isCollapsed',
]), ]),
isSubmodule() {
return this.file.type === 'submodule';
},
fileIcon() { fileIcon() {
return { return {
'fa-spinner fa-spin': this.file.loading, 'fa-spinner fa-spin': this.file.loading,
...@@ -31,6 +34,9 @@ ...@@ -31,6 +34,9 @@
shortId() { shortId() {
return this.file.id.substr(0, 8); return this.file.id.substr(0, 8);
}, },
submoduleColSpan() {
return !this.isCollapsed && this.isSubmodule ? 3 : undefined;
},
}, },
methods: { methods: {
...mapActions([ ...mapActions([
...@@ -44,7 +50,7 @@ ...@@ -44,7 +50,7 @@
<tr <tr
class="file" class="file"
@click.prevent="clickedTreeRow(file)"> @click.prevent="clickedTreeRow(file)">
<td> <td :colspan="submoduleColSpan">
<i <i
class="fa fa-fw file-icon" class="fa fa-fw file-icon"
:class="fileIcon" :class="fileIcon"
...@@ -58,7 +64,7 @@ ...@@ -58,7 +64,7 @@
> >
{{ file.name }} {{ file.name }}
</a> </a>
<template v-if="file.type === 'submodule' && file.id"> <template v-if="isSubmodule && file.id">
@ @
<span class="commit-sha"> <span class="commit-sha">
<a <a
...@@ -71,15 +77,27 @@ ...@@ -71,15 +77,27 @@
</template> </template>
</td> </td>
<template v-if="!isCollapsed"> <template v-if="!isCollapsed && !isSubmodule">
<td class="hidden-sm hidden-xs"> <td class="hidden-sm hidden-xs">
<a <a
v-if="file.lastCommit.message"
@click.stop @click.stop
:href="file.lastCommit.url" :href="file.lastCommit.url"
class="commit-message" class="commit-message"
> >
{{ file.lastCommit.message }} {{ file.lastCommit.message }}
</a> </a>
<div
v-else
class="animation-container animation-container-small"
>
<div
v-for="n in 6"
:key="n"
:class="'skeleton-line-' + n"
>
</div>
</div>
</td> </td>
<td class="commit-update hidden-xs text-right"> <td class="commit-update hidden-xs text-right">
...@@ -89,6 +107,17 @@ ...@@ -89,6 +107,17 @@
> >
{{ timeFormated(file.lastCommit.updatedAt) }} {{ timeFormated(file.lastCommit.updatedAt) }}
</span> </span>
<div
v-else
class="animation-container animation-container-small animation-container-right"
>
<div
v-for="n in 6"
:key="n"
:class="'skeleton-line-' + n"
>
</div>
</div>
</td> </td>
</template> </template>
</tr> </tr>
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<template v-if="!isCollapsed"> <template v-if="!isCollapsed">
<td <td
class="hidden-sm hidden-xs"> class="hidden-sm hidden-xs">
<div class="animation-container"> <div class="animation-container animation-container-small">
<div <div
v-for="n in 6" v-for="n in 6"
:key="n" :key="n"
......
...@@ -30,4 +30,11 @@ export default { ...@@ -30,4 +30,11 @@ export default {
commit(projectId, payload) { commit(projectId, payload) {
return Api.commitMultiple(projectId, payload); return Api.commitMultiple(projectId, payload);
}, },
getTreeLastCommit(endpoint) {
return Vue.http.get(endpoint, {
params: {
format: 'json',
},
});
},
}; };
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
} from '../utils'; } from '../utils';
export const getTreeData = ( export const getTreeData = (
{ commit, state }, { commit, state, dispatch },
{ endpoint = state.endpoints.rootEndpoint, tree = state } = {}, { endpoint = state.endpoints.rootEndpoint, tree = state } = {},
) => { ) => {
commit(types.TOGGLE_LOADING, tree); commit(types.TOGGLE_LOADING, tree);
...@@ -30,7 +30,9 @@ export const getTreeData = ( ...@@ -30,7 +30,9 @@ export const getTreeData = (
commit(types.SET_DIRECTORY_DATA, { data, tree }); commit(types.SET_DIRECTORY_DATA, { data, tree });
commit(types.SET_PARENT_TREE_URL, data.parent_tree_url); commit(types.SET_PARENT_TREE_URL, data.parent_tree_url);
commit(types.SET_LAST_COMMIT_URL, { tree, url: data.last_commit_path });
commit(types.TOGGLE_LOADING, tree); commit(types.TOGGLE_LOADING, tree);
dispatch('getLastCommitData', tree);
pushState(endpoint); pushState(endpoint);
}) })
...@@ -108,3 +110,28 @@ export const createTempTree = ({ state, commit, dispatch }, name) => { ...@@ -108,3 +110,28 @@ export const createTempTree = ({ state, commit, dispatch }, name) => {
}); });
} }
}; };
export const getLastCommitData = ({ state, commit, dispatch }, tree = state) => {
if (tree.lastCommitPath === '') return;
service.getTreeLastCommit(tree.lastCommitPath)
.then((res) => {
const lastCommitPath = normalizeHeaders(res.headers)['LOG-URL'];
commit(types.SET_LAST_COMMIT_URL, { tree, url: lastCommitPath });
return res.json();
})
.then((data) => {
data.forEach((lastCommit) => {
const entry = findEntry(tree, lastCommit.type, lastCommit.file_name);
if (entry) {
commit(types.SET_LAST_COMMIT_DATA, { entry, lastCommit });
}
});
dispatch('getLastCommitData', tree);
})
.catch(() => flash('Error fetching log data.'));
};
...@@ -4,11 +4,13 @@ export const SET_COMMIT_REF = 'SET_COMMIT_REF'; ...@@ -4,11 +4,13 @@ export const SET_COMMIT_REF = 'SET_COMMIT_REF';
export const SET_PARENT_TREE_URL = 'SET_PARENT_TREE_URL'; export const SET_PARENT_TREE_URL = 'SET_PARENT_TREE_URL';
export const SET_ROOT = 'SET_ROOT'; export const SET_ROOT = 'SET_ROOT';
export const SET_PREVIOUS_URL = 'SET_PREVIOUS_URL'; export const SET_PREVIOUS_URL = 'SET_PREVIOUS_URL';
export const SET_LAST_COMMIT_DATA = 'SET_LAST_COMMIT_DATA';
// Tree mutation types // Tree mutation types
export const SET_DIRECTORY_DATA = 'SET_DIRECTORY_DATA'; export const SET_DIRECTORY_DATA = 'SET_DIRECTORY_DATA';
export const TOGGLE_TREE_OPEN = 'TOGGLE_TREE_OPEN'; export const TOGGLE_TREE_OPEN = 'TOGGLE_TREE_OPEN';
export const CREATE_TMP_TREE = 'CREATE_TMP_TREE'; export const CREATE_TMP_TREE = 'CREATE_TMP_TREE';
export const SET_LAST_COMMIT_URL = 'SET_LAST_COMMIT_URL';
// File mutation types // File mutation types
export const SET_FILE_DATA = 'SET_FILE_DATA'; export const SET_FILE_DATA = 'SET_FILE_DATA';
......
...@@ -48,6 +48,13 @@ export default { ...@@ -48,6 +48,13 @@ export default {
previousUrl, previousUrl,
}); });
}, },
[types.SET_LAST_COMMIT_DATA](state, { entry, lastCommit }) {
Object.assign(entry.lastCommit, {
url: `${state.project.url}/commit/${lastCommit.commit.id}`,
message: lastCommit.commit.message,
updatedAt: lastCommit.commit.authored_date,
});
},
...fileMutations, ...fileMutations,
...treeMutations, ...treeMutations,
...branchMutations, ...branchMutations,
......
...@@ -18,19 +18,19 @@ export default { ...@@ -18,19 +18,19 @@ export default {
type: 'tree', type: 'tree',
parentTreeUrl, parentTreeUrl,
level, level,
}, state.project.url)), })),
...data.submodules.map(m => utils.decorateData({ ...data.submodules.map(m => utils.decorateData({
...m, ...m,
type: 'submodule', type: 'submodule',
parentTreeUrl, parentTreeUrl,
level, level,
}, state.project.url)), })),
...data.blobs.map(b => utils.decorateData({ ...data.blobs.map(b => utils.decorateData({
...b, ...b,
type: 'blob', type: 'blob',
parentTreeUrl, parentTreeUrl,
level, level,
}, state.project.url)), })),
], ],
}); });
}, },
...@@ -39,6 +39,11 @@ export default { ...@@ -39,6 +39,11 @@ export default {
parentTreeUrl: url, parentTreeUrl: url,
}); });
}, },
[types.SET_LAST_COMMIT_URL](state, { tree = state, url }) {
Object.assign(tree, {
lastCommitPath: url,
});
},
[types.CREATE_TMP_TREE](state, { parent, tmpEntry }) { [types.CREATE_TMP_TREE](state, { parent, tmpEntry }) {
parent.tree.push(tmpEntry); parent.tree.push(tmpEntry);
}, },
......
...@@ -8,6 +8,7 @@ export default () => ({ ...@@ -8,6 +8,7 @@ export default () => ({
endpoints: {}, endpoints: {},
isRoot: false, isRoot: false,
isInitialRoot: false, isInitialRoot: false,
lastCommitPath: '',
loading: false, loading: false,
onTopOfBranch: false, onTopOfBranch: false,
openFiles: [], openFiles: [],
......
...@@ -12,7 +12,12 @@ export const dataStructure = () => ({ ...@@ -12,7 +12,12 @@ export const dataStructure = () => ({
opened: false, opened: false,
active: false, active: false,
changed: false, changed: false,
lastCommit: {}, lastCommitPath: '',
lastCommit: {
url: '',
message: '',
updatedAt: '',
},
tree_url: '', tree_url: '',
blamePath: '', blamePath: '',
commitsPath: '', commitsPath: '',
...@@ -27,14 +32,13 @@ export const dataStructure = () => ({ ...@@ -27,14 +32,13 @@ export const dataStructure = () => ({
base64: false, base64: false,
}); });
export const decorateData = (entity, projectUrl = '') => { export const decorateData = (entity) => {
const { const {
id, id,
type, type,
url, url,
name, name,
icon, icon,
last_commit,
tree_url, tree_url,
path, path,
renderError, renderError,
...@@ -66,12 +70,6 @@ export const decorateData = (entity, projectUrl = '') => { ...@@ -66,12 +70,6 @@ export const decorateData = (entity, projectUrl = '') => {
renderError, renderError,
content, content,
base64, base64,
// eslint-disable-next-line camelcase
lastCommit: last_commit ? {
url: `${projectUrl}/commit/${last_commit.id}`,
message: last_commit.message,
updatedAt: last_commit.committed_date,
} : {},
}; };
}; };
......
...@@ -58,7 +58,8 @@ class Projects::RefsController < Projects::ApplicationController ...@@ -58,7 +58,8 @@ class Projects::RefsController < Projects::ApplicationController
last_commit = @repo.last_commit_for_path(@commit.id, file) last_commit = @repo.last_commit_for_path(@commit.id, file)
{ {
file_name: content.name, file_name: content.name,
commit: last_commit commit: last_commit,
type: content.type
} }
end end
end end
...@@ -70,6 +71,11 @@ class Projects::RefsController < Projects::ApplicationController ...@@ -70,6 +71,11 @@ class Projects::RefsController < Projects::ApplicationController
respond_to do |format| respond_to do |format|
format.html { render_404 } format.html { render_404 }
format.json do
response.headers["Log-Url"] = @more_log_url
render json: @logs
end
format.js format.js
end end
end end
......
...@@ -3,10 +3,6 @@ class BlobEntity < Grape::Entity ...@@ -3,10 +3,6 @@ class BlobEntity < Grape::Entity
expose :id, :path, :name, :mode expose :id, :path, :name, :mode
expose :last_commit do |blob|
request.project.repository.last_commit_for_path(blob.commit_id, blob.path)
end
expose :icon do |blob| expose :icon do |blob|
IconsHelper.file_type_icon_class('file', blob.mode, blob.name) IconsHelper.file_type_icon_class('file', blob.mode, blob.name)
end end
......
...@@ -3,10 +3,6 @@ class TreeEntity < Grape::Entity ...@@ -3,10 +3,6 @@ class TreeEntity < Grape::Entity
expose :id, :path, :name, :mode expose :id, :path, :name, :mode
expose :last_commit do |tree|
request.project.repository.last_commit_for_path(tree.commit_id, tree.path)
end
expose :icon do |tree| expose :icon do |tree|
IconsHelper.file_type_icon_class('folder', tree.mode, tree.name) IconsHelper.file_type_icon_class('folder', tree.mode, tree.name)
end end
......
...@@ -18,4 +18,8 @@ class TreeRootEntity < Grape::Entity ...@@ -18,4 +18,8 @@ class TreeRootEntity < Grape::Entity
project_tree_path(request.project, File.join(request.ref, parent_tree_path)) project_tree_path(request.project, File.join(request.ref, parent_tree_path))
end end
expose :last_commit_path do |tree|
logs_file_project_ref_path(request.project, request.ref, tree.path)
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment