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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
<script lang="ts">
import type PeerTeacher from "../models/PeerTeacher";
import type Lab from "../models/Lab";
import { labStore, ptStore } from "../stores";
import LabBox from "./helpers/LabBox.svelte";
import PT from "./helpers/PTBox.svelte";
import Icon from "./helpers/Icon.svelte";
let selectedPeerTeacher: PeerTeacher | undefined;
let selectedLab: Lab | undefined;
$: peerTeachers = [...$ptStore.values()].sort((a, b) =>
a.lastname.toUpperCase() === b.lastname.toUpperCase()
? a.firstname.toUpperCase().localeCompare(b.firstname.toUpperCase())
: a.lastname.toUpperCase().localeCompare(b.lastname.toUpperCase())
);
$: labs = [...$labStore.values()].sort((a, b) => a.id - b.id);
$: selectedPtAssignedLabs = [...(selectedPeerTeacher?.labs.values() ?? [])]
.flatMap((labId) => {
const lab = $labStore.get(labId);
return lab === undefined ? [] : [lab];
})
.sort((a, b) => a.id - b.id);
$: unassignedLabs = labs.filter((lab) => !lab.assigned);
$: compatibleLabs = labs.filter((lab) =>
isPTandLabCompatible(lab, selectedPeerTeacher)
);
$: compatiblePTs = peerTeachers.filter((pt) =>
isPTandLabCompatible(selectedLab, pt)
);
function isPTandLabCompatible(
lab: Lab | undefined,
pt: PeerTeacher | undefined
): boolean {
return (
pt != undefined &&
lab != undefined &&
!lab?.assigned &&
!pt?.conflictsWith(lab.event)
);
}
function updateReactiveDeclarations() {
selectedPeerTeacher = selectedPeerTeacher;
selectedLab = selectedLab;
peerTeachers = peerTeachers;
labs = labs;
}
function assignLab(id: number) {
const lab = $labStore.get(id);
if (lab === undefined) return;
lab.assigned = true;
selectedPeerTeacher?.labs.add(id);
updateReactiveDeclarations();
}
function unassignLab(id: number) {
const lab = $labStore.get(id);
if (lab === undefined) return;
lab.assigned = false;
selectedPeerTeacher?.labs.delete(id);
updateReactiveDeclarations();
}
// Bad code design! Very similar function to the download function in Labs page.
// This should be redesigned with more thought instead
// of automatically encapsulating it in some other file.
//* NOTE although this outputs a CSV, the csv file might look mangled because
// we output courses as "course1: labs \n course2: labs \n course3: labs..."
// The newlines \n cause issues when displaying the csv file, but they look fine
// when uploaded to Google Sheets thanks to being encompassed by quotes ""
export function downloadAssignments() {
console.log("Downloading lab assignments");
let cols = [
"First",
"Last",
"Courses",
"Labs",
"#LH",
"Office Hours",
"#OH",
"Total Hours",
];
let csv = cols.join(",") + "\n";
peerTeachers.forEach((pt) => {
let labs = new Array<string>();
pt.coursesAndLabs().forEach((sections, course) => {
labs.push(`${course} - ${sections}`);
});
let office_hours = new Array<string>();
pt.office_hours.forEach((e) => {
office_hours.push(e.info);
});
csv +=
[
pt.firstname,
pt.lastname,
"n/a",
`"${labs.join("\n")}"`,
pt.lab_hours,
`"${[office_hours.join("\n")]}"`,
pt.office_hours_hours,
pt.lab_hours + pt.office_hours_hours,
].join(",") + "\n";
});
console.log("Result of Assignments", 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 = "assignments.csv";
anchor.style.display = "none";
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
window.URL.revokeObjectURL(url);
}
// TODO Figure out way for PT boxes to both be blue if compat labs AND be bordered if selected_pt
</script>
<div
class="flex-none overflow-hidden flex-col h-[100vh] w-[80vw] px-[2vw] pt-[1vh]"
>
<!-- Top half: 3 Columns -->
<div class="flex flex-row h-[80vh]">
<!-- Peer Teacher -->
<div class="assign-box rounded-l-xl">
<div class="assign-box-header">
<div class="flex flex-row justify-center items-center gap-x-8">
<div class="flex">Peer Teacher</div>
<Icon
class="flex"
name="download"
handleClick={downloadAssignments}
/>
</div>
</div>
<div class="assign-box-body">
{#each peerTeachers as pt}
<div
class={compatiblePTs.includes(pt) //selectedPeerTeacher == pt
? "bg-info text-info-content" // "border-l-8 border-blue-500"
: "bg-base-100 text-base-100-content"}
on:click={() => {
selectedPeerTeacher = pt;
}}
>
<svelte:component this={PT} {pt} />
</div>
{/each}
</div>
</div>
<!-- Available Labs -->
<div class="assign-box">
<div class="assign-box-header">Labs: {labs.length}</div>
<div class="assign-box-body">
{#each compatibleLabs as lab}
<svelte:component
this={LabBox}
{lab}
iconName="plus-circle"
iconClick={() => {
assignLab(lab.id);
}}
/>
{/each}
</div>
</div>
<!-- Selected PT's Labs -->
<div class="assign-box rounded-r-xl">
<div class="assign-box-header">
{selectedPeerTeacher?.name ?? "PT's Labs"}
</div>
<div class="assign-box-body">
{#each selectedPtAssignedLabs as lab}
<svelte:component
this={LabBox}
{lab}
iconName="minus-circle"
iconClick={() => {
unassignLab(lab.id);
}}
/>
{/each}
</div>
</div>
</div>
<!-- Bottom half: Universal unassigned labs -->
<div class="flex flex-col mt-2 text-center">
<h1>Unassigned Labs: {unassignedLabs.length}</h1>
<ul class="menu menu-horizontal bg-base-100 rounded-box overflow-auto">
{#each unassignedLabs as lab}
<li
on:click={() => {
selectedLab = lab;
}}
class={selectedLab == lab ? "bg-info text-info-content" : ""}
>
<span>{lab.course} {lab.section}</span>
</li>
{/each}
</ul>
</div>
</div>
|