From de24c04c844e0ba1bb6903b133951ecfd3d809c2 Mon Sep 17 00:00:00 2001 From: Ivan Florentin Date: Tue, 23 Aug 2016 22:40:57 -0400 Subject: [PATCH] adjustment for relation --- src/components.js | 2 ++ src/edit.js | 47 ++++++++++++++++++++++++++++++++++++++++++----- src/list.js | 14 +++++++------- src/providers.js | 17 ++++++++++++++++- 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/components.js b/src/components.js index ec3f84a..d850649 100644 --- a/src/components.js +++ b/src/components.js @@ -1,6 +1,7 @@ import editCreator from './edit' import listCreator from './list' import displayCreator from './display' +//import relationDisplayCreator from './relationDisplay' export default function (compDef) { const componentProperName = compDef.componentName[0].toUpperCase() + @@ -9,5 +10,6 @@ export default function (compDef) { components[`edit${componentProperName}`] = editCreator(compDef) components[`list${componentProperName}`] = listCreator(compDef) components[`display${componentProperName}`] = displayCreator(compDef) +// components[`relationDisplay${componentProperName}`] = relationDisplayCreator(compDef) return components } diff --git a/src/edit.js b/src/edit.js index 7b61d2e..c75694b 100644 --- a/src/edit.js +++ b/src/edit.js @@ -1,5 +1,8 @@ import React, {PropTypes} from 'react' -import {ListSubHeader, Button, Input} from 'react-toolbox' +import {List, ListItem,ListSubHeader, Button, Input} from 'react-toolbox' +//import relationDisplayCreator from './relationDisplay' +// console.log('relationDisplay',relationDisplay) +// relationDisplay({component:{}, componentDef:{}}) export default function (compDef) { const {componentName, @@ -12,12 +15,17 @@ export default function (compDef) { fieldNames.map((fieldName)=>{ if (fields[fieldName].relation) { const relation = fields[fieldName].relation + const relationProperName = relation.toUpperCase() + relation.substring(1) propTypes[`${relation}Routes`] = PropTypes.object propTypes[`${relation}Templates`] = PropTypes.object + propTypes[`relationDisplay${relationProperName}`] = PropTypes.func + propTypes[`${relation}ComponentDef`] = PropTypes.object + propTypes[`${relation}List`] = PropTypes.array propTypes[relation] = PropTypes.object } }) const ComponentEdit = (props) =>{ +// console.log('props', props) let next = Object.assign({}, props[componentName]) const save = () =>{props[`save${componentProperName}`](next)} const store = () =>{props[`store${componentProperName}`](next)} @@ -36,15 +44,44 @@ export default function (compDef) { } if (fields[fieldName].relation) { const relation = fields[fieldName].relation + console.log(`selected ${relation}`, props[relation]) + const relationList = props[`${relation}List`] + const relationComponentDef = props[`${relation}ComponentDef`] + const relationProperName = relation.toUpperCase() + relation.substring(1) const routes = `${relation}Routes` const listRoute = props[routes][`${relation}List`] - const relationDisplay = props[`${relation}Templates`][`${relation}Display`] - console.log('this component was selected', relationDisplay, props[relation]) + const relListFields = [] + //console.log(`relation ${relation} is `, next[relation]) + if (next[relation] === undefined) { + console.log(`relation ${relation} is undefined`) + next[relation] = [] + } + console.log('is selecting?', next[`${relation}Selecting`]) + if (next[`${relation}Selecting`]) { + let found = false + next[relation].map((relItem, index) =>{ + console.log('item in list:', relItem) + relationList.map((item)=>{ + if (item.uuid === relItem) { + console.log('already in list', relItem) + found = true + } + }) + }) + if (!found) { + next[relation].push(props[relation].uuid) + save() + } + delete next[`${relation}Selecting`] + } + //ahora a crear los items para el render + return
- - + {relListFields}
diff --git a/src/list.js b/src/list.js index 508e080..c1c8a31 100644 --- a/src/list.js +++ b/src/list.js @@ -11,8 +11,8 @@ export default function (compDef) { const url = props.routing.locationBeforeTransitions.pathname 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 list = props[`${componentName}List`] +// console.log('list', list) const Items = list.map((item, index) =>{ let itemLegend = '' for (let field in fields) { @@ -28,23 +28,23 @@ export default function (compDef) { rightActions={[