client/public/src/models/CollectionModel.js
/**
   * @method overview
   * @description Runs basic aggregation queries for facet counts
   * @param {String} id - The type of aggregation to run
   * @param {Object} kwargs - Additional keyword arguments to pass to query
   * 
   * @returns {Promise}
   */
@method overview
@description Runs basic aggregation queries for facet counts
@param {String} id - The type of aggregation to run
@param {Object} kwargs - Additional keyword arguments to pass to query

@returns {Promise}
@method overview @description Runs basic aggregation queries for facet counts @param { String } id - The type of aggregation to run @param { Object } kwargs - Additional keyword arguments to pass to query @returns { Promise }
async overview(id, kwargs={}) {
    let queryObject = QueryUtils.getBaseQueryObject();
    if (id == "facets") {
      queryObject.facets["@type"] = {"type" : "facet"};
      queryObject.limit = 0;
    }
    else if (id == "randomPeople") {
      Object.assign(queryObject.filters, AssetDefs.getMainFacetById('people').baseFilter);
      queryObject.limit = 4;
      if (kwargs.limit) {
        queryObject.limit = kwargs.limit;
      }
      if (kwargs.total) {
        let randomOffset = Math.floor(Math.random() * (kwargs.total - queryObject.limit));
        queryObject.offset = randomOffset;
      }
    }
    else if (id == "randomSubjects") {
      Object.assign(queryObject.filters, AssetDefs.getMainFacetById('concepts').baseFilter);
      queryObject.limit = 10;
      if (kwargs.limit) {
        queryObject.limit = kwargs.limit;
      }
      if (kwargs.total) {
        let randomOffset = Math.floor(Math.random() * (kwargs.total - queryObject.limit));
        queryObject.offset = randomOffset;
      }
    }
    else if (id == "randomGrants") {
      Object.assign(queryObject.filters, AssetDefs.getMainFacetById('grants').baseFilter);
      queryObject.limit = 10;
      if (kwargs.limit) {
        queryObject.limit = kwargs.limit;
      }
      if (kwargs.total) {
        let randomOffset = Math.floor(Math.random() * (kwargs.total - queryObject.limit));
        queryObject.offset = randomOffset;
      }
    }
    else if (id == "peopleAggs") {
      Object.assign(queryObject.filters, AssetDefs.getMainFacetById('people').baseFilter);
      queryObject.limit = 0;
      queryObject.facets["@type"] = {"type" : "facet"};
    }
    else if (id == "worksAggs") {
      Object.assign(queryObject.filters, AssetDefs.getMainFacetById('works').baseFilter);
      if (kwargs.subjectFilter) {
        queryObject.filters[AssetDefs.getAreaField('works')] = QueryUtils.getKeywordFilter(
          QueryUtils.appendIdPrefix(kwargs.subjectFilter)
        );
        id = `${id}?subject=${kwargs.subjectFilter}`;
      }
      queryObject.limit = 0;
      queryObject.facets["@type"] = {"type" : "facet"};
    }
    else if (id == "subjectsAggs") {
      Object.assign(queryObject.filters, AssetDefs.getMainFacetById('concepts').baseFilter);
      queryObject.limit = 0;
      queryObject.facets["@type"] = {"type" : "facet"};
    }
    else if (id == "organizationsAggs") {
      Object.assign(queryObject.filters, AssetDefs.getMainFacetById('organizations').baseFilter);
      queryObject.limit = 0;
      queryObject.facets["@type"] = {"type" : "facet"};
    }
    else if (id == "grantsAggs") {
      Object.assign(queryObject.filters, AssetDefs.getMainFacetById('grants').baseFilter);
      queryObject.limit = 0;
      queryObject.facets["@type"] = {"type" : "facet"};
    }
    let state = this.store.data.overview[id];
    try {
      if( state && state.request ) {
        await state.request;
      } 
      else {
        await this.service.overview(id, queryObject);
      }
    } catch (error) {
    }
    return this.store.data.overview[id];
  }
