All files / components/start upp-start.ts

100% Statements 64/64
70.21% Branches 33/47
100% Functions 9/9
100% Lines 60/60

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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 1277x 7x 7x   7x   7x 7x 7x   7x 7x                           8x       7x 8x 8x   8x   8x 8x       9x               2x               1x 1x 1x 1x 1x 1x 1x 1x     1x       1x 1x 1x 1x 1x 1x 1x 1x     1x       1x 1x 1x 1x 1x 1x 1x 1x     1x       1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x   1x     1x               4x    
import { Component, OnDestroy } from '@angular/core';
import { Input, Output, EventEmitter } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
 
import { ViewRenderer } from '@unpispas/upp-wdgt';
 
import { languageService, languageSupport } from '@unpispas/upp-base';
import { dataService } from '@unpispas/upp-data';
import { viewService } from '@unpispas/upp-base';
 
import { Product } from '@unpispas/upp-data';
import { Family } from '@unpispas/upp-data';
 
import { PlaceView } from '@unpispas/upp-data';
import { ProductView } from '@unpispas/upp-data';
 
@Component({
    selector: 'upp-product-create',
    changeDetection: ChangeDetectionStrategy.OnPush,
    templateUrl: './upp-start.html',
    styleUrls: [
      './upp-start.scss'
    ],
    providers: [{
        provide: ViewRenderer,
        useFactory: (change: ChangeDetectorRef) => new ViewRenderer(change),
        deps: [ChangeDetectorRef]
    }]       
})
export class UppProductStartComponent extends languageSupport implements OnDestroy {
    @Input() place: PlaceView | null = null;
    @Input() parent: ProductView | null = null;
 
    @Output() Created = new EventEmitter<ProductView>();
 
    constructor(private lang: languageService, private change: ViewRenderer, private data: dataService, public view: viewService){
        super(lang, change.cdref);
    }
 
    ngOnDestroy(): void {
        super.OnDestroy();
    }
 
    /********************************/
    /* DISPLAY OPTIONS              */
    /********************************/ 
 
    get CanAddFamily() : boolean {
        return (this.parent == null);
    }
 
    /********************************/
    /* EVENT HANDLERS               */
    /********************************/  
    
    OnCreateGroup(){
        const _group = new Product(null, this.data);
        if (_group){
            _group.place = this.place?.object || null;
            _group.parent = this.parent?.object || null;
            _group.generic = false;
            _group.isgroup = true;
            _group.family = null;
            _group.status = 'AC';
        }
 
        this.OnCreate(_group);            
    }
 
    OnCreateProduct(){
        const _product = new Product(null, this.data);
        if (_product){
            _product.place = this.place?.object || null;
            _product.parent = this.parent?.object || null;
            _product.generic = false; 
            _product.isgroup = false;
            _product.family = null;
            _product.status = 'AC';
        }
 
        this.OnCreate(_product);        
    }
 
    OnCreateGeneric(){
        const _generic = new Product(null, this.data);
        if (_generic){
            _generic.place = this.place?.object || null;
            _generic.parent = this.parent?.object || null;
            _generic.generic = true; 
            _generic.isgroup = false;
            _generic.family = null;
            _generic.status = 'AC';
        }
 
        this.OnCreate(_generic);
    }
 
    OnCreateFamily(){
        const _group = new Product(null, this.data);
        if (_group){    
            _group.place = this.place?.object || null;
            _group.generic = false;
            _group.isgroup = true;
            _group.family = null;   // will be set below
            _group.status = 'AC';
        }
 
        const _family = new Family(null, this.data);
        if (_family){
            _family.product = _group;
            _family.allday = false;
            _family.status = 'AC'
 
            _group.family = _family;
        }
 
        this.OnCreate(_group);            
    }
 
    /********************************/
    /* PRIVATE METHODS              */
    /********************************/  
 
    private OnCreate(product: Product){
        this.Created.emit(this.data.alives.get(product) as ProductView);    
    }
}