<commit_before>/// <reference path="ToolboxResource.ts" />
/// <reference path="graph.ts" />
/// <reference path="sampleARM.ts" />
/// <reference path="ToolboxItems.ts" />
/// <reference path="Shapes.ts" />
/// <reference path="../../../typings/angularjs/angular.d.ts" />

angular.module('vis')
  .controller('MainCtrl', function ($scope, $modal) {
          
    $scope.toolboxItems = toolboxItems;
    
    let templateData = <ArmTemplateInterface>arm;
    let template = new ArmTemplate(templateData);
    
    var graph = new Graph(toolboxItems);
    graph.applyTemplate(template);
    
    graph.resourceSelected = function(resource:Resource, modal:boolean) {
      if(modal) {        
        var modalInstance = $modal.open({
          templateUrl: '/app/resourceEditorDialog/ResourceEditor.html',
          controller: 'ResourceEditorController',
          
          //These items get passed to the chiid controller
          resolve: {
            arm: function() {
              return template;
            },
            resource: function () {
              return resource;
            }
          }
        });
        modalInstance.result.then(function(resultResource:any) {
          if(resultResource && resultResource.deleteFlag) {
            template.deleteResource(<Resource>resultResource);
          }
        });
      } else {
        $scope.selectedResource = JSON.stringify(resource, null, 2);
        $scope.$apply();<commit_msg>Added template loading from a github referrer<commit_after>/// <reference path="ToolboxResource.ts" />
/// <reference path="graph.ts" />
/// <reference path="sampleARM.ts" />
/// <reference path="ToolboxItems.ts" />
/// <reference path="Shapes.ts" />
/// <reference path="../../../typings/angularjs/angular.d.ts" />

angular.module('vis')
  .controller('MainCtrl', function ($scope, $http, $modal) {
          
    $scope.toolboxItems = toolboxItems;
    
    let templateData = <ArmTemplateInterface>arm;
    let template = new ArmTemplate(templateData);
    
    var graph = new Graph(toolboxItems);
    
    //Check the referrer to see if there is a template. Not sure if
    //there is a way to make this more generic.
    let referrer = document.referrer;
    //referrer = 'https://github.com/Azure/azure-quickstart-templates/tree/master/101-create-security-group'
    if(referrer && referrer.indexOf("github.com/Azure/azure-quickstart-templates/") >= 0) {
      let urlParts = referrer.split("/");
      let quickStart = urlParts[urlParts.length - 1];
      
      let githubUrl = 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/'
        + quickStart
        + '/azuredeploy.json';
      
      let category = $http.get(githubUrl)
        .success(function(data:any, status, headers, config) {
          template = new ArmTemplate(<ArmTemplateInterface>data);
          graph.applyTemplate(template);
        }).error(function(data, status, headers, config) {
				  alert('Error loading your template from GitHub. Please go back and try again.')
			  });
    }
    
    //graph.applyTemplate(template);
    
    graph.resourceSelected = function(resource:Resource, modal:boolean) {
      if(modal) {        
        var modalInstance = $modal.open({
          templateUrl: '/app/resourceEditorDialog/ResourceEditor.html',
          controller: 'ResourceEditorController',
          
          //These items get passed to the chiid controller
          resolve: {
            arm: function() {
              return template;
            },
            resource: function () {
              return resource;
            }
          }
        });
        modalInstance.result.then(function(resultResource:any) {
          if(resultResource && resultResource.deleteFlag) {
            template.deleteResource(<Resource>resultResource);
          }
        });
      } else {
        $scope.selectedResource = JSON.stringify(resource, null, 2);
        $scope.$apply();
{'fraction_non_alphanumeric': 0.13368713671973717, 'fraction_numerical': 0.0017690169320192064, 'mean_word_length': 2.3149078726968173, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 21, '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': '3494693', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1045, 'n_words': 215}