Jewell Simon

Observer grade view sorting.

Discussion created by Jewell Simon on Nov 14, 2019
Latest reply on Nov 18, 2019 by Tim Batiuk

Along the same lines as this complaint Parental observation in canvas complicated with three children! Our parents had a hard time discerning grades at a quick glance...

I created a script to to at least clean up and organize the students grades on the observer view.

if you were to click view grades all of the grades would be jumbled up all the kids would be intertwined and if there was a course that was ungraded(like a counselor course or club) it would show up as well. so the script gets rid of the ungraded courses and alphabetizes the rest of the courses.

function sortGradesObservers() {
  const checkIfNull = async selector => {
    while (document.querySelector(selector) === null) {
      await new Promise(resolve => requestAnimationFrame(resolve));
    }
    return document.querySelector(selector);
  };

  checkIfNull("table.course_details.observer_grades").then(() => {
    console.info(ENV.current_user_roles.includes("observer"),window.location.pathname.includes("/grades"));
    if (
      ENV.current_user_roles.includes("observer") &&
      window.location.pathname.includes("/grades")
    ) {
        let table,
          rows,
          switching,
          i,
          thisRow,
          nextRow,
          shouldSwitch,
          percentColumn;
        table = document.querySelector("table.course_details.observer_grades");
        percentColumn = document.querySelectorAll("td.percent");
        percentColumn.forEach(one => {
          if (one.innerText === "no grade") {
            one.parentNode.style.display = "none";
          }
        });
        switching = true;
        while (switching) {
          switching = false;
          rows = table.rows;
          for (i = 0; i < rows.length; i++) {
            shouldSwitch = false;
            thisRow = rows[i].querySelectorAll("td")[0];
            if (i !== rows.length - 1) {
              nextRow = rows[i + 1].querySelectorAll("td")[0];
            }
            if (
              thisRow.innerText.toLowerCase() > nextRow.innerText.toLowerCase()
            ) {
              shouldSwitch = true;
              break;
            }
          }
          if (shouldSwitch) {
            rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
            switching = true;
          }
        }
      // set up the mutation observer
    }
  });
}

To Do:

-  add mutation observer

-  add line of demarkation between sets

Outcomes