project.js 18.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
jQuery(document).ready(function () {
    getProjects();
});

/**
 * 操作变更
 */
function operateChange() {
    getProjects();
    var operate = $("input[name='operate']:checked").val();
    if ("Rollback" == operate) {
        //隐藏Branch输入框
        document.getElementById("branch-div").style.display = "none";
        //展示 回滚选择框
        document.getElementById("rollback-div").style.display = "";
        //隐藏自动执行测试用例
        document.getElementById("autotest-div").style.display = "none";

    } else {
        //展示Branch输入框
        document.getElementById("branch-div").style.display = "";
        //隐藏 回滚选择框
        document.getElementById("rollback-div").style.display = "none";
        //展示自动执行测试用例
        document.getElementById("autotest-div").style.display = "";
    }
}

/**
 * 根据操作获取当前的项目列表
 */
function getProjects() {
    var operate = $("input[name='operate']:checked").val();
    $.ajax({
        url: 'getProjects',
        type: 'POST',
        dataType: 'json',
        contentType: "application/json",
        success: function (data) {
            var obj = eval("(" + data + ")");
            if ("Deploy" == operate) {//发布多选框
                var order1HTML = "<div class='ckbox ckbox-primary'>";
                order1HTML += " <input name='project1all' type='checkbox' id='project1all' value='project1all' onclick='projectcheckall(this,\"project1\");'/>";
                order1HTML += "<label for='project1all' style='width: 200px'>yoho30  全选</label></div>";
                var order2HTML = "<div class='ckbox ckbox-warning'>";
                order2HTML += " <input name='project2all' type='checkbox' id='project2all' value='project2all' onclick='projectcheckall(this,\"project2\");'/>";
                order2HTML += "<label for='project2all' style='width: 200px'>yoho-search  全选</label></div>";
                order2HTML += "<div style='border:1px dashed ;padding-left: 8px'>";
                var order3HTML = "<div class='ckbox ckbox-success'>";
                order3HTML += " <input name='project3all' type='checkbox' id='project3all' value='project3all' onclick='projectcheckall(this,\"project3\");'/>";
                order3HTML += "<label for='project3all' style='width: 200px'>platform  全选</label></div>";
                order3HTML += "<div style='border:1px dashed ;padding-left: 8px'>";
                var order2num = 1;
                var order3num = 1;
                var order1HTMLMap = new Map();//div 名字 and 具体html内容
                var order1HTMLMapCount = new Map();//计数的,控制换行

                for (var i = 0; i < obj.length; i++) {
                    var order = obj[i].order;//大分类
                    var name = obj[i].name;
                    var checkstr="";
                    if(default_releaseWorkJob_project!=null&&default_releaseWorkJob_project.indexOf(name+",")>=0){
                        checkstr = " checked ";
                    }
                    if ("1" == order) {//第一大类--java 核心服务
                        var groupType = obj[i].groupType;//再细分类别
                        var currentCount = order1HTMLMapCount[groupType];
                        var currentHtml = order1HTMLMap[groupType];//当前的html
                        if(currentCount == null || currentCount == 0){//div 的头部
                            currentCount = 0;
                            currentHtml= "<div style='border:1px dashed ;'> <fieldset><legend style='height:25px;margin-left:0px;margin-top:4px;margin-bottom: 4px;font-size: 14px; background-color: #c9cecf'>&nbsp;&nbsp;"+groupType+":</legend><div style='margin-left: 8px'>";
                        }

                        if (currentCount > 0 && currentCount % 4 == 0) {//换行
                            currentHtml += "</br>";
                        }
                        currentHtml += "<div class='ckbox ckbox-primary' style='display: inline'>";
                        currentHtml += " <input name='project1' type='checkbox' " + checkstr ;
                        currentHtml += "  onclick='loadProjectEnvs()' ";
                        currentHtml += " id='" + name + "' value='" + name + "'/>";
                        currentHtml += "<label for='" + name + "' style='width: 200px'>" + name + "</label></div>";
                        order1HTMLMap[groupType] =  currentHtml;//显示的内容
                        order1HTMLMapCount[groupType] =  currentCount + 1;//计数器
                    }
                    if ("2" == order) {
                        order2HTML += "<div class='ckbox ckbox-warning' style='display: inline'>";
                        order2HTML += " <input name='project2' type='checkbox' " + checkstr;
                        order2HTML += "  onclick='loadProjectEnvs()' ";
                        order2HTML += " id='" + name + "' value='" + name + "'/>";
                        order2HTML += "<label for='" + name + "' style='width: 200px'>" + name + "</label></div>";
                        if (order2num % 4 == 0) {
                            order2HTML += "</br>";
                        }
                        order2num += 1;

                    }
                    if ("3" == order) {
                        order3HTML += "<div class='ckbox ckbox-success' style='display: inline'>";
                        order3HTML += " <input name='project3' type='checkbox' " + checkstr;
                        order3HTML += "  onclick='loadProjectEnvs()' ";
                        order3HTML += " id='" + name + "' value='" + name + "'/>";
                        order3HTML += "<label for='" + name + "' style='width: 200px'>" + name + "</label></div>";
                        if (order3num % 4 == 0) {
                            order3HTML += "</br>";
                        }
                        order3num += 1;
                    }
                }
                //循环遍历,给每一种类型结尾
                for(var html1Map in order1HTMLMap){
                    order1HTMLMap[html1Map] += "</fieldset></div></div>";//div 结尾
                    order1HTML += order1HTMLMap[html1Map] +"</br>";
                }

                document.getElementById("project-div").innerHTML = order1HTML  + "</br>" + order2HTML + "</div><hr>" + order3HTML +"</div>";
                branchdefault();
            } else {//回滚单选框
                var order1HTML = "";
                var order2HTML = "";
                var order3HTML = "";

                var order1num = 1;
                var order2num = 1;
                var order3num = 1;

                for (var i = 0; i < obj.length; i++) {
                    var order = obj[i].order;
                    var name = obj[i].name;
                    if ("1" == order) {
                        order1HTML += "<div class='rdio rdio-primary' style='display: inline'>";
                        if (name == "yoho-gateway") {
                            order1HTML += " <input name='project' type='radio' id='" + name + "' value='" + name + "' onclick='loadProjectEnvs()' checked='checked'/>";
                        } else {
                            order1HTML += " <input name='project' type='radio' id='" + name + "' value='" + name + "' onclick='loadProjectEnvs()'/>";
                        }
                        order1HTML += "<label for='" + name + "' style='width: 200px'>" + name + "</label></div>";
                        if (order1num % 4 == 0) {
                            order1HTML += "</br>";
                        }
                        order1num += 1;
                    }
                    if ("2" == order) {
                        order2HTML += "<div class='rdio rdio-warning' style='display: inline'>";
                        order2HTML += " <input name='project' type='radio' id='" + name + "' value='" + name + "' onclick='loadProjectEnvs()'/>";
                        order2HTML += "<label for='" + name + "' style='width: 200px'>" + name + "</label></div>";
                        if (order2num % 4 == 0) {
                            order2HTML += "</br>";
                        }
                        order2num += 1;

                    }
                    if ("3" == order) {
                        order3HTML += "<div class='rdio rdio-success' style='display: inline'>";
                        order3HTML += " <input name='project' type='radio' id='" + name + "' value='" + name + "' onclick='loadProjectEnvs()'/>";
                        order3HTML += "<label for='" + name + "' style='width: 200px'>" + name + "</label></div>";
                        if (order3num % 4 == 0) {
                            order3HTML += "</br>";
                        }
                        order3num += 1;

                    }
                }
                document.getElementById("project-div").innerHTML = order1HTML + "<hr>" + order2HTML + "<hr>" + order3HTML;
                loadProjectEnvs();
            }

            if(default_releaseWorkJob_enviCount!=null&&default_releaseWorkJob_enviCount>=2){
                alert("提醒:工单的发布环境为"+default_releaseWorkJob_environment+"当前只选中一个!");
            }
        },
        error: function (e) {
            alert("从后台获取数据出错");
        }
    });
}

