develop
Morisse 6 years ago
parent 836974c2d5
commit b569e52f5e
  1. 55
      src/DataToTable.js

@ -7,14 +7,24 @@ const tableType = {
'user': {'primaryKey': 'User Id', 'apiAdress': '_matrix/client/r0/watchauserlist', 'user': {'primaryKey': 'User Id', 'apiAdress': '_matrix/client/r0/watchauserlist',
//'JoinTables': //'JoinTables':
//{'matchingKey': {}}, //{'matchingKey': {}},
'header': {'User Id': 'name', 'date of creation': 'creation_ts', 'header':
'Admin': 'admin', 'Partner': 'is_partner', 'Email': 'email', 'Devices': 'display_name'} }, {'User Id': {'name': 'name', 'type': 'string'},
'room': {'primaryKey': 'Room Id', 'apiAdress': '_matrix/client/r0/watcharoomlist', 'date of creation': {'name': 'creation_ts', 'type': 'date'},
'Admin': {'name': 'admin', 'type': 'boolean'},
'Partner': {'name': 'is_partner', 'type': 'boolean'},
'Email': {'name': 'email', 'type': 'string'},
'Devices': {'name': 'display_name', 'type': 'string'}} },
'room': {
'primaryKey': 'Room Id', 'apiAdress': '_matrix/client/r0/watcharoomlist',
'JoinTables': 'JoinTables':
{'watcharoomname': {'matchingKey': {'watcharoomname': {'matchingKey':
{ 'mainTable': 'Room Id', 'secondaryTable': 'room_id'}, { 'mainTable': 'Room Id', 'secondaryTable': 'room_id'},
'apiAdress': '_matrix/client/r0/watcharoomname', 'column': 'name'} }, 'apiAdress': '_matrix/client/r0/watcharoomname', 'column': 'name'} },
'header': {'Room Id': 'room_id', 'Creator': 'creator', 'Name': 'watcharoomname'} }, 'header': {'Room Id': {'name': 'room_id', 'type': 'string'},
'Name': {'name': 'watcharoomname', 'type': 'list'},
'Creator': {'name': 'creator', 'type': 'string'},
},
},
'stats': {}, 'stats': {},
}; };
@ -75,6 +85,7 @@ export default class DataToTable extends Component {
const homeServer = this.props.server; const homeServer = this.props.server;
const accessToken = this.props.token; const accessToken = this.props.token;
const JoinTables = this.state.type['JoinTables']; const JoinTables = this.state.type['JoinTables'];
console.log(accessToken);
try { try {
const userRequest = await fetch(homeServer+ this.state.type['apiAdress'], { const userRequest = await fetch(homeServer+ this.state.type['apiAdress'], {
@ -97,8 +108,12 @@ export default class DataToTable extends Component {
if ({}.hasOwnProperty.call(this.state.type['header'], columnHeader)) { if ({}.hasOwnProperty.call(this.state.type['header'], columnHeader)) {
for (const property in userData[user]) { for (const property in userData[user]) {
if ({}.hasOwnProperty.call(userData[user], property)) { if ({}.hasOwnProperty.call(userData[user], property)) {
if (property === this.state.type['header'][columnHeader]) { if (property === this.state.type['header'][columnHeader]['name']) {
dataObject[columnHeader] = userData[user][property]; dataObject[columnHeader] =
this.convertRawData(userData[user][property], this.state.type['header'][columnHeader]['type']);
}
if (this.state.type['header'][columnHeader]['type']==='list') {
dataObject[columnHeader] = [];
} }
} }
} }
@ -118,7 +133,7 @@ export default class DataToTable extends Component {
const userRequest = await fetch(homeServer+ apiAdress, { const userRequest = await fetch(homeServer+ apiAdress, {
method: 'GET', method: 'GET',
headers: { headers: {
'Authorization': 'bearer '+accessToken, 'Authorization': 'Bearer '+accessToken,
}, },
}); });
@ -134,7 +149,7 @@ export default class DataToTable extends Component {
if (this.state.arrayOfdata[dataObject][mainKey] === JoinTablesData[data][secondaryKey]) { if (this.state.arrayOfdata[dataObject][mainKey] === JoinTablesData[data][secondaryKey]) {
for (const columnHeader in this.state.type['header']) { for (const columnHeader in this.state.type['header']) {
if ({}.hasOwnProperty.call(this.state.type['header'], columnHeader)) { if ({}.hasOwnProperty.call(this.state.type['header'], columnHeader)) {
if (table === this.state.type['header'][columnHeader]) { if (table === this.state.type['header'][columnHeader]['name']) {
this.state.arrayOfdata[dataObject][columnHeader]=JoinTablesData[data][column]; this.state.arrayOfdata[dataObject][columnHeader]=JoinTablesData[data][column];
} }
} }
@ -150,6 +165,30 @@ export default class DataToTable extends Component {
this.setState({finish: true}); this.setState({finish: true});
} }
convertRawData = (rawData, type) => {
let data;
switch (type) {
case 'string':
data = rawData;
break;
case 'boolean':
if (rawData === 0) {
data = false;
} else {
data = true;
}
break;
case 'date':
data=rawData;
break;
default:
data = '';
}
return data;
}
getData = () => { getData = () => {
let data; let data;
switch (this.props.tableName) { switch (this.props.tableName) {

Loading…
Cancel
Save