<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>升级历史</title>
    <link rel="stylesheet" href="{{ asset('CmsProUi/component/pear/css/pear.css') }}">
    <link rel="stylesheet" href="{{ asset('CmsProUi/font-awesome/4.7.0/css/font-awesome.min.css') }}">
    <link rel="stylesheet" href="{{ asset('Admin/css/admin.css') }}">
    <link rel="stylesheet" href="{{ asset('Admin/css/variables.css') }}">
    <link rel="stylesheet" href="{{ asset('Admin/css/reset.css') }}">
</head>
<body>
<div class="pear-container">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="history-table" lay-filter="history-table"></table>
        </div>
    </div>
</div>

<script type="text/html" id="result-tpl">
@verbatim
{{# if(d.upgrade_result == 1){ }}
    <span class="layui-badge layui-bg-green">成功</span>
{{# } else { }}
    <span class="layui-badge">失败</span>
{{# } }}
@endverbatim
</script>

<script type="text/html" id="status-tpl">
@verbatim
{{# var isCurrent = d.LAY_TABLE_INDEX === 0; }}
{{# if(isCurrent){ }}
    <span class="layui-badge layui-bg-green">当前版本</span>
{{# } else { }}
    <span class="layui-badge layui-bg-gray">历史版本</span>
{{# } }}
@endverbatim
</script>

<script type="text/html" id="upgrade-type-tpl">
@verbatim
{{# if(d.upgrade_type === '手动升级'){ }}
    <span class="layui-badge layui-bg-blue">手动升级</span>
{{# } else if(d.upgrade_type === '自动升级'){ }}
    <span class="layui-badge layui-bg-green">自动升级</span>
{{# } else if(d.upgrade_type === '初始安装'){ }}
    <span class="layui-badge layui-bg-orange">初始安装</span>
{{# } else { }}
    <span class="layui-badge layui-bg-gray">{{ d.upgrade_type || '-' }}</span>
{{# } }}
@endverbatim
</script>

<script src="{{ asset('CmsProUi/component/layui/layui.js') }}"></script>
<script src="{{ asset('CmsProUi/component/pear/pear.js') }}"></script>
<script>
layui.use(['table', 'jquery', 'layer'], function(){
    var table = layui.table,
        $ = layui.jquery;

    $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' } });

    var cols = [[
        { title: 'ID', field: 'id', align: 'center', width: 70, sort: true },
        { title: '版本号', field: 'version', width: 100 },
        { title: '构建号', field: 'build', width: 100 },
        { title: '升级类型', field: 'upgrade_type', width: 100, templet: '#upgrade-type-tpl' },
        { title: '状态', field: 'status', align: 'center', width: 100, templet: '#status-tpl' },
        { title: '结果', field: 'upgrade_result', align: 'center', width: 80, templet: '#result-tpl' },
        { title: '操作人', field: 'operator', width: 100, templet: function(d) { return d.operator ? d.operator.username : '-'; } },
        { title: '更新日志', field: 'changelog', minWidth: 200 },
        { title: '错误信息', field: 'error_message', width: 200 },
        { title: '升级时间', field: 'create_time', width: 170 }
    ]];

    table.render({
        elem: '#history-table',
        url: '/admin/versionmgr/api/history',
        page: { layout: ['count','prev','page','next','limit'], groups: 5, limit: 15 },
        cols: cols,
        defaultToolbar: [{ title:'刷新', layEvent:'refresh', icon:'layui-icon-refresh' }],
        parseData: function(res) {
            return {
                code: res.code === 0 ? 0 : 1,
                msg: res.message || '',
                count: res.data && res.data.pagination ? res.data.pagination.total : 0,
                data: res.data ? res.data.items : []
            };
        }
    });
});
</script>
</body>
</html>
