File

src/lib/table-row-actions/table-row-header-action.directive.ts

Extends

AbstractTableRowAction

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Inputs

Constructor

constructor(renderer: Renderer2, overlay: Overlay, elementRef: ElementRef, actionMethod: TableRowActionMethod<Data>, cdr: ChangeDetectorRef, vcr: ViewContainerRef, tableDataSourceDirective: TableDataSourceDirective, snackBar: MatSnackBar, matButton: MatButton | null, matTooltip: MatTooltip | null, injector: Injector, selectRowService: SelectRowService<Data> | null)
Parameters :
Name Type Optional
renderer Renderer2 No
overlay Overlay No
elementRef ElementRef No
actionMethod TableRowActionMethod<Data> No
cdr ChangeDetectorRef No
vcr ViewContainerRef No
tableDataSourceDirective TableDataSourceDirective No
snackBar MatSnackBar No
matButton MatButton | null No
matTooltip MatTooltip | null No
injector Injector No
selectRowService SelectRowService<Data> | null No

Inputs

rxapTableRowHeaderAction
Type : string
Required :  true

Methods

Protected getElementList
getElementList()
Inherited from AbstractTableRowAction
Returns : Data[]
Public Async execute
execute()
Inherited from AbstractTableRowAction
Returns : Promise<void>
Public onClick
onClick($event: Event)
Decorators :
@HostListener('click', ['$event'])
Inherited from AbstractTableRowAction
Parameters :
Name Type Optional
$event Event No
Returns : any
Public onConfirmed
onConfirmed()
Decorators :
@HostListener('confirmed')
Inherited from AbstractTableRowAction
Returns : Promise<void>
Protected setButtonDisabled
setButtonDisabled()
Inherited from AbstractTableRowAction

Disables the action. If the button is pressed the action is NOT executed

Hint: the button is set to disabled = true to prevent any conflict with extern button enable features linke : rxapHasEnablePermission

Returns : void
Protected setButtonEnabled
setButtonEnabled()
Inherited from AbstractTableRowAction

Enables the action. If the button is pressed the action is executed

TODO : find a way to communicate the disabled state between the features Hint: the button is set to disabled = false to prevent any conflict with extern button enable features linke : rxapHasEnablePermission

Returns : void

Properties

Public Readonly isHeader
Default value : true
Inherited from AbstractTableRowAction
Protected options
Type : TableActionMethodOptions | null
Default value : null
Inherited from AbstractTableRowAction
Public Abstract type
Type : string
Inherited from AbstractTableRowAction
import { Overlay } from '@angular/cdk/overlay';
import {
  ChangeDetectorRef,
  Directive,
  ElementRef,
  Inject,
  INJECTOR,
  Injector,
  Input,
  OnDestroy,
  OnInit,
  Optional,
  Renderer2,
  ViewContainerRef,
} from '@angular/core';
import { MatButton } from '@angular/material/button';
import { MatSnackBar } from '@angular/material/snack-bar';
import { MatTooltip } from '@angular/material/tooltip';
import { Subscription } from 'rxjs';
import {
  map,
  startWith,
  tap,
} from 'rxjs/operators';
import { SelectRowService } from '../select-row/select-row.service';
import { TableDataSourceDirective } from '../table-data-source.directive';
import { AbstractTableRowAction } from './abstract-table-row-action';
import { RXAP_TABLE_ROW_ACTION_METHOD } from './tokens';
import { TableRowActionMethod } from './types';

@Directive({
  selector: 'button[rxapTableRowHeaderAction]',
  standalone: true,
  // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
  inputs: [ 'errorMessage', 'successMessage', 'refresh', 'color' ],
})
export class TableRowHeaderActionDirective<Data extends Record<string, any>>
  extends AbstractTableRowAction<Data>
  implements OnInit, OnDestroy {

  public override readonly isHeader = true;

  private _subscription?: Subscription;

  constructor(
    @Inject(Renderer2)
      renderer: Renderer2,
    @Inject(Overlay)
      overlay: Overlay,
    @Inject(ElementRef)
      elementRef: ElementRef,
    @Inject(RXAP_TABLE_ROW_ACTION_METHOD)
      actionMethod: TableRowActionMethod<Data>,
    @Inject(ChangeDetectorRef)
      cdr: ChangeDetectorRef,
    @Inject(ViewContainerRef)
      vcr: ViewContainerRef,
    @Inject(TableDataSourceDirective)
      tableDataSourceDirective: TableDataSourceDirective,
    @Inject(MatSnackBar)
      snackBar: MatSnackBar,
    @Optional()
    @Inject(MatButton)
      matButton: MatButton | null,
    @Optional()
    @Inject(MatTooltip)
      matTooltip: MatTooltip | null,
    @Inject(INJECTOR)
      injector: Injector,
    @Optional()
    @Inject(SelectRowService)
    private readonly selectRowService: SelectRowService<Data> | null,
  ) {
    super(
      renderer,
      overlay,
      elementRef,
      actionMethod,
      cdr,
      vcr,
      tableDataSourceDirective,
      snackBar,
      matButton,
      matTooltip,
      injector,
    );
  }

  public override ngOnDestroy() {
    this._subscription?.unsubscribe();
  }

  public override ngOnInit() {
    if (this.selectRowService) {
      this._subscription = this.selectRowService.selectedRows$
                               .pipe(
                                 startWith(this.selectRowService.selectedRows),
                                 map((rows) => rows.length !== 0),
                                 tap((hasSelected) => {
                                   if (hasSelected) {
                                     this.setButtonEnabled();
                                   } else {
                                     this.setButtonDisabled();
                                   }
                                   this.cdr.detectChanges();
                                 }),
                               )
                               .subscribe();
    } else {
      this.setButtonDisabled();
    }
  }

  protected override getElementList(): Data[] {
    return this.selectRowService?.selectedRows ?? [];
  }

  @Input({
    required: true,
    alias: 'rxapTableRowHeaderAction',
  })
  public override type!: string;
}

results matching ""

    No results matching ""