|
@@ -1,7 +1,8 @@
|
|
|
-import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
|
|
|
|
|
|
+import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
|
|
|
|
|
+import { FormControl } from '@angular/forms';
|
|
|
import { PaginationInstance } from 'ngx-pagination';
|
|
import { PaginationInstance } from 'ngx-pagination';
|
|
|
-import { Observable } from 'rxjs';
|
|
|
|
|
-import { map, tap } from 'rxjs/operators';
|
|
|
|
|
|
|
+import { Observable, Subject } from 'rxjs';
|
|
|
|
|
+import { debounceTime, map, takeUntil, tap } from 'rxjs/operators';
|
|
|
import { Asset, GetAssetList } from 'shared/generated-types';
|
|
import { Asset, GetAssetList } from 'shared/generated-types';
|
|
|
|
|
|
|
|
import { _ } from '../../../core/providers/i18n/mark-for-extraction';
|
|
import { _ } from '../../../core/providers/i18n/mark-for-extraction';
|
|
@@ -19,7 +20,7 @@ import { Dialog } from '../../../shared/providers/modal/modal.service';
|
|
|
styleUrls: ['./asset-picker-dialog.component.scss'],
|
|
styleUrls: ['./asset-picker-dialog.component.scss'],
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
})
|
|
})
|
|
|
-export class AssetPickerDialogComponent implements OnInit, Dialog<Asset[]> {
|
|
|
|
|
|
|
+export class AssetPickerDialogComponent implements OnInit, OnDestroy, Dialog<Asset[]> {
|
|
|
assets$: Observable<Asset[]>;
|
|
assets$: Observable<Asset[]>;
|
|
|
paginationConfig: PaginationInstance = {
|
|
paginationConfig: PaginationInstance = {
|
|
|
currentPage: 1,
|
|
currentPage: 1,
|
|
@@ -29,7 +30,9 @@ export class AssetPickerDialogComponent implements OnInit, Dialog<Asset[]> {
|
|
|
|
|
|
|
|
resolveWith: (result?: Asset[]) => void;
|
|
resolveWith: (result?: Asset[]) => void;
|
|
|
selection: Asset[] = [];
|
|
selection: Asset[] = [];
|
|
|
|
|
+ searchTerm = new FormControl('');
|
|
|
private listQuery: QueryResult<GetAssetList.Query, GetAssetList.Variables>;
|
|
private listQuery: QueryResult<GetAssetList.Query, GetAssetList.Variables>;
|
|
|
|
|
+ private destroy$ = new Subject<void>();
|
|
|
|
|
|
|
|
constructor(private dataService: DataService, private notificationService: NotificationService) {}
|
|
constructor(private dataService: DataService, private notificationService: NotificationService) {}
|
|
|
|
|
|
|
@@ -39,6 +42,23 @@ export class AssetPickerDialogComponent implements OnInit, Dialog<Asset[]> {
|
|
|
tap(result => (this.paginationConfig.totalItems = result.assets.totalItems)),
|
|
tap(result => (this.paginationConfig.totalItems = result.assets.totalItems)),
|
|
|
map(result => result.assets.items),
|
|
map(result => result.assets.items),
|
|
|
);
|
|
);
|
|
|
|
|
+ this.searchTerm.valueChanges
|
|
|
|
|
+ .pipe(
|
|
|
|
|
+ debounceTime(250),
|
|
|
|
|
+ takeUntil(this.destroy$),
|
|
|
|
|
+ )
|
|
|
|
|
+ .subscribe(searchTerm => {
|
|
|
|
|
+ this.fetchPage(
|
|
|
|
|
+ this.paginationConfig.currentPage,
|
|
|
|
|
+ this.paginationConfig.itemsPerPage,
|
|
|
|
|
+ searchTerm,
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ngOnDestroy(): void {
|
|
|
|
|
+ this.destroy$.next();
|
|
|
|
|
+ this.destroy$.complete();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pageChange(page: number) {
|
|
pageChange(page: number) {
|
|
@@ -62,7 +82,11 @@ export class AssetPickerDialogComponent implements OnInit, Dialog<Asset[]> {
|
|
|
createAssets(files: File[]) {
|
|
createAssets(files: File[]) {
|
|
|
if (files.length) {
|
|
if (files.length) {
|
|
|
this.dataService.product.createAssets(files).subscribe(res => {
|
|
this.dataService.product.createAssets(files).subscribe(res => {
|
|
|
- this.fetchPage(this.paginationConfig.currentPage, this.paginationConfig.itemsPerPage);
|
|
|
|
|
|
|
+ this.fetchPage(
|
|
|
|
|
+ this.paginationConfig.currentPage,
|
|
|
|
|
+ this.paginationConfig.itemsPerPage,
|
|
|
|
|
+ this.searchTerm.value,
|
|
|
|
|
+ );
|
|
|
this.notificationService.success(_('catalog.notify-create-assets-success'), {
|
|
this.notificationService.success(_('catalog.notify-create-assets-success'), {
|
|
|
count: files.length,
|
|
count: files.length,
|
|
|
});
|
|
});
|
|
@@ -70,9 +94,19 @@ export class AssetPickerDialogComponent implements OnInit, Dialog<Asset[]> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private fetchPage(currentPage: number, itemsPerPage: number) {
|
|
|
|
|
|
|
+ private fetchPage(currentPage: number, itemsPerPage: number, searchTerm?: string) {
|
|
|
const take = +itemsPerPage;
|
|
const take = +itemsPerPage;
|
|
|
const skip = (currentPage - 1) * +itemsPerPage;
|
|
const skip = (currentPage - 1) * +itemsPerPage;
|
|
|
- this.listQuery.ref.refetch({ options: { skip, take } });
|
|
|
|
|
|
|
+ this.listQuery.ref.refetch({
|
|
|
|
|
+ options: {
|
|
|
|
|
+ skip,
|
|
|
|
|
+ take,
|
|
|
|
|
+ filter: {
|
|
|
|
|
+ name: {
|
|
|
|
|
+ contains: searchTerm,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|