<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<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-body">
        <div class="timo-table-wrap">
            <table class="layui-table timo-table">
                <thead>
                <tr>
                    <th class="sortable" data-field="machineIpv4">机器地址</th>
                    <th class="sortable" data-field="packagePath">使用的包</th>
                    <th class="sortable" data-field="status">运行状态</th>
                    <th class="sortable" data-field="startTime">启动时间</th>
                    <th class="sortable" data-field="pid">PID</th>
                    <th class="sortable" data-field="lastCheck">上次检查</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${list}">
                    <td th:text="${item.machineIpv4}">机器地址</td>
                    <td th:text="${item.packagePath}">包路径</td>
                    <td class="app-status" th:text="${item.status}">运行状态</td>
                    <td th:text="${item.startTime}">启动时间</td>
                    <td th:text="${item.pid}">PID</td>
                    <td th:text="${item.lastCheck}">上次检查</td>
                    <td>
                        <a class="ajax-post" th:href="@{'/api/app/status/restart/'+${item.appId}+'/'+${item.machineId}}">重启</a>
                        <a class="ajax-post" th:href="@{'/api/app/status/stop/'+${item.appId}+'/'+${item.machineId}}">停止</a>
                        <a class="ajax-post" th:href="@{'/api/app/status/start/'+${item.appId}+'/'+${item.machineId}}">启动</a>
                        <a class="ajax-get" th:href="@{'/api/app/status/'+${item.appId}+'/'+${item.machineId}}">当前状态</a>
                    </td>
                </tr>
                </tbody>
            </table>
        </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">
    $(".app-status").each(function () {
        var text = $(this).text().trim()
        if (text === 'Online') {
            $(this).css("color", "#009688")
        } else {
            $(this).css("color", "#ff0000")
        }
    })
</script>
</body>
</html>