import * as vscode from 'vscode' ; import { AZSymbolInformation } from '../../symbollibraries/azSymbolInformation' ; import { AZSymbolKind } from '../../symbollibraries/azSymbolKind' ; import { ALSymbolsBasedWizard } from './alSymbolsBasedWizard' ; import { FileBuilder } from '../fileBuilder' ; import { ALSyntaxWriter } from '../../allanguage/alSyntaxWriter' ; import { DevToolsExtensionContext } from '../../devToolsExtensionContext' ; export class ALSymbolsBasedPageWizard extends ALSymbolsBasedWizard { constructor ( context ) { super ( context ) ; } async showWizard ( tableSymbols , pageType ) { if ( tableSymbols . length == 1 ) await this . showPageWizard ( tableSymbols [ 0 ] , pageType ) ; else await this . showMultiPageWizard ( tableSymbols , pageType ) ; } async showMultiPageWizard ( tableSymbols , pageType ) { if ( ! FileBuilder . checkCrsExtensionFileNamePatternRequired ( ) ) return ; const objType = AZSymbolKind . PageObject ; let relativeFileDir = await this . getRelativeFileDir ( objType ) ; let startObjectId = await this . getObjectId ( relativeFileDir , "page" , `Please enter a starting ID for the ${ pageType } pages.` , 0 ) ; if ( startObjectId < 0 ) { return ; } for ( let i = 0 ; i < tableSymbols . length ; i ++ ) { let tableSymbol = tableSymbols [ i ] ; let objectId = startObjectId + i ; let objectName = this . getDefaultPageName ( tableSymbol , pageType ) ; await this . createAndShowNewPage ( tableSymbol , objType , objectId , objectName , pageType , relativeFileDir ) ; } } async showPageWizard ( tableSymbol , pageType ) { if ( ! FileBuilder . checkCrsFileNamePatternRequired ( ) ) return ; const objType = AZSymbolKind . PageObject ; let relativeFileDir = await this . getRelativeFileDir ( objType ) ; let objectId = await this . getObjectId ( relativeFileDir , "page" , `Please enter an ID for the ${ pageType } page.` , 0 ) ; if ( objectId < 0 ) { return ; } let objectName = this . getDefaultPageName ( tableSymbol , pageType ) ; objectName = await this . getObjectName ( `Please enter a name for the ${ pageType } page.` , objectName ) ; if ( ! objectName ) { return ; } await this . createAndShowNewPage ( tableSymbol , objType , objectId , objectName , pageType , relativeFileDir ) ; } private async createAndShowNewPage ( tableSymbol , objType , objectId , objectName , pageType , relativeFileDir ) { let fileName = await FileBuilder . getPatternGeneratedFullObjectFileName ( objType , objectId , objectName ) ; let pageContents ; if ( pageType === 'List' ) { pageContents = this . buildListPageForTable ( tableSymbol , objectId , objectName ) ; } else if ( pageType === 'Card' ) { pageContents = this . buildCardPageForTable ( tableSymbol , objectId , objectName ) ; } else { vscode . window . showErrorMessage ( `Page generator for page type: ${ pageType } not implemented.` ) ; return ; } this . showNewDocument ( pageContents , fileName , relativeFileDir ) ; } buildListPageForTable ( tableSymbol , objectId , objectName ) { return this . buildPageForTable ( tableSymbol , objectId , objectName , "List" , "repeater" ) ; } buildCardPageForTable ( tableSymbol , objectId , objectName ) { return this . buildPageForTable ( tableSymbol , objectId , objectName , "Card" , "group" ) ; } private buildPageForTable ( tableSymbol , objectId , objectName , pageType , fieldGroupType ) { let writer = new ALSyntaxWriter ( undefined ) ; writer . writeStartObject ( "page" , objectId . toString ( ) , objectName ) ; writer . writeLine ( "" ) ; writer . addProperty ( "PageType" , pageType ) ; writer . addProperty ( "SourceTable" , writer . encodeName ( tableSymbol . name ) ) ; writer . addProperty ( "Caption" , writer . encodeString ( objectName ) ) ; if ( pageType === "List" ) { let appArea = vscode . workspace . getConfiguration ( 'alOutline' ) . get < string > ( 'defaultAppArea' ) ; let usageCategory = vscode . workspace . getConfiguration ( 'alOutline' ) . get < string > ( 'defaultListUsageCategory' ) ; if ( ( usageCategory ) && ( usageCategory !== "" ) ) { if ( ( appArea ) && ( appArea !== "" ) ) writer . addProperty ( "ApplicationArea" , appArea ) ; writer . addProperty ( "UsageCategory" , usageCategory ) ; } } writer . writeProperties ( ) ; writer . writeLine ( "" ) ; writer . writeStartLayout ( ) ; writer . writeStartGroup ( "area" , "content" ) ; writer . writeStartGroup ( fieldGroupType , "General" ) ; let fieldList = [ ] ; tableSymbol . collectChildSymbols ( AZSymbolKind . Field , true , fieldList ) ; fieldList . forEach ( item => { writer . writePageField ( item . name , item . name , undefined , undefined , false , undefined ) ; } ) ; writer . writeEndBlock ( ) ; writer . writeEndBlock ( ) ; writer . writeEndLayout ( ) ; writer . writeEndObject ( ) ; return writer . toWizardGeneratedString ( ) ; } private getDefaultPageName ( tableSymbol , pageType ) { return `${ tableSymbol . name . trim ( ) } ${ pageType }` ; } }