import { Component , Injector , ViewChild , OnInit } from '@angular/core' ; import { EntityDto , TenantServiceProxy , UpdateTenantFeaturesInput } from '@shared/service-proxies/service-proxies' ; import { FeatureTreeComponent } from '../shared/feature-tree/feature-tree.component' ; import { finalize } from 'rxjs/operators' ; import { ModalComponentBase } from '@shared/common/modal-component-base' ; @ Component ( { selector : 'tenantFeaturesModal' , templateUrl : './tenant-features-modal.component.html' } ) export class TenantFeaturesModalComponent extends ModalComponentBase implements OnInit { @ ViewChild ( 'featureTree' , { static : true } ) featureTree : FeatureTreeComponent ; saving = false ; resettingFeatures = false ; tenantId : number ; tenantName : string ; featureEditData : any = null ; constructor ( injector , private _tenantService ) { super ( injector ) ; } ngOnInit ( ) { this . loadFeatures ( ) ; } loadFeatures ( ) { const self = this ; self . _tenantService . getTenantFeaturesForEdit ( this . tenantId ) . subscribe ( ( result ) => { self . featureTree . editData = result ; } ) ; } save ( ) { if ( ! this . featureTree . areAllValuesValid ( ) ) { this . message . warn ( this . l ( 'InvalidFeaturesWarning' ) ) ; return ; } const input = new UpdateTenantFeaturesInput ( ) ; input . id = this . tenantId ; input . featureValues = this . featureTree . getGrantedFeatures ( ) ; this . saving = true ; this . _tenantService . updateTenantFeatures ( input ) . pipe ( finalize ( ( ) => this . saving = false ) ) . subscribe ( ( ) => { this . notify . info ( this . l ( 'SavedSuccessfully' ) ) ; this . success ( ) ; } ) ; } resetFeatures ( ) { const input = new EntityDto ( ) ; input . id = this . tenantId ; this . resettingFeatures = true ; this . _tenantService . resetTenantSpecificFeatures ( input ) . pipe ( finalize ( ( ) => this . resettingFeatures = false ) ) . subscribe ( ( ) => { this . notify . info ( this . l ( 'ResetSuccessfully' ) ) ; this . loadFeatures ( ) ; } ) ; } }