|
@@ -3,6 +3,7 @@ import {
|
|
|
Component,
|
|
Component,
|
|
|
EventEmitter,
|
|
EventEmitter,
|
|
|
Input,
|
|
Input,
|
|
|
|
|
+ OnChanges,
|
|
|
OnDestroy,
|
|
OnDestroy,
|
|
|
OnInit,
|
|
OnInit,
|
|
|
Output,
|
|
Output,
|
|
@@ -11,8 +12,14 @@ import { FormControl } from '@angular/forms';
|
|
|
import { Observable, Subject } from 'rxjs';
|
|
import { Observable, Subject } from 'rxjs';
|
|
|
import { debounceTime, map, takeUntil } from 'rxjs/operators';
|
|
import { debounceTime, map, takeUntil } from 'rxjs/operators';
|
|
|
|
|
|
|
|
|
|
+import { DeepPartial } from '../../../../../../shared/shared-types';
|
|
|
import { DataService } from '../../../data/providers/data.service';
|
|
import { DataService } from '../../../data/providers/data.service';
|
|
|
-import { ProductOptionGroup } from '../select-option-group-dialog/select-option-group-dialog.component';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ GetProductOptionGroups,
|
|
|
|
|
+ GetProductOptionGroupsVariables,
|
|
|
|
|
+ ProductOptionGroup,
|
|
|
|
|
+} from '../../../data/types/gql-generated-types';
|
|
|
|
|
+import { QueryResult } from '../../../data/types/query-result';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'vdr-select-option-group',
|
|
selector: 'vdr-select-option-group',
|
|
@@ -20,18 +27,21 @@ import { ProductOptionGroup } from '../select-option-group-dialog/select-option-
|
|
|
styleUrls: ['./select-option-group.component.scss'],
|
|
styleUrls: ['./select-option-group.component.scss'],
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
})
|
|
})
|
|
|
-export class SelectOptionGroupComponent implements OnInit, OnDestroy {
|
|
|
|
|
- @Input() existingOptionGroupIds: string[];
|
|
|
|
|
|
|
+export class SelectOptionGroupComponent implements OnInit, OnChanges, OnDestroy {
|
|
|
|
|
+ @Input() selectedGroups: ProductOptionGroup[];
|
|
|
@Output() selectGroup = new EventEmitter<ProductOptionGroup>();
|
|
@Output() selectGroup = new EventEmitter<ProductOptionGroup>();
|
|
|
- optionGroups$: Observable<ProductOptionGroup[]>;
|
|
|
|
|
|
|
+ optionGroups$: Observable<Array<DeepPartial<ProductOptionGroup>>>;
|
|
|
filterInput = new FormControl();
|
|
filterInput = new FormControl();
|
|
|
|
|
+ optionGroupsQuery: QueryResult<GetProductOptionGroups, GetProductOptionGroupsVariables>;
|
|
|
|
|
+ truncateOptionsTo = 4;
|
|
|
|
|
+ private inputChange$ = new Subject<ProductOptionGroup[]>();
|
|
|
private destroy$ = new Subject<void>();
|
|
private destroy$ = new Subject<void>();
|
|
|
|
|
|
|
|
constructor(private dataService: DataService) {}
|
|
constructor(private dataService: DataService) {}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
ngOnInit() {
|
|
|
- const optionGroupsQuery = this.dataService.product.getProductOptionGroups();
|
|
|
|
|
- this.optionGroups$ = optionGroupsQuery.stream$.pipe(map(data => data.productOptionGroups));
|
|
|
|
|
|
|
+ this.optionGroupsQuery = this.dataService.product.getProductOptionGroups();
|
|
|
|
|
+ this.optionGroups$ = this.optionGroupsQuery.stream$.pipe(map(data => data.productOptionGroups));
|
|
|
|
|
|
|
|
this.filterInput.valueChanges
|
|
this.filterInput.valueChanges
|
|
|
.pipe(
|
|
.pipe(
|
|
@@ -39,16 +49,32 @@ export class SelectOptionGroupComponent implements OnInit, OnDestroy {
|
|
|
takeUntil(this.destroy$),
|
|
takeUntil(this.destroy$),
|
|
|
)
|
|
)
|
|
|
.subscribe(filterTerm => {
|
|
.subscribe(filterTerm => {
|
|
|
- optionGroupsQuery.ref.refetch({ filterTerm });
|
|
|
|
|
|
|
+ this.optionGroupsQuery.ref.refetch({ filterTerm });
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ ngOnChanges() {
|
|
|
|
|
+ this.inputChange$.next(this.selectedGroups);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
ngOnDestroy() {
|
|
ngOnDestroy() {
|
|
|
this.destroy$.next();
|
|
this.destroy$.next();
|
|
|
this.destroy$.complete();
|
|
this.destroy$.complete();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- isAvailable(group: ProductOptionGroup): boolean {
|
|
|
|
|
- return !this.existingOptionGroupIds.includes(group.id);
|
|
|
|
|
|
|
+ refresh() {
|
|
|
|
|
+ this.optionGroupsQuery.ref.refetch();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ isSelected(group: ProductOptionGroup): boolean {
|
|
|
|
|
+ return this.selectedGroups && !!this.selectedGroups.find(g => g.id === group.id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ optionsTruncated(group: ProductOptionGroup): boolean {
|
|
|
|
|
+ return 0 < this.optionsTrucatedCount(group);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ optionsTrucatedCount(group: ProductOptionGroup): number {
|
|
|
|
|
+ return Math.max(group.options.length - this.truncateOptionsTo, 0);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|