1.0.1 • Published 1 year ago

@hubday/scheduler v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

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 :

MethodDescriptionReturn
setMode(SchedulerMode)Set the current navigation modeScheduler
getMode()Get the current navigation modeSchedulerMode

Cursor navigation :

MethodDescriptionReturn
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 modeScheduler
next()Move the cursor to the next day | week | month, according to the current navigation modeScheduler
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 modeScheduler
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 :

MethodDescriptionReturn
getEvents()All fetched events that are related to the current cursor and modePromise<Event[]>
getCurrentDateRange()The current date range that the scheduler is focusing on{ start: Date, end: Date }
clearCache()clear the cache contentScheduler
debug()print current attributes valuesundefined

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&param=: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.");
	}
}