summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-10-16 14:19:22 +0100
committerPhil Hughes <me@iamphill.com>2017-10-16 14:19:22 +0100
commitddc0f837a019ce7140dc5c84fdef4ff4094f5cab (patch)
treefb04a34540ec25493ed8df989dd01854ddba175a /app
parentfa9e729aba58ddb00e09282e63a497d9d8e99dea (diff)
downloadgitlab-ce-ddc0f837a019ce7140dc5c84fdef4ff4094f5cab.tar.gz
made serializing generic
fixed previous directory showing when it shouldnt
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/repo/components/repo_sidebar.vue6
-rw-r--r--app/assets/javascripts/repo/helpers/repo_helper.js44
-rw-r--r--app/assets/javascripts/repo/index.js1
-rw-r--r--app/assets/javascripts/repo/stores/repo_store.js1
4 files changed, 26 insertions, 26 deletions
diff --git a/app/assets/javascripts/repo/components/repo_sidebar.vue b/app/assets/javascripts/repo/components/repo_sidebar.vue
index dc990324313..12d5432d1fe 100644
--- a/app/assets/javascripts/repo/components/repo_sidebar.vue
+++ b/app/assets/javascripts/repo/components/repo_sidebar.vue
@@ -32,11 +32,11 @@ export default {
computed: {
flattendFiles() {
const map = (arr) => {
- if (arr && arr.tree && arr.tree.length === 0) {
+ if (arr && arr.files && arr.files.length === 0) {
return [];
}
- return _.map(arr.tree, a => [a, map(a)]);
+ return _.map(arr.files, a => [a, map(a)]);
};
return _.chain(this.files)
@@ -100,7 +100,7 @@ export default {
goToPreviousDirectoryClicked(prevURL) {
Service.url = prevURL;
- Helper.getContent(null)
+ Helper.getContent(null, true)
.then(() => Helper.scrollTabsRight())
.catch(Helper.loadingError);
},
diff --git a/app/assets/javascripts/repo/helpers/repo_helper.js b/app/assets/javascripts/repo/helpers/repo_helper.js
index 2481a8aa107..39c8d8738c7 100644
--- a/app/assets/javascripts/repo/helpers/repo_helper.js
+++ b/app/assets/javascripts/repo/helpers/repo_helper.js
@@ -66,7 +66,7 @@ const RepoHelper = {
const dir = entry;
dir.opened = false;
- dir.tree = [];
+ dir.files = [];
},
isRenderable() {
@@ -83,7 +83,7 @@ const RepoHelper = {
.catch(RepoHelper.loadingError);
},
- getContent(treeOrFile) {
+ getContent(treeOrFile, emptyFiles = false) {
let file = treeOrFile;
if (!Store.files.length) {
@@ -94,7 +94,10 @@ const RepoHelper = {
.then((response) => {
const data = response.data;
if (response.headers && response.headers['page-title']) data.pageTitle = response.headers['page-title'];
- if (response.headers && response.headers['is-root'] && Store.isRoot === null) Store.isRoot = convertPermissionToBoolean(response.headers['is-root']);
+ if (response.headers && response.headers['is-root'] && !Store.isInitialRoot) {
+ Store.isRoot = convertPermissionToBoolean(response.headers['is-root']);
+ Store.isInitialRoot = Store.isRoot;
+ }
if (file && file.type === 'blob') {
if (!file) file = data;
@@ -120,17 +123,24 @@ const RepoHelper = {
Store.loading.tree = false;
RepoHelper.setDirectoryOpen(file, data.pageTitle || data.name);
- if (!file) {
- Store.files = this.dataToListOfFiles(data);
- } else {
- file.tree = this.dataToListOfFiles(data, file.level + 1);
+ if (emptyFiles) {
+ Store.files = [];
}
+ this.addToDirectory(file, data);
+
Store.prevURL = Service.blobURLtoParentTree(Service.url);
}
}).catch(RepoHelper.loadingError);
},
+ addToDirectory(file, data) {
+ const tree = file || Store;
+ const files = tree.files.concat(this.dataToListOfFiles(data, file ? file.level + 1 : 0));
+
+ tree.files = files;
+ },
+
setFile(data, file) {
const newFile = data;
newFile.url = file.url || Service.url; // Grab the URL from service, happens on page refresh.
@@ -144,18 +154,6 @@ const RepoHelper = {
Store.setActiveFiles(newFile);
},
- serializeBlob(blob, level) {
- return RepoHelper.serializeRepoEntity('blob', blob, level);
- },
-
- serializeTree(tree, level) {
- return RepoHelper.serializeRepoEntity('tree', tree, level);
- },
-
- serializeSubmodule(submodule, level) {
- return RepoHelper.serializeRepoEntity('submodule', submodule, level);
- },
-
serializeRepoEntity(type, entity, level = 0) {
const { url, name, icon, last_commit } = entity;
const returnObj = {
@@ -164,7 +162,7 @@ const RepoHelper = {
url,
level,
icon: `fa-${icon}`,
- tree: [],
+ files: [],
loading: false,
opened: false,
};
@@ -192,9 +190,9 @@ const RepoHelper = {
dataToListOfFiles(data, level) {
const { blobs, trees, submodules } = data;
return [
- ...trees.map(tree => RepoHelper.serializeTree(tree, level)),
- ...blobs.map(blob => RepoHelper.serializeBlob(blob, level)),
- ...submodules.map(submodule => RepoHelper.serializeSubmodule(submodule, level)),
+ ...trees.map(tree => RepoHelper.serializeRepoEntity('tree', tree, level)),
+ ...submodules.map(submodule => RepoHelper.serializeRepoEntity('submodule', submodule, level)),
+ ...blobs.map(blob => RepoHelper.serializeRepoEntity('blob', blob, level)),
];
},
diff --git a/app/assets/javascripts/repo/index.js b/app/assets/javascripts/repo/index.js
index f0a059d7ae3..65dee7d5fd1 100644
--- a/app/assets/javascripts/repo/index.js
+++ b/app/assets/javascripts/repo/index.js
@@ -35,6 +35,7 @@ function setInitialStore(data) {
Store.newMrTemplateUrl = decodeURIComponent(data.newMrTemplateUrl);
Store.customBranchURL = decodeURIComponent(data.blobUrl);
Store.isRoot = convertPermissionToBoolean(data.root);
+ Store.isInitialRoot = convertPermissionToBoolean(data.root);
Store.currentBranch = $('button.dropdown-menu-toggle').attr('data-ref');
Store.checkIsCommitable();
Store.setBranchHash();
diff --git a/app/assets/javascripts/repo/stores/repo_store.js b/app/assets/javascripts/repo/stores/repo_store.js
index 1a9757f1a4a..49d7317a17e 100644
--- a/app/assets/javascripts/repo/stores/repo_store.js
+++ b/app/assets/javascripts/repo/stores/repo_store.js
@@ -8,6 +8,7 @@ const RepoStore = {
onTopOfBranch: false,
editMode: false,
isRoot: null,
+ isInitialRoot: null,
prevURL: '',
projectId: '',
projectName: '',