<commit_before>/// <reference path="../main/Resource.ts" />
/// <reference path="../../../typings/tsd.d.ts" />

module PortalUIEditor {
  export class ResourceEditorController {
    private $modalInstance:any;
    private $http:any;
    private $window:any;
    
    json:string;
    validationResult:string;
    
    /** @ngInject */
    constructor($modalInstance:any, $http:any, $window:any) {
      this.$modalInstance = $modalInstance;
      this.$http = $http;
      this.$window = $window;

      ArmViz.Telemetry.sendEvent('PortalUIEditor', 'Open');
    }
    
    validate() {
      try {
        JSON.parse(this.json);
        this.validationResult = "Valid JSON!";
        ArmViz.Telemetry.sendEvent('PortalUIEditor', 'Validate', 'Passed');
      } catch(err) {
        this.validationResult = "Invalid JSON: " + err.toString();
        ArmViz.Telemetry.sendEvent('PortalUIEditor', 'Validate', 'Failed: ' + err.toString());
      }
    }
  
    close() {
      this.$modalInstance.dismiss('cancel');
    };
    
    preview() {
      console.log('preview!');
      var obj:any;
      try {
        obj = JSON.parse(this.json);
      } catch(err) {
          return null;
      }
      
      let url = 'http://armportaluiredirector.azurewebsites.net/?json=POST';
      
      this.$http.post(url, obj).then((response) => {
        //console.log('Got response: ' + response);
        let cacheUrl = response.data;
        
        let portalUiUrl = 'https://portal.azure.com/#blade/Microsoft_Azure_Compute/CreateMultiVmWizardBlade/internal_bladeCallId/anything/internal_bladeCallerParams/{"initialData":{},"providerConfig":{"createUiDefinition":"{jsonUrl}"}}';
        portalUiUrl = portalUiUrl.replace('{jsonUrl}', cacheUrl);
        
        this.$window.open(portalUiUrl);
      }, (response) => {
         console.error('Not sure what to do: ' + response);
      });
    }
    
  }
}<commit_msg>Fixed portal UI preview failure issue<commit_after>/// <reference path="../main/Resource.ts" />
/// <reference path="../../../typings/tsd.d.ts" />

module PortalUIEditor {
  export class ResourceEditorController {
    private $modalInstance:any;
    private $http:any;
    private $window:any;
    
    json:string;
    validationResult:string;
    
    /** @ngInject */
    constructor($modalInstance:any, $http:any, $window:any) {
      this.$modalInstance = $modalInstance;
      this.$http = $http;
      this.$window = $window;

      ArmViz.Telemetry.sendEvent('PortalUIEditor', 'Open');
    }
    
    validate() {
      try {
        JSON.parse(this.json);
        this.validationResult = "Valid JSON!";
        ArmViz.Telemetry.sendEvent('PortalUIEditor', 'Validate', 'Passed');
      } catch(err) {
        this.validationResult = "Invalid JSON: " + err.toString();
        ArmViz.Telemetry.sendEvent('PortalUIEditor', 'Validate', 'Failed: ' + err.toString());
      }
    }
  
    close() {
      this.$modalInstance.dismiss('cancel');
    };
    
    preview() {
      console.log('preview!');
      var obj:any;
      try {
        obj = JSON.parse(this.json);
      } catch(err) {
        this.validationResult = "Invalid JSON: " + err.toString();
        ArmViz.Telemetry.sendEvent('PortalUIEditor', 'Preview', 'Failed: ' + err.toString());
        
        return null;
      }
      
      let url = 'http://armportaluiredirector.azurewebsites.net/?json=POST';
      
      this.$http.post(url, obj).then((response) => {
        //console.log('Got response: ' + response);
        let cacheUrl = response.data;
        
        let portalUiUrl = 'https://portal.azure.com/#blade/Microsoft_Azure_Compute/CreateMultiVmWizardBlade/internal_bladeCallId/anything/internal_bladeCallerParams/{"initialData":{},"providerConfig":{"createUiDefinition":"{jsonUrl}"}}';
        portalUiUrl = portalUiUrl.replace('{jsonUrl}', cacheUrl);
        
        this.$window.open(portalUiUrl);
      }, (response) => {
         console.error('Not sure what to do: ' + response);
      });
    }
    
  }
}
{'fraction_non_alphanumeric': 0.16059850374064838, 'fraction_numerical': 0.0, 'mean_word_length': 2.5716829919857522, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1561114', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1224, 'n_words': 183}