Overview

  • The tasks queue Angular component lets you display a list of unscheduled tasks.

  • You can change the task priority using drag and drop (you can move the task to a different position in the queue).

  • You can schedule the task by dragging it to the desired position in the Angular Scheduler component.

  • Includes a trial version of DayPilot Pro for JavaScript (see License below)

License

Licensed for testing and evaluation purposes. Please see the license agreement included in the sample project. You can use the source code of the tutorial if you are a licensed user of DayPilot Pro for JavaScript. Buy a license.

How to create a queue of unscheduled tasks in Angular?

angular scheduler drag and drop task queue component

Since version 2021.2.4972, DayPilot Pro for JavaScript includes a new Angular Queue component that can display an ordered list of tasks. It lets you implement a queue of unscheduled tasks that can be scheduled for a specific time using drag and drop.

  • It uses the same styling as the Angular Scheduler component so the appearance will be unified.

  • The queue component automatically activates drag and drop for the items. You can drag items from the queue to the Scheduler component and schedule it for the desired time.

  • The tasks queue is ordered - it respects the order of items in the data source.

  • Users can change the order of the tasks by dragging to a different position in the queue.

When you drag the queue item outside of the queue element, external drag and drop is activated:

  • During dragging, the source task in the queue is displayed as semi-transparent. This way users will see which task is being dragged.

  • If you drag the item outside of the queue it will show a global shadow indicating that dragging is active.

  • As soon as you reach the Scheduler grid the shadow will highlight the target position. The duration specified in the task properties will be used to calculate the exact target position.

The queue items have the following required fields:

  • id (string or number; the id must be unique)

  • text (string; this is the text that will be displayed in the task queue item)

  • duration (number or DayPilot.Duration object; this value specifies the duration that will be used when converting the task to a Scheduler event during drag and drop)

  • start and end fields (string or DayPilot.Date object) can be used instead of duration - this makes the interoperability with the Scheduler component easier

The queue task data format is compatible with the Scheduler event format. The id and text properties are used the same way in the Scheduler.

Instead of using the Queue component, you can also use the Scheduler API to create your own queue.

However, the queue component will do a lot of work for you:

  • The queue styles the items the same way as the Scheduler

  • The queue supports item reordering

  • The queue API is compatible with the Scheduler (e.g. DayPilot.Queue.events.add() is used to add a new task to the queue, just like DayPilot.Scheduler.events.add() is used to add a new event to the Angular Scheduler component).

HTML template:

<button (click)="addTask()">Add</button>
<daypilot-queue [config]="queueConfig" #queue></daypilot-queue>

TypeScript

export class SchedulerComponent implements AfterViewInit {

  @ViewChild('queue')
  queue!: DayPilotQueueComponent;

  queueConfig: DayPilot.QueueConfig = {
    emptyText: "No tasks",
  };

  async addTask(): Promise<void> {

    const durations = [
      {name: "1 hour", id: "60"},
      {name: "2 hours", id: "120"},
      {name: "3 hours", id: "180"},
      {name: "4 hours", id: "240"},
    ];

    const form = [
      {name: "Name", id: "text"},
      {name: "Duration", id: "minutes", type: "select", options: durations}
    ];
    const data= {
      text: "Task 1",
      minutes: 60
    };
    const modal = await DayPilot.Modal.form(form, data);

    if (modal.canceled) {
      return;
    }

    const e = modal.result;
    e.id = DayPilot.guid();
    e.duration = DayPilot.Duration.ofMinutes(e.minutes);

    this.queue.control.events.add(e);
  }

}

How to drag tasks from the Queue to the Scheduler?

angular scheduler drag tasks from the queue

The queue items are automatically marked as draggable. No extra steps are necessary if you want to drag them to the Scheduler.

The Scheduler will accept external items without any additional configuration changes.

The only thing you need to do is to detect the external source when the event is dropped at the target position in the Scheduler - and remove the item from the queue.

  • The Scheduler fires onEventMoved event handler when you drop the event. You need to check args.external value to detect is the item comes from the queue.

  • Then you need to remove the item from the queue using events.remove() method.

See the following example:

export class SchedulerComponent implements AfterViewInit {

  @ViewChild('scheduler')
  scheduler!: DayPilotSchedulerComponent;

  @ViewChild('queue')
  queue!: DayPilotQueueComponent;

  schedulerConfig: DayPilot.SchedulerConfig = {
    
    onEventMove: (args) => {
      if (args.external) {
        args.control.message("Moved from queue");
        this.queue.control.events.remove(args.e.data.id);
      }
    },
    
    // ...
    
  };

  constructor(private ds: DataService) {
  }

}

How to drag tasks from the Scheduler to the Queue?

angular scheduler drag tasks from the scheduler

By default, the Angular Scheduler doesn’t allow dragging events outside of the grid. You need to enable this behavior using dragOutAllowed property. No special configuration is required in the Queue - it will always accept the external item.

When the event is dropped in the queue, the Queue component will fire onEventMoved event handler. You can use the same logic that we used for the opposite direction - detect an external source and remove the source item from the Angular Scheduler.

export class SchedulerComponent implements AfterViewInit {

  @ViewChild('scheduler')
  scheduler!: DayPilotSchedulerComponent;

  @ViewChild('queue')
  queue!: DayPilotQueueComponent;

  queueConfig: DayPilot.QueueConfig = {
    emptyText: "No tasks",
    onEventMove: (args) => {
      if (args.external) {
        this.scheduler.control.events.remove(args.e.data.id);
      }
    },
  };

  schedulerConfig: DayPilot.SchedulerConfig = {
    dragOutAllowed: true,
    // ...
  };

  constructor(private ds: DataService) {
  }

}

How to change the task order in the Queue?

angular scheduler change task order in the queue

The queue supports reordering items. Simply start dragging the item - the target position will be highlighted using a thin horizontal line.

The target position is stored in args.position in onEventMoved event handler.

  • You can useit to update your backend using an HTTP call.

  • The queue handles the update automatically, you don’t need to explicitly change the task order in the data source.

export class SchedulerComponent implements AfterViewInit {

  @ViewChild('scheduler')
  scheduler!: DayPilotSchedulerComponent;

  @ViewChild('queue')
  queue!: DayPilotQueueComponent;

  queueConfig: DayPilot.QueueConfig = {
    emptyText: "No tasks",
    onEventMove: (args) => {
      if (args.external) {
        // ...
      }
      else {
        console.log("target position", args.position);
      }
    },
  };


}