javascrit 学习2 bdp

/**
 * 用户管理 列表页 相关js
 * @author lifangli 2016/7/13
 */
var DISPATCH_TASK_LISTNEW = {};
DISPATCH_TASK_LISTNEW.SearchUrl = "/ops/hbase/instance/v2/list.ajax";
DISPATCH_TASK_LISTNEW.DetailUrl = "/ops/hbase/instanceManage/v2/showInstance.html";
DISPATCH_TASK_LISTNEW.AtomWorkflowUrl = "/atom/workflow/v2/apply/add.html";
DISPATCH_TASK_LISTNEW.EditInstanceUrl = "/ops/hbase/instance/v2/edit.html";
DISPATCH_TASK_LISTNEW.PushGrantUrl = "/ops/hbase/instance/v2/prePushGrant.html"

var taskscope = {};
var SearchUrl = "";

var grace_scope;

taskscope._init_base = function () {

    refreshSearchUrl();
    taskscope._init_grid();
    grace_scope.initGrid();
};

$(document).ready(function () {


    $('#environmentId').select2();
    $('#systemLevelListId').select2();
    $('#hbaseVersionId').select2();
    $('#sdkVersionId').select2();

   /* initBusinessListJrc();
    initProductListJrc();
    initAppGroupListJrc();*/

    taskscope._init_base();
    initClusterList();
    initGroupList();
    $("#JrcSelect").toggleClass("bdp-hidden");
    initButton();


});

function refreshSearchUrl() {
    SearchUrl = DISPATCH_TASK_LISTNEW.SearchUrl;

}
// 设置cookie 有效期30天
function setTipCookie() {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = "showTip=" + escape(false) + ";expires=" + exp.toGMTString();
}

// 关闭按钮清楚cookie
$("#closeTip").click(function () {
    setTipCookie();
})

