onDrop(event: CdkDragDrop<string[]>){
if(event.previousContainer === event.container){
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
}else{
var i = 0;
var i = this.checkIfItemIsInReports(event);
if(i === 0){
//if the object is comming from unselected reports
if(this.reportData1.length === 4){
if(this.reportData2.length === 4){
if(this.reportData3.length === 4){
if(this.reportData4.length === 4){
console.log("Hello admin, you need to add a new array.");
}else{
//add to array 4
console.log(4);
this.reportData4.push(event.previousContainer.data[event.previousIndex]);
this.dragAndDropService.changeReport4(this.reportData4);
}
}else{
//add to array 3
console.log(3);
this.reportData3.push(event.previousContainer.data[event.previousIndex]);
this.dragAndDropService.changeReport3(this.reportData3);
}
}else{
//add to array 2
console.log(2);
this.reportData2.push(event.previousContainer.data[event.previousIndex]);
this.dragAndDropService.changeReport2(this.reportData2);
}
}else{
//add to array 1
console.log(1);
this.reportData1.push(event.previousContainer.data[event.previousIndex]);
this.dragAndDropService.changeReport1(this.reportData1);
}
event.previousContainer.data.splice(event.previousIndex, 1);
}else{
console.log("CURR INDEX START - CURR: " + event.currentIndex + " PREV: " + event.previousIndex);
if(event.currentIndex > event.previousIndex){
console.log("After minus - CURR: " + event.currentIndex + " PREV: " + event.previousIndex);
transferArrayItem(event.previousContainer.data, event.container.data, event.previousIndex, event.currentIndex);
if(event.currentIndex >= event.previousIndex){
event.currentIndex = event.currentIndex + 1;
}
transferArrayItem(event.container.data, event.previousContainer.data, event.currentIndex, event.previousIndex);
}else{
if(event.currentIndex < event.previousIndex){
transferArrayItem(event.previousContainer.data, event.container.data, event.previousIndex, event.currentIndex);
event.currentIndex++;
console.log("After addition - CURR: " + event.currentIndex + " PREV: " + event.previousIndex);
transferArrayItem(event.container.data, event.previousContainer.data, event.currentIndex, event.previousIndex);
}else{
if(event.currentIndex === event.previousIndex){
transferArrayItem(event.previousContainer.data, event.container.data, event.previousIndex, event.currentIndex);
event.currentIndex++;
console.log("AFTER Addition - Curr: " + event.currentIndex + " Prev: " + event.previousIndex);
transferArrayItem(event.container.data, event.previousContainer.data, event.currentIndex, event.previousIndex);
}
}
}
console.log("CURR INDEXES END - CURR: " + event.currentIndex + " PREV: " + event.previousIndex);
}
}
let userId = this.getCookie("AtlasNetLogin");
this.cookieServ.delete(userId);
this.combineAllReports();
this.setCookie(userId, this.reportData);
}