<!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" th:attr="data-url=@{'/app/build/list?env=' + ${env}}">
    <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="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="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">类型</th>
                    <th class="sortable" data-field="repoBranch">分支</th>
                    <th class="sortable" data-field="httpPort">HTTP 端口</th>
                    <th class="sortable" data-field="commitId">当前构建版本</th>
                    <th class="sortable" data-field="commitTime">提交时间</th>
                    <th class="sortable" data-field="result">构建结果</th>
                    <th class="sortable" data-field="buildTime">构建时间</th>
                    <!--<th class="sortable" data-field="packagePath">包路径</th>-->
                    <th class="sortable" data-field="buildBy">构建用户</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>
                        <a class="open-popup" data-title="应用配置详情" data-size="1200,500" href="#"
                           th:text="${item.appName}" th:attr="data-url=@{'/app/config/app/detail/'+${item.appId}}"></a>
                    </td>
                    <td th:text="${item.appType}">类型</td>
                    <td th:text="${item.repoBranch}">分支</td>
                    <td th:text="${item.httpPort}">HTTP 端口</td>
                    <td th:text="${item.commitId}">当前构建版本</td>
                    <td th:text="${item.commitTime}">提交时间</td>
                    <td>
                        <a class="open-popup build-result" data-title="构建结果" href="#"
                           th:text="${item.buildResult}" th:attr="data-url=@{'/app/log/build/'+${item.buildLogId} + '/result'}"></a>
                    </td>
                    <td th:text="${item.buildTime}">构建时间</td>
                    <!--<td th:text="${item.packagePath}">包路径</td>-->
                    <td th:text="${item.buildBy}">构建用户</td>
                    <td>
                        <a class="ajax-post" th:href="@{'/api/app/bd/update?appId='+${item.appId}}">更新</a>
                        <a class="ajax-post" th:href="@{'/api/app/bd/build?appId='+${item.appId}}">构建</a>
                        <a class="open-popup" data-title="应用部署" th:attr="data-url=@{'/app/deploy/'+${item.appId}}"
                           data-size="1000,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 getPageByEnv() {
        var selectedOption = $("#getPageByEnv option:selected")
        var param = selectedOption.text()
        url = '?env=' + param
        window.location.href = window.location.pathname + url;
    }

    $(".build-result").each(function () {
        var text = $(this).text().trim()
        if (text === '成功') {
            $(this).css("color", "#009688")
        } else {
            $(this).css("color", "#ff4500")
        }
    })
</script>
</body>
</html>