taskscope._init_grid = function () {
    var isAdmin = $("#isAdmin").val();
    var grace = angular.module('grace.bootstrap.demo', ['grace.bootstrap'], angular.injector(['grace.bootstrap.bootConfigs']).get('bootConfig'));
    grace.controller('GridDemoCtrl', ["$scope", "$http", "$gDataAdapterFactory", "$gDataAdapterModelManagerFactory", function ($scope, $http, dataAdapter, ModelManager) {
        function return_html(return_text,record){
            //if(record.approveCount > 0){
            //    return "<span style='color:red' >"+(return_text || "")+"</span>"
            //}
            return return_text || "--";
        }
        function generateData(requestData) {
            var data = {
                columnsDef: [
                    {
                        field: "instanceName", id: "instanceName", name: "实例编号", visible: true,width:120,
                        formatter: function (instanceName, record) {
                            var href = '<a href="' + DISPATCH_TASK_LISTNEW.DetailUrl + '?instanceId=' + record.id +'" target="_blank">' + instanceName + '</a>';
                            return return_html(href,record);
                        }
                    },
                    {field: "prjectName", id: "prjectName", name: "项目名称", visible: true,width:120},
                    {field: "clusterName", id: "clusterName", name: "集群", visible: true,width:80,
                        formatter:function(clusterName,record){
                            var temp = '';
                            temp = "<a href='/ops/hbase/cluster/showCluster.html?clusterName="+clusterName+"' target='_blank'>"+clusterName+"</a>";
                            return temp;
                        }
                    },
                    {field: "currentClusterName", id: "currentClusterName", name: "使用中", visible: true,width:100},
                    {field: "totalSize", id: "totalSize", name: "存储量(TB)", visible: true,width:120},
                    {field: "deptName", id: "deptName", name: "所属部门", visible: true,width:120},
                    {field: "environmentDesc", id: "environmentDesc", name: "环境", visible: true,width:100},
                    {field: "hbaseVersionDesc", id: "hbaseVersionDesc", name: "版本", visible: true,width:80},
                    {field: "systemLevelDesc", id: "systemLevelDesc", name: "级别", visible: true,width:80},
                    {field: "sdkVersion", id: "sdkVersion", name: "SDK版本", visible: true,width:100},
                    {field: "manageName", id: "manageName", name: "负责人", visible: true, enableTooltip: true,width:100},
                    {field: "groupName", id: "groupName", name: "分组", visible: true, enableTooltip: true,width:80},
                    {
                        field: "", id: "", name: "操作", visible: true,
                        formatter: function (instanceName, record) {
                            var instanceHref="--";
                            var groupHref="--";
                            var switchSub="";
                            var switchMain="";
                            var sdkCheckUrl = "";

                            if(record.hbaseVersion == 2){
                                instanceHref = '<a href="http://query.hbase.jd.com/dashboard/db/instance?orgId=1&var-hbase='+record.clusterName+'&var-namespace='+record.spaceName+'" target="_blank">实例监控</a>';
                                groupHref = '<a href="http://query.hbase.jd.com/dashboard/db/group?orgId=1&var-hbase='+record.clusterName+'&var-group='+record.groupName+'" target="_blank">分组监控</a>';
                            }

                            if(record.switchFlag == 1){
                                switchSub = '<a href="javascript:switchSub('+record.id+')">切到从</a>'
                                switchMain = '<a href="javascript:switchMain('+record.id+')">切到主</a>'
                            }

                            if(isAdmin == 'true'){
                                sdkCheckUrl = '<a href="http://mam.jd.com/dashboard/db/yan-zheng-sdkqie-huan?orgId=1&var-master='+record.clusterName+'&var-slave='+record.subClusterName+'&var-namespace='+record.spaceName+'" target="_blank">sdk验证</a>';

                            }
                            return instanceHref + "&nbsp;&nbsp;&nbsp;"+groupHref + "&nbsp;&nbsp;" +switchSub+"&nbsp;&nbsp;" + switchMain+"&nbsp;&nbsp;&nbsp;"+sdkCheckUrl;
                        }
                    },
                    {field: "modifiedToStr", id: "modifiedToStr", name: "创建时间", visible: true,width:120}
                ],
                enablePagination: true,
                paginationConfig: {
                    enableSetRefresh: true,//是否设置定时刷新
                    setTimeRefresh: 300,//时间单位为s;如果设置了开启定时刷新,请设置默认定时刷新时间
                    pageIcon: true,
                    pageSize: 10,
                    pageSizes: [50, 100],
                    enableRefresh: true
                },
                selectionConfig: {
                    checkboxSelect: true,
                    checkboxSelectWidth: 35,
                    pinned: true
                },
                enableSelection: true,
                enableSelectionMulti: true,
                expandableTable: false,
                enableColumnResize: true,
                expandableTable: false,
                enableColumnResize: true,
                enableSort:true,
                lockHeader: true,//是否固定Header表头
                lockHeaderType: "top",//固定Header表头属性;
                enableSearchAll: true,//是否支持搜索所有
                rowHeight: 40,//行高度
                headerRowHeight: 40,//表头高度
                minColumnWidth: 90,//最小列宽度
                enableAutoResize: true,//是否自适应列宽度
                enableRowDragging: true,//是否支持列drag拖拽
                enableSelectAll: true,//是否支持选择所有
                useRemoteData: true//是否支持远程后台数据
            };
            data.ajaxConfig = {
                url: SearchUrl,
                method: 'post',
                dataType: 'json',
                externalData: function () {
                    var res = {};
                    var queryStr = $('#queryStr').val();
                    var environmentId = $('#environmentId').val();
                    var systemLevelListId = $('#systemLevelListId').val();
                    var clusterNamesId = $('#clusterNamesId').val();
                    var hbaseVersionId = $('#hbaseVersionId').val();
                    var sdkVersionId = $('#sdkVersionId').val();
                    var group = $("#groupNamesId").val();
                    if(group){
                        group = group.split(",")[1];
                    }
                    if (!(queryStr == null || queryStr == "")) {
                        res['instanceName'] = queryStr;
                    }
                    if (!(environmentId == null || environmentId == "")) {
                        res['environment'] = environmentId;
                    }
                    if (!(systemLevelListId == null || systemLevelListId == "")) {
                        res['systemLevel'] = systemLevelListId;
                    }
                    if (!(clusterNamesId == null || clusterNamesId == "")) {
                        res['clusterName'] = clusterNamesId;
                    }
                    if (!(hbaseVersionId == null || hbaseVersionId == "")) {
                        res['hbaseVersion'] = hbaseVersionId;
                    }
                    if (!(sdkVersionId == null || sdkVersionId == "")) {
                        res['sdkVersion'] = sdkVersionId;
                    }
                    if (!(group == null || group == "")) {
                        res['groupName'] = group;
                    }

                    return res;
                }
            };
            return data;
        }

        function gridReady(api) {
            $scope.gridApi = api;
            //列编辑信息
            api.event.on('contentEdit', onContentEdit);
            //行选中
            api.event.on('rowSelect', onRowSelect);
            //行取消选中
            api.event.on('rowUnSelect', onRowSelect);
            //选中所有的行
            api.event.on('rowSelectAll', onRowSelectAll);
            //取消所有的行选中事件
            api.event.on('rowUnSelectAll', onRowSelectAll);

            api.event.on('paging', function () {
                $scope.result = [];
                buttonSelector($scope.result);
            });

        };


        $scope.initGrid = function (data) {
            $scope.gridOptions = generateData(data);
            $scope.gridOptions.onReady = gridReady;
            $scope.$apply();
            $scope.inited = true;
        };

        //selectedData就是当前选择行的数据
        function onRowSelectAll(evt, selectedIndex, selectedData) {
            $scope.result = selectedData;
            buttonSelector(selectedData);
        };

        //selectedData就是当前选择行的数据
        function onRowSelect(evt, rowIndex, selectedIndex, selectedData) {
            $scope.result = selectedData;
            buttonSelector(selectedData);

        };
        function onContentEdit(evt, rowIndex, field, currentValue) {
            $scope.editResult = $scope.gridApi.getRowDataByIndex(rowIndex);
            console.log("第", rowIndex, '行', field, '列,当前值:', currentValue)

        };

        //变量赋值
        grace_scope = $scope;

    }]);
    angular.bootstrap(document, ['grace.bootstrap.demo']);
}
$('#search-btn').click(function () {
    grace_scope.gridApi.toPage(1);
    //grace_scope.gridApi.reload();
});

