houdini/client/js/nonprofits/reports/modal.js
Bradley M. Kuhn fc77ee76d6 Relicense Javascript code in accordance with project's new license
The primary license of the project is changing to:
  AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later

The Additional Permission is designed to permit publicly distributed
Javascript code to be relicensed under LGPL-3.0-or-later, but not server-side
Javascript code.  As such, we've relicensed here static Javscript files under
LGPL-3.0-or-later, and those that run as part of build and/or server side
under AGPL-3.0-or-later.

Note that in future, Javascript files may be updated to be stronger copyleft
license with the Additional Permission, particularly if they adapted to run
on server side and/or turned into templates.  Of course, we'd seek public
discussion with the contributor community about such changes.

This commit is one of the many steps to relicense the entire codebase.

Documentation granting permission for this relicensing (from all past
contributors who hold copyrights) is on file with Software Freedom
Conservancy, Inc.
2018-03-25 15:10:40 -04:00

58 lines
1.7 KiB
JavaScript

// License: LGPL-3.0-or-later
const flyd = require('flyd')
const flyd_filter = require('flyd/module/filter')
const R = require('ramda')
const h = require('snabbdom/h')
const moment = require('moment')
// Modal component for exporting reports
// XXX Note: this can be generalized to be any report modal, but for now it is specific to end-of-year
flyd.log = flyd.map(console.log.bind(console))
function init() {
var state = {
currentYear: moment().year()
, changeYear$: flyd.stream()
, submit$: flyd.stream()
}
const selectedYear$ = flyd_filter(
year => Number(year) <= state.currentYear && Number(year) >= 2012
, flyd.merge(
flyd.map(ev => ev.currentTarget.value, state.changeYear$)
, flyd.stream(state.currentYear)
)
)
state.exportPath$ = flyd.map(year => `/nonprofits/${ENV.nonprofitID}/reports/end_of_year.csv?year=${year}`, selectedYear$)
return state
}
function view(state) {
return h('div.modal', {props: {id: 'endOfYearReportModal'}}, [
h('div.modal-header', [ h('h2', 'End-of-year report') ])
, h('div.modal-body', [
modalBody(state)
])
])
}
const modalBody = state => {
return h('div', [
h('p', 'Export donors who have given during a selected year, with their aggregated totals, averages, and itemized payments histories for that year.')
, h('label', 'Year')
, h('input', {
on: {change: state.changeYear$}
, props: {
type: 'number'
, placeholder: 'YYYY'
, value: state.currentYear
, min: 2012
, max: state.currentYear
}
})
, h('a.button', {props: {target: '_blank', href: state.exportPath$()}}, 'Download CSV Report')
])
}
module.exports = {init, view}