Skip to content
Snippets Groups Projects
Commit 711f1e14 authored by Jaden Diefenbaugh's avatar Jaden Diefenbaugh
Browse files

download link downloads all plots, fix weird angular undefined variables issues, fixes #15

parent 37687100
No related branches found
No related tags found
1 merge request!223Reports overhaul
...@@ -30,30 +30,34 @@ angular.module('reportApp') ...@@ -30,30 +30,34 @@ angular.module('reportApp')
return { return {
scope: { scope: {
getDownloadHref: '&', getDownloadHref: '&',
domId: '=', domId: '@',
imgName: '=' imgName: '@'
}, },
link: function(scope){ link: function(scope){
scope.downloadLinkId = `${scope.domId}-download`; scope.downloadLinkId = () => `${scope.domId}-download`;
scope.setupDownloadLinkTest = (event) => { scope.setupDownloadLinkTest = (event) => {
const a = document.querySelector(`#${scope.downloadLinkId}`); const a = document.querySelector(`#${scope.downloadLinkId()}`);
const href = scope.getDownloadHref()(); const hrefs = scope.getDownloadHref()();
if(!href){ event.preventDefault();
event.preventDefault();
return false;
}
a.href = href; hrefs.forEach((href, i) => {
a.href = href;
a.download = `${scope.imgName}-${i}.png`;
a.click();
a.href = '';
a.download = '';
})
;
}; };
}, },
template: ` template: `
<a <a
id='{{ downloadLinkId }}' id='{{ downloadLinkId() }}'
style='color: white;' style='color: white;'
class='btn btn-primary' class='btn btn-primary'
ng-click='setupDownloadLinkTest()' ng-click='setupDownloadLinkTest($event)'>
download='img.png'>
<i class='fa fa-download fa-lg'></i> <i class='fa fa-download fa-lg'></i>
Download Download
</a> </a>
......
...@@ -84,12 +84,13 @@ angular.module('reportApp') ...@@ -84,12 +84,13 @@ angular.module('reportApp')
); );
scope.exportSrcFunc = () => () => { scope.exportSrcFunc = () => () => {
const el = document.querySelector(`#${scope.renderDivId} img`); const el = document.querySelectorAll(`#${scope.renderDivId} img`);
if(!el){ const srcs = Array.from(el)
return false; .map(e => e.src)
} //.map(src => src.replace(/^data:undefined/, 'data:application/octet-stream'));
;
return el.src; return srcs;
}; };
}, },
template: ` template: `
...@@ -118,8 +119,8 @@ angular.module('reportApp') ...@@ -118,8 +119,8 @@ angular.module('reportApp')
</span> </span>
</div> </div>
<download-link <download-link
domId='domId' dom-id='{{ domId }}'
imgName='"test.png"' img-name='{{ renderDivId }}'
get-download-href='exportSrcFunc()' get-download-href='exportSrcFunc()'
> >
</download-link> </download-link>
......
...@@ -43,19 +43,20 @@ angular.module('reportApp') ...@@ -43,19 +43,20 @@ angular.module('reportApp')
}); });
scope.exportSrcFunc = () => () => { scope.exportSrcFunc = () => () => {
const el = document.querySelector(`#${scope.renderDivId} img`); const el = document.querySelectorAll(`#${scope.renderDivId} img`);
if(!el){ const srcs = Array.from(el)
return false; .map(e => e.src)
} //.map(src => src.replace(/^data:undefined/, 'data:application/octet-stream'));
;
return el.src; return srcs;
}; };
}, },
template: ` template: `
<download-link <download-link
class='pull-right' class='pull-right'
domId='domId' dom-id='{{ domId }}'
imgName='"test.png"' img-name='{{ renderDivId }}'
get-download-href='exportSrcFunc()' get-download-href='exportSrcFunc()'
> >
</download-link> </download-link>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment