|
|
@@ -2,29 +2,16 @@ import {
|
|
|
AfterViewInit,
|
|
|
ChangeDetectionStrategy,
|
|
|
Component,
|
|
|
- HostBinding,
|
|
|
- Injector,
|
|
|
Input,
|
|
|
- OnChanges,
|
|
|
OnInit,
|
|
|
Self,
|
|
|
- SimpleChanges,
|
|
|
ViewChild,
|
|
|
} from '@angular/core';
|
|
|
-import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
|
-import { BehaviorSubject, combineLatest, Observable, of } from 'rxjs';
|
|
|
+import { combineLatest } from 'rxjs';
|
|
|
import { map, tap } from 'rxjs/operators';
|
|
|
-
|
|
|
-import { ActionBarLocationId } from '../../../common/component-registry-types';
|
|
|
-import { DataService } from '../../../data/providers/data.service';
|
|
|
-import {
|
|
|
- ActionBarButtonState,
|
|
|
- ActionBarContext,
|
|
|
- ActionBarDropdownMenuItem,
|
|
|
-} from '../../../providers/nav-builder/nav-builder-types';
|
|
|
-import { NavBuilderService } from '../../../providers/nav-builder/nav-builder.service';
|
|
|
-import { NotificationService } from '../../../providers/notification/notification.service';
|
|
|
+import { ActionBarDropdownMenuItem } from '../../../providers/nav-builder/nav-builder-types';
|
|
|
+import { ActionBarBaseComponent } from '../action-bar-items/action-bar-base.component';
|
|
|
import { DropdownComponent } from '../dropdown/dropdown.component';
|
|
|
|
|
|
@Component({
|
|
|
@@ -47,55 +34,27 @@ import { DropdownComponent } from '../dropdown/dropdown.component';
|
|
|
},
|
|
|
],
|
|
|
})
|
|
|
-export class ActionBarDropdownMenuComponent implements OnInit, OnChanges, AfterViewInit {
|
|
|
+export class ActionBarDropdownMenuComponent
|
|
|
+ extends ActionBarBaseComponent<ActionBarDropdownMenuItem>
|
|
|
+ implements OnInit, AfterViewInit
|
|
|
+{
|
|
|
@ViewChild('dropdownComponent')
|
|
|
dropdownComponent: DropdownComponent;
|
|
|
|
|
|
@Input()
|
|
|
alwaysShow = false;
|
|
|
|
|
|
- @HostBinding('attr.data-location-id')
|
|
|
- @Input()
|
|
|
- locationId: ActionBarLocationId;
|
|
|
-
|
|
|
- items$: Observable<ActionBarDropdownMenuItem[]>;
|
|
|
- buttonStates: { [id: string]: Observable<ActionBarButtonState> } = {};
|
|
|
- private locationId$ = new BehaviorSubject<string>('');
|
|
|
private onDropdownComponentResolvedFn: (dropdownComponent: DropdownComponent) => void;
|
|
|
|
|
|
- constructor(
|
|
|
- private navBuilderService: NavBuilderService,
|
|
|
- private route: ActivatedRoute,
|
|
|
- private dataService: DataService,
|
|
|
- private notificationService: NotificationService,
|
|
|
- private injector: Injector,
|
|
|
- ) {}
|
|
|
-
|
|
|
ngOnInit() {
|
|
|
this.items$ = combineLatest(this.navBuilderService.actionBarDropdownConfig$, this.locationId$).pipe(
|
|
|
map(([items, locationId]) => items.filter(config => config.locationId === locationId)),
|
|
|
tap(items => {
|
|
|
- const context = this.createContext();
|
|
|
- for (const item of items) {
|
|
|
- const buttonState$ =
|
|
|
- typeof item.buttonState === 'function'
|
|
|
- ? item.buttonState(context)
|
|
|
- : of({
|
|
|
- disabled: false,
|
|
|
- visible: true,
|
|
|
- });
|
|
|
- this.buttonStates[item.id] = buttonState$;
|
|
|
- }
|
|
|
+ this.buildButtonStates(items);
|
|
|
}),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- ngOnChanges(changes: SimpleChanges): void {
|
|
|
- if ('locationId' in changes) {
|
|
|
- this.locationId$.next(changes['locationId'].currentValue);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
ngAfterViewInit() {
|
|
|
if (this.onDropdownComponentResolvedFn) {
|
|
|
this.onDropdownComponentResolvedFn(this.dropdownComponent);
|
|
|
@@ -105,26 +64,4 @@ export class ActionBarDropdownMenuComponent implements OnInit, OnChanges, AfterV
|
|
|
onDropdownComponentResolved(fn: (dropdownComponent: DropdownComponent) => void) {
|
|
|
this.onDropdownComponentResolvedFn = fn;
|
|
|
}
|
|
|
-
|
|
|
- handleClick(event: MouseEvent, item: ActionBarDropdownMenuItem) {
|
|
|
- if (typeof item.onClick === 'function') {
|
|
|
- item.onClick(event, this.createContext());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- getRouterLink(item: ActionBarDropdownMenuItem): any[] | null {
|
|
|
- return this.navBuilderService.getRouterLink(
|
|
|
- { routerLink: item.routerLink, context: this.createContext() },
|
|
|
- this.route,
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- private createContext(): ActionBarContext {
|
|
|
- return {
|
|
|
- route: this.route,
|
|
|
- injector: this.injector,
|
|
|
- dataService: this.dataService,
|
|
|
- notificationService: this.notificationService,
|
|
|
- };
|
|
|
- }
|
|
|
}
|