From 0e31236a787de52f54c10835ccb6413e241b1fe0 Mon Sep 17 00:00:00 2001 From: Ivan Florentin Date: Wed, 7 Sep 2016 21:36:57 -0400 Subject: [PATCH] now uses provideModel --- src/components.js | 16 ++++---- src/createMainContainer.js | 52 +++++++++++++------------- src/display.js | 61 ++++++++++++++---------------- src/edit.js | 76 ++++++++++++++++++-------------------- src/index.js | 10 ++--- src/list.js | 42 ++++++++++----------- src/providers.js | 3 -- src/routes.js | 20 +++++----- 8 files changed, 132 insertions(+), 148 deletions(-) diff --git a/src/components.js b/src/components.js index d850649..770f88a 100644 --- a/src/components.js +++ b/src/components.js @@ -4,12 +4,12 @@ import displayCreator from './display' //import relationDisplayCreator from './relationDisplay' export default function (compDef) { - const componentProperName = compDef.componentName[0].toUpperCase() + - compDef.componentName.substring(1) - const components = {} - components[`edit${componentProperName}`] = editCreator(compDef) - components[`list${componentProperName}`] = listCreator(compDef) - components[`display${componentProperName}`] = displayCreator(compDef) -// components[`relationDisplay${componentProperName}`] = relationDisplayCreator(compDef) - return components + const modelProperName = compDef.modelName[0].toUpperCase() + + compDef.modelName.substring(1) + const models = {} + models[`edit${modelProperName}`] = editCreator(compDef) + models[`list${modelProperName}`] = listCreator(compDef) + models[`display${modelProperName}`] = displayCreator(compDef) +// models[`relationDisplay${modelProperName}`] = relationDisplayCreator(compDef) + return models } diff --git a/src/createMainContainer.js b/src/createMainContainer.js index d506bef..b6db9e9 100644 --- a/src/createMainContainer.js +++ b/src/createMainContainer.js @@ -1,40 +1,40 @@ -import React, {Component, PropTypes} from 'react' -import {Router, Route, browserHistory} from 'react-router' +import React, {PropTypes} from 'react' +import {Router, Route} from 'react-router' const createMainContainer = (MainRoute, apps, MainContainer) =>{ const Container = (props) =>{ for (let appName in apps) { const app = apps[appName] if (app.appDef) { - for (let component of apps[appName].appDef.components) { - const componentName = component.componentName + for (let model of apps[appName].appDef.models) { + const modelName = model.modelName const appPath = `/${apps[appName].appDef.appRoute}/` - const editName = `${componentName}Edit` - const listName = `${componentName}List` - const displayName = `${componentName}Display` - const editPath = `${appPath}${componentName}/edit` - const listPath = `${appPath}${componentName}/list` - const displayPath = `${appPath}${componentName}/display` - const componentProperName = componentName[0].toUpperCase() + componentName.substring(1) - const setRoute = `setRoute${componentProperName}` - const setTemplate = `setTemplate${componentProperName}` - const templates= apps[appName].components[componentName] + const editName = `${modelName}Edit` + const listName = `${modelName}List` + const displayName = `${modelName}Display` + const editPath = `${appPath}${modelName}/edit` + const listPath = `${appPath}${modelName}/list` + const displayPath = `${appPath}${modelName}/display` + const modelProperName = modelName[0].toUpperCase() + modelName.substring(1) + const setRoute = `setRoute${modelProperName}` + const setTemplate = `setTemplate${modelProperName}` + const templates= apps[appName].components[modelName] props[setRoute]({name: editName, path: editPath}) - props[`setComponentDef${componentProperName}`](component) + props[`setModelDef${modelProperName}`](model) props[setRoute]({name: listName, path: listPath}) props[setRoute]({name: displayName, path: displayPath}) props[setTemplate]({name: editName, - template: templates[`edit${componentProperName}`]}) + template: templates[`edit${modelProperName}`]}) props[setTemplate]({name: displayName, - template: templates[`display${componentProperName}`]}) + template: templates[`display${modelProperName}`]}) props[setTemplate]({name: listName, - template: templates[`list${componentProperName}`]}) + template: templates[`list${modelProperName}`]}) } } } return
- + {MainRoute} @@ -45,13 +45,13 @@ const createMainContainer = (MainRoute, apps, MainContainer) =>{ for (let appName in apps) { const app = apps[appName] if (app.appDef) { - const components = apps[appName].appDef.components - for (let component of components) { - const componentName = component.componentName - const componentProperName = componentName[0].toUpperCase() + componentName.substring(1) - const setRoute = `setRoute${componentProperName}` - const setTemplate = `setTemplate${componentProperName}` - Container.propTypes[`setComponentDef${componentProperName}`] = PropTypes.func + const models = apps[appName].appDef.models + for (let model of models) { + const modelName = model.modelName + const modelProperName = modelName[0].toUpperCase() + modelName.substring(1) + const setRoute = `setRoute${modelProperName}` + const setTemplate = `setTemplate${modelProperName}` + Container.propTypes[`setModelDef${modelProperName}`] = PropTypes.func Container.propTypes[setRoute] = PropTypes.func Container.propTypes[setTemplate] = PropTypes.func } diff --git a/src/display.js b/src/display.js index 51b5893..c29ebf0 100644 --- a/src/display.js +++ b/src/display.js @@ -1,13 +1,13 @@ import React, {PropTypes} from 'react' import {List, ListItem, ListSubHeader, Button} from 'react-toolbox' -export default function (compDef) { - const {componentName, +export default function (modelDef) { + const {modelName, fields - } = compDef + } = modelDef let propTypes = {} - const componentProperName = componentName[0].toUpperCase() + componentName.substring(1) + const modelProperName = modelName[0].toUpperCase() + modelName.substring(1) const fieldNames = Object.keys(fields) fieldNames.map((fieldName)=>{ if (fields[fieldName].relation) { @@ -15,52 +15,47 @@ export default function (compDef) { 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[`save${modelProperName}${relationProperName}`] = PropTypes.func + propTypes[`delete${modelProperName}${relationProperName}`] = PropTypes.func + propTypes[`${relation}ModelDef`] = PropTypes.object propTypes[`${relation}List`] = PropTypes.object propTypes[relation] = PropTypes.object } }) - const ComponentDisplay = (props) =>{ - console.log('in display', props) - let state = Object.assign({}, props[componentName]) + const ModelDisplay = (props) =>{ + let state = Object.assign({}, props[modelName]) const url = props.routing.locationBeforeTransitions.pathname const editURL = `${url.slice(0, url.lastIndexOf('/')+1)}edit` const {goBack} = props - const listCaption = `Datos de ${componentProperName}` + const listCaption = `Datos de ${modelProperName}` const listFields = [] const relationFields = [] for (let fieldName of fieldNames) { - console.log('field', state[fieldName]) - const componentField = compDef.fields[fieldName] - if (componentField.relation) { - const relComponents = [] - const relation = componentField.relation + const modelField = modelDef.fields[fieldName] + if (modelField.relation) { + const relModels = [] + const relation = modelField.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]) + ids.map((id) => { const relComp = [] const relCompKeys = Object.keys(relationList[id]) relCompKeys.map((name) =>{ relComp.push(
{name}: {relationList[id][name]}
) }) - relComponents.push(relComp) + relModels.push(relComp) }) - relationFields.push(
- {componentField.relation}, {relComponents}
) + relationFields.push(
+ {modelField.relation}, {relModels}
) } } else { const field =
+ legend={modelField.label} righticon={modelField.icon}/>
listFields.push(field) } @@ -72,7 +67,7 @@ export default function (compDef) { {listFields}
Relaciones: {relationFields}
-
} - ComponentList.propTypes = { + ModelList.propTypes = { pushRoute: PropTypes.func, goBack: PropTypes.func } - ComponentList.propTypes[`${compDef.componentName}List`] = PropTypes.object - ComponentList.propTypes[`deselect${componentProperName}`] = PropTypes.func - ComponentList.propTypes[`select${componentProperName}`] = PropTypes.func - ComponentList.propTypes[`delete${componentProperName}`] = PropTypes.func - ComponentList.propTypes.routing = PropTypes.object - return ComponentList + ModelList.propTypes[`${modelDef.modelName}List`] = PropTypes.object + ModelList.propTypes[`deselect${modelProperName}`] = PropTypes.func + ModelList.propTypes[`select${modelProperName}`] = PropTypes.func + ModelList.propTypes[`delete${modelProperName}`] = PropTypes.func + ModelList.propTypes.routing = PropTypes.object + return ModelList } diff --git a/src/providers.js b/src/providers.js index 830d21a..afaa5ed 100644 --- a/src/providers.js +++ b/src/providers.js @@ -138,7 +138,6 @@ export default function (compDef) { return {} } case SAVE: { - //const next = Object.assign({}, action.component) const next = JSON.parse(JSON.stringify(action.component)) next.isValid = true for (let fieldName of fieldNames) { @@ -168,7 +167,6 @@ export default function (compDef) { } const next = Object.assign({}, state) next[fieldName] = Object.assign({}, state[fieldName]) -// console.log ('Reducer saveRelation', fieldName, id, next) if (next[fieldName] === undefined) { next[fieldName] = {} } @@ -178,7 +176,6 @@ export default function (compDef) { case DELETE_RELATION: { const next = Object.assign({}, state) const {fieldName, id} = action - // console.log ('delete', fieldName, id, state) next[fieldName] = Object.assign({}, state[fieldName]) delete next[fieldName][id] return next diff --git a/src/routes.js b/src/routes.js index a136c39..f17fc58 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1,18 +1,18 @@ import {Route} from 'react-router' import React from 'react' -export default function (compDef, components) { - const mainPath = compDef.componentName - const componentProperName = compDef.componentName[0].toUpperCase() + - compDef.componentName.substring(1) - const edit = 'edit' + componentProperName - const list = 'list' + componentProperName - const display = 'display' + componentProperName +export default function (modelDef, models) { + const mainPath = modelDef.modelName + const modelProperName = modelDef.modelName[0].toUpperCase() + + modelDef.modelName.substring(1) + const edit = 'edit' + modelProperName + const list = 'list' + modelProperName + const display = 'display' + modelProperName return ( - - - + + + ) }