{"size": 2891, "ext": "js", "max_stars_repo_path": "views/directory.js", "max_stars_repo_name": "colevandersWands/fullstuck-poc", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "views/directory.js", "max_issues_repo_name": "colevandersWands/fullstuck-poc", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "views/directory.js", "max_forks_repo_name": "colevandersWands/fullstuck-poc", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.2298850575, "max_line_length": 125, "alphanum_fraction": 0.6139744033}
// later: warnings

function renderDirectory(directory) {

  const dirColor = directory.status === 'no reports'
    ? 'black'
    : directory.status === 'error'
      ? 'red'
      : directory.status === 'passing'
        ? 'lightGreen'
        : directory.status === 'on hold'
          ? 'black'
          : directory.status === 'in progress'
            ? 'orange'
            : 'violet';

  const dirNameTextEl = document.createElement('text');
  dirNameTextEl.innerHTML = directory.dirName + '         ';
  dirNameTextEl.style.color = dirColor;

  const reportButton = document.createElement('button');
  reportButton.innerHTML = 'view raw report on GitHub';

  const reportA = document.createElement('a');
  reportA.href = 'https://github.com/' + userName + repoName + 'blob/master/exercises/' + directory.dirName + '/report.json';
  reportA.target = '_blank';
  reportA.appendChild(reportButton);

  const dirNameH2 = document.createElement('h2');
  dirNameH2.appendChild(dirNameTextEl);
  dirNameH2.appendChild(reportA);

  const statusTextEl = document.createElement('text');
  statusTextEl.innerHTML = directory.status + ': ' + directory.timeStamp;

  const filesListUl = Object.keys(directory.files)
    .map(fileName => {
      const fileColor = directory.files[fileName] === 'no reports'
        ? 'white'
        : directory.files[fileName] === 'error'
          ? 'red'
          : directory.files[fileName] === 'passing'
            ? 'lightGreen'
            : directory.files[fileName] === 'on hold'
              ? 'yellow'
              : directory.files[fileName] === 'in progress'
                ? 'orange'
                : 'violet';

      const newButton = document.createElement('button');
      newButton.innerHTML = fileName;
      newButton.style.backgroundColor = fileColor;

      const newLi = document.createElement('li');

      const reportPath = './exercises/' + directory.dirName + '/report.json';
      newLi.onclick = () => {
        if (cache.hasOwnProperty(reportPath)) {
          render(renderFile(directory, fileName));
        } else {
          fetch(reportPath)
            .then(resp => resp.json())
            .then(directory => {
              cache[reportPath] !== undefined ? cache[reportPath] = directory : null;
              render(renderFile(directory, fileName));
            })
            .catch(err => console.log(err));
        };
      };
      newLi.appendChild(newButton);
      return newLi
    })
    .reduce((ul, li) => {
      ul.appendChild(li);
      return ul;
    }, document.createElement('ul'));

  const directoryDiv = document.createElement('div');
  directoryDiv.appendChild(dirNameH2);
  directoryDiv.appendChild(statusTextEl);
  directoryDiv.appendChild(document.createElement('br'));
  directoryDiv.appendChild(document.createElement('br'));
  directoryDiv.appendChild(filesListUl);

  return directoryDiv;
}
