UNPKG

bitfront-library

Version:

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

164 lines 8.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BitReadonlyComponent = void 0; var core_1 = require("@angular/core"); var ayuda_service_1 = require("../../service/ayuda.service"); var service_1 = require("../../service"); var router_1 = require("@angular/router"); var i0 = require("@angular/core"); var i1 = require("@angular/router"); var i2 = require("../../service"); var i3 = require("../../service/ayuda.service"); var i4 = require("@angular/common"); function BitReadonlyComponent_label_0_i_3_Template(rf, ctx) { if (rf & 1) { var _r5 = i0.ɵɵgetCurrentView(); i0.ɵɵelementStart(0, "i", 3); i0.ɵɵlistener("click", function BitReadonlyComponent_label_0_i_3_Template_i_click_0_listener() { i0.ɵɵrestoreView(_r5); var ctx_r4 = i0.ɵɵnextContext(2); return ctx_r4.showAyuda(); }); i0.ɵɵelementEnd(); } } function BitReadonlyComponent_label_0_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "label"); i0.ɵɵprojection(1); i0.ɵɵtext(2, "\u00A0\u00A0 "); i0.ɵɵtemplate(3, BitReadonlyComponent_label_0_i_3_Template, 1, 0, "i", 2); i0.ɵɵelementEnd(); } if (rf & 2) { var ctx_r0 = i0.ɵɵnextContext(); i0.ɵɵadvance(3); i0.ɵɵproperty("ngIf", ctx_r0.ayuda); } } function BitReadonlyComponent_p_1_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "p", 4); i0.ɵɵtext(1); i0.ɵɵelementEnd(); } if (rf & 2) { var ctx_r1 = i0.ɵɵnextContext(); i0.ɵɵadvance(1); i0.ɵɵtextInterpolate(ctx_r1.value_lectura); } } function BitReadonlyComponent_pre_2_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "pre", 4); i0.ɵɵtext(1); i0.ɵɵelementEnd(); } if (rf & 2) { var ctx_r2 = i0.ɵɵnextContext(); i0.ɵɵadvance(1); i0.ɵɵtextInterpolate(ctx_r2.value_lectura); } } var _c0 = ["*"]; var BitReadonlyComponent = /** @class */ (function () { function BitReadonlyComponent(router, sessionShared, ayudaService, changeDetectorRef) { this.router = router; this.sessionShared = sessionShared; this.ayudaService = ayudaService; this.changeDetectorRef = changeDetectorRef; this.hideLabel = false; this.opcionesDropdown = []; } BitReadonlyComponent.prototype.ngOnInit = function () { var _this = this; if (!!this.domain && !this.data) { 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.opcionesDropdown = result.slice(); _this.changeDetectorRef.detectChanges(); }, function (error) { console.log("Error carrega dominis", _this.domain, error); }); } else { console.log("Domini sense dades", _this.domain); } }); } else if (this.data) { this.opcionesDropdown = this.data.slice(); } }; BitReadonlyComponent.prototype.ngOnChanges = function (changes) { for (var propName in changes) { if (propName === "data") { var newData = changes[propName].currentValue || []; this.opcionesDropdown = newData.slice(); this.changeDetectorRef.detectChanges(); } } }; BitReadonlyComponent.prototype.showAyuda = function () { this.ayudaService.mostrarAyuda(this.ayuda); }; Object.defineProperty(BitReadonlyComponent.prototype, "value_lectura", { get: function () { var _this = this; this.tipo = this.tipo || "text"; switch (this.tipo) { case "date": return this.valor ? service_1.GeneralUtils.getDateAsString(service_1.GeneralUtils.stringShortToDate(this.valor)) : ""; case "datetime": return this.valor ? service_1.GeneralUtils.getDateTimeAsString(service_1.GeneralUtils.stringToDate(this.valor)) : ""; case "time": return this.valor ? service_1.GeneralUtils.getTimeAsString(service_1.GeneralUtils.stringToTime(this.valor)) : ""; case "boolean": return this.valor ? "Sí" : "No"; case "list": var d = this.opcionesDropdown.find(function (d) { return d.value == _this.valor; }); return d ? d.label : ""; case "list-multiple": var labels = this.opcionesDropdown && this.opcionesDropdown.filter(function (d) { return _this.valor && _this.valor.indexOf(d.value) > -1; }).map(function (d) { return d.label; }); return labels ? labels.join(", ") : null; default: return this.valor; } }, enumerable: false, configurable: true }); Object.defineProperty(BitReadonlyComponent.prototype, "isTextarea", { get: function () { return this.tipo === "textarea"; }, enumerable: false, configurable: true }); BitReadonlyComponent.ɵfac = function BitReadonlyComponent_Factory(t) { return new (t || BitReadonlyComponent)(i0.ɵɵdirectiveInject(i1.ActivatedRoute), i0.ɵɵdirectiveInject(i2.SessionSharedService), i0.ɵɵdirectiveInject(i3.AyudaService), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef)); }; BitReadonlyComponent.ɵcmp = i0.ɵɵdefineComponent({ type: BitReadonlyComponent, selectors: [["bit-readonly"]], inputs: { ayuda: "ayuda", valor: "valor", tipo: "tipo", hideLabel: "hideLabel", data: "data", domain: "domain" }, features: [i0.ɵɵNgOnChangesFeature], ngContentSelectors: _c0, decls: 3, vars: 3, consts: [[4, "ngIf"], ["class", "lectura", 4, "ngIf"], ["class", "btn-ayuda fa fa-question", 3, "click", 4, "ngIf"], [1, "btn-ayuda", "fa", "fa-question", 3, "click"], [1, "lectura"]], template: function BitReadonlyComponent_Template(rf, ctx) { if (rf & 1) { i0.ɵɵprojectionDef(); i0.ɵɵtemplate(0, BitReadonlyComponent_label_0_Template, 4, 1, "label", 0); i0.ɵɵtemplate(1, BitReadonlyComponent_p_1_Template, 2, 1, "p", 1); i0.ɵɵtemplate(2, BitReadonlyComponent_pre_2_Template, 2, 1, "pre", 1); } if (rf & 2) { i0.ɵɵproperty("ngIf", !ctx.hideLabel); i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", !ctx.isTextarea); i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", ctx.isTextarea); } }, directives: [i4.NgIf], encapsulation: 2 }); return BitReadonlyComponent; }()); exports.BitReadonlyComponent = BitReadonlyComponent; (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BitReadonlyComponent, [{ type: core_1.Component, args: [{ selector: "bit-readonly", template: "\n <label *ngIf=\"!hideLabel\">\n <ng-content></ng-content>&nbsp;&nbsp;\n <i *ngIf=\"ayuda\" class=\"btn-ayuda fa fa-question\" (click)=\"showAyuda()\"></i>\n </label>\n <p *ngIf=\"!isTextarea\" class=\"lectura\">{{value_lectura}}</p>\n <pre *ngIf=\"isTextarea\" class=\"lectura\">{{value_lectura}}</pre>\n " }] }], function () { return [{ type: i1.ActivatedRoute }, { type: i2.SessionSharedService }, { type: i3.AyudaService }, { type: i0.ChangeDetectorRef }]; }, { ayuda: [{ type: core_1.Input }], valor: [{ type: core_1.Input }], tipo: [{ type: core_1.Input }], hideLabel: [{ type: core_1.Input }], data: [{ type: core_1.Input }], domain: [{ type: core_1.Input }] }); })(); //# sourceMappingURL=bit-readonly.component.js.map