414 lines
14 KiB
TypeScript
414 lines
14 KiB
TypeScript
/// <reference path="../../includes.ts"/>
|
||
/// <reference path="../../kubernetes/ts/kubernetesHelpers.ts"/>
|
||
/// <reference path="../../kubernetes/ts/kubernetesModel.ts"/>
|
||
/// <reference path="../../configs/ts/configsDataService.ts"/>
|
||
/// <reference path="developerEnrichers.ts"/>
|
||
/// <reference path="developerHelpers.ts"/>
|
||
/// <reference path="dataManagerHelper.ts"/>
|
||
/// <reference path="dataManagerModel.ts"/>
|
||
/// <reference path="../../configs/ts/configsHelper.ts"/>
|
||
/// <reference path="../../configs/ts/customAlert.ts"/>
|
||
|
||
module Developer {
|
||
export var WorkspacesController = controller("WorkspacesController", ["$scope", "KubernetesModel", "DataModel", "ConfigsModel", "KubernetesState", "$templateCache", "$location", "$routeParams", "$http", "$timeout", "KubernetesApiURL", "$element", "ngDialog",
|
||
($scope, KubernetesModel: Kubernetes.KubernetesModelService, DataModel:Developer.DataModelService, ConfigsModel:Configs.ConfigsModelService, KubernetesState, $templateCache:ng.ITemplateCacheService, $location:ng.ILocationService, $routeParams, $http, $timeout, KubernetesApiURL, $element, ngDialog) => {
|
||
$scope.model=DataModel;
|
||
$scope.replicasModel = KubernetesModel;
|
||
|
||
$scope.options = DataModel.paramOptions;
|
||
$scope.pageSizeChoses = DataModel.paramOptions.pagerSizeOption;
|
||
var result = getDataType($location);
|
||
|
||
|
||
$scope.treeOptions = {
|
||
nodeChildren: "childNodes",
|
||
dirSelectable: true,
|
||
injectClasses: {
|
||
ul: "a1",
|
||
li: "a2",
|
||
liSelected: "a7",
|
||
iExpanded: "a3",
|
||
iCollapsed: "a4",
|
||
iLeaf: "a5",
|
||
label: "a6",
|
||
labelSelected: "a8"
|
||
}
|
||
}
|
||
|
||
//配置数据表格需要显示的内容及显示格式
|
||
$scope.tableConfig = {
|
||
data: 'model.data',
|
||
showSelectionCheckbox: true,
|
||
enableRowClickSelection: false,
|
||
multiSelect: true,
|
||
selectedItems: [],
|
||
filterOptions: {
|
||
filterText: $location.search()["q"] || ''
|
||
},
|
||
columnDefs: [
|
||
{
|
||
field: "_key",
|
||
displayName: '编码'
|
||
},
|
||
{
|
||
field: "name",
|
||
displayName: '市-区/县',
|
||
customSortField: (field) => {
|
||
return field.regionalismCode;
|
||
}
|
||
},
|
||
{
|
||
field: "systemName",
|
||
displayName: '系统名称',
|
||
customSortField: (field) => {
|
||
return field.systemCode;
|
||
}
|
||
},
|
||
{
|
||
field: "dataBaseType",
|
||
displayName: '数据库类型',
|
||
},
|
||
{
|
||
field: "labels",
|
||
displayName: '数据标签',
|
||
cellTemplate: $templateCache.get("dataLabelsTemplate.html")
|
||
},
|
||
{
|
||
field: "year",
|
||
displayName: '年度',
|
||
},
|
||
{
|
||
field: "collectingTime",
|
||
displayName: '采集时间'
|
||
},
|
||
{
|
||
field: "extractStatus",
|
||
displayName: '汇总状态',
|
||
cellTemplate: $templateCache.get("dataExtractTemplate.html")
|
||
}
|
||
],
|
||
sortInfo: {
|
||
sortBy: "_key",
|
||
ascending: true
|
||
}
|
||
};
|
||
|
||
init($scope, $location, $routeParams);
|
||
$scope.model.paramOptions.dataType = result["dataType"];
|
||
$scope.model.paramOptions.volumeType = result["volumeType"];
|
||
|
||
$scope.$on("dataLabelFilterUpdate", ($event, text, key) => {
|
||
$scope.keyQuery += " " + text;
|
||
})
|
||
|
||
$scope.selectBatchItem = (item)=> {
|
||
$scope.navbarItems.forEach((nav) =>{
|
||
nav.class="";
|
||
});
|
||
item.class="active";
|
||
$scope.model.updateParamOption("currentPageNum", 1);
|
||
$scope.model.updateParamOption("keyQuery", $scope.keyQuery);
|
||
$scope.model.updateParamOption("dataBatch", item.alias);
|
||
}
|
||
|
||
$scope.isEmptyOrFirst = () => {
|
||
var idx = $scope.model.getParamOption("currentPageNum");
|
||
var length =$scope.model.paramOptions.totlePage;
|
||
return length <= 0 || idx <= 1;
|
||
}
|
||
|
||
$scope.isEmptyOrLast = () =>{
|
||
var idx = $scope.model.getParamOption("currentPageNum");
|
||
var length =$scope.model.paramOptions.totlePage;
|
||
return length < 1 || idx >= length;
|
||
}
|
||
|
||
$scope.first = () => {
|
||
var idx = $scope.model.getParamOption("currentPageNum");
|
||
if(idx >1){
|
||
Kubernetes.eliminateChechBoxClick();
|
||
$scope.model.updateParamOption("currentPageNum", 1);
|
||
}
|
||
}
|
||
|
||
$scope.last = () =>{
|
||
var idx = $scope.model.getParamOption("currentPageNum");
|
||
var length =$scope.model.paramOptions.totlePage;
|
||
if(idx < length){
|
||
Kubernetes.eliminateChechBoxClick();
|
||
$scope.model.updateParamOption("currentPageNum", length);
|
||
}
|
||
}
|
||
|
||
$scope.previous = () => {
|
||
var idx = $scope.model.getParamOption("currentPageNum");
|
||
var length =$scope.model.paramOptions.totlePage;
|
||
if(idx > 1){
|
||
Kubernetes.eliminateChechBoxClick();
|
||
$scope.model.updateParamOption("currentPageNum", idx-1);
|
||
}
|
||
}
|
||
|
||
$scope.next = () =>{
|
||
var length =$scope.model.paramOptions.totlePage;
|
||
var idx = $scope.model.getParamOption("currentPageNum");
|
||
if(idx < length){
|
||
Kubernetes.eliminateChechBoxClick();
|
||
$scope.model.updateParamOption("currentPageNum", idx+1);
|
||
}
|
||
}
|
||
|
||
$scope.$watch('model.paramOptions', (newValue, oldValue) => {
|
||
if(newValue){
|
||
if(newValue.currentTableSize !== oldValue.currentTableSize)
|
||
$scope.options.priorTableSize = oldValue.currentTableSize;
|
||
else
|
||
$scope.options.priorTableSize = newValue.currentTableSize;
|
||
DataModel.updateModel();
|
||
}
|
||
|
||
}, true);
|
||
|
||
$scope.search = () => {
|
||
//$scope.model.initParamOptions();
|
||
$scope.model.paramOptions.currentPageNum = 1;
|
||
$scope.model.updateParamOption("keyQuery", $scope.keyQuery);
|
||
|
||
}
|
||
|
||
$scope.deletePrompt = (selected) => {
|
||
if (angular.isString(selected)) {
|
||
selected = [{
|
||
id: selected
|
||
}];
|
||
}
|
||
/*
|
||
判断数据是否已挂载使用和正在迁移。
|
||
*/
|
||
var message = Kubernetes.checkForMigration($scope.replicasModel.replicationControllers, $scope.model.transferTasks , $scope.tableConfig.selectedItems, "manager");
|
||
if(message != ""){
|
||
Configs.customAlert("提示", "操作失败:" + message + ",不能删除!", '',null, 0, "error");
|
||
return;
|
||
}
|
||
|
||
UI.multiItemConfirmActionDialog(<UI.MultiItemConfirmActionOptions>{
|
||
collection: selected,
|
||
index: 'alias',
|
||
onClose: (result:boolean) => {
|
||
var idColl = [];
|
||
if (result) {
|
||
angular.forEach(selected, (select) => {
|
||
idColl.push(select.id);
|
||
});
|
||
$http({
|
||
method: "POST",
|
||
url: "/java/console/api/delete/data",
|
||
params: {"data": idColl}
|
||
}).success(function(data, status, headers, config) {
|
||
//成功之后做一些事情
|
||
DataModel.updateModel();
|
||
}).error(function(data, status, headers, config) {
|
||
|
||
});
|
||
}
|
||
},
|
||
title: '是否需要删除采集数据?',
|
||
action: '以下采集数据文件将会被删除:',
|
||
okText: '删除',
|
||
okClass: 'btn-danger sj_btn_cir',
|
||
custom: "该删除操作将会彻底删除数据文件,是否删除,请确认!",
|
||
customClass: "alert alert-warning sj_alert-warning",
|
||
cancelText: "取消",
|
||
cancelClass: 'sj_btn_grey'
|
||
}).open();
|
||
}
|
||
|
||
$scope.migrationClick = {
|
||
items:null,
|
||
selectedItem: {"name": "当前没有可以迁移的集群"},
|
||
dialog: new UI.Dialog(),
|
||
onOk: () => {
|
||
var migrationClick = $scope.migrationClick;
|
||
/*
|
||
向后台发生数据迁移请求,$http:发生http异步请求;第二个参数:请求url;第三个参数:请求操作类型;第四个参数:请求携带的数据;第五个参数:
|
||
一个回调函数,请求响应后的回调函数。
|
||
*/
|
||
|
||
if(Kubernetes.alreadyExitInFolder($scope.tableConfig.selectedItems, $scope.selectNode)){
|
||
migrationClick.close();
|
||
Configs.customAlert("提示", "操作失败:" + "数据已在当前目录!", '',null, 0, "error");
|
||
return;
|
||
};
|
||
|
||
Configs.oracleInfoOperate($http, "/java/console/api/volume", Configs.OperateType.MOVE,
|
||
{
|
||
"name": migrationClick.selectedItem.name,
|
||
"selectItems": $scope.tableConfig.selectedItems,
|
||
"selectNode": $scope.selectNode
|
||
}, (result, status) => {
|
||
if(status===200){
|
||
//$scope.model.updateOracleParam();
|
||
}else
|
||
throw "资源请求失败";
|
||
});
|
||
/*
|
||
页面跳转
|
||
*/
|
||
$timeout(() =>{
|
||
$location.path("/workspaces/Overview/task");
|
||
},250);
|
||
migrationClick.close();
|
||
},
|
||
open: (selected) =>{
|
||
var migrationClick = $scope.migrationClick;
|
||
|
||
ConfigsModel.updateVolumeData();
|
||
if(ConfigsModel.cluster!=null)
|
||
$scope.volumes = ConfigsModel.cluster;
|
||
|
||
/*
|
||
判断数据是否已挂载使用和正在迁移。
|
||
*/
|
||
|
||
var message = Kubernetes.checkForMigration($scope.replicasModel.replicationControllers, $scope.model.transferTasks , $scope.tableConfig.selectedItems, "manager");
|
||
|
||
if(message == ""){
|
||
if($scope.volumes && $scope.volumes instanceof Array && $scope.volumes.length >0)
|
||
migrationClick.selectedItem = $scope.volumes[0];
|
||
migrationClick.dialog.open();
|
||
}else{
|
||
Configs.customAlert("提示", "操作失败:" + message + ", 不能迁移!", '',null, 0, "error");
|
||
}
|
||
},
|
||
close: () => {
|
||
$scope.migrationClick.selectedItem = {"name": "当前没有可以迁移的集群"};
|
||
$scope.migrationClick.dialog.close();
|
||
}
|
||
};
|
||
|
||
$scope.createOracleService = (items) =>{
|
||
var exitedItems = Kubernetes.checkForCreateOracle($scope.model.transferTasks, items);
|
||
for (var i = 0; i < items.length; ++i) {
|
||
// code...
|
||
if(items[i].dataBaseType != 'ORACLE'){
|
||
Configs.customAlert("提示", "操作失败: 非ORACLE数据不需要挂载启动!", '', null, 0, "error");
|
||
return;
|
||
}
|
||
}
|
||
if(exitedItems.length == 0){
|
||
angular.forEach(items,(item)=>{
|
||
console.log(item);
|
||
var isExited = Kubernetes.checkForExit($scope.replicasModel.replicationControllers, item);
|
||
if(!isExited){
|
||
Kubernetes.createRC({
|
||
name: item._key,
|
||
labels: {
|
||
system: item.systemCode.toString(),
|
||
version: item.dataVersion.toString(),
|
||
region: item.regionalismCode.toString()
|
||
},
|
||
annotations: {
|
||
cityName: item.cityName,
|
||
districtName: item.districtName,
|
||
systemName: item.systemName,
|
||
id: item.id+"",
|
||
year: item.year,
|
||
checkoutFlag: item.checkoutFlag
|
||
},
|
||
path: item.dataPath+"app/",
|
||
isTarget: "false",
|
||
isExtract: item.extractStatus
|
||
}, (rc) =>{
|
||
Kubernetes.connectOracle($http, $timeout, "/java/console/api/connectOracle", "create", rc, 0);
|
||
});
|
||
}
|
||
});
|
||
|
||
$timeout(() => {
|
||
$location.path('/kubernetes/namespace/default/replicationControllers');
|
||
}, 200);
|
||
}else{
|
||
var name = "";
|
||
angular.forEach(exitedItems, (item) => {
|
||
name += item.name + "-" + item.systemName + ",";
|
||
});
|
||
Configs.customAlert("提示", "操作失败: 正在迁移的数据不能被启动!", '', null, 0, "error");
|
||
}
|
||
}
|
||
|
||
function init($scope,$location,$routeParams){
|
||
$scope.keyQuery = "";
|
||
$scope.model.initParamOptions();
|
||
$scope.model.updateParamOption("keyQuery", $scope.keyQuery);
|
||
if(ConfigsModel.cluster!=null)
|
||
$scope.volumes = ConfigsModel.cluster;
|
||
|
||
//创建二级菜单
|
||
$scope.subTabConfig = Developer.createCurrentSubNavBar($scope, $location, $routeParams);
|
||
$scope.navbarItems =[{
|
||
herf: "",
|
||
label: "全部",
|
||
title: "查看全部数据",
|
||
class: "active",
|
||
alias: null
|
||
},
|
||
{
|
||
herf: "",
|
||
label: "批次A",
|
||
title: "查看批次A的数据",
|
||
class: "",
|
||
alias: "A"
|
||
},
|
||
{
|
||
herf: "",
|
||
label: "批次B",
|
||
title: "查看批次B的数据",
|
||
class: "",
|
||
alias: "B"
|
||
}];
|
||
|
||
if(!($location.path().indexOf("hot") > -1)){
|
||
$scope.tableConfig.columnDefs.splice(7,0,{
|
||
field: "existHotData",
|
||
displayName: '是否已在热区',
|
||
cellTemplate: $templateCache.get("isExistHot.html")
|
||
});
|
||
}
|
||
}
|
||
|
||
function getDataType($location){
|
||
var path = $location.path();
|
||
var dataType;
|
||
var volumeType;
|
||
var subPath = path.split("/");
|
||
if(path.indexOf("hot") > -1)
|
||
$scope.isShow = true;
|
||
else
|
||
$scope.isShow = false;
|
||
|
||
switch (subPath[subPath.length -1]) {
|
||
case "financial":
|
||
dataType = "财政";
|
||
break;
|
||
case "social-security":
|
||
dataType = "社保";
|
||
break;
|
||
default:
|
||
dataType = null;
|
||
break;
|
||
};
|
||
switch (subPath[3]) {
|
||
case "hot":
|
||
volumeType = 0
|
||
break;
|
||
default:
|
||
volumeType = 1
|
||
}
|
||
return {
|
||
"dataType": dataType,
|
||
"volumeType": volumeType
|
||
}
|
||
}
|
||
}]);
|
||
}
|