<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:mo="https://gitee.com/aun/Timo">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
    <link rel="stylesheet" th:href="@{/lib/zTree_v3/css/zTreeStyle/zTreeStyle.css}" type="text/css">
</head>

<body class="timo-layout-page">
<div class="layui-card">
    <div class="layui-card-header timo-card-header">
        <span><i class="fa fa-bars"></i> 证书列表</span>
        <i class="layui-icon layui-icon-refresh refresh-btn"></i>
    </div>
    <div class="layui-card-body">
        <div class="layui-row timo-card-screen put-row">
            <div class="layui-row timo-card-screen put-row">
                <div class="pull-left layui-form-pane">
                    <div class="layui-inline">
                        <label class="layui-form-label">环境</label>
                        <div class="layui-input-block timo-search-status">
                            <select id="getPageByEnv" class="timo-search-select" name="env" onchange="getPageByCriteria()"
                                    mo:dict="ENVIRONMENT" mo-selected="${env}"></select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn timo-search-btn">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>
                </div>
                <div class="pull-right">
                    <div class="btn-group-right">
                        <button class="layui-btn open-popup" data-title="添加域名" th:attr="data-url=@{/app/config/app/add}"
                                data-size="max">
                            <i class="fa fa-plus"></i> 添加
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <div class="timo-table-wrap">
            <table class="layui-table timo-table">
                <thead>
                <tr>
                    <th class="timo-table-checkbox">
                        <label class="timo-checkbox"><input type="checkbox">
                            <i class="layui-icon layui-icon-ok"></i></label>
                    </th>
                    <th class="sortable" data-field="appName">域名</th>
                    <th class="sortable" data-field="appType">证书 ID</th>
                    <th class="sortable" data-field="appId">证书状态</th>
                    <th class="sortable" data-field="repoBranch">过期时间</th>
                    <th class="sortable" data-field="bindPorts">监听端口</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${list}">
                    <td>
                        <label class="timo-checkbox">
                            <input type="checkbox" th:value="${item.appId}">
                            <i class="layui-icon layui-icon-ok"></i>
                        </label>
                    </td>
                    <td th:text="${item.appName}">应用名</td>
                    <td th:text="${item.appId}">应用 ID</td>
                    <td th:text="${item.repoBranch}">分支</td>
                    <td th:text="${item.appType}">应用类型</td>
                    <td th:text="${item.bindPorts?: ''}">监听端口</td>
                    <td>
                        <span style="color: red" th:text="${item.total}"></span>
                        <a class="open-popup" data-title="部署配置" th:attr="data-url=@{'/app/config/app/deploy/'+${item.appId}}"
                           data-size="max" href="#">配置</a>
                    </td>
                    <td>
                        <a class="open-popup" data-title="拷贝应用" th:attr="data-url=@{'/app/config/app/copy/'+${item.appId}}"
                           href="#">证书列表</a>
                        <a class="open-popup" data-title="应用详细信息" th:attr="data-url=@{'/app/config/app/detail/'+${item.appId}}"
                           data-size="1200,500" href="#">详细</a>
                        <a class="open-popup" data-title="编辑" th:attr="data-url=@{'/app/config/app/edit/'+${item.id}}"
                           data-size="1200,500" href="#">编辑</a>
                        <a class="ajax-delete" th:attr="data-msg='确定要删除 '+ ${item.appId}"
                           th:href="@{'/api/app/config/app/' + ${item.id}}">删除</a>
                        <a class="ajax-delete" th:attr="data-msg='确定要清空 ' + ${item.appId} + ' 的本地仓库'"
                           th:href="@{'/api/app/config/app/repo/' + ${item.id}}">清空本地仓库</a>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
        <div th:replace="/common/fragment :: page"></div>
    </div>
</div>

<script th:replace="/common/template :: script"></script>
<script type="text/javascript" th:src="@{/js/plugins/jquery-2.2.4.min.js}"></script>
<script type="text/javascript">
    function getPageByCriteria() {
        var envSelectedOption = $("#getPageByEnv option:selected")
        var envParam = envSelectedOption.text()

        var typeSelectedOption = $("#getPageByType option:selected")
        var typeParam = typeSelectedOption.text()

        url = '?env=' + envParam + '&type=' + typeParam
        window.location.href = window.location.pathname + url;
    }
</script>
</body>
</html>