import { FileBuilder } from '../fileBuilder' ; import { AZSymbolInformation } from '../../symbollibraries/azSymbolInformation' ; import { AZSymbolKind } from '../../symbollibraries/azSymbolKind' ; import { ALSymbolsBasedWizard } from './alSymbolsBasedWizard' ; import { ALSyntaxWriter } from '../../allanguage/alSyntaxWriter' ; import { DevToolsExtensionContext } from '../../devToolsExtensionContext' ; export class ALSymbolsBasedReportWizard extends ALSymbolsBasedWizard { constructor ( context ) { super ( context ) ; } async showWizard ( tableSymbols ) { if ( tableSymbols . length == 1 ) await this . showReportWizard ( tableSymbols [ 0 ] ) ; else await this . showMultiReportWizard ( tableSymbols ) ; } async showMultiReportWizard ( tableSymbols ) { if ( ! FileBuilder . checkCrsExtensionFileNamePatternRequired ( ) ) return ; const objType = AZSymbolKind . ReportObject ; let relativeFileDir = await this . getRelativeFileDir ( objType ) ; let startObjectId = await this . getObjectId ( relativeFileDir , "report" , `Please enter a starting ID for the report objects.` , 0 ) ; if ( startObjectId < 0 ) { return ; } for ( let i = 0 ; i < tableSymbols . length ; i ++ ) { let tableSymbol = tableSymbols [ i ] ; let objectId = startObjectId + i ; let objectName = this . getDefaultReportName ( tableSymbol ) ; await this . createAndShowNewReport ( tableSymbol , objType , objectId , objectName , relativeFileDir ) ; } } async showReportWizard ( tableSymbol ) { if ( ! FileBuilder . checkCrsFileNamePatternRequired ( ) ) return ; const objType = AZSymbolKind . ReportObject ; let relativeFileDir = await this . getRelativeFileDir ( objType ) ; let objectId = await this . getObjectId ( relativeFileDir , "report" , "Please enter an ID for the report object." , 0 ) ; if ( objectId < 0 ) { return ; } let objectName = await this . getObjectName ( "Please enter a name for the report object." , this . getDefaultReportName ( tableSymbol ) ) ; if ( ! objectName ) return ; await this . createAndShowNewReport ( tableSymbol , objType , objectId , objectName , relativeFileDir ) ; } private async createAndShowNewReport ( tableSymbol , objType , objectId , objectName , relativeFileDir ) { let fileName = await FileBuilder . getPatternGeneratedFullObjectFileName ( objType , objectId , objectName ) ; this . showNewDocument ( this . buildReportForTable ( tableSymbol , objectId , objectName ) , fileName , relativeFileDir ) ; } buildReportForTable ( tableSymbol , objectId , objectName ) { let writer = new ALSyntaxWriter ( undefined ) ; writer . writeStartObject ( "report" , objectId . toString ( ) , objectName ) ; this . appendDataSet ( writer , tableSymbol ) ; this . appendReportRequestPage ( writer ) ; writer . writeEndObject ( ) ; return writer . toWizardGeneratedString ( ) ; } private appendDataSet ( writer , tableSymbol ) { var dataSetName = writer . createName ( tableSymbol . name ) ; writer . writeStartNamedBlock ( "dataset" ) ; writer . writeStartNameSourceBlock ( "dataitem" , dataSetName , writer . encodeName ( tableSymbol . name ) ) ; let fieldList = [ ] ; tableSymbol . collectChildSymbols ( AZSymbolKind . Field , true , fieldList ) ; fieldList . forEach ( item => { writer . writeNameSourceBlock ( "column" , writer . createName ( item . name ) , writer . encodeName ( item . name ) ) ; } ) ; writer . writeEndBlock ( ) ; writer . writeEndBlock ( ) ; } private appendReportRequestPage ( writer ) { writer . writeStartNamedBlock ( "requestpage" ) ; writer . writeStartLayout ( ) ; writer . writeStartGroup ( "area" , "content" ) ; writer . writeStartGroup ( "group" , "GroupName" ) ; writer . writeEndBlock ( ) ; writer . writeEndBlock ( ) ; writer . writeEndLayout ( ) ; writer . writeStartNamedBlock ( "actions" ) ; writer . writeStartGroup ( "area" , "processing" ) ; writer . writeEndBlock ( ) ; writer . writeEndBlock ( ) ; writer . writeEndBlock ( ) ; } private getDefaultReportName ( tableSymbol ) { return `${ tableSymbol . name . trim ( ) } Report` ; } }