bitfront-library
Version:
Angular CLI project with components and classes used by other Angular projects of the BIT foundation.
349 lines • 17.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitFooterComponent = void 0;
var core_1 = require("@angular/core");
var paginator_1 = require("primeng/paginator");
var rxjs_1 = require("rxjs");
var global_constants_1 = require("../global.constants");
var base_filter_1 = require("../../base/shared/base.filter");
var i0 = require("@angular/core");
var i1 = require("@angular/common");
var i2 = require("./bit-help.component");
var i3 = require("primeng/paginator");
var _c0 = ["pc"];
var _c1 = function (a0, a1, a2, a3) { return [a0, a1, a2, a3]; };
function BitFooterComponent_ul_2_li_7_Template(rf, ctx) { if (rf & 1) {
var _r9 = i0.ɵɵgetCurrentView();
i0.ɵɵelementStart(0, "li");
i0.ɵɵelementStart(1, "p-paginator", 7, 8);
i0.ɵɵlistener("onPageChange", function BitFooterComponent_ul_2_li_7_Template_p_paginator_onPageChange_1_listener($event) { i0.ɵɵrestoreView(_r9); var ctx_r8 = i0.ɵɵnextContext(2); return ctx_r8.paginate($event); });
i0.ɵɵelementEnd();
i0.ɵɵelementEnd();
} if (rf & 2) {
var ctx_r6 = i0.ɵɵnextContext(2);
i0.ɵɵadvance(1);
i0.ɵɵproperty("rows", ctx_r6.itemsPerPage)("totalRecords", ctx_r6.totalItems)("pageLinkSize", ctx_r6.pageLinkSize)("rowsPerPageOptions", i0.ɵɵpureFunction4(4, _c1, ctx_r6.baseItemsPerPage, ctx_r6.baseItemsPerPage * 5, ctx_r6.baseItemsPerPage * 25, ctx_r6.baseItemsPerPage * 50));
} }
function BitFooterComponent_ul_2_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelementStart(0, "ul", 4);
i0.ɵɵelementStart(1, "li");
i0.ɵɵelementStart(2, "label");
i0.ɵɵtext(3, "\u00A0\u00A0\u00A0\u00A0Nombre de resultats:");
i0.ɵɵelementEnd();
i0.ɵɵelementEnd();
i0.ɵɵelementStart(4, "li", 5);
i0.ɵɵelementStart(5, "span");
i0.ɵɵtext(6);
i0.ɵɵelementEnd();
i0.ɵɵelementEnd();
i0.ɵɵtemplate(7, BitFooterComponent_ul_2_li_7_Template, 3, 9, "li", 6);
i0.ɵɵelementEnd();
} if (rf & 2) {
var ctx_r0 = i0.ɵɵnextContext();
i0.ɵɵproperty("hidden", ctx_r0.emptyResult);
i0.ɵɵadvance(6);
i0.ɵɵtextInterpolate(ctx_r0.totalItems);
i0.ɵɵadvance(1);
i0.ɵɵproperty("ngIf", ctx_r0.paginator);
} }
function BitFooterComponent_span_5_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelementStart(0, "span", 9);
i0.ɵɵelement(1, "i", 10);
i0.ɵɵtext(2);
i0.ɵɵelementEnd();
} if (rf & 2) {
var ctx_r1 = i0.ɵɵnextContext();
i0.ɵɵadvance(2);
i0.ɵɵtextInterpolate(ctx_r1.initMessage);
} }
function BitFooterComponent_span_6_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelementStart(0, "span", 9);
i0.ɵɵtext(1);
i0.ɵɵelementEnd();
} if (rf & 2) {
var ctx_r2 = i0.ɵɵnextContext();
i0.ɵɵadvance(1);
i0.ɵɵtextInterpolate(ctx_r2.searchingMessage);
} }
function BitFooterComponent_span_7_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelementStart(0, "span", 9);
i0.ɵɵtext(1);
i0.ɵɵelementEnd();
} if (rf & 2) {
var ctx_r3 = i0.ɵɵnextContext();
i0.ɵɵadvance(1);
i0.ɵɵtextInterpolate(ctx_r3.readOnlyMessage);
} }
function BitFooterComponent_span_8_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelementStart(0, "span", 11);
i0.ɵɵelement(1, "i", 12);
i0.ɵɵtext(2);
i0.ɵɵelementEnd();
} if (rf & 2) {
var ctx_r4 = i0.ɵɵnextContext();
i0.ɵɵadvance(2);
i0.ɵɵtextInterpolate(ctx_r4.finishMessage);
} }
function BitFooterComponent_span_9_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelementStart(0, "span", 11);
i0.ɵɵelement(1, "i", 12);
i0.ɵɵtext(2, "S'ha produ\u00EFt un error");
i0.ɵɵelementEnd();
} }
/**
* Componenente que muestra un paginador en la sección footer.
**/
var BitFooterComponent = /** @class */ (function () {
function BitFooterComponent() {
this.mostrarAvisos = true;
this.fixed = true; //indicará si lo queremos fijo abajo en la página. Por defecto sí.
this.itemsPerPage = base_filter_1.BaseFilter.RESULTADOS_PAGE; // número de elementos por página que mostramos
this.onPageChange = new core_1.EventEmitter(); //para notificar cambios en la página a mostrar
this.onNewPageSize = new core_1.EventEmitter(); //para notificar cambios en los elementos a mostrar por página
this.baseItemsPerPage = base_filter_1.BaseFilter.RESULTADOS_PAGE; // guardamos el número de resultados preconfigurados por página para mostrar la lista de x, x+10 y x+20
}
BitFooterComponent.prototype.ngOnInit = function () {
if (this.typeFooter == undefined) {
this.typeFooter = "list";
}
if (this.paginator == undefined) {
this.paginator = false;
} //mensajes por defecto si no vienen definidos
if (this.messages == undefined && this.typeFooter === BitFooterComponent.TYPE_LIST) {
this.messages = new Map();
this.messages.set(global_constants_1.PageStatus.Init, "Introdueixi els criteris de cerca i premi 'Cerca'");
this.messages.set(global_constants_1.PageStatus.Searching, "Cercant...");
this.messages.set(global_constants_1.PageStatus.FinishSearch, "No s'ha trobat cap dada amb les dades introduïdes");
}
else if (this.messages == undefined && this.typeFooter === BitFooterComponent.TYPE_FORM) {
this.messages = new Map();
this.messages.set(global_constants_1.PageStatus.Init, "Premi el botó Desa per actualitzar les dades");
this.messages.set(global_constants_1.PageStatus.Searching, "Enviant la sol·licitud...");
this.messages.set(global_constants_1.PageStatus.FinishSearch, "Dades actualitzades satisfactòriament");
}
else if (this.messages == undefined && this.typeFooter === BitFooterComponent.TYPE_BLANK) {
console.log("the footer is BLANK!");
this.messages = new Map();
}
};
/**
* Cuando tengamos la referncia al componente paginator nos suscribimos al observable para recibir la notificación
* de que se ha realizado una autobúsqueda con una página y/o resultados por página diferente al estándar
*/
BitFooterComponent.prototype.ngAfterViewInit = function () {
var _this = this;
this.autoQueryObs &&
this.autoQueryObs.subscribe(function (filter) {
if (_this.pc) {
_this.itemsPerPage = filter.resultados;
_this.pc.rows = filter.resultados;
_this.pc._first = (filter.pagina - 1) * _this.pc.rows;
_this.pc.updatePageLinks();
}
});
};
/**
* Escucharemos a cambios en las propiedades totalItems para actualizar el paginador con respecto a las páginas que mostramos
*/
BitFooterComponent.prototype.ngOnChanges = function (changes) {
var log = [];
for (var propName in changes) {
var changedProp = changes[propName];
if (propName === "totalItems") {
this.totalItems = changedProp.currentValue;
changedProp.previousValue !== changedProp.currentValue ? this.calculatePageLinkSize() : undefined; //recalculamos
}
}
};
/** Calcula el número de enlaces visibles en el paginador (en el rango entre 1 y 20). */
BitFooterComponent.prototype.calculatePageLinkSize = function () {
this.pageLinkSize = Math.ceil(this.totalItems / this.itemsPerPage);
if (this.pageLinkSize < 1) {
this.pageLinkSize = 1;
}
if (this.pageLinkSize > 20) {
this.pageLinkSize = 20;
}
};
/** Establece el número de página en la visualización de resultados. Se invoca cuando el usuario cambia el número de resultados a mostrar o cambia de página */
BitFooterComponent.prototype.paginate = function (event) {
console.log("Page changed to", event.page);
if (event.rows !== this.itemsPerPage) {
// han cambiado el número de elementos por página
//notificamos que los elementos por pagina han cambiado
this.onNewPageSize.emit(event.rows);
this.itemsPerPage = event.rows;
this.calculatePageLinkSize(); // recalculamos el número de enlaces de página
}
else {
//notificamos a nuestro papa que la página ha cambiado
this.onPageChange.emit(event.page + 1);
}
};
BitFooterComponent.prototype.getStyle = function () {
if (this.fixed) {
return "footer navbar-fixed-bottom";
}
else {
return "footer";
}
};
Object.defineProperty(BitFooterComponent.prototype, "searchInitiated", {
/** Flag: la página está realizando la búsqueda. */
get: function () {
return this.status === global_constants_1.PageStatus.Init;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BitFooterComponent.prototype, "searching", {
/** Flag: la página está realizando la búsqueda. */
get: function () {
return this.status === global_constants_1.PageStatus.Searching;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BitFooterComponent.prototype, "searchFinished", {
/** Flag: la página ha finalizado la última búsqueda. */
get: function () {
return this.status === global_constants_1.PageStatus.FinishSearch;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BitFooterComponent.prototype, "readOnly", {
/** Flag: la página está en modo solo lectura */
get: function () {
return this.status == global_constants_1.PageStatus.ReadOnly;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BitFooterComponent.prototype, "error", {
/** Flag: la página ha finalizado con error */
get: function () {
return this.status == global_constants_1.PageStatus.Error;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BitFooterComponent.prototype, "foundResult", {
/** Flag: encontrado resultado. */
get: function () {
return this.totalItems > 0;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BitFooterComponent.prototype, "emptyResult", {
/** Flag: no hay resultados. */
get: function () {
return this.totalItems === 0;
},
enumerable: false,
configurable: true
});
Object.defineProperty(BitFooterComponent.prototype, "initMessage", {
get: function () {
return this.messages.get(global_constants_1.PageStatus.Init);
},
enumerable: false,
configurable: true
});
Object.defineProperty(BitFooterComponent.prototype, "searchingMessage", {
get: function () {
return this.messages.get(global_constants_1.PageStatus.Searching);
},
enumerable: false,
configurable: true
});
Object.defineProperty(BitFooterComponent.prototype, "finishMessage", {
get: function () {
return this.messages.get(global_constants_1.PageStatus.FinishSearch);
},
enumerable: false,
configurable: true
});
Object.defineProperty(BitFooterComponent.prototype, "readOnlyMessage", {
get: function () {
return this.messages.get(global_constants_1.PageStatus.ReadOnly);
},
enumerable: false,
configurable: true
});
BitFooterComponent.TYPE_LIST = "list";
BitFooterComponent.TYPE_FORM = "form";
BitFooterComponent.TYPE_BLANK = "blank";
BitFooterComponent.ɵfac = function BitFooterComponent_Factory(t) { return new (t || BitFooterComponent)(); };
BitFooterComponent.ɵcmp = i0.ɵɵdefineComponent({ type: BitFooterComponent, selectors: [["bit-footer"]], viewQuery: function BitFooterComponent_Query(rf, ctx) { if (rf & 1) {
i0.ɵɵviewQuery(_c0, 1);
} if (rf & 2) {
var _t = void 0;
i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.pc = _t.first);
} }, inputs: { autoQueryObs: "autoQueryObs", totalItems: "totalItems", paginator: "paginator", mostrarAvisos: "mostrarAvisos", fixed: "fixed", status: "status", typeFooter: ["type", "typeFooter"], messages: "messages" }, outputs: { onPageChange: "onPageChange", onNewPageSize: "onNewPageSize" }, features: [i0.ɵɵNgOnChangesFeature], decls: 11, vars: 8, consts: [["class", "paginas", 3, "hidden", 4, "ngIf"], [1, "navbar-right"], ["class", "mensaje mensaje-informacion", 4, "ngIf"], ["class", "mensaje mensaje-error", 4, "ngIf"], [1, "paginas", 3, "hidden"], [1, "valor"], [4, "ngIf"], [3, "rows", "totalRecords", "pageLinkSize", "rowsPerPageOptions", "onPageChange"], ["pc", ""], [1, "mensaje", "mensaje-informacion"], [1, "glyphicon", "glyphicon-info-sign"], [1, "mensaje", "mensaje-error"], [1, "glyphicon", "glyphicon-alert"]], template: function BitFooterComponent_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelementStart(0, "footer");
i0.ɵɵelementStart(1, "div");
i0.ɵɵtemplate(2, BitFooterComponent_ul_2_Template, 8, 3, "ul", 0);
i0.ɵɵelementStart(3, "ul", 1);
i0.ɵɵelementStart(4, "li");
i0.ɵɵtemplate(5, BitFooterComponent_span_5_Template, 3, 1, "span", 2);
i0.ɵɵtemplate(6, BitFooterComponent_span_6_Template, 2, 1, "span", 2);
i0.ɵɵtemplate(7, BitFooterComponent_span_7_Template, 2, 1, "span", 2);
i0.ɵɵtemplate(8, BitFooterComponent_span_8_Template, 3, 1, "span", 3);
i0.ɵɵtemplate(9, BitFooterComponent_span_9_Template, 3, 0, "span", 3);
i0.ɵɵelement(10, "bit-help");
i0.ɵɵelementEnd();
i0.ɵɵelementEnd();
i0.ɵɵelementEnd();
i0.ɵɵelementEnd();
} if (rf & 2) {
i0.ɵɵclassMap(ctx.getStyle());
i0.ɵɵadvance(2);
i0.ɵɵproperty("ngIf", ctx.typeFooter === "list");
i0.ɵɵadvance(3);
i0.ɵɵproperty("ngIf", ctx.searchInitiated);
i0.ɵɵadvance(1);
i0.ɵɵproperty("ngIf", ctx.searching);
i0.ɵɵadvance(1);
i0.ɵɵproperty("ngIf", ctx.readOnly);
i0.ɵɵadvance(1);
i0.ɵɵproperty("ngIf", !ctx.searching && ctx.searchFinished && ctx.emptyResult);
i0.ɵɵadvance(1);
i0.ɵɵproperty("ngIf", ctx.error);
} }, directives: [i1.NgIf, i2.BitHelpComponent, i3.Paginator], encapsulation: 2 });
return BitFooterComponent;
}());
exports.BitFooterComponent = BitFooterComponent;
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BitFooterComponent, [{
type: core_1.Component,
args: [{
selector: "bit-footer",
template: "\n <footer [class]=\"getStyle()\">\n <div>\n <ul *ngIf=\"typeFooter === 'list'\" [hidden]=\"emptyResult\" class=\"paginas\">\n <li><label> Nombre de resultats:</label></li>\n <li class=\"valor\">\n <span>{{ totalItems }}</span>\n </li>\n <li *ngIf=\"paginator\">\n <!-- Hay un bug con pageLinkSize. Pese a recalcularlo bien cuando se selecciona otra ventana de resultados. El componenten no lo actualiza hasta cambiar de p\u00E1gina-->\n <p-paginator\n #pc\n [rows]=\"itemsPerPage\"\n [totalRecords]=\"totalItems\"\n [pageLinkSize]=\"pageLinkSize\"\n [rowsPerPageOptions]=\"[\n baseItemsPerPage,\n baseItemsPerPage * 5,\n baseItemsPerPage * 25,\n baseItemsPerPage * 50\n ]\"\n (onPageChange)=\"paginate($event)\"\n ></p-paginator>\n </li>\n </ul>\n <ul class=\"navbar-right\">\n <li>\n <span class=\"mensaje mensaje-informacion\" *ngIf=\"searchInitiated\"\n ><i class=\"glyphicon glyphicon-info-sign\"></i>{{ initMessage }}</span\n >\n <span class=\"mensaje mensaje-informacion\" *ngIf=\"searching\">{{ searchingMessage }}</span>\n <span class=\"mensaje mensaje-informacion\" *ngIf=\"readOnly\">{{ readOnlyMessage }}</span>\n <span class=\"mensaje mensaje-error\" *ngIf=\"!searching && searchFinished && emptyResult\"\n ><i class=\"glyphicon glyphicon-alert\"></i>{{ finishMessage }}</span\n >\n <span class=\"mensaje mensaje-error\" *ngIf=\"error\"\n ><i class=\"glyphicon glyphicon-alert\"></i>S'ha produ\u00EFt un error</span\n >\n <bit-help></bit-help>\n </li>\n </ul>\n </div>\n </footer>\n "
}]
}], null, { pc: [{
type: core_1.ViewChild,
args: ["pc"]
}], autoQueryObs: [{
type: core_1.Input
}], totalItems: [{
type: core_1.Input
}], paginator: [{
type: core_1.Input
}], mostrarAvisos: [{
type: core_1.Input
}], fixed: [{
type: core_1.Input
}], status: [{
type: core_1.Input
}], typeFooter: [{
type: core_1.Input,
args: ["type"]
}], messages: [{
type: core_1.Input
}], onPageChange: [{
type: core_1.Output
}], onNewPageSize: [{
type: core_1.Output
}] }); })();
//# sourceMappingURL=bit-footer.component.js.map