function refreshBufMagList(e) {
    var code = e.keyCode;
    if (code == 13) {
        grace_scope.gridApi.toPage(1);
        grace_scope.gridApi.reload();
    }
}
/*
 *Div隐藏显示操作
 */
$('#HlevSearch-btn').click(function () {
    $("#JrcSelect").toggleClass("bdp-hidden");
});


function buttonSelector(selectedData) {
    if (selectedData.length == 0) {
        initButton();
    } else if (selectedData.length == 1) {
        $("#jrcedit-btn").removeClass("disabled");
        $("#jrcdrop-btn").removeClass("disabled");
        $("#jrcpush-btn").removeClass("disabled");
        $("#jrcupgrade-btn").removeClass("disabled");
    } else if (selectedData.length > 1) {
        initButton();
    }
};
function initButton() {
    $("#jrcedit-btn").addClass("disabled");
    $("#jrcdrop-btn").addClass("disabled");
    $("#jrcpush-btn").addClass("disabled");
    $("#jrcupgrade-btn").addClass("disabled");

};
/**
 * 修改实例
 */
$("#jrcedit-btn").click(function () {

    if (grace_scope.result == null || grace_scope.result.length == 0 || grace_scope.result.length > 1) {
        $.bdpUtil.alertDialog($("#mainContainer"), "您只能选中一条记录才能进行此操作,请重新选择后继续!");
        return false;
    }
    //跳转到修改页面
    else {
        var id = grace_scope.result[0].id;
        var instanceName = grace_scope.result[0].instanceName;
        $.ajax({
            url:'/ops/hbase/instance/v2/flageEdit.ajax',
            type: 'GET',
            dataType: 'json',
            async: false,
            data: {id:id,instanceName:instanceName},
            success: function (data) {
                if(data.success){
                    // window.open('/ops/hbase/instance/v2/edit.html?instanceId=' + id);
                    window.open(DISPATCH_TASK_LISTNEW.EditInstanceUrl + '?instanceId=' + id,'_blank');
                }else{
                    $.bdpUtil.alertDialog($("#mainPlatformContainer"),"您无权限进行修改,请刷新列表!");
                }
            },
            error: function(data){ //失败
                $.bdpUtil.alertDialog($("#mainPlatformContainer"),"您无权限进行修改,请刷新列表!");
            },
            dataType: "json"
        });

    }

});

