export abstract class DataSourceBaseEntity<T> extends DataSource<T>{
public dataSourceSubjects = new BehaviorSubject<T[]>([]);
public allSourceSubjects: Array<T>;
public apiClient: any;
constructor( public loadingSubject?:Subject<boolean>){
super();
console.log("constructor DataSourceBaseEntity")
this.loadingSubject = new BehaviorSubject<boolean>(true);
}
abstract loadSubjects(): Observable<T[]>;
}
@Injectable()
export class WarehouseTableDataSource extends DataSourceBaseEntity<TaxpayerStoreSimpleDto> {
public loading = this.loadingSubject.asObservable();
loadSubjects(): Observable<TaxpayerStoreSimpleDto[]>{
return this.apiClient.getUserTaxpayerStores().pipe(
catchError(() => of([])),
finalize(() =>
this.loadingSubject.next(false)),
)
}
}
@Component({
selector: 'app-warehouse',
templateUrl: './warehouse.component.html',
styleUrls: ['./warehouse.component.scss'],
providers: [WarehouseTableDataSource],
})
export class WarehouseComponent implements OnInit, OnDestroy {
menuItems: any[];
filterForm: FormGroup;
displayedColumns: string[] = ["name",'externalId',"warehouseTypeCode",
"status","address","isDefault","isPostingGoods","isInherited","isJointStore","isCooperativeStore","isRawMaterials", 'responsiblePersonIin'];
reorginized = REORGANIZED;
warehouseUDSs = WAREHOUSESUDSS;
statuses = STATUSES;
private unsubscription$: Subject<void> = new Subject<void>();
public get TaxpayerStoreStatus(): typeof TaxpayerStoreStatus {
return TaxpayerStoreStatus;
}
public get TaxpayerStoreType(): typeof StoreType {
return StoreType;
}
constructor(
taxPayerApi: TaxpayerStoreClient,
private formBuilder: FormBuilder,
private commonValuesService: CommonUpdateValuesService,
private titleService: Title,
public dataSource: WarehouseTableDataSource) {
this.dataSource.apiClient = taxPayerApi;
this.titleService.setTitle('Склады');
}
ngOnInit() {
this.filterForm =
this.formBuilder.group({
warehouseName: [],
reorganizedWarehousePerson: [],
warehouseUDS:[],
statusWarehouse: []
});
this.dataSource.loadSubjects()
.pipe(takeUntil(this.unsubscription$))
.subscribe((data) => {
this.dataSource.dataSourceSubjects.next(data);
});
}
ngOnDestroy(): void {
console.log("warehoudse component destroyed")
this.unsubscription$.next();
this.unsubscription$.complete()
}
}