<commit_before>'use strict';

// like main function in C
$(document).ready(function () {
  // UI 初始化
  var zeroMargin = {
      top:	0
    ,	bottom:	0
    ,	left:	0
    ,	right:	0
  };
  $('body').layout({
    inset:        zeroMargin,
    closable:      false,
    west__minSize: 0.15,
    west__maxSize: 0.40
  });

  $("#btnAddURL").bind('click', g.gui.addURL);

  g.service.getIndex();
});

var g = {};
g.data = {};
g.service = {};
g.gui = {};
g.service.getIndex = function() {
  $.getJSON( "/_/getIndex", function( indexObj ) {
    g.data.sources = indexObj.sources;

    g.data.tags = {};
    for (var t in indexObj.tags) {
      g.data.tags[t] = parseInt(indexObj.tags[t]);
    }

    g.gui.updateTagTree();

  }).fail(function() {
    alert("获取Index数据错误！");
  })
};

g.service.getData = function(node) {
  var address = null;
  if ( node.type === "source") {
    var select = node.value;
    address = "/_/getDataBySource";
    if ( select !== "all" && select !== undefined) {
      address = "/_/getDataBySource?source=" + select;
    }
  } else if (node.type === "tag") {
    var select = node.value;
    address = "/_/getDataByTag";
    if ( select !== null && select !== undefined) {
      address = "/_/getDataByTag?tag=" + select;
    }
  }

  if ( address !== null) {
    // 显示等待窗口
    $( "#waitDialog" ).dialog({
      dialogClass: "no-close",
      modal: true
    });

    $.getJSON( address, function( dataObj ) {
      g.data.collects = {};
      var html = "";
      for(var i = 0; i < dataObj.length; i++) {
        // B端保存数据
        g.data.collects[ dataObj[i].index ] = dataObj[i].tags;
        html += g.post.build( dataObj[i]);
      }
      $("#listItems").html(html);

      // 配置相关GUI事件处理
      $(".btnDeleteCollect").bind('click',function(){
        var index = $(this).attr('index');
        g.service.removeCollect( index );
        $("#item_" + index).remove();
      });
      $(".linkText").linkify();
      $(".btnAccessOrignalWeibo").bind('click', function(){
        var index = $(this).attr('index');
        if(index !== undefined) {
          g.service.accessWeibo(index);
        }
      });
      g.gui.refreshTagEvent();

      $("#waitDialog").dialog( "close" );
    });
  }
};

g.service.removeCollect = function(index){
  var address = '/_/removeCollect?index=' + index;
  $.getJSON( address, function( dataObj ) {

  });

  var needUpdate = false;
  var removedTags = g.data.collects[index];
  for(var j = 0; removedTags !== undefined && j < removedTags.length; j++) {
    g.data.tags[removedTags[j]] --;
    if ( g.data.tags[removedTags[j]] === 0) {
      delete g.data.tags[removedTags[j]];
      needUpdate = true;
    }
  }
  if ( needUpdate) {
    g.gui.updateTagTree();
  }
}

g.service.removeTag = function(index, tag) {
  var tagsString = jQuery.param({tags:g.data.collects[index]});
  var address = '/_/updateTag?index=' + index;
  if ( tagsString !== "") {
    address = address + '&' + tagsString;
  }
  $.getJSON( address, function( dataObj ) {

  });

  if ( g.data.tags.hasOwnProperty(tag)) {
    g.data.tags[tag] --;
    if ( g.data.tags[tag] === 0) {
      delete g.data.tags[tag];
    }
  }

  g.gui.updateTagTree();
};

g.service.addTag = function(index, newTags) {
  var tagsString = jQuery.param({tags:g.data.collects[index]});
  var address = '/_/updateTag?index=' + index;
  if ( tagsString !== "") {
    address = address + '&' + tagsString;
  }
  $.getJSON( address, function( dataObj ) {

  });


  for(var j = 0; j < newTags.length; j++) {
    if ( g.data.tags.hasOwnProperty(newTags[j]) ) {
       g.data.tags[newTags[j]] ++;
    } else {
       g.data.tags[newTags[j]] = 1;
    }
  }
  g.gui.updateTagTree();
};

