<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模型版本</title>
	<link href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link href="../static/css/font-awesome.min.css" th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
    <link href="../static/css/animate.min.css" th:href="@{/css/animate.min.css}" rel="stylesheet"/>
    <link href="../static/css/style.css" th:href="@{/css/style.css}" rel="stylesheet"/>
    <style>
        .vertical-container {
            max-width: 1670px;
        }
    </style>
</head>
<body class="gray-bg">
<!--<div style="width:180px;position:fixed;top:10px;right:10px;z-index: 999" class="select-list" id="select-list">-->
<!--    <a class="btn btn-danger" onclick="closeItem()">-->
<!--        <i class="fa fa-reply-all"></i> 关闭-->
<!--    </a>-->
<!--</div>-->
    <div class="row animated fadeInRight">
        <div class="ibox float-e-margins">
            <div id="ibox-content">
                 <div id="vertical-timeline" class="vertical-container light-timeline">
                     <input type="hidden" id="projectId" name="projectId" th:value="${modelVersion.projectId}">
                     <div class="vertical-timeline-block" >
                         <div class="vertical-timeline-icon yellow-bg">
                             <i class="fa fa-times-circle"></i>
                         </div>
                         <div class="vertical-timeline-content">
                             <h2>[[${modelVersion.versionNo}]]</h2>
                             <p>[[${modelVersion.versionRemark}]]</p>
                             <a href="#" class="btn btn-sm btn-primary" name="scriptInfo" th:data-version="0">脚本详情 <i class="chevron fa fa-chevron-down"></i></a>
                             <span class="vertical-date">
                                 <small> [[${#dates.format(modelVersion.createTime, 'yyyy-MM-dd HH:mm:ss')}]]</small>
                             </span>
                         </div>
                         <div class="vertical-timeline-content ibox-content sqlscript" data-content="0" style="display:none;">
                             <div class="row text-right p-xxs">
                                 <a href="#" class="btn btn-sm btn-success m-t-n-xs" name="btnSaveVersion" onclick="buildNewVersion()"><i class="fa fa-floppy-o"></i> 保存新版本 </a>
                             </div>
                             <div class="row">
                                 <div class="col-sm-4">
                                     <div class="ibox float-e-margins">
                                         <div class="ibox-title">
                                             <h5>变化信息</h5>
                                         </div>
                                         <div class="ibox-content">
                                             <div class="form-group">
                                                 <div class="form-control-static"><pre name="changeContent">无</pre></div>
                                             </div>
                                         </div>
                                     </div>
                                 </div>
                                 <div class="col-sm-7">
                                     <div class="ibox float-e-margins">
                                         <div class="ibox-title">
                                             <h5>变化脚本</h5>
                                         </div>
                                         <div class="ibox-content">
                                             <div class="form-group">
                                                 <div class="form-control-static"><pre name="scriptContent">无</pre></div>
                                             </div>
                                         </div>
                                     </div>
                                 </div>
                             </div>
                         </div>
                     </div>
                     <div class="vertical-timeline-block" th:if="${versionList != null}" th:each="mv : ${versionList}">
                         <div class="vertical-timeline-icon navy-bg" th:if="${mv.syncFlag=='1'}">
                             <i class="fa fa-check-circle"></i>
                         </div>
                         <div class="vertical-timeline-icon yellow-bg" th:if="${mv.syncFlag !='1'}">
                             <i class="fa fa-times-circle"></i>
                         </div>
                         <div class="vertical-timeline-content">
                             <h2>[[${mv.versionNo}]]</h2>

                             <p>[[${mv.versionRemark}]]</p>
                             <a href="#" class="btn btn-sm btn-primary" name="scriptInfo" th:data-version="${mv.id}">脚本详情 <i class="chevron fa fa-chevron-down"></i></a>
                             <span class="vertical-date">
                                 <small> [[${#dates.format(mv.createTime, 'yyyy-MM-dd HH:mm:ss')}]]</small>
                             </span>
                         </div>
                         <div class="vertical-timeline-content ibox-content sqlscript" data-content="0" style="display:none;">
                             <div class="row text-right p-xxs">
                                 <a href="#" class="btn btn-sm btn-warning m-t-n-xs" name="btnSyncFlag" onclick="syncFlag()" th:data-version="${mv.id}" th:if="${mv.syncFlag !='1'}"><i class="fa fa-exchange"></i> 标记为同步 </a>
                             </div>
                             <div class="row">
                                 <div class="col-sm-4">
                                     <div class="ibox float-e-margins">
                                         <div class="ibox-title">
                                             <h5>变化信息</h5>
                                         </div>
                                         <div class="ibox-content">
                                             <div class="form-group">
                                                 <div class="form-control-static"><pre name="changeContent">无</pre></div>
                                             </div>
                                         </div>
                                     </div>
                                 </div>
                                 <div class="col-sm-7">
                                     <div class="ibox float-e-margins">
                                         <div class="ibox-title">
                                             <h5>变化脚本</h5>
                                         </div>
                                         <div class="ibox-content">
                                             <div class="form-group">
                                                 <div class="form-control-static"><pre name="scriptContent">无</pre></div>
                                             </div>
                                         </div>
                                     </div>
                                 </div>
                             </div>
                         </div>
                     </div>
                 </div>
             </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('model:modelVersion:edit')}]];
        var removeFlag = [[${@permission.hasPermi('model:modelVersion:remove')}]];

        var prefix = ctx + "model/modelVersion";

        $(document).ready(function(){

        });

        $("[name=scriptInfo]").click(function() {
            var div_ibox = $(this).closest("div.vertical-timeline-block"),
                i = $(this).find("i"),
                c = div_ibox.find(".sqlscript");
            var versionId = $(this).data("version");
            var flag = c.data("content");

            if(versionId <= 0 || (versionId > 0 && flag=="0")) {
                var url = prefix + '/getSqlScript';
                $.ajax({
                    type: "get",
                    url: url,
                    dataType: "json",
                    data: {
                        projectId: $("#projectId").val(),
                        id: versionId
                    },
                    success: function (data) {
                        console.log("flag=" + flag + " versionId="+versionId+" getSqlScript")
                        c.data("content", "1");
                        modelVersion = data.value;
                        // if(versionId <= 0 || modelVersion.syncFlag == "1") {
                        //     div_ibox.find('[name=btnSyncFlag]').hide();
                        // }
                        var changeContent = modelVersion.changeContent;
                        if ($.common.isEmpty(changeContent) || changeContent.length <= 0) {
                            div_ibox.find("[name=changeContent]").text("无");
                        } else {
                            if(modelVersion.parentVersionId == 0) {
                                div_ibox.find("[name=changeContent]").text("全量脚本");
                            } else {
                                div_ibox.find("[name=changeContent]").text(changeContent);
                            }
                        }
                        var scriptContent = modelVersion.scriptContent;
                        if ($.common.isEmpty(scriptContent) || scriptContent.length <= 0) {
                            div_ibox.find("[name=scriptContent]").text("无");
                            div_ibox.find("[name=btnSaveVersion]").hide();
                        } else {
                            div_ibox.find("[name=scriptContent]").text(scriptContent);
                            // if(versionId > 0) {
                            //     div_ibox.find("[name=btnSaveVersion]").hide();
                            // }
                        }
                        // $("#tasklist").html(data);
                    }
                });
            }
            c.slideToggle(),
                i.toggleClass("fa-chevron-down").toggleClass("fa-chevron-up"),
                div_ibox.toggleClass("").toggleClass("border-bottom"),
                setTimeout(function () {
                    div_ibox.resize();
                }, 50);
        });

        $("[name=btnSaveVersion]").click(function() {
            var projectId = $("#projectId").val();
            var url = prefix + '/add/' + projectId;
            $.modal.open("保存新版本", url);
        });

        $("[name=btnSyncFlag]").click(function() {
            var projectId = $("#projectId").val();
            var versionId = $(this).data("version");
            $.operate.post(prefix + "/setSyncFlag", { "id": versionId, "projectId":projectId, "syncFlag":"1"});

            var config = {
                url: prefix + "/setSyncFlag",
                type: "post",
                dataType: "json",
                data: {
                    "id": versionId,
                    "projectId":projectId,
                    "syncFlag":"1"
                },
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍候...");
                },
                success: function(result) {
                    // $.modal.msgSuccess(result.msg);
                    var parent = activeWindow();
                    $.modal.close();
                    parent.$.modal.msgSuccess(result.msg);
                    parent.location.reload();
                    $.modal.closeLoading();
                }
            };
            $.ajax(config)
        });
    </script>
</body>
</html>
