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

Elimina widget ContainerFacets

Se integra con el cliente web, por lo que se elimina implementación y
tests.
parent 4d503732
Loading
Loading
Loading
Loading

src/app/ContainerFacets.js

deleted100644 → 0
+0 −170
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dijit/_WidgetBase"
	, "dojo/_base/lang"
	, "dojo/Evented"
	, "./Facet"
], function(
	declare
	, _WidgetBase
	, lang
	, Evented
	, Facet
) {

	return declare([_WidgetBase, Evented], {

		"class": "containerFacets",

		constructor: function(args){

			this.config = {
				maxInitialEntries: 5,
				aggs: null,
				openFacets: false,
				order: null,
				instance: {},
				i18n: null,
				events: {
					CONFIG_CHANGED: "configChanged",
					UPDATE_QUERY: "updateQuery",
					UPDATE_CONSULT: "updateConsult"
				}
			};

			lang.mixin(this, this.config, args);

			this.on(this.events.CONFIG_CHANGED, this._render);

			this.query = {};
		},

		postCreate: function() {

			this.domNode.removeAttribute('widgetId');

			this.inherited(arguments);
		},

		setConfig: function(config) {

			this.config = config;
			this.emit(this.events.CONFIG_CHANGED, config);
		},

		setI18n: function(i18n) {

			this.i18n = i18n;
		},

		_render: function() {

			if (Object.keys(this.instance).length !== 0) {
				for (var item in this.instance) {
					this.instance[item].termSelection = this.instance[item].widget.termSelection;
				}
			}

			this._cleanChildrenNode();

			for (var i = 0; i < this.order.length; i++) {
				this._renderItem(this.order[i]);
			}
		},

		_renderItem: function(item) {

			var facetsPrefix = 'sterms#',
				content = this.config.aggregations[item],
				open;

			if (!content) {
				return;
			}

			if (!content.buckets) {
				content = content[item] || content[facetsPrefix + item];
			}

			if (this.instance && this.instance[item] && (this.instance[item].termSelection.length != 0)) {
				open = true;
			} else if (this.aggs && this.aggs[item] && this.aggs[item].open) {
				open = this.aggs[item].open;
			} else {
				open = this.openFacets;
			}

			var widget = new Facet({
				termSelection: (this.instance && this.instance[item]) ? this.instance[item].termSelection : [],
				label: item,
				termsFieldFacet: (this.aggs && this.aggs[item]) ? this.aggs[item].terms.field : item,
				title: (this.i18n && this.i18n[item]) ? this.i18n[item] : item,
				i18n: this.i18n,
				open: open,
				config: content,
				maxInitialEntries: this.maxInitialEntries
			}).placeAt(this.domNode);

			this.instance[item] = {
				widget: widget,
				termSelection: []
			};

			if (widget.termSelection.length != 0) {
				widget.emit(widget.events.TERMS_CHANGED);
			}

			widget.on(this.events.UPDATE_QUERY, lang.hitch(this, this.updateQuery));
		},

		_cleanChildrenNode: function() {

			while (this.domNode.firstChild) {
				this.domNode.removeChild(this.domNode.firstChild);
			}
		},

		updateQuery: function(queryTerm, title) {

			queryTerm ? this.add(title, queryTerm) : this.remove(title);

			this.emit(this.events.UPDATE_CONSULT, this.query);
		},

		add: function(title, queryTerm) {

			this.query[title] = queryTerm;
		},

		remove: function(title) {

			delete this.query[title];
		},

		setPrefixFieldFacet: function(/*String*/ prefixFieldFacet) {

			this.prefixFieldFacet = prefixFieldFacet;
		},

		setSuffixFieldFacet: function(/*String*/ suffixFieldFacet) {

			this.suffixFieldFacet = suffixFieldFacet;
		},

		setFieldFacets: function(/*json*/ fieldFacet) {

			this.fieldFacet = fieldFacet;
		},

		setOrder: function(/*json*/ order) {

			this.order = order;
		},

		setAggs: function(/*json*/ aggs) {

			this.aggs = aggs;
			this.setOrder(Object.keys(aggs));
		}
	});
});
+0 −37
Original line number Diff line number Diff line
<html>
	<head>
		<meta charset="utf-8">
		<title>Test Container Facets</title>
		<link rel='stylesheet' type"text/css" href="../../../src/stylesheets/style.css">
	</head>
	<body class="db">
		<div id="grid" class="grid">
		</div>
		<script src="../../../src/dojoConfig.js"></script>
		<script src="../../../src/dojo/dojo.js"></script>
		<script>
			require([
			    'dojo/dom',
			    'dojo/fx',
			    "app/ContainerFacets",
			    'dojo/domReady!'
			], function (dom, fx, ContainerFacets) {

				var config = {"took":8,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":7417,"max_score":0.0,"hits":[]},"aggregations":{"endemicity":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"Desconocida","doc_count":6539},{"key":"Canaria","doc_count":88},{"key":"Otra","doc_count":78},{"key":"Atlántica","doc_count":43},{"key":"Macaronésica","doc_count":1}]},"interest":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"Uso ornamental","doc_count":6539},{"key":"Especie peligrosa","doc_count":88},{"key":"Otro","doc_count":78},{"key":"Uso industrial","doc_count":43},{"key":"Interés pesquero","doc_count":1}]},"ecology":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"Otro","doc_count":3620},{"key":"Desconocida","doc_count":2958},{"key":"Béntica","doc_count":131},{"key":"Pelágica","doc_count":29},{"key":"Demersal","doc_count":11}]}}},

					config2 = {"took":8,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":7417,"max_score":0.0,"hits":[]},"aggregations":{"endemicity":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"Desconocida","doc_count":6539},{"key":"Canaria","doc_count":88},{"key":"Otra","doc_count":78},{"key":"Atlántica","doc_count":43},{"key":"Macaronésica","doc_count":1}]},"interest":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"Uso ornamental","doc_count":6539},{"key":"Especie peligrosa","doc_count":88},{"key":"Otro","doc_count":78},{"key":"Uso industrial","doc_count":43},{"key":"Interés pesquero","doc_count":1}]}}},

					widget = new ContainerFacets({openFacets: true});

				widget.setConfig(config);

				var node = dom.byId('grid');

				widget.placeAt(node, 'last');

				//widget.setConfig(config2);

			});
		</script>
	</body>
</html>
 No newline at end of file
+0 −26
Original line number Diff line number Diff line
define([
	'intern!object'
	, 'intern/chai!assert'
	, 'require'
], function (
	registerSuite
	, assert
	, require
) {

	registerSuite({
		name: 'Test container facets',

		"label click and checkBox checked": function() {
			return this.remote
				.get(require.toUrl('./testContainerFacets.html'))
					.setFindTimeout(5000)
					.findByCssSelector("div[data-redmic-id='endemicity'] > div label").click().end()
					.findByCssSelector("div input[data-redmic-id='Desconocida']").getProperty('checked').then(
						function (checked) {
							assert.strictEqual(checked, true, 'Debería ser igual, true los dos');
						}
				).end();
		}
	});
});
 No newline at end of file

tests/app/testContainerFacets.js

deleted100644 → 0
+0 −111
Original line number Diff line number Diff line
define([
	"intern!object"
	, "intern/chai!assert"
	, "app/ContainerFacets"
	, "dojo/on"
], function(
		registerSuite
		, assert
		, ContainerFacets
		, on
){
		registerSuite({

			name: "Container Facets Test",

			"Comprueba la funcion add": function(){
				widget = new ContainerFacets();

				widget.add("endemicity", {"endemicity": ["canaria"]});

				assert.strictEqual(Object.keys(widget.query).length, 1);

				var result = {"endemicity":["canaria"]};
				assert.strictEqual(widget.query["endemicity"].key, result.key);
				assert.strictEqual(widget.query["endemicity"].value, result.value);
			},

			"Comprueba la funcion remove": function(){
				widget = new ContainerFacets();

				widget.add("endemicity", {"endemicity": ["canaria"]});

				widget.remove("endemicity");

				assert.strictEqual(Object.keys(widget.query).length, 0);
			},

			"Comprueba que la funcion updateQuery añada": function(){
				widget = new ContainerFacets();
				var inEvent = false;

				on(widget, widget.events.UPDATECONSULT, function(queryTerm) {
					inEvent = true;
				});

				widget.updateQuery({"endemicity": ["canaria"]}, "endemicity");
				assert.strictEqual(Object.keys(widget.query).length, 1);

				var result = {"endemicity": ["canaria"]};
				assert.strictEqual(widget.query["endemicity"].key, result.key);
				assert.strictEqual(widget.query["endemicity"].value, result.value);
				assert.isTrue(inEvent, "Deberia ser true");
			},

			"Comprueba que la funcion updateQuery elimine": function(){
				widget = new ContainerFacets();
				var inEvent = false;
				on(widget, widget.events.UPDATECONSULT, function(queryTerm) {
					inEvent = true;
				});

				widget.updateQuery({"endemicity": ["canaria"]}, "endemicity");

				widget.updateQuery(null, "endemicity");
				widget.remove("endemicity");

				assert.strictEqual(Object.keys(widget.query).length, 0);
				assert.isTrue(inEvent, "Deberia ser true");
			},

			"Comprueba que la funcion updateQuery actualice uno": function(){
				widget = new ContainerFacets();
				var inEvent = false;
				on(widget, widget.events.UPDATECONSULT, function(queryTerm) {
					inEvent = true;
				});

				widget.updateQuery({"endemicity": ["canaria"]}, "endemicity");

				var result = {"endemicity": ["canaria"]};
				assert.strictEqual(widget.query["endemicity"].key, result.key);
				assert.strictEqual(widget.query["endemicity"].value, result.value);
				assert.isTrue(inEvent, "Deberia ser true");

				inEvent = false;
				widget.updateQuery({"endemicity": ["dos"], "coche": ['rojo']}, "endemicity");

				result = {"endemicity": ["dos"], "coche": ['rojo']}
				assert.strictEqual(Object.keys(widget.query).length, 1);
				assert.strictEqual(Object.keys(widget.query["endemicity"]).length, 2);
				assert.strictEqual(widget.query["endemicity"]['endemicity'].key, result['endemicity'].key);
				assert.strictEqual(widget.query["endemicity"]['endemicity'].value, result['endemicity'].value);
				assert.strictEqual(widget.query["endemicity"]['coche'].key, result['coche'].key);
				assert.strictEqual(widget.query["endemicity"]['coche'].value, result['coche'].value);
				assert.isTrue(inEvent, "Deberia ser true");
			},

			"Construccion correcta del widget": function() {
				config = {"took":8,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":7417,"max_score":0.0,"hits":[]},"aggregations":{"endemicity":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"Desconocida","doc_count":6539},{"key":"Canaria","doc_count":88},{"key":"Otra","doc_count":78},{"key":"Atlántica","doc_count":43},{"key":"Macaronésica","doc_count":1}]},"interest":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"Uso ornamental","doc_count":6539},{"key":"Especie peligrosa","doc_count":88},{"key":"Otro","doc_count":78},{"key":"Uso industrial","doc_count":43},{"key":"Interés pesquero","doc_count":1}]},"ecology":{"doc_count_error_upper_bound":0,"sum_other_doc_count":0,"buckets":[{"key":"Otro","doc_count":3620},{"key":"Desconocida","doc_count":2958},{"key":"Béntica","doc_count":131},{"key":"Pelágica","doc_count":29},{"key":"Demersal","doc_count":11}]}}}

				widget = new ContainerFacets({
					order: ["endemicity", "interest", "ecology"]
				});

				widget.setConfig(config);

				assert.strictEqual(widget.config, config, 'Debería ser igual la configuracion en ambos');
			}

		});
});
 No newline at end of file