2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2018-06-30 18:04:44 +02:00
|
|
|
const codesByIcon = Object.assign(Object.create(null), {
|
|
|
|
cancel: 'cancelled'
|
|
|
|
})
|
|
|
|
|
2017-11-12 01:23:34 +01:00
|
|
|
// todo: is passing in profile necessary?
|
2019-06-21 18:43:10 +02:00
|
|
|
// todo: pass in tag list from hint reference, e.g.:
|
|
|
|
// "tagL": [
|
|
|
|
// "RES_JNY_H3" // H3 = level 3 heading? shown on overview
|
|
|
|
// ]
|
|
|
|
// "tagL": [
|
|
|
|
// "RES_JNY_DTL" // only shown in journey detail
|
|
|
|
// ]
|
2018-06-30 18:04:44 +02:00
|
|
|
const parseHint = (profile, h, icons) => {
|
2018-06-01 11:12:54 +02:00
|
|
|
// todo: C
|
2018-07-02 18:48:23 +02:00
|
|
|
// todo:
|
|
|
|
// { type: 'Q',
|
|
|
|
// code: '',
|
|
|
|
// icoX: 11,
|
|
|
|
// txtN:
|
|
|
|
// 'RE 3132: Berlin Zoologischer Garten - Brandenburg Hbf: Information. A railway carriage is missing',
|
|
|
|
// sIdx: 4 }
|
2018-06-11 18:41:53 +02:00
|
|
|
|
|
|
|
const text = h.txtN && h.txtN.trim() || ''
|
2018-06-30 18:04:44 +02:00
|
|
|
const icon = 'number' === typeof h.icoX && icons[h.icoX] || null
|
|
|
|
const code = h.code || (icon && icon.res && codesByIcon[icon.res]) || null
|
2018-06-07 15:41:00 +02:00
|
|
|
|
2018-06-11 19:50:44 +02:00
|
|
|
if (h.type === 'M') {
|
|
|
|
return {
|
|
|
|
type: 'status',
|
|
|
|
summary: h.txtS && h.txtS.trim() || '',
|
2018-06-30 18:04:44 +02:00
|
|
|
code,
|
2018-06-11 19:50:44 +02:00
|
|
|
text
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-07 16:00:28 +02:00
|
|
|
if (h.type === 'L') {
|
2018-06-01 11:12:54 +02:00
|
|
|
return {
|
|
|
|
type: 'status',
|
|
|
|
code: 'alternative-trip',
|
2018-06-11 18:41:53 +02:00
|
|
|
text,
|
2018-06-26 14:57:02 +02:00
|
|
|
tripId: h.jid
|
2018-06-01 11:12:54 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-07 16:00:28 +02:00
|
|
|
if (h.type === 'A') {
|
2018-07-09 19:26:15 +02:00
|
|
|
return {
|
|
|
|
type: 'hint',
|
|
|
|
code: h.code || null,
|
|
|
|
text: h.txtN || null
|
2018-06-30 18:04:44 +02:00
|
|
|
}
|
2018-06-07 15:41:00 +02:00
|
|
|
}
|
2018-06-30 18:04:44 +02:00
|
|
|
|
2018-12-28 00:36:09 +01:00
|
|
|
if (h.type === 'D' || h.type === 'U' || h.type === 'R' || h.type === 'N' || h.type === 'Y') {
|
2018-06-01 11:12:54 +02:00
|
|
|
// todo: how can we identify the individual types?
|
2018-07-02 18:48:23 +02:00
|
|
|
// todo: does `D` mean "disturbance"?
|
2018-06-01 11:12:54 +02:00
|
|
|
return {
|
|
|
|
type: 'status',
|
2018-06-30 18:04:44 +02:00
|
|
|
code,
|
2018-06-11 18:41:53 +02:00
|
|
|
text
|
2018-06-01 11:12:54 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-02 18:48:23 +02:00
|
|
|
|
2018-06-01 11:12:54 +02:00
|
|
|
return null
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
2018-06-07 16:00:28 +02:00
|
|
|
module.exports = parseHint
|