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/system/ts/sqlManagement.ts

277 lines
8.1 KiB

/// <reference path="../../includes.ts"/>
/// <reference path="systemPlugin.ts"/>
/// <reference path="systemHelpers.ts"/>
/// <reference path="systemServices.ts"/>
/// <reference path="../../configs/ts/configsUtils.ts"/>
/// <reference path="../../configs/ts/customAlert.ts"/>
/// <reference path="../../kubernetes/ts/kubernetesHelpers.ts"/>
module System{
export var SystemSQLManagement = controller('SystemSQLManagement', ['$scope', '$location', '$http', '$element', '$templateCache', 'NgTableParams', 'ngDialog', 'SystemModel', ($scope, $location, $http, $element, $templateCache, NgTableParams, ngDialog, SystemModel) => {
shareInit($scope);
$scope.cities = classifyCity(SystemModel.regionalismInfo);
$scope.status = [{id: 0, label: "有缺失"}, {id: 1, label: "正常"}, {id: 2, label:"待归档"}, {id: 3, label: "待审核"}];
SystemModel.updateSqlInfo();
$scope.model = SystemModel.sqlInfo;
$scope.checkboxes = {
checked: false,
items: {}
};
$scope.optionsFilter= {
x: "all",
y: "all",
z: "all"
}
$scope.tableParams = new NgTableParams({count: 25}, {
counts: [25, 50, 100],
dataset: $scope.model
});
$scope.citySelect = (x) => {
$scope.optionsFilter.x = x;
$scope.optionsFilter.y = $scope.y = "all";
if(x != "all"){
$scope.countries = classifyCountry(SystemModel.regionalismInfo, x); //获取当前市下所有区县
}else{
$scope.countries = [];
}
}
$scope.countrySelect = (y) => {
$scope.optionsFilter.y = y;
}
$scope.statusSelect = (z) => {
$scope.optionsFilter.z = z;
}
$scope.$watch(() =>{
return $scope.optionsFilter;
}, (value) =>{
shareUpdate($scope.model, value);
}, true);
$scope.quickCheck = () => {
updateSqlStatus("/java/console/api/filePackage/totalVerifySqlFile");
}
$scope.quickFile = () => {
updateSqlStatus("/java/console/api/filePackage/totalOnholeSqlFile");
}
$scope.help = () => {
ngDialog.open({
template: 'statusHelp.html',
width: 600,
height: 370,
closeByDocument: false,
className: 'ngdialog-theme-default'
});
}
// watch for check all checkbox
$scope.$watch(function() {
return $scope.checkboxes.checked;
}, function(value) {
angular.forEach($scope.model, function(item) {
$scope.checkboxes.items[item.id] = value;
});
});
// watch for data checkboxes
$scope.$watch(function() {
return $scope.checkboxes.items;
}, function(values) {
$scope.checkable = false;
for(var index in values){
if(values[index] == true){
$scope.checkable = true;
break;
}
}
var checked = 0, unchecked = 0,
total = $scope.model.length;
angular.forEach($scope.model, function(item) {
checked += ($scope.checkboxes.items[item.id]) || 0;
unchecked += Number((!$scope.checkboxes.items[item.id])) || 0;
});
if ((unchecked == 0) || (checked == 0)) {
$scope.checkboxes.checked = (checked == total);
}
angular.element($element[0].getElementsByClassName("select-all")).prop("indeterminate", (checked != 0 && unchecked != 0));
}, true);
//查看
$scope.viewSql = (selected, type) => {
ngDialog.open({
template: 'sqlView.html',
controller:'Configs.SqlViewController',
width: 1000,
height: 600,
scope: $scope,
closeByDocument : false,
data: {type: type, item: selected },
className: 'ngdialog-theme-default'
});
}
//上传
$scope.addSql = (selected, type) => {
ngDialog.open({
template: 'sqlAdd.html',
controller:'Configs.SqlAddController',
width: 600,
height: 600,
scope: $scope,
closeByDocument : false,
data: {type: type, item: selected },
className: 'ngdialog-theme-default'
});
}
//审核
$scope.verifySql = (selected, type) => {
ngDialog.open({
template: 'sqlVerification.html',
controller:'Configs.sqlVerificationController',
width: 1000,
height: 600,
scope: $scope,
closeByDocument : false,
data: {type: type, item: selected },
className: 'ngdialog-theme-default'
});
}
//替换
$scope.moveSql = (selected, type) => {
ngDialog.open({
template: 'sqlMove.html',
controller:'Configs.sqlMoveController',
width: 600,
height: 600,
scope: $scope,
closeByDocument : false,
data: {type: type, item: selected },
className: 'ngdialog-theme-default'
});
}
$scope.$on('onOk', (event, data) => {
Configs.create_mask(); //创建遮罩层
Kubernetes.create_locadEffect("正在更新文件,请稍等!"); //创建数据加载效果层
var target = document.getElementById('loading')
var spinner = new Spinner(Kubernetes.loadConfigs()).spin(target);
$http({
url: "/java/console/api/filePackage/handleSqlFile",
method: "POST",
params: {type: data.type, opt: data.opt},
data: JSON.stringify({
item: data.item,
content: data.content
})
}).success((data,header,config,status) => {
$("#load").remove();
Kubernetes.removeMask();
$scope.model = SystemModel.sqlInfo = data.data;
shareUpdate($scope.model, $scope.optionsFilter);
}).error((data,header,config,status) => {
$("#load").remove();
Kubernetes.removeMask();
});
});
$scope.$on("replace", (event, data) => {
$http({
url: "/java/console/api/filePackage/handleSqlFile",
method: "POST",
params: {type: data.type, opt: data.opt},
data: JSON.stringify({
item: data.item,
content: data.content
})
}).success((data,header,config,status) => {
$scope.model = SystemModel.sqlInfo = data.data;
shareUpdate($scope.model, $scope.optionsFilter);
}).error((data,header,config,status) => {
Configs.customAlert("提示", "脚本替换或归档失败!", '',null, 0, "error");
});
});
function shareUpdate (data, value){
var filter = data, result = [];
if(value.x != "all"){
angular.forEach(filter, (item) => {
if(item.cityName == value.x)
result.push(item);
});
filter = result;
result = [];
}
if(value.y != "all"){
angular.forEach(filter, (item) => {
if(item.districtName == value.y)
result.push(item);
});
filter = result;
result = [];
}
if(value.z != "all"){
angular.forEach(filter, (item) =>{
if($scope.status[item.sysStatus].label == value.z)
result.push(item);
});
filter = result;
result = [];
}
$scope.tableParams.settings({
dataset: filter
});
$scope.checkboxes = {
checked: false,
items: {}
};
}
function updateSqlStatus(url: string) {
var items = [];
if($scope.model && $scope.model.length > 0){
angular.forEach($scope.model, (item) => {
if($scope.checkboxes.items[item.id])
items.push(item);
});
}
if(items.length <= 0)
return;
Configs.create_mask(); //创建遮罩层
Kubernetes.create_locadEffect("正在更新文件,请稍等!"); //创建数据加载效果层
$http({
url: url,
method: 'POST',
data: JSON.stringify(items)
}).success(function(data,header,config,status){
$scope.model = SystemModel.sqlInfo = data.data;
shareUpdate($scope.model, $scope.optionsFilter);
$("#load").remove();
Kubernetes.removeMask();
//响应成功
}).error(function(data,header,config,status){
//处理响应失败
$("#load").remove();
Kubernetes.removeMask();
Configs.customAlert("提示", "一键审核或归档失败!", '',null, 0, "error");
});
}
}])
}