Skip to content

Commit

Permalink
Merge pull request #116 from root-systems/feature/add-params-to-task-…
Browse files Browse the repository at this point in the history
…plan

backend to create all the respective objects and relations on order start
  • Loading branch information
ahdinosaur authored Jul 26, 2017
2 parents 4b4f37e + 4f4ef07 commit 0001349
Show file tree
Hide file tree
Showing 28 changed files with 371 additions and 196 deletions.
191 changes: 91 additions & 100 deletions agents/components/Profile.js
Original file line number Diff line number Diff line change
@@ -1,118 +1,109 @@
import PropTypes from 'prop-types'
import React from 'react'
import { connect as connectFela } from 'react-fela'
import { Field, reduxForm as connectForm } from 'redux-form'
import { pipe } from 'ramda'
import { pipe, isNil, not } from 'ramda'
import { TextField } from 'redux-form-material-ui'
import RaisedButton from 'material-ui/RaisedButton'
import { compose, withState, withHandlers } from 'recompose'
import h from 'react-hyperscript'

import { FormattedMessage } from '../../lib/Intl'
import styles from '../styles/Profile'
import Button from '../../app/components/Button'
import AvatarField from '../../app/components/AvatarField'

class Profile extends React.Component {
constructor (props, context) {
super(props, context)
this.state = {
isEditing: false
}
}

toggleEdit () {
this.setState({
isEditing: !this.state.isEditing
})
}

render () {
const { isEditing } = this.state
const { styles, agent, agent: { profile: { name, description, avatar } } } = this.props

return (
<form className={styles.container}>
<p className={styles.intro}>
<FormattedMessage
id='agents.profile'
className={styles.labelText}
/>
</p>
<div className={styles.innerContainer}>
<div className={styles.avatarContainer}>
<Field
name='avatar'
component={AvatarField}
isEditingProfile={isEditing}
value={avatar}
/>
</div>
<div className={styles.infoContainer}>
<Field
name='name'
floatingLabelText={
<FormattedMessage
id='agents.nameLabel'
className={styles.labelText}
/>
}
component={TextField}
fullWidth={true}
value={name}
disabled={!isEditing}
/>
<Field
name='description'
floatingLabelText={
<FormattedMessage
id='agents.descriptionLabel'
className={styles.labelText}
/>
}
component={TextField}
value={description}
fullWidth={true}
multiLine={true}
rowsMax={5}
disabled={!isEditing}
/>
</div>
</div>
<div className={styles.buttonContainer}>
<RaisedButton className={styles.button} type='button' onClick={() => { this.toggleEdit() }}>
{
isEditing
? <FormattedMessage
id='agents.saveProfile'
className={styles.labelText}
/>
: <FormattedMessage
id='agents.editProfile'
className={styles.labelText}
/>
}
</RaisedButton>
</div>
</form>
)
}

}

