<!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})"></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="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="machineIpv4" th:value="${param.machineIpv4}" 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 class="pull-right">
                    <div class="btn-group-right">
                        <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/machine/host/delete}">批量删除</a></dd>
                            </dl>
                        </div>
                    </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 data-field="machineIpv4">机器地址</th>
                    <th data-field="bootTime">启动时间</th>
                    <th data-field="status">当前状态</th>
                    <th data-field="osArch">系统架构</th>
                    <th data-field="osName">系统名字</th>
                    <th data-field="osVersion">系统版本</th>
                    <th data-field="agentVersion">Agent 版本</th>
                    <th>所属环境</th>
                    <th>SSH 认证</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${list}">
                    <td><label class="timo-checkbox"><input type="checkbox" th:value="${item.machineId}">
                        <i class="layui-icon layui-icon-ok"></i></label></td>
                    <td th:text="${item.machineIpv4}">机器地址</td>
                    <td th:text="${item.bootTime}">启动时间</td>
                    <td class="machine-status" th:text="${item.status}">当前状态</td>
                    <td th:text="${item.osArch}">系统架构</td>
                    <td th:text="${item.osName}">系统名字</td>
                    <td th:text="${item.osVersion}">系统版本</td>
                    <td th:text="${item.agentVersion}">Agent 版本</td>
                    <td>
                        <a class="open-popup" data-title="设置机器所属环境"
                           th:attr="data-url=@{'/machine/host/env/'+${item.machineId}}" href="#">设置</a>
                    </td>
                    <td>
                        <a class="open-popup" data-title="设置 SSH 帐号"
                           th:attr="data-url=@{'/machine/host/sshauth/'+${item.machineId}}" href="#">设置</a>
                    </td>
                    <td>
                        <!--<a class="open-popup" data-title="机器管理" th:attr="data-url=@{'/machine/stat'}"
                           data-size="max" href="#">管理</a>-->
                        <a class="open-popup" data-title="WebTerminal" th:attr="data-url=@{'/machine/host/webssh/'+${item.machineId}}"
                           data-size="max">SSH</a>
                        <a class="open-popup" data-title="机器详细信息" th:attr="data-url=@{'/machine/host/detail/'+${item.machineId}}"
                           data-size="960,480" href="#">详细</a>
                        <a class="ajax-delete" th:attr="data-msg='确定要删除 '+ ${item.machineId} + ' 机器?'"
                           th:href="@{'/api/machine/host/' + ${item.machineId}}">删除</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;
    }

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