<commit_before>'use strict';

/**
 * @ngdoc service
 * @name grafterizerApp.datagraftPostMessage
 * @description
 * # datagraftPostMessage
 * Service in the grafterizerApp.
 */
angular.module('grafterizerApp')
.service('datagraftPostMessage', function($state, apiKeyService) {

  var channel = 'datagraft-post-message';
  var connected = false;

  var receiveMessage = function(event) {
    var data = event.data;
    if (!data || !data.channel || data.channel !== channel) return;

    try {
      switch (data.message) {
        case 'state.go':
          $state.go(data.state, data.toParams);
          break;
        case 'set-authorization':
          connected = true;
          apiKeyService.setKeyPass(data.keypass);
          break;
      }
    } catch (e) {
      Raven.captureException(e);
    }
  };

  this.setup = function() {
    window.addEventListener('message', receiveMessage, false);
    window.parent.postMessage({
      channel: channel,
      message: 'ready'
    }, '*');
  };

  this.isConnected = function() {<commit_msg>upload-and-new postmessage method<commit_after>'use strict';

/**
 * @ngdoc service
 * @name grafterizerApp.datagraftPostMessage
 * @description
 * # datagraftPostMessage
 * Service in the grafterizerApp.
 */
angular.module('grafterizerApp')
.service('datagraftPostMessage', function(
  $rootScope,
  $state,
  apiKeyService,
  uploadFile) {

  var channel = 'datagraft-post-message';
  var connected = false;

  var receiveMessage = function(event) {
    var data = event.data;
    if (!data || !data.channel || data.channel !== channel) return;

    try {
      switch (data.message) {
        case 'state.go':
          $state.go(data.state, data.toParams);
          break;
        case 'set-authorization':
          connected = true;
          apiKeyService.setKeyPass(data.keypass);
          break;
        case 'upload-and-new':
          var file = new Blob([data.distribution], {type: data.type});
          file.name = data.name;
          uploadFile.upload(file, function(data) {
            $rootScope.actions.save(data['@id']);
          });

          break;
      }
    } catch (e) {
      Raven.captureException(e);
    }
  };

  this.setup = function() {
    window.addEventListener('message', receiveMessage, false);
    window.parent.postMessage({
      channel: channel,
      message: 'ready'
    }, '*');
  };

  this.isConnected = function() {
{'fraction_non_alphanumeric': 0.13871635610766045, 'fraction_numerical': 0.0, 'mean_word_length': 2.6606060606060606, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2357097', 'n_tokens_mistral': 740, 'n_tokens_neox': 723, 'n_words': 145}