import { Injector } from '@angular/core' ; import { Observable } from 'rxjs/Rx' ; import { LogCategories } from './../../../shared/models/constants' ; import { ServerFarm } from '../../../shared/models/server-farm' ; import { ArmObj , ResourceId , Sku } from '../../../shared/models/arm/arm-obj' ; import { PlanService } from '../../../shared/services/plan.service' ; import { PlanSpecPickerData } from './plan-price-spec-manager' ; import { PriceSpec , PriceSpecInput } from './price-spec' ; import { PortalResources } from './../../../shared/models/portal-resources' ; export abstract class DV3SeriesPriceSpec extends PriceSpec { private readonly _sku : string ; private readonly _skuNotAvailableMessage : string ; private readonly _skuNotAvailableLink : string ; private _planService : PlanService ; constructor ( injector , sku , skuNotAvailableMessage , skuNotAvailableLink ) { super ( injector ) ; this . _planService = injector . get ( PlanService ) ; this . _sku = sku ; this . _skuNotAvailableMessage = this . _ts . instant ( skuNotAvailableMessage ) ; this . _skuNotAvailableLink = skuNotAvailableLink ; } protected abstract _matchSku ( sku ) ; protected abstract _shouldHideForNewPlan ( data ) ; protected abstract _shouldHideForExistingPlan ( plan , containsJbossSite ) ; private _checkIfSkuEnabledOnStamp ( resourceId ) { if ( this . state !== 'hidden' ) { return this . _planService . getAvailableSkusForPlan ( resourceId ) . do ( availableSkus => { this . state = availableSkus . find ( s => this . _matchSku ( s . sku ) ) ? 'enabled' : 'disabled' ; if ( this . state === 'disabled' ) { this . disabledMessage = this . _skuNotAvailableMessage ; this . disabledInfoLink = this . _skuNotAvailableLink ; } } ) ; } return Observable . of ( null ) ; } private _checkIfSkuEnabledInRegion ( subscriptionId , location , isLinux , isXenonWorkersEnabled ) { if ( this . state !== 'hidden' && this . state !== 'disabled' ) { return this . _planService . getAvailableGeoRegionsForSku ( subscriptionId , this . _sku , isLinux , isXenonWorkersEnabled ) . do ( geoRegions => { if ( ! geoRegions . find ( g => g . properties . name . toLowerCase ( ) === location . toLowerCase ( ) ) ) { this . state = 'disabled' ; this . disabledMessage = this . _skuNotAvailableMessage ; this . disabledInfoLink = this . _skuNotAvailableLink ; } } ) . catch ( e => { this . skuAvailabilityCheckFailed = true ; this . _logService . error ( LogCategories . specPicker , '/get-available-georegions-for-sku' , `Failed to get available georegions for sku: ${ e }` ) ; return Observable . of ( null ) ; } ) ; } return Observable . of ( null ) ; } private _updateHardwareItemsList ( isHyperV ) { if ( isHyperV ) { this . hardwareItems . splice ( 0 , 0 , { iconUrl : 'image/storage.svg' , title : this . _ts . instant ( PortalResources . hyperVIsolation ) , description : this . _ts . instant ( PortalResources . hyperVIsolationDesc ) , } ) ; } } protected _updateFeatureItemsList ( input ) { } runInitialization ( input ) { if ( input . planDetails ) { this . _updateFeatureItemsList ( input ) ; this . _updateHardwareItemsList ( input . planDetails . plan . properties . hyperV ) ; this . state = this . _shouldHideForExistingPlan ( input . planDetails . plan , input . planDetails . containsJbossSite ) ? 'hidden' : this . state ; return this . _checkIfSkuEnabledOnStamp ( input . planDetails . plan . id ) . switchMap ( _ => { return this . checkIfDreamspark ( input . subscriptionId ) ; } ) ; } else if ( input . specPickerInput . data ) { const isXenon = input . specPickerInput . data . hyperV || input . specPickerInput . data . isXenon ; this . _updateFeatureItemsList ( input ) ; this . _updateHardwareItemsList ( isXenon ) ; this . state = this . _shouldHideForNewPlan ( input . specPickerInput . data ) ? 'hidden' : this . state ; return this . checkIfDreamspark ( input . subscriptionId ) . switchMap ( _ => { return this . _checkIfSkuEnabledInRegion ( input . subscriptionId , input . specPickerInput . data . location , input . specPickerInput . data . isLinux , isXenon ) ; } ) ; } return Observable . of ( null ) ; } }