UNPKG

bitfront-library

Version:

Angular CLI project with components and classes used by other Angular projects of the BIT foundation.

124 lines 7 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.BitDropDownGeneralComponent = void 0; var core_1 = require("@angular/core"); var router_1 = require("@angular/router"); var ayuda_service_1 = require("../../service/ayuda.service"); var session_shared_service_1 = require("../../service/session-shared.service"); var bit_custom_component_1 = require("./bit-custom.component"); var i0 = require("@angular/core"); var i1 = require("@angular/router"); var i2 = require("../../service/session-shared.service"); var i3 = require("../../service/ayuda.service"); /** * Clase que utiliza un custom componente para select de elementos * Utiliza la interfaz ControlValueAccessor * <bit-select [domain]="'DOMAIN_TIPO_LOG'" id="tipolog" [control]="formControl">&nbsp;&nbsp;Tipus d'operació</bit-select> * * @input data: array de objetos a mostrar en el select. Puede ser null, en cuyo caso domain no puede ser null * @input domain: nombre del dominio que contiene los datos y que nos resolverá la página cuando cargue el componente. Puede ser null, en cuyo caso data no puede ser null * @input id: identificador del componente select * @input filter: true indicará que podemos buscar dentro del select, false que no. **/ var BitDropDownGeneralComponent = /** @class */ (function (_super) { __extends(BitDropDownGeneralComponent, _super); function BitDropDownGeneralComponent(router, sessionShared, ayudaService, changeDetectorRef) { var _this = _super.call(this, ayudaService, changeDetectorRef) || this; _this.router = router; _this.sessionShared = sessionShared; _this.ayudaService = ayudaService; _this.changeDetectorRef = changeDetectorRef; _this.hideLabel = false; // forzar no reservar espacio para el nombre del campo _this.listaOpciones = []; _this.listaOpcionesVisible = []; return _this; } /** Si se dan las condiciones, transforma los valores de number a string (o viceversa). */ BitDropDownGeneralComponent.prototype.transformValue = function () { if (this.control.value !== this.valorActual) { if (!this.control.value || this.control.value.length === 0) { this.valorActual = this.control.value; } // si es necesario, realizamos la transformación y aplicamos el nuevo valor else if (this.valueAs === "string" && typeof this.control.value[0] !== "string") { this.valorActual = this.control.value.map(String); this.control.setValue(this.valorActual, { emitEvent: false }); } else if (this.valueAs === "number" && typeof this.control.value[0] !== "number") { this.valorActual = this.control.value.map(Number); this.control.setValue(this.valorActual, { emitEvent: false }); } } }; BitDropDownGeneralComponent.prototype.ngOnInit = function () { var _this = this; _super.prototype.ngOnInit.call(this); if (this.data == null && this.domain != null) { //esta manera retornaría los datos alojados en el snapshot pero no tendríamos refresco en el caso de producirse //this.tiposLog = this.getTiposLogFromDomain(this.route.snapshot.data[TipoLog.DOMAIN_TIPO_LOG]);//this.route.data.pluck(TipoLog.DOMAIN_TIPO_LOG); //esta manera nos permite subscribirnos a los datos de data con lo que si hay refresco nos enteramos this.router.data.subscribe(function (result) { var dominios = result["dominios"]; var domainTipo = dominios[_this.domain]; if (domainTipo != null) { domainTipo.subscribe(function (result) { //console.log(result); _this.sessionShared.set(_this.domain, result.slice()); // almacenamos en sesión una copia para evitar transmitir cambios _this.listaOpciones = result.slice(); _this.postRetrieveData(); }, function (error) { _this.listaOpciones = [{ value: null, label: "Error carrega dominis" }]; }); } else { console.log("No hay datos para el dominio", _this.domain); _this.listaOpciones = [{ value: null, label: "Error carrega dominis" }]; } }); } else if (this.data) { // incluso si la lista de valores ha sido proporcionada, // hay que añadir algunos comportamientos posteriores this.listaOpciones = this.data.slice(); this.postRetrieveData(); } //console.log("Componente inicializado"); }; BitDropDownGeneralComponent.prototype.onBlur = function () { this.onTouchedCallback(); }; BitDropDownGeneralComponent.prototype.onFocus = function () { this.onTouchedCallback(); }; BitDropDownGeneralComponent.ɵfac = function BitDropDownGeneralComponent_Factory(t) { return new (t || BitDropDownGeneralComponent)(i0.ɵɵdirectiveInject(i1.ActivatedRoute), i0.ɵɵdirectiveInject(i2.SessionSharedService), i0.ɵɵdirectiveInject(i3.AyudaService), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); }; BitDropDownGeneralComponent.ɵdir = i0.ɵɵdefineDirective({ type: BitDropDownGeneralComponent, inputs: { hideLabel: "hideLabel", data: "data", domain: "domain", valueAs: "valueAs", id: "id" }, features: [i0.ɵɵInheritDefinitionFeature] }); return BitDropDownGeneralComponent; }(bit_custom_component_1.BitCustomComponent)); exports.BitDropDownGeneralComponent = BitDropDownGeneralComponent; (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BitDropDownGeneralComponent, [{ type: core_1.Directive }], function () { return [{ type: i1.ActivatedRoute }, { type: i2.SessionSharedService }, { type: i3.AyudaService }, { type: i0.ChangeDetectorRef }]; }, { hideLabel: [{ type: core_1.Input }], data: [{ type: core_1.Input }], domain: [{ type: core_1.Input }], valueAs: [{ type: core_1.Input }], id: [{ type: core_1.Input }] }); })(); //# sourceMappingURL=bit-dropdown-general.component.js.map