Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@fbinhouse/volvo-cms-core / dist / lib / model / variableInstance.js
Size: Mime:
"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var mobx_1 = require("mobx");
var metadata_1 = require("../../constants/metadata");
var services_1 = require("../../constants/services");
var stores_1 = require("../../constants/stores");
var interfaces_1 = require("../../interfaces");
var container_1 = require("../../ioc/model/container");
var container_2 = require("../../ioc/model/container");
var metadata_2 = require("../metadata");
var VariableInstance = /** @class */ (function () {
    function VariableInstance(model, metadata, code) {
        this.uuid = mobx_1.extras.getDebugName(this);
        this._model = model;
        this._metadata = metadata;
        this._code = code;
    }
    Object.defineProperty(VariableInstance.prototype, "value", {
        get: function () {
            var _this = this;
            var data = this._model.getPage().getModelData(this._model.getId()).data[this._code];
            if (data._value !== undefined) {
                if (this._metadata.options.responsive) {
                    var breakpointReached = false;
                    var value = void 0;
                    for (var _i = 0, _a = Object.keys(interfaces_1.interfaces.Breakpoint).reverse(); _i < _a.length; _i++) {
                        var breakpoint = _a[_i];
                        if (breakpoint === this._model.getPage().getApp().currentBreakpoint) {
                            breakpointReached = true;
                        }
                        var breakpointValue = data._value[breakpoint];
                        if (breakpointValue !== null && breakpointValue !== undefined) {
                            value = breakpointValue;
                        }
                        if (value !== undefined && breakpointReached) {
                            break;
                        }
                    }
                    return value;
                }
                return data._value;
            }
            if (this._metadata.options.repeatable) {
                return data
                    .map(function (ref) { return _this._model.getPage().transformModel(ref._ref); });
            }
            if (data._ref !== null) {
                return this._model.getPage().transformModel(data._ref);
            }
        },
        set: function (value) {
            throw new Error('Must not set value of a variable instance directly. Use setter on model instance instead.');
        },
        enumerable: true,
        configurable: true
    });
    VariableInstance.prototype.setValue = function (value) {
        var _a;
        var modelData = this._model.getPage().getModelData(this._model.getId());
        if (this._metadata.type === 'child') {
            throw new Error('Reference variables must not be set directly.');
        }
        if (this._metadata.options.responsive) {
            var currentValue = modelData.data[this._code]
                ._value;
            modelData.data[this._code] = { _value: __assign({}, currentValue, (_a = {}, _a[this._model.getPage().getApp().currentBreakpoint] = value, _a)) };
        }
        else {
            modelData.data[this._code] = { _value: value };
        }
        this._model._page.getApp().controller.emit('pageModelVariableSet', this._model._page.id, this._model._id, this._code, modelData.data[this._code]._value);
    };
    Object.defineProperty(VariableInstance.prototype, "isEditable", {
        get: function () {
            if (this.options.isEditable) {
                return this.options.isEditable(this._model);
            }
            return true;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(VariableInstance.prototype, "options", {
        get: function () {
            return this._metadata.options;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(VariableInstance.prototype, "typeCode", {
        get: function () {
            return this.getVariableTypeMetadata().code;
        },
        enumerable: true,
        configurable: true
    });
    VariableInstance.prototype.getCode = function () {
        return this._code;
    };
    VariableInstance.prototype.getVariableTypeMetadata = function () {
        return Reflect.getOwnMetadata(metadata_1.default.VARIABLE_TYPE, this._metadata.type);
    };
    VariableInstance.prototype.getElementComponent = function () {
        return this._elementRegistry.getElementComponentByVariableType(this.typeCode);
    };
    VariableInstance.prototype.getFormElementComponent = function () {
        return this._formElementRegistry.getElementComponentByVariableType(this.typeCode);
    };
    VariableInstance.prototype.getModel = function () {
        return this._model;
    };
    VariableInstance.prototype.requestValueChange = function (value) {
        var app = this.getModel().getPage().getApp();
        app.requestValueChange(this, value);
    };
    VariableInstance.prototype.hasFlag = function (flagId, path) {
        return this._metadata.hasFlag(flagId, path);
    };
    __decorate([
        container_2.ibd.lazyInject(services_1.default.ELEMENT_REGISTRY),
        __metadata("design:type", Object)
    ], VariableInstance.prototype, "_elementRegistry", void 0);
    __decorate([
        container_2.ibd.lazyInject(services_1.default.FORM_ELEMENT_REGISTRY),
        __metadata("design:type", Object)
    ], VariableInstance.prototype, "_formElementRegistry", void 0);
    __decorate([
        mobx_1.computed,
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [Object])
    ], VariableInstance.prototype, "value", null);
    __decorate([
        mobx_1.computed,
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [])
    ], VariableInstance.prototype, "isEditable", null);
    VariableInstance = __decorate([
        container_1.provideStore(stores_1.default.VARIABLE_INSTANCE),
        __metadata("design:paramtypes", [Object, metadata_2.VariableMetadata, String])
    ], VariableInstance);
    return VariableInstance;
}());
exports.default = VariableInstance;
//# sourceMappingURL=variableInstance.js.map