Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stoptime pickup/dropoff type keypress event in timetable view #205

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 75 additions & 3 deletions public/javascripts/views/trip-pattern-schedule-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ var GtfsEditor = GtfsEditor || {};
// delete trip (also requires shift key, as coded in the function)
deleteTrip: 46,
// also backspace, for laptop users with no delete key...
deleteTripAlternate: 8
deleteTripAlternate: 8,
// pickup only
pickup: 80,
// dropoff only
dropoff: 68
};

/**
Expand Down Expand Up @@ -74,6 +78,8 @@ var GtfsEditor = GtfsEditor || {};
// TODO: single-time view
// time is seconds since midnight
var text;

console.log(value.get('stopTime'));
if (value.get('stopTime') === null) {
text = '<span class="time no-stop">-</span>';
} else {
Expand All @@ -82,7 +88,15 @@ var GtfsEditor = GtfsEditor || {};
var st = value.get('stopTime');
var time = arr ? st.arrivalTime : st.departureTime;
var spTime = splitTime(time);

if (st.dropOffType === 'NONE'){
td.style.backgroundColor = 'yellow';
}
if (st.pickupType === 'NONE'){
td.style.backgroundColor = 'blue';
if (st.dropOffType === 'NONE'){
td.style.backgroundColor = 'red';
}
}
if (spTime === null) {
// time is to be interpolated by consumer
text = '';
Expand Down Expand Up @@ -506,7 +520,53 @@ var GtfsEditor = GtfsEditor || {};

this.$container.handsontable('render');
},
modifyStopTimeType: function(coords, type) {
var instance = this;

// get the affected trips
// [0] and [2] are the first and last selected rows. Javascript's slice excludes the end, so we add one.
var trips = this.collection.slice(coords[0], coords[2] + 1);

_.each(trips, function(trip) {
// find the affected stoptimes
var fromCell = coords[1] - 4;
var toCell = coords[3] - 4;
var from = Math.floor(fromCell / 2);
var to = Math.floor(toCell / 2) + 1;
var affectedStopTimes = trip.get('stopTimes').slice(from, to);

_.each(affectedStopTimes, function(st, idx) {
if (st === null || _.isUndefined(st))
return;

// if we're not looking at the first stoptime, and/or the first cell is even, update arrival time
// if the first cell is odd and this is the first stoptime, we're only updating the departureTime.
// but don't update interpolated times, leave them interpolated
if ((idx !== 0 || fromCell % 2 === 0)){
if(type === 'p'){
if(st.pickupType === 'SCHEDULED' || st.pickupType === null){
st.pickupType = 'NONE';
}
else{
st.pickupType = 'SCHEDULED';
}
}
else if (type === 'd'){
if(st.dropOffType === 'SCHEDULED' || st.dropOffType === null){
st.dropOffType = 'NONE';
}
else{
st.dropOffType = 'SCHEDULED';
}
}
}
});

trip.modified = true;
});

this.$container.handsontable('render');
},
/** sort the trips by first stop time, nulls first */
sort: function () {
this.collection.sort();
Expand All @@ -519,7 +579,7 @@ var GtfsEditor = GtfsEditor || {};

st.stopId = patternStop.stopId;
st.pickupType = this.stops.get(patternStop.stopId).get('pickupType');
st.dropOffType = this.stops.get(patternStop.stopId).get('dropoffType');
st.dropOffType = this.stops.get(patternStop.stopId).get('dropOffType');

st.arrivalTime = st.departureTime = null;

Expand Down Expand Up @@ -554,6 +614,18 @@ var GtfsEditor = GtfsEditor || {};
instance.collection.trigger('change');
});

// p: specify pickup or dropoff only
}
else if (e.keyCode == keyCodes.pickup || e.keyCode == keyCodes.dropoff) {
if (_.isUndefined(sel) || sel[1] < 4)
return;

this.getInput('[p]ickup or [d]ropoff only?', function(input) {
instance.modifyStopTimeType(sel, input);
instance.collection.trigger('change');
});
console.log('pickup!')
console.log(sel)
// i: insert new trip
// basically, duplicate this trip or these trips, with the entered offset
} else if (e.keyCode == keyCodes.insert) {
Expand Down