UNPKG

@iotile/iotile-cloud

Version:

A typescript library for interfacing with the IOTile Cloud API

122 lines 4.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var displaywidget_1 = require("./displaywidget"); var SensorGraph = /** @class */ (function () { function SensorGraph(data) { if (data === void 0) { data = {}; } this.id = data.id; this.name = data.name; this.slug = data.slug; this.org = data.org; this.projectTemplate = data.project_template; this.variableTemplates = data.variable_templates; this.uiExtra = data.ui_extra; this.version = data.version; this.majorVersion = data.major_version; this.minorVersion = data.minor_version; this.patchVersion = data.patch_version; this.createdOn = data.created_on; this.rawData = data; this.displayWidgetTemplates = []; if (!this.uiExtra) { this.uiExtra = { mobile: { controller: 'defaultCtrl', directory: null, settingsController: 'defaultSettingsCtrl', settingsTemplate: 'default-settings', template: 'default', settings: { template: "device-settings", controller: "DeviceSettingsCtrl" }, ioInfo: null }, }; } if ("display_widget_templates" in data) { var that_1 = this; data["display_widget_templates"].forEach(function (d) { var widget = new displaywidget_1.DisplayWidget(d); that_1.displayWidgetTemplates.push(widget); }); } } SensorGraph.prototype.getVersion = function () { return 'v' + [this.majorVersion, this.minorVersion, this.patchVersion].join('.'); }; SensorGraph.prototype.getUiExtra = function (type) { if (this.uiExtra && this.uiExtra[type]) { return this.uiExtra[type]; } return null; }; SensorGraph.prototype.getIoInfo = function (type) { if (this.getUiExtra(type)) { var uiExtra = this.getUiExtra(type); if (uiExtra.ioInfo && uiExtra.ioInfo.order && uiExtra.ioInfo.map) { return uiExtra.ioInfo; } } return null; }; // Mobile method SensorGraph.prototype.getStreamLids = function () { var ioInfo = this.getIoInfo('mobile'); if (ioInfo == null) { return []; } var streams = []; for (var lid in ioInfo.map) { streams.push(lid); if (ioInfo.map[lid].derived) { var derivedStreams = ioInfo.map[lid].derived; for (var derivedType in derivedStreams) { if (derivedStreams[derivedType].lid) { streams.push(derivedStreams[derivedType].lid); } } } } return streams; }; // Mobile method SensorGraph.prototype.getIoInfoParameter = function (lid, name) { var ioInfo = this.getIoInfo('mobile'); // 1. Check if there is an ioInfo.map and if so, if there is // data for the given LID if (ioInfo) { if (ioInfo.map[lid][name]) { return ioInfo.map[lid][name]; } } else { // 2. Look for a global value for that parameter name var uiExtra = this.getUiExtra('mobile'); if (uiExtra[name]) { return uiExtra[name]; } } return ''; }; SensorGraph.prototype.getSettingsController = function (lid) { var controller = this.getIoInfoParameter(lid, 'settingsController'); if (controller !== '') { return controller; } return 'defaultSettingsCtrl'; }; SensorGraph.prototype.getSettingsTemplate = function (lid) { var template = this.getIoInfoParameter(lid, 'settingsTemplate'); if (template !== '') { return template; } return 'default-settings'; }; SensorGraph.prototype.toJson = function () { return this.rawData; }; return SensorGraph; }()); exports.SensorGraph = SensorGraph; //# sourceMappingURL=sensorgraph.js.map