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

Retoca componente Browser

Integra extensión para comunicarse con el nuevo componente
SelectionManager desde Browser.

Renombra extensión de integración con Selector (antiguo) correspondiente
al componente Row, para diferenciarlo del de Browser.

Ajusta lógica de entrada de datos y mejora la actualización de elementos
ya existentes, sin necesidad de volver a mostrar componentes Row ya
presentes en Browser.
parent 1ddaf255
Loading
Loading
Loading
Loading
+3 −12
Original line number Diff line number Diff line
@@ -364,15 +364,6 @@ define([
			this._rows[idProperty] = this._merge([this._rows[idProperty] || {}, obj || {}]);
		},

		_setRowData: function(idProperty, data) {

			if (!this._isIdProperty(idProperty) || !this._rows[idProperty]) {
				return;
			}

			this._rows[idProperty].data = data;
		},

		_mergeRowData: function(idProperty, data) {

			if (!this._isIdProperty(idProperty) || !this._rows[idProperty]) {
@@ -444,16 +435,16 @@ define([

		_parserIndexData: function(response) {

			const data = response.data?.data || response.data;
			const data = response.data?.data ?? response.data;

			return data.content || data;
			return data.content ?? data.body ?? data;
		},

		_processNewData: function(response) {

			const data = this._parserIndexData(response);

			data?.forEach((dataItem, index) => {
			data?.forEach?.((dataItem, index) => {

				if (!dataItem[this.idProperty]) {
					dataItem[this.idProperty] = index + 1;
+22 −14
Original line number Diff line number Diff line
@@ -95,34 +95,42 @@ define([

			this._rescueOldInstance(item);

			var idProperty = this._getItemIdProperty(item),
				rowInstance = this._addOrUpdateRow(item),
				obj = {
					node: this.rowsContainerNode
				};
			const idProperty = this._getItemIdProperty(item),
				rowInstance = this._addOrUpdateRow(item);

			obj.data = this._getRowData(idProperty);
			if (!rowInstance) {
				return;
			}

			const rowData = this._merge([this._getRowData(idProperty), item]);

			if (this.insertInFront) {
				obj.inFront = true;
			if (rowInstance._getShown()) {
				this._publish(rowInstance.getChannel('UPDATE_DATA'), {
					data: rowData
				});
				return;
			}

			rowInstance && this._publish(rowInstance.getChannel('SHOW'), obj);
			const showProps = {
				node: this.rowsContainerNode,
				data: rowData,
				inFront: !!this.insertInFront
			};

			this._publish(rowInstance.getChannel('SHOW'), showProps);
		},

		_addOrUpdateRow: function(item) {

			var idProperty = this._getItemIdProperty(item),
				rowInstance = this._getRowInstance(idProperty);
			const idProperty = this._getItemIdProperty(item);

			let rowInstance = this._getRowInstance(idProperty);
			if (!rowInstance) {
				this._addRow(idProperty, item);
				rowInstance = this._getRowInstance(idProperty);
			} else {
				item = this._mergeRowData(idProperty, item);

				this._publish(rowInstance.getChannel('UPDATE_TEMPLATE'), {
					template: this._getTemplate(item)
					template: this._getTemplate(this._mergeRowData(idProperty, item))
				});
			}

+187 −0
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "src/component/base/_SelectionManager"
	, 'src/component/browser/row/_BrowserRowSelect'
], function(
	declare
	, lang
	, aspect
	, _SelectionManager
	, _BrowserRowSelect
) {

	return declare(_SelectionManager, {
		// summary:
		//   Base de selección para componente Browser, adaptando la base común de selección a este componente.

		postMixInProperties: function() {

			const defaultConfig = {
				events: {
					CLEAR_SELECTION_ROWS: "clearSelectionRows",
					SELECT_ALL_ROWS: "SelectAllRows",
					SELECTED_ROW: "selectedRow",
					DESELECTED_ROW: "deselectedRow"
				},
				actions: {
					SELECTED_ROW: "selectedRow",
					DESELECTED_ROW: "deselectedRow",
					SELECT_ROW: "selectRow",
					DESELECT_ROW: "deselectRow",
					CLEAR_SELECTION_ROWS: "clearSelectionRows",
					SELECT_ALL_ROWS: "SelectAllRows"
				}
			};

			this._mergeOwnAttributes(defaultConfig);

			this.inherited(arguments);

			aspect.after(this, "_setConfigurations", lang.hitch(this, this._setSelectConfigurations));
			aspect.before(this, "_mixEventsAndActions", lang.hitch(this, this._mixSelectEventsAndActions));

			aspect.after(this, "_definitionRow", lang.hitch(this, this._definitionSelectRow));
		},

		_setSelectConfigurations: function() {

			this.rowConfig = this._merge([{
				simpleSelection: this.simpleSelection
			}, this.rowConfig || {}]);
		},

		_mixSelectEventsAndActions: function () {

			lang.mixin(this.events, this.selectEvents);
			lang.mixin(this.actions, this.selectActions);

			delete this.selectEvents;
			delete this.selectActions;
		},

		_defineSubscriptions: function () {

			this.inherited(arguments);

			this.subscriptionsConfig.push({
				channel : this.getChannel("SELECT_ROW"),
				callback: "_subSelectRow"
			},{
				channel : this.getChannel("DESELECT_ROW"),
				callback: "_subDeselectRow"
			});
		},

		_definePublications: function() {

			this.inherited(arguments);

			this.publicationsConfig.push({
				event: 'SELECTED_ROW',
				channel: this.getChannel("SELECTED_ROW")
			},{
				event: 'DESELECTED_ROW',
				channel: this.getChannel("DESELECTED_ROW")
			},{
				event: 'SELECT_ALL_ROWS',
				channel: this.getChannel("SELECT_ALL_ROWS")
			},{
				event: 'CLEAR_SELECTION_ROWS',
				channel: this.getChannel("CLEAR_SELECTION_ROWS")
			});
		},

		_subSelectRow: function(req) {

			const itemId = req.idProperty,
				item = req.item,
				target = this._getSelectionTarget(),
				selectEvent = this.simpleSelection ? 'SELECT_SINGLE_ITEM' : 'SELECT_ITEM';

			console.log('sele', selectEvent, {itemId, item, target})
			this._emitEvt(selectEvent, {itemId, item, target});
		},

		_subDeselectRow: function(req) {

			const itemId = req.idProperty,
				item = req.item,
				target = this._getSelectionTarget();

			console.log('desele', {itemId, item, target})
			this._emitEvt('DESELECT_ITEM', {itemId, item, target});
		},

		_onItemSelected: function(res) {

			const itemId = res?.itemId;
			this._selectRow(itemId);
		},

		_selectRow: function(idProperty) {

			if (!this._isIdProperty(idProperty)) {
				return;
			}

			// TODO tiene sentido? hacerlo antes que el SELECT de row? replantear
			this._emitEvt('SELECTED_ROW', {
				idProperty
			});

			const rowInstance = this._getRowInstance(idProperty);

			if (!rowInstance) {
				return;
			}

			this._publish(rowInstance.getChannel('SELECT'));
		},

		_deselectRow: function(idProperty) {

			if (!this._isIdProperty(idProperty)) {
				return;
			}

			// TODO tiene sentido? hacerlo antes que el DESELECT de row? replantear
			this._emitEvt('DESELECTED_ROW', {
				idProperty
			});

			const rowInstance = this._getRowInstance(idProperty);

			if (!rowInstance) {
				return;
			}

			this._publish(rowInstance.getChannel('DESELECT'));
		},

		_onItemDeselected: function(res) {

			const itemId = res?.itemId;
			this._deselectRow(itemId);
		},

		_onSelectionCleared: function() {

			this._emitEvt('CLEAR_SELECTION_ROWS');
		},

		_definitionSelectRow: function() {

			this._defRow.push(_BrowserRowSelect);
		},

		_addRow: function(itemId) {

			this.inherited(arguments);

			const target = this._getSelectionTarget();
			//this._emitEvt('GET_SELECTION', {target, itemId});
		}
	});
});
+4 −6
Original line number Diff line number Diff line
@@ -11,13 +11,11 @@ define([

		_addData: function(response) {

			if (!response?.data?.features) {
				this.inherited(arguments);
			}

			if (response?.data?.features) {
				// TODO evitar sobreescribir respuesta, en su lugar adaptar su lectura donde haga falta
				response.data.data = response.data.features;
				//delete response.data.features;
			}

			this.inherited(arguments);
		},
+3 −3
Original line number Diff line number Diff line
@@ -3,13 +3,13 @@ define([
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "src/component/base/_Selection"
	, "./row/_Select"
	, 'src/component/browser/row/_BrowserRowSelect'
], function(
	declare
	, lang
	, aspect
	, _Selection
	, _SelectRow
	, _BrowserRowSelect
) {

	return declare(_Selection, {
@@ -184,7 +184,7 @@ define([

		_definitionSelectRow: function() {

			this._defRow.push(_SelectRow);
			this._defRow.push(_BrowserRowSelect);
		},

		_getSelections: function() {
Loading