<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<title>全网监控智能分析平台</title>
</head>
<body>
	<div id="sticky-wrap"></div>

	<div>
		<div class="container">
			<ol class="breadcrumb">
			<li><a href="${ctx}/index">首页</a></li>
			<li>预分析与建模</li>
			<li class="active">数据模型管理</li>
		</ol>
		</div>
	</div>

	<div id="main-container main-tab-container">
		<div id="content" class="container">
			<div class="tab-bar-bt">
				<ul class="nav nav-tabs">
					<li class="active"><a href="#home" data-toggle="tab">模型维护</a></li>
					<li><a href="${ctx}/BaseManage/TaskManage/modelMonitorHome">模型监控</a></li>
				</ul>
			</div>
			<div class="section">
				<div class="tab-content">

					<div class="tab-pane fade in active" id="home">
						<div class="row me-row">

							<div id="slidePushMenus2" class="cbp-spmenu-push">

								<div class="slideMenu" id="cbp-spmenu-s2" style="">
									<div class="form">
										<tags:ModelResultPeriodTag/>
										<tags:FXJM_modelResult_DataModelTypeTag/>
										<tags:FXJM_Status/>
										<tags:ModelDataType/>
										<tags:FXJM_TitleSearch/>
										<!-- <tags:FXJM_modelResult_DeployedServerTag/> -->
										<button id="submit" class="btn btn-primary" onclick="modelResultSubmit()">提交</button>
										<button id="disable" class="btn btn-warning"	onclick="modelResultReset()">重置</button>
									</div>
								</div>

								<div class="main col-xs-12">
									<div id="mainm2" class="mainm" ></div>

									<div class="content clearfix">
										<div class="block clearfix">
											<button id="showLeftPush2" class="menu-trigger btn btn-default" onclick="toggleMenu('slidePushMenus2')"> 
												<span class="glyphicon glyphicon-list"></span>
											</button>
											<div class="slide-menu-tags">
												<span id="PeriodTag" class="label label-info" data-placement="bottom" >最近一个月</span> 
												<span id="DataModelTag" class="label label-info" data-placement="bottom" ></span>
												<span id="DataModelTitleTag" class="label label-info" data-placement="bottom" ></span>
												<span id="DataModelStatusTag" class="label label-info" data-placement="bottom" ></span>
											</div>
											<div class="bt-list-import">
												<a href="#" id="uploadExcel" class=""> <span
													class="glyphicon glyphicon-import"></span> <span
													class="glyphicon-class">导出Excel</span> </a>
											</div>
										</div>

										<div class="row">
											<div class="col-xs-12">
												<div class="table-header">
												模型查询结果
											     <shiro:hasAnyRoles name="admin,dataAnalysis,businessAnalysis">
													<div id="time_div" style="top: -6px;float: right;height: 0px;position: relative;">
														<button class="btn-sm btn btn-info btn-sm btn-group btn-group-cog" id="ModelDownload" onclick="modelDownload()" disabled>模型下载</button>
														<button class="btn-sm btn btn-primary btn-sm btn-group btn-group-cog" id="updateModel" disabled>修改模型</button>
														<button class="btn-sm btn btn-primary btn-sm btn-group btn-group-cog" id="createModel">新建模型</button>
													</div>
												 </shiro:hasAnyRoles>	
												</div>
											     <table id="modelResultTable" class="table table-hover table-striped">
	                                            </table>
	                                      		<input type="hidden" id="dataModelView" name="dataModelView" value='${dataModelViewList}' />
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<form action="#" method="get" id="listForm"></form>
				</div>
			</div>
		</div>
	</div>
<script type="text/javascript" src="${ctx}/static/js/modelResultDetailTable.js"></script>
<script type="text/javascript">
	initDate();



	var receiveModelPageNum = "${modelPageNum}";
	modelResultDetailTable();
	if(receiveModelPageNum!=1){
		$("#goPageNo").attr("value",receiveModelPageNum);
		//document.getElementById("jumpButton").click();
		$("#jumpButton").click();
	}
	
	var receiveModelType = "${labelModelType}";
	var receiveGlobalModelType = "${globalModelType}";
	var receiveModelPeriod = "${labelModelPeriod}";
	var receiveModelTitle = "${labelModelTitle}";
	var receiveModelStatusId = "${labelModelStatusId}";
	var receiveKpiTypeId = "${labelKpiTypeId}";
	var judge = true;
	
	if(receiveModelPeriod!="" && receiveModelPeriod!=null){
		$("#PeriodTag").text("时间范围").attr('data-original-title',receiveModelPeriod).tooltip();
		$("#DataModelTag").text("数据模型类别").append($("<span class='badge'></span>").text(receiveModelType.split(" ").length)).attr('data-original-title',receiveModelType).tooltip();
		var modelStatusText = $("#modelStatus option[value="+receiveModelStatusId+"]").text();
		$("#DataModelStatusTag").text("模型状态").attr('data-original-title',modelStatusText).tooltip();
		var kpiTypeIdText = $("#kpiTypeId option[value="+receiveKpiTypeId+"]").text();
		$("#KpiTypeIdTag").text("数据类型").attr('data-original-title',kpiTypeIdText).tooltip();
	}
	if(receiveModelTitle!="" && receiveModelTitle!=null){
		$("#DataModelTitleTag").text("模型名称").attr('data-original-title', receiveModelTitle).tooltip();
	}
	
