diff --git a/src/display.js b/src/display.js index 934d4f2..a4e9443 100644 --- a/src/display.js +++ b/src/display.js @@ -8,7 +8,8 @@ export default function (compDef) { const componentProperName = componentName[0].toUpperCase() + componentName.substring(1) const fieldNames = Object.keys(fields) - const ComponentEdit = (props) =>{ + const ComponentDisplay = (props) =>{ + console.log('in display', props) let next = Object.assign({}, props[componentName]) const url = props.routing.locationBeforeTransitions.pathname const editURL = `${url.slice(0, url.lastIndexOf('/')+1)}edit` @@ -39,15 +40,15 @@ export default function (compDef) { ) } - ComponentEdit.propTypes = { + ComponentDisplay.propTypes = { pushRoute: PropTypes.func, goBack: PropTypes.func, routing: PropTypes.object } - ComponentEdit.propTypes[`${componentName}`] = PropTypes.object - ComponentEdit.propTypes[`save${componentProperName}`] = PropTypes.func - ComponentEdit.propTypes[`store${componentProperName}`] = PropTypes.func - return ComponentEdit + ComponentDisplay.propTypes[`${componentName}`] = PropTypes.object + ComponentDisplay.propTypes[`save${componentProperName}`] = PropTypes.func + ComponentDisplay.propTypes[`store${componentProperName}`] = PropTypes.func + return ComponentDisplay } diff --git a/src/edit.js b/src/edit.js index af04d50..8291e0d 100644 --- a/src/edit.js +++ b/src/edit.js @@ -13,7 +13,8 @@ export default function (compDef) { if (fields[fieldName].relation) { const relation = fields[fieldName].relation propTypes[`${relation}Routes`] = PropTypes.object - //console.log(fieldName, relation) + propTypes[`${relation}Templates`] = PropTypes.object + propTypes[relation] = PropTypes.object } }) const ComponentEdit = (props) =>{ @@ -22,7 +23,6 @@ export default function (compDef) { const store = () =>{props[`store${componentProperName}`](next)} const {goBack} = props const listCaption = `Ingrese datos de ${componentProperName}` - // const listFields = [] const listFields = fieldNames.map((fieldName)=>{ let label = fields[fieldName].label if (!label || label === '') { @@ -36,11 +36,15 @@ export default function (compDef) { } if (fields[fieldName].relation) { const relation = fields[fieldName].relation - console.log('relation:', relation) const routes = `${relation}Routes` const listRoute = props[routes][`${relation}List`] - return
diff --git a/src/providers.js b/src/providers.js index 5d46d10..7561952 100644 --- a/src/providers.js +++ b/src/providers.js @@ -12,6 +12,7 @@ export default function (compDef) { const componentProperName = componentName[0].toUpperCase() + componentName.substring(1) const componentCapitalName = componentName.toUpperCase() const routesName = componentName + 'Routes' + const templatesName = componentName + 'Templates' const crudInit = {} const crudErrorInit = {} @@ -30,6 +31,8 @@ export default function (compDef) { const DELETE = `DELETE_${componentCapitalName}` const SET_ROUTE = `SET_ROUTE_${componentCapitalName}` const DELETE_ROUTE = `DELETE_ROUTE_${componentCapitalName}` + const SET_TEMPLATE = `SET_TEMPLATE_${componentCapitalName}` + const DELETE_TEMPLATE = `DELETE_TEMPLATE_${componentCapitalName}` const actions = {} const reducers = {} @@ -58,6 +61,13 @@ export default function (compDef) { actions[`deleteRoute${componentProperName}`] = (routeDef) =>{ return {type: DELETE_ROUTE, ...routeDef} } + actions[`setTemplate${componentProperName}`] = (templateDef) =>{ + return {type: SET_TEMPLATE, ...templateDef} + } + actions[`deleteTemplate${componentProperName}`] = (templateDef) =>{ + return {type: DELETE_TEMPLATE, ...templateDef} + } + reducers[routesName] = (state = {}, action) =>{ switch (action.type) { case SET_ROUTE: { @@ -76,6 +86,24 @@ export default function (compDef) { } } + reducers[templatesName] = (state = {}, action) =>{ + switch (action.type) { + case SET_TEMPLATE: { + const {name, template} = action + let temp = {} + temp[name] = template + return Object.assign({}, state, temp) + } + case DELETE_TEMPLATE: { + const {name} = action + const next = Object.assign({}, state) + delete next[name] + return next + } + default : return state + } + } + reducers[componentName] = (state = {isValid: false}, action) =>{ switch (action.type) { case SELECT: {