Commit ddc0f837 authored by Phil Hughes's avatar Phil Hughes

made serializing generic

fixed previous directory showing when it shouldnt
parent fa9e729a
...@@ -32,11 +32,11 @@ export default { ...@@ -32,11 +32,11 @@ export default {
computed: { computed: {
flattendFiles() { flattendFiles() {
const map = (arr) => { const map = (arr) => {
if (arr && arr.tree && arr.tree.length === 0) { if (arr && arr.files && arr.files.length === 0) {
return []; return [];
} }
return _.map(arr.tree, a => [a, map(a)]); return _.map(arr.files, a => [a, map(a)]);
}; };
return _.chain(this.files) return _.chain(this.files)
...@@ -100,7 +100,7 @@ export default { ...@@ -100,7 +100,7 @@ export default {
goToPreviousDirectoryClicked(prevURL) { goToPreviousDirectoryClicked(prevURL) {
Service.url = prevURL; Service.url = prevURL;
Helper.getContent(null) Helper.getContent(null, true)
.then(() => Helper.scrollTabsRight()) .then(() => Helper.scrollTabsRight())
.catch(Helper.loadingError); .catch(Helper.loadingError);
}, },
......
...@@ -66,7 +66,7 @@ const RepoHelper = { ...@@ -66,7 +66,7 @@ const RepoHelper = {
const dir = entry; const dir = entry;
dir.opened = false; dir.opened = false;
dir.tree = []; dir.files = [];
}, },
isRenderable() { isRenderable() {
...@@ -83,7 +83,7 @@ const RepoHelper = { ...@@ -83,7 +83,7 @@ const RepoHelper = {
.catch(RepoHelper.loadingError); .catch(RepoHelper.loadingError);
}, },
getContent(treeOrFile) { getContent(treeOrFile, emptyFiles = false) {
let file = treeOrFile; let file = treeOrFile;
if (!Store.files.length) { if (!Store.files.length) {
...@@ -94,7 +94,10 @@ const RepoHelper = { ...@@ -94,7 +94,10 @@ const RepoHelper = {
.then((response) => { .then((response) => {
const data = response.data; const data = response.data;
if (response.headers && response.headers['page-title']) data.pageTitle = response.headers['page-title']; 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.type === 'blob') {
if (!file) file = data; if (!file) file = data;
...@@ -120,17 +123,24 @@ const RepoHelper = { ...@@ -120,17 +123,24 @@ const RepoHelper = {
Store.loading.tree = false; Store.loading.tree = false;
RepoHelper.setDirectoryOpen(file, data.pageTitle || data.name); RepoHelper.setDirectoryOpen(file, data.pageTitle || data.name);
if (!file) { if (emptyFiles) {
Store.files = this.dataToListOfFiles(data); Store.files = [];
} else {
file.tree = this.dataToListOfFiles(data, file.level + 1);
} }
this.addToDirectory(file, data);
Store.prevURL = Service.blobURLtoParentTree(Service.url); Store.prevURL = Service.blobURLtoParentTree(Service.url);
} }
}).catch(RepoHelper.loadingError); }).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) { setFile(data, file) {
const newFile = data; const newFile = data;
newFile.url = file.url || Service.url; // Grab the URL from service, happens on page refresh. newFile.url = file.url || Service.url; // Grab the URL from service, happens on page refresh.
...@@ -144,18 +154,6 @@ const RepoHelper = { ...@@ -144,18 +154,6 @@ const RepoHelper = {
Store.setActiveFiles(newFile); 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) { serializeRepoEntity(type, entity, level = 0) {
const { url, name, icon, last_commit } = entity; const { url, name, icon, last_commit } = entity;
const returnObj = { const returnObj = {
...@@ -164,7 +162,7 @@ const RepoHelper = { ...@@ -164,7 +162,7 @@ const RepoHelper = {
url, url,
level, level,
icon: `fa-${icon}`, icon: `fa-${icon}`,
tree: [], files: [],
loading: false, loading: false,
opened: false, opened: false,
}; };
...@@ -192,9 +190,9 @@ const RepoHelper = { ...@@ -192,9 +190,9 @@ const RepoHelper = {
dataToListOfFiles(data, level) { dataToListOfFiles(data, level) {
const { blobs, trees, submodules } = data; const { blobs, trees, submodules } = data;
return [ return [
...trees.map(tree => RepoHelper.serializeTree(tree, level)), ...trees.map(tree => RepoHelper.serializeRepoEntity('tree', tree, level)),
...blobs.map(blob => RepoHelper.serializeBlob(blob, level)), ...submodules.map(submodule => RepoHelper.serializeRepoEntity('submodule', submodule, level)),
...submodules.map(submodule => RepoHelper.serializeSubmodule(submodule, level)), ...blobs.map(blob => RepoHelper.serializeRepoEntity('blob', blob, level)),
]; ];
}, },
......
...@@ -35,6 +35,7 @@ function setInitialStore(data) { ...@@ -35,6 +35,7 @@ function setInitialStore(data) {
Store.newMrTemplateUrl = decodeURIComponent(data.newMrTemplateUrl); Store.newMrTemplateUrl = decodeURIComponent(data.newMrTemplateUrl);
Store.customBranchURL = decodeURIComponent(data.blobUrl); Store.customBranchURL = decodeURIComponent(data.blobUrl);
Store.isRoot = convertPermissionToBoolean(data.root); Store.isRoot = convertPermissionToBoolean(data.root);
Store.isInitialRoot = convertPermissionToBoolean(data.root);
Store.currentBranch = $('button.dropdown-menu-toggle').attr('data-ref'); Store.currentBranch = $('button.dropdown-menu-toggle').attr('data-ref');
Store.checkIsCommitable(); Store.checkIsCommitable();
Store.setBranchHash(); Store.setBranchHash();
......
...@@ -8,6 +8,7 @@ const RepoStore = { ...@@ -8,6 +8,7 @@ const RepoStore = {
onTopOfBranch: false, onTopOfBranch: false,
editMode: false, editMode: false,
isRoot: null, isRoot: null,
isInitialRoot: null,
prevURL: '', prevURL: '',
projectId: '', projectId: '',
projectName: '', projectName: '',
......
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