Giter VIP home page Giter VIP logo

ngx-time-scheduler's Introduction

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

Name Required Type Default Description
periods Yes Period[] null An array of Period denoting what periods to display and use to traverse the calendar.
sections Yes Section[] null An array of Section to fill up the sections of the scheduler.
items Yes Item[] null An array of Item to fill up the items of the scheduler.
events No Events new Events() The events that can be hooked into.
currentTimeFormat No string 'DD-MMM-YYYY HH:mm' The momentjs format to use for concise areas, such as tooltips.
showHeaderTitle No boolean true Whether the header title should be displayed.
showActionButtons No boolean true Whether the buttons on header should be displayed.
showCurrentTime No boolean true Whether the current time should be marked on the scheduler.
showGoto No boolean true Whether the Goto button should be displayed.
showToday No boolean true Whether the Today button should be displayed.
showBusinessDayOnly No boolean false Whether business days only displayed (Sat-Sun).
allowDragging No boolean false Whether or not dragging should be allowed.
headerFormat No string 'Do MMM YYYY' The momentjs format to use for the date range displayed as a header.
minRowHeight No number 40 The minimum height, in pixels, that a section should be.
maxHeight No number null The maximum height of the scheduler.
text No Text new Text() An object containing the text use in the scheduler, to be easily customized.
start No moment moment().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.
locale No string `` (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.

Name Parameter Return Type Description
itemPush item: Item void Push the new item object into the existing one.
itemPop None void Pop the last item from the existing one.
itemRemove id: number void Remove the item with defined item id from the existing one.
sectionPush section: Section void Push the new section object into the existing one.
sectionPop None void Pop the last section from the existing one.
sectionRemove id: number void Remove the section with defined section id from the existing one.
refresh None void Refresh the scheduler view.

Models

Period

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

Name Type Required Default Description
name string Yes null The name is use to select the period and should be unique.
classes string Yes null Any css classes you wish to add to this item.
timeFramePeriod number Yes null The number of minutes between each "Timeframe" of the period.
timeFrameOverall number Yes null The total number of minutes that the period shows.
timeFrameHeaders string[] Yes null An 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.
timeFrameHeadersTooltip string[] No null An 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.
tooltip string No null It is use to display tooltip on period button.

Section

Sections used to fill the scheduler.

Name Type Required Default Description
id number Yes null A unique identifier for the section.
name string Yes null The name to display for the section.
tooltip string No null It is use to display tooltip for the section.

Item

Items used to fill the scheduler.

Name Type Required Default Description
id number Yes null An identifier for the item (doesn't have to be unique, but may help you identify which item was interacted with).
name string Yes null The name to display for the item.
start any Yes null A Moment object denoting where this object starts.
end any Yes null A Moment object denoting where this object ends.
classes string Yes null Any css classes you wish to add to this item.
sectionID number Yes null The ID of the section that this item belongs to.
tooltip string No null It is use to display tooltip for the section.

Text

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

Name Type Default
NextButton string 'Next'
PrevButton string 'Prev'
TodayButton string 'Today'
GotoButton string 'Go to'
SectionTitle string 'Section'
HeaderTitle string null

Events

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

Name Parameters Return type Description
ItemClicked item: Item void Triggered when an item is clicked.
ItemContextMenu item: Item, event: MouseEvent void Triggered when an item is righted click (Context Menu).
SectionClickEvent section: Section void Triggered when a section is clicked.
SectionContextMenuEvent section: Section, event: MouseEvent void Triggered when a section is righted click (Context Menu).
ItemDropped item: Item void Triggered when an item is dropped onto a section. item is the new data after the action.
PeriodChange start: moment.Moment, end: moment.Moment void Triggered 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

ngx-time-scheduler's People

Contributors

abhishekjain12 avatar carlitoxenlaweb avatar koylee7 avatar koyyew avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngx-time-scheduler's Issues

Unable to get observable passed to Items list

Hello,

Angular 9.1.6

I have successfully mapped the sections variable to an observable, however the items variable refuses to work and is constantly "undefined", even though the variable can be found, and output to console.

Is this an issue of the latest angular? Do you have an example of the scheduler working with an observable call service?

Set "startdate" for a period

Hi!
Currently I only can create a timeline starting today. Is it possible to define the first date of a period. Example:
Today is 27.12. my period is one day (from 00:00-23:00). So my time scheduler shows
Screenshot 2020-12-27 205742

Above the time scheduler there is a datepicker where the user can select a date in past or future. When the user changes the date, I want to update the time scheduler to show the date selected.
Screenshot 2020-12-27 205921

Is this possible, if yes, where can I configure it?
Thanks in advance,
Daniela

Icons in Text

Hello, is it possible to accept html tag e.g. icons for Text customisation?

Thanks.

Bug on multiple items using same date

If you have few items the calendar display blocks as expected

image

But if you have a lot of data (more than 20 items) in the same section the calendar goes wrong

image

On the prev image exists 3 items in front of 1 item

Bug on 29th October

There seems to be a bug after Daylight-Saving-Time-Change on 29th October.

image

The same thing happens when time changes on the 31th march again. The day is completely missing
image

Context menu

A right click event for items would be great for adding context - menu for example

Items overlapped for the same section

Hey. There are occurences where the items for the same section overlaps. Below is the example:

this.sections = [{"id":1,"name":"Section 1","tooltip":"Section 1"}];

this.items = [
  {
    "id": 1,
    "sectionID": 1,
    "name": "Item 1",
    "start": moment("2020-07-01T16:00:00.000Z"),
    "end": moment("2020-07-10T16:00:00.000Z"),
    "classes": "occupied",
    "tooltip": "Item 1"
  },
  {
    "id": 2,
    "sectionID": 1,
    "name": "Item 2",
    "start": moment("2020-07-01T16:00:00.000Z"),
    "end": moment("2020-07-21T16:00:00.000Z"),
    "classes": "completed",
    "tooltip": "Item 2"
  },
  {
    "id": 3,
    "sectionID": 1,
    "name": "Item 3",
    "start": moment("2020-07-07T16:00:00.000Z"),
    "end": moment("2020-07-14T16:00:00.000Z"),
    "classes": "occupied",
    "tooltip": "Item 3"
  },
  {
    "id": 4,
    "sectionID": 1,
    "name": "Item 4",
    "start": moment("2020-07-12T16:00:00.000Z"),
    "end": moment("2020-07-17T16:00:00.000Z"),
    "classes": "completed",
    "tooltip": "Item 4"
  },
  {
    "id": 5,
    "sectionID": 1,
    "name": "Item 5",
    "start": moment("2020-07-14T16:00:00.000Z"),
    "end": moment("2020-07-19T16:00:00.000Z"),
    "classes": "completed",
    "tooltip": "Item 5"
  },
  {
    "id": 6,
    "sectionID": 1,
    "name": "Item 6",
    "start": moment("2020-07-14T16:00:00.000Z"),
    "end": moment("2020-07-19T16:00:00.000Z"),
    "classes": "completed",
    "tooltip": "Item 6"
  },
  {
    "id": 7,
    "sectionID": 1,
    "name": "Item 7",
    "start": moment("2020-07-14T16:00:00.000Z"),
    "end": moment("2020-07-19T16:00:00.000Z"),
    "classes": "completed",
    "tooltip": "Item 7"
  },
  {
    "id": 8,
    "sectionID": 1,
    "name": "Item 8",
    "start": moment("2020-07-15T16:00:00.000Z"),
    "end": moment("2020-07-21T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 8"
  },
  {
    "id": 9,
    "sectionID": 1,
    "name": "Item 9",
    "start": moment("2020-07-16T16:00:00.000Z"),
    "end": moment("2020-07-22T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 9"
  },
  {
    "id": 10,
    "sectionID": 1,
    "name": "Item 10",
    "start": moment("2020-07-18T16:00:00.000Z"),
    "end": moment("2020-07-24T16:00:00.000Z"),
    "classes": "completed",
    "tooltip": "Item 10"
  },
  {
    "id": 11,
    "sectionID": 1,
    "name": "Item 11",
    "start": moment("2020-07-19T16:00:00.000Z"),
    "end": moment("2020-07-25T16:00:00.000Z"),
    "classes": "completed",
    "tooltip": "Item 11"
  },
  {
    "id": 12,
    "sectionID": 1,
    "name": "Item 12",
    "start": moment("2020-07-19T16:00:00.000Z"),
    "end": moment("2020-07-24T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 12"
  },
  {
    "id": 13,
    "sectionID": 1,
    "name": "Item 13",
    "start": moment("2020-07-20T16:00:00.000Z"),
    "end": moment("2020-07-25T16:00:00.000Z"),
    "classes": "completed",
    "tooltip": "Item 13"
  },
  {
    "id": 14,
    "sectionID": 1,
    "name": "Item 14",
    "start": moment("2020-07-20T16:00:00.000Z"),
    "end": moment("2020-07-25T16:00:00.000Z"),
    "classes": "completed",
    "tooltip": "Item 14"
  },
  {
    "id": 15,
    "sectionID": 1,
    "name": "Item 15",
    "start": moment("2020-07-20T16:00:00.000Z"),
    "end": moment("2020-07-24T16:00:00.000Z"),
    "classes": "completed",
    "tooltip": "Item 15"
  },
  {
    "id": 16,
    "sectionID": 1,
    "name": "Item 16",
    "start": moment("2020-07-20T16:00:00.000Z"),
    "end": moment("2020-07-25T16:00:00.000Z"),
    "classes": "completed",
    "tooltip": "Item 16"
  },
  {
    "id": 17,
    "sectionID": 1,
    "name": "Item 17",
    "start": moment("2020-07-20T16:00:00.000Z"),
    "end": moment("2020-07-25T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 17"
  },
  {
    "id": 18,
    "sectionID": 1,
    "name": "Item 18",
    "start": moment("2020-07-23T16:00:00.000Z"),
    "end": moment("2020-07-29T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 18"
  },
  {
    "id": 19,
    "sectionID": 1,
    "name": "Item 19",
    "start": moment("2020-07-29T16:00:00.000Z"),
    "end": moment("2020-08-04T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 19"
  },
  {
    "id": 20,
    "sectionID": 1,
    "name": "Item 20",
    "start": moment("2020-07-30T16:00:00.000Z"),
    "end": moment("2020-08-05T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 20"
  },
  {
    "id": 21,
    "sectionID": 1,
    "name": "Item 21",
    "start": moment("2020-07-30T16:00:00.000Z"),
    "end": moment("2020-08-05T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 21"
  },
  {
    "id": 22,
    "sectionID": 1,
    "name": "Item 22",
    "start": moment("2020-08-05T16:00:00.000Z"),
    "end": moment("2020-08-11T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 22"
  },
  {
    "id": 23,
    "sectionID": 1,
    "name": "Item 23",
    "start": moment("2020-08-05T16:00:00.000Z"),
    "end": moment("2020-08-11T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 23"
  },
  {
    "id": 24,
    "sectionID": 1,
    "name": "Item 24",
    "start": moment("2020-08-05T16:00:00.000Z"),
    "end": moment("2020-08-11T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 24"
  },
  {
    "id": 25,
    "sectionID": 1,
    "name": "Item 25",
    "start": moment("2020-10-03T16:00:00.000Z"),
    "end": moment("2020-10-09T16:00:00.000Z"),
    "classes": "reserved",
    "tooltip": "Item 25"
  }
];

Move items time

It would be great to be able to move items in time aswell and not only between sections

Cannot read property 'nativeElement' of undefined

Hi,

Thanks for quick update regarding section pop/push and more.

I've upgraded the package and now i get following error:

image

Can this be due to mismatch of Angular version ? I'm using 9.1.2.

Regards.

Feature request: hide header

Hi!
I have just found this project and it is very promising and super easy to use. Is there a way to hide header and all previous and next and period buttons?
Thnx,
Janez

Calendar view bug at month's end

If you compare the header column '31 (SUN)' you will find the associated section column on the wrong position. Please check the attached picture.
ngxtimeschedulerJPG

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.