コード例 #1
0
ファイル: MuiDataTableView.js プロジェクト: cggh/panoptes
MuiDataTableView = withAPIData(MuiDataTableView, ({config, props}) => {

  let {table, columns, order, startRowIndex, query, maxRowsPerPage, joins, onClickComponentTemplateDocPath} = props;

  query = query || (table ? config.tablesById[table].defaultQuery : null) || SQL.nullQuery;

  let stopRowIndex = undefined;
  if (maxRowsPerPage !== undefined && maxRowsPerPage > 0) {
    stopRowIndex = startRowIndex + maxRowsPerPage - 1;
  } else {
    stopRowIndex = undefined;
  }

  //This ensures we are fetching in a cache friendly way
  let fetchStartRowIndex = startRowIndex !== undefined ? Math.floor(startRowIndex / 100) * 100 : undefined;
  let fetchStopRowIndex = stopRowIndex !== undefined ? (Math.floor(stopRowIndex / 100) + 1) * 100 : undefined;

  let columnsSet = new Set(columns);
  columnsSet.add(config.tablesById[table].primKey);

  let requests = {
    data: {
      method: 'query',
      args: resolveJoins({
        database: config.dataset,
        table,
        columns: Array.from(columnsSet),
        query,
        transpose: true,
        start: fetchStartRowIndex,
        stop: fetchStopRowIndex,
        joins,
        orderBy: order
      }, config)
    }
  };

  // Don't make this call unnecessarily.
  if (onClickComponentTemplateDocPath !== undefined) {
    requests.onClickComponentTemplate = {
      method: 'staticContent',
      args: {
        url: `/panoptes/Docs/${config.dataset}/${onClickComponentTemplateDocPath}`
      }
    };
  }
  return {requests};

});
コード例 #2
0
ファイル: ItemTemplate.js プロジェクト: cggh/panoptes
      (componentCancellation) => {
        // Add API calls for the used child tables onto an array of promises.
        let promises = usedChildTables.map((usedChildTableName) => {
          let usedChildTableAPIargs = {
            database: this.config.dataset,
            table: usedChildTableName,
            query: SQL.WhereClause.encode(
              SQL.WhereClause.CompareFixed(childField[usedChildTableName], '=', primKey)
            ),
            columns: columnSpecsByTable[usedChildTableName],
            transpose: true
          };
          return LRUCache.get(
            `query${JSON.stringify(usedChildTableAPIargs)}`, (cacheCancellation) =>
              API.query({cancellation: cacheCancellation, ...usedChildTableAPIargs}),
            componentCancellation
          );
        });

        // Push the API call for the data item record onto the array of promises.
        let APIargs = resolveJoins({
          database: this.config.dataset,
          table,
          columns: _map(this.config.tablesById[table].properties, 'id').concat(usedParentTables),
          transpose: true,
          query: SQL.WhereClause.encode(
            SQL.WhereClause.CompareFixed(this.config.tablesById[table].primKey, '=', primKey)
          ),
        }, this.config);
        promises.push(
          LRUCache.get(
            `query${JSON.stringify(APIargs)}`,
            (cacheCancellation) =>
              API.query({cancellation: cacheCancellation, ...APIargs}),
            componentCancellation
          )
        );

        return Promise.all(promises);

      })