|
| 1 | +import React from 'react'; |
| 2 | +import {CardActions} from 'material-ui/Card'; |
| 3 | +import { |
| 4 | + List, Datagrid, Edit, Create, Show, SimpleShowLayout, SimpleForm, |
| 5 | + DateField, TextField, |
| 6 | + TextInput, DateInput, |
| 7 | + EditButton,ShowButton, DeleteButton, RefreshButton, ListButton, CreateButton |
| 8 | +} from 'admin-on-rest'; |
| 9 | +import {configList, configEdit, configCreate, configShow} from '../config/{{{lc}}}'; |
| 10 | + |
| 11 | +export const {{title}}List = (props) => ( |
| 12 | + <List |
| 13 | + actions={<{{title}}ListActions/>} |
| 14 | + {...props} |
| 15 | + > |
| 16 | + <Datagrid> |
| 17 | + {{#each fields}} |
| 18 | + {configList.{{name}} && <TextField source="{{{name}}}" />} |
| 19 | + {{/each}} |
| 20 | + {configList.buttons.show && <ShowButton />} |
| 21 | + {configList.buttons.edit && <EditButton />} |
| 22 | + {configList.buttons.delete && <DeleteButton />} |
| 23 | + </Datagrid> |
| 24 | + </List> |
| 25 | +); |
| 26 | + |
| 27 | +const {{title}}Title = ({record}) => { |
| 28 | + return <span>{{title}} {record && record.id ? ` : ${record.id}` : ''}</span>; |
| 29 | +}; |
| 30 | + |
| 31 | +export const {{title}}Edit = (props) => ( |
| 32 | + <Edit |
| 33 | + actions={<{{title}}EditActions/>} |
| 34 | + title={<{{title}}Title />} |
| 35 | + {...props} |
| 36 | + > |
| 37 | + <SimpleForm> |
| 38 | + {{#each formFields}} |
| 39 | + {{#compare type "==" "dateTime" }} |
| 40 | + {configEdit.{{name}} && <DateInput source="{{{name}}}" />} |
| 41 | + {{else}} |
| 42 | + {configEdit.{{name}} && <TextInput source="{{{name}}}" />} |
| 43 | + {{/compare}} |
| 44 | + {{/each}} |
| 45 | + </SimpleForm> |
| 46 | + </Edit> |
| 47 | +); |
| 48 | + |
| 49 | +export const {{title}}Create = (props) => ( |
| 50 | + <Create title='Create a {{{title}}}' {...props}> |
| 51 | + <SimpleForm> |
| 52 | + {{#each formFields}} |
| 53 | + {{#compare type "==" "dateTime" }} |
| 54 | + {configCreate.{{name}} && <DateField source="{{{name}}}" />} |
| 55 | + {{else}} |
| 56 | + {configCreate.{{name}} && <TextInput source="{{{name}}}" />} |
| 57 | + {{/compare}} |
| 58 | + {{/each}} |
| 59 | + </SimpleForm> |
| 60 | + </Create> |
| 61 | +); |
| 62 | + |
| 63 | +export const {{title}}Show = (props) => ( |
| 64 | + <Show |
| 65 | + actions={<{{title}}ShowActions/>} |
| 66 | + title={<{{title}}Title />} |
| 67 | + {...props} |
| 68 | + > |
| 69 | + <SimpleShowLayout> |
| 70 | + {{#each fields}} |
| 71 | + {configShow.{{name}} && <TextField source="{{{name}}}" />} |
| 72 | + {{/each}} |
| 73 | + </SimpleShowLayout> |
| 74 | + </Show> |
| 75 | +); |
| 76 | + |
| 77 | +const cardActionStyle = { |
| 78 | + zIndex: 2, |
| 79 | + display: 'inline-block', |
| 80 | + float: 'right', |
| 81 | +}; |
| 82 | + |
| 83 | +const {{title}}ListActions = ({basePath, data}) => ( |
| 84 | + <CardActions style={cardActionStyle}> |
| 85 | + {configList.buttons.create && <CreateButton basePath={basePath} />} |
| 86 | + {configList.buttons.refresh && <RefreshButton basePath={basePath} record={data} />} |
| 87 | + </CardActions> |
| 88 | +); |
| 89 | + |
| 90 | +const {{title}}ShowActions = ({basePath, data}) => ( |
| 91 | + <CardActions style={cardActionStyle}> |
| 92 | + {configShow.buttons.edit && <EditButton basePath={basePath} record={data}/>} |
| 93 | + {configShow.buttons.list && <ListButton basePath={basePath}/>} |
| 94 | + {configShow.buttons.delete && <DeleteButton basePath={basePath} record={data}/>} |
| 95 | + {configShow.buttons.refresh && <RefreshButton basePath={basePath} record={data}/>} |
| 96 | + </CardActions> |
| 97 | +); |
| 98 | + |
| 99 | +const {{title}}EditActions = ({basePath, data}) => ( |
| 100 | + <CardActions style={cardActionStyle}> |
| 101 | + {configShow.buttons.show && <ShowButton basePath={basePath} record={data}/>} |
| 102 | + {configShow.buttons.list && <ListButton basePath={basePath}/>} |
| 103 | + {configShow.buttons.delete && <DeleteButton basePath={basePath} record={data}/>} |
| 104 | + {configShow.buttons.refresh && <RefreshButton basePath={basePath} record={data}/>} |
| 105 | + </CardActions> |
| 106 | +); |
0 commit comments