I have a Trello-like web app. with Task
s that can be dragged & dropped in status boxes (To do, ogoing and done). I use ng2-dragula to achieve the drag & drop feature and wanted to implement a way to filter my tasks with an Angular 2
pipe.
So I did, by first defining my pipe:
@Pipe({
name: 'taskFilter',
pure: false
})
export class TaskFilterPipe implements PipeTransform {
transform(items: Task[], filter: Task): Task[] {
if (!items || !filter) {
return items;
}
// pipes items array, items which match and return true will be kept, false will be filtered out
return items.filter((item: Task) => this.applyFilter(item, filter));
}
applyFilter(task: Task, filter: Task): boolean {
for (const field in filter) {
if (filter[field]) {
if (typeof filter[field] === 'string') {
if (task[field].toLowerCase().indexOf(filter[field].toLowerCase()) === -1) {
return false;
}
}
}
}
return true;
}
}
And adding it to my *ngFor
:
<!-- For every different status we have, display a card with its tasks -->
<md-grid-tile *ngFor="let istatus of status">
<!-- Display every task in our array and pipe in the filter -->
<div *ngFor="let task of tasks | taskFilter:projectService.filteredTask">
<!-- Check if said task has the right status and display it -->
<md-card class="task-card" *ngIf="task.status == istatus" (click)="openDetails(task)">
{{task.title}}
</md-card>
</div>
</md-grid-tile>
It works, yay ! But when I drag & drop any task, it simply disappears, never to be found again.
It seems that changing a task's status in any way is making it disappear, how can that be related to my pipe?
Is there a way to use both dragula and Angular 2 pipes?