Home Manual Reference Source Test

src/view/feedback.js

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