2018-06-07 18:46:24 +02:00
|
|
|
'use strict'
|
|
|
|
|
2019-03-27 18:31:56 +01:00
|
|
|
const brToNewline = require('@derhuerst/br2nl')
|
2018-06-07 18:46:24 +02:00
|
|
|
|
|
|
|
const parseDateTime = require('./date-time')
|
|
|
|
|
2018-06-30 18:04:44 +02:00
|
|
|
const typesByIcon = Object.assign(Object.create(null), {
|
|
|
|
HimWarn: 'status'
|
|
|
|
})
|
|
|
|
|
2018-06-07 18:46:24 +02:00
|
|
|
// todo: is passing in profile necessary?
|
2018-06-30 18:04:44 +02:00
|
|
|
const parseWarning = (profile, w, icons) => {
|
2019-05-27 16:08:09 +02:00
|
|
|
// todo: pass `d`/`d.common` in, parse `w.fLocX`/`w.tLocX`/`w.icoX`
|
|
|
|
// todo: hid, act, pub, lead, tckr, comp,
|
2018-06-07 18:46:24 +02:00
|
|
|
// todo: cat (1, 2), pubChL
|
|
|
|
// pubChL:
|
|
|
|
// [ { name: 'timetable',
|
|
|
|
// fDate: '20180606',
|
|
|
|
// fTime: '073000',
|
|
|
|
// tDate: '20180713',
|
|
|
|
// tTime: '030000' },
|
|
|
|
// { name: 'export',
|
|
|
|
// fDate: '20180606',
|
|
|
|
// fTime: '073000',
|
|
|
|
// tDate: '20180713',
|
|
|
|
// tTime: '030000' } ]
|
|
|
|
|
2018-07-02 16:59:38 +02:00
|
|
|
const icon = 'number' === typeof w.icoX && icons[w.icoX] || null
|
2018-06-30 18:04:44 +02:00
|
|
|
const type = icon && icon.res && typesByIcon[icon.res] || 'warning'
|
|
|
|
|
2018-08-24 20:16:23 +02:00
|
|
|
const res = {
|
2019-03-27 18:58:34 +01:00
|
|
|
id: w.hid || null,
|
2018-06-30 18:04:44 +02:00
|
|
|
type,
|
2019-03-27 18:58:34 +01:00
|
|
|
summary: brToNewline(w.head), // todo: decode HTML entities
|
|
|
|
text: brToNewline(w.text), // todo: decode HTML entities
|
2018-06-07 18:46:24 +02:00
|
|
|
priority: w.prio,
|
2018-08-24 20:16:23 +02:00
|
|
|
category: w.cat || null // todo: parse to sth meaningful
|
2018-06-07 18:46:24 +02:00
|
|
|
}
|
2019-05-27 16:32:42 +02:00
|
|
|
if ('prod' in w) res.products = profile.parseProducts(61442)
|
2018-08-24 20:16:23 +02:00
|
|
|
|
2018-10-15 16:21:29 +02:00
|
|
|
// todo: pass tzOffset to `parseDateTime`
|
|
|
|
if (w.sDate && w.sTime) res.validFrom = parseDateTime(profile, w.sDate, w.sTime, null)
|
|
|
|
if (w.eDate && w.eTime) res.validUntil = parseDateTime(profile, w.eDate, w.eTime, null)
|
|
|
|
if (w.lModDate && w.lModTime) res.modified = parseDateTime(profile, w.lModDate, w.lModTime, null)
|
2018-08-24 20:16:23 +02:00
|
|
|
|
|
|
|
return res
|
2018-06-07 18:46:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = parseWarning
|