Resource definition and customization.
Resources are the things that tasks depend on and can represent people, supplies, rooms, elevators, etc. All resources are simple JSON objects with a set of options which determines how the resource is reserved. The only required option is the id of the resource.
// a basic resource called 'Res1' var resource = {id: 'Res1'};
Note Resources required by tasks will be generated automatically for you if you don't specify them yourself.
Resources are JSON objects that are customized using the following properties:
Later
schedule. The resource will never be reserved for a
time when the available schedule is invalid.isNotReservable
to true.Example resources:
// a basic resource that is always available var r1 = {id: 'Resource1'}; // a resource that can only be scheduled on weekdays var r2 = { id: 'Resource2', available: later.parse.text('every weekday') }; // a resource that will not be reserved by a task var r3 = {id: 'Resource3', isNotReservable: true}; // a fully customized resource var r4 = { id: 'Resource4', available: later.parse.recur().on(2).dayOfWeek().after('9:00').time(), isNotReservable: false };
Often times the resources that your application defines are not in the format that Schedule requires. To make the conversion process easier, Schedule includes a resource generator that can be used on any array of objects to produce valid resources.
// creating a default resource generator var t = schedule.resources();
Used to specify the value or function that should be called to
define the id
of the resource. If a function is specified,
it will be passed in the object and index from the input data array.
Used to specify the value or function that should be called to
define the available
schedule of the resource. If a function is specified,
it will be passed in the object and index from the input data array.
Used to specify the value or function that should be called to
define the isNotReservable
property of the resource. If a function is specified,
it will be passed in the object and index from the input data array.
// the original items that we want to make into resources var elevators = [ {name: 'E1', available: 'every weekday after 8:00am and before 4:00pm'}, {name: 'E2', available: 'every weekday after 8:00am and before 4:00pm'} ]; // creating our resource generator var r = schedule.resources() // use the name of our object as the id .id(function(d) { return d.name; }) // use later.parse.text to convert available into a valid schedule .schedule(function(d) { return d.availability ? later.parse.text(d.availability) : undefined; }) // set all of the elevators to be reservable .isNotReservable(false); // create resources out of our elevators var resources = r(elevators);