Commit ac3c0eb7 authored by Henrique Varella Ehrenfried's avatar Henrique Varella Ehrenfried

Merge branch 'sinapir_download_table' into 'development'

Sinapir download table

See merge request !39
parents 682ff151 ec5a9f24
......@@ -104,6 +104,39 @@ class Table extends Component {
}
}
componentDidUpdate(prevProps) {
if (this.props.getCsv && JSON.stringify(this.props.data) !== JSON.stringify(prevProps.data)) {
this.dataObjectToCsv();
}
}
dataObjectToCsv() {
let data = this.props.data;
let csvTable = '';
if (data[0] !== undefined) {
let headerList = Object.keys(data[0]);
let header = '';
headerList.forEach(h => {
header += '"' + h + '",';
})
header.slice(0, -1)
csvTable = "data:text/csv;charset=utf-8," + header + '\n';
data.forEach(row => {
headerList.forEach(column => {
if (row[column] !== null)
csvTable += '"' + row[column] + '"';
csvTable += ',';
})
csvTable = csvTable.slice(0, -1) + '\n'
})
csvTable = encodeURI(csvTable);
}
this.props.getCsv(csvTable);
}
render() {
var defaultButton = props => (
<button style={style[this.state.mode].button} type="button" {...props} className="-btn">
......
......@@ -63,6 +63,10 @@ class Table extends Component {
var header = this.loadHeader();
if (data) this.setState({ data: data });
if (header) this.setState({ headers: header });
if (this.props.getCsv) {
this.dataToCsv();
}
}
componentDidUpdate(prevProps) {
......@@ -72,6 +76,12 @@ class Table extends Component {
if (data) this.setState({ data: data });
if (header) this.setState({ headers: header });
}
// Update CSV data
if (this.props.getCsv && JSON.stringify(this.props.body) !== JSON.stringify(prevProps.body)) {
this.dataToCsv();
}
prevProps = null;
}
......@@ -177,6 +187,34 @@ class Table extends Component {
}
return (body);
}
dataToCsv() {
let data = this.props.body;
console.log(data, this.props)
let csvTable = '';
if (data[0] !== undefined) {
let headerList = this.props.header;
let header = '';
headerList.forEach(h => {
header += '"' + h + '",';
})
header.slice(0, -1)
csvTable = "data:text/csv;charset=utf-8," + header + '\n';
data.forEach(row => {
row.forEach(item => {
if (item !== null)
csvTable += '"' + item + '"';
csvTable += ',';
})
csvTable = csvTable.slice(0, -1) + '\n'
})
csvTable = encodeURI(csvTable);
}
this.props.getCsv(csvTable);
}
}
export default Table;
......
......@@ -30,6 +30,7 @@ import './Styles/AgreementsInExecution.css'
import { getRegionState, getStateAcronym } from '../enviroment';
import Collapsible from 'react-materialize/lib/Collapsible';
import CollapsibleContainer from '../Components/CollapsibleContainer';
import CardFooter from '../Components/CardFooter'
// /**
// * Contains adherence level of states and cities to the SINAPIR.<br />
......@@ -48,9 +49,13 @@ class AgreementsInExecution extends Component {
state: null,
area: null,
clickedInMap: null,
municipiosCsv: '',
contatosCsv: ''
}
this.handleMapClick = this.handleMapClick.bind(this);
this.handleFilterChange = this.handleFilterChange.bind(this);
this.conveniosCsv = this.conveniosCsv.bind(this);
this.emendasCsv = this.emendasCsv.bind(this);
}
formatData(objectConvenios) {
......@@ -140,6 +145,14 @@ class AgreementsInExecution extends Component {
return this.formatData(data);
}
conveniosCsv(csv) {
this.setState({ conveniosCsv: csv });
}
emendasCsv(csv) {
this.setState({ emendasCsv: csv});
}
render() {
let contrastString = this.context.state.contrast;
return (
......@@ -200,8 +213,10 @@ class AgreementsInExecution extends Component {
body={this.conveniosTable(conveniosJson)}
classes="striped agreementsTableCells"
divClasses="agreementsTable"
getCsv={this.conveniosCsv}
pageSi>
</Table>
<CardFooter data={this.state.conveniosCsv} source=" Sistema de Convênios - SICONV"></CardFooter>
</CollapsibleContainer>
</Collapsible>
</Col>
......@@ -217,8 +232,10 @@ class AgreementsInExecution extends Component {
body={this.conveniosTable(emendasJson)}
classes="striped agreementsTableCells"
divClasses="agreementsTable"
getCsv={this.emendasCsv}
pageSi>
</Table>
<CardFooter data={this.state.emendasCsv} source=" Sistema de Convênios - SICONV"></CardFooter>
</CollapsibleContainer>
</Collapsible>
</Col>
......
......@@ -28,6 +28,7 @@ import cadpirContatos from '../JsonsAntigos/sinapir-members/cadpir'
import './Styles/SinapirMembers.css'
import PageTable from '../Components/PageTable'
import { getStateAcronym } from '../enviroment'
import CardFooter from '../Components/CardFooter'
// /**
// * Contains adherence level of states and cities to the SINAPIR.<br />
......@@ -45,7 +46,9 @@ class SinapirMembers extends Component {
cadpirContatos: [],
municipiosData: [],
clickedCity: null,
showOnlySinapirContacts: true
showOnlySinapirContacts: true,
municipiosCsv: '',
contatosCsv: '',
};
this.getMapClick = this.getMapClick.bind(this);
this.clearMap = this.clearMap.bind(this);
......@@ -54,6 +57,8 @@ class SinapirMembers extends Component {
this.handleMunicipiosTableClick = this.handleMunicipiosTableClick.bind(this);
this.handleCheckboxClick = this.handleCheckboxClick.bind(this);
this.clearFilters = this.clearFilters.bind(this);
this.municipiosCsv = this.municipiosCsv.bind(this);
this.contatosCsv = this.contatosCsv.bind(this);
}
componentDidMount() {
......@@ -137,6 +142,14 @@ class SinapirMembers extends Component {
this.setState({ clickedCity: null, clickedInMap: null})
}
municipiosCsv(csv) {
this.setState({ municipiosCsv : csv});
}
contatosCsv(csv) {
this.setState({ contatosCsv : csv });
}
render() {
let contrastString = this.context.state.contrast;
return (
......@@ -194,6 +207,7 @@ class SinapirMembers extends Component {
data={this.municipiosTable()}
pageSize={9}
onClick={this.handleMunicipiosTableClick}
getCsv={this.municipiosCsv}
defaultSorted={[
{
id: "Estado",
......@@ -201,6 +215,7 @@ class SinapirMembers extends Component {
}
]}>
</PageTable>
<CardFooter data={this.state.municipiosCsv} source=" Entes federados participantes do SINAPIR e modalidades de gestão (2019)"></CardFooter>
</Card>
<Card title="Gestores e informações de contato (CadPIR)" id="sinapir1pannel-3" className={`${contrastString}pannel hoverable`}>
......@@ -228,6 +243,7 @@ class SinapirMembers extends Component {
mode='normal'
data={this.contatosTable()}
columnsWidth={200}
getCsv={this.contatosCsv}
defaultSorted={[
{
id: "Ente Federado participa do SNPIR",
......@@ -239,6 +255,7 @@ class SinapirMembers extends Component {
}
]}
></PageTable>
<CardFooter data={this.state.contatosCsv} source=" Cadastro Nacional de Órgãos e Conselhos de Promoção da Igualdade Racial - CadPIR (Agosto 2019)"></CardFooter>
</Card>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment