19.0.0 • Published 4 months ago

ngx-resource-timeline v19.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Angular Resource Timeline

GitHub issues GitHub forks GitHub stars GitHub license Latest Version Downloads

A simple Angular timeline scheduler library, now reimagined as Angular Resource Timeline.


Compatibility

This release is v19.0.0 and is compatible with Angular 19. Future releases will target newer Angular versions.

Library VersionAngular CompatibilityNotes
19.0.0Angular 19Latest release
18.0.0Angular 18Legacy release
17.0.0Angular 17Legacy release
16.0.0Angular 16Legacy release
15.0.2Angular 15Legacy release
Upcoming-Planned releases for newer Angular versions

Installation

Install via npm:

npm i ngx-resource-timeline

Note: Version v19.0.0 is compatible with Angular v19.0.0.


Getting Started

1. Import the NgxResourceTimelineModule

In your app module, import the module from ngx-resource-timeline:

import { NgxResourceTimelineModule } from 'ngx-resource-timeline';

@NgModule({
  imports: [
    BrowserModule,
    NgxResourceTimelineModule,
  ],
  // ... other properties
})
export class AppModule { }

2. Use the <ngx-rt> Component

Add the <ngx-rt> component in your template (e.g., app.component.html):

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

3. Configure Your Component

Set up your component (e.g., app.component.ts) as follows:

import { Component, OnInit } from '@angular/core';
import { Item, Period, Section, Events, NgxResourceTimelineService } from 'ngx-resource-timeline';
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: NgxResourceTimelineService) { }

  ngOnInit() {
    this.events.SectionClickEvent = (section) => console.log('Section clicked:', section);
    this.events.ItemClicked = (item) => console.log('Item clicked:', item);
    this.events.ItemDropped = (item) => console.log('Item dropped:', 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 objects defining the periods to display and traverse.
sectionsYesSection[]nullAn array of Section objects to populate the timeline.
itemsYesItem[]nullAn array of Item objects to render on the timeline.
eventsNoEventsnew Events()An object containing events for user interactions.
currentTimeFormatNostring'DD-MMM-YYYY HH:mm'The moment.js format used for concise areas such as tooltips.
showHeaderTitleNobooleantrueControls the display of the header title.
showActionButtonsNobooleantrueControls the display of header action buttons.
showCurrentTimeNobooleantrueDetermines if the current time is marked on the timeline.
showGotoNobooleantrueDetermines if the Goto button is displayed.
showTodayNobooleantrueDetermines if the Today button is displayed.
showBusinessDayOnlyNobooleanfalseIf true, only business days (Mon-Fri) are displayed.
allowDraggingNobooleanfalseIf true, items can be dragged.
headerFormatNostring'Do MMM YYYY'The moment.js format for the header's date range display.
minRowHeightNonumber40The minimum height (in pixels) for a section.
maxHeightNonumbernullThe maximum height of the timeline.
textNoTextnew Text()An object for customizing textual elements in the timeline.
startNomomentmoment().startOf('day')The timeline's start time; it is recommended to use the start of the day.
localeNostring(empty, defaults to 'en')Sets the locale for moment.js. Defaults to English (United States).

NOTE: Date locale is not available for the Goto button datepicker; it will default to the user's system settings. Suggestions are welcome.


Methods

Use these methods to dynamically manipulate items and sections:

NameParameterReturn TypeDescription
itemPushitem: ItemvoidAdds a new item to the timeline.
itemPopNonevoidRemoves the last item from the timeline.
itemRemoveid: numbervoidRemoves the item with the specified ID.
sectionPushsection: SectionvoidAdds a new section to the timeline.
sectionPopNonevoidRemoves the last section from the timeline.
sectionRemoveid: numbervoidRemoves the section with the specified ID.
refreshNonevoidRefreshes/re-renders the timeline view.

Models

Period

NameTypeRequiredDefaultDescription
namestringYesnullThe unique name for selecting this period.
classesstringYesnullAny CSS classes to apply to this period.
timeFramePeriodnumberYesnullThe interval (in minutes) between time frames.
timeFrameOverallnumberYesnullThe total number of minutes this period covers.
timeFrameHeadersstring[]YesnullAn array of moment.js formats for header rows; merged if identical.
timeFrameHeadersTooltipstring[]NonullFormats for header tooltips.
tooltipstringNonullTooltip text for the period button.

Section

NameTypeRequiredDefaultDescription
idnumberYesnullA unique identifier for the section.
namestringYesnullThe display name for the section.
tooltipstringNonullTooltip text for the section.

Item

NameTypeRequiredDefaultDescription
idnumberYesnullAn identifier for the item (need not be globally unique).
namestringYesnullThe display name for the item.
startanyYesnullA moment.js object indicating when the item starts.
endanyYesnullA moment.js object indicating when the item ends.
classesstringYesnullAny CSS classes to apply to the item.
sectionIDnumberYesnullThe ID of the section the item belongs to.
tooltipstringNonullTooltip text for the item.

Text

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

Events

NameParametersReturn TypeDescription
ItemClickeditem: ItemvoidTriggered when an item is clicked.
ItemContextMenuitem: Item, event: MouseEventvoidTriggered when an item is right-clicked (context menu).
SectionClickEventsection: SectionvoidTriggered when a section is clicked.
SectionContextMenuEventsection: Section, event: MouseEventvoidTriggered when a section is right-clicked (context menu).
ItemDroppeditem: ItemvoidTriggered when an item is dropped; item reflects its updated state.
PeriodChangestart: moment.Moment, end: moment.MomentvoidTriggered when the displayed period changes (e.g., via Next/Prev buttons).

NOTE: To prevent the default browser context menu, call event.preventDefault() in your ItemContextMenu or SectionContextMenuEvent handlers.


Demo

Demo


Credits

This project is based on the work originally created by Zallist and further developed by abhishekjain12.
Angular Resource Timeline updates this work to support Angular 15, Angular 16, Angular 17, Angular 18 and Angular 19. Future releases will target newer Angular versions.


License

Released under the MIT License.


Enjoy using Angular Resource Timeline! If you find it useful, please star the repository, submit issues, or contribute.

19.0.0

4 months ago

18.0.0

4 months ago

17.0.1

4 months ago

17.0.0

4 months ago

16.0.1

5 months ago

16.0.0

5 months ago

15.0.2

5 months ago

15.0.1

5 months ago

15.0.0

5 months ago