Repository URL to install this package:
|
Version:
1.1.3 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var bumpMenu_1 = require("./bumpMenu");
var urlSettings_1 = require("./urlSettings");
var utils_1 = require("./utils");
var getBump_1 = require("./utils/getBump");
/**
* Manages all client side session data and provides functions for lookup and
* mutation of that data.
*
* The only client side session data not handled by this class is the session id
* used by the current implementation of the server protocol. Management of
* session id the responsibility of the protocol adaptor.
*
* @struct
* @constructor
* @param {spv.ds.impl.SessionInitData} init_data
*/
var SessionState = /** @class */ (function () {
function SessionState(initData) {
this.categoryId = null;
this.categoryShortTexts = {};
this.categoryMediumTexts = {};
this.categoryLongTexts = {};
this.categoryCampaignText = {};
this.allTexts = {};
this.modelId = null;
this.initData = initData;
}
SessionState.prototype.getAuxiliaryData = function () {
return this.auxData;
};
SessionState.prototype.getBumpSeries = function (bump, modelId) {
var seriesOfModel = [];
for (var _i = 0, _a = bump.series; _i < _a.length; _i++) {
var serie = _a[_i];
if (serie.model_id === modelId) {
seriesOfModel.push(serie);
}
}
if (seriesOfModel.length === 0) {
throw new Error("Could not find image serie for model ID: " + modelId);
}
return seriesOfModel;
};
SessionState.prototype.getCategoryId = function () {
if (!this.categoryId) {
throw new Error('Category ID not set, configuration not loaded');
}
return this.categoryId;
};
SessionState.prototype.getImageSerieInfos = function () {
var bump = getBump_1.default(this.initData, this.getCategoryId());
var modelSeries = this.getBumpSeries(bump, this.getModelId());
return modelSeries.map(utils_1.convertToImageSerieInfo);
};
SessionState.prototype.getModelId = function () {
if (!this.modelId) {
throw new Error('Model ID not set, configuration not loaded');
}
return this.modelId;
};
SessionState.prototype.getRootMenuItems = function () {
var bump = getBump_1.default(this.initData, this.getCategoryId());
return bump.menus.map(function (item) { return new bumpMenu_1.default(item.id, item.name, item.short_text); });
};
SessionState.prototype.getItem = function (itemId) {
var bump = getBump_1.default(this.initData, this.getCategoryId());
var bumpItem = bump.items.find(function (item) { return item.id === itemId; });
if (!bumpItem) {
return null;
}
return {
id: bumpItem.id,
shortText: bumpItem.name,
mediumText: bumpItem.short_text,
longText: bumpItem.information
};
};
SessionState.prototype.getUpdate = function () {
if (!this.stateUpdate) {
throw new Error('State update not set');
}
return this.stateUpdate;
};
SessionState.prototype.getUrlSettings = function () {
var categoryIds = this.initData.bumps.map(function (bump) { return bump.category; });
if (categoryIds.length === 0) {
throw new Error('No categories found in session init data');
}
var bump = getBump_1.default(this.initData, categoryIds[0]);
return new urlSettings_1.default(bump.gui_url, bump.icon_url, bump.composed_url, bump.readmore_content_url, bump.summary_content_url);
};
SessionState.prototype.setCategoryId = function (stateUpdate) {
if (!stateUpdate.category) {
throw new Error("The category ID is invalid");
}
if (this.initData.bumps.map(function (bump) { return bump.category; }).indexOf(stateUpdate.category) === -1) {
throw new Error("The category id is missing in init data: " + stateUpdate.category);
}
this.categoryId = stateUpdate.category;
};
SessionState.prototype.setModelId = function (stateUpdate) {
if (!stateUpdate.modelId) {
throw new Error('The model ID is invalid');
}
this.modelId = stateUpdate.modelId;
};
SessionState.prototype.update = function (stateUpdate, auxData) {
this.setCategoryId(stateUpdate);
this.setModelId(stateUpdate);
this.stateUpdate = stateUpdate;
this.auxData = auxData;
};
SessionState.prototype.assertHasLoadedConfig = function () {
this.getCategoryId();
this.getModelId();
};
return SessionState;
}());
exports.default = SessionState;
//# sourceMappingURL=sessionState.js.map