|
|
@@ -1,12 +1,15 @@
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
import { FormControl, FormGroup } from '@angular/forms';
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
-import { Observable } from 'rxjs';
|
|
|
-import { debounceTime, takeUntil } from 'rxjs/operators';
|
|
|
-import { GetProductList, SearchProducts } from 'shared/generated-types';
|
|
|
+import { EMPTY, Observable } from 'rxjs';
|
|
|
+import { debounceTime, map, switchMap, takeUntil } from 'rxjs/operators';
|
|
|
+import { DeletionResult, GetProductList, SearchProducts } from 'shared/generated-types';
|
|
|
|
|
|
import { BaseListComponent } from '../../../common/base-list.component';
|
|
|
+import { _ } from '../../../core/providers/i18n/mark-for-extraction';
|
|
|
+import { NotificationService } from '../../../core/providers/notification/notification.service';
|
|
|
import { DataService } from '../../../data/providers/data.service';
|
|
|
+import { ModalService } from '../../../shared/providers/modal/modal.service';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'vdr-products-list',
|
|
|
@@ -18,7 +21,13 @@ export class ProductListComponent
|
|
|
implements OnInit {
|
|
|
searchForm: FormGroup | undefined;
|
|
|
groupByProduct = true;
|
|
|
- constructor(private dataService: DataService, router: Router, route: ActivatedRoute) {
|
|
|
+ constructor(
|
|
|
+ private dataService: DataService,
|
|
|
+ private modalService: ModalService,
|
|
|
+ private notificationService: NotificationService,
|
|
|
+ router: Router,
|
|
|
+ route: ActivatedRoute,
|
|
|
+ ) {
|
|
|
super(router, route);
|
|
|
super.setQueryFn(
|
|
|
(...args: any[]) =>
|
|
|
@@ -49,6 +58,33 @@ export class ProductListComponent
|
|
|
.subscribe(() => this.refresh());
|
|
|
}
|
|
|
|
|
|
+ deleteProduct(productId: string) {
|
|
|
+ this.modalService
|
|
|
+ .dialog({
|
|
|
+ title: _('catalog.confirm-delete-product'),
|
|
|
+ buttons: [
|
|
|
+ { type: 'seconday', label: _('common.cancel') },
|
|
|
+ { type: 'danger', label: _('common.delete'), returnValue: true },
|
|
|
+ ],
|
|
|
+ })
|
|
|
+ .pipe(
|
|
|
+ switchMap(response => (response ? this.dataService.product.deleteProduct(productId) : EMPTY)),
|
|
|
+ )
|
|
|
+ .subscribe(
|
|
|
+ () => {
|
|
|
+ this.notificationService.success(_('common.notify-delete-success'), {
|
|
|
+ entity: 'Product',
|
|
|
+ });
|
|
|
+ this.refresh();
|
|
|
+ },
|
|
|
+ err => {
|
|
|
+ this.notificationService.error(_('common.notify-delete-error'), {
|
|
|
+ entity: 'Product',
|
|
|
+ });
|
|
|
+ },
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
private getFormValue<T>(controlName: string, defaultValue: T): T {
|
|
|
if (!this.searchForm) {
|
|
|
return defaultValue;
|