/**
 * 普通建表跳转
 */
$('#jrcadd-btn').click(function () {
    var workFlowId = $("#newInstanceWorkflowId").val();
    window.open(DISPATCH_TASK_LISTNEW.AtomWorkflowUrl + '?workFlowId=' + workFlowId, '_blank');
});


/**
 * 实例下线
 */
$("#jrcdrop-btn").click(function () {

    if (grace_scope.result == null || grace_scope.result.length == 0 || grace_scope.result.length > 1) {
        $.bdpUtil.alertDialog($("#mainPlatformContainer"), "您只能选中一条记录才能进行此操作,请重新选择后继续!");
        return false;
    }
    //跳转到流程中心下线申请页面
    else {
        var instanceName = grace_scope.result[0].instanceName;
        // var data = "{text_1:" + '"' +instanceName + '"' + "}";
        // var workFlowId = $("#offInstanceWorkFlowId").val();
        $.bdpUtil.showConfirmDialog(
            $("#mainPlatformContainer"),
            "请确认是否下线实例【" + instanceName + "】?",
            function (result) {
                if (result) {
                    // window.open(DISPATCH_TASK_LISTNEW.AtomWorkflowUrl + '?workFlowId=' + workFlowId + '&data=' + data);
                    goWorkFlow(instanceName);
                }
            }
        );
    }
});

function goWorkFlow(instanceName) {
    $.ajax({
        url:'/ops/hbase/instance/v2/goWorkFlow.ajax',
        type: 'GET',
        dataType: 'json',
        async: false,
        data: {instanceName:instanceName},
        success: function (data) {
            if(data.success){
                $.bdpUtil.alertDialog($("#mainPlatformContainer"),"实例下线申请提交成功,请等待审核!<br/>进入<a href='/atom/workflow/v2/request/apply.html' target='_blank' >我的申请</a>,查看审批详情");
            }else{
                $.bdpUtil.alertDialog($("#mainPlatformContainer"),data._msg);
            }
        },
        error: function(data){ //失败
            $.bdpUtil.alertDialog($("#mainPlatformContainer"),"您无权限进行修改,请刷新列表!");
        },
        dataType: "json"
    });
}

function checkAccess(instanceName,record) {
    $.ajax({
        url:'/ops/hbase/instance/v2/checkAccess.ajax',
        type: 'GET',
        dataType: 'json',
        async: false,
        data: {instanceName:instanceName},
        success: function (data) {
            if(data.success){
                // $.bdpUtil.alertDialog($("#mainPlatformContainer"),"实例下线申请提交成功,请等待审核!<br/>进入<a href='/atom/workflow/v2/request/apply.html' target='_blank' >我的申请</a>,查看审批详情");
                var href = '<a href="' + DISPATCH_TASK_LISTNEW.DetailUrl + '?instanceId=' + record.id +'" target="_blank">' + instanceName + '</a>';
                return return_html(href,record);
            }else{
                $.bdpUtil.alertDialog($("#mainPlatformContainer"),data._msg);
            }
        },
        error: function(data){ //失败
            $.bdpUtil.alertDialog($("#mainPlatformContainer"),"您无权限进行修改,请刷新列表!");
        },
        dataType: "json"
    });
}

