2.0.0 • Published 1 year ago

ngx-time-scheduler v2.0.0

Weekly downloads
144
License
MIT
Repository
github
Last release
1 year ago

Angular Time Scheduler

GitHub issues GitHub forks GitHub stars GitHub license latest npm

A simple Angular Timeline Scheduler library

Installation

Install via NPM

npm i ngx-time-scheduler

Note: v2.0.0 is compatible with Angular v15.0.0+

Getting Started

Import the NgxTimeSchedulerModule in your app module.

import {NgxTimeSchedulerModule} from 'ngx-time-scheduler';

@NgModule({
  imports: [
    BrowserModule,
    NgxTimeSchedulerModule,
  ],
  ...
})
export class AppModule {
}

Use ngx-ts in your app-component.html template.

<ngx-ts
  [items]="items"
  [periods]="periods"
  [sections]="sections"
  [events]="events"
  [showBusinessDayOnly]="false"
  [allowDragging]="true"
></ngx-ts>

And in your app.component.ts component class:

import {Component, OnInit} from '@angular/core';
import {Item, Period, Section, Events, NgxTimeSchedulerService} from 'ngx-time-scheduler';
import * as moment from 'moment';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
  events: Events = new Events();
  periods: Period[];
  sections: Section[];
  items: Item[];

  constructor(private service: NgxTimeSchedulerService) {
  }

  ngOnInit() {
    this.events.SectionClickEvent = (section) => {
      console.log(section);
    };
    this.events.ItemClicked = (item) => {
      console.log(item);
    };
    this.events.ItemDropped = (item) => {
      console.log(item);
    };

    this.periods = [
      {
        name: '3 days',
        timeFramePeriod: (60 * 3),
        timeFrameOverall: (60 * 24 * 3),
        timeFrameHeaders: [
          'Do MMM',
          'HH'
        ],
        classes: 'period-3day'
      }, {
        name: '1 week',
        timeFrameHeaders: ['MMM YYYY', 'DD(ddd)'],
        classes: '',
        timeFrameOverall: 1440 * 7,
        timeFramePeriod: 1440,
      }, {
        name: '2 week',
        timeFrameHeaders: ['MMM YYYY', 'DD(ddd)'],
        classes: '',
        timeFrameOverall: 1440 * 14,
        timeFramePeriod: 1440,
      }];

    this.sections = [{
      name: 'A',
      id: 1
    }, {
      name: 'B',
      id: 2
    }, {
      name: 'C',
      id: 3
    }, {
      name: 'D',
      id: 4
    }, {
      name: 'E',
      id: 5
    }];

    this.items = [{
      id: 1,
      sectionID: 1,
      name: 'Item 1',
      start: moment().startOf('day'),
      end: moment().add(5, 'days').endOf('day'),
      classes: ''
    }, {
      id: 2,
      sectionID: 3,
      name: 'Item 2',
      start: moment().startOf('day'),
      end: moment().add(4, 'days').endOf('day'),
      classes: ''
    }, {
      id: 3,
      sectionID: 1,
      name: 'Item 3',
      start: moment().add(1, 'days').startOf('day'),
      end: moment().add(3, 'days').endOf('day'),
      classes: ''
    }];

  }

  addItem() {
    this.service.itemPush({
      id: 4,
      sectionID: 5,
      name: 'Item 4',
      start: moment().startOf('day'),
      end: moment().add(3, 'days').endOf('day'),
      classes: ''
    });
  }

  popItem() {
    this.service.itemPop();
  }

  removeItem() {
    this.service.itemRemove(4);
  }

}

Inputs

NameRequiredTypeDefaultDescription
periodsYesPeriod[]nullAn array of Period denoting what periods to display and use to traverse the calendar.
sectionsYesSection[]nullAn array of Section to fill up the sections of the scheduler.
itemsYesItem[]nullAn array of Item to fill up the items of the scheduler.
eventsNoEventsnew Events()The events that can be hooked into.
currentTimeFormatNostring'DD-MMM-YYYY HH:mm'The momentjs format to use for concise areas, such as tooltips.
showHeaderTitleNobooleantrueWhether the header title should be displayed.
showActionButtonsNobooleantrueWhether the buttons on header should be displayed.
showCurrentTimeNobooleantrueWhether the current time should be marked on the scheduler.
showGotoNobooleantrueWhether the Goto button should be displayed.
showTodayNobooleantrueWhether the Today button should be displayed.
showBusinessDayOnlyNobooleanfalseWhether business days only displayed (Sat-Sun).
allowDraggingNobooleanfalseWhether or not dragging should be allowed.
headerFormatNostring'Do MMM YYYY'The momentjs format to use for the date range displayed as a header.
minRowHeightNonumber40The minimum height, in pixels, that a section should be.
maxHeightNonumbernullThe maximum height of the scheduler.
textNoTextnew Text()An object containing the text use in the scheduler, to be easily customized.
startNomomentmoment().startOf('day')The start time of the scheduler as a moment object. It's recommend to use .startOf('day') on the moment for a clear starting point.
localeNostring (empty === 'en') | To load a locale, pass the key and the string values to moment.locale. By default, Moment.js uses English (United States) locale strings.

