<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
    <meta name="description" content=""/>
    <meta name="author" content=""/>
    <title>游戏列表</title>
    <link href="/static/css/styles.css" rel="stylesheet"/>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/js/all.min.js"
            crossorigin="anonymous"></script>
</head>
<style>
    .nav-item:hover .dropdown-menu {
        display: block;
    }
    #loadTasksButton {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
}

#loadTasksButton:hover {
    background-color: #0056b3;
}

#tasksTable {
    width: 100%;
    background-color: white;
    border-collapse: collapse;
    margin-top: 10px;
}

#tasksTable th, #tasksTable td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}

#tasksTable th {
    background-color: #007bff;
    color: white;
}

#tasksTable tr:nth-child(even) {
    background-color: #f2f2f2;
}

#tasksTable tr:hover {
    background-color: #ddd;
}

#tasksTable td button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 5px;
}

#tasksTable td button:hover {
    background-color: #0056b3;
}
</style>
<body class="sb-nav-fixed">
<nav class="sb-topnav navbar navbar-expand navbar-dark bg-dark">
    <a class="navbar-brand ps-3" href="index.html">游戏评分系统</a>
    <button class="btn btn-link btn-sm order-1 order-lg-0 me-4 me-lg-0" id="sidebarToggle" href="#!"><i
            class="fas fa-bars"></i></button>
    <form class="d-none d-md-inline-block form-inline ms-auto me-0 me-md-3 my-2 my-md-0">
    </form>
    <ul class="navbar-nav ms-auto ms-md-0 me-3 me-lg-4">
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" id="navbarDropdown" href="#" role="button" data-bs-toggle="dropdown"
               aria-expanded="false">
                <i class="fas fa-user fa-fw"></i>
                {{ email }}
            </a>
            <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
                <li><a class="dropdown-item" href="/login">退出登录</a></li>
            </ul>
        </li>
    </ul>
</nav>

<div id="layoutSidenav">
    <div id="layoutSidenav_nav">
        <nav class="sb-sidenav accordion sb-sidenav-dark" id="sidenavAccordion">
            <div class="sb-sidenav-menu">
                <div class="nav">
                    <div class="sb-sidenav-menu-heading">首页</div>
                    <a class="nav-link active" href="/home">
                        <div class="sb-nav-link-icon">
                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-display" viewBox="0 0 16 16">
                              <path d="M0 4s0-2 2-2h12s2 0 2 2v6s0 2-2 2h-4c0 .667.083 1.167.25 1.5H11a.5.5 0 0 1 0 1H5a.5.5 0 0 1 0-1h.75c.167-.333.25-.833.25-1.5H2s-2 0-2-2V4zm1.398-.855a.758.758 0 0 0-.254.302A1.46 1.46 0 0 0 1 4.01V10c0 .325.078.502.145.602.07.105.17.188.302.254a1.464 1.464 0 0 0 .538.143L2.01 11H14c.325 0 .502-.078.602-.145a.758.758 0 0 0 .254-.302 1.464 1.464 0 0 0 .143-.538L15 9.99V4c0-.325-.078-.502-.145-.602a.757.757 0 0 0-.302-.254A1.46 1.46 0 0 0 13.99 3H2c-.325 0-.502.078-.602.145z"/>
                            </svg>
                        </div>
                        首页
                    </a>
                    <a class="nav-link " href="/task_submit">
                        <div class="sb-nav-link-icon">
                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-upload" viewBox="0 0 16 16">
                                <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/>
                                <path d="M7.646 1.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 2.707V10.5a.5.5 0 0 1-1 0V2.707L5.354 4.854a.5.5 0 1 1-.708-.708l3-3z"/>
                            </svg>
                        </div>
                        评分上传
                    </a>
                    <a class="nav-link " href="/game_submit">
                        <div class="sb-nav-link-icon">
                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-upload" viewBox="0 0 16 16">
                                <path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z"/>
                                <path d="M7.646 1.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 2.707V10.5a.5.5 0 0 1-1 0V2.707L5.354 4.854a.5.5 0 1 1-.708-.708l3-3z"/>
                            </svg>
                        </div>
                        游戏上传
                    </a>
                    <a class="nav-link " href="/task_list">
                        <div class="sb-nav-link-icon">
                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
                                 class="bi bi-list" viewBox="0 0 16 16">
                                <path fill-rule="evenodd" d="M5 11.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5z"/>
                            </svg>
                        </div>
                        游戏列表
                    </a>
                    <a class="nav-link " href="/community_list">
                        <div class="sb-nav-link-icon">
                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
                                 class="bi bi-list" viewBox="0 0 16 16">
                                <path fill-rule="evenodd" d="M5 11.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5z"/>
                            </svg>
                        </div>
                        社区列表
                    </a>
                    <div class="collapse" id="collapsePages" aria-labelledby="headingTwo"
                         data-bs-parent="#sidenavAccordion">
                        <nav class="sb-sidenav-menu-nested nav accordion" id="sidenavAccordionPages">
                            <a class="nav-link collapsed" href="#" data-bs-toggle="collapse"
                               data-bs-target="#pagesCollapseAuth" aria-expanded="false"
                               aria-controls="pagesCollapseAuth">
                                Authentication
                                <div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
                            </a>
                            <div class="collapse" id="pagesCollapseAuth" aria-labelledby="headingOne"
                                 data-bs-parent="#sidenavAccordionPages">
                                <nav class="sb-sidenav-menu-nested nav">
                                    <a class="nav-link" href="login.html">Login</a>
                                    <a class="nav-link" href="register.html">Register</a>
                                    <a class="nav-link" href="password.html">Forgot Password</a>
                                </nav>
                            </div>
                            <a class="nav-link collapsed" href="#" data-bs-toggle="collapse"
                               data-bs-target="#pagesCollapseError" aria-expanded="false"
                               aria-controls="pagesCollapseError">
                                Error
                                <div class="sb-sidenav-collapse-arrow"><i class="fas fa-angle-down"></i></div>
                            </a>
                            <div class="collapse" id="pagesCollapseError" aria-labelledby="headingOne"
                                 data-bs-parent="#sidenavAccordionPages">
                                <nav class="sb-sidenav-menu-nested nav">
                                    <a class="nav-link" href="401.html">401 Page</a>
                                    <a class="nav-link" href="404.html">404 Page</a>
                                    <a class="nav-link" href="500.html">500 Page</a>
                                </nav>
                            </div>
                        </nav>
                    </div>
                </div>
            </div>
            <div class="sb-sidenav-footer">
                Game Ratings
            </div>
        </nav>
    </div>
    <div id="layoutSidenav_content">
        <main>
            <div class="card mb-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <div>
                        <i class="fas fa-chart-area me-1"></i>
                        社区列表
                    </div>
                    <div class="d-flex">
                        <input type="text" id="searchBox" class="form-control form-control-sm me-2" placeholder="搜索社区名" style="width: 200px;" required>
                        <button id="loadTasksButton" onclick="submitTask2()">查看列表详情</button>
                    </div>
                </div>
                <div class="card-body">
                    <div id="mainOne" style="width: 100%; height: 1000px;">
                        <table id="tasksTable" class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>社区编号</th>
                                <th>社区名</th>
                                <th>社区描述</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                        <!-- 分页控件 -->
                        <div id="pagination" style="margin-top: 10px;">
                            <button onclick="changePage(-1)">上一页</button>
                            <span id="currentPage">1</span>
                            <button onclick="changePage(1)">下一页</button>
                            <span>总页数: <span id="totalPages">0</span></span>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <footer class="py-4 bg-light mt-auto">
            <div class="container-fluid px-4">
                <div class="d-flex align-items-center justify-content-between small">
                    <div class="text-muted">Copyright &copy; 游戏评分管理平台 2024</div>
                </div>
            </div>
        </footer>
    </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
        crossorigin="anonymous"></script>
