Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
updated to latest react and react-toolbox
Browse files Browse the repository at this point in the history
relations starting to appear
  • Loading branch information
ivanflorentin committed Aug 18, 2016
1 parent 1bc67c2 commit 791217e
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 43 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@
"babel-preset-react": "^6.1.4",
"babel-preset-stage-2": "^6.5.0",
"node-uuid": "^1.4.7",
"normalize.css": "^4.2.0",
"react": "^15.3.0",
"react-addons-css-transition-group": "^15.3.0",
"react-addons-update": "^15.3.0",
"react-dom": "^15.3.0",
"react-redux-provide": "^6.0.0-rc.56",
"react-toolbox": "^1.1.2",
"redux-replicate": "^2.0.0-rc.6",
"validator": "^5.5.0"
"validator": "^5.5.0",
"webpack": "^1.13.1"
},
"babel": {
"plugins": [
Expand Down
96 changes: 63 additions & 33 deletions src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,22 @@ export default function (compDef) {

const componentProperName = componentName[0].toUpperCase() + componentName.substring(1)
const fieldNames = Object.keys(fields)
fieldNames.map((fieldName)=>{
if (fields[fieldName].relation) {
const relation = fields[fieldName].relation
propTypes[`${relation}Routes`] = PropTypes.object
//console.log(fieldName, relation)
}
})
const ComponentEdit = (props) =>{
let next = Object.assign({}, props[componentName])
const save = () =>{props[`save${componentProperName}`](next)}
const store = () =>{props[`store${componentProperName}`](next)}
const {goBack} = props
const listCaption = `Ingrese datos de ${componentProperName}`
const listFields = []

for (let fieldName of fieldNames) {
if (fields[fieldName].relation && fields[fieldName].relation === 'oneToMany') {
console.log('oneToMany', fields[fieldName].component, fields[fieldName].remoteField)
const remoteField = fields[fieldName].remoteField
}
if (fields[fieldName].relation && fields[fieldName].relation === 'manyToOne') {
console.log('manyToOne', fields[fieldName].component, fields[fieldName].remoteField)
}
if (fields[fieldName].relation && fields[fieldName].relation === 'manyToMany') {
console.log('manyToMany', fields[fieldName].component, fields[fieldName].remoteField)
}
if (fields[fieldName].relation && fields[fieldName].relation === 'oneToOne') {
console.log('oneToOne', fields[fieldName].component, fields[fieldName].remoteField)
}
let label = fields[fieldName].label
// const listFields = []
const listFields = fieldNames.map((fieldName)=>{
let label = fields[fieldName].label
if (!label || label === '') {
label = fieldName
}
Expand All @@ -41,35 +34,72 @@ export default function (compDef) {
if (next[fieldError]) {
error = <span>{next[fieldError]}</span>
}
const field = <div key={fieldName}>
<Input value={next[fieldName] ||''}
if (fields[fieldName].relation) {
const relation = fields[fieldName].relation
console.log('relation:', relation)
const routes = `${relation}Routes`
const listRoute = props[routes][`${relation}List`]
return <div key={fieldName}><Button icon='add' onClick={(e) => {
console.log('go to ', props[routes], props.pushRoute)
props.pushRoute(listRoute)
}}
/></div>
}
return <div key={fieldName}>
<Input value={next[fieldName] ||''}
type={componentField.uiType} label={label} name='name' icon={componentField.icon}
hint={componentField.hint}
onChange={(e) => {
next[fieldName] = e
save()
}}/>
{error}
{error}
</div>
})
return <div>
<ListSubHeader caption={listCaption}/>
{listFields}
<Button icon='done' floating disabled={!next.isValid} accent mini onClick={(e)=>{
store()
goBack()
}}/>
<Button icon='undo' floating accent mini onClick={()=>{goBack()}}/>
</div>
listFields.push(field)
}
return (
<div>
<ListSubHeader caption={listCaption}/>
{listFields}
<Button icon='done' floating disabled={!next.isValid} accent mini onClick={(e)=>{
store()
goBack()
}}/>
<Button icon='undo' floating accent mini onClick={()=>{goBack()}}/>
</div>
)
}
ComponentEdit.propTypes = propTypes
ComponentEdit.propTypes[`${componentName}`] = PropTypes.object
ComponentEdit.propTypes[`save${componentProperName}`] = PropTypes.func
ComponentEdit.propTypes[`store${componentProperName}`] = PropTypes.func
ComponentEdit.propTypes.goBack = PropTypes.func
ComponentEdit.propTypes.pushRoute = PropTypes.func
return ComponentEdit
}
//create a separate parser
// for (let fieldName of fieldNames) {
// if (fields[fieldName].relation) {
// const relation = fields[fieldName].relation
// console.log('relation:', relation)
// }
// let label = fields[fieldName].label
// if (!label || label === '') {
// label = fieldName
// }
// const componentField = compDef.fields[fieldName]
// const fieldError = `${fieldName}Error`
// let error = ''
// if (next[fieldError]) {
// error = <span>{next[fieldError]}</span>
// }
// const field = <div key={fieldName}>
// <Input value={next[fieldName] ||''}
// type={componentField.uiType} label={label} name='name' icon={componentField.icon}
// hint={componentField.hint}
// onChange={(e) => {
// next[fieldName] = e
// save()
// }}/>
// {error}
// </div>
// listFields.push(field)
// }
// return (
31 changes: 24 additions & 7 deletions src/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function (compDef) {
const displayURL = `${url.slice(0, url.lastIndexOf('/')+1)}display`
const editURL = `${url.slice(0, url.lastIndexOf('/')+1)}edit`
const list = props[listName]
console.log('list', list)
const Items = list.map((item, index) =>{
let itemLegend = ''
for (let field in fields) {
Expand All @@ -24,20 +25,36 @@ export default function (compDef) {
}
}
return <ListItem key={index} legend={itemLegend} leftIcon={compDef.icon}
onClick={() =>{
props[`select${componentProperName}`](props[listName][index])
props.pushRoute(displayURL)
}
}>
this is a child
</ListItem>
rightActions={[
<Button key='edit' icon='edit' floating accent mini
onClick={() =>{
props[`select${componentProperName}`](props[listName][index])
props.pushRoute(editURL)
}}
/>,
<Button key='display' icon='description' floating accent mini
onClick={() =>{
props[`select${componentProperName}`](props[listName][index])
props.pushRoute(displayURL)
}}/>,
<Button key='select' icon='done' floating accent mini
onClick={() =>{
props[`select${componentProperName}`](props[listName][index])
props.goBack()
}}/>]}
/>
})

return <div>
<List selectable ripple>
<center><ListSubHeader caption={compDef.listTitle} /></center>
{Items}
</List>
<Button icon='undo'
floating accent mini onClick={()=>{
props.goBack()
}}/>

<Button icon='add'
floating accent mini onClick={()=>{
props[`deselect${componentProperName}`]()
Expand Down
5 changes: 3 additions & 2 deletions src/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default function (compDef) {
replication
} = compDef

console.log('replicator', replication)
const listProperName = listName[0].toUpperCase() + listName.substring(1)
const listCapitalName = listName.toUpperCase()
const componentProperName = componentName[0].toUpperCase() + componentName.substring(1)
Expand Down Expand Up @@ -63,7 +62,9 @@ export default function (compDef) {
switch (action.type) {
case SET_ROUTE: {
const {name, path} = action
return Object.assign({}, state, {name, path})
let route = {}
route[name] = path
return Object.assign({}, state, route)
}
case DELETE_ROUTE: {
const {name} = action
Expand Down

0 comments on commit 791217e

Please sign in to comment.