{% extends "skeleton.html" %}
{% block content %}

<h3>Список пользователей</h3>
<hr />

{% include '/inc/filter.html' %}

<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getUsers"></pagination-component>

{% include '/inc/users.html' %}

<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getUsers"></pagination-component>

<backtotop-component></backtotop-component>

{% endblock %}

{% block breadcrumb %}
<ol class="breadcrumb mt-3">
    <li class="breadcrumb-item"><a href="/"><i class="fa fa-home"></i></a></li>
    <li class="breadcrumb-item">Список пользователей</li>
</ol>
{% endblock %}

{% block script %}
<script type="text/javascript" src="/static/components/backtotop.js"></script>
<link rel="stylesheet" href="/static/components/backtotop.css"></link>
<script type="text/javascript" src="/static/components/pagination.js"></script>

<script type="text/javascript">
Object.assign(root.data, {
    raw_users: [],
    pagination: {{ pagedata['pagination']|tojson|safe }},
});
Object.assign(root.methods, {
    getUsers: function() {
        let vm = this;
        axios.post(
            '/api',
            {
                "jsonrpc": "2.0",
                "method": "users",
                "params": {
                    "page": vm.pagination.page
                },
                "id": 1
            }
        ).then(
            function(response) {
                if ('result' in response.data) {
                    vm.raw_users = response.data['result'];
                }
            }
        );
    }
});
Object.assign(root.computed, {
    users: function() {
        let vm = this;
        return vm.raw_users;
    }
});
root.created = function() {
    let vm = this;
    axios.post(
        '/api',
        [
            {
                "jsonrpc": "2.0",
                "method": 'users',
                "params": {
                    "page": vm.pagination.page
                },
                "id": 1
            },
            {
                "jsonrpc": "2.0",
                "method": 'users.count',
                "params": {},
                "id": 1
            }
        ]
    ).then(
        function(response) {
            if ('result' in response.data[0]) {
                vm.raw_users = response.data[0]['result'];
            }
            if ('result' in response.data[1]) {
                vm.pagination.size = response.data[1]['result'];
            }
        }
    );
};
</script>
{% endblock %}