NOTE: Date locale is currently not available for Goto(button) datepicker. It will apply a date locale as per the user's system setting. Feel free to provide suggestions.

Methods

Object with properties which create periods that can be used to traverse the calendar.

NameParameterReturn TypeDescription
itemPushitem: ItemvoidPush the new item object into the existing one.
itemPopNonevoidPop the last item from the existing one.
itemRemoveid: numbervoidRemove the item with defined item id from the existing one.
sectionPushsection: SectionvoidPush the new section object into the existing one.
sectionPopNonevoidPop the last section from the existing one.
sectionRemoveid: numbervoidRemove the section with defined section id from the existing one.
refreshNonevoidRefresh the scheduler view.

Models

Period

Object with properties which create periods that can be used to traverse the calendar.

NameTypeRequiredDefaultDescription
namestringYesnullThe name is use to select the period and should be unique.
classesstringYesnullAny css classes you wish to add to this item.
timeFramePeriodnumberYesnullThe number of minutes between each "Timeframe" of the period.
timeFrameOverallnumberYesnullThe total number of minutes that the period shows.
timeFrameHeadersstring[]YesnullAn array of momentjs formats which is use to display the header rows at the top of the scheduler. Rather than repeating formats, the scheduler will merge all cells which are followed by a cell which shows the same date. For example, instead of seeing "Tuesday, Tuesday, Tuesday" with "3pm, 6pm, 9pm" below it, you'll instead see "Tuesday" a single time.
timeFrameHeadersTooltipstring[]NonullAn array of momentjs formats which is use to display the tooltip of the header rows at the top of the scheduler. Rather than repeating formats, the scheduler will merge all cells which are followed by a cell which shows the same date. For example, instead of seeing "Tuesday, Tuesday, Tuesday" with "3pm, 6pm, 9pm" below it, you'll instead see "Tuesday" a single time.
tooltipstringNonullIt is use to display tooltip on period button.

Section

Sections used to fill the scheduler.

NameTypeRequiredDefaultDescription
idnumberYesnullA unique identifier for the section.
namestringYesnullThe name to display for the section.
tooltipstringNonullIt is use to display tooltip for the section.

Item

Items used to fill the scheduler.

NameTypeRequiredDefaultDescription
idnumberYesnullAn identifier for the item (doesn't have to be unique, but may help you identify which item was interacted with).
namestringYesnullThe name to display for the item.
startanyYesnullA Moment object denoting where this object starts.
endanyYesnullA Moment object denoting where this object ends.
classesstringYesnullAny css classes you wish to add to this item.
sectionIDnumberYesnullThe ID of the section that this item belongs to.
tooltipstringNonullIt is use to display tooltip for the section.

Text

An object containing the text use in the scheduler, to be easily customized.

NameTypeDefault
NextButtonstring'Next'
PrevButtonstring'Prev'
TodayButtonstring'Today'
GotoButtonstring'Go to'
SectionTitlestring'Section'
HeaderTitlestringnull

Events

A selection of events are provided to hook into when creating the scheduler, and are triggered with most interactions with items.

NameParametersReturn typeDescription
ItemClickeditem: ItemvoidTriggered when an item is clicked.
ItemContextMenuitem: Item, event: MouseEventvoidTriggered when an item is righted click (Context Menu).
SectionClickEventsection: SectionvoidTriggered when a section is clicked.
SectionContextMenuEventsection: Section, event: MouseEventvoidTriggered when a section is righted click (Context Menu).
ItemDroppeditem: ItemvoidTriggered when an item is dropped onto a section. item is the new data after the action.
PeriodChangestart: moment.Moment, end: moment.MomentvoidTriggered when an period is change.

NOTE: To prevent the default context menu of the browser, use event.preventDefault() in an event.ItemContextMenu() or event.SectionContextMenuEvent() function.

Demo

Demo

Credits

This time scheduler is based on the work done by Zallist.

License

MIT license

2.0.0

1 year ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago