File

feature-libs/organization/administration/components/shared/item-active.directive.ts

Implements

OnInit OnDestroy

Metadata

Selector [cxOrgItemActive]

Index

Properties
Methods

Constructor

constructor(itemService: ItemService<T>, messageService: MessageService)
Parameters :
Name Type Optional
itemService ItemService<T> No
messageService MessageService No

Methods

Protected handleDisabledItems
handleDisabledItems(item: BaseItem)
Parameters :
Name Type Optional
item BaseItem No
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

Protected subscription
import { Directive, OnDestroy, OnInit } from '@angular/core';
import { GlobalMessageType } from '@spartacus/core';
import { distinctUntilChanged, filter } from 'rxjs/operators';
import { ItemService } from './item.service';
import { MessageService } from './message/services/message.service';
import { BaseItem } from './organization.model';

@Directive({
  selector: '[cxOrgItemActive]',
})
export class ItemActiveDirective<T = BaseItem> implements OnInit, OnDestroy {
  protected subscription;

  constructor(
    protected itemService: ItemService<T>,
    protected messageService: MessageService
  ) {}

  ngOnInit() {
    this.subscription = this.itemService.current$
      .pipe(
        distinctUntilChanged(
          (previous: BaseItem, current: BaseItem) =>
            previous?.active === current?.active
        ),
        filter((item) => item && item?.active === false)
      )
      .subscribe((item) => this.handleDisabledItems(item));
  }

  protected handleDisabledItems(item: BaseItem) {
    this.messageService.add({
      message: {
        key: 'organization.notification.disabled',
        params: { item },
      },
      type: GlobalMessageType.MSG_TYPE_ERROR,
    });
  }

  ngOnDestroy() {
    this.subscription?.unsubscribe();
  }
}

result-matching ""

    No results matching ""