v7.3.0

Assigning resources

Each task on the TaskBoard can have multiple resources assigned. This guide describes how this is handled on the data level.

We recommend getting familiar with tasks in the Working with tasks guide before reading this guide.

Project and stores

TaskBoard uses a project to hold the data it needs. The project has three main stores:

  • TaskStore - Contains tasks, project.taskStore
  • ResourceStore - Contains resources, project.resourceStore
  • AssignmentStore - Contains assignments, links between a task and a resource, project.assignmentStore

As outlined above, a TaskStore holds the tasks of a TaskBoard. These can be linked to multiple resources held in a ResourceStore. In relational database terms they have a many-to-many relationship. To be able to define which tasks have which resources assigned to them we need the relational concept of a link table, which is the AssignmentStore.

Of these stores, you are only required to use the TaskStore. But if you want to assign resources to tasks, you also have to use a ResourceStore and an AssignmentStore.

Resource records

Resources are represented by resource records (instances of ResourceModel) in the ResourceStore. They have a set of predefined fields that might be useful in your application:

  • id - Resource's unique id
  • name - Resource's name, displayed in task editor, in resource avatar tooltips etc.
  • iconCls - Icon to display on resource avatars
  • image - Image name, use in combination with resourceImagePath
  • imageUrl - Image url

Assignment records

Assignments are links between tasks and resources, represented by assignment records (instances of AssignmentModel) in the AssignmentStore. They have a very slim set of fields:

  • id - Assignments unique id
  • event - Linked task, called event since data layer is shared with Scheduler
  • resource - Linked resource

Defining resources and assignments

As with tasks, initial resources and assignments can be supplied inline or loaded using CrudManger. Snippet showing inline data:

const taskBoard = new TaskBoard({
    project : { 
        tasks : [
           { id : 1, name : 'Learn about tasks', status : 'doing' },
           /*...*/
        ],

        resourcesData : [ 
            { id : 1, name : 'Mr Smith' },
            /*...*/
        ],

        assignmentsData : [
            // Assignment that links task #1 to resource #1
            { id : 1, event : 1, resource : 1 }
        ]  
    } 
});

And this snippet shows how to load from a backend:

const taskBoard = new TaskBoard({
   project : {
       transport : {
           load : {
               url : 'backend/load.php'
           }
       },

       autoLoad : true
   } 
});

Programmatically assigning a resource

Resources can be assigned to tasks using the UI (using TaskEdit and TaskMenu). If you want to programmatically assign, the following snippet shows the basics:

const task     = taskBoard.project.taskStore.getById(10),
      resource = taskBoard.project.resourceStore.getById(5);

// To assign
task.assign(resource);

// To unassign
task.unassign(resource);

Contents