{"size": 2050, "ext": "js", "max_stars_repo_path": "files/dashboard/usage-reports/src/reportsMain.js", "max_stars_repo_name": "BrianDehlinger/cloud-automation", "max_stars_repo_stars_event_min_datetime": "2019-01-09T18:37:48.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-01T12:54:24.000Z", "max_issues_repo_path": "files/dashboard/usage-reports/src/reportsMain.js", "max_issues_repo_name": "BrianDehlinger/cloud-automation", "max_issues_repo_issues_event_min_datetime": "2018-06-22T18:39:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T20:58:17.000Z", "max_forks_repo_path": "files/dashboard/usage-reports/src/reportsMain.js", "max_forks_repo_name": "BrianDehlinger/cloud-automation", "max_forks_repo_forks_event_min_datetime": "2018-08-08T20:32:28.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-20T23:59:16.000Z"}
{"max_stars_count": 12, "max_issues_count": 1420, "max_forks_count": 16, "avg_line_length": 32.5396825397, "max_line_length": 129, "alphanum_fraction": 0.6136585366}
import { amap, fetchRecentData } from './dataHelper.js';
import './datePicker.js';
import './reportsTable.js';
import './reportsTabPanel.js';
import './windowSizer.js';

const reportList = ['all', 'fence', 'guppy', 'indexd', 'peregrine', 'sheepdog'];

export function main() {
  const windowDOM = document.querySelector('g3r-window-sizer');
  const dateRange = windowDOM.dateRange;
  const statusDOM = document.getElementById('status');
  const dataTables = {
    projects: { 'all': document.body.querySelector('.g3reports-projects g3r-table') },
    rcodes: reportList.reduce(
      (acc,name) => { acc[name] = document.body.querySelector(`.g3reports-rcodes div[name="${name}"] g3r-table`); return acc; }, 
      {}
    ),
    rtimes: reportList.reduce(
      (acc,name) => { acc[name] = document.body.querySelector(`.g3reports-rtimes div[name="${name}"] g3r-table`); return acc; }, 
      {}
    ),
    users: { 'all': document.body.querySelector('.g3reports-users g3r-table') },
  };

  statusDOM.innerHTML = `<p>Initializing</p>`;
  
  // Download data in the 'all' tabs
  amap(
    Object.keys(dataTables), 
    (rtype) => fetchRecentData(rtype, 'all', dateRange)
  ).then(
    (infoList) => {
      infoList.map(
        (info) => {
          dataTables[info.reportType][info.service].data = info.massage;
        }
      );
      statusDOM.innerHTML = `<p>Initial data downloaded ...</p>`;
    }
  );
  // Go ahead and fetch data in other tabs now
  amap(
    reportList.slice(1).reduce((acc, serviceName) => {
      ['rtimes', 'rcodes'].forEach((reportType) => { acc.push({serviceName, reportType}); });
      return acc;
    }, []),
    ({reportType, serviceName}) => fetchRecentData(reportType, serviceName, dateRange)
  ).then(
    (infoList) => {
      infoList.map(
        (info) => {
          //console.log(`Rendering ${info.service} ${info.reportType}`, info);
          dataTables[info.reportType][info.service].data = info.massage;
        }
      );
      statusDOM.innerHTML = `<p>All data downloaded</p>`;
    }
  );
}


main();