Commit 49b333f8 authored by CarlosGC1989's avatar CarlosGC1989
Browse files

Refactoriza implementación de listado

parent 65da4c75
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ module.exports = function(grunt) {
		grunt.config('shell.test-functional-local-parallel', {
			command: function() {

				var serverUrlParam = grunt.option('server-url'),
				var serverUrlParam = grunt.option('server-url') || 'http://redmic.local',
					userParam = grunt.option('user'),
					passParam = grunt.option('pass'),
					serverPort = 9000,
+57 −28
Original line number Diff line number Diff line
@@ -24,20 +24,46 @@ define([

		_addData: function(response) {

			var rowsOld = this._rows,
				data = response.data;
			this._clearRowsData();

			this._proccesNewData(response);

			this._clearOldRowsData();
		},

		_clearRowsData: function(response) {

			this._rowsOld = this._rows;
			this._rows = {};
		},

		_clearOldRowsData: function() {

			for (var key in this._rowsOld) {
				this._removeRowInstance(this._rowsOld[key].instance);
			}

			delete this._rowsOld;
		},

		_proccesNewData: function(response) {

			var data = response.data;

			if (data.data) {
				data = data.data;
			}

			this._rows = {};

			for (var i = 0; i < data.length; i++) {
				this._rescueOldInstance(data[i]);
				this._addItem(data[i]);
			}
		},

		_rescueOldInstance: function(item) {

				var item = data[i],
					idProperty = item[this.idProperty];
					row = rowsOld[idProperty];
			var idProperty = item[this.idProperty],
				row = this._rowsOld[idProperty],
				rowInstance = row && row.instance;

			if (rowInstance) {
@@ -46,25 +72,34 @@ define([
					data: item
				});

					delete rowsOld[idProperty];
				if (this._rowsOld) {
					delete this._rowsOld[idProperty];
				}

				this._addItem(item);
			}

			for (var key in rowsOld) {
				this._removeRowInstance(rowsOld[key].instance);
			}
		},

		_addItem: function(item) {

			var idProperty = item[this.idProperty],
				rowInstance = this._getRowInstance(idProperty),
				rowInstance = this._addOrUpdateRow(item),
				obj = {
					node: this.rowsContainerNode
				};

			obj.data = this._getRowData(idProperty);

			if (this.insertInFront) {
				obj.inFront = true;
			}

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

		_addOrUpdateRow: function(item) {

			var idProperty = item[this.idProperty],
				rowInstance = this._getRowInstance(idProperty);

			if (!rowInstance) {
				this._addRow(idProperty, item);
				rowInstance = this._getRowInstance(idProperty);
@@ -76,13 +111,7 @@ define([
				});
			}

			obj.data = this._getRowData(idProperty);

			if (this.insertInFront) {
				obj.inFront = true;
			}

			rowInstance && this._publish(rowInstance.getChannel('SHOW'), obj);
			return rowInstance;
		}
	});
});