<commit_before>// little but instructive

var app = angular.module("littleStateApp", []);

app.controller("littleStateCtrl", function($scope, simpleState) {
  
  $scope.sm = simpleState.init('unchanged', {
    "states":{
      "unchanged":{
        "trans":{
          "edit": function ($scope) {
            $scope.previous_content = $scope.content;
            return 'editing';
          },
          "mark_for_removal": "crossout"
        }
      },
      "editing":{
        "trans":{
          "accept": function ($scope) {
            if ($scope.compare_courses($scope.previous_content, $scope.content)) {
              delete $scope.previous_content;
              return 'unchanged';
            }
            else {
              return 'changed';
            }
          },
          "revert": function ($scope) {
            $scope.content = angular.extend({}, $scope.previous_content);
            $scope.content = $scope.content;
            delete $scope.previous_content;
            return 'unchanged';
          }
        }
      },
      "changed":{
        "trans":{
          "edit": "editing",
          "restore_original": function ($scope) {
            $scope.$parent.$parent.content = angular.extend({}, $scope.previous_content);
            $scope.content = $scope.$parent.$parent.content;
            delete $scope.previous_content;
            return 'unchanged';
          }
        }
      },
      "crossout": {
        "trans": {
          "restore_original": "unchanged"
        }
      }
    }
  }, 
  function(new_state) {
    $scope.current_state = new_state;
  });
  
  $scope.go = function (path) {
    $scope.template = $scope.sm.go(path, $scope);
  };
  
});

// data driven templates (with data binding)
// attrabutes:
//     data-driven-template
//     content=""
//
app.directive('stateView', function ($compile, $templateCache) {

  var linker = function(scope, element, attrs) {
    //alert(JSON.stringify(attrs.define_fn));
    scope.$watch("current_state", function() {
      var state, template;

      if (scope.content.last_state) {
        template = scope.content.last_state + '.html';
      }
      else {
        if (scope.content.id === 'new') {
          template = 'new_edit.html';
        }
        else {
          template = 'unchanged.html';
        }
      }
      element.html($templateCache.get(template));
      $compile(element.contents())(scope);
    });
  };

  return {
    restrict: "A",
    replace: true,
    link: linker,
    scope: {
      content:'=content'
    }
  };
});<commit_msg>better directive, but still not loading the templates<commit_after>// little but instructive

var app = angular.module("littleStateApp", []);

app.controller("littleStateCtrl", function($scope, simpleState) {
  
  $scope.sm = simpleState.init('unchanged', {
    "states":{
      "unchanged":{
        "trans":{
          "edit": function ($scope) {
            $scope.previous_content = $scope.content;
            return 'editing';
          },
          "mark_for_removal": "crossout"
        }
      },
      "editing":{
        "trans":{
          "accept": function ($scope) {
            if ($scope.compare_courses($scope.previous_content, $scope.content)) {
              delete $scope.previous_content;
              return 'unchanged';
            }
            else {
              return 'changed';
            }
          },
          "revert": function ($scope) {
            $scope.content = angular.extend({}, $scope.previous_content);
            $scope.content = $scope.content;
            delete $scope.previous_content;
            return 'unchanged';
          }
        }
      },
      "changed":{
        "trans":{
          "edit": "editing",
          "restore_original": function ($scope) {
            $scope.$parent.$parent.content = angular.extend({}, $scope.previous_content);
            $scope.content = $scope.$parent.$parent.content;
            delete $scope.previous_content;
            return 'unchanged';
          }
        }
      },
      "crossout": {
        "trans": {
          "restore_original": "unchanged"
        }
      }
    }
  }, 
  function(new_state) {
    $scope.current_state = new_state;
  });
  
  $scope.go = function (path) {
    $scope.template = $scope.sm.go(path, $scope);
  };
  
});

// data driven templates (with data binding)
// attrabutes:
//     data-driven-template
//     content=""
//
app.directive('stateView', function ($compile, $templateCache) {

  var linker = function(scope, element, attrs) {
    //alert(JSON.stringify(attrs.define_fn));
    scope.$watch("current_state", function() {
      var state, template, template_html, contents;

      if (scope.content) {
        template = scope.content.current_state + '.html';
      }
      else {
        template = 'view-state-initial.html';
      }
      template_html = $templateCache.get(template);
      element.html(template_html);
      contents = element.contents();
      $compile(contents)(scope);
    });
  };

  return {
    restrict: "A",
    replace: true,
    link: linker,
    scope: {
      content:'=content'
    }
  };
});
{'fraction_non_alphanumeric': 0.15078901227352426, 'fraction_numerical': 0.0, 'mean_word_length': 1.9203640500568828, 'pattern_counts': {'":': 32, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '7206157', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1466, 'n_words': 265}