async overview ( id , kwargs = { } ) { let queryObject = QueryUtils . getBaseQueryObject ( ) ; if ( id == "facets" ) { queryObject . facets [ "@type" ] = { "type" : "facet" } ; queryObject . limit = 0 ; } else if ( id == "randomPeople" ) { Object . assign ( queryObject . filters , AssetDefs . getMainFacetById ( 'people' ) . baseFilter ) ; queryObject . limit = 4 ; if ( kwargs . limit ) { queryObject . limit = kwargs . limit ; } if ( kwargs . total ) { let randomOffset = Math . floor ( Math . random ( ) * ( kwargs . total - queryObject . limit ) ) ; queryObject . offset = randomOffset ; } } else if ( id == "randomSubjects" ) { Object . assign ( queryObject . filters , AssetDefs . getMainFacetById ( 'concepts' ) . baseFilter ) ; queryObject . limit = 10 ; if ( kwargs . limit ) { queryObject . limit = kwargs . limit ; } if ( kwargs . total ) { let randomOffset = Math . floor ( Math . random ( ) * ( kwargs . total - queryObject . limit ) ) ; queryObject . offset = randomOffset ; } } else if ( id == "randomGrants" ) { Object . assign ( queryObject . filters , AssetDefs . getMainFacetById ( 'grants' ) . baseFilter ) ; queryObject . limit = 10 ; if ( kwargs . limit ) { queryObject . limit = kwargs . limit ; } if ( kwargs . total ) { let randomOffset = Math . floor ( Math . random ( ) * ( kwargs . total - queryObject . limit ) ) ; queryObject . offset = randomOffset ; } } else if ( id == "peopleAggs" ) { Object . assign ( queryObject . filters , AssetDefs . getMainFacetById ( 'people' ) . baseFilter ) ; queryObject . limit = 0 ; queryObject . facets [ "@type" ] = { "type" : "facet" } ; } else if ( id == "worksAggs" ) { Object . assign ( queryObject . filters , AssetDefs . getMainFacetById ( 'works' ) . baseFilter ) ; if ( kwargs . subjectFilter ) { queryObject . filters [ AssetDefs . getAreaField ( 'works' ) ] = QueryUtils . getKeywordFilter ( QueryUtils . appendIdPrefix ( kwargs . subjectFilter ) ) ; id = ` ${ id } ${ kwargs . subjectFilter } ` ; } queryObject . limit = 0 ; queryObject . facets [ "@type" ] = { "type" : "facet" } ; } else if ( id == "subjectsAggs" ) { Object . assign ( queryObject . filters , AssetDefs . getMainFacetById ( 'concepts' ) . baseFilter ) ; queryObject . limit = 0 ; queryObject . facets [ "@type" ] = { "type" : "facet" } ; } else if ( id == "organizationsAggs" ) { Object . assign ( queryObject . filters , AssetDefs . getMainFacetById ( 'organizations' ) . baseFilter ) ; queryObject . limit = 0 ; queryObject . facets [ "@type" ] = { "type" : "facet" } ; } else if ( id == "grantsAggs" ) { Object . assign ( queryObject . filters , AssetDefs . getMainFacetById ( 'grants' ) . baseFilter ) ; queryObject . limit = 0 ; queryObject . facets [ "@type" ] = { "type" : "facet" } ; } let state = this . store . data . overview [ id ] ; try { if ( state && state . request ) { await state . request ; } else { await this . service . overview ( id , queryObject ) ; } } catch ( error ) { } return this . store . data . overview [ id ] ; }
@method overview
 @description Runs basic aggregation queries for facet counts
 @param {String} id - The type of aggregation to run
 @param {Object} kwargs - Additional keyword arguments to pass to query
@method overview @description Runs basic aggregation queries for facet counts @param { String } id - The type of aggregation to run @param { Object } kwargs - Additional keyword arguments to pass to query
// error is recorded in store