|
17 | 17 | v-permission:or="[PERMISSIONS.PORTFOLIO_MANAGEMENT, PERMISSIONS.BOM_UPLOAD]"> |
18 | 18 | <span class="fa fa-upload"></span> {{ $t('message.upload_bom') }} |
19 | 19 | </b-button> |
| 20 | + <b-dropdown variant="outline-primary" v-permission="PERMISSIONS.PORTFOLIO_MANAGEMENT"> |
| 21 | + <template #button-content> |
| 22 | + <span class="fa fa-download"></span> {{ $t('message.download_bom') }} |
| 23 | + </template> |
| 24 | + <b-dropdown-item @click="downloadBom('inventory')" href="#">{{ $t('message.inventory') }}</b-dropdown-item> |
| 25 | + <b-dropdown-item @click="downloadBom('withVulnerabilities')" href="#">{{ $t('message.inventory_with_vulnerabilities') }}</b-dropdown-item> |
| 26 | + <b-dropdown-item @click="downloadBom('vex')" href="#">{{ $t('message.vex_long_desc') }}</b-dropdown-item> |
| 27 | + </b-dropdown> |
20 | 28 | </div> |
21 | 29 | </div> |
22 | 30 | <bootstrap-table |
|
198 | 206 | } |
199 | 207 | this.$refs.table.uncheckAll(); |
200 | 208 | }, |
| 209 | + downloadBom: function (data) { |
| 210 | + let url = `${this.$api.BASE_URL}/${this.$api.URL_BOM}/cyclonedx/project/${this.uuid}`; |
| 211 | + this.axios.request({ |
| 212 | + responseType: 'blob', |
| 213 | + url: url, |
| 214 | + method: 'get', |
| 215 | + params: { |
| 216 | + format: 'json', |
| 217 | + variant: data, |
| 218 | + download: 'true' |
| 219 | + } |
| 220 | + }).then((response) => { |
| 221 | + const url = window.URL.createObjectURL(new Blob([response.data])); |
| 222 | + const link = document.createElement('a'); |
| 223 | + link.href = url; |
| 224 | + let filename = "bom.json"; |
| 225 | + let disposition = response.headers["content-disposition"] |
| 226 | + if (disposition && disposition.indexOf('attachment') !== -1) { |
| 227 | + let filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/; |
| 228 | + let matches = filenameRegex.exec(disposition); |
| 229 | + if (matches != null && matches[1]) { |
| 230 | + filename = matches[1].replace(/['"]/g, ''); |
| 231 | + } |
| 232 | + } |
| 233 | + link.setAttribute('download', filename); |
| 234 | + document.body.appendChild(link); |
| 235 | + link.click(); |
| 236 | + }); |
| 237 | + }, |
201 | 238 | tableLoaded: function(data) { |
202 | 239 | if (data && Object.prototype.hasOwnProperty.call(data, "total")) { |
203 | 240 | this.$emit('total', data.total); |
|
0 commit comments