var initcodeManage = function(){
	console.log("initcodeManage");
	$('[data-toggle="tooltip"]').tooltip();

	loadNodeConfig();  //调用节点管理,获得可选择集群

	setTimeout(function() {
		getUnitSession();

	}, 2000);

	$("#ypkIsPrivate")[0].value = "公共目录";
	changeYpkPath();

	getP2PNodes();
};
var getP2PNodes = function() {
    console.log("getP2PNodes")
    global.wssocket.send("{\"action\":\"getP2PNodes\"}");
}

var onGetP2PNodes = function(obj) {
    global.p2pNodes = obj.peers;
    console.log("onGetP2PNodes function", obj);
    var json = {};
    json.type = "P2P";
    json.value = obj.peers;
    json.key = "_P2PUnit";
    console.log("onGetP2PNodes json", json);
    addNodeUnit(json);
}

var changeYpkPath = function () {
	var isPublic =$("#ypkIsPrivate")[0].innerHTML;
	if(isPublic == "公共目录"){
		$("#ypkIsPrivate")[0].innerHTML = "私有目录";
		global.ypkIsPrivate = true;
		listFiles();
	}else{
		$("#ypkIsPrivate")[0].innerHTML = "公共目录";
		global.ypkIsPrivate = false;
		listFiles();
	}
};

var listFiles = function() {
	var isPublic =$("#ypkIsPrivate")[0].innerHTML;
	console.log(isPublic);
	if(isPublic == "公共目录"){
		global.wssocket.send("{\"action\":\"listCompiledFiles\",\"isPrivate\":false}");
	}else{
		global.wssocket.send("{\"action\":\"listCompiledFiles\",\"isPrivate\":true}");
	}
};

var updateGlobalProject = function() {
	setTimeout(updateGlobalProjectInternal, 100);
};

var updateGlobalProjectInternal = function() {
	var isPublic = $("#publicDir-tab").hasClass("active");
	console.log("updateGlobalProject, isPublic:" + isPublic);
	if (isPublic)
		global.projects = global.publicProjects;
	else
		global.projects = global.privateProjects;
	mainVue.projects = global.projects;
};

var changeYpkName = function(obj) {
	global.ypkName = obj;
	console.log("global.ypkName = " + global.ypkName);
};

var onListCompiledFiles = function(obj) {
	global.filewssocket = global.wssocket;
	var data = JSON.parse(obj.data);
	console.log(data);
	var html = "<option selected>请选择ypk文件</option>";
	for(var i = 0;i < data.length;i++){
		html += ("<option selected>" + data[i] + "</option>");
		changeYpkName(data[i]);
	}
	$("#selectYpkFile").html(html);
};