All files / src/view feedback.js

100% Statements 11/11
100% Branches 18/18
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                              2x 2x 2x                         2x 2x   2x 1x   2x 2x 2x 2x    
import { downloadBlob } from "./download.js";
 
/**
 * Collects feedback form values, downloads the MIDI file, and opens a pre-filled
 * mailto: link with the form data and composition parameters (theta) in the body.
 * @param {HTMLDialogElement} dialog - Wrapper element for the user-feedback form.
 * @param {string} midiB64 - Base64-encoded MIDI data.
 * @param {Object} parameters - Top-level parameters (theta) attached as JSON to the mail body.
 * @param {Object} report - Mail data beyond the raw parameters.
 * @param {Object<string, Object<string, string>>} report.aspects
 *  Nested tristate answers grouped by [data-tri-group] fieldset.
 * @param {Array<{label: string, chords: string[]}>} [report.chordProgression]
 *  Per-form-part Roman-numeral progression as heard; appended as raw text when present.
 */
export function submitFeedback(dialog, midiB64, parameters, report) {
  const data = new FormData(dialog.querySelector("form"));
  const stem = downloadBlob(midiB64);
  const lines = [
    "Please find the generated MIDI file attached.",
    "",
    `Occupation: ${data.get("occupation") || "-"}`,
    `Musical experience (1-5): ${data.get("experience") || "-"}`,
    `Overall impression (1-5): ${data.get("rating") || "-"}`,
    `Aspect ratings: ${JSON.stringify(report.aspects)}`,
    `Further questions: ${JSON.stringify({ human: data.get("human") ? "yes" : "no", reuse: data.get("reuse") ? "yes" : "no" })}`,
    `Comments: ${data.get("feedback") || "-"}`,
    "",
    "Parameters:",
    JSON.stringify(parameters, null, 2),
  ];
  const progression = (report.chordProgression || [])
    .map((p) => `${p.label}: ${(p.chords || []).join(" -> ")}`)
    .join("\n");
  if (progression) {
    lines.push("", "Chord progression:", progression);
  }
  const body = lines.join("\n");
  const url = `mailto:medinger@b-tu.de?subject=${encodeURIComponent(stem)}&body=${encodeURIComponent(body)}`;
  window.open(url, "_self");
  dialog.close();
}