db-vendo-client/parse/warning.js

90 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-06-07 18:46:24 +02:00
'use strict'
2019-03-27 18:31:56 +01:00
const brToNewline = require('@derhuerst/br2nl')
2019-02-25 15:04:25 +01:00
const omit = require('lodash/omit')
2018-06-07 18:46:24 +02:00
const typesByIcon = Object.assign(Object.create(null), {
HimWarn: 'status'
})
const parseMsgEdge = (ctx) => (e) => {
const res = omit(e, [
'icoX',
'fLocX', 'fromLocation',
'tLocX', 'toLocation'
])
2019-08-23 16:02:34 +02:00
res.icon = e.icon || null
// todo: rename `Loc` -> `Location` [breaking]
res.fromLoc = e.fromLocation || null
res.toLoc = e.toLocation || null
2019-02-25 15:04:25 +01:00
return res
}
const parseMsgEvent = ({profile}) => (e) => {
2019-02-25 15:04:25 +01:00
return {
// todo: rename `Loc` -> `Location` [breaking]
fromLoc: e.fromLocation || null,
toLoc: e.toLocation || null,
start: profile.parseDateTime(ctx, e.fDate, e.fTime, null),
end: profile.parseDateTime(ctx, e.tDate, e.tTime, null),
2019-02-25 15:04:25 +01:00
sections: e.sectionNums || [] // todo: parse
}
}
const parseWarning = (ctx, w) => {
const {profile, res: resp} = ctx
2019-08-23 15:36:57 +02:00
// todo: act, pub, lead, tckr, prod, comp,
2019-02-25 15:04:25 +01:00
// todo: cat (1, 2), pubChL, rRefL, impactL
2018-06-07 18:46:24 +02:00
// pubChL:
// [ { name: 'timetable',
// fDate: '20180606',
// fTime: '073000',
// tDate: '20180713',
// tTime: '030000' },
// { name: 'export',
// fDate: '20180606',
// fTime: '073000',
// tDate: '20180713',
// tTime: '030000' } ]
2019-02-25 15:04:25 +01:00
// { name: '1',
// fDate: '20190219',
// fTime: '000000',
// tDate: '20190225',
// tTime: '120000' }
2018-06-07 18:46:24 +02:00
2019-08-23 16:02:34 +02:00
const icon = w.icon || null
2018-10-27 14:50:45 +02:00
const type = icon && icon.type && typesByIcon[icon.type] || 'warning'
const res = {
2019-03-27 18:58:34 +01:00
id: w.hid || null,
type,
2019-02-25 15:04:25 +01:00
summary: w.head ? brToNewline(w.head) : null, // todo: decode HTML entities?
text: w.text ? brToNewline(w.text) : null, // todo: decode HTML entities?
icon, // todo: parse icon
2018-06-07 18:46:24 +02:00
priority: w.prio,
category: w.cat || null // todo: parse to sth meaningful
2018-06-07 18:46:24 +02:00
}
if ('prod' in w) res.products = profile.parseProductsBitmask(ctx, w.prod)
2019-02-25 15:04:25 +01:00
if (w.edgeRefL && resp.common && resp.common.himMsgEdgeL) {
2019-02-25 15:04:25 +01:00
res.edges = w.edgeRefL
.map(i => resp.common.himMsgEdgeL[i])
2019-02-25 15:04:25 +01:00
.filter(e => !!e)
.map(parseMsgEdge(ctx))
2019-02-25 15:04:25 +01:00
}
if (w.eventRefL && resp.common && resp.common.himMsgEventL) {
2019-02-25 15:04:25 +01:00
res.events = w.eventRefL
.map(i => resp.common.himMsgEventL[i])
2019-02-25 15:04:25 +01:00
.filter(e => !!e)
.map(parseMsgEvent(ctx))
2019-02-25 15:04:25 +01:00
}
if (w.sDate && w.sTime) res.validFrom = profile.parseDateTime(ctx, w.sDate, w.sTime, null)
if (w.eDate && w.eTime) res.validUntil = profile.parseDateTime(ctx, w.eDate, w.eTime, null)
if (w.lModDate && w.lModTime) res.modified = profile.parseDateTime(ctx, w.lModDate, w.lModTime, null)
return res
2018-06-07 18:46:24 +02:00
}
module.exports = parseWarning