abowden-spotx closed pull request #4747: [WiP] Download Dashboards as PDF
URL: https://github.com/apache/incubator-superset/pull/4747
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/assets/javascripts/dashboard/components/Header.jsx 
b/superset/assets/javascripts/dashboard/components/Header.jsx
index 52d3024ff9..f56ee1c932 100644
--- a/superset/assets/javascripts/dashboard/components/Header.jsx
+++ b/superset/assets/javascripts/dashboard/components/Header.jsx
@@ -7,6 +7,7 @@ import Button from '../../components/Button';
 import FaveStar from '../../components/FaveStar';
 import InfoTooltipWithTrigger from '../../components/InfoTooltipWithTrigger';
 import { t } from '../../locales';
+import * as util from '../../reduxUtils';
 
 const propTypes = {
   dashboard: PropTypes.object.isRequired,
@@ -68,6 +69,19 @@ class Header extends React.PureComponent {
         {btnText}
       </Button>);
   }
+  renderDownloadButton() {
+    // TODO: review button style
+    const btnText = 'Download';
+    return (
+      <button
+        bsStyle="default"
+        className="m-r-5"
+        style={{ width: '100px' }}
+        onClick={util.downloadCurPage}
+      >
+        {btnText}
+      </button>);
+  }
   render() {
     const dashboard = this.props.dashboard;
     return (
diff --git a/superset/assets/javascripts/reduxUtils.js 
b/superset/assets/javascripts/reduxUtils.js
index d843d279a2..9036e5421f 100644
--- a/superset/assets/javascripts/reduxUtils.js
+++ b/superset/assets/javascripts/reduxUtils.js
@@ -98,3 +98,15 @@ export function areArraysShallowEqual(arr1, arr2) {
 export function areObjectsEqual(obj1, obj2) {
   return equals(obj1, obj2, true);
 }
+
+export function downloadCurPage() {
+  // This will call a python script to download the current page as a pdf
+  $.ajax({
+      type: 'GET',
+      url: '/download_pdf',
+      data: function() {
+          return string(window.location.href) //TODO: pass dash specific info
+      },
+      success: alert('PDF Downloaded')
+  })
+}
diff --git a/superset/views/core.py b/superset/views/core.py
index 91a420ae28..d723a37adf 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -692,6 +692,15 @@ def ping():
     return 'OK'
 
 
+@app.route('/download_pdf')
+def download_pdf(url='http://localhost:8088/superset/dashboard/births/'): 
#TODO: collect url to download
+    #TODO: pass session authorization
+    dir = os.getcwd() #TODO
+    file_name = 'sample_dl.pdf' #TODO: file naming structure
+    pdfkit.from_url(url, dir + file_name)
+    return 'Success'
+
+
 class KV(BaseSupersetView):
 
     """Used for storing and retrieving key value pairs"""


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to