</script>

<script type="text/javascript">
	$("#createModel").click(function(){
			$.dialog({
				title: "提醒",
				content:"确定新建模型?",
				ok: function(){location.href="${ctx}/ModelManage/ModelMaintain";},
				okValue:"确定",
				cancel: function(){},
				cancelValue:"取消",
				lock:true
				}); 
	});

	function modelResultReset(){
		initDate();
		dataModelTypeReset();
		/* deployedServerReset(); */
		titleReset();
		judge=true;
	}
	
	function modelResultSubmit(){
		var modelPeriod = getPeriodStr();
		var modelType = getDateModelTypeStr();
		var modelStatusId = getModelStatusCheckedValue();
		//var deployedServer = getDeployedServerIdStr();
		var modelTitle = $.trim(getTitle());
		var kpiTypeId = getKpiTypeIdCheckedValue();
		receiveGlobalModelType = modelType;
		receiveModelPeriod = modelPeriod;
		receiveModelTitle = modelTitle;
		receiveModelStatusId = modelStatusId;
		receiveKpiTypeId = kpiTypeId;
		if(modelTitle!=""){
			$.ajax({
				    type : 'GET',
					contentType : 'application/json',
					url: "${ctx}/ModelManage/ModelResult/modelTableChange?modelTitle="+encodeURIComponent(modelTitle)+"&modelPeriod="+modelPeriod+"&modelType="+modelType+"&kpiTypeId="+kpiTypeId,/* +"&deployedServer="+deployedServer */
					dataType : 'text',
					async: false,
					beforeSend: function(data) { 
					},
					success: function(data) {
	                   $("#dataModelView").val(data);
	                   modelResultDetailTable();
	                   modelId="";
	                   $("#updateModel").attr("disabled", true);
                        $("#ModelDownload").attr("disabled", true);
					   toggleMenu('slidePushMenus2');//隐藏筛选项
				       updateTag(true);
					}
				});
		}else{
			if(modelPeriod==""){
			$.alert("时间选择不能为空");
		}else if(modelType==""){
			$.alert("模型类别选择不能为空");
		}/* else if(deployedServer==""){
			$.alert("部署服务器选择不能为空");
		} */else{
			$.ajax({
				    type : 'GET',
					contentType : 'application/json',
					url: "${ctx}/ModelManage/ModelResult/modelTableChange?modelPeriod="+modelPeriod+"&modelType="+modelType+"&modelTitle="+encodeURIComponent(modelTitle)+"&modelStatusId="+modelStatusId+"&kpiTypeId="+kpiTypeId,/* +"&deployedServer="+deployedServer */
					dataType : 'text',
					async: false,
					beforeSend: function(data) { 
					},
					success: function(data) {
	                   $("#dataModelView").val(data);
	                   modelResultDetailTable();
	                   modelId="";
	                   $("#updateModel").attr("disabled", true);
                        $("#ModelDownload").attr("disabled", true);
					   toggleMenu('slidePushMenus2');//隐藏筛选项
				       updateTag(true);
					}
				});
		}
		}
		
	}
	
	function updateTag(ifUpdate){
		if(ifUpdate){
			$("#PeriodTag").empty();
			$("#DataModelTag").empty();
			$("#DataModelTitleTag").empty();
			$("#DataModelStatusTag").empty();
			$("#KpiTypeIdTag").empty();
			if(judge == true){
                 $("#PeriodTag").text("最近一个月");
            }else{
				if(""==$.trim(getTitle())){
					$("#PeriodTag").text("时间范围").attr('data-original-title',getPeriodStr()).tooltip();
					$("#DataModelTag").text("数据模型类别").append($("<span class='badge'></span>").text(getDateModelTypeValues().length)).attr('data-original-title',getDataModelTypeTitleStr()).tooltip();
					$("#DataModelStatusTag").text("模型状态").attr('data-original-title',getModelStatusCheckedText()).tooltip();
					$("#KpiTypeIdTag").text("数据类型").attr('data-original-title',kpiTypeIdText()).tooltip();
				}else{
					$("#DataModelTitleTag").text("模型名称").attr('data-original-title', $.trim(getTitle())).tooltip();
				}
			//$("#DeployedServerTag").text("部署服务器").append($("<span class='badge'></span>").text(getDeployedServerValues().length)).attr('data-original-title',getDeployedServerTitleStr()).tooltip();
		  }	
		}
	}

    function modelDownload() {
        var url = "${ctx}/ModelManage/ModelMaintain/modelDownload";
        var form = $("<form></form>").attr("action", url).attr("method", "POST");
        form.append($("<input/>").attr("type", "hidden").attr("name", "modelId").attr("value", modelId));
        form.appendTo('body').submit().remove();
    }

	//更新按钮点击
	$("#updateModel").click(function(){
			var pageNum = $("#goPageNo").val();
			$.dialog({
				title: "提醒",
				content:"确定修改模型?",
				ok: function(){location.href="${ctx}/ModelManage/ModelParameterConfiguration?dataModelId="+modelId+"&modelPeriod="+receiveModelPeriod+"&modelType="+receiveGlobalModelType+"&modelStatusId="+receiveModelStatusId+"&modelTitle="+encodeURIComponent(receiveModelTitle)+"&modelPageNum="+pageNum;},
				okValue:"确定",
				cancel: function(){},
				cancelValue:"取消",
				lock:true
				}); 
		
		
	
		/* $.confirm("确定修改模型?",
		function(){location.href="${ctx}/ModelManage/ModelParameterConfiguration?dataModelId="+modelId;},
		function(){}); */
	});
	
	//查看参数
	function lookParm(dataModelId,dataModelTitle){
			$.dialog({
				title:"数据模型标题:"+dataModelTitle,
				/*content:"<div id='paramList'>"+
				"<div class='col-xs-12'><div class='panel panel-default'><div class='panel-heading'>参数列表</div><div class='panel-body'> <table class='table table-hover table-striped' width='500'> <thead class='col-md-12'> <tr class='row mx-0'> <th width='40%'>参数ID号</th> <th width='35%'>参数名</th><th width='35%'>参数编码</th> <th width='20%'>参数值</th> <th width='25%'>参数类型</th> </tr> </thead> <tbody> </tbody> </table> </div> </div> </div>"+
				"</div>",*/
                content:"<div id='paramList'>"+
                "<div class='col-xs-12'><div class='panel panel-default'><div class='panel-heading'>参数列表</div><div class='panel-body'> <table class='table table-striped text-center ' > <thead class='col-md-15'> <tr class='row mx-0'> <th class='col-3 text-center'>参数ID号</th> <th class='col-3 text-center'>参数名</th><th class='col-3 text-center'>参数编码</th> <th class='col-3 text-center'>参数值</th> <th class='col-3 text-center'>参数类型</th> </tr> </thead> <tbody class='col-md-15'> </tbody> </table> </div> </div> </div>"+
                "</div>",
				lock:true,
				width:700,
				initialize:function(){
					$.ajax({
						type : 'GET',
						contentType : 'application/json',
						url: "${ctx}/ModelManage/ModelResult/findParam?dataModelId="+dataModelId,
						dataType : 'text',
						beforeSend: function(data) { 
						},
						success: function(data){
							for(var i=0;i<data.length;i++){
			                      if(data[i]=='\"'){
			                         data=data.replace('\"','\'');
			                      }             
			                  }
							  data=eval("("+data+")");
							if(data!=null && data!=""){
								var paramTbody = $('#paramList tbody');
								for(var i=0;i<data.length;i++){
									if(data[i].parameterValue=="undefined" || data[i].parameterValue==null || data[i].parameterValue==""){
										data[i].parameterValue="";
									}
									paramTbody.append($("<tr class='row mx-0'></tr>").append("<td class='col-3'>"+data[i].parameterId+"</td>")
										                          .append("<td class='col-3'>"+data[i].parameterCode+"</td>")
											 					  .append("<td class='col-3'>"+data[i].parameterName+"</td>")
											 					  .append("<td class='col-3'>"+data[i].parameterValue+"</td>")
											 					  .append("<td class='col-3'>"+data[i].parameterDataType+"</td>"));
								}
							}
						}
						});
					}

			});
		}
		
		$("#uploadExcel").click(function(){
			var listForm=$("#listForm");
           	listForm.attr("method","post");
		   	listForm.attr("action","${ctx}/ModelManage/ModelResult/uploadModel");
		   	listForm.submit();
		   	listForm.attr("action","#");
		});
</script>
</body>
</html>