You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aggregation-platform/plugins/developer/ts/workspaces.ts

474 lines
18 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/// <reference path="../../includes.ts"/>
/// <reference path="../../kubernetes/ts/kubernetesHelpers.ts"/>
/// <reference path="developerEnrichers.ts"/>
/// <reference path="developerHelpers.ts"/>
/// <reference path="developerNavigation.ts"/>
module Developer {
export var WorkspacesController = controller("WorkspacesController",
["$scope", "KubernetesModel", "KubernetesState", "$templateCache", "$location", "$routeParams", "$http", "$timeout", "KubernetesApiURL", "DataInfoModel", "$interval",
($scope, KubernetesModel:Kubernetes.KubernetesModelService, KubernetesState, $templateCache:ng.ITemplateCacheService, $location:ng.ILocationService, $routeParams, $http, $timeout, KubernetesApiURL, DataInfoModel,$interval) => {
$scope.model = DataInfoModel;
$scope.items=[];
$scope.localitems=[];
var rootPath="";
var FilterList ={
length:0
};
update();
$scope.treeOptions = {
nodeChildren: "children",
dirSelectable: true,
multiSelection: false,
injectClasses: {
ul: "a1",
li: "a2",
liSelected: "a7",
iExpanded: "a3",
iCollapsed: "a4",
iLeaf: "a5",
label: "a6",
labelSelected: "a8"
}
};
$scope.treeOptionss = {
nodeChildren: "children",
dirSelectable: true,
multiSelection: true,
injectClasses: {
ul: "a1",
li: "a2",
liSelected: "a7",
iExpanded: "a3",
iCollapsed: "a4",
iLeaf: "a5",
label: "a6",
labelSelected: "a8"
}
};
$scope.showSelected = (node,selected)=>{
$scope.model.serveritems = [];
var array = new Array();
if(selected){
if(node.children.length > 0){
array.unshift(node);
while(array.length > 0){
var childNode=array.pop();
if(childNode.children.length>0){
for(var i=0;i<childNode.children.length;i++)
array.unshift(childNode.children[i]);
}else{
if(childNode.hasOwnProperty("path"))
$scope.model.serveritems.push(childNode);
}
}
}else{
if(node.hasOwnProperty("path"))
$scope.model.serveritems.push(node);
}
}
};
$scope.dataForTheTree = $scope.model.serverdata;
$scope.dataForTheTreeLocal = $scope.model.localdata;
$scope.$watch('model.serverdata', function(newValue,oldValue){
if(newValue){
$scope.dataForTheTree = $scope.model.serverdata;
}
});
$scope.$watch('model.localdata', function(newValue,oldValue){
if(newValue){
$scope.dataForTheTreeLocal = $scope.model.localdata;
}
});
$scope.upLoadXMLFile = (files) => {
FilterList.length=0;
if(files.length>0){
var j=0;
for(var i=0;i<files.length;i++){
if(files[i].name.indexOf("data.xml")!=-1){
//console.log(files[i]);
rootPath=files[i].webkitRelativePath.replace(/\/data.xml$/,"");
var reader= new FileReader();
var resultString = "{\"name\": \"\", \"children\":[";
reader.onload = function(){
var str = event.target.result;
// alert(str);
var item = "<Data>";
var itemEnd = "</Data>";
// ´ý·µ»ØµÄ½á¹û£º
if(str != undefined){
// Õû¸öxml ÍêÕûÊý¾Ý£ºxmldata
var xmldata = str.toString();
// °´ÔÏó·ÖµÄÊý¾Ý£º
var itemArray = xmldata.split(item);
var itemsize = itemArray.length;
for(var k = 1; k < itemsize; k++){
var itemvalue = itemArray[k].split(itemEnd);
// province
var provinceValueTemp = itemvalue[0].split("<province>");
var provinceValue = provinceValueTemp[provinceValueTemp.length-1].split("</province>")[0];
//city
var cityValueTemp = itemvalue[0].split("<city>");
var cityValue = cityValueTemp[cityValueTemp.length-1].split("</city>")[0];
// county
var countyValueTemp = itemvalue[0].split("<county>");
var countyValue = countyValueTemp[countyValueTemp.length-1].split("</county>")[0];
// <code>
var codeValueTemp = itemvalue[0].split("<code>");
var codeValue = codeValueTemp[codeValueTemp.length-1].split("</code>")[0];
// <sys_name>
var sys_nameValueTemp = itemvalue[0].split("<sys_name>");
var sys_nameValue = sys_nameValueTemp[sys_nameValueTemp.length-1].split("</sys_name>")[0];
// <character_set>
var character_setValueTemp = itemvalue[0].split("<character_set>");
var character_setValue = character_setValueTemp[character_setValueTemp.length-1].split("</character_set>")[0];
// <sys_name_code>
var sys_name_codeValueTemp = itemvalue[0].split("<sys_name_code>");
var sys_name_codeValue = sys_name_codeValueTemp[sys_name_codeValueTemp.length-1].split("</sys_name_code>")[0];
// <contact>
var contactValueTemp = itemvalue[0].split("<contact>");
var contactValue = contactValueTemp[contactValueTemp.length-1].split("</contact>")[0];
// <phone>
var phoneValueTemp = itemvalue[0].split("<phone>");
var phoneValue = phoneValueTemp[phoneValueTemp.length-1].split("</phone>")[0];
// <date>
var dateValueTemp = itemvalue[0].split("<date>");
var dateValue = dateValueTemp[dateValueTemp.length-1].split("</date>")[0];
//id :
var itemId = codeValue + "_" + sys_name_codeValue;
// http get version
var rid = itemId//.replace(/\"/g, "");
// TODO typeValue 通过前端页面获取或者财政01或社保02
var typeValue = "01";
// TODO batchValue 通过前端页面获取或者批次A 大写的A批次B 大写的B
var batchValue = "A";
var itemname = cityValue + countyValue + sys_nameValue;
var versionid = 1;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if(xhr.status==200){
versionid = xhr.responseText;
}
}
}
xhr.open("get","/getversion?id="+rid, false);
xhr.send(null);
var jsobj = JSON.parse(versionid);
var xmlversion = jsobj.id;
var properValue = "{\"id\":\""+itemId+"\", \"name\":\""+itemname+"\", \"city\":\""+
cityValue + "\", \"county\":\""+countyValue+"\", \"system\":\""+
sys_nameValue+"\", \"type\":\"" + typeValue + "\",\"batch\":\""+
batchValue+"\",\"version\":\""+xmlversion+"\", \"province\":\""+
provinceValue +"\", \"code\":\""+
codeValue +"\", \"character_set\":\""+
character_setValue +"\", \"sys_name_code\":\""+
sys_name_codeValue +"\", \"contact\":\""+
contactValue +"\", \"phone\":\""+
phoneValue +"\", \"date\":\""+
dateValue +"\"}";
resultString = resultString + properValue;
if(k < itemsize-1){
resultString =resultString+", "
}
}
resultString = resultString+"]}";
}
$scope.$apply(function(){
$scope.model.localdata = JSON.parse(resultString.toString());
});
}
reader.readAsText(files[i],"utf-8");
}
else{
FilterList.length+=1;
var file_id=files[i].name.replace(/\.\w*$/,'');
// var file_id=file[i].webkitRelativePath.replace(/^[a-z]*\/$/,'');
// file_id = file_id.replace(/\/\w+$/,'');
FilterList[j++]=files[i];
}
}
}
$scope.model.uploadprocess = {};
}
$scope.upLoadFiles = ()=>{
if($scope.model.uploadedStatus == "once"){
return;
}
$scope.model.uploadedStatus = "once";
$scope.model.createFolderList(FilterList,rootPath);
if($scope.model.folderList.length >0 && $scope.model.selectednodes.length >0){
var isNotExited = [];
var isExited = [];
for(var node in $scope.model.selectednodes){
if(!$scope.model.folderList.hasOwnProperty($scope.model.selectednodes[node].id)){
isNotExited.push($scope.model.selectednodes[node]);
}else{
if($scope.model.uploadprocess[$scope.model.selectednodes[node].id] === 'undefined' || $scope.model.uploadprocess[$scope.model.selectednodes[node].id] === 0)
isExited.push($scope.model.selectednodes[node]);
}
}
if(isNotExited.length >0 ){
var str = "以下数据文件不存在:\n\r文件名:\n";
for(var item in isNotExited)
str += isNotExited[item].id+"\n";
alert(str);
}
if(isExited.length <=0){
alert("数据文件中没有可用上传的文件!");
}else{
var isuploaad = 1,i = 0;
var timerForUpload = $interval(function(){
if(i >= isExited.length){
// clearInterval(timerForUpload);
$interval.cancel(timerForUpload);
}
if(isuploaad == 1){
var r = new Resumable({
target:'/uploadfiles',
chunkSize:50*1024*1024,
simultaneousUploads:400,
testChunks:true,
throttleProgressCallbacks:1
});
var xhr = new XMLHttpRequest();
xhr.open("GET","/getclientip",true);
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if(xhr.status==200){
r.setip(xhr.responseText);
}
}
}
xhr.send(null);
r.on('fileAdded', function(file){
r.upload();
update();
});
$scope.model.resumablejs.push({
dirname : isExited[i].id,
resumable : r
});
r.setRootPath(isExited[i].type+"/"+isExited[i].batch+"/"+isExited[i].id+"/"+isExited[i].version+"/");
r.myLoadFiles($scope.model.folderList[isExited[i].id]);
r.upload();
r.on('fileProgress',function(file){
var file_id=file.relativePath.replace(/^[a-z]*\/$/,'');
var filestr = "";
var reg = /\/[0-9]*_*[0-9]*\//g;
var resultstr;
while( (resultstr = reg.exec(file_id)) != null){
filestr = resultstr[0];
}
file_id = filestr.replace(/\/*/g,'');
r.setFileId(file_id);
// $scope.$apply(function(){
$scope.model.uploadprocess[file_id] = Math.floor(r.progress()*98);
// });
});
r.on('complete', function(){
var timerForchmod = setInterval(function(){
var pathjson = "\"path\":\""+r.getrootPath()+"\""
var datamessage = {"path":r.getrootPath(),"filenum":$scope.model.folderList[isExited[i-1].id].length};
$scope.model.uploadprocess[r.getFileId()] = Math.round(r.progress()*99);
$http({
url:'/setchmod2dir',
method:'GET',
params:datamessage
}).success(function(data,header,config,status){
if(data){
//console.log(data);
var clientdata = data;
if(clientdata == "chmod"){
sendDateMessage(isExited[i-1]);
r.setisnowcheck("1");
r.mkRetfileUploadSucceed();
clearInterval(timerForchmod);
}
}
}).error(function(data,header,config,status){
console.log("-----sendDateMessage-------------"+status);
});
},5000);
});
i++;
isuploaad = 0;
r.on('fileuploadendsucceed', function(){
$scope.model.uploadprocess[r.getFileId()] = Math.floor(r.progress()*100);
$timeout(() => {
$http({
url:'/xmlformserver',
method:'Post'
}).success(function(data,header,config,status){
if(data){
$scope.model.serverdata = data;
}
}).error(function(data,header,config,status){
console.log("error");
});
},2000);
isuploaad = 1;
});
}
},2000);
}
}else{
alert("您没有选择需要上传的数据文件,或你选择的文件中不存在指定格式的数据文件!");
}
}
function sendDateMessage(datamessage){
$http({
url:'/sendDateMessage',
method:'GET',
params:datamessage
}).success(function(data,header,config,status){
if(data)
var clientdata = data;
}).error(function(data,header,config,status){
});
}
$scope.downLoadFiles = ()=>{
Kubernetes.connectOracle($http, $timeout, "192.168.0.103:64182", "320614-54-1", 500);
}
$scope.isSelected= (node)=>{
var index = $scope.model.findItemIndex(node);
if(index !== -1){
$scope.model.selecteditems.splice(index,1);
}
else{
$scope.model.selecteditems.push(node);
}
}
$scope.showSelectedLocal = (node,selected) => {
var index = $scope.model.findNodes(node);
if(index !== "-1"){
if($scope.model.uploadprocess[node.id] ===0)
$scope.model.selectednodes.splice(index,1);
}else{
$scope.model.uploadprocess[node.id] =0;
$scope.model.selectednodes.push(node);
}
}
$scope.startOracle = ()=> {
if($scope.model.selecteditems.length >0){
for(var id in $scope.model.selecteditems){
var Obj = createRCObj($scope.model.selecteditems[id]);
if(!checkIsRunning(KubernetesModel.replicationControllers,Obj)){
Kubernetes.createRC(Obj, (rc) =>{
console.log(rc.metadata.name);
Kubernetes.connectOracle($http, $timeout, "/connectToOracle", "", rc.metadata.name, 0);
});
}
}
}
}
function checkIsRunning(replicationControllers,item){
for(var rc in replicationControllers){
if(item.name === replicationControllers[rc].metadata.name)
return true;
}
return false;
}
function createRCObj(item: Object){
var array =item.id.split("_");
if(array[0] === "10"){
//console.log(item);
return {
"name": item.fakename,
"labels": {
"name": item.fakename
},
"path": item.path +"app/",
"isTarget" : "true"
}
}else{
return {
"name": array[2] + "-" + array[3] + "-" + array[4],
"labels": {
"type": array[0],
"batch": array[1],
"region": array[2],
"system": array[3],
"version": array[4]
},
"path": item.path +"app/",
"isTarget": "false"
}
}
}
function setchmod2dir(datamessage){
$http({
url:'/setchmod2dir',
method:'GET',
params:datamessage
}).success(function(data,header,config,status){
if(data)
var clientdata = data;
}).error(function(data,header,config,status){
console.log("-----sendDateMessage-------------"+status);
});
}
function update(){
for(var i=0; i<$scope.model.resumablejs.length; i++){
var dirId = $scope.model.resumablejs[i].dirname;
var r = $scope.model.resumablejs[i].resumable;
r.on('fileProgress', (file) =>{
if(r.getisnowcheck().indexOf("0") == -1){
$scope.$apply(function(){
$scope.model.uploadprocess[dirId] = Math.floor(r.progress()*100);
});
}
else{
$scope.$apply(function(){
$scope.model.uploadprocess[dirId] = Math.floor(r.progress()*98);
});
}
});
}
}
}]);
}