<commit_before>//initiate the client
var oh = Ohmage("/app", "documents-app")

//attach global callbacks
oh.callback("done", function(x, status, req){
})

//global error handler. In ohmage 200 means unauthenticated
oh.callback("error", function(msg, code, req){
	(code == 200) ? window.location.replace("../web/#login") : alert("Error!\n" + msg);
});

//main app
$(function() {
oh.user.whoami().done(function(username){
	
	//make sure we don't timeout
	oh.keepalive();

  oh.user.info().done(function(x){
    var classes = _.map(x[username]['classes'], function(value,key){ return {"urn":key,"name":value}; });
    sorted_classes = _.sortBy(classes, "name");
    $.each(sorted_classes, function(k,v) {
      $('#modal-class')
        .append($("<option></option>")
        .attr("value",v['urn'])
        .text(v['name']));
    });
    $('#modal-class').multiselect({maxHeight:200});
    
    var campaigns = _.map(x[username]['campaigns'], function(value,key){ return {"urn":key,"name":value}; });
    sorted_campaigns = _.sortBy(campaigns, "name");
    $.each(sorted_campaigns, function(k,v) {
      $('#modal-campaign')
        .append($("<option></option>")
        .attr("value",v['urn'])
        .text(v['name']));
    });
    $('#modal-campaign').multiselect({maxHeight:200});
  });
        //grab list of documents and provide them to datatables	
  oh.document.search("").done(function(x){
	 document_data = $.map(x, function(val,key){val.uuid=key; return val;});
    $.each(document_data, function(k,v){
     v['size'] = bytesToSize(v['size'])
     v['campaign_class'] = [];
     v['edit-button'] = '<button type="button" class="btn btn-success" data-toggle="modal" data-target="#detail-modal" data-uuid="'+v['uuid']+'">Edit</button>'
	   v['button'] = '<form action="/app/document/read/contents" method="post" target="outputframe"><input type="hidden" name="document_id" value="'+v['uuid']+'"><input type="hidden" name="client" value="doc_app"><input type="submit" class="btn btn-primary" value="Download">'
	   //make the class/campaign list be their names instead of urns.
     if (!$.isEmptyObject(v['class_role'])){
       var attached_class_list = _.keys(v['class_role'])
       $.each(_.keys(v['class_role']), function(k){
        var name_lookup = _.findWhere(sorted_classes, {"urn":k})
        var push_me = (typeof name_lookup === "undefined") ? k : name_lookup.name;
        v['campaign_class'].push(push_me);
       });
     }
     if (!$.isEmptyObject(v['campaign_role'])){
       var attached_campaign_list = _.keys(v['campaign_role'])
       $.each(_.keys(v['campaign_role']), function(k){
        var name_lookup = _.findWhere(sorted_campai, {"urn":k})
        var push_me = (typeof name_lookup === "undefined") ? k : name_lookup.name;
        v['campaign_class'].push(push_me);       
       });
     }

     //$.isEmptyObject(v['campaign_role']) || v['campaign_class'].push(_.keys(v['campaign_role']));
	   //$.isEmptyObject(v['class_role']) || v['campaign_class'].push(_.keys(v['class_role']));
    });
   var table = $('#documents').DataTable( {
    "data": document_data,
	  "lengthMenu": [25, 50, 100, "All"],
	  "oSearch": {"sSearch": "",
  	 "bRegex": true
		},
    "columns": [
     { "data": "name" },
     { "data": "creator" },
     { "data": "campaign_class[, ]" },
     { "data": "creation_date" },
     { "data": "privacy_state" },
     { "data": "size" },
     { "data": "edit-button" },
     { "data": "button" }
    ],<commit_msg>told you<commit_after>//initiate the client
var oh = Ohmage("/app", "documents-app")

//attach global callbacks
oh.callback("done", function(x, status, req){
})

//global error handler. In ohmage 200 means unauthenticated
oh.callback("error", function(msg, code, req){
	(code == 200) ? window.location.replace("../web/#login") : alert("Error!\n" + msg);
});

//main app
$(function() {
oh.user.whoami().done(function(username){
	
	//make sure we don't timeout
	oh.keepalive();

  oh.user.info().done(function(x){
    var classes = _.map(x[username]['classes'], function(value,key){ return {"urn":key,"name":value}; });
    sorted_classes = _.sortBy(classes, "name");
    $.each(sorted_classes, function(k,v) {
      $('#modal-class')
        .append($("<option></option>")
        .attr("value",v['urn'])
        .text(v['name']));
    });
    $('#modal-class').multiselect({maxHeight:200});
    
    var campaigns = _.map(x[username]['campaigns'], function(value,key){ return {"urn":key,"name":value}; });
    sorted_campaigns = _.sortBy(campaigns, "name");
    $.each(sorted_campaigns, function(k,v) {
      $('#modal-campaign')
        .append($("<option></option>")
        .attr("value",v['urn'])
        .text(v['name']));
    });
    $('#modal-campaign').multiselect({maxHeight:200});
  });
        //grab list of documents and provide them to datatables	
  oh.document.search("").done(function(x){
	 document_data = $.map(x, function(val,key){val.uuid=key; return val;});
    $.each(document_data, function(k,v){
     v['size'] = bytesToSize(v['size'])
     v['campaign_class'] = [];
     v['edit-button'] = '<button type="button" class="btn btn-success" data-toggle="modal" data-target="#detail-modal" data-uuid="'+v['uuid']+'">Edit</button>'
	   v['button'] = '<form action="/app/document/read/contents" method="post" target="outputframe"><input type="hidden" name="document_id" value="'+v['uuid']+'"><input type="hidden" name="client" value="doc_app"><input type="submit" class="btn btn-primary" value="Download">'
	   //make the class/campaign list be their names instead of urns.
     if (!$.isEmptyObject(v['class_role'])){
       var attached_class_list = _.keys(v['class_role'])
       $.each(attached_class_list, function(index,value){
        var find_me = {};
        find_me['urn'] = value;
        var name_lookup = _.findWhere(sorted_classes, find_me);
        var push_me = (typeof name_lookup === "undefined") ? value : name_lookup.name;
        v['campaign_class'].push(push_me);
       });
     }
     if (!$.isEmptyObject(v['campaign_role'])){
       var attached_campaign_list = _.keys(v['campaign_role'])
       $.each(attached_campaign_list, function(index,value){
        var find_me = {};
        find_me['urn'] = value;
        var name_lookup = _.findWhere(sorted_campaigns, find_me);
        var push_me = (typeof name_lookup === "undefined") ? value : name_lookup.name;
        v['campaign_class'].push(push_me);
       });
     }

     //$.isEmptyObject(v['campaign_role']) || v['campaign_class'].push(_.keys(v['campaign_role']));
	   //$.isEmptyObject(v['class_role']) || v['campaign_class'].push(_.keys(v['class_role']));
    });
   var table = $('#documents').DataTable( {
    "data": document_data,
	  "lengthMenu": [25, 50, 100, "All"],
	  "oSearch": {"sSearch": "",
  	 "bRegex": true
		},
    "columns": [
     { "data": "name" },
     { "data": "creator" },
     { "data": "campaign_class[, ]" },
     { "data": "creation_date" },
     { "data": "privacy_state" },
     { "data": "size" },
     { "data": "edit-button" },
     { "data": "button" }
    ],
{'fraction_non_alphanumeric': 0.21863951350586905, 'fraction_numerical': 0.00537406307452977, 'mean_word_length': 3.775151924375422, 'pattern_counts': {'":': 38, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4844891', 'n_tokens_mistral': 2399, 'n_tokens_neox': 2304, 'n_words': 409}