Advertisement
Guest User

i dont even

a guest
May 24th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as React from 'react';
  2. import { Fragment } from 'react';
  3. import { Link, RouteComponentProps, NavLink, Redirect } from 'react-router-dom';
  4. import { connect } from 'react-redux';
  5. import { ApplicationState } from '../store';
  6. import * as TableStore from '../store/TableForm';
  7. import { TableState, columnData } from '../store/TableForm';
  8.  
  9. // Material-UI Imports
  10. import Paper from 'material-ui/Paper';
  11. import FormInput from './FormInput';
  12. import Divider from 'material-ui/Divider';
  13.  
  14. import { withStyles } from 'material-ui/styles';
  15.  
  16. import { Table, TableBody, TableCell, TableHead, TableRow } from 'material-ui';
  17. import { Select, Menu, MenuItem, Button } from 'material-ui';
  18.  
  19. import { Icon, IconButton } from 'material-ui';
  20.  
  21. import { Collapse } from 'material-ui';
  22.  
  23. import { ExpansionPanel, ExpansionPanelSummary, ExpansionPanelDetails, Typography } from 'material-ui';
  24. import { List, ListItem, ListItemText, ListSubheader } from 'material-ui';
  25. import { TypographyProps } from 'material-ui/Typography';
  26.  
  27. // Material-UI-Icons Imports
  28. import { Folder, Edit, Delete, NoteAdd, ViewList, Add, Search } from 'material-ui-icons'
  29.  
  30. import FormatAlignLeftIcon from 'material-ui-icons/FormatAlignLeft'
  31. import KeyboardArrowDownIcon from 'material-ui-icons/KeyboardArrowDown'
  32. import KeyboardArrowUpIcon from 'material-ui-icons/KeyboardArrowUp'
  33. import KeyboardArrowRightIcon from 'material-ui-icons/KeyboardArrowRight'
  34. import CloseIcon from 'material-ui-icons/Close';
  35.  
  36.  
  37. //Component Imports
  38. import DialogWin from './DialogWin';
  39. import FormFill from './FormFill';
  40. import FormDatas from './FormDatas';
  41.  
  42. import { formData } from '../store/TableForm';
  43.  
  44.  
  45. type TableProps =
  46.     TableStore.TableState
  47.     & typeof TableStore.actionCreators
  48.     & RouteComponentProps<{}>;
  49.  
  50. const schema = {
  51.     title: "Formi",
  52.     type: "object",
  53.     required: ["title"],
  54.     properties: {
  55.         title: { type: "string", title: "Name", default: "" },
  56.         id: { type: 'string', title: 'type', default: '' }
  57.     }
  58. };
  59.  
  60. interface IState {
  61.     dialogData: any,
  62.     nestedOpen: any,
  63.     fillData: any,
  64.     listData: any,
  65.     nestVal: string
  66. }
  67.  
  68.  
  69. class TableForm extends React.Component<TableProps, IState> {
  70.     constructor(props: IState & TableProps) {
  71.         super(props);
  72.         this.state = {
  73.             dialogData: undefined,
  74.             nestedOpen: false,
  75.             fillData: undefined,
  76.             listData: undefined,
  77.             nestVal: "0"
  78.         }
  79.         //hello.bind(this);
  80.     }
  81.     componentDidMount() {
  82.         this.props.pull(); //load form list from storage
  83.         //this.props.sqlGetData(); // launch data in target table.
  84.         //this.props.sqlGetColumns(); // launch columns of target table
  85.         //this.props.sqlGetTable(); // launch list of tablenames in target database.
  86.     }
  87.     testData = [
  88.         { title: "First item", type: "text" },
  89.         { title: "2 item", type: "text" },
  90.         { title: "3 item", type: "text" }
  91.     ];
  92.  
  93.     toggleOpen = (probObj: columnData[], heading: string) => {
  94.         this.setState({ dialogData: <DialogWin dialogContent={probObj} key={"dialogWinDiv"} helloString={heading} onClose={(() => { this.setState({ dialogData: undefined }) }).bind(this)} /> });
  95.     };
  96.  
  97.     CloseButton = () => {
  98.         if (this.state.fillData) {
  99.             this.setState({ fillData: null })
  100.         }
  101.     };
  102.  
  103.     handleFill = (pKey: string, rKey: string) => {
  104.         this.props.load(pKey, rKey);
  105.  
  106.         this.setState({
  107.             fillData: <FormFill {...this.props} closeThis={this.CloseButton.bind(this)} />
  108.         })
  109.     };
  110.  
  111.     handleClick = (rKey: string) => {
  112.         this.setState({ nestVal: rKey });
  113.         this.setState({ nestedOpen: !this.state.nestedOpen });
  114.     };
  115.  
  116.     addForm = () => {
  117.         return (
  118.             <NavLink exact to={'/form'} activeClassName='active' key="navLink"><Button key="navButton"><Add /> Create New Form</Button></NavLink>
  119.         )
  120.     };
  121.  
  122.     dropIt = (pKey: string, rKey: string, tName: string) => {
  123.         this.props.load(pKey, rKey);
  124.         console.log(this.props.form);
  125.         this.props.dropTable(pKey, rKey, tName);
  126.         this.props.pull();
  127.     };
  128.  
  129.     loadDataProps = (pKey: string, rKey: string) => {
  130.         this.props.load(pKey, rKey);
  131.         console.log('dataProps loaded');
  132.     };
  133.  
  134.     listForms = (data: formData[]) => {
  135.         return <div className="formsList" key="formListDiv">
  136.  
  137.             {this.props.formList.map(form => {
  138.                 console.log('listin mappi');
  139.                 return (
  140.                     <div>
  141.                         <ListItem
  142.                             button
  143.                             onClick={() => { this.handleClick(form.rowKey) }}
  144.                         >
  145.                             <KeyboardArrowUpIcon />
  146.                             <ListItemText inset primary={form.tableName} />
  147.                         </ListItem>
  148.                         <Collapse in={this.state.nestVal == form.rowKey ? true : false} timeout="auto" unmountOnExit>
  149.                             <Button className="button" key={"button1" + form.rowKey} style={{ marginRight: '20px' }} variant="raised" aria-label="Inspect" onClick={() => { this.toggleOpen(form.columns, form.partitionKey) }}><Folder /> Details </Button>
  150.                             <Button className="button" key={"button2" + form.rowKey} style={{ marginRight: '20px' }} variant="raised" aria-label="Fill" onClick={() => { this.handleFill(form.partitionKey, form.rowKey) }}> <NoteAdd /> Fill </Button>
  151.                             <Button className="button" key={"button3" + form.rowKey} style={{ marginRight: '20px' }} variant="raised" aria-label="Do Nothing"> <Edit /> Edit </Button>
  152.                             <NavLink onClick={() => { this.loadDataProps(form.partitionKey, form.rowKey) }} exact to={'/datas'} activeClassName='active' key={"navLink" + form.rowKey}><Button className="button" key={"button5" + form.rowKey} style={{ marginRight: '20px' }} variant="raised" aria-label="Inspect"> <Search /> Inspect Data</Button></NavLink>
  153.                             <Button className="button" key={"button6" + form.rowKey} variant="raised" aria-label="Delete" onClick={() => this.dropIt(form.partitionKey, form.rowKey, form.tableName)}> <Delete /> Delete </Button>
  154.                         </Collapse>
  155.                     </div>
  156.                 )
  157.             })}
  158.         </div>
  159.  
  160.     };
  161.  
  162.     public render() {
  163.  
  164.         return (
  165.             <div key="forms">
  166.                 <Paper key="paperBase">
  167.                     <List
  168.                         key={"list"}
  169.                         component="nav"
  170.                         subheader={<ListSubheader component="h1">Form List</ListSubheader>}
  171.                     >
  172.                         {this.listForms(this.props.formList)}
  173.                     </List>
  174.                 </Paper>
  175.                 <div key="dyanimicDiv">
  176.                     {this.state.dialogData}
  177.                     {this.addForm()}
  178.                     {this.state.fillData}
  179.                 </div>
  180.                 {/*<FormInput />*/}
  181.  
  182.             </div>
  183.         );
  184.  
  185.     }
  186. }
  187.  
  188.  
  189.  
  190. // Wire up the React component to the Redux store
  191. export default connect(
  192.     (state: ApplicationState) => state.table, // Selects which state properties are merged into the component's props
  193.     TableStore.actionCreators                 // Selects which action creators are merged into the component's props
  194. )(TableForm) as typeof TableForm;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement