all files / common/models/sort-on/ sort-on.js

73.77% Statements 45/61
50% Branches 10/20
55.56% Functions 10/18
73.77% Lines 45/61
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91  19× 19×   30×                                       16× 16×     10×   16×           18× 18×     12×   18×       24×                      
"use strict";
var immutable_class_1 = require('immutable-class');
var plywood_1 = require('plywood');
var dimension_1 = require('../dimension/dimension');
var measure_1 = require('../measure/measure');
var check;
var SortOn = (function () {
    function SortOn(parameters) {
        this.dimension = parameters.dimension;
        this.measure = parameters.measure;
    }
    SortOn.isSortOn = function (candidate) {
        return immutable_class_1.isInstanceOf(candidate, SortOn);
    };
    SortOn.equal = function (s1, s2) {
        return s1 === s2 || s1.equals(s2);
    };
    SortOn.getName = function (s) {
        return s.toName();
    };
    SortOn.getTitle = function (s) {
        return s.getTitle();
    };
    SortOn.fromDimension = function (dimension) {
        return new SortOn({ dimension: dimension });
    };
    SortOn.fromMeasure = function (measure) {
        return new SortOn({ measure: measure });
    };
    SortOn.fromSortAction = function (sortAction, dataSource, fallbackDimension) {
        if (!sortAction)
            return SortOn.fromDimension(fallbackDimension);
        var sortOnName = sortAction.expression.name;
        var measure = dataSource.getMeasure(sortOnName);
        if (measure)
            return SortOn.fromMeasure(measure);
        return SortOn.fromDimension(fallbackDimension);
    };
    SortOn.fromJS = function (parameters) {
        var value = {};
        if (parameters.dimension) {
            value.dimension = dimension_1.Dimension.fromJS(parameters.dimension);
        }
        else {
            value.measure = measure_1.Measure.fromJS(parameters.measure);
        }
        return new SortOn(value);
    };
    SortOn.prototype.valueOf = function () {
        return {
            dimension: this.dimension,
            measure: this.measure
        };
    };
    SortOn.prototype.toJS = function () {
        var js = {};
        if (this.dimension) {
            js.dimension = this.dimension.toJS();
        }
        else {
            js.measure = this.measure.toJS();
        }
        return js;
    };
    SortOn.prototype.toJSON = function () {
        return this.toJS();
    };
    SortOn.prototype.toString = function () {
        return "[SortOn: " + this.toName() + "]";
    };
    SortOn.prototype.equals = function (other) {
        return SortOn.isSortOn(other) &&
            (this.dimension ? this.dimension.equals(other.dimension) : this.measure.equals(other.measure));
    };
    SortOn.prototype.toName = function () {
        var measure = this.measure;
        return measure ? measure.name : this.dimension.name;
    };
    SortOn.prototype.getTitle = function () {
        var measure = this.measure;
        return measure ? measure.title : this.dimension.title;
    };
    SortOn.prototype.getExpression = function () {
        var measure = this.measure;
        return plywood_1.$(measure ? measure.name : 'SEGMENT');
    };
    return SortOn;
}());
exports.SortOn = SortOn;
check = SortOn;