UNPKG

fabric8-planner

Version:
146 lines 5.68 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { Injectable } from '@angular/core'; import { createEntityAdapter } from '@ngrx/entity'; import { createFeatureSelector, createSelector, select, Store } from '@ngrx/store'; import { combineLatest, of as ObservableOf } from 'rxjs'; import { map, startWith } from 'rxjs/operators'; import { modelService, switchModel } from './common.model'; var labelAdapter = createEntityAdapter(); var _a = labelAdapter.getSelectors(), selectIds = _a.selectIds, selectEntities = _a.selectEntities, selectAll = _a.selectAll, selectTotal = _a.selectTotal; var LabelModel = /** @class */ (function (_super) { __extends(LabelModel, _super); function LabelModel() { return _super !== null && _super.apply(this, arguments) || this; } return LabelModel; }(modelService)); export { LabelModel }; var LabelAttributes = /** @class */ (function () { function LabelAttributes() { } return LabelAttributes; }()); export { LabelAttributes }; var LabelLinks = /** @class */ (function () { function LabelLinks() { } return LabelLinks; }()); export { LabelLinks }; var LabelRelationships = /** @class */ (function () { function LabelRelationships() { } return LabelRelationships; }()); export { LabelRelationships }; var LabelMapper = /** @class */ (function () { function LabelMapper() { this.serviceToUiMapTree = [{ fromPath: ['id'], toPath: ['id'] }, { fromPath: ['attributes', 'name'], toPath: ['name'] }, { fromPath: ['attributes', 'background-color'], toPath: ['backgroundColor'] }, { fromPath: ['attributes', 'version'], toPath: ['version'] }, { fromPath: ['attributes', 'border-color'], toPath: ['borderColor'] }, { fromPath: ['attributes', 'text-color'], toPath: ['textColor'] } ]; this.uiToServiceMapTree = [{ fromPath: ['id'], toPath: ['id'] }, { fromPath: ['name'], toPath: ['attributes', 'name'] }, { fromPath: ['backgroundColor'], toPath: ['attributes', 'background-color'] }, { fromPath: ['version'], toPath: ['attributes', 'version'] }, { fromPath: ['borderColor'], toPath: ['attributes', 'border-color'] }, { fromPath: ['textColor'], toPath: ['attributes', 'text-color'] }, { toPath: ['type'], toValue: 'labels' } ]; } LabelMapper.prototype.toUIModel = function (arg) { return switchModel(arg, this.serviceToUiMapTree); }; LabelMapper.prototype.toServiceModel = function (arg) { return switchModel(arg, this.uiToServiceMapTree); }; return LabelMapper; }()); export { LabelMapper }; var LabelQuery = /** @class */ (function () { function LabelQuery(store) { this.store = store; this.plannerSelector = createFeatureSelector('planner'); this.labelSelector = createSelector(this.plannerSelector, function (state) { return state.labels; }); this.getAllLabelsSelector = createSelector(this.labelSelector, selectAll); this.getLabelEntities = createSelector(this.labelSelector, selectEntities); } LabelQuery.prototype.getLables = function () { return this.store.pipe(select(this.getAllLabelsSelector)); }; Object.defineProperty(LabelQuery.prototype, "getlabelNames", { get: function () { return this.getLables().pipe(map(function (labels) { return labels.map(function (label) { return label.name; }); })); }, enumerable: true, configurable: true }); LabelQuery.prototype.getLabelObservableById = function (number) { var labelSelector = createSelector(this.getLabelEntities, function (state) { return state[number]; }); return this.store.pipe(select(labelSelector)); }; LabelQuery.prototype.getLabelObservablesByIds = function (ids) { var _this = this; if (!ids.length) { return ObservableOf([]); } return combineLatest(ids.map(function (id) { return _this.getLabelObservableById(id); })) // TODO RxJS 6 combineLatest should come from rxjs/operators .pipe( // If the label is not available in the state // it comes as undefined so we filter them out map(function (labels) { return labels.filter(function (l) { return !!l; }); }), // In case the combine operation is stuck for any single // observable inside, we start the stream with an empty array startWith([])); }; LabelQuery.decorators = [ { type: Injectable }, ]; /** @nocollapse */ LabelQuery.ctorParameters = function () { return [ { type: Store, }, ]; }; return LabelQuery; }()); export { LabelQuery }; //# sourceMappingURL=label.model.js.map