Resources

Resource definition and customization.

Overview

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.

Resource options

Resources are JSON objects that are customized using the following properties:

id (required)
The id of the resource. Every resource must specify a unique id.
available
Defines when the resource may be reserved. Specified using any valid Later schedule. The resource will never be reserved for a time when the available schedule is invalid.
isNotReservable
By default, resources are reserved so that they can only be used by one task at a time. If you want to allow resources to be used by multiple tasks at the same time, set 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
  };

Resource generator

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();

tasks#id

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.


tasks#available

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.


tasks#isNotReservable

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.


Example usage:

  // 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);