<commit_before>/**
 * Copyright 2013-2019  GenieACS Inc.
 *
 * This file is part of GenieACS.
 *
 * GenieACS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * GenieACS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with GenieACS.  If not, see <http://www.gnu.org/licenses/>.
 */

import m, { ClosureComponent, Component } from "mithril";
import * as notifications from "./notifications";

export async function init(): Promise<{}> {
  return m.request({ url: "/init" });
}

export const component: ClosureComponent = (vnode): Component => {
  let options = vnode.attrs;
  const selected = new Set<string>();
  for (const [k, v] of Object.entries(options)) if (v) selected.add(k);

  return {
    view: () => {
      document.title = "Initialization wizard - GenieACS";

      const checkboxes = [
        "users",
        "presets",
        "filters",
        "device",
        "index",
        "overview"
      ].map(s => {
        if (!options[s]) selected.delete(s);
        return m("input", {
          type: "checkbox",
          checked: selected.has(s),
          disabled: !options[s],
          style: "display: inline; margin-right: 0.5em;",
          onclick: e => {
            if (e.target.checked) selected.add(s);
            else selected.delete(s);
          }
        });
      });

      return m(".wizard-dialog", [
        m("h1", "Initialization wizard"),
        m(
          "p",
          "This wizard will seed the database with a minimal initial configuration to serve as a starting point. Select what you want to initialize and click 'ABRACADABRA!'."
        ),
        m("div", m("label", checkboxes[0], "Users, roles and permissions")),
        m("div", m("label", checkboxes[1], "Presets and provisions")),
        m(
          "div",
          m("label", checkboxes[2], "Devices predefined search filters")
        ),
        m("div", m("label", checkboxes[3], "Device details page")),
        m("div", m("label", checkboxes[4], "Devices listing page")),
        m("div", m("label", checkboxes[5], "Overview page")),
        m(
          "button.primary",
          {
            style: "margin: 10px;",
            disabled: selected.size === 0,
            onclick: e => {
              e.target.disabled = true;

              const opts = {};
              for (const s of selected) opts[s] = true;

              m.request({
                method: "POST",
                url: "/init",
                data: opts
              })
                .then(() => {<commit_msg>Missed wizard page in Mithril 2 upgrade<commit_after>/**
 * Copyright 2013-2019  GenieACS Inc.
 *
 * This file is part of GenieACS.
 *
 * GenieACS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * GenieACS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with GenieACS.  If not, see <http://www.gnu.org/licenses/>.
 */

import m, { ClosureComponent, Component } from "mithril";
import * as notifications from "./notifications";

export async function init(): Promise<{}> {
  return m.request({ url: "/init" });
}

export const component: ClosureComponent = (vnode): Component => {
  let options = vnode.attrs;
  const selected = new Set<string>();
  for (const [k, v] of Object.entries(options)) if (v) selected.add(k);

  return {
    view: () => {
      document.title = "Initialization wizard - GenieACS";

      const checkboxes = [
        "users",
        "presets",
        "filters",
        "device",
        "index",
        "overview"
      ].map(s => {
        if (!options[s]) selected.delete(s);
        return m("input", {
          type: "checkbox",
          checked: selected.has(s),
          disabled: !options[s],
          style: "display: inline; margin-right: 0.5em;",
          onclick: e => {
            if (e.target.checked) selected.add(s);
            else selected.delete(s);
          }
        });
      });

      return m(".wizard-dialog", [
        m("h1", "Initialization wizard"),
        m(
          "p",
          "This wizard will seed the database with a minimal initial configuration to serve as a starting point. Select what you want to initialize and click 'ABRACADABRA!'."
        ),
        m("div", m("label", checkboxes[0], "Users, roles and permissions")),
        m("div", m("label", checkboxes[1], "Presets and provisions")),
        m(
          "div",
          m("label", checkboxes[2], "Devices predefined search filters")
        ),
        m("div", m("label", checkboxes[3], "Device details page")),
        m("div", m("label", checkboxes[4], "Devices listing page")),
        m("div", m("label", checkboxes[5], "Overview page")),
        m(
          "button.primary",
          {
            style: "margin: 10px;",
            disabled: selected.size === 0,
            onclick: e => {
              e.target.disabled = true;

              const opts = {};
              for (const s of selected) opts[s] = true;

              m.request({
                method: "POST",
                url: "/init",
                body: opts
              })
                .then(() => {
{'fraction_non_alphanumeric': 0.13166666666666665, 'fraction_numerical': 0.007166666666666667, 'mean_word_length': 2.183554376657825, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3991262', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1641, 'n_words': 586}