diff --git a/beat/web/reports/static/reports/app/directives/downloadLink.js b/beat/web/reports/static/reports/app/directives/downloadLink.js index 213e368e07f1bbe1d8b8fec51d0c3630216e53cf..49342b12cc54ab263b516b90b65201d2e7e0818e 100644 --- a/beat/web/reports/static/reports/app/directives/downloadLink.js +++ b/beat/web/reports/static/reports/app/directives/downloadLink.js @@ -30,30 +30,34 @@ angular.module('reportApp') return { scope: { getDownloadHref: '&', - domId: '=', - imgName: '=' + domId: '@', + imgName: '@' }, link: function(scope){ - scope.downloadLinkId = `${scope.domId}-download`; + scope.downloadLinkId = () => `${scope.domId}-download`; + scope.setupDownloadLinkTest = (event) => { - const a = document.querySelector(`#${scope.downloadLinkId}`); - const href = scope.getDownloadHref()(); + const a = document.querySelector(`#${scope.downloadLinkId()}`); + const hrefs = scope.getDownloadHref()(); - if(!href){ - event.preventDefault(); - return false; - } + event.preventDefault(); - a.href = href; + hrefs.forEach((href, i) => { + a.href = href; + a.download = `${scope.imgName}-${i}.png`; + a.click(); + a.href = ''; + a.download = ''; + }) + ; }; }, template: ` <a - id='{{ downloadLinkId }}' + id='{{ downloadLinkId() }}' style='color: white;' class='btn btn-primary' - ng-click='setupDownloadLinkTest()' - download='img.png'> + ng-click='setupDownloadLinkTest($event)'> <i class='fa fa-download fa-lg'></i> Download </a> diff --git a/beat/web/reports/static/reports/app/directives/edit/plotItem.js b/beat/web/reports/static/reports/app/directives/edit/plotItem.js index 79c6df93dccf9f632b03225b51d6e8546dc59962..e2e320b216382816aa65a3f896982e0ccc335ad4 100644 --- a/beat/web/reports/static/reports/app/directives/edit/plotItem.js +++ b/beat/web/reports/static/reports/app/directives/edit/plotItem.js @@ -84,12 +84,13 @@ angular.module('reportApp') ); scope.exportSrcFunc = () => () => { - const el = document.querySelector(`#${scope.renderDivId} img`); - if(!el){ - return false; - } + const el = document.querySelectorAll(`#${scope.renderDivId} img`); + const srcs = Array.from(el) + .map(e => e.src) + //.map(src => src.replace(/^data:undefined/, 'data:application/octet-stream')); + ; - return el.src; + return srcs; }; }, template: ` @@ -118,8 +119,8 @@ angular.module('reportApp') </span> </div> <download-link - domId='domId' - imgName='"test.png"' + dom-id='{{ domId }}' + img-name='{{ renderDivId }}' get-download-href='exportSrcFunc()' > </download-link> diff --git a/beat/web/reports/static/reports/app/directives/view/plotItem.js b/beat/web/reports/static/reports/app/directives/view/plotItem.js index 2b268fffc69ad371f7931586b0768984ab4a736f..a13535e30a0351c931f7a1350afada1a21d6e511 100644 --- a/beat/web/reports/static/reports/app/directives/view/plotItem.js +++ b/beat/web/reports/static/reports/app/directives/view/plotItem.js @@ -43,19 +43,20 @@ angular.module('reportApp') }); scope.exportSrcFunc = () => () => { - const el = document.querySelector(`#${scope.renderDivId} img`); - if(!el){ - return false; - } + const el = document.querySelectorAll(`#${scope.renderDivId} img`); + const srcs = Array.from(el) + .map(e => e.src) + //.map(src => src.replace(/^data:undefined/, 'data:application/octet-stream')); + ; - return el.src; + return srcs; }; }, template: ` <download-link class='pull-right' - domId='domId' - imgName='"test.png"' + dom-id='{{ domId }}' + img-name='{{ renderDivId }}' get-download-href='exportSrcFunc()' > </download-link>