Employee Shift Scheduling

Use the summary mode of the timeline view with eventDisplay: 'fill' that can be configured under the timeline settings of the view option.

This will give you summarized daily events similar to the event calendar labels where each event is printed under the appropriate day, time slot (shift) for the appropriate resource one after the other.

Build a custom add/edit dialog with the necessary fields. The event dialog can be fully custom as seen in this CRUD example.

Customize the dialog header with a custom template using the headerTemplate option.

Get started with this example

Demo

Loading the live demo

Preview in full screen

Plan employee shifts on a Timeline — show workers as resource rows with morning and afternoon slots, and manage shifts with a custom add/edit dialog.

Code

import { CommonModule } from '@angular/common';
import { Component, ViewChild } from '@angular/core';
import { FormsModule } from '@angular/forms';
import {
  formatDate,
  MbscCalendarEvent,
  MbscDatepickerValue,
  MbscEventcalendarView,
  MbscEventClickEvent,
  MbscEventCreatedEvent,
  MbscEventDeletedEvent,
  MbscEventUpdatedEvent,
  MbscModule,
  MbscPopup,
  MbscPopupButton,
  MbscPopupOptions,
  MbscResource,
  MbscSlot,
  Notifications,
  setOptions ,
} from '@mobiscroll/angular';

setOptions({
  locale:  ,
  theme: ' ',
  themeVariant: ' '
});

@Component({
  selector: 'app-root', 
  templateUrl: './app.component.html',
  providers: [Notifications],
  standalone: true,
  imports: [CommonModule, FormsModule, MbscModule],
})
export class AppComponent {
  constructor(private notify: Notifications) {}

  @ViewChild('popup', { static: false })
  popup!: MbscPopup;

  deletedShift!: MbscCalendarEvent;
  isEdit = false;
  minTime = '';
  maxTime = '';
  shift!: MbscCalendarEvent;
  shiftDates?: MbscDatepickerValue;
  shiftNotes?: string;
  headerPrimary = '';
  headerDate = '';

  popupButtons: (MbscPopupButton | 'cancel')[] = [];

  popupResponsive: Record<string, MbscPopupOptions> = {
    medium: {
      display: 'center',
      fullScreen: false,
      touchUi: false,
      width: 400,
    },
  };

  staff: MbscResource[] = [
    {
      id: 1,
      name: 'Ryan',
      color: '#e20000',
      title: 'Cloud System Engineer',
      img: 'https://img.mobiscroll.com/demos/m1.png',
    },
    {
      id: 2,
      name: 'Kate',
      color: '#60e81a',
      title: 'Help Desk Specialist',
      img: 'https://img.mobiscroll.com/demos/f1.png',
    },
    {
      id: 3,
      name: 'John',
      color: '#3ba7ff',
      title: 'Application Developer',
      img: 'https://img.mobiscroll.com/demos/m2.png',
    },
    {
      id: 4,
      name: 'Mark',
      color: '#e25dd2',
      title: 'Network Administrator',
      img: 'https://img.mobiscroll.com/demos/m3.png',
    },
    {
      id: 5,
      name: 'Sharon',
      color: '#f1e920',
      title: 'Data Quality Manager',
      img: 'https://img.mobiscroll.com/demos/f2.png',
    },
    {
      id: 6,
      name: 'Emma',
      color: '#1ac38d',
      title: 'Product Tactics Agent',
      img: 'https://img.mobiscroll.com/demos/f3.png',
    },
    {
      id: 7,
      name: 'Michael',
      color: '#f18a1a',
      title: 'UX Designer',
      img: 'https://img.mobiscroll.com/demos/m4.png',
    },
    {
      id: 8,
      name: 'Laura',
      color: '#7b61ff',
      title: 'DevOps Engineer',
      img: 'https://img.mobiscroll.com/demos/f4.png',
    },
  ];

  shifts: MbscCalendarEvent[] = [
    {
      start: '2026-10-27T07:00',
      end: '2026-10-27T13:00',
      title: '07:00 - 13:00',
      resource: 1,
      slot: 1,
    },
    {
      start: '2026-10-27T07:00',
      end: '2026-10-27T13:00',
      title: '07:00 - 13:00',
      resource: 7,
      slot: 1,
    },
    {
      start: '2026-10-27T12:00',
      end: '2026-10-27T18:00',
      title: '12:00 - 18:00',
      resource: 3,
      slot: 2,
    },
    {
      start: '2026-10-27T12:00',
      end: '2026-10-27T18:00',
      title: '12:00 - 18:00',
      resource: 8,
      slot: 2,
    },
    {
      start: '2026-10-28T07:00',
      end: '2026-10-28T13:00',
      title: '07:00 - 13:00',
      resource: 4,
      slot: 1,
    },
    // Showing partial data. Download full source.
  ];

  myView: MbscEventcalendarView = {
    timeline: {
      type: 'week',
      eventDisplay: 'fill',
      startDay: 1,
      endDay: 5,
    },
  };