//实例统计
$("#jrcDepInstance-btn").click(function(){
    window.open("/ops/hbase/instance/v2/instanceDep.html");
});

//推数授权
$("#jrcpush-btn").click(function () {

    if (grace_scope.result == null || grace_scope.result.length == 0 || grace_scope.result.length > 1) {
        $.bdpUtil.alertDialog($("#mainContainer"), "您只能选中一条记录才能进行此操作,请重新选择后继续!");
        return false;
    }
    //跳转到申请页面页面
    else {

        var instanceName = grace_scope.result[0].instanceName;
        var data = '{"instance_name":"'+instanceName+'"}';
        window.open(DISPATCH_TASK_LISTNEW.AtomWorkflowUrl + '?workFlowId=10338&data='+data, '_blank');
    }

});

//数据库迁移/升级

$('#jrcupgrade-btn').click(function () {

    if (grace_scope.result == null || grace_scope.result.length == 0 || grace_scope.result.length > 1) {
        $.bdpUtil.alertDialog($("#mainContainer"), "您只能选中一条记录才能进行此操作,请重新选择后继续!");
        return false;
    }
    //跳转到申请页面页面
    else {

        var instanceName = grace_scope.result[0].instanceName;
        var data = '{"instance_name":"'+instanceName+'"}';
        window.open(DISPATCH_TASK_LISTNEW.AtomWorkflowUrl + '?workFlowId=10332&data='+data, '_blank');
    }

});
//切换到从集群
function switchSub(instanceId){
    if(!instanceId){
        return;
    }
    var instanceIds =[];
    instanceIds[0] = instanceId;
    var type = "instance";
    $.ajax({
        url:'/ops/hbase/cluster/switchZk.ajax',
        type: 'GET',
        dataType: 'json',
        async: false,
        data: {instanceIds:instanceIds,type:type,groups:"",cluster:""},
        success: function (data) {
           $('#show_switch_win_btn').trigger('click');

        },
        error: function(data){ //失败
            $('#show_switch_win_btn').trigger('click');
        },
        dataType: "json"
    });
}

//切换到主集群
function switchMain(instanceId){
    if(!instanceId){
        return;
    }
    var instanceIds =[];
    instanceIds[0] = instanceId;
    var type = "instance";
    $.ajax({
        url:'/ops/hbase/cluster/switchSubZk.ajax',
        type: 'GET',
        dataType: 'json',
        async: false,
        data: {instanceIds:instanceIds,type:type,groups:"",cluster:""},
        success: function (data) {
            $('#show_switch_win_btn').trigger('click');
        },
        error: function(data){ //失败
            $('#show_switch_win_btn').trigger('click');
        },
        dataType: "json"
    });
}

/*
$("#updateDepInstance-btn").click(function () {
    $.ajax({
        url:'/ops/hbase/instance/v2/updateInstanceDep.ajax',
        type: 'GET',
        dataType: 'json',
        async: false,
        success: function (data) {

        },
        error: function(data){ //失败

        },
        dataType: "json"
    });
});


//实例统计
$("#sdkinfo-btn").click(function(){
    window.open("/ops/hbase/instance/v2/instanceSdkVersion.html");
});*/

