parse: refactor applyRemarks

This commit is contained in:
Jannis R 2019-08-23 16:24:09 +02:00
parent 018fc84bf5
commit f02fe301c7
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -14,24 +14,19 @@ const applyRemarks = (leg, refs) => {
for (let [remark, ref] of findRemarks(refs)) { for (let [remark, ref] of findRemarks(refs)) {
const {fromLocation, toLocation} = ref const {fromLocation, toLocation} = ref
if (ref.fromLocation && ref.toLocation) { const fromI = fromLocation ? leg.stopovers.findIndex(s => s.stop === fromLocation) : -1
const fromI = leg.stopovers.findIndex(s => s.stop === fromLocation) const toI = toLocation ? leg.stopovers.findIndex(s => s.stop === toLocation) : -1
const toI = leg.stopovers.findIndex(s => s.stop === toLocation)
if (fromI < 0 || toI < 0) continue if (fromI < 0 || toI < 0) continue
const wholeLeg = fromI === 0 && toI === (leg.stopovers.length - 1) const wholeLeg = fromI === 0 && toI === (leg.stopovers.length - 1)
if (!wholeLeg) { if (wholeLeg) addRemark(leg, remark)
else {
for (let i = fromI; i <= toI; i++) { for (let i = fromI; i <= toI; i++) {
const stopover = leg.stopovers[i] const stopover = leg.stopovers[i]
if (!stopover) continue if (stopover) addRemark(stopover, remark)
addRemark(stopover, remark)
}
continue
} }
} }
addRemark(leg, remark)
// todo: `ref.tagL` // todo: `ref.tagL`
} }
} }