<commit_before>define([
  '#qt_core/controllers/all'
],

function (A) {
  'use strict';

  return Marionette.Controller.extend({
    initialize: function (options)	 {
      /*A.vent.on(A.Cfg.events.livraison.transporteur.get,this.onGetTransporteurData,this);*/

      A._v.onCfg('data.items.get','',this.onGetItems,this);
      A._v.onCfg('data.items.getOne','',this.onGetOneItem,this);
    },

    onDestroy : function() {
      /*A.vent.off(A.Cfg.events.livraison.transporteur.get,this.onGetTransporteurData,this);*/


      A._v.offCfg('data.items.get','',this.onGetItems,this);
      A._v.offCfg('data.items.getOne','',this.onGetOneItem,this);
     
    },

    /////////////////////////////////////////////////////////////////////
    // Get Items

    onGetItems:function() {
       A.ApiEventsHelper.listenOkErrorAndTrigger3(A.Cfg.eventApi(A.Cfg.events.data.items.get),null,null,
        function(result) {
          //alert('oui');
          A._i.setOnCfg('allItems',result);
          return A.vent.trigger(A.Cfg.eventOk(A.Cfg.events.data.items.get));
        }, function(error) {
          alert("Non1");
      });
    },

     /////////////////////////////////////////////////////////////////////
    // Get One Item & nivigate to view
    onGetOneItem:function(id,viewid) {

      ///NEW : get item for direct call
       var self=this;
      A.ApiEventsHelper.listenOkErrorAndTrigger3(A.Cfg.eventApi(A.Cfg.events.data.items.getOne),{id : id},null,
        function(item) {
          A._i.setOnCfg('currentItem',item);
          return self.getAllAnalysisTracks(item,function(resultAnalysis) {
            item.set('analysisTracksObjects',resultAnalysis);
             //new : get all annotations on item
            return self.getAllAnotationsTracks(item,function(result) {
              item.set('annotationTracksObjects',result);
              return A._v.trigCfg('navigate.page','',viewid);
            });

          })
        }, function(error) {
          alert("Non1");
      });
      return;



      console.error("Temp : get one item does not work direct from list");

      var item = _.find(A._i.getOnCfg('allItems'),function(it) {return it.get('uuid')===id});
      if (!item)
        return console.error('no item found on '+id);

     
      

      

        

      
    },

    //get all analysis tracks
    getAllAnalysisTracks:function(item,callback) {
        var indexAnalysis = 0;
        var result = [];

        if ( (!item.get('analysis_tracks')) || item.get('analysis_tracks').length==0 )
          return callback();

        var getNewAnalysis = function() {
          if (indexAnalysis>=12) {
            console.error('tmp debug, 6 analysis track limit')
            return callback(result);
          }

          if (indexAnalysis >= item.get('analysis_tracks').length)
            return callback(result);

          var urlAnnotation = item.get('analysis_tracks')[indexAnalysis];
          $.get(urlAnnotation,function(res) {
              result.push(res);
              indexAnalysis++;
              return getNewAnalysis();
          });<commit_msg>(player/delete track) disabled delete call<commit_after>define([
  '#qt_core/controllers/all'
],

function (A) {
  'use strict';

  return Marionette.Controller.extend({
    initialize: function (options)	 {
      /*A.vent.on(A.Cfg.events.livraison.transporteur.get,this.onGetTransporteurData,this);*/

      A._v.onCfg('data.items.get','',this.onGetItems,this);
      A._v.onCfg('data.items.getOne','',this.onGetOneItem,this);
    },

    onDestroy : function() {
      /*A.vent.off(A.Cfg.events.livraison.transporteur.get,this.onGetTransporteurData,this);*/


      A._v.offCfg('data.items.get','',this.onGetItems,this);
      A._v.offCfg('data.items.getOne','',this.onGetOneItem,this);
     
    },

    /////////////////////////////////////////////////////////////////////
    // Get Items

    onGetItems:function() {
       A.ApiEventsHelper.listenOkErrorAndTrigger3(A.Cfg.eventApi(A.Cfg.events.data.items.get),null,null,
        function(result) {
          //alert('oui');
          A._i.setOnCfg('allItems',result);
          return A.vent.trigger(A.Cfg.eventOk(A.Cfg.events.data.items.get));
        }, function(error) {
          alert("Non1");
      });
    },

     /////////////////////////////////////////////////////////////////////
    // Get One Item & nivigate to view
    onGetOneItem:function(id,viewid) {

      ///NEW : get item for direct call
       var self=this;
      A.ApiEventsHelper.listenOkErrorAndTrigger3(A.Cfg.eventApi(A.Cfg.events.data.items.getOne),{id : id},null,
        function(item) {
          A._i.setOnCfg('currentItem',item);

          //NEW 02/17 : we dont call the analysis track objects
          return self.getAllAnotationsTracks(item,function(result) {
              item.set('annotationTracksObjects',result);
              return A._v.trigCfg('navigate.page','',viewid);
            });

          /*return self.getAllAnalysisTracks(item,function(resultAnalysis) {
            item.set('analysisTracksObjects',resultAnalysis);
             //new : get all annotations on item
            return self.getAllAnotationsTracks(item,function(result) {
              item.set('annotationTracksObjects',result);
              return A._v.trigCfg('navigate.page','',viewid);
            });

          })*/
        }, function(error) {
          alert("Non1");
      });
      return;
      
    },

    //get all analysis tracks
    getAllAnalysisTracks:function(item,callback) {
        var indexAnalysis = 0;
        var result = [];

        if ( (!item.get('analysis_tracks')) || item.get('analysis_tracks').length==0 )
          return callback();

        var getNewAnalysis = function() {
          if (indexAnalysis>=12) {
            console.error('tmp debug, 6 analysis track limit')
            return callback(result);
          }

          if (indexAnalysis >= item.get('analysis_tracks').length)
            return callback(result);

          var urlAnnotation = item.get('analysis_tracks')[indexAnalysis];
          $.get(urlAnnotation,function(res) {
              result.push(res);
              indexAnalysis++;
              return getNewAnalysis();
          });
{'fraction_non_alphanumeric': 0.1847041847041847, 'fraction_numerical': 0.003527336860670194, 'mean_word_length': 2.026686074721009, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3439371', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1771, 'n_words': 255}