<commit_before>(function () {
  'use strict';

  var angular = window.angular;
  var Handlebars = window.Handlebars;
  var saveAs = window.saveAs;
  var Dyframe = window.Dyframe;

  var appName = 'webpage-toolkit';
  var schemaUrl = 'data/schema.json';
  var templateUrl = 'data/template.hbs';

  Dyframe.addProfile('pc', {
    width: 1024,
    deviceWidth: null
  });

  angular
  .module('webpageToolkit', ['schemaForm', 'angularFileUpload', 'LocalStorageModule', 'ui.sortable'])
  .config([
    'localStorageServiceProvider',
    'schemaFormDecoratorsProvider',
    function (localStorageServiceProvider, decoratorsProvider) {
      localStorageServiceProvider.setPrefix(appName);
      decoratorsProvider.addMapping(
        'bootstrapDecorator',
        'array',
        'assets/templates/array.html'
      );
    }
  ])
  .controller('FormController', [
    '$scope',
    '$q',
    '$http',
    '$timeout',
    'localStorageService',
    function ($scope, $q, $http, $timeout, localStorageService) {

      var template;

      $scope.schema = {};
      $scope.model = {};
      $scope.defaults = {};
      $scope.form = ['*'];
      $scope.loaded = false;
      $scope.started = false;
      $scope.settings = {
        previewDevice: 'pc'
      };
      $scope.html = '';
      $scope.errorShown = false;
      $scope.errorMessage = '';

      $scope.init = function () {
        var schemaRequest = $scope.loadSchema();
        var templateRequest = $scope.loadTemplate();
        $q.all([schemaRequest, templateRequest]).then(function () {
          $scope.loaded = true;
        });
      };

      $scope.loadSchema = function () {
        var request = $http.get(schemaUrl).then(function (data) {
          $scope.schema = data.data;
        });
        return request;
      };

      $scope.loadTemplate = function () {
        var request = $http.get(templateUrl).then(function (data) {
          template = Handlebars.compile(data.data);
        });
        return request;
      };

      $scope.start = function () {
        $scope.defaults = angular.copy($scope.model);
        $scope.syncStorage('model');
        $scope.syncStorage('settings');
        $scope.started = true;
      };

      $scope.syncStorage = function (key) {
        if (!localStorageService.get(key)) {
          localStorageService.set(key, $scope[key]);
        }
        localStorageService.bind($scope, key);
      };

      $scope.getHtml = function () {
        return template($scope.model);
      };

      $scope.getJson = function () {
        return JSON.stringify($scope.model, null, '  ');
      };

      $scope.openPreview = function () {
        var child = window.open();
        child.document.open();
        child.document.write($scope.html);
        child.document.close();
      };

      $scope.downloadHtml = function () {
        $scope.$broadcast('schemaFormValidate');
        if (!$scope.appForm.$valid) {
          $scope.alert('Invalid form input');
          return;
        }
        $scope.download('index.html', $scope.html);
      };

      $scope.downloadJson = function () {
        $scope.download('data.json', $scope.getJson());
      };

      $scope.download = function (filename, text) {
        var blob = new Blob([text], {type: 'text/plain;charset=utf-8'});
        saveAs(blob, filename);
      };

      $scope.importJson = function (file) {
        var reader = new FileReader();
        reader.readAsText(file);
        reader.onload = function () {
          $scope.import($scope.parseJson(reader.result));
        };
      };

      $scope.parseJson = function (string) {
        return JSON.parse(string);
      };

      $scope.import = function (data) {
        $scope.model = angular.copy(data);
        $scope.$apply();<commit_msg>Strip invalid keys from import file<commit_after>(function () {
  'use strict';

  var angular = window.angular;
  var _ = window._;
  var Handlebars = window.Handlebars;
  var saveAs = window.saveAs;
  var Dyframe = window.Dyframe;

  var appName = 'webpage-toolkit';
  var schemaUrl = 'data/schema.json';
  var templateUrl = 'data/template.hbs';

  Dyframe.addProfile('pc', {
    width: 1024,
    deviceWidth: null
  });

  angular
  .module('webpageToolkit', ['schemaForm', 'angularFileUpload', 'LocalStorageModule', 'ui.sortable'])
  .config([
    'localStorageServiceProvider',
    'schemaFormDecoratorsProvider',
    function (localStorageServiceProvider, decoratorsProvider) {
      localStorageServiceProvider.setPrefix(appName);
      decoratorsProvider.addMapping(
        'bootstrapDecorator',
        'array',
        'assets/templates/array.html'
      );
    }
  ])
  .controller('FormController', [
    '$scope',
    '$q',
    '$http',
    '$timeout',
    'localStorageService',
    function ($scope, $q, $http, $timeout, localStorageService) {

      var template;

      $scope.schema = {};
      $scope.model = {};
      $scope.defaults = {};
      $scope.form = ['*'];
      $scope.loaded = false;
      $scope.started = false;
      $scope.settings = {
        previewDevice: 'pc'
      };
      $scope.html = '';
      $scope.errorShown = false;
      $scope.errorMessage = '';

      $scope.init = function () {
        var schemaRequest = $scope.loadSchema();
        var templateRequest = $scope.loadTemplate();
        $q.all([schemaRequest, templateRequest]).then(function () {
          $scope.loaded = true;
        });
      };

      $scope.loadSchema = function () {
        var request = $http.get(schemaUrl).then(function (data) {
          $scope.schema = data.data;
        });
        return request;
      };

      $scope.loadTemplate = function () {
        var request = $http.get(templateUrl).then(function (data) {
          template = Handlebars.compile(data.data);
        });
        return request;
      };

      $scope.start = function () {
        $scope.defaults = angular.copy($scope.model);
        $scope.syncStorage('model');
        $scope.syncStorage('settings');
        $scope.started = true;
      };

      $scope.syncStorage = function (key) {
        if (!localStorageService.get(key)) {
          localStorageService.set(key, $scope[key]);
        }
        localStorageService.bind($scope, key);
      };

      $scope.getHtml = function () {
        return template($scope.model);
      };

      $scope.getJson = function () {
        return JSON.stringify($scope.model, null, '  ');
      };

      $scope.openPreview = function () {
        var child = window.open();
        child.document.open();
        child.document.write($scope.html);
        child.document.close();
      };

      $scope.downloadHtml = function () {
        $scope.$broadcast('schemaFormValidate');
        if (!$scope.appForm.$valid) {
          $scope.alert('Invalid form input');
          return;
        }
        $scope.download('index.html', $scope.html);
      };

      $scope.downloadJson = function () {
        $scope.download('data.json', $scope.getJson());
      };

      $scope.download = function (filename, text) {
        var blob = new Blob([text], {type: 'text/plain;charset=utf-8'});
        saveAs(blob, filename);
      };

      $scope.importJson = function (file) {
        var reader = new FileReader();
        reader.readAsText(file);
        reader.onload = function () {
          $scope.import($scope.parseJson(reader.result));
        };
      };

      $scope.parseJson = function (string) {
        var data = JSON.parse(string);
        data = _.pick(data, Object.keys($scope.defaults));
        return data;
      };

      $scope.import = function (data) {
        $scope.model = angular.copy(data);
        $scope.$apply();
{'fraction_non_alphanumeric': 0.1532258064516129, 'fraction_numerical': 0.0013007284079084287, 'mean_word_length': 2.2858974358974358, 'pattern_counts': {'":': 0, '<': 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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2196830', 'n_tokens_mistral': 2258, 'n_tokens_neox': 2210, 'n_words': 392}