<!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>
        <a th:href="@{/api/bak/config/app/export}"><i class="fa fa-download"></i></a>
    </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="getPageByEnv()"
                                    mo:dict="ENVIRONMENT" mo-selected="${env}"></select>
                        </div>
                    </div>
                    <div class="layui-inline timo-search-box">
                        <label class="layui-form-label">应用</label>
                        <div class="layui-input-block">
                            <input type="text" name="appName" th:value="${param.appName}" placeholder="请输入应用名"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn timo-search-btn">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>
                </div>
            </div>
            <div class="pull-right screen-btn-group">
                <div class="btn-group-right">
                    <button type="button" class="layui-btn upload-image" name="file[]"
                            th:attr="up-url=@{/api/bak/config/app/import}" up-field="path">
                        <i class="fa fa-upload"></i> 导入
                    </button>
                    <button class="layui-btn open-popup" data-title="添加应用" th:attr="data-url=@{/app/config/app/add}"
                            data-size="1200,500">
                        <i class="fa fa-plus"></i> 添加
                    </button>
                    <div class="btn-group">
                        <button class="layui-btn">批量操作<span class="caret"></span></button>
                        <dl class="layui-nav-child layui-anim layui-anim-upbit">
                            <dd><a class="ajax-status" th:href="@{/api/app/config/app/enable}">启用</a></dd>
                            <dd><a class="ajax-status" th:href="@{/api/app/config/app/disable}">禁用</a></dd>
                        </dl>
                    </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="appId">应用 ID</th>
                    <th class="sortable" data-field="repoBranch">分支</th>
                    <th class="sortable" data-field="appType">应用类型</th>
                    <th class="sortable" data-field="httpPort">HTTP 端口</th>
                    <th>部署配置</th>
                    <th>通知组</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${list}">
                    <td><label class="timo-checkbox"><input type="checkbox" th:value="${item.id}">
                        <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.runningConfig?.httpPort?: ''}">HTTP 端口</td>
                    <td>
                        <a class="open-popup" data-title="部署配置" th:attr="data-url=@{'/app/config/app/deploy/'+${item.id}}"
                           data-size="1200,500" href="#">设置</a>
                    </td>
                    <td>
                        <a class="open-popup" data-title="设置通知组" th:attr="data-url=@{'/app/config/app/notify/'+${item.id}}"
                           href="#">设置</a>
                    </td>
                    <td>
                        <a class="open-popup" data-title="拷贝" th:attr="data-url=@{'/app/config/app/copy/'+${item.id}}"
                           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>
                    </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 getPageByEnv() {
        var selectedOption = $("#getPageByEnv option:selected")
        var param = selectedOption.text()
        url = '?env=' + param
        window.location.href = window.location.pathname + url;
    }
</script>
</body>
</html>