diff --git a/src/display.js b/src/display.js
index a4e9443..51b5893 100644
--- a/src/display.js
+++ b/src/display.js
@@ -5,34 +5,74 @@ export default function (compDef) {
const {componentName,
fields
} = compDef
+ let propTypes = {}
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
+ const relationProperName = relation[0].toUpperCase() + relation.substring(1)
+ propTypes[`${relation}Routes`] = PropTypes.object
+ propTypes[`${relation}Templates`] = PropTypes.object
+ propTypes[`save${componentProperName}${relationProperName}`] = PropTypes.func
+ propTypes[`delete${componentProperName}${relationProperName}`] = PropTypes.func
+ propTypes[`${relation}ComponentDef`] = PropTypes.object
+ propTypes[`${relation}List`] = PropTypes.object
+ propTypes[relation] = PropTypes.object
+ }
+ })
+
+
const ComponentDisplay = (props) =>{
console.log('in display', props)
- let next = Object.assign({}, props[componentName])
+ let state = Object.assign({}, props[componentName])
const url = props.routing.locationBeforeTransitions.pathname
const editURL = `${url.slice(0, url.lastIndexOf('/')+1)}edit`
const {goBack} = props
const listCaption = `Datos de ${componentProperName}`
const listFields = []
+ const relationFields = []
for (let fieldName of fieldNames) {
+ console.log('field', state[fieldName])
const componentField = compDef.fields[fieldName]
- const field =
-
-
- listFields.push(field)
+ if (componentField.relation) {
+ const relComponents = []
+ const relation = componentField.relation
+ const relationList = props[`${relation}List`]
+ console.log('Props relationList', `${relation}List`, relationList)
+ console.log(`relation, ${componentField.relation}`, state[fieldName])
+ if (state[fieldName]) {
+ const ids = Object.keys(state[fieldName])
+ ids.map((id, index) => {
+ console.log('rel id', relationList[id])
+ const relComp = []
+ const relCompKeys = Object.keys(relationList[id])
+ relCompKeys.map((name) =>{
+ relComp.push({name}: {relationList[id][name]}
)
+ })
+ relComponents.push(relComp)
+ })
+ relationFields.push(
+ {componentField.relation}, {relComponents}
)
+ }
+ } else {
+ const field =
+
+
+ listFields.push(field)
+ }
}
-
return (
{listFields}
+ Relaciones: {relationFields}
-
+ })
+ return
+
+ {listFields}
+ {
+ this.store()
+ this.goBack()
+ }}/>
+ {this.goBack()}}/>
+
+ }
}
+
ComponentEdit.propTypes = propTypes
ComponentEdit.propTypes[`${componentName}`] = PropTypes.object
ComponentEdit.propTypes[`save${componentProperName}`] = PropTypes.func
diff --git a/src/list.js b/src/list.js
index a529660..bd02f6d 100644
--- a/src/list.js
+++ b/src/list.js
@@ -12,7 +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[`${componentName}List`]
- console.log('list', list)
+ //console.log('list', list)
const ids = Object.keys(list)
const Items = ids.map((id, index) =>{
const item = list[id]
diff --git a/src/providers.js b/src/providers.js
index 5b02706..830d21a 100644
--- a/src/providers.js
+++ b/src/providers.js
@@ -17,16 +17,6 @@ export default function (compDef) {
const componentDefinitionName = componentName + 'ComponentDef'
let fieldNames = Object.keys(fields)
-
- /*
- const crudInit = {}
- const crudErrorInit = {}
- if (fieldNames.length > 0) {
- for (let fieldName of fieldNames) {
- crudInit[fieldName] = fields[fieldName].defaultValue
- crudErrorInit[`${fieldName}Error`] = ''
- }}
- */
const SELECT = `SELECT_${componentCapitalName}`
const DESELECT = `DESELECT_${componentCapitalName}`
const SAVE = `SAVE_${componentCapitalName}`
@@ -142,27 +132,30 @@ export default function (compDef) {
reducers[componentName] = (state = {isValid: false}, action) =>{
switch (action.type) {
case SELECT: {
- console.log('select', state, action)
return action.component
}
case DESELECT: {
return {}
}
case SAVE: {
- const next = Object.assign({}, action.component)
+ //const next = Object.assign({}, action.component)
+ const next = JSON.parse(JSON.stringify(action.component))
next.isValid = true
for (let fieldName of fieldNames) {
const value = String(action.component[fieldName])
const validators = fields[fieldName].validate
if (validators && validators.length > 0) {
- let validatorPassed = true
+ next.isValid= true
+ next[`${fieldName}Error`] = []
for (let validator of validators) {
const valid = validator.func(value, validator.params)
if (!valid) {
next.isValid = false
- next[`${fieldName}Error`] = validator.message
+ next[`${fieldName}Error`].push(validator.message)
}
- else {delete next[`${fieldName}Error`]}
+ }
+ if (next.isValidm && next[`${fieldName}Error`]) {
+ delete next[`${fieldName}Error`]
}
}
}
@@ -175,7 +168,7 @@ export default function (compDef) {
}
const next = Object.assign({}, state)
next[fieldName] = Object.assign({}, state[fieldName])
- console.log ('save', fieldName, id, next)
+// console.log ('Reducer saveRelation', fieldName, id, next)
if (next[fieldName] === undefined) {
next[fieldName] = {}
}
@@ -185,7 +178,7 @@ export default function (compDef) {
case DELETE_RELATION: {
const next = Object.assign({}, state)
const {fieldName, id} = action
- console.log ('delete', fieldName, id, state)
+ // console.log ('delete', fieldName, id, state)
next[fieldName] = Object.assign({}, state[fieldName])
delete next[fieldName][id]
return next