Commit cb74cbb3 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Compatibiliza paginación y refactoriza

Aplica compatibilidad con los nuevos parámetros de petición en el
componente de barra de paginación.

Refactoriza para reutilizar lógica entre barras de paginación y total.

Aplica barra de paginación a listado de eventos de seguimiento acústico.
parent 7014cf20
Loading
Loading
Loading
Loading
+56 −30
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, 'put-selector'
	, "src/component/base/_Module"
	, "src/component/base/_Show"
	, "src/component/base/_Store"
	, 'src/component/browser/bars/_BarCommons'
], function(
	declare
	, lang
	, aspect
	, put
	, _Module
	, _Show
	, _Store
	, _BarCommons
) {
	return declare([_Module, _Show, _Store], {

	return declare([_Module, _Show, _Store, _BarCommons], {
		//	summary:
		//
		//	description:
		//
		//		Componente que aporta un indicador de página y navegación entre ellas.

		constructor: function(args) {

@@ -56,7 +55,7 @@ define([
				channel : this.getChannel("RESET_PAGINATION"),
				callback: "_subResetPagination"
			},{
				channel: this._buildChannel(this.browserChannel, this.actions.CLEAR),
				channel: this._buildChannel(this.browserChannel, 'CLEAR'),
				callback: "_subClearBrowser"
			});
		},
@@ -128,12 +127,30 @@ define([

			this.inherited(arguments);

			this._once(this._buildChannel(this.queryChannel, this.actions.GOT_PROPS),
			if (this.queryChannel) {
				this._once(this._buildChannel(this.queryChannel, 'GOT_PROPS'),
					lang.hitch(this, this._subModelChannelGotProps));

			this._publish(this._buildChannel(this.queryChannel, this.actions.GET_PROPS), {
				this._publish(this._buildChannel(this.queryChannel, 'GET_PROPS'), {
					modelChannel: true
				});

				return;
			}

			const size = this.rowPerPage,
				page = 0;

			this._emitEvt('ADD_REQUEST_PARAMS', {
				method: 'GET',
				target: this.target,
				params: {
					query: {
						size, page
					},
					sharedParams: true
				}
			});
		},

		_subModelChannelGotProps: function(res) {
@@ -141,7 +158,7 @@ define([
			var modelChannel = res.modelChannel;

			this._setSubscription({
				channel: this._buildChannel(modelChannel, this.actions.VALUE_CHANGED),
				channel: this._buildChannel(modelChannel, 'VALUE_CHANGED'),
				callback: lang.hitch(this, this._subModelValueChanged)
			});
		},
@@ -321,27 +338,33 @@ define([
		_goToPage: function(value) {

			if (this.totalPages && value && value <= this.totalPages && value > 0) {
				this._publishPagination(this._calcRank(value));
				this._publishPagination(value);
			}
		},

		_publishPagination: function(obj) {
		_publishPagination: function(value) {

			if (this.queryChannel) {
				const query = this._calcRank(value);

				this._updateDataByMe = true;

				this._publish(this._buildChannel(this.queryChannel, this.actions.ADD_TO_QUERY), {
					query: obj
				this._publish(this._buildChannel(this.queryChannel, 'ADD_TO_QUERY'), {
					query
				});

				return;
			}

			this._emitPaginationRequest(value);
		},

		_calcRank: function(value) {

			var start = (value - 1) * this.rowPerPage,
				obj = {
					size: this.rowPerPage
					size: this.rowPerPage,
					page: value
				};

			if (start !== undefined && start !== null) {
@@ -351,23 +374,26 @@ define([
			return obj;
		},

		getNodeToShow: function() {
		_emitPaginationRequest: function(value) {

			const page = value - 1,
				size = this.rowPerPage;

			return this.domNode;
			this._emitEvt('REQUEST', {
				method: 'GET',
				target: this.target,
				params: {
					query: {
						page, size
					},
					sharedParams: true
				}
			});
		},

		_dataAvailable: function(response) {

			var data = response.data,
				total = (data.total >= 0) ? data.total : response.total;

			if ((total === undefined || total === null)) {
				if (data.data) {
					total = data.data.total;
				} else {
					total = data.length;
				}
			}
			const total = this._getTotalValueFromResponse(response);

			this._updateDataByMe = false;

+11 −29
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, 'put-selector'
	, "src/component/base/_Module"
	, "src/component/base/_Show"
	, "src/component/base/_Store"
	, 'src/component/browser/bars/_BarCommons'
], function(
	declare
	, lang
	, aspect
	, put
	, _Module
	, _Show
	, _Store
	, _BarCommons
) {
	return declare([_Module, _Show, _Store], {

	return declare([_Module, _Show, _Store, _BarCommons], {
		//	summary:
		//
		//	description:
		//
		//		Componente que aporta un contador del total de elementos disponibles.

		constructor: function(args) {

@@ -45,10 +44,10 @@ define([
				channel: this.getChannel("SET_TOTAL"),
				callback: "_subSetTotal"
			},{
				channel: this._buildChannel(this.browserChannel, this.actions.CLEAR),
				channel: this._buildChannel(this.browserChannel, 'CLEAR'),
				callback: "_subClearBrowser"
			},{
				channel: this._buildChannel(this.browserChannel, this.actions.DATA_REMOVED),
				channel: this._buildChannel(this.browserChannel, 'DATA_REMOVED'),
				callback: "_subDataRemovedBrowser"
			});
		},
@@ -92,35 +91,18 @@ define([
			this._setTotal(this.total - 1);
		},

		getNodeToShow: function() {

			return this.domNode;
		},

		_dataAvailable: function(response) {

			var data = response.data,
				total = (data.total >= 0) ? data.total : response.total;

			if (total === undefined || total === null) {
				if (data.data) {
					total = data.data.total;
				} else if (data.content) {
					total = data.content.length;
				} else {
					total = data.length;
				}
			}

			const total = this._getTotalValueFromResponse(response);
			this._setTotal(total);
		},

		_itemAvailable: function(response) {

			this._once(this._buildChannel(this.browserChannel, this.actions.GOT_DATA),
			this._once(this._buildChannel(this.browserChannel, 'GOT_DATA'),
				lang.hitch(this, this._subBrowserGotData));

			this._publish(this._buildChannel(this.browserChannel, this.actions.GET_DATA));
			this._publish(this._buildChannel(this.browserChannel, 'GET_DATA'));
		},

		_subBrowserGotData: function(req) {
+25 −0
Original line number Diff line number Diff line
define([
	'dojo/_base/declare'
], function(
	declare
) {

	return declare(null, {
		//	summary:
		//		Lógica común a componentes de barra.

		_getTotalValueFromResponse: function(response) {

			const resData = response.data,
				resPage = resData.page;

			let total = resPage?.totalElements ?? resData?.total ?? response.total;

			if (total === undefined || total === null) {
				total = resData?.content?.length ?? resData?.data?.total ?? resData.length;
			}

			return total;
		}
	});
});
+2 −3
Original line number Diff line number Diff line
@@ -19,11 +19,10 @@ define([
			this.inherited(arguments);

			const parentChannel = this.getChannel(),
				target = this._getTarget(),
				queryChannel = this.browserConfig.queryChannel;
				target = this._getTarget();

			this.mergeComponentAttribute('paginationBarConfig', {
				parentChannel, target, queryChannel
				parentChannel, target
			});
		},

+3 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ define([
	, 'src/component/base/_Store'
	, 'src/design/browser/_AddFacetComponent'
	, 'src/design/browser/_AddOrderBarComponent'
	, 'src/design/browser/_AddPaginationBarComponent'
	, 'src/design/browser/_AddTotalBarComponent'
	, 'src/design/browser/_BrowserWithTopbarAndFilterPanelDesignLayout'
	, 'src/redmicConfig'
@@ -22,6 +23,7 @@ define([
	, _Store
	, _AddFacetComponent
	, _AddOrderBarComponent
	, _AddPaginationBarComponent
	, _AddTotalBarComponent
	, _BrowserWithTopbarAndFilterPanelDesignLayout
	, redmicConfig
@@ -31,7 +33,7 @@ define([
) {

	return declare([_Module, _Show, _Store, _BrowserWithTopbarAndFilterPanelDesignLayout, _AddTotalBarComponent,
		_AddOrderBarComponent, _AddFacetComponent], {
		_AddOrderBarComponent, _AddPaginationBarComponent, _AddFacetComponent], {
		//	summary:
		//		Widget para mostrar un listado de las observaciones registradas en el punto seleccionado.