| 
									
										
										
										
											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 parseDateTime = require('./date-time') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-30 18:04:44 +02:00
										 |  |  | const typesByIcon = Object.assign(Object.create(null), { | 
					
						
							|  |  |  | 	HimWarn: 'status' | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-23 16:17:20 +02:00
										 |  |  | const parseMsgEdge = (profile) => (e) => { | 
					
						
							|  |  |  | 	const res = omit(e, [ | 
					
						
							|  |  |  | 		'icoX', | 
					
						
							|  |  |  | 		'fLocX', 'fromLocation', | 
					
						
							|  |  |  | 		'tLocX', 'toLocation' | 
					
						
							|  |  |  | 	]) | 
					
						
							| 
									
										
										
										
											2019-08-23 16:02:34 +02:00
										 |  |  | 	res.icon = e.icon || null | 
					
						
							| 
									
										
										
										
											2019-08-23 16:17:20 +02:00
										 |  |  | 	// 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 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-08-23 16:17:20 +02:00
										 |  |  | const parseMsgEvent = (profile) => (e) => { | 
					
						
							| 
									
										
										
										
											2019-02-25 15:04:25 +01:00
										 |  |  | 	return { | 
					
						
							| 
									
										
										
										
											2019-08-23 16:17:20 +02:00
										 |  |  | 		// todo: rename `Loc` -> `Location` [breaking]
 | 
					
						
							|  |  |  | 		fromLoc: e.fromLocation || null, | 
					
						
							|  |  |  | 		toLoc: e.toLocation || null, | 
					
						
							| 
									
										
										
										
											2019-02-25 15:04:25 +01:00
										 |  |  | 		start: parseDateTime(profile, e.fDate, e.fTime, null), | 
					
						
							|  |  |  | 		end: parseDateTime(profile, e.tDate, e.tTime, null), | 
					
						
							|  |  |  | 		sections: e.sectionNums || [] // todo: parse
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 15:03:33 +01:00
										 |  |  | const parseWarning = (profile, w, data) => { | 
					
						
							| 
									
										
										
										
											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' | 
					
						
							| 
									
										
										
										
											2018-06-30 18:04:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-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, | 
					
						
							| 
									
										
										
										
											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-02-25 15:04:25 +01:00
										 |  |  | 	if ('prod' in w) res.products = profile.parseProducts(w.prod) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (w.edgeRefL && data.himMsgEdgeL) { | 
					
						
							|  |  |  | 		res.edges = w.edgeRefL | 
					
						
							|  |  |  | 		.map(i => data.himMsgEdgeL[i]) | 
					
						
							|  |  |  | 		.filter(e => !!e) | 
					
						
							| 
									
										
										
										
											2019-08-23 16:17:20 +02:00
										 |  |  | 		.map(parseMsgEdge(profile)) | 
					
						
							| 
									
										
										
										
											2019-02-25 15:04:25 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (w.eventRefL && data.himMsgEventL) { | 
					
						
							|  |  |  | 		res.events = w.eventRefL | 
					
						
							|  |  |  | 		.map(i => data.himMsgEventL[i]) | 
					
						
							|  |  |  | 		.filter(e => !!e) | 
					
						
							| 
									
										
										
										
											2019-08-23 16:17:20 +02:00
										 |  |  | 		.map(parseMsgEvent(profile)) | 
					
						
							| 
									
										
										
										
											2019-02-25 15:04:25 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-24 20:16:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-15 16:21:29 +02:00
										 |  |  | 	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 |