import { WebSiteManagementClient , WebSiteManagementModels } from '@azure/arm-appservice' ; import { createSlot , ParsedSite } from 'vscode-azureappservice' ; import { AzExtParentTreeItem , AzExtTreeItem , IActionContext , ICreateChildImplContext , TreeItemIconPath } from 'vscode-azureextensionui' ; import { showSiteCreated } from '../commands/createFunctionApp/showSiteCreated' ; import { localize } from '../localize' ; import { createWebSiteClient } from '../utils/azureClients' ; import { treeUtils } from '../utils/treeUtils' ; import { ProductionSlotTreeItem } from './ProductionSlotTreeItem' ; import { SlotTreeItem } from './SlotTreeItem' ; export class SlotsTreeItem extends AzExtParentTreeItem { public static contextValue : string = 'azFuncSlots' ; public readonly contextValue : string = SlotsTreeItem . contextValue ; public readonly label : string = localize ( 'slots' , 'Slots' ) ; public readonly childTypeLabel : string = localize ( 'slot' , 'Slot' ) ; public readonly parent : ProductionSlotTreeItem ; public suppressMaskLabel : boolean = true ; private _nextLink : string | undefined ; public constructor ( parent ) { super ( parent ) ; } public get id ( ) : string { return 'slots' ; } public get iconPath ( ) : TreeItemIconPath { return treeUtils . getIconPath ( this . contextValue ) ; } public hasMoreChildrenImpl ( ) { return ! ! this . _nextLink ; } public async loadMoreChildrenImpl ( clearCache , context ) { if ( clearCache ) { this . _nextLink = undefined ; } const client = await createWebSiteClient ( [ context , this ] ) ; const webAppCollection = this . _nextLink ? await client . webApps . listSlotsNext ( this . _nextLink ) : await client . webApps . listSlots ( this . parent . site . resourceGroup , this . parent . site . siteName ) ; this . _nextLink = webAppCollection . nextLink ; return await this . createTreeItemsWithErrorHandling ( webAppCollection , 'azFuncInvalidSlot' , ( site ) => { return new SlotTreeItem ( this , new ParsedSite ( site , this . subscription ) ) ; } , ( site ) => { return site . name ; } ) ; } public async createChildImpl ( context ) { const existingSlots = < SlotTreeItem [ ] > await this . getCachedChildren ( context ) ; const newSite = await createSlot ( this . parent . site , existingSlots . map ( s => s . site ) , context ) ; const parsedSite = new ParsedSite ( newSite , this . subscription ) ; showSiteCreated ( parsedSite , context ) ; return new SlotTreeItem ( this , parsedSite ) ; } }