Skip to content

Commit

Permalink
feat(DataExport): compressed + uncompressed
Browse files Browse the repository at this point in the history
  • Loading branch information
adeelshahid committed May 18, 2018
1 parent 4e94623 commit 1d208b3
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/pages/export/Data.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'components'
import moment from 'moment'
import { api } from 'services'
import { apiConfig } from 'config'
import { today, createBlob, downloadBlob } from 'helpers'
import { getInstance } from 'd2/lib/d2'

Expand Down Expand Up @@ -274,24 +275,28 @@ export class DataExport extends FormBase {
formData.append('selectedDataSets', v)
})

let filename = `data.${exportFormat}`
const endpoint = '../../dhis-web-importexport/exportDataValue.action'
const { data } = await api.post(endpoint, formData)
let contents = data
if (exportFormat === 'json') {
contents = JSON.stringify(data)
}

const blobURL = createBlob(contents, exportFormat, compression)

if (compression === 'none') {
downloadBlob(blobURL, filename)
return
}

filename += `.${compression}`
window
.fetch(
`${apiConfig.server}/dhis-web-importexport/exportDataValue.action`,
{
body: formData,
cache: 'no-cache',
credentials: 'include',
method: 'POST',
mode: 'cors',
redirect: 'follow'
}
)
.then(response => response.blob())
.then(blob => {
let filename = `data.${exportFormat}`
if (compression !== 'none') {
filename += `.${compression}`
}

// TODO: download zipped blob
const url = window.URL.createObjectURL(blob)
downloadBlob(url, filename)
})
} catch (e) {
console.log('Data Export error', e, '\n')
}
Expand Down

0 comments on commit 1d208b3

Please sign in to comment.