Commit 98cb0590 authored by Arko Dey Bhowmick's avatar Arko Dey Bhowmick

testing dd

parent 6a581a16
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"name": "nkda", "name": "nkda",
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"@angular/cdk": "^19.1.3", "@angular/cdk": "^19.2.6",
"@angular/common": "^19.1.4", "@angular/common": "^19.1.4",
"@angular/compiler": "^19.1.4", "@angular/compiler": "^19.1.4",
"@angular/core": "^19.1.4", "@angular/core": "^19.1.4",
...@@ -811,9 +811,9 @@ ...@@ -811,9 +811,9 @@
} }
}, },
"node_modules/@angular/cdk": { "node_modules/@angular/cdk": {
"version": "19.1.3", "version": "19.2.6",
"resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-19.1.3.tgz", "resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-19.2.6.tgz",
"integrity": "sha512-A8d1V4AU2ZcNnEEwAUp4W1uYdT7EKHZM0PGicVhLyeetwYrpHiLoPioD7sw89TlPuJcd6mS7xV6AnXQ8peOoXg==", "integrity": "sha512-AneN/NeAYU4+AwzicTwtYE9CkMcWA0cAJ41SNfSyoHaaHNXSkryzwSmTYS3FO+taqd7OGnBePeWJbW2uJXcvfA==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"tslib": "^2.3.0" "tslib": "^2.3.0"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
"@angular/cdk": "^19.1.3", "@angular/cdk": "^19.2.6",
"@angular/common": "^19.1.4", "@angular/common": "^19.1.4",
"@angular/compiler": "^19.1.4", "@angular/compiler": "^19.1.4",
"@angular/core": "^19.1.4", "@angular/core": "^19.1.4",
......
...@@ -87,4 +87,13 @@ export const routes: Routes = [ ...@@ -87,4 +87,13 @@ export const routes: Routes = [
], ],
}, },
{
path: RequestMapperService.TEST_DRAG_AND_DROP,
loadComponent: () =>
import('./component-library/drag-n-drop/drag-n-drop-annother/drag-n-drop-annother.component').then(
(m) => m.DragNDropAnnotherComponent
),
canActivate: [],
data: { roles: RoleMapperService.getAllRole },
},
]; ];
<!-- <div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
@for (movie of movies; track movie) {
<div class="example-box" cdkDrag>
<div class="example-handle" cdkDragHandle>
<svg width="24px" fill="currentColor" viewBox="0 0 24 24">
<path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z"></path>
<path d="M0 0h24v24H0z" fill="none"></path>
</svg>
</div>
<div class="example-custom-placeholder" *cdkDragPlaceholder></div>
{{movie}}
</div>
}
</div>
-->
<!-- <div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
<div *ngFor="let category of movies;">
<h3>{{ category.category }}</h3>
<div *ngFor="let subcategory of category.subcategories;">
<h4>{{ subcategory.name }}</h4>
<div cdkDropList class="subcategory-list" (cdkDropListDropped)="drop($event)">
<div *ngFor="let movie of subcategory.movies;" class="example-box" cdkDrag>
<div class="example-handle" cdkDragHandle>
<svg width="24px" fill="currentColor" viewBox="0 0 24 24">
<path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z"></path>
<path d="M0 0h24v24H0z" fill="none"></path>
</svg>
</div>
<div class="example-custom-placeholder" *cdkDragPlaceholder></div>
{{ movie.title }}
</div>
</div>
</div>
</div>
</div> -->
<!-- Categories (Draggable) -->
<div cdkDropList [cdkDropListData]="movies" class="category-list" (cdkDropListDropped)="drop($event)">
<div *ngFor="let category of movies; trackBy: trackByFn" class="category-box" cdkDrag>
<div class="example-custom-placeholder" *cdkDragPlaceholder></div>
<h3 cdkDragHandle class="movie-box">
<div class="movie-handle" cdkDragHandle>
<svg width="24px" fill="currentColor" viewBox="0 0 24 24">
<path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z"></path>
<path d="M0 0h24v24H0z" fill="none"></path>
</svg>
</div>
{{ category.category }}
</h3>
<!-- Subcategories (Draggable) -->
<div cdkDropList [cdkDropListData]="category.subcategories" class="subcategory-list" (cdkDropListDropped)="drop($event)">
<div *ngFor="let subcategory of category.subcategories; trackBy: trackByFn" class="subcategory-box" cdkDrag>
<div class="example-custom-placeholder" *cdkDragPlaceholder></div>
<h4 cdkDragHandle class="movie-box">
<div class="movie-handle" cdkDragHandle>
<svg width="24px" fill="currentColor" viewBox="0 0 24 24">
<path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z"></path>
<path d="M0 0h24v24H0z" fill="none"></path>
</svg>
</div>
{{ subcategory.name }}
</h4>
<!-- Movies (Draggable) -->
<div cdkDropList [cdkDropListData]="subcategory.movies" class="movie-list" (cdkDropListDropped)="drop($event)">
<div *ngFor="let movie of subcategory.movies; trackBy: trackByFn" class="movie-box" cdkDrag>
<div class="movie-handle" cdkDragHandle>
<svg width="24px" fill="currentColor" viewBox="0 0 24 24">
<path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z"></path>
<path d="M0 0h24v24H0z" fill="none"></path>
</svg>
</div>
<div class="example-custom-placeholder" *cdkDragPlaceholder></div>
{{ movie.title }}
</div>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
// .example-list {
// width: 500px;
// max-width: 100%;
// border: solid 1px #ccc;
// min-height: 60px;
// display: block;
// background: white;
// border-radius: 4px;
// overflow: hidden;
// }
// .example-box {
// padding: 20px 10px;
// border-bottom: solid 1px #ccc;
// color: rgba(0, 0, 0, 0.87);
// display: flex;
// flex-direction: row;
// align-items: center;
// justify-content: flex-start;
// box-sizing: border-box;
// cursor: move;
// background: white;
// font-size: 14px;
// gap: 20px;
// }
// .cdk-drag-preview {
// box-sizing: border-box;
// border-radius: 4px;
// box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
// 0 8px 10px 1px rgba(0, 0, 0, 0.14),
// 0 3px 14px 2px rgba(0, 0, 0, 0.12);
// }
// .cdk-drag-animating {
// transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
// }
// .example-box:last-child {
// border: none;
// }
// .example-list.cdk-drop-list-dragging .example-box:not(.cdk-drag-placeholder) {
// transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
// }
// .example-custom-placeholder {
// background: #ccc;
// border: dotted 3px #999;
// min-height: 60px;
// transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
// }
.category-list {
width: 100%;
max-width: 600px;
border: 2px solid #aaa;
background: #f8f9fa;
padding: 10px;
border-radius: 8px;
margin-bottom: 20px;
}
.category-box {
padding: 15px;
background: #dfe6e9;
border-radius: 6px;
margin-bottom: 10px;
cursor: grab;
}
.subcategory-list {
margin-left: 20px;
padding-left: 10px;
border-left: 2px solid #ccc;
}
.subcategory-box {
background: #b2bec3;
padding: 10px;
border-radius: 6px;
margin-bottom: 10px;
cursor: grab;
}
.movie-list {
margin-left: 30px;
}
.movie-box {
padding: 8px;
background: white;
border: 1px solid #ccc;
border-radius: 4px;
margin-bottom: 5px;
cursor: grab;
display: flex;
align-items: center;
}
.movie-handle {
margin-right: 10px;
}
.example-custom-placeholder {
background: #ccc;
border: dotted 3px #999;
min-height: 60px;
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
}
.cdk-drag-preview {
box-sizing: border-box;
border-radius: 4px;
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
0 8px 10px 1px rgba(0, 0, 0, 0.14),
0 3px 14px 2px rgba(0, 0, 0, 0.12);
}
.cdk-drag-animating {
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
}
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DragNDropAnnotherComponent } from './drag-n-drop-annother.component';
describe('DragNDropAnnotherComponent', () => {
let component: DragNDropAnnotherComponent;
let fixture: ComponentFixture<DragNDropAnnotherComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DragNDropAnnotherComponent]
})
.compileComponents();
fixture = TestBed.createComponent(DragNDropAnnotherComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { CdkDropList, CdkDrag, CdkDragPlaceholder, CdkDragDrop, moveItemInArray, CdkDragHandle, transferArrayItem } from '@angular/cdk/drag-drop';
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
@Component({
selector: 'app-drag-n-drop-annother',
imports: [CdkDropList, CdkDrag, CdkDragPlaceholder, CdkDragHandle, CommonModule],
templateUrl: './drag-n-drop-annother.component.html',
styleUrl: './drag-n-drop-annother.component.scss'
})
export class DragNDropAnnotherComponent {
movies = [
{
category: 'Prequel Trilogy',
subcategories: [
{
name: 'Episodes I-III',
movies: [
{ id: 1, title: 'Episode I - The Phantom Menace' },
{ id: 2, title: 'Episode II - Attack of the Clones' },
{ id: 3, title: 'Episode III - Revenge of the Sith' },
]
},
{
name: 'Episodes 4-7',
movies: [
{ id: 1, title: 'Episode 4 - 4 The Phantom Menace' },
{ id: 2, title: 'Episode 5 - 5 Attack of the Clones' },
{ id: 3, title: 'Episode I7 - 7 Revenge of the Sith' },
]
}
]
},
{
category: 'Original Trilogy',
subcategories: [
{
name: 'Episodes IV-VI',
movies: [
{ id: 4, title: 'Episode IV - A New Hope' },
{ id: 5, title: 'Episode V - The Empire Strikes Back' },
{ id: 6, title: 'Episode VI - Return of the Jedi' },
]
}
]
},
{
category: 'Sequel Trilogy',
subcategories: [
{
name: 'Episodes VII-IX',
movies: [
{ id: 7, title: 'Episode VII - The Force Awakens' },
{ id: 8, title: 'Episode VIII - The Last Jedi' },
{ id: 9, title: 'Episode IX - The Rise of Skywalker' },
]
}
]
}
];
// drop(event: CdkDragDrop<string[]>) {
// moveItemInArray(this.movies, event.previousIndex, event.currentIndex);
// }
public drop(event: CdkDragDrop<any[]>) {
if (event.previousContainer === event.container) {
// Moving within the same list
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
// Moving between different lists
transferArrayItem(event.previousContainer.data, event.container.data, event.previousIndex, event.currentIndex);
}
}
public trackByFn(index: number, item: any) {
return item.id || index;
}
}
<div cdkDropList class="exam-list" [cdkDropListData]="exams" (cdkDropListDropped)="drop($event)">
<div *ngFor="let exam of exams" cdkDrag class="exam-item">
<span class="drag-handle" cdkDragHandle>☰</span>
{{ exam.name }}
<!-- Nested list for subExams -->
<div *ngIf="exam.subExams.length > 0" cdkDropList [cdkDropListData]="exam.subExams" (cdkDropListDropped)="drop($event)">
<div *ngFor="let subExam of exam.subExams" cdkDrag class="sub-exam-item">
<span class="drag-handle" cdkDragHandle>☰</span>
{{ subExam.name }}
<!-- Nested list for subAssesments -->
<div *ngIf="subExam.subAssessments && subExam.subAssessments.length > 0" cdkDropList [cdkDropListData]="subExam.subAssessments" (cdkDropListDropped)="drop($event)" >
<div *ngFor="let subAssesment of subExam.subAssessments" cdkDrag class="sub-exam-item">
<span class="drag-handle" cdkDragHandle>☰</span>
{{ subAssesment.name }}
</div>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
.list-container {
width: 350px;
padding: 15px;
border: 1px solid #ddd;
background-color: #f8f9fa;
border-radius: 5px;
}
/* Style for the main list */
.exam-list {
padding: 10px;
background: #ffffff;
border-radius: 8px;
border: 1px solid #ddd;
}
/* Style for exam items */
.exam-item,
.sub-exam-item {
padding: 12px;
margin: 6px 0;
background: white;
border-radius: 6px;
border: 1px solid #ccc;
cursor: grab;
display: flex;
align-items: center;
justify-content: flex-start;
transition: background 0.2s ease-in-out;
flex-wrap: wrap;
}
/* Dragging effect */
.cdk-drag-placeholder {
background-color: #e0e0e0;
border: 2px dashed #aaa;
height: 50px;
}
/* Sub-exam items (nested lists) */
.sub-exam-item {
padding: 10px;
margin-left: 20px;
background: #eef;
border-radius: 6px;
border: 1px solid #bbb;
}
/* Drag handle */
.drag-handle {
margin-right: 10px;
font-size: 18px;
color: #555;
cursor: grab;
}
/* Prevent text selection while dragging */
.exam-item,
.sub-exam-item {
-webkit-user-select: none; /* Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Standard */
}
/* Placeholder when dragging */
.drop-placeholder {
height: 40px;
background-color: #e0e0e0;
border: 2px dashed #aaa;
margin: 6px;
text-align: center;
line-height: 40px;
font-weight: bold;
color: #666;
border-radius: 6px;
}
/* Hover effect on items */
.exam-item:hover,
.sub-exam-item:hover {
background: #f1f1f1;
}
.cdk-drop-list {
width: 100%;
}
\ No newline at end of file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DragNDropComponent } from './drag-n-drop.component';
describe('DragNDropComponent', () => {
let component: DragNDropComponent;
let fixture: ComponentFixture<DragNDropComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DragNDropComponent]
})
.compileComponents();
fixture = TestBed.createComponent(DragNDropComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component } from '@angular/core';
import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
import { CommonModule } from '@angular/common';
import { DragDropModule } from '@angular/cdk/drag-drop';
@Component({
selector: 'app-drag-n-drop',
standalone: true,
imports: [CommonModule, DragDropModule],
templateUrl: './drag-n-drop.component.html',
styleUrl: './drag-n-drop.component.scss'
})
export class DragNDropComponent {
exams = [
{
name: 'Level 1 - Term 1',
subExams: [
{ name: 'Level 2 - Assignment 4 (D)' },
{ name: 'Level 2 - Assignment 5 (D)',
subAssessments: [
{ name: 'Level 3 - Assessment 1' },
{ name: 'Level 3 - Assessment 2' },
{ name: 'Level 3 - Assessment 3' },
{ name: 'Level 3 - Assessment 4' },
]
},
]
},
{ name: 'Level 1 - Term 2', subExams: [] },
{ name: 'Level 1 - Term 3', subExams: [
{ name: 'Level 2 - Assignment 4 (D)' },
{ name: 'Level 2 - Assignment 5 (D)',
subAssessments: [
{ name: 'Level 3 - Assessment 1' },
{ name: 'Level 3 - Assessment 2' },
{ name: 'Level 3 - Assessment 3' },
{ name: 'Level 3 - Assessment 4' },
]
},
] },
{ name: 'Level 1 - Term 4', subExams: [] },
{ name: 'Level 1 - Term 5', subExams: [] },
{ name: 'Level 1 - Cycle 2', subExams: [] }
];
// drop(event: CdkDragDrop<any[]>, parentSubExam?: any) {
// if (event.previousContainer === event.container) {
// moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
// } else {
// // Ensure Level 3 items stay under the same Level 2 parent
// if (parentSubExam && event.previousContainer.data === parentSubExam.subAssessments) {
// transferArrayItem(
// event.previousContainer.data,
// event.container.data,
// event.previousIndex,
// event.currentIndex
// );
// }
// }
// }
drop(event: CdkDragDrop<any[]>, targetParent?: any) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
const draggedItem = event.previousContainer.data[event.previousIndex];
// Ensure we are working with a Level 3 Assessment
if (targetParent && targetParent.subAssessments) {
transferArrayItem(
event.previousContainer.data,
targetParent.subAssessments,
event.previousIndex,
event.currentIndex
);
}
}
}
}
...@@ -23,5 +23,8 @@ export class RequestMapperService { ...@@ -23,5 +23,8 @@ export class RequestMapperService {
public static readonly EXAM_URL: string = 'exam'; public static readonly EXAM_URL: string = 'exam';
public static readonly ROUTINE_URL: string = 'routine'; public static readonly ROUTINE_URL: string = 'routine';
public static readonly TEST_DRAG_AND_DROP: string = 'drag-and-drop';
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment