aggregation-platform/plugins/configs/ts/shareController.ts

346 lines
9.1 KiB
TypeScript

/// <reference path="../../includes.ts"/>
/// <reference path="configPlugin.ts"/>
/// <reference path="configsDataService.ts"/>
/// <reference path="../../configs/ts/configsUtils.ts"/>
/// <reference path="../../configs/ts/customAlert.ts"/>
/// <reference path="../../kubernetes/ts/kubernetesHelpers.ts"/>
module Configs{
export var TableEdit = controller('TableEdit', ['$scope', ($scope) => {
$scope.editRow = (entity)=>{
$scope.$emit('editRow', entity);
}
$scope.deleteRowOne ={
show: false,
item: null,
open: (entity) => {
var deleteRowOne = $scope.deleteRowOne;
deleteRowOne.show = true;
deleteRowOne.item = entity;
},
onOk: () => {
var deleteRowOne = $scope.deleteRowOne;
$scope.$emit('deleteRow', deleteRowOne.item);
},
onCancel: () => {
var deleteRowOne = $scope.deleteRowOne;
deleteRowOne.show = false;
deleteRowOne.item = null;
}
}
}]);
export var VolumeController = controller('VolumeController', ['$scope', '$http', ($scope, $http) => {
$scope.submitted = false;
$scope.status = $scope.ngDialogData.status;
$scope. cancel = () =>{
$scope.closeThisDialog();
$scope.submitted = false;
}
$scope.deleteBrock = (volume:volume, brock) => {
if(volume.brick.length>1)
deleteBrock(volume, brock);
else
$scope.showMessage = true;
}
$scope.addBrock = (volume) => {
var block = {
ip: "", //存储块的机器ip地址
path: "", //存储块路径
status: false, //存储块的状态
editable:true
};
addBrock(volume, block);
$scope.showMessage = false;
}
$scope.stopVolume = (volume) =>{
volume.status = false;
}
$scope.startVolume = (volume) =>{
volume.status = true;
}
$scope.onSubmit = (entity) => {
console.log(entity);
if($scope.volumeForm.$valid){
$scope.$emit('update', entity);
$scope.closeThisDialog();
}else{
$scope.submitted = true;
}
}
}]);
export var SystemInfoController = controller('SystemInfoController', ['$scope', ($scope) =>{
}]);
export var SqlViewController = controller('SqlViewController', ['$scope', '$http', ($scope, $http) =>{
$scope.title = shareInit($scope.ngDialogData);
$scope.content = "";
getSqlContent();
function getSqlContent(){
$http({
url: "/java/console/api/filePackage/readSqlFile",
method:'POST',
params: {type: $scope.ngDialogData.type},
data: JSON.stringify($scope.ngDialogData.item)
}).success(function(data,header,config,status){
$scope.old_content = data.data1;
//响应成功
}).error(function(data,header,config,status){
//处理响应失败
$scope.old_content = "获取脚本内容失败"
});
}
$scope.upLoadSqlFile = () => {
if(typeof FileReader == 'undefined'){
throw "浏览器不支持FileReader读取文件";
}else{
Configs.FileInputPlugin((file) =>{
if(typeof typeof FileReader == 'undefined')
throw "浏览器不支持FileReader读取文件";
else{
var fr = new FileReader();
fr.onloadend = (e) =>{
$scope.new_content = e.target["result"];
$scope.enable = true;
}
fr.onloadstart = () =>{
$scope.$apply(() =>{
$scope.content = "正在读取数据请稍等...";
});
$scope.content = "正在读取数据请稍等...";
}
fr.readAsText(file[0],"GBK");
}
});
}
}
$scope.onOk = () => {
$scope.enable = false;
if(null == $scope.new_content || $scope.new_content == ""){
console.log("上传的内容不能为空");
$scope.closeThisDialog();
}else{
$scope.$emit("onOk",{
url: "/java/console/api/filePackage/handleSqlFile",
item: $scope.ngDialogData.item,
content: $scope.new_content,
opt: "add",
type: $scope.ngDialogData.type
});
$scope.closeThisDialog();
}
}
$scope.cancel = () => {
$scope.enable = false;
$scope.closeThisDialog();
}
}]);
export var SqlAddController = controller('SqlAddController', ['$scope', '$http', ($scope, $http) => {
$scope.content = "";
$scope.title = shareInit($scope.ngDialogData);
$scope.sqlFileUpload = () =>{
Configs.FileInputPlugin((file) =>{
if(typeof FileReader == 'undefined')
throw "浏览器不支持FileReader读取文件";
else{
var fr = new FileReader();
fr.onloadend = (e) =>{
$scope.content = e.target["result"];
$scope.enable = true;
}
fr.onloadstart = () =>{
$scope.$apply(() =>{
$scope.content = "正在读取数据请稍等...";
});
$scope.content = "正在读取数据请稍等...";
}
fr.readAsText(file[0],"GBK");
}
});
}
$scope.onOk = () => {
$scope.enable = false;
if(null ==$scope.content || $scope.content == ""){
console.log("上传的内容不能为空");
$scope.closeThisDialog();
}
else{
$scope.$emit("onOk",{
url: "/java/console/api/filePackage/handleSqlFile",
item: $scope.ngDialogData.item,
content: $scope.content,
opt: "add",
type: $scope.ngDialogData.type
});
$scope.closeThisDialog();
}
}
$scope.cancel = () => {
$scope.enable = false;
$scope.closeThisDialog();
}
}]);
export var sqlVerificationController = controller('sqlVerificationController', ['$scope', '$http', ($scope, $http) => {
getSqlContent();
$scope.title = shareInit($scope.ngDialogData);
$scope.replace = () => {
$scope.$emit("replace", {
url: "/java/console/api/filePackage/handleSqlFile",
item: $scope.ngDialogData.item,
content: $scope.content,
opt: "replace",
type: $scope.ngDialogData.type
});
$scope.closeThisDialog();
}
function getSqlContent(){
$http({
url: "/java/console/api/filePackage/readSqlFile",
method:'POST',
params: {type: $scope.ngDialogData.type},
data: JSON.stringify($scope.ngDialogData.item)
}).success(function(data,header,config,status){
$scope.standard = data.data1;
$scope.unnormal = data.data2;
//响应成功
}).error(function(data,header,config,status){
//处理响应失败
$scope.unnormal = $scope.standard = "获取脚本内容失败";
});
}
$scope.cancel = () => {
//$scope.closeThisDialog();
$scope.$emit("replace", {
url: "/java/console/api/filePackage/handleSqlFile",
item: $scope.ngDialogData.item,
content: $scope.content,
opt: "delete",
type: $scope.ngDialogData.type
});
$scope.closeThisDialog();
}
}]);
export var sqlMoveController = controller("sqlMoveController", ['$scope', '$http', ($scope, $http) => {
getSqlContent();
$scope.title = shareInit($scope.ngDialogData);
$scope.move = () => {
$scope.$emit("replace", {
url: "/java/console/api/filePackage/handleSqlFile",
item: $scope.ngDialogData.item,
content: $scope.content,
opt: "replace",
type: $scope.ngDialogData.type
});
$scope.closeThisDialog();
}
$scope.cancel = () => {
$scope.closeThisDialog();
}
function getSqlContent(){
$http({
url: "/java/console/api/filePackage/readSqlFile",
method:'POST',
params: {type: $scope.ngDialogData.type},
data: JSON.stringify($scope.ngDialogData.item)
}).success(function(data,header,config,status){
$scope.content = data.data2;
//响应成功
}).error(function(data,header,config,status){
//处理响应失败
$scope.content = "获取脚本内容失败";
});
}
}]);
export var sysVerUpdateController = controller('sysVerUpdateController', ['$scope', '$http', ($scope, $http) => {
$scope.checkboxItmes = [];
$scope.click = ($event, name) => {
if($event.target.checked){
if($scope.checkboxItmes.indexOf(name) == -1)
$scope.checkboxItmes.push(name)
}
else{
for(var i= 0; i < $scope.checkboxItmes.length; i++){
if($scope.checkboxItmes[i] === name){
$scope.checkboxItmes.splice(i,1);
break;
}
}
}
}
getData();
$scope.replace = () => {
$scope.requestBody = $scope.data1;
angular.forEach($scope.checkboxItmes, (item) => {
$scope.requestBody[item] = $scope.data2[item];
});
$scope.$emit("updateRow", $scope.requestBody);
$scope.closeThisDialog();
}
$scope.cancel = () => {
$scope.closeThisDialog();
}
function getData(){
$http({
url: "/java/console/api/checkout/findDetails",
method:'POST',
data: JSON.stringify($scope.ngDialogData)
}).success(function(data,header,config,status){
$scope.data1 = data.data1;
$scope.data2 = data.data2;
//响应成功
}).error(function(data,header,config,status){
//处理响应失败
$scope.content = "获取脚本内容失败";
});
}
}]);
function shareInit(ngDialogData) {
var title = "";
if(ngDialogData.type != 'undefined'){
switch (ngDialogData.type) {
case "userTableStatus" :
title = "UserTablespace";
break;
case "ckPayStatus":
title = "Chechout_Pay"
break;
case "ckIndicateStatus":
title = "Chechout_Indicate"
break;
}
}
return title;
}
}