<commit_before>import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { JsonConvert, OperationMode, ValueCheckingMode } from "json2typescript";

import {
  DeviceInfo,
  Status,
  PingResult,
  RunnerInfo,
  ViaInfo
} from "../objects";
import { MatDialog } from "@angular/material";
import { RebootComponent } from "../popups/reboot/reboot.component";

@Injectable({
  providedIn: "root"
})
export class APIService {
  public theme = "default";

  private jsonConvert: JsonConvert;
  private urlParams: URLSearchParams;

  constructor(private http: HttpClient, private dialog: MatDialog) {
    this.jsonConvert = new JsonConvert();
    this.jsonConvert.ignorePrimitiveChecks = false;

    this.urlParams = new URLSearchParams(window.location.search);
    if (this.urlParams.has("theme")) {
      this.theme = this.urlParams.get("theme");
    }
  }

  public switchToUI() {
    window.location.assign("http://localhost:10000/ui");
  }

  public refresh() {
    window.location.reload(true);
  }

  public switchTheme(name: string) {
    console.log("switching theme to", name);

    this.theme = name;
    this.urlParams.set("theme", name);
    window.history.replaceState(
      null,
      "System Health Dashboard",
      window.location.pathname + "?" + this.urlParams.toString()
    );
  }

  public async reboot() {
    try {
      this.dialog.open(RebootComponent, { disableClose: true });
      const data = await this.http
        .put("device/reboot", {
          responseType: "text"
        })
        .toPromise();
    } catch (e) {
      // bug where responseType doesn't actually work
      if (e.status === 200) {
        console.log(e.error.text);<commit_msg>fixing switch to ui...<commit_after>import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { JsonConvert, OperationMode, ValueCheckingMode } from "json2typescript";

import {
  DeviceInfo,
  Status,
  PingResult,
  RunnerInfo,
  ViaInfo
} from "../objects";
import { MatDialog } from "@angular/material";
import { RebootComponent } from "../popups/reboot/reboot.component";

@Injectable({
  providedIn: "root"
})
export class APIService {
  public theme = "default";

  private jsonConvert: JsonConvert;
  private urlParams: URLSearchParams;

  constructor(private http: HttpClient, private dialog: MatDialog) {
    this.jsonConvert = new JsonConvert();
    this.jsonConvert.ignorePrimitiveChecks = false;

    this.urlParams = new URLSearchParams(window.location.search);
    if (this.urlParams.has("theme")) {
      this.theme = this.urlParams.get("theme");
    }
  }

  public switchToUI() {
    window.location.pathname = "/ui"
  }

  public refresh() {
    window.location.reload(true);
  }

  public switchTheme(name: string) {
    console.log("switching theme to", name);

    this.theme = name;
    this.urlParams.set("theme", name);
    window.history.replaceState(
      null,
      "System Health Dashboard",
      window.location.pathname + "?" + this.urlParams.toString()
    );
  }

  public async reboot() {
    try {
      this.dialog.open(RebootComponent, { disableClose: true });
      const data = await this.http
        .put("device/reboot", {
          responseType: "text"
        })
        .toPromise();
    } catch (e) {
      // bug where responseType doesn't actually work
      if (e.status === 200) {
        console.log(e.error.text);
{'fraction_non_alphanumeric': 0.13478893740902476, 'fraction_numerical': 0.003784570596797671, 'mean_word_length': 3.215950920245399, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5988959', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1029, 'n_words': 231}