/* tslint:disable:member-ordering */ import { Directive, ElementRef, HostListener, Input } from '@angular/core'; import { CmTableFixedService, IHighlight } from './cmTableFixex.service'; import { debug } from 'util'; @Directive({ selector: '[rowHighlight]' }) export class RowHighlightDirective { @Input('rowHighlight') rowHighlight: { hoverColor?: string, rowIndex: number }; constructor(private el: ElementRef, private highlithService: CmTableFixedService) { let that = this; that.highlithService.missionHighlight$.subscribe((highlight: IHighlight) => { if (highlight.index == that.rowHighlight.rowIndex) { if (highlight.isSelect) { that.highlightColor(that.rowHighlight.hoverColor ? that.rowHighlight.hoverColor : "#ebf7ff"); } else { that.highlightColor("#ffffff"); } } }); } @HostListener('mouseenter') onMouseEnter() { this.highlithService.highlightMission({ isSelect: true, index: this.rowHighlight.rowIndex }); } @HostListener('mouseleave') onMouseLeave() { this.highlithService.highlightMission({ isSelect: false, index: this.rowHighlight.rowIndex }); } private highlightColor(color: any) { this.el.nativeElement.style.backgroundColor = color; } } /* Copyright 2017 Google Inc. All Rights Reserved. Use of this source code is governed by an MIT-style license that can be found in the LICENSE file at http://angular.io/license */