aboutsummaryrefslogtreecommitdiff
path: root/src/components/Labs.svelte
diff options
context:
space:
mode:
authorFurkan Sahin <furkan-dev@proton.me>2022-07-27 16:49:51 -0500
committerFurkan Sahin <furkan-dev@proton.me>2022-07-27 16:49:51 -0500
commitc81c5f2ffeb037918429b4f279588161452d344b (patch)
treeb46e99c58d8877548b6bcb73aed1846b20577df9 /src/components/Labs.svelte
parentc04946973e7cbb5f96b4f626458921ed713b2c48 (diff)
Labs download button to get CSV output of assignments
Diffstat (limited to 'src/components/Labs.svelte')
-rw-r--r--src/components/Labs.svelte27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/components/Labs.svelte b/src/components/Labs.svelte
index 465b87a..9f6e781 100644
--- a/src/components/Labs.svelte
+++ b/src/components/Labs.svelte
@@ -2,7 +2,6 @@
import { labStore, ptStore } from "../stores";
import type Lab from "../models/Lab";
import Icon from "./helpers/Icon.svelte";
- var csvwriter = require("csvwriter");
let selected_lab: Lab | undefined;
@@ -26,8 +25,26 @@
function download() {
// prepare data in CSV format
- let data: [""];
-
+ let cols = headers.slice(1, -1);
+ let csv = cols.join(",") + "\n";
+ labsAndPts.forEach((row) => {
+ let l = row.lab;
+ csv += `${l.course},${l.section},${l.time},${l.location},${
+ row.pt?.name ?? "UNASSIGNED"
+ }\n`;
+ });
+ console.log(csv);
+
+ const blob = new Blob([csv], { type: "text/csv" });
+ const anchor = document.createElement("a");
+ const url = window.URL.createObjectURL(blob);
+ anchor.href = url;
+ anchor.download = "lab-assignments.csv";
+ anchor.style.display = "none";
+ document.body.appendChild(anchor);
+ anchor.click();
+ document.body.removeChild(anchor);
+ window.URL.revokeObjectURL(url);
}
</script>
@@ -40,8 +57,8 @@
{#if i == 0}
<th>
{labs.length}
- <Icon name="info" class="h-4 w-4" handleClick={download} /></th
- >
+ <Icon name="download" class="h-4 w-4" handleClick={download} />
+ </th>
{:else}
<th>{header}</th>
{/if}