Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
adjustment for relation
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanflorentin committed Aug 24, 2016
1 parent c0fe213 commit de24c04
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/components.js
Original file line number Diff line number Diff line change
@@ -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() +
Expand All @@ -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
}
47 changes: 42 additions & 5 deletions src/edit.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)}
Expand All @@ -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 <div key={fieldName}>
<relationDisplay component={props[relation]}/>
<label>{relation}</label>

<List>{relListFields}</List>
<Button icon='add' onClick={(e) => {
next[`${relation}Selecting`] = true
save()
props.pushRoute(listRoute)
}}
/></div>
Expand Down
14 changes: 7 additions & 7 deletions src/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -28,23 +28,23 @@ export default function (compDef) {
rightActions={[
<Button key='edit' icon='edit' floating accent mini
onClick={() =>{
props[`select${componentProperName}`](props[listName][index])
props[`select${componentProperName}`](props[`${componentName}List`][index])
props.pushRoute(editURL)
}}
/>,
<Button key='display' icon='description' floating accent mini
onClick={() =>{
props[`select${componentProperName}`](props[listName][index])
props[`select${componentProperName}`](props[`${componentName}List`][index])
props.pushRoute(displayURL)
}}/>,
<Button key='select' icon='done' floating accent mini
onClick={() =>{
props[`select${componentProperName}`](props[listName][index])
props[`select${componentProperName}`](props[`${componentName}List`][index])
props.goBack()
}}/>,
<Button key='delete' icon='close' floating accent mini
onClick={() =>{
props[`delete${componentProperName}`](props[listName][index])
props[`delete${componentProperName}`](props[`${componentName}List`][index])
}}/>
]}
/>
Expand All @@ -71,7 +71,7 @@ export default function (compDef) {
pushRoute: PropTypes.func,
goBack: PropTypes.func
}
ComponentList.propTypes[compDef.listName] = PropTypes.array
ComponentList.propTypes[`${compDef.componentName}List`] = PropTypes.array
ComponentList.propTypes[`deselect${componentProperName}`] = PropTypes.func
ComponentList.propTypes[`select${componentProperName}`] = PropTypes.func
ComponentList.propTypes[`delete${componentProperName}`] = PropTypes.func
Expand Down
17 changes: 16 additions & 1 deletion src/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ export default function (compDef) {
} = compDef

const listProperName = listName[0].toUpperCase() + listName.substring(1)
const componentListName = componentName + 'List'
const listCapitalName = listName.toUpperCase()
const componentProperName = componentName[0].toUpperCase() + componentName.substring(1)
const componentCapitalName = componentName.toUpperCase()
const routesName = componentName + 'Routes'
const templatesName = componentName + 'Templates'
const componentDefinitionName = componentName + 'ComponentDef'

const crudInit = {}
const crudErrorInit = {}
Expand All @@ -33,6 +35,7 @@ export default function (compDef) {
const DELETE_ROUTE = `DELETE_ROUTE_${componentCapitalName}`
const SET_TEMPLATE = `SET_TEMPLATE_${componentCapitalName}`
const DELETE_TEMPLATE = `DELETE_TEMPLATE_${componentCapitalName}`
const SET_COMPONENT_DEF = `SET_COMPOENET_DEF_${componentCapitalName}`

const actions = {}
const reducers = {}
Expand Down Expand Up @@ -67,6 +70,18 @@ export default function (compDef) {
actions[`deleteTemplate${componentProperName}`] = (templateDef) =>{
return {type: DELETE_TEMPLATE, ...templateDef}
}
actions[`setComponentDef${componentProperName}`] = (componentDef) =>{
return {type: SET_COMPONENT_DEF, componentDef}
}

reducers[componentDefinitionName] = (state = {}, action) =>{
switch (action.type) {
case SET_COMPONENT_DEF: {
return action.componentDef
}
default: return state
}
}

reducers[routesName] = (state = {}, action) =>{
switch (action.type) {
Expand Down Expand Up @@ -136,7 +151,7 @@ export default function (compDef) {
}
}

reducers[listName] = (state = [], action) =>{
reducers[componentListName] = (state = [], action) =>{
switch (action.type) {
case LOAD: {
return action.list
Expand Down

0 comments on commit de24c04

Please sign in to comment.