function loadProjectEnvs(){
    var projects = "";
    var operate = $("input[name='operate']:checked").val();
    if ("Deploy" == operate) {//发布
        $('input[name="project1"]:checked').each(function () {
            projects = projects + "," + $(this).val();//向数组中添加元素
        });
        $('input[name="project2"]:checked').each(function () {
            projects = projects + "," + $(this).val();//向数组中添加元素
        });
        $('input[name="project3"]:checked').each(function () {
            projects = projects + "," + $(this).val();//向数组中添加元素
        });
    }else{
        projects = $("input[name='project']:checked").val();
    }

    $("#environmentDiv_common").empty();

    if(projects==null){
        return ;
    }


    $.ajax({
        url: contextPath+'project/getJavaProjectEnvList?projects=' + projects,
        type: 'POST',
        dataType: 'json',
        success: function (dataList) {
            if (!dataList) {
                return;
            }

            //动态生成环境的组件
            var env_HTML = "";
            for(var i = 0; i < dataList.length; i++){
                var env = dataList[i];
                if (i % 4 == 0) {
                    env_HTML += "</br>";
                }
                var show_label=env;
                env_HTML += "<div class='rdio rdio-default' style='display: inline'>";
                env_HTML += " <input name='environments' type='radio' id='dy_env_" + env + "' value='" + env +"' ";
                //env_HTML += " checked ";
                env_HTML += "  onclick= 'changeservers()' ";
                env_HTML += "/>";
                env_HTML += "<label for='dy_env_" + env + "' style='width: 200px'>" + show_label + "</label></div>";
            }
            $("#environmentDiv_common").append(env_HTML);
        },
        error: function (e) {
            alert("获取项目环境失败");
        }
    });
}

