import { Injectable } from "@angular/core" ; import { NgRxSortable } from "@angular-skyhook/sortable" ; import { KanbanList } from './lists' ; import { Card } from "./card" ; import { ItemTypes } from "./item-types" ; import { Store , select } from '@ngrx/store' ; import { ActionTypes , _render , _listById , _isCopying , CARD_ID_WHEN_COPYING } from "./store" ; import { filter } from 'rxjs/operators' ; @ Injectable ( ) export class SortableSpecService { boardSpec = new NgRxSortable < KanbanList > ( this . store , ActionTypes . SortList , { type : ItemTypes . LIST , trackBy : list => list . id , getList : _listId => this . store . pipe ( select ( _render ) ) , } ) ; isCopying = false ; subs = this . store . pipe ( select ( _isCopying ) ) . subscribe ( x => this . isCopying = x ) ; listSpec = new NgRxSortable < Card > ( this . store , ActionTypes . SortCard , { type : ItemTypes . CARD , trackBy : card => card . id , getList : listId => this . store . pipe ( select ( _listById ( listId ) ) , filter ( x => x != undefined ) ) , isDragging : ( ground , inFlight ) => { let flyingId = this . isCopying ? CARD_ID_WHEN_COPYING : inFlight . data . id ; return ground . id === flyingId ; } } ) ; constructor ( public store ) { } ngOnDestroy ( ) { this . subs . unsubscribe ( ) ; } }