Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Fix report export urls (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
anehx authored Oct 24, 2017
1 parent 2efba36 commit a2f4a20
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
15 changes: 8 additions & 7 deletions app/analysis/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,31 @@ const AnalysisController = Controller.extend(ReportFilterControllerMixin, {

exportLinks: config.APP.REPORTEXPORTS,

getTarget(url) {
getTarget(url, params) {
let queryString = toQueryString(
cleanParams(
this.getProperties(
cleanParams({
...params,
...this.getProperties(
...this.get('queryParams').filter(
key => !['page', 'page_size'].includes(key)
),
'jwt'
)
)
})
)

return `${url}&${queryString}`
return `${url}?${queryString}`
},

actions: {
download(url) {
download(url, params) {
/* istanbul ignore else */
if (testing) {
return
}

/* istanbul ignore next */
window.location.href = this.getTarget(url)
window.location.href = this.getTarget(url, params)
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion app/analysis/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

<p>
{{#each exportLinks as |link index|}}
<button {{action 'download' link.url}}
<button {{action 'download' link.url link.params}}
type="button"
disabled={{gt model.length 4000}}
class="btn btn-default"
Expand Down
18 changes: 14 additions & 4 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,29 @@ module.exports = function(environment) {
REPORTEXPORTS: [
{
label: 'CSV',
url: '/api/v1/reports/export?file_type=csv'
url: '/api/v1/reports/export',
params: {
file_type: 'csv'
}
},
{
label: 'ODS',
url: '/api/v1/reports/export?file_type=ods'
url: '/api/v1/reports/export',
params: {
file_type: 'ods'
}
},
{
label: 'XLSX',
url: '/api/v1/reports/export?file_type=xlsx'
url: '/api/v1/reports/export',
params: {
file_type: 'xlsx'
}
},
{
label: 'Work report',
url: '/api/v1/work-reports'
url: '/api/v1/work-reports',
params: {}
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/analysis/controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ describe('Unit | Controller | analysis', function() {
controller.set('page_size', 100)
controller.set('customer', 1)

let target = controller.getTarget('test')
let target = controller.getTarget('test', { foo: 'bar' })

expect(target).to.contain('foo=bar')
expect(target).to.contain('jwt=foobar')
expect(target).to.contain('user=1')
expect(target).to.contain('customer=1')
Expand Down

0 comments on commit a2f4a20

Please sign in to comment.