File

libs/favorite/src/lib/favorite-toggler/favorite-toggler.component.ts

Implements

OnChanges

Metadata

selector n52-favorite-toggler
templateUrl ./favorite-toggler.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(favSrvc: FavoriteService, notifier: NotifierService, translate: TranslateService)
Parameters :
Name Type Optional
favSrvc FavoriteService No
notifier NotifierService No
translate TranslateService No

Inputs

dataset
Type : HelgolandTimeseries
options
Type : DatasetOptions

Methods

Public ngOnChanges
ngOnChanges(changes: SimpleChanges)
Parameters :
Name Type Optional
changes SimpleChanges No
Returns : void
Public toggle
toggle()
Returns : void

Properties

Public isFavorite
Type : boolean
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { DatasetOptions, HelgolandTimeseries, NotifierService } from '@helgoland/core';
import { TranslateService } from '@ngx-translate/core';

import { FavoriteService } from '../service/favorite.service';

@Component({
  selector: 'n52-favorite-toggler',
  templateUrl: './favorite-toggler.component.html'
})
export class FavoriteTogglerComponent implements OnChanges {

  @Input() public dataset: HelgolandTimeseries;
  @Input() public options: DatasetOptions;

  public isFavorite: boolean;

  constructor(
    protected favSrvc: FavoriteService,
    protected notifier: NotifierService,
    protected translate: TranslateService
  ) { }

  public ngOnChanges(changes: SimpleChanges): void {
    if (changes.dataset && this.dataset) {
      this.isFavorite = this.favSrvc.hasFavorite(this.dataset);
    }
  }

  public toggle() {
    if (this.isFavorite) {
      this.isFavorite = false;
      this.favSrvc.removeFavorite(this.dataset.internalId);
      this.translate.get('favorite.notifier.remove-favorite').subscribe((translation) => {
        this.notifier.notify(translation + ': ' + this.dataset.label);
      });
    } else {
      this.isFavorite = true;
      this.favSrvc.addFavorite(this.dataset, this.options);
      this.translate.get('favorite.notifier.add-favorite').subscribe((translation) => {
        this.notifier.notify(translation + ': ' + this.dataset.label);
      });
    }
  }
}
<i class="fa" (click)="toggle(); $event.stopPropagation();" [ngClass]="isFavorite ? 'fa-star' : 'fa-star-o'"></i>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""