<commit_before><commit_msg>Start to do the CommentsRetriever<commit_after>"use strict";

angular.module('arethusa.comments').factory('CommentsRetriever', [
  'configurator',
  function(configurator) {
    var test = [
      { "id": 47,
        "user": "<NAME>",
        "reason": "general",
        "created_at": "2014-07-30T12:34:33Z",
        "updated_at": "2014-07-30T12:34:33Z",
        "comment": "##1.3##\n\ntest comment"
      }
    ];

    var comments = {};

    function splitIdAndComment(comment) {
      var regexp = new RegExp('^##(.*?)##\n\n(.*)$');
      var match = regexp.exec(comment);
      return match ? match.slice(1, 3) : ['noId', comment];
    }

    function addComments(id, comment) {
      arethusaUtil.setProperty(comments, id, comment);
    }

    function parseComments(res) {
      angular.forEach(res, function(commentObj, i) {
        var comment = commentObj.comment;
        var extracted = splitIdAndComment(comment);
        addComments(extracted[0], extracted[1]);
      });
    }

    return function(conf) {
      var self = this;
      var resource = configurator.provideResource(conf.resource);

      var alreadyLoaded;

      this.getData = function(chunkId, callback) {
        if (alreadyLoaded) {
          callback(comments[chunkId]);
        } else {
          resource.get().then(function(res) {
            parseComments(test); // this will be res.data of course
            callback(comments[chunkId]);
          });
        }
      };
    };
  }
]);
{'fraction_non_alphanumeric': 0.15312916111850866, 'fraction_numerical': 0.023968042609853527, 'mean_word_length': 2.4953488372093022, 'pattern_counts': {'":': 6, '<': 4, '<?xml version=': 0, '>': 4, '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': '4618114', 'n_tokens_mistral': 492, 'n_tokens_neox': 457, 'n_words': 86}