Update tag

This commit is contained in:
RemiZOffAlex
2020-02-16 22:58:54 +03:00
parent 0c190878c3
commit 9a9e84db0d
5 changed files with 196 additions and 1 deletions

View File

@@ -26,3 +26,13 @@ def tag_id(id):
return views_user.tag_id(id)
else:
return views_guest.tag_id(id)
@app.route('/tag/<int:id>/notes')
def tag_notes(id):
"""Заметки с меткой
"""
if lib.get_user():
return views_user.tag_notes(id)
else:
abort(404)

View File

@@ -7,6 +7,7 @@
Тег {{ tag.name }}</h3>
<hr />
{% endraw %}
{% include 'user/tag_menu.html' %}
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
@@ -35,6 +36,7 @@
var app = new Vue({
el: '#app',
data: {
menuitem: null,
tag: {{ pagedata['tag']|tojson|safe }},
pages: [],
pagination: {{ pagedata['pagination']|tojson|safe }},
@@ -80,7 +82,9 @@ var app = new Vue({
{
"jsonrpc": "2.0",
"method": "tag.pages.count",
"params": {},
"params": {
"id": vm.tag.id
},
"id": 1
}
]
@@ -95,6 +99,12 @@ var app = new Vue({
}
);
},
computed: {
filteredPages: function() {
let vm = this;
return vm.pages;
}
}
})
</script>
{% endblock %}

View File

@@ -0,0 +1,14 @@
<div class="row">
<div class="col">
<div class="btn-group">
<div class="btn btn-primary mb-2" v-if="menuitem===null"><i class="fa fa-bars"></i></div>
<a class="btn btn-outline-secondary mb-2" :href="'/tag/' + tag.id" v-else><i class="fa fa-bars"></i></a>
</div>
<div class="btn btn-primary mb-2" v-if="menuitem==='notes'">Заметки</div>
<a class="btn btn-outline-secondary mb-2" :href="'/tag/' + tag.id + '/notes'" v-else>Заметки</a>
</div>
</div>
<hr />

View File

@@ -0,0 +1,133 @@
{% 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 %}

View File

@@ -44,3 +44,31 @@ def tag_id(id):
body = render_template('user/tag.html', pagedata=pagedata)
return body
def tag_notes(id):
"""Метка
"""
pagedata = {}
tag = models.db_session.query(
models.Tag
).filter(
models.Tag.id == id
).first()
if tag is None:
abort(404)
pagedata['title'] = 'Метка {} - {}'.format(
tag.name,
app.config['TITLE']
)
pagedata['tag'] = tag.as_dict()
pagedata['pagination'] = {
"page": 1,
"per_page": app.config['ITEMS_ON_PAGE'],
"size": 0
}
body = render_template('user/tag_notes.html', pagedata=pagedata)
return body