Skip to content
Snippets Groups Projects
time.component.ts 1.28 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
    
    import { Criterion, TimeCriterion } from '../../store/model';
    
    @Component({
        selector: 'app-time',
        templateUrl: 'time.component.html',
        styleUrls: ['time.component.css'],
        changeDetection: ChangeDetectionStrategy.OnPush
    })
    export class TimeComponent {
        @Input() id: number;
        @Input() label: string;
        @Input()
        set criterion(criterion: Criterion) {
            this.getDefault(criterion);
        }
        @Output() add: EventEmitter<TimeCriterion> = new EventEmitter();
    
    
        time: Date = null;
        isTimeDisabled: boolean;
    
        isValidTime: boolean = false;
    
        addCriterion() {
    
            const fd = new TimeCriterion(this.id, this.time);
    
            this.add.emit(fd);
        }
    
        getDefault(criterion: Criterion): void {
            if (!criterion) {
    
                this.time = null;
                this.isTimeDisabled = false;
    
                this.isValidTime = false;
            } else {
                const c = criterion as TimeCriterion;
    
                this.time = c.value;
                this.isTimeDisabled = true;
    
                this.isValidTime = true;
            }
        }
    
        change(): void {
    
                this.isValidTime = false;
            } else {
                this.isValidTime = true;
            }
        }
    }