aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2017-07-26 10:14:59 +0200
committerGitHub2017-07-26 10:14:59 +0200
commitd4df8c81179d0e396db562f1d7331ca6f3ed0a5a (patch)
tree4f25b8c5c08b7acd784db197440d1cf27632e7be
parentcada0f02d732dce25492d7f7eb6d6232d56188dd (diff)
parenta486dbe65187aade64c998e21dae139f8bccc6d1 (diff)
downloadchouette-core-d4df8c81179d0e396db562f1d7331ca6f3ed0a5a.tar.bz2
Merge pull request #39 from af83/4161_StopPoints_RouteEdit
4161 stop points route edit
-rw-r--r--app/assets/javascripts/es6_browserified/itineraries/index.js13
-rw-r--r--app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js19
-rw-r--r--spec/javascripts/itineraries/reducers/stop_points_spec.js19
3 files changed, 32 insertions, 19 deletions
diff --git a/app/assets/javascripts/es6_browserified/itineraries/index.js b/app/assets/javascripts/es6_browserified/itineraries/index.js
index a8f3048fa..2ffb84319 100644
--- a/app/assets/javascripts/es6_browserified/itineraries/index.js
+++ b/app/assets/javascripts/es6_browserified/itineraries/index.js
@@ -75,22 +75,9 @@ document.querySelector('input[name=commit]').addEventListener('click', (event)=>
addInput('for_boarding',stopPoint.for_boarding, i)
addInput('for_alighting',stopPoint.for_alighting, i)
})
- if(state.stopPoints.length < datas.length){
- for(var j= state.stopPoints.length; j < datas.length; j++){
- updateFormForDeletion(datas[j])
- }
- }
} else {
event.preventDefault()
let msg = "L'itinĂ©raire doit comporter au moins deux arrĂȘts"
$('#stop_points').find('.subform').after("<div class='alert alert-danger'><span class='fa fa-lg fa-exclamation-circle'></span><span>" + msg + "</span></div>")
}
})
-
-const updateFormForDeletion = (stop) =>{
- if (stop.stoppoint_id !== undefined){
- let now = Date.now()
- addInput('id', stop.stoppoint_id, now)
- addInput('_destroy', 'true', now)
- }
-}
diff --git a/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js b/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js
index 24c3e5d87..a3b8accb3 100644
--- a/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js
+++ b/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js
@@ -20,6 +20,14 @@ const stopPoint = (state = {}, action, length) => {
}
}
+const updateFormForDeletion = (stop) =>{
+ if (stop.stoppoint_id !== undefined){
+ let now = Date.now()
+ addInput('id', stop.stoppoint_id, now)
+ addInput('_destroy', 'true', now)
+ }
+}
+
const stopPoints = (state = [], action) => {
switch (action.type) {
case 'ADD_STOP':
@@ -30,18 +38,19 @@ const stopPoints = (state = [], action) => {
case 'MOVE_STOP_UP':
return [
...state.slice(0, action.index - 1),
- state[action.index],
- state[action.index - 1],
+ _.assign({}, state[action.index], { stoppoint_id: state[action.index - 1].stoppoint_id }),
+ _.assign({}, state[action.index - 1], { stoppoint_id: state[action.index].stoppoint_id }),
...state.slice(action.index + 1)
]
case 'MOVE_STOP_DOWN':
return [
...state.slice(0, action.index),
- state[action.index + 1],
- state[action.index],
+ _.assign({}, state[action.index + 1], { stoppoint_id: state[action.index].stoppoint_id }),
+ _.assign({}, state[action.index], { stoppoint_id: state[action.index + 1].stoppoint_id }),
...state.slice(action.index + 2)
]
case 'DELETE_STOP':
+ updateFormForDeletion(state[action.index])
return [
...state.slice(0, action.index),
...state.slice(action.index + 1).map((stopPoint)=>{
@@ -56,7 +65,7 @@ const stopPoints = (state = [], action) => {
{},
t,
{
- stoppoint_id: "",
+ stoppoint_id: t.stoppoint_id,
text: action.text.text,
stoparea_id: action.text.stoparea_id,
user_objectid: action.text.user_objectid,
diff --git a/spec/javascripts/itineraries/reducers/stop_points_spec.js b/spec/javascripts/itineraries/reducers/stop_points_spec.js
index 93fe85d36..6eae5d5b4 100644
--- a/spec/javascripts/itineraries/reducers/stop_points_spec.js
+++ b/spec/javascripts/itineraries/reducers/stop_points_spec.js
@@ -16,6 +16,7 @@ describe('stops reducer', () => {
{
text: 'first',
index: 0,
+ stoppoint_id: 72,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -27,6 +28,7 @@ describe('stops reducer', () => {
{
text: 'second',
index: 1,
+ stoppoint_id: 73,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -54,6 +56,7 @@ describe('stops reducer', () => {
{
text: 'first',
index: 0,
+ stoppoint_id: 72,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -65,6 +68,7 @@ describe('stops reducer', () => {
{
text: 'second',
index: 1,
+ stoppoint_id: 73,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -99,6 +103,7 @@ describe('stops reducer', () => {
{
text: 'second',
index: 1,
+ stoppoint_id: 72,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -110,6 +115,7 @@ describe('stops reducer', () => {
{
text: 'first',
index: 0,
+ stoppoint_id: 73,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -133,6 +139,7 @@ describe('stops reducer', () => {
{
text: 'second',
index: 1,
+ stoppoint_id: 72,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -144,6 +151,7 @@ describe('stops reducer', () => {
{
text: 'first',
index: 0,
+ stoppoint_id: 73,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -167,6 +175,7 @@ describe('stops reducer', () => {
{
text: 'first',
index: 0,
+ stoppoint_id: 72,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -205,8 +214,8 @@ describe('stops reducer', () => {
text: 'new value',
name: 'new',
index: 0,
+ stoppoint_id: 72,
edit: false,
- stoppoint_id: '',
stoparea_id: 1,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -226,6 +235,7 @@ describe('stops reducer', () => {
{
text: 'second',
index: 1,
+ stoppoint_id: 73,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -251,6 +261,7 @@ describe('stops reducer', () => {
{
text: 'first',
index: 0,
+ stoppoint_id: 72,
edit: false,
for_boarding: 'prohibited',
for_alighting: 'normal',
@@ -262,6 +273,7 @@ describe('stops reducer', () => {
{
text: 'second',
index: 1,
+ stoppoint_id: 73,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -285,6 +297,7 @@ describe('stops reducer', () => {
{
text: 'first',
index: 0,
+ stoppoint_id: 72,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -293,6 +306,7 @@ describe('stops reducer', () => {
json: {
text: 'first',
index: 0,
+ stoppoint_id: 72,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -303,6 +317,7 @@ describe('stops reducer', () => {
{
text: 'second',
index: 1,
+ stoppoint_id: 73,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -326,6 +341,7 @@ describe('stops reducer', () => {
{
text: 'first',
index: 0,
+ stoppoint_id: 72,
edit: true,
for_boarding: 'normal',
for_alighting: 'normal',
@@ -337,6 +353,7 @@ describe('stops reducer', () => {
{
text: 'second',
index: 1,
+ stoppoint_id: 73,
edit: false,
for_boarding: 'normal',
for_alighting: 'normal',