Created
May 15, 2018 03:44
-
-
Save idream3/fd60ccda06f32e94c0fafaf99731f4b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async getDocsForView(entryId, projectId, depth = 1) { | |
| this.state.state.cursor('fetchingStatus').set(true); | |
| let res = []; | |
| const entry = await this.getDoc(entryId); | |
| res.push(entry); | |
| const parentId = R.last(entry.ancestors); | |
| const childrenIds = R.concat(R.keys(entry.stepIds), R.keys(entry.postIds)); | |
| const keys = [].concat(childrenIds, parentId || []); | |
| this.getComputedProperties(entry, projectId); | |
| const response = await this.getAllDocs( | |
| { | |
| include_docs: true, | |
| conflicts: true, | |
| keys, | |
| selector: { | |
| $not: { | |
| 'meta.deleted': 'true' | |
| } | |
| } | |
| }, | |
| entry | |
| ); | |
| const docs = response.rows.filter(r => r.doc !== undefined).map(r => r.doc); | |
| const children = docs.filter(d => d._id !== parentId); | |
| const parent = docs.filter(d => d._id === parentId)[0]; | |
| res.push(parent, ...children); | |
| // -- Grandchildren for checkpoints?? | |
| // Render application tree | |
| CouchUtils.addEntriesToState([parent, entry, ...children]); | |
| if (entry.meta.dependant && entry.meta.display === 'flat') { | |
| const grandChildrenIds = R.compose( | |
| R.flatten, | |
| R.map(d => R.concat( | |
| R.keys(d.stepIds), | |
| R.keys(d.postIds) | |
| )) | |
| )(children) | |
| const response = await this.getAllDocs( | |
| { | |
| include_docs: true, | |
| conflicts: true, | |
| keys: grandChildrenIds, | |
| selector: { | |
| $not: { | |
| 'meta.deleted': 'true' | |
| } | |
| } | |
| }, | |
| entry | |
| ); | |
| const grandChildren = response.rows | |
| .filter(r => r.doc !== undefined) | |
| .map(r => r.doc) | |
| res.push(...grandChildren) | |
| CouchUtils.addEntriesToState(grandChildren); | |
| const postCommentIds = R.compose( | |
| R.flatten, | |
| R.map(d => R.keys(d.postIds)), | |
| )(grandChildren) | |
| if (postCommentIds.length) { | |
| const responseDepth2 = await this.getAllDocs( | |
| { | |
| include_docs: true, | |
| conflicts: true, | |
| keys: postCommentIds, | |
| selector: { | |
| $not: { | |
| 'meta.deleted': 'true' | |
| } | |
| } | |
| }, | |
| entry | |
| ); | |
| const postComments = responseDepth2.rows | |
| .filter(r => r.doc !== undefined) | |
| .map(r => r.doc) | |
| res.push(...postComments) | |
| CouchUtils.addEntriesToState(postComments); | |
| } | |
| } | |
| console.log('res', res) | |
| return res; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment