Commit 882ac55f authored by Arko Dey Bhowmick's avatar Arko Dey Bhowmick

feat: add dd

parent f8aa8dc8
<!-- <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) --> <!-- Categories (Draggable) -->
<div cdkDropList [cdkDropListData]="movies" class="category-list" (cdkDropListDropped)="drop($event)"> <div cdkDropList [cdkDropListData]="movies" class="category-list" (cdkDropListDropped)="drop($event)">
...@@ -56,13 +13,13 @@ ...@@ -56,13 +13,13 @@
</svg> </svg>
</div> </div>
{{ category.category }} {{ category.category }}
<button (click)="collapse(movies)">col</button> <button (click)="collapse(movies, i, 'movies')">col</button>
</h3> </h3>
<!-- Subcategories (Draggable) --> <!-- Subcategories (Draggable) -->
<div cdkDropList [cdkDropListData]="category.subcategories" class="subcategory-list" (cdkDropListDropped)="drop($event)"> <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 *ngFor="let subcategory of category.subcategories; let k = index; trackBy: trackByFn" class="subcategory-box {{ !category.collapsed ? '' : 'd_none' }}" cdkDrag>
<ng-container *ngIf="!category.collapsed"> <!-- <ng-container *ngIf="!category.collapsed"> -->
<div class="example-custom-placeholder" *cdkDragPlaceholder></div> <div class="example-custom-placeholder" *cdkDragPlaceholder></div>
<h4 cdkDragHandle class="movie-box"> <h4 cdkDragHandle class="movie-box">
<div class="movie-handle" cdkDragHandle> <div class="movie-handle" cdkDragHandle>
...@@ -72,14 +29,14 @@ ...@@ -72,14 +29,14 @@
</svg> </svg>
</div> </div>
{{ subcategory.name }} {{ subcategory.name }}
<button (click)="collapse(category.subcategories)">col</button> <button (click)="collapse(category.subcategories, k, 'subcategories')">col</button>
</h4> </h4>
</ng-container> <!-- </ng-container> -->
<!-- Movies (Draggable) --> <!-- Movies (Draggable) -->
<div cdkDropList [cdkDropListData]="subcategory.movies" class="movie-list" (cdkDropListDropped)="drop($event)"> <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 *ngFor="let movie of subcategory.movies; trackBy: trackByFn" class="movie-box {{ !subcategory.collapsed ? '' : 'd_none'}}" cdkDrag>
<ng-container *ngIf="!subcategory.collapsed"> <!-- <ng-container *ngIf="!subcategory.collapsed"> -->
<div class="movie-handle" cdkDragHandle> <div class="movie-handle" cdkDragHandle>
<svg width="24px" fill="currentColor" viewBox="0 0 24 24"> <svg width="24px" fill="currentColor" viewBox="0 0 24 24">
...@@ -92,12 +49,12 @@ ...@@ -92,12 +49,12 @@
{{ movie.title }} {{ movie.title }}
<!-- <button (click)="collapse()">col</button> --> <!-- <button (click)="collapse()">col</button> -->
</ng-container> <!-- </ng-container> -->
</div> </div>
</div> </div>
</div> </div>
</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 { .category-list {
width: 100%; width: 100%;
...@@ -63,33 +10,35 @@ ...@@ -63,33 +10,35 @@
} }
.category-box { .category-box {
padding: 15px; padding: 1px 10px;
background: #dfe6e9; // background: #dfe6e9;
border-radius: 6px; border-radius: 6px;
margin-bottom: 10px; margin-bottom: 0;
cursor: grab; cursor: grab;
} }
.subcategory-list { .subcategory-list {
margin-left: 20px; margin-left: 20px;
// padding: 10px;
padding-left: 10px; padding-left: 10px;
border-left: 2px solid #ccc; border-left: 2px solid #ccc;
} }
.subcategory-box { .subcategory-box {
background: #b2bec3; // background: #b2bec3;
padding: 10px; padding: 1px 10px;
border-radius: 6px; border-radius: 6px;
margin-bottom: 10px; margin-bottom: 5px;
cursor: grab; cursor: grab;
} }
.movie-list { .movie-list {
margin-left: 30px; margin-left: 30px;
// padding: 10px;
} }
.movie-box { .movie-box {
padding: 8px; padding: 7px 12px;
background: white; background: white;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 4px; border-radius: 4px;
...@@ -97,6 +46,7 @@ ...@@ -97,6 +46,7 @@
cursor: grab; cursor: grab;
display: flex; display: flex;
align-items: center; align-items: center;
margin: 0px 0px 5px;
} }
.movie-handle { .movie-handle {
...@@ -124,4 +74,8 @@ ...@@ -124,4 +74,8 @@
.cdk-drag-animating { .cdk-drag-animating {
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
}
.d_none {
display: none;
} }
\ No newline at end of file
...@@ -12,11 +12,11 @@ export class DragNDropAnnotherComponent { ...@@ -12,11 +12,11 @@ export class DragNDropAnnotherComponent {
movies = [ movies = [
{ {
category: 'Prequel Trilogy', category: 'Prequel Trilogy',
collapsed: false, collapsed: true,
subcategories: [ subcategories: [
{ {
name: 'Episodes I-III', name: 'Episodes I-III',
collapsed: false, collapsed: true,
movies: [ movies: [
{ id: 1, title: 'Episode I - The Phantom Menace' }, { id: 1, title: 'Episode I - The Phantom Menace' },
{ id: 2, title: 'Episode II - Attack of the Clones' }, { id: 2, title: 'Episode II - Attack of the Clones' },
...@@ -25,7 +25,7 @@ export class DragNDropAnnotherComponent { ...@@ -25,7 +25,7 @@ export class DragNDropAnnotherComponent {
}, },
{ {
name: 'Episodes 4-7', name: 'Episodes 4-7',
collapsed: false, collapsed: true,
movies: [ movies: [
{ id: 1, title: 'Episode 4 - 4 The Phantom Menace' }, { id: 1, title: 'Episode 4 - 4 The Phantom Menace' },
{ id: 2, title: 'Episode 5 - 5 Attack of the Clones' }, { id: 2, title: 'Episode 5 - 5 Attack of the Clones' },
...@@ -36,11 +36,11 @@ export class DragNDropAnnotherComponent { ...@@ -36,11 +36,11 @@ export class DragNDropAnnotherComponent {
}, },
{ {
category: 'Original Trilogy', category: 'Original Trilogy',
collapsed: false, collapsed: true,
subcategories: [ subcategories: [
{ {
name: 'Episodes IV-VI', name: 'Episodes IV-VI',
collapsed: false, collapsed: true,
movies: [ movies: [
{ id: 4, title: 'Episode IV - A New Hope' }, { id: 4, title: 'Episode IV - A New Hope' },
{ id: 5, title: 'Episode V - The Empire Strikes Back' }, { id: 5, title: 'Episode V - The Empire Strikes Back' },
...@@ -51,11 +51,11 @@ export class DragNDropAnnotherComponent { ...@@ -51,11 +51,11 @@ export class DragNDropAnnotherComponent {
}, },
{ {
category: 'Sequel Trilogy', category: 'Sequel Trilogy',
collapsed: false, collapsed: true,
subcategories: [ subcategories: [
{ {
name: 'Episodes VII-IX', name: 'Episodes VII-IX',
collapsed: false, collapsed: true,
movies: [ movies: [
{ id: 7, title: 'Episode VII - The Force Awakens' }, { id: 7, title: 'Episode VII - The Force Awakens' },
{ id: 8, title: 'Episode VIII - The Last Jedi' }, { id: 8, title: 'Episode VIII - The Last Jedi' },
...@@ -85,22 +85,25 @@ export class DragNDropAnnotherComponent { ...@@ -85,22 +85,25 @@ export class DragNDropAnnotherComponent {
return item.id || index; return item.id || index;
} }
public collapse(array: any[]): void { public collapse(array: any[], index:number, str?: string): void {
array.forEach((elm) => { array[index].collapsed = !array[index].collapsed;
// Check if the element has the `collapsed` property and toggle it // array.forEach((elm) => {
if (elm.hasOwnProperty('collapsed')) {
elm.collapsed = !elm.collapsed; // if (elm.hasOwnProperty('collapsed')) {
} // elm.collapsed = !elm.collapsed;
// }
// Check for any nested arrays inside the object // // Check for any nested arrays inside the object
Object.keys(elm).forEach((key) => { // Object.keys(elm).forEach((key, i) => {
if (Array.isArray(elm[key])) {
// Recursive call to check deeper nested arrays // if (Array.isArray(elm[key])) {
this.collapse(elm[key]);
} // // Recursive call to check deeper nested arrays
}); // this.collapse(elm[key], i);
}); // }
// });
// });
console.log(array) console.log(array)
} }
......
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