import * as path from 'path' ; import { DevToolsExtensionContext } from "../../devToolsExtensionContext" ; import { ToolsGetObjectsListRequest } from '../../langserver/symbolsinformation/toolsGetObjectsListRequest' ; import { ToolsSymbolInformationRequest } from '../../langserver/symbolsinformation/toolsSymbolInformationRequest' ; import { SymbolWithNameInformation } from '../../symbolsinformation/smbolWithNameInformation' ; import { ALPermissionSetSyntaxBuilder } from '../syntaxbuilders/alPermissionSetSyntaxBuilder' ; import { ALObjectWizardSettings } from "./alObjectWizardSettings" ; import { ALPermissionSetWizardData } from "./alPermissionSetWizardData" ; import { ProjectItemWizardPage } from "./projectItemWizardPage" ; export class ALPermissionSetWizardPage extends ProjectItemWizardPage { private _permissionSetWizardData : ALPermissionSetWizardData ; constructor ( toolsExtensionContext , title , settings , data ) { if ( ! title ) title = "AL Permission Set Wizard" ; super ( toolsExtensionContext , title , settings ) ; this . _permissionSetWizardData = data ; } protected onDocumentLoaded ( ) { this . sendMessage ( { command : 'setData' , data : this . _permissionSetWizardData } ) ; this . loadPermissionSets ( ) ; } protected getHtmlContentPath ( ) { return path . join ( 'htmlresources' , 'alpermissionsetwizard' , 'alpermissionsetwizard.html' ) ; } protected getViewType ( ) { return "azALDevTools.ALPermissionSetWizard" ; } protected async finishWizard ( data ) { await this . setBuilderData ( data ) ; this . runBuilder ( ) ; return true ; } protected async setBuilderData ( data ) { this . _permissionSetWizardData . objectId = data . objectId ; this . _permissionSetWizardData . objectName = data . objectName ; this . _permissionSetWizardData . objectCaption = data . objectCaption ; this . _permissionSetWizardData . inclAllObjects = data . inclAllObjects ; this . _permissionSetWizardData . selectedPermissionSetList = data . selectedPermissionSetList ; this . _permissionSetWizardData . projectSettings = await this . getProjectSettings ( ) ; if ( this . _permissionSetWizardData . inclAllObjects ) { let getObjectsRequest = new ToolsGetObjectsListRequest ( this . _settings . getDestDirectoryPath ( ) ) ; getObjectsRequest . setIncludeObjectsWithPermissions ( ) ; let getObjectsResponse = await this . _toolsExtensionContext . toolsLangServerClient . getObjectsList ( getObjectsRequest ) ; if ( ( getObjectsResponse ) && ( getObjectsResponse . symbols ) ) this . _permissionSetWizardData . selectedObjectsList = getObjectsResponse . symbols ; } } protected runBuilder ( ) { var builder = new ALPermissionSetSyntaxBuilder ( ) ; var source = builder . buildFromPermissionSetWizardData ( this . _settings . getDestDirectoryUri ( ) , this . _permissionSetWizardData ) ; this . createObjectFile ( 'PermissionSet' , '' , this . _permissionSetWizardData . objectName , source ) ; } protected async loadPermissionSets ( ) { let response = await this . _toolsExtensionContext . toolsLangServerClient . getPermissionSetsList ( new ToolsSymbolInformationRequest ( this . _settings . getDestDirectoryPath ( ) , false ) ) ; if ( response ) this . _permissionSetWizardData . permissionSetList = SymbolWithNameInformation . toNamesList ( response . symbols ) ; if ( ( this . _permissionSetWizardData . permissionSetList ) && ( this . _permissionSetWizardData . permissionSetList . length > 0 ) ) this . sendMessage ( { command : "setPermissionSets" , data : this . _permissionSetWizardData . permissionSetList } ) ; } }