|
| 1 | +<template> |
| 2 | + <div class="bucket"> |
| 3 | + <div class="row"> |
| 4 | + <div class="col-md-3"> |
| 5 | + <div class="container"> |
| 6 | + <h3>{{bucket}} ({{manifestEntries.length}})</h3> |
| 7 | + <b-nav vertical pills class="w-100"> |
| 8 | + <!-- <b-nav-item active>Active</b-nav-item> --> |
| 9 | + <b-nav-item v-for="(subject, index) in manifestEntries" |
| 10 | + :key="subject" :active="index === currentReportIdx" |
| 11 | + @click="currentReportIdx = index"> |
| 12 | + {{subject.split('/')[0]}} |
| 13 | + </b-nav-item> |
| 14 | + </b-nav> |
| 15 | + </div> |
| 16 | + </div> |
| 17 | + <div class="col-md-9"> |
| 18 | + <h1 v-if="manifestEntries.length"> |
| 19 | + {{manifestEntries[currentReportIdx].split('/')[0]}} |
| 20 | + </h1> |
| 21 | + <div v-if="ready"> |
| 22 | + <report |
| 23 | + :reportProp="currentReport" |
| 24 | + /> |
| 25 | + </div> |
| 26 | + <div v-else> |
| 27 | + loading... |
| 28 | + </div> |
| 29 | + </div> |
| 30 | + </div> |
| 31 | + </div> |
| 32 | +</template> |
| 33 | + |
| 34 | +<script> |
| 35 | +import axios from 'axios'; |
| 36 | +import _ from 'lodash'; |
| 37 | +import Report from './Report'; |
| 38 | +
|
| 39 | +export default { |
| 40 | + name: 'bucket', |
| 41 | + data() { |
| 42 | + return { |
| 43 | + manifestEntries: [], |
| 44 | + currentReportIdx: 0, |
| 45 | + currentReport: {}, |
| 46 | + ready: false, |
| 47 | + }; |
| 48 | + }, |
| 49 | + components: { |
| 50 | + Report, |
| 51 | + }, |
| 52 | + methods: { |
| 53 | + /** |
| 54 | + * XML parser for pubmed query returns. |
| 55 | + */ |
| 56 | + xmlParser(input) { |
| 57 | + const parser = new DOMParser(); |
| 58 | + const xmlDoc = parser.parseFromString(input, 'text/xml'); |
| 59 | + return xmlDoc; |
| 60 | + }, |
| 61 | + /** |
| 62 | + * |
| 63 | + */ |
| 64 | + parseS3(data) { |
| 65 | + const xml = this.xmlParser(data); |
| 66 | + const keys = xml.getElementsByTagName('Key'); |
| 67 | + const continuation = xml.getElementsByTagName('NextContinuationToken'); |
| 68 | + const isTruncated = xml.getElementsByTagName('IsTruncated')[0].innerHTML; |
| 69 | + if (isTruncated === 'true') { |
| 70 | + this.continuation = encodeURIComponent(continuation[0].innerHTML); |
| 71 | + } else { |
| 72 | + this.continuation = null; |
| 73 | + } |
| 74 | + const allKeys = _.map(keys, k => k.innerHTML); |
| 75 | + const reportsFiltered = _.filter(allKeys, k => k.endsWith('_report.json'));// _.map(allKeys, k => k.split('/')[0]); |
| 76 | + const keysFixed = _.uniq(reportsFiltered); |
| 77 | + return keysFixed; |
| 78 | + }, |
| 79 | + /** |
| 80 | + * if there is a continuation token.. |
| 81 | + */ |
| 82 | + S3Continuation(token) { |
| 83 | + let url = `https://s3-us-west-2.amazonaws.com/${this.bucket}/?list-type=2&`; |
| 84 | + // url += `prefix=${this.config.manifestS3.prefix}/&max-keys=100000`; |
| 85 | + url += '&max-keys=100000'; |
| 86 | + // url += `&delimiter=${this.config.manifestS3.delimiter}`; |
| 87 | + url += `&continuation-token=${token}`; |
| 88 | + if (!token) { |
| 89 | + return 0; |
| 90 | + } |
| 91 | + return axios.get(url).then((resp) => { |
| 92 | + const keysFixed2 = this.parseS3(resp.data); |
| 93 | + this.manifestEntries = _.uniq(this.manifestEntries.concat(keysFixed2)); |
| 94 | + if (this.continuation) { |
| 95 | + this.S3Continuation(this.continuation); |
| 96 | + } |
| 97 | + }); |
| 98 | + }, |
| 99 | + /** |
| 100 | + * get a list of files that are in a bucket of an S3 |
| 101 | + * with a prefix and a delimiter (usually, a .) |
| 102 | + * TODO: make the keys firebase safe!! |
| 103 | + */ |
| 104 | + getS3Manifest() { |
| 105 | + let url = `https://s3-us-west-2.amazonaws.com/${this.bucket}/?list-type=2&`; |
| 106 | + url += '&max-keys=100000'; |
| 107 | + // url += `prefix=${this.config.manifestS3.prefix} |
| 108 | + // /&max-keys=${this.config.manifestS3.max_keys}`; |
| 109 | + // url += `&delimiter=${this.config.manifestS3.delimiter}`; |
| 110 | + // console.log(url); |
| 111 | + return axios.get(url).then((resp) => { |
| 112 | + const keysFixed = this.parseS3(resp.data); |
| 113 | + this.manifestEntries = _.uniq(this.manifestEntries.concat(keysFixed)); |
| 114 | + if (this.continuation) { |
| 115 | + this.S3Continuation(this.continuation); |
| 116 | + } |
| 117 | + }); |
| 118 | + }, |
| 119 | + updateReport() { |
| 120 | + this.ready = false; |
| 121 | + axios.get(`https://s3-us-west-2.amazonaws.com/${this.bucket}/${this.manifestEntries[this.currentReportIdx]}`) |
| 122 | + .then((resp) => { |
| 123 | + this.currentReport = resp.data; |
| 124 | + this.ready = true; |
| 125 | + }); |
| 126 | + }, |
| 127 | + }, |
| 128 | + computed: { |
| 129 | + bucket() { |
| 130 | + return this.$route.params.bucket; |
| 131 | + }, |
| 132 | + }, |
| 133 | + watch: { |
| 134 | + bucket() { |
| 135 | + this.getS3Manifest(); |
| 136 | + }, |
| 137 | + currentReportIdx() { |
| 138 | + this.updateReport(); |
| 139 | + }, |
| 140 | + }, |
| 141 | + mounted() { |
| 142 | + this.getS3Manifest().then(this.updateReport); |
| 143 | + }, |
| 144 | +}; |
| 145 | +</script> |
| 146 | + |
| 147 | +<style> |
| 148 | +
|
| 149 | +</style> |
0 commit comments