123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- /**
- * A Utility class that processes Location Data from Query Results data rows. Currently there are
- * mainly two types of locations information, regions and points, corresponding to the regions
- * and points related slots on tiledmap widget.
- *
- * */
- define(['underscore', '../../../../lib/@waca/dashboard-common/dist/query/FacetDataObject'], function (_, FacetData) {
- 'use strict';
- /**
- * @private
- */
- var _instance = null;
- /**
- *@constructor
- */
- var Helper = function Helper() {};
- //return the column indexes for each types of location slots IDs
- Helper.prototype._getGeoDataColumnIndexes = function (fields) {
- if (!fields) {
- return;
- }
- var result = {};
- var aLocationsSlotIDs = ['featureId', 'featureIdRefinement', 'pointId', 'pointIdRefinement'];
- var _fLocationFieldIndex = function _fLocationFieldIndex(slotId, index, result) {
- if (aLocationsSlotIDs.indexOf(slotId) >= 0) {
- result[slotId] = index;
- }
- };
- _.each(fields, function (field, index) {
- _fLocationFieldIndex(field.id, index, result);
- });
- return result;
- };
- /**
- * @param aDataRows {Array} data rows returned from query resutls
- * @param fields {Array} fields inside the query spec
- *
- * @return a JSON object that has location feature IDs and its refinement information.
- * The sample response below shows Bejing, Shanghai are lowest level Feature IDs, while
- * it's refinement location feature is Thailand.
- *
- * {
- "regions": [
- {
- "name": "Thailand",
- "children": ["Bangkok"]
- }, {
- "name": "China",
- "children": [
- "Beijing", "Shanghai"
- ]
- }, {
- "name": "Japan",
- "children": ["Tokyo"]
- }
- ],
- "points": [
- {
- "name": "Alberta",
- "children": ["Calgary"]
- }, {
- "name": "Ontario",
- "children": [
- "Ottawa", "Toronto"
- ]
- }, {
- "name": "Quebec",
- "children": ["Montreal"]
- }
- ]
- }
- * */
- Helper.prototype.getGeoRequestPayload = function (aDataRows, fields) {
- var oGeoColumnIndexes = this._getGeoDataColumnIndexes(fields);
- if (oGeoColumnIndexes.featureId === -1 && oGeoColumnIndexes.pointId === -1) {
- return [];
- }
- var aPointLocations = [];
- var aRegionLocations = [];
- for (var i = 0; i < aDataRows.length; i++) {
- this._addToLocationArray([oGeoColumnIndexes.featureId, oGeoColumnIndexes.featureIdRefinement], aDataRows, i, aRegionLocations);
- this._addToLocationArray([oGeoColumnIndexes.pointId, oGeoColumnIndexes.pointIdRefinement], aDataRows, i, aPointLocations);
- }
- return aRegionLocations;
- };
- Helper.prototype._addToLocationArray = function (aLocationLevelIndexes, aDataRows, rowIndex, aLocations) {
- //TODO: When RAVE2 slots has parental refinement reference, we will pass in the regions
- //and points location IDs array automatically
- var childLocationIndex = aLocationLevelIndexes[0];
- var parentLocationIndex = aLocationLevelIndexes[1];
- var sChildLocationId = new FacetData(aDataRows[rowIndex][childLocationIndex]).displayValue;
- if (parentLocationIndex) {
- var sChildLocationIdRefinement = new FacetData(aDataRows[rowIndex][parentLocationIndex]).displayValue;
- if (sChildLocationIdRefinement && sChildLocationIdRefinement.length > 0) {
- var oDataItem = this.findDataItem(aLocations, sChildLocationIdRefinement);
- if (!oDataItem) {
- oDataItem = { 'name': sChildLocationIdRefinement, 'children': [] };
- aLocations.push(oDataItem);
- }
- if (sChildLocationId && !_.contains(oDataItem.children, sChildLocationId)) {
- oDataItem.children.push({ name: sChildLocationId });
- }
- } else {
- if (sChildLocationId && sChildLocationId.length > 0) {
- aLocations.push({ name: sChildLocationId });
- }
- }
- } else if (sChildLocationId && sChildLocationId.length > 0) {
- aLocations.push({ name: sChildLocationId });
- }
- };
- Helper.prototype.findDataItem = function (aLocations, sFeatureId) {
- return _.find(aLocations, function (location) {
- return location.name === sFeatureId;
- });
- };
- var _singleton = {
- getInstance: function getInstance() {
- if (!_instance) {
- _instance = new Helper();
- }
- return _instance;
- }
- };
- return _singleton.getInstance();
- });
- //# sourceMappingURL=QueryManagerGeoHelper.js.map
|