<script src="static/js/scripts.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script>
<script src="static/lib/echarts.js"></script>
<script src="static/assets/demo/chart-area-demo.js"></script>
<script src="static/assets/demo/chart-bar-demo.js"></script>
<script src="static/assets/demo/chart-pie-demo.js"></script>
<script>
    let currentPage = 1;
    let pageSize = 10; // 每页显示的条目数

    async function submitTask2() {
        currentPage = 1; // 重置为第一页
        loadTasks();
    }

    function changePage(increment) {
        currentPage += increment;
        loadTasks();
    }

    async function loadTasks() {
        const response = await fetch(`/load_history_communities?page=${currentPage}&size=${pageSize}`, {
            method: 'GET'
        });
        const data = await response.json();
        const communities = data.communities; // 获取社区数据
        renderTasks(communities); // 渲染当前页的社区
        updatePagination(data.totalPages); // 更新分页控件
    }

    function renderTasks(communities) {
        const tableBody = $('#tasksTable tbody');
        tableBody.empty(); // 清空表格

        let currentTaskId = 1;
        $.each(communities, function(i, community) {
            var row = $('<tr></tr>');
            row.append($('<td></td>').text(community.CommunityID));
            row.append($('<td></td>').text(community.CommunityName));
            row.append($('<td></td>').text(community.Description));
            row.append($('<td></td>').text(community.CreationDate));
            var btn = $('<button></button>').text('查看').click(function() {
                window.location.href = community.url;
            });
            row.append($('<td></td>').append(btn));
            tableBody.append(row);
        });
    }

    function updatePagination(totalPages) {
        const pagination = $('#pagination');
        pagination.empty(); // 清空分页控件

        // 渲染分页按钮
        for (let i = 1; i <= totalPages; i++) {
            const pageButton = $('<button></button>').text(i).click(function() {
                currentPage = parseInt($(this).text());
                loadTasks();
            });
            pagination.append(pageButton);
        }

        // 更新当前页码显示
        document.getElementById('currentPage').textContent = currentPage;
        document.getElementById('totalPages').textContent = totalPages;
    }

    // 在页面加载完成后加载社区数据
    document.addEventListener('DOMContentLoaded', loadTasks);
</script>
</body>
</html>
