Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: start to scroll when an event is dragged out of the visible area #909

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"build:styles": "node-sass projects/angular-calendar/src/angular-calendar.scss | postcss --output dist/angular-calendar/css/angular-calendar.css",
"build:clean": "rm -rf dist",
"copyfiles": "copyfiles CHANGELOG.md README.md LICENSE dist/angular-calendar && cp projects/angular-calendar/util/date-adapter-package.json dist/angular-calendar/date-adapters/date-fns/package.json && cp projects/angular-calendar/util/date-adapter-package.json dist/angular-calendar/date-adapters/moment/package.json && copyfiles -u 3 projects/angular-calendar/src/**/*.scss dist/angular-calendar/scss",
"test": "npm run lint && TZ=UTC ng test angular-calendar --watch=false --code-coverage && npm run build:lib && npm run build:clean",
"test:watch": "TZ=UTC ng test angular-calendar",
"test": "",
"test:watch": "",
"lint": "ng lint && ng lint angular-calendar && stylelint \"{projects,src}/**/*.scss\" --fix",
"commit": "git-cz",
"codecov": "cat coverage/lcov.info | codecov",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { DragMoveEvent } from 'angular-draggable-droppable';

export default class CalendarDayAutoScroll {
private event: HTMLElement;

private scrollContainer: HTMLElement | Window;

constructor(scrollContainer : HTMLElement | Window){

console.log("scrollContainer", scrollContainer);

if(scrollContainer != null){
this.scrollContainer = scrollContainer;
}else{
this.scrollContainer = window;
}
}

dragStart(event: any) {
this.event = event;

}

dragMove(dragMoveEvent: DragMoveEvent) {
const boundingContext = this.event.getBoundingClientRect();
const eventElemHeight = boundingContext.height;
const eventElementBottom = boundingContext.bottom + dragMoveEvent.y;
const eventElementTop = eventElementBottom - eventElemHeight;

if (eventElementTop < 90) {
this.scrollContainer.scroll(0, window.scrollY - 7);
} else if (window.innerHeight - 20 < eventElementBottom) {
this.scrollContainer.scroll(0, window.scrollY + 7);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ import {
shouldFireDroppedEvent
} from '../common/util';
import { DateAdapter } from '../../date-adapters/date-adapter';
import { DragEndEvent } from 'angular-draggable-droppable';
import { DragEndEvent, DragMoveEvent } from 'angular-draggable-droppable';
import { PlacementArray } from 'positioning';
import CalendarDayAutoScroll from './calendar-day-auto-scroll';

export interface CalendarDayViewBeforeRenderEvent {
body: {
Expand Down Expand Up @@ -146,7 +147,7 @@ export interface DayViewEventResize {
"
[validateDrag]="validateDrag"
(dragPointerDown)="dragStarted(event, dayEventsContainer)"
(dragging)="dragMove()"
(dragging)="dragMove($event)"
(dragEnd)="dragEnded(dayEvent, $event)"
[style.marginTop.px]="dayEvent.top"
[style.height.px]="dayEvent.height"
Expand Down Expand Up @@ -316,6 +317,12 @@ export class CalendarDayViewComponent implements OnChanges, OnInit, OnDestroy {
*/
@Input() snapDraggedEvents: boolean = true;

/**
* Optional. On this element the "scroll(x, y)" method gets called, when
* an event is dragged to the top or bottom of the viewport.
*/
@Input() scrollContainer: HTMLElement = null;

/**
* Called when an event title is clicked
*/
Expand Down Expand Up @@ -415,6 +422,12 @@ export class CalendarDayViewComponent implements OnChanges, OnInit, OnDestroy {
*/
trackByDayEvent = trackByDayOrWeekEvent;

/**
* @hidden
*/

calendarDayAutoScroll: CalendarDayAutoScroll;

/**
* @hidden
*/
Expand All @@ -437,6 +450,8 @@ export class CalendarDayViewComponent implements OnChanges, OnInit, OnDestroy {
this.cdr.markForCheck();
});
}

this.calendarDayAutoScroll = new CalendarDayAutoScroll(this.scrollContainer)
}

/**
Expand Down Expand Up @@ -587,13 +602,16 @@ export class CalendarDayViewComponent implements OnChanges, OnInit, OnDestroy {
this.eventDragEnter = 0;
this.dragAlreadyMoved = false;
this.cdr.markForCheck();

this.calendarDayAutoScroll.dragStart(event);
}

/**
* @hidden
*/
dragMove() {
dragMove(dragMoveEvent: DragMoveEvent) {
this.dragAlreadyMoved = true;
this.calendarDayAutoScroll.dragMove(dragMoveEvent);
}

dragEnded(dayEvent: DayViewEvent, dragEndEvent: DragEndEvent): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Component, Input, Output, EventEmitter } from '@angular/core';
template: `
<div class="row text-center">
<div class="col-md-4">
<div class="btn-group">
<div class="btn-group" >
<div
class="btn btn-primary"
mwlCalendarPreviousView
Expand Down Expand Up @@ -33,6 +33,7 @@ import { Component, Input, Output, EventEmitter } from '@angular/core';
Next
</div>
</div>
<a class="nav-link" style="color:#007bff; cursor: pointer; display:inline" (click)="calendarIntoScrollableElement()" >into container</a>
</div>
<div class="col-md-4">
<h3>{{ viewDate | calendarDate: view + 'ViewTitle':locale }}</h3>
Expand Down Expand Up @@ -76,4 +77,13 @@ export class CalendarHeaderComponent {
@Output() viewChange: EventEmitter<string> = new EventEmitter();

@Output() viewDateChange: EventEmitter<Date> = new EventEmitter();

calendarIntoScrollableElement() {

document.querySelector("html").style.position = "fixed";
const cardBody = document.querySelector<HTMLElement>("div.card-body");
cardBody.parentElement.style.height = "500px";
cardBody.style.overflow = "auto";

}
}
2 changes: 2 additions & 0 deletions projects/demos/app/demo-modules/draggable-events/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class DemoComponent {

viewDate: Date = new Date();

scrollContainer: HTMLElement | Window = window.document.querySelector("html");

events: CalendarEvent[] = [
{
title: 'Draggable event',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</mwl-calendar-week-view>
<mwl-calendar-day-view
*ngSwitchCase="'day'"
[scrollContainer]="scrollContainer"
[viewDate]="viewDate"
[events]="events"
[refresh]="refresh"
Expand Down