/**
 * check box全选
 * @param obj
 * @param cName
 */
function projectcheckall(obj, cName) {
    var checkboxs = document.getElementsByName(cName);
    for (var i = 0; i < checkboxs.length; i += 1) {
        checkboxs[i].checked = obj.checked;
    }

}

//确认提交
function comfirmSubmit() {
    var operate = $("input[name='operate']:checked").val();
    var environment = $("input[name='environments']:checked").val();

    if (!environment) {
        localAlert("参数错误","请填写发布环境");
        return;
    }

    var projects = new Array();
    if ("Deploy" == operate) {//发布
        $('input[name="project1"]:checked').each(function () {
            projects.push($(this).val());//向数组中添加元素
        });
        $('input[name="project2"]:checked').each(function () {
            projects.push($(this).val());//向数组中添加元素
        });
        $('input[name="project3"]:checked').each(function () {
            projects.push($(this).val());//向数组中添加元素
        });
        if (projects.length == 0) {
            localAlert("参数错误", "请选择项目");
            return;
        }
        var branch = $("input[name='branch']").val();
        if (branch == "") {
            localAlert("参数错误", "请填写分支名称");
            return;
        }
        var workid = $("input[name='workid']").val();
        if (workid == "") {
            localAlert("参数错误", "请填写关联工单号");
            return;
        }

        $.ajax({
            url: 'check?projects=' + projects + '&branch=' + branch+ '&environment=' + environment+ '&workid=' + workid,
            type: 'POST',
            success: function (dataResp) {
                if (dataResp==null||dataResp.code != 200) {
                    localAlert("校验不通过",dataResp.message);
                    return;
                } else {
                    $("input[name='operate_name']").val(operate);
                    $("input[name='project_name']").val(projects);
                    $("input[name='environment_name']").val(environment);
                    $("input[name='branch_name']").val(branch);
                    $("input[name='workid_name']").val(workid);
                    $('#confirmSubmitDivId').modal('show');
                }
            },
            error: function (e) {
                localAlert("错误","从后台获取数据出错");
            }
        });
    } else {//回滚
        var project = $("input[name='project']:checked").val();
        var rollbackfile = $("#rollbackList option:selected").val();
        if (project == "") {
            localAlert("参数错误","请选择回滚项目");
            return;
        }
        var workid = $("input[name='workid']").val();
        if (workid == "") {
            localAlert("参数错误","请填写关联工单号");
            return;
        }
        if (typeof(rollbackfile) == "undefined" || rollbackfile == "") {
            localAlert("参数错误","请选择回滚版本");
            return;
        }
        $("input[name='operate_name']").val(operate);
        $("input[name='project_name']").val(project);
        $("input[name='environment_name']").val(environment);
        $("input[name='rollbackfile_name']").val(rollbackfile);
        $("input[name='workid_name']").val(workid);
        $('#confirmSubmitDivId').modal('show');

    }
}

