-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9e96e8
commit 491c98d
Showing
5 changed files
with
205 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { ProjectController } from "$lib/controller/project-controller"; | ||
import type { StageEntry } from "$lib/model/backend"; | ||
import type { PageLoad } from "./$types"; | ||
import type { PapersByStage } from "./types"; | ||
|
||
export const load: PageLoad = ({ params }) => { | ||
const projectId = Number(params.projectId); | ||
if (Number.isNaN(projectId)) { | ||
throw new Error(`Invalid projectId ${params.projectId}`); | ||
} | ||
|
||
const projectController = new ProjectController(projectId); | ||
|
||
const loadingCriteria = projectController.getCriteria(); | ||
// attach noop-catch to handle promise rejection correctly (see https://svelte.dev/docs/kit/load#Streaming-with-promises) | ||
loadingCriteria.catch(() => {}); | ||
|
||
const loadingStageCount = projectController.getStageCount(); | ||
// attach noop-catch to handle promise rejection correctly (see https://svelte.dev/docs/kit/load#Streaming-with-promises) | ||
loadingStageCount.catch(() => {}); | ||
|
||
const loadingStageEntries = projectController.getAllPapers(); | ||
// attach noop-catch to handle promise rejection correctly (see https://svelte.dev/docs/kit/load#Streaming-with-promises) | ||
loadingStageEntries.catch(() => {}); | ||
|
||
const loadingPapersByStage = Promise.all([loadingStageEntries, loadingStageCount]).then( | ||
([stageEntries, stageCount]) => getPapersByStage(stageEntries, stageCount), | ||
); | ||
// attach noop-catch to handle promise rejection correctly (see https://svelte.dev/docs/kit/load#Streaming-with-promises) | ||
loadingPapersByStage.catch(() => {}); | ||
|
||
const loadingYears = loadingStageEntries.then((stageEntries) => { | ||
const years = new Set<number>(); | ||
stageEntries.forEach((stageEntry) => { | ||
years.add(stageEntry.paper.year ?? -1); | ||
}); | ||
return Array.from(years); | ||
}); | ||
// attach noop-catch to handle promise rejection correctly (see https://svelte.dev/docs/kit/load#Streaming-with-promises) | ||
loadingYears.catch(() => {}); | ||
|
||
const loadingPublishers = loadingStageEntries.then((stageEntries) => { | ||
const publishers = new Set<string>(); | ||
stageEntries.forEach((stageEntry) => { | ||
publishers.add(stageEntry.paper.publisherName); | ||
}); | ||
return Array.from(publishers); | ||
}); | ||
// attach noop-catch to handle promise rejection correctly (see https://svelte.dev/docs/kit/load#Streaming-with-promises) | ||
loadingPublishers.catch(() => {}); | ||
|
||
const loadingMembers = projectController.getMembers(); | ||
// attach noop-catch to handle promise rejection correctly (see https://svelte.dev/docs/kit/load#Streaming-with-promises) | ||
loadingMembers.catch(() => {}); | ||
|
||
const loadingReviewers = Promise.all([loadingStageEntries, loadingMembers]).then( | ||
([stageEntries, members]) => { | ||
const reviewerIds = new Set<number>(); | ||
stageEntries.forEach((stageEntry) => { | ||
stageEntry.paper.reviewData?.reviews.forEach((review) => { | ||
reviewerIds.add(review.user.id); | ||
}); | ||
}); | ||
return members.filter((member) => reviewerIds.has(member.id)); | ||
}, | ||
); | ||
// attach noop-catch to handle promise rejection correctly (see https://svelte.dev/docs/kit/load#Streaming-with-promises) | ||
loadingReviewers.catch(() => {}); | ||
|
||
return { | ||
loadingCriteria, | ||
loadingStageCount, | ||
loadingPapersByStage, | ||
loadingYears, | ||
loadingPublishers, | ||
loadingReviewers, | ||
}; | ||
}; | ||
|
||
function getPapersByStage(papers: StageEntry[], stageCount: number): PapersByStage[] { | ||
const papersByStage: PapersByStage[] = []; | ||
for (let i = 0; i <= stageCount; i++) { | ||
papersByStage.push({ stageIndex: i, papers: papers.filter((paper) => paper.stage === i) }); | ||
} | ||
return papersByStage; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { StageEntry } from "$lib/model/backend"; | ||
|
||
export interface PapersByStage { | ||
stageIndex: number; | ||
papers: StageEntry[]; | ||
} |