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

316 lines
9.5 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: "待审核"}];
$scope.cityFilter = $scope.model = SystemModel.sqlInfo;
$scope.checkboxes = {
checked: false,
items: {}
};
$scope.tableParams = new NgTableParams({count: 25}, {
counts: [25, 50, 100],
dataset: $scope.model
});
$scope.citySelect = (x) => {
if($scope.z != 'all'){
$scope.statusFilter = [];
angular.forEach($scope.model, (item) => {
if($scope.status[item.sysStatus].label == $scope.z)
$scope.statusFilter.push(item)
});
}else
$scope.statusFilter = $scope.model;
if(x != 'all'){
$scope.countries = classifyCountry(SystemModel.regionalismInfo, x); //获取当前市下所有区县
$scope.cityFilter = [];
angular.forEach($scope.statusFilter, (item) => {
if(x == item.cityName)
$scope.cityFilter.push(item);
});
}else{
$scope.countries=[];
$scope.y = 'all';
$scope.cityFilter = $scope.statusFilter;
}
$scope.countryFilter = $scope.cityFilter;
$scope.tableParams.settings({
dataset: $scope.cityFilter
});
}
$scope.countrySelect = (y) => {
if(y != 'all'){
$scope.countryFilter = [];
angular.forEach($scope.cityFilter, (item) => {
if(item.districtName == y)
$scope.countryFilter.push(item);
});
}else
$scope.countryFilter = $scope.cityFilter
$scope.tableParams.settings({
dataset: $scope.countryFilter
});
}
$scope.statusSelect = (z) => {
var tmp = [];
if($scope.x == 'all')
tmp = $scope.model;
else
tmp = $scope.countryFilter ;
var result = [];
if(z != 'all'){
angular.forEach(tmp, (item) => {
if($scope.status[item.sysStatus].label == z)
result.push(item);
});
$scope.tableParams.settings({
dataset: result
});
}else{
$scope.tableParams.settings({
dataset: tmp
});
}
}
$scope.quickCheck = () => {
updateSqlStatus("/java/console/api/filePackage/totalVerifySqlFile");
}
$scope.quitFile = () => {
updateSqlStatus("/java/console/api/filePackage/totalOnholeSqlFile");
}
$scope.help = () => {
ngDialog.open({
template: 'statusHelp.html',
width: 900,
height: 600,
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);
}
// grayed checkbox
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();
shareUpdate(data);
}).error((data,header,config,status) => {
});
});
$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) => {
shareUpdate(data);
}).error((data,header,config,status) => {
Configs.customAlert("提示", "脚本替换或归档失败!", '',null, 0, "error");
})
});
function shareUpdate (data){
$scope.filterResult = $scope.model = SystemModel.sqlInfo = data.data;
var result = [];
if($scope.x != "all"){
angular.forEach($scope.filterResult, (item) => {
if(item.cityName == $scope.x)
result.push(item);
});
$scope.filterResult = result;
result = [];
}
if($scope.y != "all"){
angular.forEach($scope.filterResult, (item) => {
if(item.districtName == $scope.y)
result.push(item);
});
$scope.filterResult = result;
result = [];
}
$scope.tableParams.settings({
dataset: $scope.filterResult
});
}
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;
$http({
url: url,
method: 'POST',
data: JSON.stringify(items)
}).success(function(data,header,config,status){
var result = data.data, filter;
if($scope.z != 'all'){
result = [];
angular.forEach(data.data, (item) =>{
if($scope.status[item.sysStatus].label == $scope.z)
result.push(item);
});
}
filter = result;
if($scope.x != 'all'){
filter = [];
var tmp = [];
angular.forEach(result, (item) => {
if($scope.x == item.cityName)
tmp.push(item);
});
filter = tmp;
if($scope.y != 'all'){
filter = [];
angular.forEach(tmp, (item) => {
if($scope.y == item.districtName)
filter.push(item);
});
}
}
$scope.tableParams.settings({
dataset: filter
});
//响应成功
}).error(function(data,header,config,status){
//处理响应失败
});
}
}])
}