{% set page_title = _("Overview") %}

{% extends theme("management/management_layout.html") %}

{% block breadcrumb %}
<ol class="breadcrumb flaskbb-breadcrumb">
    <li><a href="{{ url_for('forum.index') }}">{% trans %}Forum{% endtrans %}</a></li>
    <li class="active">{% trans %}Management{% endtrans %}</li>
</ol>
{% endblock %}

{% block management_content %}
<div class="col-md-12 settings-col">
    <div class="panel settings-panel">
        <div class="panel-heading settings-head">
            <span class="fa fa-tasks"></span> {% trans %}Overview{% endtrans %}
        </div>
        <div class="panel-body settings-body">
            <div class="settings-content">
                <div class="stats">
                    <div class="row stats-row">
                        <div class="overview-notifications col-md-12 col-sm-12 col-xs-12">
                            {% if unread_reports > 0 %}
                            <div class="alert-message alert-message-warning">
                                <h4>{% trans %}There is something that wants your attention.{% endtrans %}</h4>
                                <p>{% trans url=url_for('management.unread_reports') %}You have <a href="{{ url }}">{{ unread_reports }} unread reports</a>.{% endtrans %}</p>
                            </div>
                            {% else %}
                            <div id="overview-no-notifications" class="alert-message alert-message-success">
                                <h4>{% trans %}Everything seems alright.{% endtrans %}</h4>
                                <p>{% trans %}No new notifications.{% endtrans %}</p>
                            </div>
                            {% endif %}
                        </div>
                    </div>
                    <div class="row stats-row">
                        <div class="col-md-4 col-sm-4 col-xs-4">
                            <div class="stats-widget">
                                <div class="icon">
                                     <i class="fa fa-users text-success"></i>
                                </div>
                                <div class="text">
                                    <var>{{ all_users }}</var>
                                    <label class="text-muted">{% trans %}users{% endtrans %}</label>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-4 col-sm-4 col-xs-4">
                            <div class="stats-widget">
                                <div class="icon">
                                     <i class="fa fa-comment text-primary"></i>
                                </div>
                                <div class="text">
                                    <var>{{ post_count }}</var>
                                    <label class="text-muted">{% trans %}posts{% endtrans %}</label>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-4 col-sm-4 col-xs-4">
                            <div class="stats-widget">
                                <div class="icon">
                                     <i class="fa fa-comments text-info"></i>
                                </div>
                                <div class="text">
                                    <var>{{ topic_count }}</var>
                                    <label class="text-muted">{% trans %}topics{% endtrans %}</label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row stats-row">

                        <div class="col-md-4 col-sm-4 col-xs-4">
                            <div class="row stats-heading">{% trans %}Statistics{% endtrans %}</div>

                            <div class="row stats-item">
                                <div class="key pull-left">{% trans %}Registered users{% endtrans %}</div><div class="value pull-right">{{ all_users }}</div>
                            </div>
                            <div class="row stats-item">
                                <div class="key pull-left">{% trans %}Online users{% endtrans %}</div><div class="value pull-right">{{ online_users }}</div>
                            </div>
                            <div class="row stats-item">
                                <div class="key pull-left">{% trans %}Banned users{% endtrans %}</div><div class="value pull-right">{{ banned_users }}</div>
                            </div>
                            <div class="row stats-item">
                                <div class="key pull-left">{% trans %}Groups{% endtrans %}</div><div class="value pull-right">{{ all_groups }}</div>
                            </div>
                            <div class="row stats-item">
                                <div class="key pull-left">{% trans %}Topics{% endtrans %}</div><div class="value pull-right">{{ topic_count }}</div>
                            </div>
                            <div class="row stats-item">
                                <div class="key pull-left">{% trans %}Posts{% endtrans %}</div><div class="value pull-right">{{ post_count }}</div>
                            </div>
                            <div class="row stats-item">
                                <div class="key pull-left">{% trans %}Reports{% endtrans %}</div><div class="value pull-right">{{ report_count }}</div>
                            </div>
                        </div>

                        <div class="col-md-4 col-sm-4 col-xs-4">
                            <div class="row stats-heading">{% trans %}Components{% endtrans %}</div>

                            <div class="row stats-item">
                                <div class="key pull-left">FlaskBB</div><div class="value pull-right">{{ flaskbb_version }}</div>
                            </div>
                            <!--  TODO: Implement a API. one day..
                            <div class="row stats-item">
                                <div class="key pull-left">FlaskBB API</div><div class="value pull-right">v1</div>
                            </div>
                            -->
                            <div class="row stats-item">
                                <div class="key pull-left">Celery</div>
                                <div class="value pull-right">
                                    <span id="celery-status" class="text-warning">checking status</span>
                                    {{ celery_version }}
                                </div>
                            </div>
                            <div class="row stats-item">
                                <div class="key pull-left">Flask</div><div class="value pull-right">{{ flask_version }}</div>
                            </div>
                            <div class="row stats-item">
                                <div class="key pull-left">Python</div><div class="value pull-right">{{ python_version }}</div>
                            </div>
                        </div>

                        <div class="col-md-4 col-sm-4 col-xs-4">
                            <div class="row stats-heading">{% trans %}Plugins{% endtrans %}</div>

                            {% for plugin in plugins %}
                            <div class="row stats-item">
                                <div class="key pull-left">
                                {% if plugin.installed %}
                                    <a href="{{ url_for('management.settings', plugin=plugin.name) }}">{{ plugin.name.title() }}</a>
                                {% else %}
                                    <a href="{{ url_for('management.plugins') }}">{{ plugin.name.title() }}</a>
                                {% endif %}
                                </div>
                                <div class="value pull-right">
                                    {% if not plugin.enabled %}
                                        <span class="text-danger">not enabled</span>
                                    {% elif plugin.enabled %}
                                        {% if plugin.is_installed %}
                                        <span class="text-success">enabled &amp; installed</span>
                                        {% elif not plugin.is_installable %}
                                        <span class="text-success">enabled</span>
                                        {% elif not plugin.is_installed %}
                                        <span class="text-warning">not installed</span>
                                        {% endif %}
                                    {% endif %}
                                    {{ plugin.version }}
                                </div>
                            </div>
                            {% endfor %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>

function celery_not_running_notification() {
    content = "<div class='alert-message alert-message-danger'>" +
        "<h4>{% trans %}There is a problem.{% endtrans %}</h4>" +
        "<p>{% trans %}Celery is <strong>not</strong> running.{% endtrans %}</p>" +
        "<p>{% trans %}You can start celery with this command:{% endtrans %}</p>" +
        "<pre>flaskbb --config {{ current_app.config["CONFIG_PATH"] }} celery worker</pre>" +
        "</div>";

    // replace the no notifications notice with ours
    if(document.getElementById("#overview-no-notifications") == null) {
        $("#overview-no-notifications").replaceWith(content);
    } else {
        $(".overview-notifications").append(content);
    }
}

$(document).ready(function () {
    var $celerystatus = $('#celery-status');

    $.getJSON('/admin/celerystatus', function(data) {
        if(data.celery_running) {
            $celerystatus.replaceWith("<span id='celery-status' class='text-success'><strong>running</strong></span>");
        } else {
            $celerystatus.replaceWith("<span id='celery-status' class='text-danger'><strong>not running</strong></span>");
            celery_not_running_notification()
        }
    });
});
</script>
{% endblock %}