$("#jrcSwtichInstance-btn").click(function(){


    if (grace_scope.result == null || grace_scope.result.length == 0) {
        $.bdpUtil.alertDialog($("#mainPlatformContainer"), "请新选择后继续!");
        return false;
    }else {

       var instanceIds= new Array();
       for(var i=0;i< grace_scope.result.length;i++){
           instanceIds.push(grace_scope.result[i].id);
       }
       $.ajax({
            url:'/ops/hbase/instance/v2/checkInstancePermission.ajax',
            type: 'GET',
            dataType: 'json',
            async: false,
            data: {instanceIds:instanceIds},
            success: function (data) {

                if(!data._code){
                    var tempData = data.data;

                    $("#permission_content").data("instanceSwitchData",tempData);
                    var trStr = '';
                    for(var n = 0; n < tempData.length;n++){
                        var node = tempData[n];
                        var projectName = node.projectName;

                        var currentClusterName = node.currentClusterName;
                        var targetName = node.targetName;
                        var instanceName = node.instanceName;
                        var currentNamePermission = node[instanceName+"_"+currentClusterName];
                        var targetNamePermission = node[instanceName+"_"+targetName];


                        var tempCurrentPermission='';

                        for(var key in currentNamePermission){
                            var permissionValue = currentNamePermission[key];
                            //判断当前权限是否在目标集群周一致
                            var targetPersimissionValue = targetNamePermission[key];

                            if(permissionValue != targetPersimissionValue){
                                tempCurrentPermission =tempCurrentPermission +'<span title="此权限在目标集群不一致" style="color:red">'+key+":"+currentNamePermission[key]+'</span><br>';
                            }else{
                                tempCurrentPermission =tempCurrentPermission +key+":"+currentNamePermission[key]+'<br>';
                            }



                        }


                        var tempTargetPermission='';
                        for(var key in targetNamePermission){
                            tempTargetPermission =tempTargetPermission +key+":"+targetNamePermission[key]+"<br>";
                        }


                        trStr = trStr+
                            "<tr>" +
                            "   <td>"+instanceName+"</td>" +
                            "   <td>"+projectName+"</td>" +
                            "   <td>"+currentClusterName+"</td>" +
                            "   <td>"+tempCurrentPermission+"</td>" +
                            "   <td>"+targetName+"</td>" +
                            "   <td>"+tempTargetPermission+"</td>" +
                            "</tr>";



                    }


                    $("#permission_content").empty().append(trStr);
                    $('#switch_win_btn').trigger('click');
                }else{
                    $.bdpUtil.alertDialog($("#mainPlatformContainer"), "获取权限校验失败");
                }

            },
            error: function(data){ //失败
                console.info("切换失败:"+data)
                $.bdpUtil.alertDialog($("#mainPlatformContainer"), "切换失败请联系管理员");
            }
        });

    }
});

$("#jrcancle-btn-switch").click(function(){
    $('#switch_win_btn').trigger('click');
});


$("#jrcIPInstance-btn").click(function(){
    window.open("/ops/hbase/instance/v2/instanceIps.html");
});



$("#jrok-btn-switch").click(function(){
    var switchInstanceInfo = $("#permission_content").data("instanceSwitchData");
    var node1 = switchInstanceInfo[0];
    var currentClusterName1 = node1.currentClusterName;
    var targetCluster1 = node1.targetName;

    //检验所选的集群是否一致
    for(var i = 1; i < switchInstanceInfo.length;i++){
       var node = switchInstanceInfo[i];
       if(currentClusterName1 != node.currentClusterName){
           $.bdpUtil.alertDialog($("#mainPlatformContainer"), "所选实例当前所在集群不一致");
           return;
       }
        if(targetCluster1 != node.targetName){
            $.bdpUtil.alertDialog($("#mainPlatformContainer"), "所选实例的目标集群不一致");
            return;
        }


    }

    $.ajax({
        url:'/ops/hbase/instance/v2/switchInstance.ajax',
        type: 'POST',
        dataType: 'json',
        async: false,
        data: {data:JSON.stringify(switchInstanceInfo)},
        success: function (data) {
           
            $.bdpUtil.alertDialog($("#mainPlatformContainer"), data._msg);
            $("#jrcancle-btn-switch").trigger('click');

        },
        error: function(data){ //失败

        }
    });

    console.info(switchInstanceInfo);
});


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值