diff --git a/package.json b/package.json index a76fb45..aa88c58 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,10 @@ }, "author": "Ivan Florentin ", "license": "ISC", + "repository" : + { "type" : "git" + , "url" : "https://github.com/ivanflorentin/ProvideAppCRUD" + }, "dependencies": { "babel-core": "^6.7.4", "babel-eslint": "^4.1.5", diff --git a/src/edit.js b/src/edit.js index fb8e119..ed2a54d 100644 --- a/src/edit.js +++ b/src/edit.js @@ -1,5 +1,5 @@ import React, {PropTypes} from 'react' -import {List, ListItem,ListSubHeader, Button, Input} from 'react-toolbox' +import {List, ListItem, ListSubHeader, Button, Input} from 'react-toolbox' export default function (compDef) { const {componentName, @@ -12,23 +12,24 @@ export default function (compDef) { fieldNames.map((fieldName)=>{ if (fields[fieldName].relation) { const relation = fields[fieldName].relation - const relationProperName = relation.toUpperCase() + relation.substring(1) + const relationProperName = relation[0].toUpperCase() + relation.substring(1) propTypes[`${relation}Routes`] = PropTypes.object propTypes[`${relation}Templates`] = PropTypes.object - propTypes[`relationDisplay${relationProperName}`] = PropTypes.func + propTypes[`save${componentProperName}${relationProperName}`] = PropTypes.func + propTypes[`delete${componentProperName}${relationProperName}`] = PropTypes.func propTypes[`${relation}ComponentDef`] = PropTypes.object - propTypes[`${relation}List`] = PropTypes.array + propTypes[`${relation}List`] = PropTypes.object propTypes[relation] = PropTypes.object } }) const ComponentEdit = (props) =>{ const next = Object.assign({}, props[componentName]) + console.log('next', next, props) const save = () =>{props[`save${componentProperName}`](next)} const store = () =>{props[`store${componentProperName}`](next)} const {goBack} = props const listCaption = `Ingrese datos de ${componentProperName}` - const listFields = fieldNames.map((fieldName)=>{ let label = fields[fieldName].label if (!label || label === '') { @@ -42,51 +43,40 @@ export default function (compDef) { } if (fields[fieldName].relation) { const relation = fields[fieldName].relation - console.log('relation',props[relation]) const relationList = props[`${relation}List`] const relationComponentDef = props[`${relation}ComponentDef`] - const relationProperName = relation.toUpperCase() + relation.substring(1) + const relationProperName = relation[0].toUpperCase() + relation.substring(1) + const saveRelation = props[`save${componentProperName}${relationProperName}`] + const deleteRelation = props[`delete${componentProperName}${relationProperName}`] const routes = `${relation}Routes` const listRoute = props[routes][`${relation}List`] if (next[relation]===undefined) {next[relation]=[]} if (next[`${relation}Selecting`]) { - if (next[relation].indexOf(props[relation].uuid)===-1) { - console.log('adding', props[relation].uuid) - next[relation].push(props[relation].uuid) - } + saveRelation(props[relation].uuid) delete next[`${relation}Selecting`] } - const relListFields= relationList.filter(comp =>{ - if (next[relation].indexOf(comp.uuid)) { - return true - } - return false - }).map(comp=>{ + const ids = Object.keys(relationList) + const relListFields = ids.map(id => { + const comp = relationList[id] let thisComp = [] for (let key in comp) { thisComp.push(
{key}: {comp[key]}
) } return
{thisComp} -
}) - return
{relListFields}
diff --git a/src/list.js b/src/list.js index c1c8a31..a529660 100644 --- a/src/list.js +++ b/src/list.js @@ -12,8 +12,10 @@ 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) - const Items = list.map((item, index) =>{ + console.log('list', list) + const ids = Object.keys(list) + const Items = ids.map((id, index) =>{ + const item = list[id] let itemLegend = '' for (let field in fields) { let label = fields[field].label @@ -28,23 +30,23 @@ export default function (compDef) { rightActions={[