lib/Models/AbsIttCatalogItem.js
function loadDataFiles(item) {
  // An array of arrays, indexed by activeItemsPerConcept[conceptIndex][codeIndex].
  var activeCodesPerConcept = item._concepts.map(function(concept) {
    return concept.activeItems;
  });

  // If any one of the concepts has no active selection, there will be no files to load.
  for (var i = activeCodesPerConcept.length - 1; i >= 0; i--) {
    if (activeCodesPerConcept[i].length === 0) {
      return when();
    }
  }

  // If there is no valid region selected (including when there are two!), stop.
  if (!defined(getActiveRegionTypeCode(item))) {
    return when();
  }

  // Find every possible combination, taking a single code from each concept.
  var activeCombinations = arrayProduct(activeCodesPerConcept);

  // Construct the 'and' part of the requests by combining concept.id and the AbsCode.name,
  // eg. and=REGIONTYPE.SA4,AGE.A04,MEASURE.3
  var andParameters = activeCombinations.map(function(codes) {
    return codes
      .map(function(code, index) {
        return code.concept.id + "." + code.code;
      })
      .join(",");
  });

  var loadDataPromises = andParameters.map(function(andParameter) {
    // Build a promise which resolves once this datafile has loaded (unless we have cached this promise already).
    // Note in the original there was different cacheing stuff... but not sure if it was being used?
    if (!defined(item._loadDataFilePromise[andParameter])) {
      var parameters = {
        method: "GetGenericData",
        datasetid: item.datasetId,
        and: andParameter,
        or: item.regionConcept,
        format: "csv"
      };
      var url = item._baseUrl + "?" + objectToQuery(parameters);
      item._loadDataFilePromise[andParameter] = loadText(url).then(
        loadTableStructure.bind(undefined, item)
      );
    }
    return item._loadDataFilePromise[andParameter];
  });

  var totalPopulationsUrl =
    item.regionPopulationsUrlPrefix + getActiveRegionTypeCode(item) + ".csv";
  loadDataPromises.push(
    loadText(totalPopulationsUrl).then(loadTableStructure.bind(undefined, item))
  );

  return when.all(loadDataPromises).then(function(tableStructures) {
    return {
      tableStructures: tableStructures,
      activeCombinations: activeCombinations
    };
  });
}
function loadDataFiles(item) {
  // An array of arrays, indexed by activeItemsPerConcept[conceptIndex][codeIndex].
  var activeCodesPerConcept = item._concepts.map(function(concept) {
    return concept.activeItems;
  });

  // If any one of the concepts has no active selection, there will be no files to load.
  for (var i = activeCodesPerConcept.length - 1; i >= 0; i--) {
    if (activeCodesPerConcept[i].length === 0) {
      return when();
    }
  }

  // If there is no valid region selected (including when there are two!), stop.
  if (!defined(getActiveRegionTypeCode(item))) {
    return when();
  }

  // Find every possible combination, taking a single code from each concept.
  var activeCombinations = arrayProduct(activeCodesPerConcept);

  // Construct the 'and' part of the requests by combining concept.id and the AbsCode.name,
  // eg. and=REGIONTYPE.SA4,AGE.A04,MEASURE.3
  var andParameters = activeCombinations.map(function(codes) {
    return codes
      .map(function(code, index) {
        return code.concept.id + "." + code.code;
      })
      .join(",");
  });

  var loadDataPromises = andParameters.map(function(andParameter) {
    // Build a promise which resolves once this datafile has loaded (unless we have cached this promise already).
    // Note in the original there was different cacheing stuff... but not sure if it was being used?
    if (!defined(item._loadDataFilePromise[andParameter])) {
      var parameters = {
        method: "GetGenericData",
        datasetid: item.datasetId,
        and: andParameter,
        or: item.regionConcept,
        format: "csv"
      };
      var url = item._baseUrl + "?" + objectToQuery(parameters);
      item._loadDataFilePromise[andParameter] = loadText(url).then(
        loadTableStructure.bind(undefined, item)
      );
    }
    return item._loadDataFilePromise[andParameter];
  });

  var totalPopulationsUrl =
    item.regionPopulationsUrlPrefix + getActiveRegionTypeCode(item) + ".csv";
  loadDataPromises.push(
    loadText(totalPopulationsUrl).then(loadTableStructure.bind(undefined, item))
  );

  return when.all(loadDataPromises).then(function(tableStructures) {
    return {
      tableStructures: tableStructures,
      activeCombinations: activeCombinations
    };
  });
}
function loadDataFiles ( item ) { // An array of arrays, indexed by activeItemsPerConcept[conceptIndex][codeIndex]. var activeCodesPerConcept = item . _concepts . map ( function ( concept ) { return concept . activeItems ; } ) ; // If any one of the concepts has no active selection, there will be no files to load. for ( var i = activeCodesPerConcept . length - 1 ; i >= 0 ; i -- ) { if ( activeCodesPerConcept [ i ] . length === 0 ) { return when ( ) ; } } // If there is no valid region selected (including when there are two!), stop. if ( ! defined ( getActiveRegionTypeCode ( item ) ) ) { return when ( ) ; } // Find every possible combination, taking a single code from each concept. var activeCombinations = arrayProduct ( activeCodesPerConcept ) ; // Construct the 'and' part of the requests by combining concept.id and the AbsCode.name, // eg. and=REGIONTYPE.SA4,AGE.A04,MEASURE.3 var andParameters = activeCombinations . map ( function ( codes ) { return codes . map ( function ( code , index ) { return code . concept . id + "." + code . code ; } ) . join ( "," ) ; } ) ; var loadDataPromises = andParameters . map ( function ( andParameter ) { // Build a promise which resolves once this datafile has loaded (unless we have cached this promise already). // Note in the original there was different cacheing stuff... but not sure if it was being used? if ( ! defined ( item . _loadDataFilePromise [ andParameter ] ) ) { var parameters = { method : "GetGenericData" , datasetid : item . datasetId , and : andParameter , or : item . regionConcept , format : "csv" } ; var url = item . _baseUrl + "?" + objectToQuery ( parameters ) ; item . _loadDataFilePromise [ andParameter ] = loadText ( url ) . then ( loadTableStructure . bind ( undefined , item ) ) ; } return item . _loadDataFilePromise [ andParameter ] ; } ) ; var totalPopulationsUrl = item . regionPopulationsUrlPrefix + getActiveRegionTypeCode ( item ) + ".csv" ; loadDataPromises . push ( loadText ( totalPopulationsUrl ) . then ( loadTableStructure . bind ( undefined , item ) ) ) ; return when . all ( loadDataPromises ) . then ( function ( tableStructures ) { return { tableStructures : tableStructures , activeCombinations : activeCombinations } ; } ) ; }
Loads all the datafiles for this catalog item, given the active concepts.
@private
@param  {AbsIttCatalogItem} item The AbsIttCatalogItem instance.
@return {Promise} A Promise which resolves to an object of TableStructures for each loaded dataset,
with the total populations as the final one; and the active combinations.
Loads all the datafiles for this catalog item given the active concepts .