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

{% raw %}
<h3>
<a class="btn btn-outline-secondary" href="/tags"><i class="fa fa-chevron-left"></i></a>
Тег {{ tag.name }}</h3>
<hr />
{% endraw %}

{% include 'user/tag_menu.html' %}

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

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

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

{% endblock %}

{% block breadcrumb %}
{% raw %}
<ol class="breadcrumb mt-3">
    <li class="breadcrumb-item"><a href="/"><i class="fa fa-home"></i></a></li>
    <li class="breadcrumb-item"><a href="/tags">Список тегов</a></li>
    <li class="breadcrumb-item">{{ tag.name }}</li>
    <li class="breadcrumb-item">Заметки с тегом</li>
</ol>
{% endraw %}
{% 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, {
    menuitem: 'notes',
    tag: {{ pagedata['tag']|tojson|safe }},
    raw_notes: [],
    pagination: {{ pagedata['pagination']|tojson|safe }},
});
Object.assign(root.methods, {
    getNotes: function() {
        /* Получить список статей */
        let vm = this;
        axios.post(
            '/api',
            {
                "jsonrpc": "2.0",
                "method": "tag.notes",
                "params": {
                    "id": vm.tag.id,
                    "page": vm.pagination.page
                },
                "id": 1
            }
        ).then(
            function(response) {
                if ('result' in response.data) {
                    vm.raw_notes = response.data['result'];
                }
            }
        );
    },
});
root.created = function() {
    let vm = this;
    axios.post(
        '/api',
        [
            {
                "jsonrpc": "2.0",
                "method": "tag.notes",
                "params": {
                    "id": vm.tag.id,
                    "page": vm.pagination.page
                },
                "id": 1
            },
            {
                "jsonrpc": "2.0",
                "method": "tag.notes.count",
                "params": {},
                "id": 1
            }
        ]
    ).then(
        function(response) {
            if ('result' in response.data[0]) {
                vm.raw_notes = response.data[0]['result'];
            }
            if ('result' in response.data[1]) {
                vm.pagination.size = response.data[1]['result'];
            }
        }
    );
};
Object.assign(root.computed, {
    notes: function() {
        let vm = this;
        return vm.raw_notes;
    }
});
</script>
{% endblock %}
