all files / common/models/external-view/ external-view.js

84.44% Statements 38/45
83.33% Branches 10/12
90% Functions 9/10
84.44% Lines 38/45
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77  30× 30×   30×   30× 30× 30× 30× 30×         30×                 30×   26×   28× 28×             30×       30× 12× 30×             21×              
"use strict";
var immutable_class_1 = require('immutable-class');
var check;
var ExternalView = (function () {
    function ExternalView(parameters) {
        var title = parameters.title, linkGenerator = parameters.linkGenerator;
        Iif (!title)
            throw new Error("External view must have title");
        Iif (typeof linkGenerator !== 'string')
            throw new Error("Must provide link generator function");
        this.title = title;
        this.linkGenerator = linkGenerator;
        var linkGeneratorFnRaw = null;
        try {
            linkGeneratorFnRaw = new Function('dataSource', 'timezone', 'filter', 'splits', linkGenerator);
        }
        catch (e) {
            throw new Error("Error constructing link generator function: " + e.message);
        }
        this.linkGeneratorFn = function (dataSource, timezone, filter, splits) {
            try {
                return linkGeneratorFnRaw(dataSource, timezone, filter, splits);
            }
            catch (e) {
                console.warn("Error with custom link generating function '" + title + "': " + e.message + " [" + linkGenerator + "]");
                return null;
            }
        };
        this.sameWindow = Boolean(parameters.sameWindow);
    }
    ExternalView.isExternalView = function (candidate) {
        return immutable_class_1.isInstanceOf(candidate, ExternalView);
    };
    ExternalView.fromJS = function (parameters) {
        var value = parameters;
        return new ExternalView({
            title: value.title,
            linkGenerator: value.linkGenerator,
            linkGeneratorFn: value.linkGeneratorFn,
            sameWindow: value.sameWindow
        });
    };
    ExternalView.prototype.toJS = function () {
        var js = {
            title: this.title,
            linkGenerator: this.linkGenerator
        };
        if (this.sameWindow === true)
            js.sameWindow = true;
        return js;
    };
    ExternalView.prototype.valueOf = function () {
        var value = {
            title: this.title,
            linkGenerator: this.linkGenerator
        };
        if (this.sameWindow === true)
            value.sameWindow = true;
        return value;
    };
    ExternalView.prototype.toJSON = function () {
        return this.toJS();
    };
    ExternalView.prototype.equals = function (other) {
        return ExternalView.isExternalView(other) &&
            this.title === other.title &&
            this.linkGenerator === other.linkGenerator &&
            this.sameWindow === other.sameWindow;
    };
    ExternalView.prototype.toString = function () {
        return this.title + ": " + this.linkGenerator;
    };
    return ExternalView;
}());
exports.ExternalView = ExternalView;
check = ExternalView;