bitfront-library
Version:
Angular CLI project with components and classes used by other Angular projects of the BIT foundation.
227 lines • 13.6 kB
JavaScript
;
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.BitDropDownComponent = exports.CUSTOM_DROPDOWN_CONTROL_VALUE_ACCESSOR = void 0;
var core_1 = require("@angular/core");
var forms_1 = require("@angular/forms");
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_dropdown_general_component_1 = require("./bit-dropdown-general.component");
var i0 = require("@angular/core");
var i1 = require("@angular/router");
var i2 = require("../../service/session-shared.service");
var i3 = require("../../service/ayuda.service");
var i4 = require("@angular/common");
var i5 = require("primeng/dropdown");
var i6 = require("@angular/forms");
var i7 = require("primeng/api");
var i8 = require("../bit-control-messages.component");
function BitDropDownComponent_label_0_span_3_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelement(0, "span", 4);
} }
function BitDropDownComponent_label_0_i_5_Template(rf, ctx) { if (rf & 1) {
var _r6 = i0.ɵɵgetCurrentView();
i0.ɵɵelementStart(0, "i", 5);
i0.ɵɵlistener("click", function BitDropDownComponent_label_0_i_5_Template_i_click_0_listener() { i0.ɵɵrestoreView(_r6); var ctx_r5 = i0.ɵɵnextContext(2); return ctx_r5.showAyuda(); });
i0.ɵɵelementEnd();
} }
function BitDropDownComponent_label_0_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelementStart(0, "label");
i0.ɵɵprojection(1);
i0.ɵɵtext(2, "\u00A0 ");
i0.ɵɵtemplate(3, BitDropDownComponent_label_0_span_3_Template, 1, 0, "span", 2);
i0.ɵɵtext(4, "\u00A0\u00A0 ");
i0.ɵɵtemplate(5, BitDropDownComponent_label_0_i_5_Template, 1, 0, "i", 3);
i0.ɵɵelementEnd();
} if (rf & 2) {
var ctx_r0 = i0.ɵɵnextContext();
i0.ɵɵadvance(3);
i0.ɵɵproperty("ngIf", ctx_r0.obligatorio);
i0.ɵɵadvance(2);
i0.ɵɵproperty("ngIf", ctx_r0.ayuda);
} }
function BitDropDownComponent_p_1_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelementStart(0, "p", 6);
i0.ɵɵtext(1);
i0.ɵɵelementEnd();
} if (rf & 2) {
var ctx_r1 = i0.ɵɵnextContext();
i0.ɵɵproperty("id", ctx_r1.nombre);
i0.ɵɵadvance(1);
i0.ɵɵtextInterpolate(ctx_r1.value_lectura);
} }
var _c0 = function (a0) { return { "opcion-desactivada": a0 }; };
function BitDropDownComponent_div_2_ng_template_2_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelementStart(0, "span", 10);
i0.ɵɵtext(1);
i0.ɵɵelementEnd();
} if (rf & 2) {
var item_r9 = ctx.$implicit;
i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(2, _c0, item_r9.inactivo));
i0.ɵɵadvance(1);
i0.ɵɵtextInterpolate(item_r9.label);
} }
function BitDropDownComponent_div_2_control_messages_3_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelement(0, "control-messages", 11);
} if (rf & 2) {
var ctx_r8 = i0.ɵɵnextContext(2);
i0.ɵɵproperty("control", ctx_r8.control)("field", ctx_r8.id);
} }
function BitDropDownComponent_div_2_Template(rf, ctx) { if (rf & 1) {
var _r11 = i0.ɵɵgetCurrentView();
i0.ɵɵelementStart(0, "div");
i0.ɵɵelementStart(1, "p-dropdown", 7);
i0.ɵɵlistener("ngModelChange", function BitDropDownComponent_div_2_Template_p_dropdown_ngModelChange_1_listener($event) { i0.ɵɵrestoreView(_r11); var ctx_r10 = i0.ɵɵnextContext(); return ctx_r10.value = $event; })("onFocus", function BitDropDownComponent_div_2_Template_p_dropdown_onFocus_1_listener() { i0.ɵɵrestoreView(_r11); var ctx_r12 = i0.ɵɵnextContext(); return ctx_r12.onFocus(); })("onBlur", function BitDropDownComponent_div_2_Template_p_dropdown_onBlur_1_listener() { i0.ɵɵrestoreView(_r11); var ctx_r13 = i0.ɵɵnextContext(); return ctx_r13.onBlur(); });
i0.ɵɵtemplate(2, BitDropDownComponent_div_2_ng_template_2_Template, 2, 4, "ng-template", 8);
i0.ɵɵelementEnd();
i0.ɵɵtemplate(3, BitDropDownComponent_div_2_control_messages_3_Template, 1, 2, "control-messages", 9);
i0.ɵɵelementEnd();
} if (rf & 2) {
var ctx_r2 = i0.ɵɵnextContext();
i0.ɵɵadvance(1);
i0.ɵɵpropertyInterpolate("id", ctx_r2.nombre);
i0.ɵɵproperty("ngModel", ctx_r2.value)("options", ctx_r2.listaOpcionesVisible)("filter", ctx_r2.filter)("autoWidth", ctx_r2.autoWidth);
i0.ɵɵadvance(2);
i0.ɵɵproperty("ngIf", ctx_r2.control != null);
} }
var _c1 = ["*"];
exports.CUSTOM_DROPDOWN_CONTROL_VALUE_ACCESSOR = {
provide: forms_1.NG_VALUE_ACCESSOR,
useExisting: core_1.forwardRef(function () { return BitDropDownComponent; }),
multi: true
};
/**
* Clase que utiliza un custom componente para select de elementos
* Utiliza la interfaz ControlValueAccessor
* <bit-select [domain]="'DOMAIN_TIPO_LOG'" id="tipolog" [control]="formControl"> 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 BitDropDownComponent = /** @class */ (function (_super) {
__extends(BitDropDownComponent, _super);
function BitDropDownComponent(router, sessionShared, ayudaService, changeDetectorRef) {
var _this = _super.call(this, router, sessionShared, ayudaService, changeDetectorRef) || this;
_this.router = router;
_this.sessionShared = sessionShared;
_this.ayudaService = ayudaService;
_this.changeDetectorRef = changeDetectorRef;
_this.filter = false;
_this.emptyText = "Qualsevol"; //valor por defecto seleccionable como primer elemento
_this.includeEmpty = true;
_this.listaOpcionesVisible = [];
return _this;
}
/** Si se dan las condiciones, transforma el valor de number a string (o viceversa). */
BitDropDownComponent.prototype.transformValue = function () {
if (this.control.value !== this.valorActual) {
// si es necesario, realizamos la transformación y aplicamos el nuevo valor
if (this.valueAs === "string" && typeof this.control.value !== "string") {
this.valorActual = this.control.value || this.control.value === 0 ? "" + this.control.value : null;
this.control.setValue(this.valorActual, { emitEvent: false });
}
else if (this.valueAs === "number" && typeof this.control.value !== "number") {
this.valorActual = this.control.value ? +this.control.value : null;
this.control.setValue(this.valorActual, { emitEvent: false });
}
}
};
BitDropDownComponent.prototype.ngOnChanges = function (changes) {
var hayCambios = false;
for (var propName in changes) {
var changedProp = changes[propName];
if (propName === "data") {
this.listaOpciones = changedProp.currentValue ? changedProp.currentValue.slice() : [];
hayCambios = true;
}
else if (propName === "dominio") {
this.domain = changedProp.currentValue;
// TODO: recargar dominio por si es distinto?
}
else if (propName === "excludedValues") {
this.excludedValues = changedProp.currentValue;
hayCambios = true;
}
else if (propName === "includeEmpty") {
this.includeEmpty = changedProp.currentValue;
hayCambios = true;
}
}
if (hayCambios) {
this.postRetrieveData();
}
};
// custom processing after retrieving data array from service
BitDropDownComponent.prototype.postRetrieveData = function () {
var _this = this;
if (this.listaOpciones) {
this.listaOpcionesVisible = Object.assign([], this.listaOpciones);
if (this.includeEmpty) {
// determinamos si debemos incluir la opción "sin selección" y con qué texto
this.listaOpcionesVisible.splice(0, 0, { value: null, label: this.emptyText });
}
// repasamos si hay opciones a excluir que debamos eliminar
if (this.excludedValues) {
this.listaOpcionesVisible = this.listaOpcionesVisible.filter(function (op) { return _this.excludedValues.indexOf(op.value) < 0; });
}
}
};
Object.defineProperty(BitDropDownComponent.prototype, "value_lectura", {
get: function () {
var val = this.value;
var dom = this.listaOpciones && this.listaOpciones.find(function (d) { return d.value == val; });
return dom ? dom.label : null;
},
enumerable: false,
configurable: true
});
BitDropDownComponent.ɵfac = function BitDropDownComponent_Factory(t) { return new (t || BitDropDownComponent)(i0.ɵɵdirectiveInject(i1.ActivatedRoute), i0.ɵɵdirectiveInject(i2.SessionSharedService), i0.ɵɵdirectiveInject(i3.AyudaService), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); };
BitDropDownComponent.ɵcmp = i0.ɵɵdefineComponent({ type: BitDropDownComponent, selectors: [["bit-dropdown"]], inputs: { filter: "filter", excludedValues: "excludedValues", autoWidth: "autoWidth", emptyText: "emptyText", includeEmpty: "includeEmpty" }, features: [i0.ɵɵProvidersFeature([exports.CUSTOM_DROPDOWN_CONTROL_VALUE_ACCESSOR]), i0.ɵɵInheritDefinitionFeature, i0.ɵɵNgOnChangesFeature], ngContentSelectors: _c1, decls: 3, vars: 3, consts: [[4, "ngIf"], ["class", "lectura", 3, "id", 4, "ngIf"], ["class", "obligatorio fa fa-asterisk", 4, "ngIf"], ["class", "btn-ayuda fa fa-question", 3, "click", 4, "ngIf"], [1, "obligatorio", "fa", "fa-asterisk"], [1, "btn-ayuda", "fa", "fa-question", 3, "click"], [1, "lectura", 3, "id"], [3, "id", "ngModel", "options", "filter", "autoWidth", "ngModelChange", "onFocus", "onBlur"], ["pTemplate", "item"], [3, "control", "field", 4, "ngIf"], [3, "ngClass"], [3, "control", "field"]], template: function BitDropDownComponent_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵprojectionDef();
i0.ɵɵtemplate(0, BitDropDownComponent_label_0_Template, 6, 2, "label", 0);
i0.ɵɵtemplate(1, BitDropDownComponent_p_1_Template, 2, 2, "p", 1);
i0.ɵɵtemplate(2, BitDropDownComponent_div_2_Template, 4, 6, "div", 0);
} if (rf & 2) {
i0.ɵɵproperty("ngIf", !ctx.hideLabel);
i0.ɵɵadvance(1);
i0.ɵɵproperty("ngIf", ctx.readOnly);
i0.ɵɵadvance(1);
i0.ɵɵproperty("ngIf", !ctx.readOnly);
} }, directives: [i4.NgIf, i5.Dropdown, i6.NgControlStatus, i6.NgModel, i7.PrimeTemplate, i4.NgClass, i8.BitControlMessages], encapsulation: 2 });
return BitDropDownComponent;
}(bit_dropdown_general_component_1.BitDropDownGeneralComponent));
exports.BitDropDownComponent = BitDropDownComponent;
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BitDropDownComponent, [{
type: core_1.Component,
args: [{
selector: "bit-dropdown",
template: "\n <label *ngIf=\"!hideLabel\">\n <ng-content></ng-content> \n <span *ngIf=\"obligatorio\" class=\"obligatorio fa fa-asterisk\"></span> \n <i *ngIf=\"ayuda\" (click)=\"showAyuda()\" class=\"btn-ayuda fa fa-question\"></i>\n </label>\n <p *ngIf=\"readOnly\" class=\"lectura\" [id]=\"nombre\">{{value_lectura}}</p>\n <div *ngIf=\"!readOnly\">\n <p-dropdown \n id=\"{{nombre}}\" \n [(ngModel)]=\"value\"\n [options]=\"listaOpcionesVisible\" \n [filter]=\"filter\"\n [autoWidth]=\"autoWidth\"\n (onFocus)=\"onFocus()\" \n (onBlur)=\"onBlur()\">\n <ng-template let-item pTemplate=\"item\">\n <span [ngClass]=\"{'opcion-desactivada': item.inactivo}\">{{item.label}}</span>\n </ng-template>\n </p-dropdown>\n <control-messages *ngIf=\"control!=null\" [control]=\"control\" [field]=\"id\"></control-messages>\n </div>\n ",
providers: [exports.CUSTOM_DROPDOWN_CONTROL_VALUE_ACCESSOR]
}]
}], function () { return [{ type: i1.ActivatedRoute }, { type: i2.SessionSharedService }, { type: i3.AyudaService }, { type: i0.ChangeDetectorRef }]; }, { filter: [{
type: core_1.Input
}], excludedValues: [{
type: core_1.Input
}], autoWidth: [{
type: core_1.Input
}], emptyText: [{
type: core_1.Input
}], includeEmpty: [{
type: core_1.Input
}] }); })();
//# sourceMappingURL=bit-dropdown.component.js.map