<!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="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">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block timo-search-status">
                        <select id="getPageByAppType" class="timo-search-select" name="type" onchange="getPageByCriteria()"
                                mo:dict="APP_TYPE" mo-selected="${type}"></select>
                    </div>
                </div>
            </div>
        </div>
        <div class="timo-table-wrap">
            <table class="layui-table timo-table">
                <thead>
                <tr>
                    <th class="sortable" data-field="appName">应用</th>
                    <th class="sortable" data-field="bindPorts">监听端口</th>
                    <th class="sortable" data-field="packagePath">包路径</th>
                    <th class="sortable" data-field="totalDeployed">部署数量</th>
                    <th>运行状态</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${list}">
                    <td>
                        <a class="open-popup" data-title="应用配置详情" data-size="1000,500" href="#"
                           th:text="${item.appName}" th:attr="data-url=@{'/app/config/app/detail/'+${item.appId}}"></a>
                    </td>
                    <td th:text="${item.bindPorts}">监听端口</td>
                    <td th:text="${item.packagePath}">部署数量</td>
                    <td style="color: red" th:text="${item.totalDeployed}">部署数量</td>
                    <td>
                        <a class="open-popup"
                           th:attr="data-title=${item.appName} + ' - 运行状态', data-url=@{'/app/stat/detail/'+${item.appId}}"
                           data-size="1200,500" href="#">查看
                        </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 = $("#getPageByAppType option:selected")
        var typeParam = typeSelectedOption.text()

        url = '?env=' + envParam + '&type=' + typeParam
        window.location.href = window.location.pathname + url;
    }

    function getPageByEnv() {
        var selectedOption = $("#getPageByEnv option:selected")
        var param = selectedOption.text()
        url = '?env=' + param
        window.location.href = window.location.pathname + url;
    }

    function getPageByAppType() {
        var selectedOption = $("#getPageByAppType option:selected")
        var param = selectedOption.text()
        url = '?appType=' + param
        window.location.href = window.location.pathname + url;
    }

    $(".app-status").each(function () {
        var text = $(this).text().trim()
        if (text === 'Online') {
            $(this).css("color", "#009688")
        } else {
            $(this).css("color", "#ff0000")
        }
    })
</script>
</body>
</html>