<commit_before>var Tabula;
window.Tabula = Tabula || {};

Tabula.UI_VERSION = "0.9.9-2015-03-28" // when we make releases, we should remember to up this.
// I've decided to decouple the UI version from the "API" version in preparation for actually
// turning htem into different projects.

var TabulaRouter = Backbone.Router.extend({
  routes: {
    "":                            "upload",
    "/":                           "upload",
    "pdf/:file_id":                "view",
    "pdf/:file_id/extract":        "view", // you have to make selections first, so going directly to /extract doesn't work.
    "queue/:file_id":              'status',
    "error":                       'uploadError',
    "help":                        'help',
    "about":                       'about'
  },

  help: function(){
    document.title="Help | Tabula";
    $('nav li a').removeClass('active'); $('nav #help-nav').addClass('active');
    $('#tabula-app').html( _.template( $('#help-template').html().replace(/nestedscript/g, 'script') )({
    }) );
  },

  about: function(){
    document.title="About | Tabula";
    $('nav li a').removeClass('active'); $('nav #about-nav').addClass('active');
    $('#tabula-app').html( _.template( $('#about-template').html().replace(/nestedscript/g, 'script') )({
    }) );
  },


  upload: function() {
    document.title="Import | Tabula";
    $('nav li a').removeClass('active'); $('nav #upload-nav').addClass('active');
    $.ajax({
      url: "/js/library.js",
      dataType: "script",
      async: true,
      success: function(data, status, jqxhr){
        Tabula.library = new Tabula.Library({el: $('#tabula-app')[0]}).render();
      },
      error: function(a,b,c){
        console.log(a,b,c);
      }
    });
  },

  view: function(file_id) {
    $('nav li a').removeClass('active');
    // $('body').prepend( _.template( $('#navbar-template').html().replace(/nestedscript/g, 'script') )({}) ); // navbar.
    $('body').addClass('page-selections')
    $('#tabula-app').html( _.template( $('#pdf-view-template').html().replace(/nestedscript/g, 'script') )({}) );

    $.ajax({
      url: "/js/pdf_view.js",
      dataType: "script",
      async: true,
      success: function(data, status, jqxhr){
        Tabula.pdf_view = new Tabula.PDFView({pdf_id: file_id});
        Tabula.pdf_view.getData();
      },
      error: function(a,b,c){
        console.log(a,b,c);
      }
    });
  },
});


