{% extends "user/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' %}

{% raw %}
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getNotes"></pagination-component>

<div class="row" v-for="(note, noteIdx) in notes">
<div class="col py-2" :class="{'bg-light': noteIdx % 2}">

<a :href="'/note/' + note.id" v-html="note.title"></a>

<div class="row">
<div class="col small text-muted">
<span v-for="(tag, tagIdx) in note.tags">
<i class="fa fa-tag"></i> <a class="text-monospace" :href="'/tag/' + tag.id">{{ tag.name }}</a>&nbsp;
</span>
</div>
</div>

<div class="row">
<div class="col small text-muted">
Создано: {{ note.created }}&nbsp;
Обновлено: {{ note.updated }}
</div>
</div>

</div>
</div>

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

{% endraw %}
{% 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">
var app = new Vue({
    el: '#app',
    data: {
        menuitem: 'notes',
        tag: {{ pagedata['tag']|tojson|safe }},
        notes: [],
        pagination: {{ pagedata['pagination']|tojson|safe }},
    },
    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.notes = response.data['result'];
                    }
                }
            );
        },
    },
    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.notes = response.data[0]['result'];
                }
                if ('result' in response.data[1]) {
                    vm.pagination.size = response.data[1]['result'];
                }
            }
        );
    },
    computed: {
        filteredPages: function() {
            let vm = this;
            return vm.pages;
        }
    },
})
</script>
{% endblock %}