  getShiftTimes(event: MbscCalendarEvent) {
    const d = event.start as Date;
    const start = new Date(d.getFullYear(), d.getMonth(), d.getDate(), event.slot === 1 ? 7 : 12);
    const end = new Date(d.getFullYear(), d.getMonth(), d.getDate(), event.slot === 1 ? 13 : 18);

    return {
      title: formatDate('HH:mm', start) + ' - ' + formatDate('HH:mm', end),
      start: start,
      end: end,
    };
  }

  fillPopup(event: MbscCalendarEvent, isEdit: boolean) {
    this.isEdit = isEdit;
    this.minTime = event.slot === 1 ? '07:00' : '12:00';
    this.maxTime = event.slot === 1 ? '13:00' : '18:00';
    this.shift = event;
    this.shiftDates = [new Date(event.start as Date), new Date(event.end as Date)];
    this.shiftNotes = event['notes'];
  }

  deleteEvent(event: MbscCalendarEvent) {
    this.shifts = this.shifts.filter((s) => s.id !== event.id);
    this.notify.snackbar({
      button: {
        action: () => {
          this.shifts = [...this.shifts, event];
        },
        text: 'Undo',
      },
      message: 'Shift deleted',
    });
  }

  updateEvent(event: MbscCalendarEvent) {
    const index = this.shifts.findIndex((s) => s.id === event.id);
    const newShifts = [...this.shifts];

    newShifts.splice(index, 1, event);

    this.shifts = newShifts;
  }

  saveEvent(event: MbscCalendarEvent) {
    const dates = this.shiftDates as Date[];
    const start = dates[0];
    const end = dates[1] ? dates[1] : dates[0];

    const shiftStart = new Date(event.start as Date);
    const shiftEnd = new Date(event.end as Date);

    shiftStart.setHours(start.getHours(), start.getMinutes(), 0, 0);
    shiftEnd.setHours(end.getHours(), end.getMinutes(), 0, 0);

    event.start = shiftStart;
    event.end = shiftEnd;
    event.title = formatDate('HH:mm', start) + ' - ' + formatDate('HH:mm', end);
    event['notes'] = this.shiftNotes;

    if (this.isEdit) {
      this.updateEvent(event);
    } else {
      // Add the new event to the list
      this.shifts = [...this.shifts, event];
    }
    this.popup.close();
  }

  handleEventClick(args: MbscEventClickEvent) {
    const event = args.event;
    const resource = args.resourceObj!;
    const slot = args.slotObj!;

    this.fillPopup(event, true);
    this.popupButtons = [
      'cancel',
      {
        handler: () => {
          this.saveEvent(event);
        },
        keyCode: 'enter',
        text: 'Save',
        cssClass: 'mbsc-popup-button-primary',
      },
    ];
    this.headerPrimary = 'Edit ' + resource.name + "'s hours";
    this.headerDate =
      formatDate('DDDD', new Date(event.start as Date)) + ' ' + slot.name + ', ' + formatDate('D MMMM YYYY', new Date(event.start as Date));
    this.popup.open();
  }

  handleEventCreated(args: MbscEventCreatedEvent) {
    setTimeout(() => {
      const event = args.event;
      const slot = args.slotObj!;

      this.fillPopup(event, false);
      this.popupButtons = [
        'cancel',
        {
          handler: () => {
            this.saveEvent(event);
          },
          keyCode: 'enter',
          text: 'Add',
          cssClass: 'mbsc-popup-button-primary',
        },
      ];
      this.headerPrimary = 'New shift';
      this.headerDate =
        formatDate('DDDD', new Date(event.start as Date)) +
        ' ' +
        slot.name +
        ', ' +
        formatDate('D MMMM YYYY', new Date(event.start as Date));
      this.popup.open();
    });
  }

  handleEventCreateFailed() {
    this.notify.toast({ message: "Can't create shift" });
  }

  handleEventDeleted(args: MbscEventDeletedEvent) {
    setTimeout(() => {
      this.deleteEvent(args.event);
    });
  }

  handleEventUpdated(args: MbscEventUpdatedEvent) {
    setTimeout(() => {
      const shift = args.event;
      if (shift.slot !== args.oldEvent!.slot) {
        const data = this.getShiftTimes(shift);
        shift.start = data.start;
        shift.end = data.end;
        shift.title = data.title;
        this.updateEvent(shift);
      }
    });
  }

  handleEventUpdateFailed() {
    this.notify.toast({ message: "Can't move shift" });
  }

  handlePopupClose() {
    if (!this.isEdit) {
      // Remove event if popup is cancelled
      this.shifts = [...this.shifts];
    }
  }

  handleShiftDeleteClick() {
    this.deleteEvent(this.shift);
    this.popup.close();
  }
}

Duplicate Session

You have signed in on a different machine. To keep everything in sync, you have been signed out of this session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.

Duplicate Session

We noticed you are logged in on a different machine and have closed your old session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.