aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/assets/javascripts/es6_browserified/actions/index.js12
-rw-r--r--app/assets/javascripts/es6_browserified/components/Todo.js17
-rw-r--r--app/assets/javascripts/es6_browserified/components/TodoList.js6
-rw-r--r--app/assets/javascripts/es6_browserified/containers/VisibleTodoList.js3
-rw-r--r--app/assets/javascripts/es6_browserified/reducers/todos.js31
-rw-r--r--app/assets/javascripts/es6_browserified/stop_points.js10
-rw-r--r--app/helpers/routes_helper.rb6
-rw-r--r--spec/javascripts/actions_spec.js25
8 files changed, 77 insertions, 33 deletions
diff --git a/app/assets/javascripts/es6_browserified/actions/index.js b/app/assets/javascripts/es6_browserified/actions/index.js
index b92f9c913..7d225f2f6 100644
--- a/app/assets/javascripts/es6_browserified/actions/index.js
+++ b/app/assets/javascripts/es6_browserified/actions/index.js
@@ -24,11 +24,19 @@ const actions = {
},
updateInputValue : (index, text) => {
return {
- type : "UPDATE_INPUT_VALUE",
+ type : 'UPDATE_INPUT_VALUE',
index,
text
}
+ },
+ updateSelectValue: (e, index) => {
+ return {
+ type :'UPDATE_SELECT_VALUE',
+ select_id: e.currentTarget.id,
+ select_value: e.currentTarget.value,
+ index
+ }
}
}
-export default actions
+module.exports = actions
diff --git a/app/assets/javascripts/es6_browserified/components/Todo.js b/app/assets/javascripts/es6_browserified/components/Todo.js
index 85aff9825..b5313876e 100644
--- a/app/assets/javascripts/es6_browserified/components/Todo.js
+++ b/app/assets/javascripts/es6_browserified/components/Todo.js
@@ -20,21 +20,17 @@ const Todo = (props) => {
</div>
<div style={secondBlock}>
<div style={{display: 'inline-block', width: '100%', verticalAlign: 'middle'}}>
- <select id="1">
- <option value="" disabled="disabled" selected="selected">Select...</option>
- <option value="opt1">option #1</option>
- <option value="opt2">option #2</option>
- <option value="opt3">option #3</option>
+ <select value={props.value.for_boarding} id="for_boarding" onChange={props.onSelectChange}>
+ <option value="forbidden">interdit</option>
+ <option value="normal">normal</option>
</select>
</div>
</div>
<div style={secondBlock}>
<div style={{display: 'inline-block', width: '100%', verticalAlign: 'middle'}}>
- <select id="2">
- <option value="" disabled="disabled" selected="selected">Select...</option>
- <option value="opt1">option #1</option>
- <option value="opt2">option #2</option>
- <option value="opt3">option #3</option>
+ <select value={props.value.for_alighting} id="for_alighting" onChange={props.onSelectChange}>
+ <option value="forbidden">interdit</option>
+ <option value="normal">normal</option>
</select>
</div>
</div>
@@ -70,6 +66,7 @@ Todo.propTypes = {
onMoveUpClick: PropTypes.func.isRequired,
onMoveDownClick: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
+ onSelectChange: PropTypes.func.isRequired,
first: PropTypes.bool,
last: PropTypes.bool,
index: PropTypes.number,
diff --git a/app/assets/javascripts/es6_browserified/components/TodoList.js b/app/assets/javascripts/es6_browserified/components/TodoList.js
index 79967e336..03bd4dbf6 100644
--- a/app/assets/javascripts/es6_browserified/components/TodoList.js
+++ b/app/assets/javascripts/es6_browserified/components/TodoList.js
@@ -1,7 +1,7 @@
import React, {PropTypes} from 'react'
import Todo from './Todo'
-const TodoList = ({ todos, onDeleteClick, onMoveUpClick, onMoveDownClick, onChange }) => {
+const TodoList = ({ todos, onDeleteClick, onMoveUpClick, onMoveDownClick, onChange, onSelectChange }) => {
return (
<div className='list-group'>
{todos.map((todo, index) =>
@@ -13,6 +13,7 @@ const TodoList = ({ todos, onDeleteClick, onMoveUpClick, onMoveDownClick, onChan
}}
onMoveDownClick={() => onMoveDownClick(index)}
onChange={ onChange }
+ onSelectChange={ (e) => onSelectChange(e, index) }
first={ index === 0 }
last={ index === (todos.length - 1) }
index={ index }
@@ -27,7 +28,8 @@ TodoList.propTypes = {
todos: PropTypes.array.isRequired,
onDeleteClick: PropTypes.func.isRequired,
onMoveUpClick: PropTypes.func.isRequired,
- onMoveDownClick: PropTypes.func.isRequired
+ onMoveDownClick: PropTypes.func.isRequired,
+ onSelectChange: PropTypes.func.isRequired
}
export default TodoList
diff --git a/app/assets/javascripts/es6_browserified/containers/VisibleTodoList.js b/app/assets/javascripts/es6_browserified/containers/VisibleTodoList.js
index 4bb4e6c05..a9b395279 100644
--- a/app/assets/javascripts/es6_browserified/containers/VisibleTodoList.js
+++ b/app/assets/javascripts/es6_browserified/containers/VisibleTodoList.js
@@ -21,6 +21,9 @@ const mapDispatchToProps = (dispatch) => {
},
onChange: (index, text) =>{
dispatch(actions.updateInputValue(index, text))
+ },
+ onSelectChange: (e, index) =>{
+ dispatch(actions.updateSelectValue(e, index))
}
}
}
diff --git a/app/assets/javascripts/es6_browserified/reducers/todos.js b/app/assets/javascripts/es6_browserified/reducers/todos.js
index cf3c0cbf7..cbbb59c37 100644
--- a/app/assets/javascripts/es6_browserified/reducers/todos.js
+++ b/app/assets/javascripts/es6_browserified/reducers/todos.js
@@ -5,19 +5,10 @@ const todo = (state = {}, action, length) => {
case 'ADD_STOP':
return {
text: '',
- index: length
+ index: length,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
}
- case 'UPDATE_INPUT_VALUE':
- console.log('reducer', action)
- if (state.index !== action.index) {
- return state
- }
-
- return Object.assign(
- {},
- state,
- {text: action.text.text, stoparea_id: action.text.stoparea_id}
- )
default:
return state
}
@@ -64,7 +55,11 @@ const todos = (state = [], action) => {
return state.map( (t, i) => {
if (i === action.index) {
updateFormForDeletion(t)
- return action.text
+ return Object.assign(
+ {},
+ t,
+ {text: action.text.text, stoparea_id: action.text.stoparea_id}
+ )
} else {
return t
}
@@ -72,6 +67,16 @@ const todos = (state = [], action) => {
// return state.map(t =>
// todo(t, action)
// )
+ case 'UPDATE_SELECT_VALUE':
+ return state.map( (t,i) => {
+ if (i === action.index) {
+ let stopState = Object.assign({}, t)
+ stopState[action.select_id] = action.select_value
+ return stopState
+ } else {
+ return t
+ }
+ })
default:
return state
}
diff --git a/app/assets/javascripts/es6_browserified/stop_points.js b/app/assets/javascripts/es6_browserified/stop_points.js
index 339264d51..f3ac81906 100644
--- a/app/assets/javascripts/es6_browserified/stop_points.js
+++ b/app/assets/javascripts/es6_browserified/stop_points.js
@@ -5,8 +5,10 @@ import { createStore } from 'redux'
import todoApp from './reducers'
import App from './components/App'
import addInput from './form_helper'
+
+// logger, DO NOT REMOVE
// var applyMiddleware = require('redux').applyMiddleware
-// var createLogger = require('redux-logger').default
+// var createLogger = require('redux-logger')
// var thunkMiddleware = require('redux-thunk').default
// var promise = require('redux-promise')
@@ -25,7 +27,9 @@ const getInitialState = () => {
index: index,
city_name: value.city_name,
zip_code: value.zip_code,
- text: fancyText
+ text: fancyText,
+ for_boarding: value.for_boarding || "normal",
+ for_alighting: value.for_alighting || "normal"
})
}
return state
@@ -55,5 +59,7 @@ document.querySelector('input[name=commit]').addEventListener('click', (event)=>
addInput('id',todo.stoppoint_id, i)
addInput('stop_area_id',todo.stoparea_id, i)
addInput('position',i, i)
+ addInput('for_boarding',todo.for_boarding, i)
+ addInput('for_alighting',todo.for_alighting, i)
}
})
diff --git a/app/helpers/routes_helper.rb b/app/helpers/routes_helper.rb
index 71017fd13..99278625d 100644
--- a/app/helpers/routes_helper.rb
+++ b/app/helpers/routes_helper.rb
@@ -14,7 +14,11 @@ module RoutesHelper
end
def route_json_for_edit(route)
- route.stop_points.includes(:stop_area).map { |s| s.stop_area.attributes.slice("name","city_name", "zip_code").merge(stoppoint_id: s.id, stoparea_id: s.stop_area.id) }.to_json
+ route.stop_points.includes(:stop_area).map do |stop_point|
+ stop_area_attributes = stop_point.stop_area.attributes.slice("name","city_name", "zip_code")
+ stop_point_attributes = stop_point.attributes.slice("for_boarding","for_alighting")
+ stop_area_attributes.merge(stop_point_attributes).merge(stoppoint_id: stop_point.id, stoparea_id: stop_point.stop_area.id)
+ end.to_json
end
end
diff --git a/spec/javascripts/actions_spec.js b/spec/javascripts/actions_spec.js
index 43ebba77f..55de1c31f 100644
--- a/spec/javascripts/actions_spec.js
+++ b/spec/javascripts/actions_spec.js
@@ -19,7 +19,7 @@ describe('actions', () => {
})
})
describe('actions', () => {
- it('should create an action to add a stop', () => {
+ it('should create an action to move down a stop', () => {
const index = 1
const expectedAction = {
type: 'MOVE_STOP_DOWN',
@@ -29,7 +29,7 @@ describe('actions', () => {
})
})
describe('actions', () => {
- it('should create an action to add a stop', () => {
+ it('should create an action to delete a stop', () => {
const index = 1
const expectedAction = {
type: 'DELETE_STOP',
@@ -39,7 +39,7 @@ describe('actions', () => {
})
})
describe('actions', () => {
- it('should create an action to add a stop', () => {
+ it('should create an action to update the value of a stop', () => {
const text = 'updated text'
const index = 1
const expectedAction = {
@@ -50,3 +50,22 @@ describe('actions', () => {
expect(actions.updateInputValue(index, text)).toEqual(expectedAction)
})
})
+
+describe('actions', () => {
+ it('should create an action to update the up select of a stop', () => {
+ const event = {
+ currentTarget: {
+ value: 'forbidden',
+ id: 'up'
+ }
+ }
+ const index = 1
+ const expectedAction = {
+ type :'UPDATE_SELECT_VALUE',
+ select_id: 'up',
+ select_value: 'forbidden',
+ index
+ }
+ expect(actions.updateSelectValue(event, index)).toEqual(expectedAction)
+ })
+})