Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions src/routes/dashboard/classes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function formatWeekends(weekends: string): string {
}

const ClassTile: Component<{ class: any }, {}> = function() {
const teachers = Array.isArray(this.class.teachers) ? this.class.teachers : [];

this.css = `
h2 {
margin: 0;
Expand All @@ -22,16 +24,17 @@ const ClassTile: Component<{ class: any }, {}> = function() {
<h2 class="m3-font-title-medium">{this.class.title}</h2>
<div class="m3-font-label-medium">{this.class.sourcedId}</div>
<div>Class size: {this.class.classSize}</div>
{this.class.teachers.map((x: any) => { return <div>Teacher: {x.givenName} {x.familyName} ({x.sourcedId})</div>; })}
{teachers.map((x: any) => { return <div>Teacher: {x.givenName} {x.familyName} ({x.sourcedId})</div>; })}
</Card>
</div>
);
}

export const Classes: Component<{ loaded: boolean, error: Error | undefined, }, { disabled: boolean, schoolyear: any, classes: any }> = function() {
export const Classes: Component<{ loaded: boolean, error: Error | undefined, }, { disabled: boolean, notice: string, schoolyear: any, classes: any[] }> = function() {
this.loaded = false;
this.error = undefined;
this.disabled = false;
this.notice = "";
this.schoolyear = { startHour: 0, endHour: 0, weekend: "" };
this.classes = [];

Expand All @@ -45,9 +48,31 @@ export const Classes: Component<{ loaded: boolean, error: Error | undefined, },

const backpack = await fetchBearer("https://nodeapi.classlink.com/tenant/customization/backpack").then(r => r.json());
this.disabled = backpack.enableStudentbackpack !== "1";
if (this.disabled) {
this.notice = "Your admin has disabled viewing of classes data.";
this.loaded = true;
return;
}

this.schoolyear = await fetchGws("https://analytics-data.classlink.io/teacherConsole/v1p0/schoolyear").then(r => r.json());
this.classes = await fetchBearer("https://myclasses.apis.classlink.com/v1/classes").then(r => r.json());
const classesResponse = await fetchBearer("https://myclasses.apis.classlink.com/v1/classes");
if (classesResponse.status === 403) {
this.disabled = true;
this.notice = "My Classes is disabled for this district.";
this.loaded = true;
return;
}
if (!classesResponse.ok) throw new Error(`ClassLink returned HTTP ${classesResponse.status}.`);

const classes = await classesResponse.json();
if (Array.isArray(classes)) {
this.classes = classes;
} else if (classes?.code === "MYCLASSES_DISABLED" || classes?.statusCode === 403) {
this.disabled = true;
this.notice = classes.message || "My Classes is disabled for this district.";
} else {
throw new Error(classes?.message || "ClassLink returned an invalid classes response.");
}

this.loaded = true;
} catch (error) {
Expand All @@ -67,13 +92,15 @@ export const Classes: Component<{ loaded: boolean, error: Error | undefined, },
<div>
<Layout loading={use(this.loaded, x => !x)} error={use(this.error)}>
<h1 class="m3-font-headline-medium">Classes</h1>
{$if(use(this.disabled), <p class="disabled">Your admin has disabled viewing of classes data. The APIs are still accessible however.</p>)}
<p>
School year: {use(this.schoolyear, x => x.Year)} ({use(this.schoolyear, x => x.startDate)} to {use(this.schoolyear, x => x.endDate)}) {use(this.schoolyear, x => x.startHour.toString().padStart(2, "0"))}:00-{use(this.schoolyear, x => x.endHour.toString().padStart(2, "0"))}:00, weekends on {use(this.schoolyear, x => formatWeekends(x.weekend))}
</p>
<div class="classes">
{use(this.classes, x => x.map((x: any) => { return <ClassTile class={x} /> }))}
</div>
{$if(use(this.notice, x => !!x), <p class="disabled">{use(this.notice)}</p>)}
{$if(use(this.disabled, x => !x), <div>
<p>
School year: {use(this.schoolyear, x => x.Year)} ({use(this.schoolyear, x => x.startDate)} to {use(this.schoolyear, x => x.endDate)}) {use(this.schoolyear, x => x.startHour.toString().padStart(2, "0"))}:00-{use(this.schoolyear, x => x.endHour.toString().padStart(2, "0"))}:00, weekends on {use(this.schoolyear, x => formatWeekends(x.weekend))}
</p>
<div class="classes">
{use(this.classes, x => x.map((x: any) => { return <ClassTile class={x} /> }))}
</div>
</div>)}
</Layout>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/dashboard/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const WispTestCard: Component<{}, { res: Response | undefined, body: string | un
this.body = undefined;
this.error = undefined;
try {
this.res = await fetch("http://applications.apis.classlink.com");
this.res = await fetch("https://applications.apis.classlink.com");
this.body = await this.res?.text();
} catch (err) {
this.error = "" + err;
Expand Down