Tabula.getVersion = function(){
  Tabula.notification = new Backbone.Model({});
  Tabula.new_version = new Backbone.Model({});
  $.getJSON("/version", function(data){
    Tabula.api_version = data["api"];
    Tabula.getNotifications();

    // if(Tabula.api_version.slice(0,3) == "rev"){
    //   $('#dev-mode-ribbon').show();
    // }

  })
}
Tabula.getNotifications = function(){
  if(localStorage.getItem("tabula-notifications") === false) return;
  $.get('https://api.github.com/repos/tabulapdf/tabula/releases',
       function(data) {
         if (data.length < 1) return;
         if (Tabula.api_version.indexOf('rev') == 0) return;
         // check if new version
         var i = data.map(function(d) { return d.name; }).indexOf(Tabula.api_version);
         // if index >= 1, current release is not the newest
         if (i == 0) return;
         var new_release = data[0];
         if(new_release){
            Tabula.new_version.set(new_release);
         }
     });
  $.ajax({
    url: 'http://tabula.jeremybmerrill.com/tabula/notifications.jsonp', 
    dataType: "jsonp",
    jsonpCallback: 'notifications',
    success: function(data){
      if(data.length < 1) return;

      // find the first listed notification where today is between its `live_date` and `expires_date`<commit_msg>version bump to 1.0.0 in UI; more thorough versioning code, since we'll be using github prereleases a bit<commit_after>var Tabula;
window.Tabula = Tabula || {};

Tabula.UI_VERSION = "1.0.0-2015-08-05" // when we make releases, we should remember to up this.
// Add '-pre' to the end of this for a prerelease version; this will let
// our "new version" check give you that channel.

// Note that this is separate from the "API version" (internal app version)
// which is what we check against GitHub. In the future, this will allow us
// to modularize the UI from the backend some more.

var TabulaRouter = Backbone.Router.extend({
  routes: {
    "":                            "upload",
    "/":                           "upload",
    "pdf/:file_id":                "view",
    "pdf/:file_id/extract":        "view", // you have to make selections first, so going directly to /extract doesn't work.
    "queue/:file_id":              'status',
    "error":                       'uploadError',
    "help":                        'help',
    "about":                       'about'
  },

  help: function(){
    document.title="Help | Tabula";
    $('nav li a').removeClass('active'); $('nav #help-nav').addClass('active');
    $('#tabula-app').html( _.template( $('#help-template').html().replace(/nestedscript/g, 'script') )({
    }) );
  },

  about: function(){
    document.title="About | Tabula";
    $('nav li a').removeClass('active'); $('nav #about-nav').addClass('active');
    $('#tabula-app').html( _.template( $('#about-template').html().replace(/nestedscript/g, 'script') )({
    }) );
  },


  upload: function() {
    document.title="Import | Tabula";
    $('nav li a').removeClass('active'); $('nav #upload-nav').addClass('active');
    $.ajax({
      url: "/js/library.js",
      dataType: "script",
      async: true,
      success: function(data, status, jqxhr){
        Tabula.library = new Tabula.Library({el: $('#tabula-app')[0]}).render();
      },
      error: function(a,b,c){
        console.log(a,b,c);
      }
    });
  },

  view: function(file_id) {
    $('nav li a').removeClass('active');
    // $('body').prepend( _.template( $('#navbar-template').html().replace(/nestedscript/g, 'script') )({}) ); // navbar.
    $('body').addClass('page-selections')
    $('#tabula-app').html( _.template( $('#pdf-view-template').html().replace(/nestedscript/g, 'script') )({}) );

    $.ajax({
      url: "/js/pdf_view.js",
      dataType: "script",
      async: true,
      success: function(data, status, jqxhr){
        Tabula.pdf_view = new Tabula.PDFView({pdf_id: file_id});
        Tabula.pdf_view.getData();
      },
      error: function(a,b,c){
        console.log(a,b,c);
      }
    });
  },
});


Tabula.getVersion = function(){
  Tabula.notification = new Backbone.Model({});
  Tabula.new_version = new Backbone.Model({});
  $.getJSON("/version", function(data){
    Tabula.api_version = data["api"];
    Tabula.getNotifications();

    // if(Tabula.api_version.slice(0,3) == "rev"){
    //   $('#dev-mode-ribbon').show();
    // }

  })
}
Tabula.getNotifications = function(){
  if(localStorage.getItem("tabula-notifications") === false) return;
  $.get('https://api.github.com/repos/tabulapdf/tabula/releases',
      function(data) {
        if (data.length < 1) return;
        if (Tabula.api_version.indexOf('rev') == 0) return;

        var prerelease = (Tabula.UI_VERSION.indexOf("-pre") !== -1);
        if (prerelease) {console.log("Is prerelease");}

        // check if new version
        var non_prerelease_i = 0;
        for (var i=0; i<data.length; i++) {
          var d = data[i];
          if (!!d.draft) { continue; } // ignore drafts
          if (!prerelease && !!d.prerelease) { continue; } // ignore prereleases unless we're on a prerelease
          console.log("checking " + d.name + " vs " + Tabula.api_version);
          if ((non_prerelease_i === 0) && (d.name == Tabula.api_version)){
            // if index == 0, current release is the newest, so break out of this fn
            console.log(" -> IS LATEST");
            return;
          } else {
            // keep iterating, maybe we'll find this version later in list
            non_prerelease_i += 1;
          }
        }

        // We're not the latest release, grab data from GitHub & tell user
        var new_release = data[0];
        if(new_release){
          Tabula.new_version.set(new_release);
        }
      }
  );
  $.ajax({
    url: 'http://tabula.jeremybmerrill.com/tabula/notifications.jsonp', 
    dataType: "jsonp",
    jsonpCallback: 'notifications',
    success: function(data){
      if(data.length < 1) return;

      // find the first listed notification where today is between its `live_date` and `expires_date`
{'fraction_non_alphanumeric': 0.1826639971734778, 'fraction_numerical': 0.00553527264162054, 'mean_word_length': 2.5061932287365813, 'pattern_counts': {'":': 16, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '7559020', 'n_tokens_mistral': 2715, 'n_tokens_neox': 2643, 'n_words': 596}