UNPKG

nakedobjects.spa

Version:

Single Page Application client for a Naked Objects application.

89 lines 4.16 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 __()); }; })(); 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); }; import * as Models from './models'; import { Injectable } from '@angular/core'; import { ContextService } from './context.service'; import { TypeResultCache } from './type-result-cache'; import { ConfigService } from './config.service'; import forEach from 'lodash/forEach'; var ColorService = (function (_super) { __extends(ColorService, _super); function ColorService(context, configService) { var _this = _super.call(this, context) || this; _this.configService = configService; _this.toColorNumberFromHref = function (href) { var type = _this.typeFromUrl(href); return _this.toColorNumberFromType(type); }; _this.toColorNumberFromType = function (type) { return _this.getResult(type); }; _super.prototype.setDefault.call(_this, 0); _this.configureFromConfig(); return _this; } ColorService.prototype.typeFromUrl = function (url) { var oid = Models.ObjectIdWrapper.fromHref(url, this.configService.config.keySeparator); return oid.domainType; }; ColorService.prototype.addType = function (type, result) { _super.prototype.addType.call(this, type, result); }; ColorService.prototype.addMatch = function (matcher, result) { _super.prototype.addMatch.call(this, matcher, result); }; ColorService.prototype.addSubtype = function (type, result) { _super.prototype.addSubtype.call(this, type, result); }; ColorService.prototype.setDefault = function (def) { _super.prototype.setDefault.call(this, def); }; ColorService.prototype.getDefault = function () { return this.default; }; ColorService.prototype.configureFromConfig = function () { var _this = this; var colorConfig = this.configService.config.colors; if (colorConfig) { var typeMap = colorConfig.typeMap; var subtypeMap = colorConfig.subtypeMap; var regexArray = colorConfig.regexArray; var dflt = colorConfig.default; if (typeMap) { forEach(typeMap, function (v, k) { return _this.addType(k, v); }); } if (regexArray) { forEach(regexArray, function (item) { return _this.addMatch(new RegExp(item.regex), item.color); }); } if (subtypeMap) { forEach(subtypeMap, function (v, k) { return _this.addSubtype(k, v); }); } if (dflt != null) { this.setDefault(dflt); } } }; return ColorService; }(TypeResultCache)); ColorService = __decorate([ Injectable(), __metadata("design:paramtypes", [ContextService, ConfigService]) ], ColorService); export { ColorService }; //# sourceMappingURL=color.service.js.map