function getRollbackList() {
    var project = $("input[name='project']:checked").val();
    var environment = $("input[name='environments']:checked").val();
    if(!environment){
        return;
    }
    $.ajax({
        url: 'rollbackList?project=' + project + "&environment=" + environment,
        type: 'POST',
        dataType: 'json',
        success: function (data) {
            if ("failed" == data) {
                document.getElementById("select-rollbackList-div").innerHTML = "";
                return;
            }

            var list = eval("(" + data + ")");
            //动态生成rollbackList的select组件
            var innerHTMLContext = "<select id='rollbackList' data-placeholder='Choose One' style='width:350px;'>";
            for (var i = 0; i < list.length; i++) {
                innerHTMLContext += "<option value='" + list[i] + "'>" + list[i] + "</option>";
            }
            innerHTMLContext += "</select>";
            document.getElementById("select-rollbackList-div").innerHTML = innerHTMLContext;

            jQuery('#rollbackList').select2({
                minimumResultsForSearch: -1
            });
        },
        error: function (e) {
            alert("该项目暂无备份,无法回滚");
        }
    });
}
function changeservers() {
    var operate = $("input[name='operate']:checked").val();
    if (operate == "Rollback") {
        getRollbackList();
    }
    if(operate == "Deploy"){
        branchdefault();
    }
}

function branchdefault() {
    var operate = $("input[name='operate']:checked").val();
    if (operate == "Deploy") {
        if(default_releaseWorkJob_branch!=null&&default_releaseWorkJob_branch.length>0){
            $("input[name='branch']").val(default_releaseWorkJob_branch);
            return;
        }
        var environment = $("input[name='environments']:checked").val();
        if(environment == "test"){
            $("input[name='branch']").val("test");
        } else if(environment == "dev"){
            $("input[name='branch']").val("dev");
        }else{
            if(environment==null||environment == "aws" || environment == "qcloud" || environment == "qcloud_gray"){
                $("input[name='branch']").val("master");
            }
        }
    }
}

function autotest(){
    var environment = $("input[name='environments']:checked").val();
    if("qcloud_gray" == environment){
        alert("灰度环境不支持测试用例执行");
        return;
    }
    var projects = new Array();
    $('input[name="project1"]:checked').each(function () {
        projects.push($(this).val());//向数组中添加元素
    });
    $('input[name="project2"]:checked').each(function () {
        projects.push($(this).val());//向数组中添加元素
    });
    $('input[name="project3"]:checked').each(function () {
        projects.push($(this).val());//向数组中添加元素
    });
    if (projects.length == 0) {
        alert("请选择项目");
        return;
    }
    var branch = $("input[name='branch']").val();
    if (branch == "") {
        alert("请填写分支名称");
        return;
    }

    $.ajax({
        url: 'aototest/autoTestService?models=' + projects + "&branch=" + branch,
        type: 'POST',
        dataType: 'json',
        success: function (data) {
            console.log(data);
            if(data.code != 200){
                alert(data.message);
            }else{
                var iWidth = 900;
                var iHeight = 600;
                var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的垂直位置;
                var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //获得窗口的水平位置;
                window.open("aototest/toAutoTestResult?id=" + data.data.taskname, "_blank", "height=" + iHeight + ", width=" + iWidth + ", top=" + iTop + ", left=" + iLeft);
            }
        },
        error: function (e) {
            alert("系统错误");
        }
    });

}

function getWorkids(){


}