<!DOCTYPE html>
<html>
<head>
    {% load static %}
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Archery-SQL审核查询平台</title>
    <link rel="shortcut icon" href="{% static 'img/favicon.ico' %}"/>

    <!-- 引入 Bootstrap -->
    <link href="{% static 'bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
    <link href="{% static 'metisMenu/css/metisMenu.min.css' %}" rel="stylesheet">
    <link href="{% static 'sb-admin-2/css/sb-admin-2.css' %}" rel="stylesheet">
    <link href="{% static 'font-awesome/css/font-awesome.min.css' %}" rel="stylesheet">
    <link href="{% static 'bootstrap-select/css/bootstrap-select.min.css' %}" rel="stylesheet">
    <link href="{% static 'bootstrap-table/css/bootstrap-table.min.css' %}" rel="stylesheet">
    <style type="text/css">
    table{
        max-width: none !important;      /*解决 ios 横向滚动失效*/
    }
    </style>
    <!-- django i18n -->
    <script type="text/javascript" src="{% url 'sql:javascript-catalog' %}"></script>
</head>
<body>

<div id="wrapper">

    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/index/"><strong>Archery</strong></a>
        </div>

        <!-- /.navbar-header -->
        <ul class="nav navbar-top-links navbar-right">
            <li>
                <a>你好，{{ user }}</a>
            </li>
            {% if todo > 0 %}
                <li>
                    <a href="/workflow/">
                        <span class="fa fa-bell ">{{ todo }}</span>
                    </a>
                </li>
            {% else %}
                <li>
                    <a href="/workflow/">
                        <span class="fa fa-bell "></span>
                    </a>
                </li>
            {% endif %}
            <!-- /.dropdown -->
            <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                    <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
                </a>
                <ul class="dropdown-menu dropdown-user">
                    {% if user.is_superuser %}
                        <li>
                            <a target="_blank" href="/api/debug"><i class="fa fa-info fa-fw"></i> 系统信息</a>
                        </li>
                        <li>
                            <a target="_blank" href="/admin"><i class="fa fa-sitemap fa-fw"></i> 管理后台</a>
                        </li>
                    {% endif %}
                    <li><a href="/admin/password_change/"><i class="fa fa-user fa-fw"></i> 修改密码</a></li>
                    <li><a href="/logout/"><i class="fa fa-gear fa-fw"></i> 退出</a></li>
                </ul>
                <!-- /.dropdown-user -->
            </li>
            <!-- /.dropdown -->
            <li>
                <a href="https://github.com/hhyo/Archery" target="_blank">
                    <i class="fa fa-github fa-lg" aria-hidden="true"></i>
                </a>
            </li>
        </ul>
        <!-- /.navbar-top-links -->

        <div class="navbar-default sidebar" role="navigation">
            <div class="sidebar-nav navbar-collapse">
                <ul class="nav" id="side-menu">
                    {% if perms.sql.menu_dashboard %}
                        <li>
                            <a href="/dashboard/"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>
                        </li>
                    {% endif %}
                    {% if perms.sql.menu_sqlcheck %}
                        <li>
                            <a href="#"><i class="fa fa-check fa-fw"></i> SQL审核<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                {% if perms.sql.menu_sqlworkflow %}
                                    <li>
                                        <a href="/sqlworkflow/">SQL上线</a>
                                    </li>
                                {% endif %}
                                {% if perms.sql.menu_sqlanalyze %}
                                    <li>
                                        <a href="/sqlanalyze/">SQL分析</a>
                                    </li>
                                {% endif %}
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                    {% endif %}
                    {% if perms.sql.menu_query %}
                        <li>
                            <a href="#"><i class="fa fa-search fa-fw"></i> SQL查询<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                {% if perms.sql.menu_sqlquery %}
                                    <li>
                                        <a href="/sqlquery/">在线查询</a>
                                    </li>
                                {% endif %}
                                {% if perms.sql.menu_data_dictionary %}
                                    <li>
                                        <a href="/data_dictionary/">数据字典</a>
                                    </li>
                                {% endif %}
                                {% if perms.sql.menu_queryapplylist %}
                                    <li>
                                        <a href="/queryapplylist/">权限管理</a>
                                    </li>
                                {% endif %}

                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                    {% endif %}
                    {% if perms.sql.menu_sqloptimize %}
                        <li>
                            <a href="#"><i class="fa fa-wrench fa-fw"></i> SQL优化<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                {% if perms.sql.menu_sqladvisor %}
                                    <li>
                                        <a href="/sqladvisor/">优化工具</a>
                                    </li>
                                {% endif %}
                                {% if perms.sql.menu_slowquery %}
                                    <li>
                                        <a href="/slowquery/">慢查日志</a>
                                    </li>
                                {% endif %}
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                    {% endif %}
                    {% if perms.sql.menu_instance %}
                        <li>
                            <a href="#"><i class="fa fa-database fa-fw"></i> 实例管理<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                {% if perms.sql.menu_instance_list %}
                                    <li>
                                        <a href="/instance/">实例列表</a>
                                    </li>
                                {% endif %}
                                {% if perms.sql.menu_dbdiagnostic %}
                                    <li>
                                        <a href="/dbdiagnostic/">会话管理</a>
                                    </li>
                                {% endif %}
                                {% if perms.sql.menu_database %}
                                    <li>
                                        <a href="/database/">数据库管理</a>
                                    </li>
                                {% endif %}

                                {% if perms.sql.menu_instance_account %}
                                    <li>
                                        <a href="/instanceaccount/">账号管理</a>
                                    </li>
                                {% endif %}
                                {% if perms.sql.menu_param %}
                                    <li>
                                        <a href="/instanceparam/">参数配置</a>
                                    </li>
                                {% endif %}
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                    {% endif %}
                    {% if perms.sql.menu_tools %}
                        <li>
                            <a href="#"><i class="fa fa-plug fa-fw"></i> 工具插件<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                {% if perms.sql.menu_archive %}
                                    <li>
                                        <a href="/archive/">PTArchiver</a>
                                    </li>
                                {% endif %}
                                {% if perms.sql.menu_binlog2sql %}
                                    <li>
                                        <a href="/binlog2sql/">Binlog2SQL</a>
                                    </li>
                                {% endif %}
                                {% if perms.sql.menu_schemasync %}
                                    <li>
                                        <a href="/schemasync/">SchemaSync</a>
                                    </li>
                                {% endif %}
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                    {% endif %}
                    {% if perms.sql.menu_system %}
                        <li>
                            <a href="#"><i class="fa fa-cogs fa-fw"></i> 系统管理<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level">
                                <li>
                                    <a href="/config/">配置项管理</a>
                                </li>
                                <li>
                                    <a href="/group/">资源组管理</a>
                                </li>
                                <li>
                                    <a href="#">其他配置管理 <span class="fa arrow"></span></a>
                                    <ul class="nav nav-third-level collapse">
                                        <li>
                                            <a target="_blank" href="/admin/sql/users/">用户管理</a>
                                        </li>
                                        <li>
                                            <a target="_blank" href="/admin/auth/group/">权限组管理</a>
                                        </li>
                                        <li>
                                            <a target="_blank" href="/admin/">全部后台数据</a>
                                        </li>
                                    </ul>
                                    <!-- /.nav-third-level -->
                                </li>
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                    {% endif %}
                    {% if perms.sql.menu_document %}
                        <li>
                            <a href="/dbaprinciples/"><i class="fa fa-sitemap fa-fw"></i> 相关文档</a>
                        </li>
                    {% endif %}
                </ul>
            </div>
            <!-- /.sidebar-collapse -->
        </div>
        <!-- /.navbar-static-side -->
    </nav>

    <!-- Page Content -->
    <div id="page-wrapper">
        <div class="clearfix">
            <br>
            {% block content %}
            {% endblock content %}
            <!--底部部分 -->
            <footer class="text-center">
                <hr>
                <p><strong>&copy; Archery</strong>&nbsp;(v{{ archery_version }})</p>
            </footer>
        </div>
    </div>
    <!-- /#page-wrapper -->