g.service.addURL = function(url, memo) {
  var param = {
    'source': 'url',
    'url' : url,
    'memo': memo
  };
  var address = '/_/insertCollect?' + $.param(param);
  $.getJSON( address, function( dataObj ) {
  });
};

g.service.accessWeibo = function(index) {
  if ( index === undefined) {
    return;
  }
  var address = '/_/getAddressOfWeibo?index=' + index;
  $.getJSON( address, function( dataObj ) {
    if ( dataObj.url != undefined) {
      var win = window.open(dataObj.url, '_blank');
    }
  });
};

g.gui.updateTagTree = function() {
  var treeData = [
      {label:'数据来源'},
      {label:'标签'},
  ];
  treeData[0].children = [];
  treeData[0].children.push({label:'全部来源', type:'source', vlaue:'all'});
  treeData[1].children = [];
  treeData[1].children.push({label:'未设置标签', type:'tag', vlaue:null});

  for(var i in g.data.sources) {
    treeData[0].children.push({
        label:  g.data.sources[i]
      , type:   'source'
      , value:  i
    });
  }

  var myTags = [];
  for (var t in g.data.tags) {
      myTags.push(t);
  }
  myTags.sort();

  for(var i =0; i < myTags.length; i++) {
    var t = myTags[i];
    treeData[1].children.push({
        label:  t + "（" + g.data.tags[t] + "）"
      , type:   'tag'<commit_msg>Just backup<commit_after>'use strict';

// like main function in C
$(document).ready(function () {
  // UI 初始化
  var zeroMargin = {
      top:	0
    ,	bottom:	0
    ,	left:	0
    ,	right:	0
  };
  $('body').layout({
    inset:        zeroMargin,
    closable:      false,
    west__minSize: 0.15,
    west__maxSize: 0.40
  });

  $("#btnAddURL").bind('click', g.gui.addURL);

  g.service.getIndex();
});

var g = {};
g.data = {};
g.service = {};
g.gui = {};
g.service.getIndex = function() {
  $.getJSON( "/_/getIndex", function( indexObj ) {
    g.data.sources = indexObj.sources;

    g.data.tags = {};
    for (var t in indexObj.tags) {
      g.data.tags[t] = parseInt(indexObj.tags[t]);
    }

    g.gui.updateTagTree();

  }).fail(function() {
    alert("获取Index数据错误！");
  })
};

g.service.getData = function(node) {
  var address = null;
  if ( node.type === "source") {
    var select = node.value;
    address = "/_/getDataBySource";
    if ( select !== "all" && select !== undefined) {
      address = "/_/getDataBySource?source=" + select;
    }
  } else if (node.type === "tag") {
    var select = node.value;
    address = "/_/getDataByTag";
    if ( select !== null && select !== undefined) {
      address = "/_/getDataByTag?tag=" + select;
    }
  }

  if ( address !== null) {
    // 显示等待窗口
    $( "#waitDialog" ).dialog({
      dialogClass: "no-close",
      modal: true
    });

    $.getJSON( address, function( dataObj ) {
      g.data.collects = {};
      var html = "";
      for(var i = 0; i < dataObj.length; i++) {
        // B端保存数据
        g.data.collects[ dataObj[i].index ] = dataObj[i].tags;
        html += g.post.build( dataObj[i]);
      }
      $("#listItems").html(html);

      // 配置相关GUI事件处理
      $(".btnDeleteCollect").bind('click',function(){
        var index = $(this).attr('index');
        g.service.removeCollect( index );
        $("#item_" + index).remove();
      });
      $(".linkText").linkify();
      $(".btnAccessOrignalWeibo").bind('click', function(){
        var index = $(this).attr('index');
        if(index !== undefined) {
          g.service.accessWeibo(index);
        }
      });
      g.gui.refreshTagEvent();

      $("#waitDialog").dialog( "close" );
    });
  }
};

g.service.removeCollect = function(index){
  var address = '/_/removeCollect?index=' + index;
  $.getJSON( address, function( dataObj ) {

  });

  var needUpdate = false;
  var removedTags = g.data.collects[index];
  for(var j = 0; removedTags !== undefined && j < removedTags.length; j++) {
    g.data.tags[removedTags[j]] --;
    if ( g.data.tags[removedTags[j]] === 0) {
      delete g.data.tags[removedTags[j]];
      needUpdate = true;
    }
  }
  if ( needUpdate) {
    g.gui.updateTagTree();
  }
}

g.service.removeTag = function(index, tag) {
  var tagsString = jQuery.param({tags:g.data.collects[index]});
  var address = '/_/updateTag?index=' + index;
  if ( tagsString !== "") {
    address = address + '&' + tagsString;
  }
  $.getJSON( address, function( dataObj ) {

  });

  if ( g.data.tags.hasOwnProperty(tag)) {
    g.data.tags[tag] --;
    if ( g.data.tags[tag] === 0) {
      delete g.data.tags[tag];
    }
  }

  g.gui.updateTagTree();
};

g.service.addTag = function(index, newTags) {
  var tagsString = jQuery.param({tags:g.data.collects[index]});
  var address = '/_/updateTag?index=' + index;
  if ( tagsString !== "") {
    address = address + '&' + tagsString;
  }
  $.getJSON( address, function( dataObj ) {

  });


  for(var j = 0; j < newTags.length; j++) {
    if ( g.data.tags.hasOwnProperty(newTags[j]) ) {
       g.data.tags[newTags[j]] ++;
    } else {
       g.data.tags[newTags[j]] = 1;
    }
  }
  g.gui.updateTagTree();
};

g.service.addURL = function(url, memo) {
  var param = {
    'source': 'url',
    'url' : url,
    'memo': memo
  };
  var address = '/_/insertCollect?' + $.param(param);
  $.getJSON( address, function( dataObj ) {
  });
};

g.service.accessWeibo = function(index) {
  if ( index === undefined) {
    return;
  }
  var address = '/_/getAddressOfWeibo?index=' + index;
  $.getJSON( address, function( dataObj ) {
    if ( dataObj.url != undefined) {
      var win = window.open(dataObj.url, '_blank');
    }
  });
};

g.gui.updateTagTree = function() {
  var treeData = [
      {label:'数据来源'},
      {label:'标签'},
  ];
  treeData[0].children = [];
  treeData[0].children.push({label:'全部来源', type:'source', vlaue:'all'});
  treeData[1].children = [];
  treeData[1].children.push({label:'#未设置标签#', type:'tag', vlaue:null});
  treeData[1].children.push({label:'#多标签选择#', type:'tag', vlaue:null});
  treeData[1].children.push({label:'#星标#', type:'start', vlaue:'start'});

  for(var i in g.data.sources) {
    treeData[0].children.push({
        label:  g.data.sources[i]
      , type:   'source'
      , value:  i
    });
  }

  var myTags = [];
  for (var t in g.data.tags) {
      myTags.push(t);
  }
  myTags.sort();

  for(var i =0; i < myTags.length; i++) {
    var t = myTags[i];
    treeData[1].children.push({
        label:  t + "（" + g.data.tags[t] + "）"
      , type:   'tag'
{'fraction_non_alphanumeric': 0.20227635782747605, 'fraction_numerical': 0.004792332268370607, 'mean_word_length': 2.5673076923076925, 'pattern_counts': {'":': 0, '<': 11, '<?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': '5168220', 'n_tokens_mistral': 3698, 'n_tokens_neox': 3688, 'n_words': 666}