import { Component, ViewChild } from "@angular/core";
import { DataManager, WebApiAdaptor } from "@syncfusion/ej2-data";
import { TreeViewComponent, DragAndDropEventArgs } from "@syncfusion/ej2-angular-navigations";
import {
ScheduleComponent,
View,
EventSettingsModel,
GroupModel,
DragEventArgs,
ResizeEventArgs,
CellClickEventArgs,
ResourceDetails
} from "@syncfusion/ej2-angular-schedule";
@Component({
selector: "app-root",
templateUrl: "app.component.html",
})
export class AppComponent {
title = "testSync";
@ViewChild("scheduleObj", { static: false })
public scheduleObj: ScheduleComponent;
public setView: View = "TimelineDay";
public setViews: View[] = ["TimelineDay", "TimelineWeek", "TimelineMonth"];
public setDate: Date = new Date(2020, 2, 11);
public allowMultipleResource: Boolean = true;
public resourceDataSource: Object[] = [
{ Name: "SAV", Id: 1, Color: "#ffaa00" },
{ Name: "Livraison", Id: 2, Color: "#f8a398" },
{ Name: "Maintenance", Id: 3, Color: "#7499e1" }
];
public groupDataSource: Object[] = [
{ Name: "Jean-Michel", Id: 1, Color: "red", GroupID: 1 },
{ Name: "René", Id: 2, Color: "green", GroupID: 2 },
{ Name: "Joël", Id: 3, Color: "yellow", GroupID: 2 }
];
public groupData: GroupModel = {
resources: ["ResourcesUbi", "GroupsUbi"],
allowGroupEdit: true
};
public eventObject: EventSettingsModel = {
dataSource: [
{
Id: 1,
Subject: "Test Planning",
StartTime: new Date(2020, 2, 11, 12, 0),
EndTime: new Date(2020, 2, 11, 13, 0),
Location: "Ubiwan",
ResourceID: 1,
GroupID: 1
},
{
Id: 2,
Subject: "Test Planning 2",
StartTime: new Date(2020, 2, 11, 13, 0),
EndTime: new Date(2020, 2, 11, 16, 0),
Location: "Ubiwan",
ResourceID: 2,
GroupID: 3
}
],
fields: {
subject: { name: "Subject", default: "Nouvel événement" },
location: { name: "Location", validation: { required: true } }
}
};
public waitingList: { [key: string]: Object }[] = [
{
Id: 1,
Name: "Dépot marchandise"
},
{
Id: 2,
Name: "Récupération marchandise"
},
{
Id: 3,
Name: "RDV exterieur"
},
{
Id: 4,
Name: "Passer chez Ubiwan"
},
{
Id: 5,
Name: "Installation"
},
{
Id: 6,
Name: "Réparation"
}
];
public field: Object = {
dataSource: this.waitingList,
id: "Id",
text: "Name"
};
public allowDragAndDrop: boolean = true;
onDragStart(args: DragEventArgs): void {
args.scroll.enable = false;
args.interval = 10;
}
onActionBegin(args) {
if (
args.requestType === "eventCreate" ||
args.requestType === "eventChange"
) {
var data = args.requestType === "eventCreate" ? args.data[0] : args.data;
var groupIndex = this.scheduleObj.eventBase.getGroupIndexFromEvent(data);
console.log("groupIndex from OnActionBegin", groupIndex);
if (
this.scheduleObj.isSlotAvailable(
data.StartTime as Date,
data.EndTime as Date,
groupIndex as number
)
) {
console.log("Slot is available");
} else {
args.cancel = true;
alert("Slot isn't available");
}
}
console.log('eventObject.dataSource', this.eventObject.dataSource);
}
onResizeStart(args: ResizeEventArgs): void {
args.scroll.scrollBy = 500;
args.interval = 10;
}
onTreeDragStop(args: DragAndDropEventArgs): void {
let cellData: CellClickEventArgs = this.scheduleObj.getCellDetails(
args.target
);
let resourceDetails: ResourceDetails = this.scheduleObj.getResourcesByIndex(
cellData.groupIndex
);
let eventData: { [key: string]: Object } = {
Subject: args.draggedNodeData.text,
StartTime: cellData.startTime,
EndTime: cellData.endTime,
IsAllDay: cellData.isAllDay,
ResourceID: resourceDetails.resourceData.GroupID,
GroupID: resourceDetails.resourceData.Id
};
const groupIndex = cellData.groupIndex;
console.log("groupIndex from onTreeDragStop", groupIndex);
if (
this.scheduleObj.isSlotAvailable(
eventData.StartTime as Date,
eventData.EndTime as Date,
groupIndex as number
)
) {
console.log("Slot is available");
this.scheduleObj.openEditor(eventData, "Add", true);
} else {
args.cancel = true;
alert("Slot isn't available");
}
}
}