From c1ade00f1d05a95dc790c7f1ff0ecdca550e3196 Mon Sep 17 00:00:00 2001 From: xiaoluoboding Date: Fri, 19 Aug 2016 14:20:46 +0800 Subject: [PATCH] Urgly way to rebuild the tree object --- index.html | 2 +- src/components/Tree.vue | 45 ++++++++++++++++++----------- src/components/main.vue | 14 --------- src/vuex/modules/github.js | 58 ++++++++++++++++++++------------------ 4 files changed, 60 insertions(+), 59 deletions(-) diff --git a/index.html b/index.html index 9b80bb9..adce67e 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - repository-tree + Repository Tree
diff --git a/src/components/Tree.vue b/src/components/Tree.vue index 2216a1c..a4fc7b1 100644 --- a/src/components/Tree.vue +++ b/src/components/Tree.vue @@ -1,30 +1,43 @@ diff --git a/src/components/main.vue b/src/components/main.vue index 78c6aeb..3e18bcb 100644 --- a/src/components/main.vue +++ b/src/components/main.vue @@ -49,18 +49,4 @@ export default { line-height: 26px; color: #666; } - - .boxed-header { - position: relative; - padding: 10px; - margin-bottom: -1px; - font-size: 13px; - line-height: 20px; - color: #68777d; - background-color: #f2f9fc; - border: 1px solid #c9e6f2; - border-radius: 3px; - border-bottom-right-radius: 0; - border-bottom-left-radius: 0; - } diff --git a/src/vuex/modules/github.js b/src/vuex/modules/github.js index 17d2f14..00f2097 100644 --- a/src/vuex/modules/github.js +++ b/src/vuex/modules/github.js @@ -12,7 +12,7 @@ import treeify from 'treeify' // initial state const state = { siteLink: 'https://github.com/', - repoLink: '', + repoLink: 'https://github.com/xiaoluoboding/vue-stroll', userName: '', repoName: '', repoTree: [] @@ -29,46 +29,48 @@ const mutations = { state.repoName = repoName }, [SET_REPOTREE](state, repoTree) { - let rootTree = [] - // set rootBlob - let rootBlobArray = filter(repoTree, function(obj) { - return !obj.path.includes('/') && obj.type == 'blob' - }) - let rootBlob = {} - for (let i in rootBlobArray) { - rootBlob[rootBlobArray[i].path] = null - } - // console.dir(rootBlob) + let perttyTree = {} - let rootTreeArray = filter(repoTree, function(obj) { - return obj.type == 'tree' - }) - - let treeArray = {} - for (var i in rootTreeArray) { + // set rootTree + let rootTreeArray = filter(repoTree, (obj) => !obj.path.includes('/') && obj.type == 'tree') + let rootTree = {} + for (let i in rootTreeArray) { if (rootTreeArray.hasOwnProperty(i)) { + rootTree[rootTreeArray[i].path] = [] + } + } + + // console.log(rootTree); + // set rootBlob + let rootBlobArray = filter(repoTree, (obj) => !obj.path.includes('/') && obj.type == 'blob') + let rootBlob = {} + for (let i in rootBlobArray) { + if (rootBlobArray.hasOwnProperty(i)) { + rootBlob[rootBlobArray[i].path] = null } } - let childBlobArray = filter(repoTree, function(obj) { - return obj.path.includes('/') && obj.type == 'blob' - }) + // console.log(rootBlob); - let childArray = {} + // iterate childBlob + let childBlobArray = filter(repoTree, (obj) => obj.path.includes('/') && obj.type == 'blob') for (var i in childBlobArray) { if (childBlobArray.hasOwnProperty(i)) { let treeParent = childBlobArray[i].path.split('\/').shift() let treeChild = childBlobArray[i].path.split('\/').pop() - console.log(childBlobArray[i].path) - console.log(treeChild) - childArray[treeChild] = null + for (var i in rootTreeArray) { + if (rootTreeArray.hasOwnProperty(i) && rootTreeArray[i].path == treeParent) { + rootTree[treeParent][treeChild] = null + } + } } } - console.log(childArray) - // set rootTree - rootTree.push(rootBlob) - state.repoTree = treeify.asTree(rootTree) + + // set perttyTree + perttyTree = _.merge(rootTree, rootBlob) + console.log(perttyTree); + state.repoTree = treeify.asTree(perttyTree) } }