|
@@ -2,11 +2,19 @@ import { Component, OnInit } from '@angular/core';
|
|
|
import { FormControl } from '@angular/forms';
|
|
import { FormControl } from '@angular/forms';
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
|
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
|
|
|
-import { BaseListComponent, DataService, GetAssetList, NotificationService } from '@vendure/admin-ui/core';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ Asset,
|
|
|
|
|
+ BaseListComponent,
|
|
|
|
|
+ DataService,
|
|
|
|
|
+ DeletionResult,
|
|
|
|
|
+ GetAssetList,
|
|
|
|
|
+ ModalService,
|
|
|
|
|
+ NotificationService,
|
|
|
|
|
+} from '@vendure/admin-ui/core';
|
|
|
import { SortOrder } from '@vendure/common/lib/generated-shop-types';
|
|
import { SortOrder } from '@vendure/common/lib/generated-shop-types';
|
|
|
import { PaginationInstance } from 'ngx-pagination';
|
|
import { PaginationInstance } from 'ngx-pagination';
|
|
|
-import { combineLatest, Observable } from 'rxjs';
|
|
|
|
|
-import { debounceTime, map, takeUntil } from 'rxjs/operators';
|
|
|
|
|
|
|
+import { combineLatest, EMPTY, Observable } from 'rxjs';
|
|
|
|
|
+import { debounceTime, map, switchMap, takeUntil } from 'rxjs/operators';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'vdr-asset-list',
|
|
selector: 'vdr-asset-list',
|
|
@@ -20,6 +28,7 @@ export class AssetListComponent extends BaseListComponent<GetAssetList.Query, Ge
|
|
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
|
private notificationService: NotificationService,
|
|
private notificationService: NotificationService,
|
|
|
|
|
+ private modalService: ModalService,
|
|
|
private dataService: DataService,
|
|
private dataService: DataService,
|
|
|
router: Router,
|
|
router: Router,
|
|
|
route: ActivatedRoute,
|
|
route: ActivatedRoute,
|
|
@@ -27,7 +36,7 @@ export class AssetListComponent extends BaseListComponent<GetAssetList.Query, Ge
|
|
|
super(router, route);
|
|
super(router, route);
|
|
|
super.setQueryFn(
|
|
super.setQueryFn(
|
|
|
(...args: any[]) => this.dataService.product.getAssetList(...args),
|
|
(...args: any[]) => this.dataService.product.getAssetList(...args),
|
|
|
- data => data.assets,
|
|
|
|
|
|
|
+ (data) => data.assets,
|
|
|
(skip, take) => ({
|
|
(skip, take) => ({
|
|
|
options: {
|
|
options: {
|
|
|
skip,
|
|
skip,
|
|
@@ -51,16 +60,13 @@ export class AssetListComponent extends BaseListComponent<GetAssetList.Query, Ge
|
|
|
map(([itemsPerPage, currentPage, totalItems]) => ({ itemsPerPage, currentPage, totalItems })),
|
|
map(([itemsPerPage, currentPage, totalItems]) => ({ itemsPerPage, currentPage, totalItems })),
|
|
|
);
|
|
);
|
|
|
this.searchTerm.valueChanges
|
|
this.searchTerm.valueChanges
|
|
|
- .pipe(
|
|
|
|
|
- debounceTime(250),
|
|
|
|
|
- takeUntil(this.destroy$),
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ .pipe(debounceTime(250), takeUntil(this.destroy$))
|
|
|
.subscribe(() => this.refresh());
|
|
.subscribe(() => this.refresh());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
filesSelected(files: File[]) {
|
|
filesSelected(files: File[]) {
|
|
|
if (files.length) {
|
|
if (files.length) {
|
|
|
- this.dataService.product.createAssets(files).subscribe(res => {
|
|
|
|
|
|
|
+ this.dataService.product.createAssets(files).subscribe((res) => {
|
|
|
super.refresh();
|
|
super.refresh();
|
|
|
this.notificationService.success(_('asset.notify-create-assets-success'), {
|
|
this.notificationService.success(_('asset.notify-create-assets-success'), {
|
|
|
count: files.length,
|
|
count: files.length,
|
|
@@ -68,4 +74,48 @@ export class AssetListComponent extends BaseListComponent<GetAssetList.Query, Ge
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ deleteAsset(asset: Asset) {
|
|
|
|
|
+ this.showModalAndDelete(asset.id)
|
|
|
|
|
+ .pipe(
|
|
|
|
|
+ switchMap((response) => {
|
|
|
|
|
+ if (response.result === DeletionResult.DELETED) {
|
|
|
|
|
+ return [true];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return this.showModalAndDelete(asset.id, response.message || '').pipe(
|
|
|
|
|
+ map((r) => r.result === DeletionResult.DELETED),
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ }),
|
|
|
|
|
+ )
|
|
|
|
|
+ .subscribe(
|
|
|
|
|
+ () => {
|
|
|
|
|
+ this.notificationService.success(_('common.notify-delete-success'), {
|
|
|
|
|
+ entity: 'Asset',
|
|
|
|
|
+ });
|
|
|
|
|
+ this.refresh();
|
|
|
|
|
+ },
|
|
|
|
|
+ (err) => {
|
|
|
|
|
+ this.notificationService.error(_('common.notify-delete-error'), {
|
|
|
|
|
+ entity: 'Asset',
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private showModalAndDelete(assetId: string, message?: string) {
|
|
|
|
|
+ return this.modalService
|
|
|
|
|
+ .dialog({
|
|
|
|
|
+ title: _('catalog.confirm-delete-facet'),
|
|
|
|
|
+ body: message,
|
|
|
|
|
+ buttons: [
|
|
|
|
|
+ { type: 'secondary', label: _('common.cancel') },
|
|
|
|
|
+ { type: 'danger', label: _('common.delete'), returnValue: true },
|
|
|
|
|
+ ],
|
|
|
|
|
+ })
|
|
|
|
|
+ .pipe(
|
|
|
|
|
+ switchMap((res) => (res ? this.dataService.product.deleteAsset(assetId, !!message) : EMPTY)),
|
|
|
|
|
+ map((res) => res.deleteAsset),
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|