import { ScenarioResult } from './../shared/services/scenario/scenario.models' ; import { BroadcastEvent } from 'app/shared/models/broadcast-event' ; import { BroadcastService } from './../shared/services/broadcast.service' ; import { Subject } from 'rxjs/Subject' ; import { Subscription as RxSubscription } from 'rxjs/Subscription' ; import { DisableInfo } from './feature-item' ; import { PortalService } from '../shared/services/portal.service' ; import { OpenBladeInfo , FrameBladeParams } from '../shared/models/portal' ; import { SiteTabIds } from 'app/shared/models/constants' ; import { PortalResources } from 'app/shared/models/portal-resources' ; export interface DisableInfo { enabled : boolean ; disableMessage : string ; } export class FeatureItem { public title : string | null ; public keywords : string | null ; public enabled = true ; public info : string | null ; public warning : string | null ; public isHighlighted : boolean | null ; public isEmpty : boolean | null ; public highlight : boolean | null ; public iconUrl = 'image/activity-log.svg' ; public superScriptIconUrl : string | null = null ; public nameFocusable : boolean ; public imageFocusable : boolean ; public onName = false ; public onImage = false ; constructor ( title , keywords , info , iconUrl ? , superScriptIconUrl ? ) { this . title = title ; this . keywords = keywords ; this . info = info ; this . iconUrl = iconUrl ? iconUrl : this . iconUrl ; this . superScriptIconUrl = superScriptIconUrl ; } click ( ) { } dispose ( ) { } } export class DisableableFeature extends FeatureItem { private _enabledRxSub : RxSubscription ; private _overrideSub : RxSubscription ; public enabled = false ; constructor ( title , keywords , info , imageUrl , superScriptIconUrl ? , _disableInfoStream ? , overrideDisableInfo ? , overrideDisableStream ? ) { super ( title , keywords , info , imageUrl , superScriptIconUrl ) ; if ( overrideDisableInfo ) { this . setWarningandEnabled ( overrideDisableInfo ) ; } else if ( overrideDisableStream ) { this . _overrideSub = overrideDisableStream . subscribe ( streamInfo => { this . setWarningandEnabled ( streamInfo ) ; } ) ; } else if ( _disableInfoStream ) { this . _enabledRxSub = _disableInfoStream . subscribe ( disableInfo => { this . enabled = disableInfo . enabled ; if ( ! this . enabled ) { this . warning = disableInfo . disableMessage ; } } ) ; } } dispose ( ) { if ( this . _enabledRxSub ) { this . _enabledRxSub . unsubscribe ( ) ; this . _enabledRxSub = null ; } if ( this . _overrideSub ) { this . _overrideSub . unsubscribe ( ) ; this . _overrideSub = null ; } } setWarningandEnabled ( scenarioResult ) { if ( scenarioResult . status === 'disabled' ) { this . warning = scenarioResult . data ; } this . enabled = scenarioResult . status !== 'disabled' ; } } abstract class BaseDisableableBladeFeature < T = any > extends DisableableFeature { constructor ( title , keywords , info , imageUrl , protected _bladeInfo , protected _portalService , disableInfoStream ? , overrideDisableInfo ? ) { super ( title , keywords , info , imageUrl , null , disableInfoStream , overrideDisableInfo ) ; } } export class DisableableBladeFeature extends BaseDisableableBladeFeature < any > { click ( ) { this . _portalService . openBlade ( this . _bladeInfo , 'site-manage' ) ; } } export class DisableableFrameBladeFeature < T = any > extends BaseDisableableBladeFeature < FrameBladeParams < T > > { click ( ) { this . _portalService . openFrameBlade ( this . _bladeInfo , 'site-manage' ) ; } } abstract class BaseBladeFeature < T = any > extends FeatureItem { constructor ( title , keywords , info , imageUrl , public bladeInfo , protected _portalService ) { super ( title , keywords , info , imageUrl ) ; } } export class BladeFeature extends BaseBladeFeature < any > { click ( ) { this . _portalService . openBlade ( this . bladeInfo , 'site-manage' ) ; } } export class FrameBladeFeature < T = any > extends BaseBladeFeature < FrameBladeParams < T > > { click ( ) { this . _portalService . openFrameBlade ( this . bladeInfo , 'site-manage' ) ; } } export class OpenBrowserWindowFeature extends FeatureItem { constructor ( title , keywords , info , private _url ) { super ( title , keywords , info ) ; } click ( ) { window . open ( this . _url ) ; } } export class TabFeature extends FeatureItem { constructor ( title , keywords , info , imageUrl , public featureId , private _broadcastService ) { super ( title , keywords , info , imageUrl , 'image/new-tab.svg' ) ; if ( featureId === SiteTabIds . logicApps ) { this . warning = PortalResources . tab_logicAppsDeprecation ; } } click ( ) { this . _broadcastService . broadcastEvent ( BroadcastEvent . OpenTab , this . featureId ) ; } } export class DisableableTabFeature extends DisableableFeature { constructor ( title , keywords , info , imageUrl , public featureId , private _broadcastService , disableInfoStream ? , overrideDisableInfo ? ) { super ( title , keywords , info , imageUrl , 'image/new-tab.svg' , disableInfoStream , overrideDisableInfo ) ; } click ( ) { this . _broadcastService . broadcastEvent ( BroadcastEvent . OpenTab , this . featureId ) ; } }