Profile.propTypes = {
agent: PropTypes.shape({
profile: PropTypes.shape({
avatar: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
name: PropTypes.string.isRequired
}).isRequired
})
}
function Profile (props) {
const { styles, isEditing, toggleEdit, agent } = props
if (isNil(agent)) return null
const { profile } = agent
if (isNil(profile)) return null
const { name, description, avatar } = profile

Profile.defaultProps = {
return h('form', {
className: styles.container
}, [
h('p', {
className: styles.intro
}, [
h(FormattedMessage, {
id: 'agents.profile',
className: styles.labelText
})
]),
h('div', {
className: styles.innerContainer
}, [
h('div', {
className: styles.avatarContainer
}, [
h(Field, {
name: 'avatar',
component: AvatarField,
isEditingProfile: isEditing,
value: avatar
})
]),
h('div', {
className: styles.infoContainer
}, [
h(Field, {
name: 'name',
floatingLabelText: (
h(FormattedMessage, {
id: 'agents.nameLabel',
className: styles.labelText
})
),
component: TextField,
fullWidth: true,
value: name,
disabled: not(isEditing)
}),
h(Field, {
name: 'description',
floatingLabelText: (
h(FormattedMessage, {
id: 'agents.descriptionLabel',
className: styles.labelText
})
),
component: TextField,
value: description,
fullWidth: true,
multiLine: true,
rowsMax: 5,
disabled: not(isEditing)
})
])
]),
h('div', {
className: styles.buttonContainer
}, [
h(RaisedButton, {
className: styles.button,
type: 'button',
onClick: () => toggleEdit()
}, [
isEditing
? h(FormattedMessage, {
id: 'agents.saveProfile',
className: styles.labelText
})
: h(FormattedMessage, {
id: 'agents.editProfile',
className: styles.labelText
})
])
])
])
}

export default pipe(
export default compose(
connectFela(styles),
withState('isEditing', 'setEditing', false),
withHandlers({
toggleEdit: ({ setEditing }) => () => setEditing(not)
}),
connectForm({
form: 'profile',
initialValues: {
Expand Down
3 changes: 0 additions & 3 deletions agents/getters/getAgents.js

This file was deleted.

4 changes: 2 additions & 2 deletions app/containers/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { connect } from 'feathers-action-react'
import Dashboard from '../components/Dashboard'
import { actions as taskPlanActions } from '../../tasks/dux/plans'
import { actions as taskWorkActions } from '../../tasks/dux/works'
import * as orderingActions from '../../ordering/actions'
import { actions as orderActions } from '../../ordering/dux/orders'
import getDashboardProps from '../getters/getDashboardProps'

export default connect({
selector: getDashboardProps,
actions: {
taskPlans: taskPlanActions,
taskWorks: taskWorkActions,
ordering: orderingActions
orders: orderActions
},
query: [
{
Expand Down
4 changes: 2 additions & 2 deletions app/getters/getDashboardProps.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createStructuredSelector } from 'reselect'

import getTaskPlans from '../../tasks/getters/getTaskPlans'
import getParentTaskPlans from '../../tasks/getters/getParentTaskPlans'

const getDashboardProps = createStructuredSelector({
taskPlans: getTaskPlans
taskPlans: getParentTaskPlans
})

export default getDashboardProps
11 changes: 11 additions & 0 deletions db/migrations/20170721153408_add-Params-to-taskPlans.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
exports.up = function (knex, Promise) {
return knex.schema.table('taskPlans', function (table) {
table.json('params').references('taskPlans.id')
})
}

exports.down = function (knex, Promise) {
return knex.schema.table('taskPlans', function (table) {
table.dropColumn('params')
})
}
10 changes: 10 additions & 0 deletions db/migrations/20170725145631_create-orders-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
exports.up = function (knex, Promise) {
return knex.schema.createTableIfNotExists('orders', function (table) {
table.increments('id')
table.integer('agentId').references('agents.id')
})
}

exports.down = function (knex, Promise) {
return knex.schema.dropTableIfExists('orders')
}
13 changes: 13 additions & 0 deletions db/migrations/20170725155010_fix-task-assignees.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exports.up = function (knex, Promise) {
return knex.schema.table('taskPlans', function (table) {
table.dropColumn('assignee')
table.integer('assigneeId').references('assignee.id')
})
}

exports.down = function (knex, Promise) {
return knex.schema.table('taskPlans', function (table) {
table.string('assignee').notNullable()
table.dropColumn('assigneeId')
})
}
4 changes: 2 additions & 2 deletions epic.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { combineEpics } from 'redux-observable'

import { epic as agents } from 'dogstack-agents'
import ordering from './ordering/epic'
import { epic as taskPlans } from './tasks/dux/plans'
import { epic as taskWorks } from './tasks/dux/works'
import { epic as orders } from './ordering/dux/orders'

export default combineEpics(
agents,
ordering,
orders,
taskPlans,
taskWorks
)
2 changes: 1 addition & 1 deletion ordering/components/DashboardOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function DashboardOrders (props) {
<RaisedButton
className={styles.button}
type='button'
onClick={actions.ordering.startOrder}
onClick={() => actions.orders.create({})}
>
<FormattedMessage
id='app.startOrder'
Expand Down
7 changes: 7 additions & 0 deletions ordering/dux/orders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import createModule from 'feathers-action'

const module = createModule('orders')

export const actions = module.actions
export const updater = module.updater
export const epic = module.epic
31 changes: 0 additions & 31 deletions ordering/epic.js

This file was deleted.

Loading

0 comments on commit 0001349

Please sign in to comment.