UNPKG

emsi-lib

Version:

A EMSI (Emergency Management Shared Information) object model to manipulate emergency messages defined in ISO/TR 22351 document

76 lines (75 loc) 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Emsi = void 0; const parse_1 = require("../common/parse"); const types_1 = require("../common/types"); const context_1 = require("./context"); const event_1 = require("./event"); const mission_1 = require("./mission"); const resource_1 = require("./resource"); class Emsi { setContext(context) { this.context = context; return this; } setEvent(event) { this.event = event; return this; } addMissions(missions) { if (!this.mission) this.mission = new Array(); this.mission.push(...missions); return this; } addResources(resources) { if (!this.resource) this.resource = new Array(); this.resource.push(...resources); return this; } generateXml(options, fn) { return parse_1.js2xml({ emsi: { context: this.context, event: this.event, mission: this.mission, resource: this.resource } }, options, fn); } loadFromXml(xml, options, fn) { const js = parse_1.xml2js(xml, options, fn); if (js === null || js === void 0 ? void 0 : js.emsi) { if (js.emsi.context) { this.context = context_1.Context.default().assign(js.emsi.context); } if (js.emsi.event) { this.event = event_1.Event.default().assign(js.emsi.event); } if (js.emsi.mission) { this.mission = new Array(); if (js.emsi.mission instanceof Array) js.emsi.mission.forEach((add) => { var _a; return (_a = this.mission) === null || _a === void 0 ? void 0 : _a.push(mission_1.Mission.default().assign(add)); }); else this.mission.push(mission_1.Mission.default().assign(js.emsi.mission)); } if (js.emsi.resource) { this.resource = new Array(); if (js.emsi.mission instanceof Array) js.emsi.mission.forEach((add) => { var _a; return (_a = this.resource) === null || _a === void 0 ? void 0 : _a.push(resource_1.Resource.default().assign(add)); }); else this.resource.push(resource_1.Resource.default().assign(js.emsi.mission)); } } return this; } checkStatus() { if (!this.context || !this.event) return types_1.EmsiStatus.PARTIAL; if (this.context.id && this.context.mode && this.context.msgType && this.event.id) return types_1.EmsiStatus.READY; if (!this.mission && !this.resource) return types_1.EmsiStatus.EMPTY; return types_1.EmsiStatus.ERROR; } } exports.Emsi = Emsi;