@hubday/scheduler v1.0.1
Scheduler
Fetch and process your lessons of the day
/ week
/ month
from any external sources !
Built-in calendar like navigation (Move in time a cursor).
Can be implemented with any kind of calendar source (Ical, Json, etc..)
Prebuilt modules for
hyperplanning
/ade
/celcat
.
Authors : @alexboin, @celian-rib
Usage
Here's an example of basic usage :
Get all events of January 17 from an
hyperplanning
source.
import { HyperplanningScheduler } from "scheduler";
const scheduler = new HyperplanningScheduler("F28486A74D71A7B44CD0B88D32986A91");
scheduler
.setDate("2022-01-17")
.getEvents()
.then(console.log);
API
Types & Interfaces :
Event :
export interface Event {
id: string;
subject: string;
description: string[];
dateStart: Date;
dateEnd: Date;
locations: string[];
}
(Built-in custom event type) Lesson :
You can make your own interface that the scheduler will work with
export interface Lesson extends Event {
groups: string[];
type?: string;
teachers: string[];
}
SchedulerMode :
type SchedulerMode = "day" | "week" | "month";
Methods :
Navigation mode :
Method | Description | Return |
---|---|---|
setMode(SchedulerMode) | Set the current navigation mode | Scheduler |
getMode() | Get the current navigation mode | SchedulerMode |
Cursor navigation :
Method | Description | Return |
---|---|---|
setDate(Date) | Set the cursor on the given date (Change the mode to day ) | Scheduler |
move(number) | Move the cursor depending on the given number of steps and the current navigation mode | Scheduler |
next() | Move the cursor to the next day | week | month, according to the current navigation mode | Scheduler |
nextDay() | Move to the next day (Set the navigation mode to day ) | Scheduler |
nextWeek() | Move to the next week (Set the navigation mode to week ) | Scheduler |
nextMonth() | Move to the next month (Set the navigation mode to month ) | Scheduler |
previous() | Move the cursor to the previous day | week | month, according to the current navigation mode | Scheduler |
previousDay() | Move to the previous day (Set the navigation mode to day ) | Scheduler |
previousWeek() | Move to the previous week (Set the navigation mode to week ) | Scheduler |
previousMonth() | Move to the previous month (Set the navigation mode to month ) | Scheduler |
Other :
Method | Description | Return |
---|---|---|
getEvents() | All fetched events that are related to the current cursor and mode | Promise<Event[]> |
getCurrentDateRange() | The current date range that the scheduler is focusing on | { start: Date, end: Date } |
clearCache() | clear the cache content | Scheduler |
debug() | print current attributes values | undefined |
Prevent CORS policy issues
The scheduler instance has to fetch ical data from external source, causing CORS issue if you'r using node in a browser environment.
In order to you the scheduler you'll have to make your own proxy redirecting the requests to the right urls.
Examples :
Scheduler config and netlify toml config for proxying requests
1) Hyplerplanning :
Proxy url template :
/api/scheduler/hyperplanning/:schedulerId/:dateParameter
Implementation :
private scheduler = new HyperplanningScheduler( "F28486A74D71A7B44CD0B88D32986A91", { proxyUrl: "/api/scheduler/hyperplanning/:schedulerId/:dateParameter" } );
[[redirects]] from = "/api/scheduler/hyperplanning/:schedulerId/:dateParameter" to = "https://hyperplanning.iut.u-bordeaux.fr/Telechargements/ical/Edt.ics?version=2021.0.1.3&idICal=:schedulerId¶m=:dateParameter" status = 200
2) Ade :
Proxy url template :
/api/scheduler/ade/:schedulerId/:dateParameter
Implementation :
private scheduler2 = new AdeScheduler("7214", { proxyUrl: "/api/scheduler/ade/:schedulerId/:dateParameter", });
[[redirects]] from = "/api/scheduler/ade/:schedulerId/:dateParameter" to = "https://ade.bordeaux-inp.fr/jsp/custom/modules/plannings/anonymous_cal.jsp?resources=:schedulerId&projectId=1&calType=ical&:dateParameter" status = 200
3) Celcat :
Proxy url template :
/api/scheduler/celcat
Celcat service is using a method post (The parameters are not in the url )
Implementation :
private scheduler3 = new CelcatScheduler("CP100A2", { proxyUrl: "/api/scheduler/celcat", });
[[redirects]] from = "/api/scheduler/celcat" to = "https://celcat.u-bordeaux.fr/Calendar/Home/GetCalendarData" status = 200
Custom Scheduler from you own source
import { Scheduler, Event } from "scheduler";
export interface CustomInterface extends Event {
myValue: string;
}
export default class CustomScheduler extends Scheduler<CustomInterface> {
minDate = "2010-01-01";
maxDate: "2030-12-31";
protected fetchSource(): Promise<string> {
// Fetch the data from your custom source
// Return the fetched data as string
throw new Error("Method not implemented.");
}
protected parseEvents(data: string): CustomInterface[] {
// Parse here the fetched data to construct
// the final result
throw new Error("Method not implemented.");
}
}