<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ page import="com.eactive.eai.rms.common.login.SessionManager"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/jsp/common/include/localemessage.jsp" %>
<%@ page import="com.eactive.eai.common.util.SystemUtil"%>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Expires", "0");

	request.setCharacterEncoding("UTF-8");

%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<jsp:include page="/jsp/common/include/css.jsp"/>
<jsp:include page="/jsp/common/include/script.jsp"/>
<script language="javascript" >
var url			= '<c:url value="/onl/admin/rule/rollingSuffixMan.json"/>';
var url_view	= '<c:url value="/onl/admin/rule/rollingSuffixMan.view"/>';
var roleString	= "<%=SessionManager.getRoleIdString(request)%>";
var devSvr		= <%=SystemUtil.isDevServer()%>;
var svrInst = new Array();

function init (){
	$.ajax({
		type : "POST",
		url:url,
		dataType:"json",
		data:{cmd: 'FIND_CURRENT_COMMITID'},
		success:function(response){
			$('#currentCommitId').text(response.commitId);
		},
		error: function(xhr, status, error) {
		    console.log("Ajax Error: " + error);
		    console.log("Status: " + status);
		    console.log("Response Text: " + xhr.responseText);
		}
	});
}

function formatDate(jsonDate) {
    var date = new Date(
        jsonDate[0], 
        jsonDate[1] - 1, 
        jsonDate[2], 
        jsonDate[3], 
        jsonDate[4], 
        jsonDate[5], 
        Math.floor(jsonDate[6] / 1000000) // Convert nanoseconds to milliseconds
    );

    function pad(number, length) {
        return number.toString().padStart(length, '0');
    }

    var formattedDate = date.getFullYear() + '-' +
                        pad(date.getMonth() + 1, 2) + '-' +
                        pad(date.getDate(), 2) + ' ' +
                        pad(date.getHours(), 2) + ':' +
                        pad(date.getMinutes(), 2) + ':' +
                        pad(date.getSeconds(), 2) + ' ' +
                        pad(date.getMilliseconds(), 3);

    return formattedDate;
}

$(document).ready(function() {	
	init();
	
	var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로 
	$('#grid').jqGrid({
		datatype:"json",
		mtype: 'POST',
		url: url,
		postData : gridPostData,
		colNames:['ID',
                  'Commit ID',
                  '등록일시',
                  'Table Suffix'
                  ],
		colModel:[
				{ name : 'id', align:'left'	,sortable:false },
				{ name : 'commitId', align:'left' },
				{ name : 'createdDate', align:'left', formatter: formatDate },
				{ name : 'suffix', align: 'left' }
				],
        jsonReader: {
             repeatitems:false
        },	          
    	pager : $('#pager'),
		page : '${param.page}',
		rowNum : '${rmsDefaultRowNum}',
	    autoheight: true,
	    height: $("#container").height(),
		autowidth: true,
		viewrecords: true,
		rowList : eval('[${rmsDefaultRowList}]'),
		gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});	//그리드 헤더 화살표 삭제(정렬X)		
			}
        },
        loadError: function (jqXHR, textStatus, errorThrown) {
        	var location ='<%=request.getContextPath()%>/';
        	comloadError(jqXHR, textStatus, errorThrown ,location);
    	}		
	});
	
	resizeJqGridWidth('grid','content_middle','1000');
	
});

 
</script>
</head>
	<body>		
		<div class="right_box">
			<div class="content_top">
				<ul class="path">
					<li><a href="#">${rmsMenuPath}</a></li>					
				</ul>						
			</div><!-- end content_top -->
			<div class="content_middle" id="content_middle">
				<div class="title">버전관리 이력조회<span class="tooltip">버전관리 이력조회</span></div>
				<div style="font-size: 24px">Current CommitId : <span style="font-weight: bold;color:#d43f3a;" id="currentCommitId"></span></div>

				<table id="grid"></table>
				<div id="pager"></div>			
			</div><!-- end content_middle -->
		</div><!-- end right_box -->				
	</body>	
</html>

