All files / components/option/view upp-view.ts

96.66% Statements 29/30
83.33% Branches 5/6
100% Functions 5/5
96% Lines 24/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 646x 6x 6x   6x   6x 6x 6x 6x     6x                         3x       6x 3x 3x   3x 3x       3x               2x 2x 2x             2x 1x     1x 1x 1x    
import { Component, OnDestroy } from '@angular/core';
import { Input } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
 
import { ViewRenderer } from '@unpispas/upp-wdgt';
 
import { alertService } from '@unpispas/upp-base';
import { languageService, languageSupport } from '@unpispas/upp-base';
import { dataService } from '@unpispas/upp-data';
import { viewService } from '@unpispas/upp-base';
 
import { UserView } from '@unpispas/upp-data';
import { EmployeePermission } from '@unpispas/upp-data';
import { CategoryView } from '@unpispas/upp-data';
import { ProductOptView } from '@unpispas/upp-data';
 
@Component({
    selector: 'upp-option-view',
    changeDetection: ChangeDetectionStrategy.OnPush,
    templateUrl: './upp-view.html',
    styleUrls: [
      './upp-view.scss'
    ],
    providers: [{
        provide: ViewRenderer,
        useFactory: (change: ChangeDetectorRef) => new ViewRenderer(change),
        deps: [ChangeDetectorRef]
    }]       
})
export class UppOptionViewComponent extends languageSupport implements OnDestroy {
    @Input() category: CategoryView | null = null;
    @Input() option: ProductOptView | null = null;
 
    constructor(private lang: languageService, private change: ViewRenderer, private alertCtrl: alertService, private data: dataService, public view: viewService){
        super(lang, change.cdref);
    }
 
    ngOnDestroy(): void {
        super.OnDestroy();
    }
 
    /********************************/
    /* EVENT HANDLERS               */
    /********************************/  
    
    private CanAvailable(): boolean{
        const _user: UserView = this.data.alives.get(this.data.user) as UserView;
        if (_user){
            return _user.IsAllowedTo(EmployeePermission.CanAvailable);
        }
 
        return false;  
    }
 
    OnAvailable(value: boolean): void {
        if (!this.option || !this.CanAvailable()){
            return;
        }
 
        this.option.status = (value) ? 'AC' : 'UN';
        this.option.DoCommit();
        this.change.markForCheck();
    }
}