Authored by zhengyouwei

php build

... ... @@ -21,6 +21,8 @@ public class BuildRequest implements Serializable {
private String user;
private String host;
public String getTag() {
return tag;
}
... ... @@ -84,4 +86,12 @@ public class BuildRequest implements Serializable {
public void setUser(String user) {
this.user = user;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
}
... ...
package com.ui.ctrl;
import com.ui.http.HttpRestClient;
import com.ui.model.domain.BuildMessage;
import com.ui.model.req.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
import java.util.*;
/**
* Created by fruwei on 2016/6/16.
*/
@RestController
@RequestMapping("phpBuild")
public class PhpBuildCtrl {
Logger log = LoggerFactory.getLogger(PhpBuildCtrl.class);
@Autowired
private HttpRestClient httpRestClient;
//private String URL = "http://172.31.16.167:8883/php/";
private String URL = "http://127.0.0.1:8883/php/";
@RequestMapping("/toProject")
public ModelAndView toProject(Model model) {
return new ModelAndView("project/php_project");
}
/**
* 获取所有项目
*
* @return
*/
@RequestMapping(value = "getProjects", method = RequestMethod.POST)
@ResponseBody
public String getProjects() {
try {
return httpRestClient.get(URL + "getProjects", String.class, null);
} catch (Exception ex) {
return "failed";
}
}
/**
* 获取所有项目
*
* @return
*/
@RequestMapping(value = "getProject", method = RequestMethod.POST)
@ResponseBody
public String getProjects(String name) {
try {
return httpRestClient.get(URL + "getProject?name="+name , String.class, null);
} catch (Exception ex) {
return "failed";
}
}
/**
* 执行任务
*
* @return
*/
@RequestMapping(value = "build", method = RequestMethod.POST)
public ModelAndView build(String project_name, String environment_name, String operate_name, String branch_name, String rollbackfile_name,String hosts_name, Model model, HttpSession session) {
try {
User user = (User) session.getAttribute("user");
List<BuildMessage> list = new ArrayList<>();
BuildRequest buildRequest = new BuildRequest();
buildRequest.setBranch(branch_name);
buildRequest.setUser(user.getName());
buildRequest.setEnvironment(environment_name);
buildRequest.setRollbackfile(rollbackfile_name);
buildRequest.setOperate(operate_name);
buildRequest.setHost(hosts_name);
String messageids = "";
if ("Deploy".equals(operate_name)) {
String[] array = project_name.split(",");
if (array.length > 4) {
String[] newArray = new String[]{"", "", "", ""};
for (int i = 0; i < array.length; i++) {
newArray[i % 4] = newArray[i % 4] + array[i] + ",";
}
for (String project : newArray) {
buildRequest.setProject(project.substring(0, project.length() - 1));
BuildMessage buildMessage = httpRestClient.post(URL + "build", buildRequest, BuildMessage.class);
if (buildMessage != null) {
list.add(buildMessage);
messageids = messageids + buildMessage.getId() + ",";
}
}
} else {
for (String project : array) {
buildRequest.setProject(project);
BuildMessage buildMessage = httpRestClient.post(URL + "build", buildRequest, BuildMessage.class);
if (buildMessage != null) {
list.add(buildMessage);
messageids = messageids + buildMessage.getId() + ",";
}
}
}
} else {
buildRequest.setProject(project_name);
BuildMessage buildMessage = httpRestClient.post(URL + "build", buildRequest, BuildMessage.class);
if (buildMessage != null) {
list.add(buildMessage);
messageids = messageids + buildMessage.getId() + ",";
}
}
model.addAttribute("environment_name", environment_name);
model.addAttribute("operate_name", operate_name);
model.addAttribute("branch_name", branch_name);
model.addAttribute("rollbackfile_name", rollbackfile_name);
model.addAttribute("messageids", messageids);
model.addAttribute("messageList", list);
model.addAttribute("hosts_name", hosts_name);
} catch (Exception ex) {
}
return new ModelAndView("project/php_project_build");
}
/**
* 获取执行结果
*
* @param messageid
* @return
*/
@RequestMapping(value = "getbuildmsg", method = RequestMethod.POST)
@ResponseBody
public String getbuildmsg(String messageid, String project) {
try {
Map<String, String> map = new HashMap<>();
map.put("messageid", messageid);
map.put("project", project);
return httpRestClient.get(URL + "getbuildmsg", String.class, map);
} catch (Exception ex) {
return "failed";
}
}
@RequestMapping(value = "cancelBuild")
@ResponseBody
public String cancelBuild(String id) {
try {
Map<String, String> map = new HashMap<>();
map.put("id", id);
return httpRestClient.get(URL + "cancelBuild", String.class, map);
} catch (Exception ex) {
return "failed";
}
}
@RequestMapping(value = "rollbackList", method = RequestMethod.POST)
@ResponseBody
public String rollbackList(String project, String environment) {
try {
Map<String, String> map = new HashMap<>();
map.put("project", project);
map.put("environment", environment);
return httpRestClient.get(URL + "rollbackList", String.class, map);
} catch (Exception ex) {
return "failed";
}
}
}
... ...
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目发布</title>
<link rel="stylesheet" href="<%=basePath %>css/unicorn.main.css"/>
<link rel="stylesheet" href="<%=basePath %>css/unicorn.grey.css"/>
<link rel="stylesheet" href="<%=basePath %>css/bootstrap.min.css"/>
<link href="<%=basePath%>css/style.default.css" rel="stylesheet">
<link href="<%=basePath%>css/morris.css" rel="stylesheet">
<link href="<%=basePath%>css/select2.css" rel="stylesheet"/>
</head>
<body style="background-color: #444444;font-size: 14px">
<!-- 头部 -->
<div id="head">
</div>
<div id="content">
<div id="breadcrumb">
<a href="#" title="Go to Home" class="tip-bottom"><i
class="icon-home"></i> Home</a> <a href="#" class="current">项目发布</a>
</div>
<div>
<!-- query panel -->
<form class="form-bordered">
<div class="form-group">
<label class="col-sm-1 control-label">操作选择</label>
<div class="col-sm-8" style="display: inline">
<div class="rdio rdio-default">
<input type="radio" name="operate" id="operatedeploy" value="Deploy" checked="checked"
onclick="operateChange()"/>
<label for="operatedeploy">发布
</label>
</div>
<div class="rdio rdio-default" >
<input type="radio" name="operate" value="Rollback" id="operateback" onclick="operateChange()"/>
<label for="operateback">回滚</label>
</div>
</div>
<div id="autotest-div">
<input type="button" class="btn btn-primary" id="autotest-button" onclick="autotest()" value="执行自动测试用例" </input>
</div>
</div>
<div class="form-group">
<label class="col-sm-1 control-label">项目选择</label>
<div class="col-sm-8" id="project-div">
</div>
</div>
<div class="form-group">
<label class="col-sm-1 control-label">发布环境</label>
<div class="col-sm-8" id="select-environment-div">
</div>
</div>
<div class="form-group" id="branch-div">
<label class="col-sm-1 control-label">Branch输入</label>
<div class="col-sm-8">
<input name="branch" type="text" class="form-control"
style="width: 300px"/>
</div>
</div>
<div class="form-group" id="rollback-div" style="display: none">
<label class="col-sm-1 control-label">回滚版本选择</label>
<div class="col-sm-8" id="select-rollbackList-div">
</div>
</div>
<div class="form-group">
<label class="col-sm-1 control-label">确认操作</label>
<div class="col-sm-8">
<button type="button" id="submit-btn" onclick="comfirmSubmit()" class="btn btn-primary">提交</button>
</div>
</div>
</form>
</div>
</div>
<!-- 初始化确认页面 -->
<div class="modal fade" id="confirmSubmitDivId" tabindex="-1" role="dialog" aria-labelledby="confirmSubmitLabel"
aria-hidden="true" style="padding-top: 10%">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h2 class="modal-title" id="confirmSubmitLabel">
<span style="font-weight: bold;"> 确认提交</span>
</h2>
</div>
<div class="modal-body">
<form class="bs-example bs-example-form" action="<%=basePath %>phpBuild/build" role="form"
id="GitBranchCreateForm" method="post">
<div class="input-group">
<span class="input-group-addon">操作类型</span>
<input type="text" name="operate_name" class="form-control" readonly="readonly">
</div>
<br>
<div class="input-group">
<span class="input-group-addon">发布环境</span>
<input type="text" name="environment_name" class="form-control" readonly="readonly">
</div>
<br>
<div class="input-group">
<span class="input-group-addon">工程名称</span>
<input type="text" name="project_name" class="form-control" readonly="readonly">
</div>
<br>
<div class="input-group">
<span class="input-group-addon">主机地址</span>
<input type="text" name="hosts_name" class="form-control" readonly="readonly">
</div>
<br>
<div class="input-group">
<span class="input-group-addon">分支名称</span>
<input type="text" name="branch_name" class="form-control" readonly="readonly">
</div>
<br>
<div class="input-group">
<span class="input-group-addon">回滚文件</span>
<input type="text" name="rollbackfile_name" class="form-control" readonly="readonly">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">确认</button>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
<script src="<%=basePath%>js/jquery-2.1.4.min.js"></script>
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<script src="<%=basePath%>js/select2.min.js"></script>
<script src="<%=basePath%>js/custom.js"></script>
<script src="<%=basePath%>script/build/php_project.js"></script>
<script src="<%=basePath %>/js/unicorn.js"></script>
<script src="<%=basePath %>script/common/genarate_left_panel.js"></script>
<script type="text/javascript">
$("#li_project").addClass("active open");
$("#li_phpRelease").addClass("active");
</script>
</html>
... ...
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=basePath %>css/bootstrap.min.css"/>
<link rel="stylesheet" href="<%=basePath %>css/bootstrap-datetimepicker.css"/>
<link href="<%=basePath %>js/bootstrap-plugin/css/bootstrap.table.css" rel="stylesheet" media="screen"/>
<link rel="stylesheet" href="<%=basePath %>css/bootstrap-responsive.min.css"/>
<link rel="stylesheet" href="<%=basePath %>css/fullcalendar.css"/>
<link rel="stylesheet" href="<%=basePath %>css/unicorn.main.css"/>
<link rel="stylesheet" href="<%=basePath %>css/unicorn.grey.css"/>
<link rel="stylesheet" href="<%=basePath %>css/jquery-ui.css"/>
<link rel="stylesheet" href="<%=basePath %>css/uniform.css"/>
<link rel="stylesheet" href="<%=basePath %>css/select2.css"/>
<link rel="stylesheet" href="<%=basePath %>js/jstree/themes/proton/style.css"/>
<link rel="stylesheet" href="<%=basePath %>css/select2.css"/>
<link rel="stylesheet" href="<%=basePath %>css/yoho.css"/>
<script src="<%=basePath %>js/excanvas.min.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jquery-1.12.0.min.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jquery-ui.custom.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>/js/bootstrap.min.js"></script>
<script src="<%=basePath %>/js/unicorn.js"></script>
<script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/moment-with-locales.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/global.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.pagination.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.table.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.dialog.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.panel.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.alerts.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.accordion.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.breadcrumb.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.validate.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/layer/layer.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.select.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jstree/jstree.min.js"></script>
<script src="<%=basePath %>js/jquery.toaster.js"></script>
<script>
var contextPath = '<%=basePath %>';
</script>
<title>YOHO!运维</title>
</head>
<body>
<!-- 头部 -->
<div id="head">
</div>
<!-- 右侧具体内容 -->
<div id="content">
<div id="breadcrumb">
<a href="#" title="Go to Home" class="tip-bottom"><i
class="icon-home"></i> Home</a> <a href="#" class="current">发布进程</a>
</div>
<div class="container-fluid">
<div class="widget-box">
<div class="widget-title">
<h5>发布进程信息</h5>
</div>
<div class="widget-content nopadding">
<div class="widget-title" style="height: 53px;">
<div>
<div class="form-inline" role="form" id="inBoxQueryDiv"
style=" margin-top: 12px;margin-left: 25px;float: left;">
<div class="input-group" style="float: left;">
<span class="input-group-addon">操作:</span>
<input type="text" id="operate_name" name="operate_name" class="form-control"
readonly="readonly" value="${operate_name}"/>
</div>
<div class="input-group" style="float: left;">
<span class="input-group-addon">环境:</span>
<input type="text" id="environment_name" name="environment_name" class="form-control"
readonly="readonly" value="${environment_name}"/>
</div>
<div class="input-group" style="float: left;">
<span class="input-group-addon">分支:</span>
<input type="text" id="branch_name" name="branch_name" class="form-control"
readonly="readonly" value="${branch_name}"/>
</div>
<div class="input-group" style="float: left;">
<span class="input-group-addon">主机:</span>
<input type="text" id="hosts_name" name="hosts_name" class="form-control"
readonly="readonly" value="${hosts_name}"/>
</div>
<div class="input-group" style="float: left;">
<span class="input-group-addon">回滚:</span>
<input type="text" id="rollbackfile_name" name="rollbackfile_name" class="form-control"
readonly="readonly" value="${rollbackfile_name}"/>
</div>
</div>
</div>
</div>
<c:forEach items="${messageList }" var="message">
<div style="float: left;height: 600px;">
<hr>
<div>执行顺序:<strong>${message.projectOrder}</strong>
</div>
<div>当前项目:<input type="text" id="currentProject_${message.id}" value="${message.currentProject}" readonly="readonly">
<button type="button" id="cancel-btn_${message.id}" onclick="cancelBuild('${message.id}')"
class="btn btn-xs btn-danger">取消
</button>
</div>
<div style="height: 50px" class="alert alert-warning" id="task-info-div_${message.id}">
</div>
<textarea id="resultArea_${message.id}" rows="25" cols="100"
style="background-color: black; color: white" readonly="readonly"></textarea>
</div>
</c:forEach>
</div>
</div>
</div>
</div>
<input type="hidden" id="messageListHidden" value="${messageids}">
</body>
<script src="<%=basePath %>script/common/genarate_left_panel.js"></script>
<script>
$("#li_project").addClass("active open");
$("#li_phpRelease").addClass("active");
</script>
<script>
var myArray;
var removeArray = new Array();
$(function () {
var messageListHidden = $("#messageListHidden").val();
myArray = messageListHidden.split(",");
var interval = setInterval(function () {//查后台,展示数据
$.each(myArray, function (idx, val) {
if(jQuery.inArray(val, removeArray) != -1){
return;
}
if(val == ""){
return;
}
var cproject = $("#currentProject_"+val).val();
$.ajax({
url: contextPath + 'phpBuild/getbuildmsg?messageid=' + val+"&project="+cproject,
type: 'POST',
dataType: 'json',
success: function (data3) {
var obj2 = eval("(" + data3 + ")");
var messagedata = obj2.data;
var currproject = messagedata.currentProject;
if (currproject != cproject) {
$("#currentProject_"+val).val(currproject);//更换当前的项目
$("#resultArea_" + val).val("")
}
if (messagedata.message != "") {
var d = $("#resultArea_" + val).val();
$("#resultArea_"+ val).val(d + messagedata.message);
var scrollTop = $("#resultArea_" + val)[0].scrollHeight;
$("#resultArea_" + val).scrollTop(scrollTop);
}
//code为2 ,则结束
var code = obj2.code;
var message = obj2.message;
if (code == 2) {
document.getElementById("task-info-div_" + val).innerHTML = "<strong>'" + message + "'</strong>";
removeArray.push(val);
$("#cancel-btn_"+val).hide();
}
},
error: function (e) {
}
});
});
}, 3000);
});
/**
* 取消
*/
function cancelBuild(messageid) {
var jsondata = {"id": messageid};
$.ajax({
url: contextPath + 'project/cancelBuild',
type: 'POST',
dataType: 'json',
data: jsondata,
success: function (data) {
},
error: function (e) {
}
});
}
</script>
<script>
document.onkeydown = function()
{
if(event.keyCode==116 || event.keyCode==8 || (event.ctrlKey && event.keyCode==82) || event.keyCode == 13) {
event.keyCode=0;
event.returnValue = false;
}
}
document.oncontextmenu = function() {event.returnValue = false;}
</script>
\ No newline at end of file
... ...
... ... @@ -161,7 +161,7 @@
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<script src="<%=basePath%>js/select2.min.js"></script>
<script src="<%=basePath%>js/custom.js"></script>
<script src="<%=basePath%>script/project.js"></script>
<script src="<%=basePath%>script/build/project.js"></script>
<script src="<%=basePath %>/js/unicorn.js"></script>
<script src="<%=basePath %>script/common/genarate_left_panel.js"></script>
<script type="text/javascript">
... ...
var ENV;
jQuery(document).ready(function () {
getProjects();
});
/**
* 操作变更
*/
function operateChange() {
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";
getRollbackList();
} else {
//展示Branch输入框
document.getElementById("branch-div").style.display = "";
//隐藏 回滚选择框
document.getElementById("rollback-div").style.display = "none";
//展示自动执行测试用例
document.getElementById("autotest-div").style.display = "";
branchdefault();
}
}
/**
* 根据操作获取当前的项目列表
*/
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 + ")");
var order1HTML = "";
var order2HTML = "";
var order1num = 1;
var order2num = 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'>";
order1HTML += " <input name='project' type='radio' id='" + name + "' value='" + name + "' onclick='changeProject()' checked='checked'/>";
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='changeProject()'/>";
order2HTML += "<label for='" + name + "' style='width: 200px'>" + name + "</label></div>";
if (order2num % 4 == 0) {
order2HTML += "</br>";
}
order2num += 1;
}
document.getElementById("project-div").innerHTML = order1HTML + "<hr>" + order2HTML + "<hr>";
changeProject();
}
},
error: function (e) {
alert("从后台获取数据出错");
}
});
}
//确认提交
function comfirmSubmit() {
var operate = $("input[name='operate']:checked").val();
var environment = $("input[name='environments']:checked").val();
var project = $("input[name='project']:checked").val();
if (!project) {
alert("请选择项目");
return;
}
var hosts = new Array();
$("input[name=\""+environment+"-checkbox\"]:checked").each(function () {
hosts.push($(this).val());//向数组中添加元素
});
$("input[name='operate_name']").val(operate);
$("input[name='project_name']").val(project);
$("input[name='environment_name']").val(environment);
$("input[name='hosts_name']").val(hosts);
if ("Deploy" == operate) {//发布
var branch = $("input[name='branch']").val();
if (branch == "") {
alert("请填写分支名称");
return;
}
$("input[name='branch_name']").val(branch);
$('#confirmSubmitDivId').modal('show');
} else {//回滚
var rollbackfile = $("#rollbackList option:selected").val();
if (typeof(rollbackfile) == "undefined" || rollbackfile == "") {
alert("请选择回滚版本");
return;
}
$("input[name='rollbackfile_name']").val(rollbackfile);
$('#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 changeProject(){
var operate = $("input[name='operate']:checked").val();
var project = $("input[name='project']:checked").val();
$.ajax({
url: 'getProject?name=' + project,
type: 'POST',
dataType: 'json',
success: function (data) {
$("#select-environment-div").empty();
if ("failed" == data) {
return;
}
var pythonProject = eval("(" + data + ")");
//动态生成环境的组件
var list = pythonProject.envs;
ENV = list;
for(var i = 0; i < list.length; i++){
var env = list[i];
var div = $("<div>").addClass("rdio rdio-default");
var redio = $("<input>");
redio.attr("type","radio");
redio.attr("name","environments");
redio.attr("id",env.name);
redio.attr("value",env.name);
redio.attr("onclick","changeservers()");
redio.attr("checked","checked");
var label = $("<label for=\""+env.name+"\">"+env.name+"</label>");
var checkBoxDiv = $("<div>").attr("id",env.name+"-div").attr("display","display");
var hosts = env.host_ips;
for(var j = 0; j < hosts.length; j++){
var host = hosts[i];
checkBoxDiv.append("<input type=\"checkbox\" value=\""+host+"\" name=\""+env.name +"-checkbox\" checked=\"checked\">"+host+"");
}
div.append(redio).append(label).append(checkBoxDiv);
$("#select-environment-div").append(div);
}
changeservers();
},
error: function (e) {
alert("获取项目失败环境失败");
}
});
}
function changeservers() {
var environment = $("input[name='environments']:checked").val();
for(var i = 0; i < ENV.length; i++){
$("#"+ENV[i].name+"-div").hide();
}
$("#"+environment+"-div").show();
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") {
$("input[name='branch']").val("master");
}
}
... ...
... ... @@ -66,9 +66,9 @@ innerHTML += "</ul></li>";
/*project*/
innerHTML += "<li class='submenu' id='li_project'><a id='li_project_a' href='#'><i class='icon icon-th-list'></i> <span>项目发布</span><span class='label'>5</span></a><ul>";
innerHTML += "<li id='li_projectRelease'><a id='li_projectRelease_a' href=''><i class='icon icon-th'></i> <span>项目发布</span></a></li>";
innerHTML += "<li id='li_projectRelease'><a id='li_projectRelease_a' href=''><i class='icon icon-th'></i> <span>JAVA发布</span></a></li>";
innerHTML += "<li id='li_phpRelease'><a id='li_phpRelease_a' href=''><i class='icon icon-th'></i> <span>PHP发布</span></a></li>";
innerHTML += "<li id='li_om'><a id='li_om_a' href=''><i class='icon icon-th'></i> <span>OM发布</span></a></li>";
/*innerHTML += "<li id='li_om_new'><a id='li_om_new_a' href=''><i class='icon icon-th'></i> <span>OM_New发布</span></a></li>";*/
innerHTML += "<li id='li_node'><a id='li_node_a' href=''><i class='icon icon-th'></i> <span>NODE发布</span></a></li>";
innerHTML += "<li id='li_projectHistory'><a id='li_projectHistory_a' href=''><i class='icon icon-th'></i> <span>历史记录</span></a></li>";
innerHTML += "</ul></li>";
... ... @@ -111,6 +111,7 @@ document.getElementById("li_rabbitview_a").setAttribute("href", path + "/rabbitm
/*document.getElementById("li_redisInfo_a").setAttribute("href", path + "/redisInfo/toRedisInfo");
document.getElementById("li_nginxview_a").setAttribute("href", path + "/nginx/toNginxView");*/
document.getElementById("li_projectRelease_a").setAttribute("href", path + "/project/toProject");
document.getElementById("li_phpRelease_a").setAttribute("href", path + "/phpBuild/toProject");
document.getElementById("logout_a").setAttribute("href", path + "/user/logout");
document.getElementById("changepwd_a").setAttribute("href", path + "/user/toupdatePwd");
document.getElementById("li_sms_a").setAttribute("href", path + "/sms/toSmsLog");
... ...