From c7c45c80f9ea58e3dde63bd24723aab58b6fbd43 Mon Sep 17 00:00:00 2001 From: Ivan Florentin Date: Fri, 5 Aug 2016 23:17:53 -0400 Subject: [PATCH] first load --- .gitignore | 2 + package.json | 32 +++++++++++++ src/components.js | 13 ++++++ src/display.js | 44 ++++++++++++++++++ src/edit.js | 48 ++++++++++++++++++++ src/index.js | 30 +++++++++++++ src/list.js | 51 +++++++++++++++++++++ src/menu.js | 38 ++++++++++++++++ src/providers.js | 111 ++++++++++++++++++++++++++++++++++++++++++++++ src/routes.js | 19 ++++++++ 10 files changed, 388 insertions(+) create mode 100644 .gitignore create mode 100644 package.json create mode 100644 src/components.js create mode 100644 src/display.js create mode 100644 src/edit.js create mode 100644 src/index.js create mode 100644 src/list.js create mode 100644 src/menu.js create mode 100644 src/providers.js create mode 100644 src/routes.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7339900 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +*.*~ \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..d4eed5c --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "provide-app-crud", + "version": "1.0.0", + "description": "Application CRUD using Provide, Redux, React and ReactToobox ", + "main": "src/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Ivan Florentin ", + "license": "ISC", + "dependencies": { + "react": "^15.3.0", + "react-redux-provide": "^6.0.0-rc.56", + "validator": "^5.5.0", + "babel-core": "^6.7.4", + "babel-eslint": "^4.1.5", + "babel-loader": "^6.0.1", + "babel-plugin-react-transform": "^1.1.1", + "babel-plugin-transform-es2015-spread": "^6.6.5", + "babel-plugin-transform-object-rest-spread": "^6.6.5", + "babel-preset-es2015": "^6.6.0", + "babel-preset-react": "^6.1.4", + "babel-preset-stage-2": "^6.5.0", + "babel-polyfill": "^6.7.2" + }, + "babel": { + "plugins": [ + "transform-object-rest-spread" + ] + } + +} diff --git a/src/components.js b/src/components.js new file mode 100644 index 0000000..ec3f84a --- /dev/null +++ b/src/components.js @@ -0,0 +1,13 @@ +import editCreator from './edit' +import listCreator from './list' +import displayCreator from './display' + +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) + return components +} diff --git a/src/display.js b/src/display.js new file mode 100644 index 0000000..477ca40 --- /dev/null +++ b/src/display.js @@ -0,0 +1,44 @@ +import React, {PropTypes} from 'react' +import {Button} from 'react-toolbox' +import {Card, CardTitle, CardText, CardActions} from 'react-toolbox/lib/card' + +export default function (compDef) { + const {componentName} = compDef + + const ComponentDisplay = (props) => { + const {goBack, pushRoute, routing} = props + const url = routing.locationBeforeTransitions.pathname + const editURL = `${url.slice(0, url.lastIndexOf('/')+1)}edit` + const component = props[`${componentName}`] + let content = [] + let cardActions =
+
+ if (component.index !== undefined) { + for (let field of component) { + if (component[field] && compDef[field]) { + content.push(

{compDef[field].label} : {component[field]}

) + } + } + } + + return + + {content} + {cardActions} + + } + + ComponentDisplay.propTypes = {} + ComponentDisplay.propTypes[`${componentName}`] = PropTypes.object + ComponentDisplay.propTypes.goBack = PropTypes.func + ComponentDisplay.propTypes.pushRoute = PropTypes.func + ComponentDisplay.propTypes.routing = PropTypes.object + + return ComponentDisplay +} diff --git a/src/edit.js b/src/edit.js new file mode 100644 index 0000000..2cebea3 --- /dev/null +++ b/src/edit.js @@ -0,0 +1,48 @@ +import React, {PropTypes} from 'react' +import {ListSubHeader, Button, Input} from 'react-toolbox' + +export default function (compDef) { + const {componentName, + fields + } = compDef + + const componentProperName = componentName[0].toUpperCase() + componentName.substring(1) + const fieldNames = Object.keys(fields) + const ComponentEdit = (props) =>{ + let next = Object.assign({}, props[componentName]) + const save = () =>{props[`save${componentProperName}`](next)} + const store = () =>{props[`store${componentProperName}`](next)} + const {goBack} = props + const listCaption = `Ingrese datos de ${componentProperName}` + const listFields = [] + + for (let fieldName of fieldNames) { + const componentField = compDef.fields[fieldName] + const field = { + next[fieldName] = e + save() + }}/> + listFields.push(field) + } + + return ( +
+ + {listFields} +
+ ) + } + ComponentEdit.propTypes = {} + ComponentEdit.propTypes[`${componentName}`] = PropTypes.object + ComponentEdit.propTypes[`save${componentProperName}`] = PropTypes.func + ComponentEdit.propTypes[`store${componentProperName}`] = PropTypes.func + ComponentEdit.propTypes.goBack = PropTypes.func + return ComponentEdit +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..4709ea2 --- /dev/null +++ b/src/index.js @@ -0,0 +1,30 @@ +import {Route} from 'react-router' +import React from 'react' +import componentCreator from './components' +import provideComponentCrud from './providers' +import routeCreator from './routes' +import menuCreator from './menu' + +export default function (appDef) { + const components = {} + const providers = {} + const componentRoutes = [] + appDef.components.map((compDef) =>{ + components[compDef.componentName] = componentCreator(compDef) + providers[compDef.componentName] = provideComponentCrud(compDef) + componentRoutes.push(routeCreator(compDef, components[compDef.componentName])) + }) + const menu = menuCreator(appDef) + const MainRoute = + + {componentRoutes} + + + const app = { + appDef, + appName: appDef.appName, + components, + providers, + routes: MainRoute} + return app +} diff --git a/src/list.js b/src/list.js new file mode 100644 index 0000000..0c70f72 --- /dev/null +++ b/src/list.js @@ -0,0 +1,51 @@ +import React, {PropTypes} from 'react' +import {List, ListItem, ListSubHeader, Button} from 'react-toolbox' + +export default function (compDef) { + const {componentName, + fields, + listName + } = compDef + const componentProperName = componentName[0].toUpperCase() + componentName.substring(1) + const ComponentList = (props) =>{ + 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] + const Items = list.map((item, index) =>{ + let itemLegend = '' + for (let field in fields) { + if (item[field] && item[field] !== '') { + itemLegend = itemLegend + ` ${fields[field].label}: ${item[field]}` + } + } + return { + props[`select${componentProperName}`](props[listName][index]) + props.pushRoute(editURL) + } + }/> + }) + + return
+ +
+ {Items} +
+
+ } + ComponentList.propTypes = { + pushRoute: PropTypes.func, + goBack: PropTypes.func + } + ComponentList.propTypes[compDef.listName] = PropTypes.array + ComponentList.propTypes[`deselect${componentProperName}`] = PropTypes.func + ComponentList.propTypes[`select${componentProperName}`] = PropTypes.func + ComponentList.propTypes.routing = PropTypes.object + return ComponentList +} diff --git a/src/menu.js b/src/menu.js new file mode 100644 index 0000000..b1f8a83 --- /dev/null +++ b/src/menu.js @@ -0,0 +1,38 @@ +import React, {PropTypes} from 'react' +import Button from 'react-toolbox/lib/button' +import Navigation from 'react-toolbox/lib/navigation' + +export default function (appDef) { + const {appRoute, + appTitle + } = appDef + const AppMenu = (props) =>{ + const {pushRoute} = props + const buttons = appDef.components.map((component, index) =>{ + const {componentName} = component + const componentProperName = componentName[0].toUpperCase() + + componentName.substring(1) + return