</div>

<script src="{% static 'jquery/jquery.min.js' %}"></script>
<script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
<script src="{% static 'metisMenu/js/metisMenu.min.js' %}"></script>
<script src="{% static 'sb-admin-2/js/sb-admin-2.js' %}"></script>
<script src="{% static 'bootstrap-select/js/bootstrap-select.min.js' %}"></script>
<script src="{% static 'bootstrap-select/js/i18n/defaults-zh_CN.min.js' %}"></script>
<script src="{% static 'bootstrap-table/js/bootstrap-table.min.js' %}"></script>
<script src="{% static 'bootstrap-table/js/bootstrap-table-zh-CN.min.js' %}"></script>
<script src="{% static 'sql-formatter/sql-formatter.min.js' %}"></script>
<script src="{% static 'dist/js/formatter.js' %}"></script>

</body>
<script>
    <!-- 解决CSRF-->
    $(function () {
        $.ajaxSetup({
            headers: {"X-CSRFToken": getCookie("csrftoken")}
        });
    });

    function getCookie(name) {
        var cookieValue = null;
        if (document.cookie && document.cookie !== '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) === (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }

    // 解决下拉筛选项被表格遮挡
    // https://github.com/twbs/bootstrap/issues/11037#issuecomment-274870381
    $('.table-responsive').on('shown.bs.dropdown', function (e) {
        var t = $(this),
            m = $(e.target).find('.dropdown-menu'),
            tb = t.offset().top + t.height(),
            mb = m.offset().top + m.outerHeight(true),
            d = 20; // Space for shadow + scrollbar.
        if (t[0].scrollWidth > t.innerWidth()) {
            if (mb + d > tb) {
                t.css('padding-bottom', ((mb + d) - tb));
            }
        } else {
            t.css('overflow', 'visible');
        }
    }).on('hidden.bs.dropdown', function () {
        $(this).css({'padding-bottom': '', 'overflow': ''});
    }).on('page-change.bs.table', function () {
        $(this).css({'padding-bottom': '', 'overflow': ''});
    });
</script>
{% block js %}
{% endblock %}
</html>
