Update
This commit is contained in:
@@ -1,36 +1,24 @@
|
||||
{% extends "/public/skeleton.html" %}
|
||||
{% block content %}
|
||||
{% raw %}
|
||||
|
||||
<a href="/pages">Назад</a>
|
||||
<h3>
|
||||
<a class="btn btn-outline-secondary" href="/pages"><i class="fa fa-chevron-left"></i></a>
|
||||
{{ page.title }}</h3>
|
||||
{{ pagedata['page'].title }}</h3>
|
||||
<hr />
|
||||
|
||||
<div class="row">
|
||||
<div class="col small text-muted">
|
||||
<span v-for="(tag, tagIdx) in page.tags">
|
||||
<i class="fa fa-tag"></i> <a class="text-monospace" :href="'/tag/' + tag.id">{{ tag.name }}</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
{% for tagLink in pagedata['page'].tags %}
|
||||
<a href="/tag/{{ tagLink.tag.id }}">{{ tagLink.tag.name }}</a>;
|
||||
{% endfor %}
|
||||
</p>
|
||||
|
||||
<span v-html="page.body"></span>
|
||||
{{ pagedata['page'].body|safe }}
|
||||
|
||||
<div class="row">
|
||||
<div class="col small text-muted">
|
||||
<i class="fa fa-user"></i> <a class="text-monospace" :href="'/user/' + page.user.id">{{ page.user.name }}</a>
|
||||
Создано: {{ page.created }}
|
||||
Обновлено: {{ page.updated }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endraw %}
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
<ul>
|
||||
<li><a href="/"><i class="fa fa-home"></i></a></li>
|
||||
<li><a href="/">Домой</a></li>
|
||||
<li><a href="/pages">Список статей</a></li>
|
||||
<li>{{ pagedata['page'].title }}</li>
|
||||
</ul>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
<h3>Статьи</h3>
|
||||
<hr />
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
|
||||
|
||||
<div class="row" v-if="firstAlpha">
|
||||
<div class="col py-2 text-center">
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
{% extends "/private/skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
|
||||
<h3>
|
||||
<a class="btn btn-outline-secondary" href="/pages"><i class="fa fa-chevron-left"></i></a>
|
||||
Новая страница
|
||||
</h3>
|
||||
<hr />
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="title">Заголовок</label>
|
||||
<input class="form-control" id="title" name="title" type="text" v-model="page.title">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="body">Текст</label>
|
||||
<textarea class="form-control" cols="40" id="body" name="body" rows="8" v-model="page.body"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="row mt-3">
|
||||
<div class="col">
|
||||
<button type="submit" class="btn btn-outline-success pull-right" v-on:click="send"><i class="fa fa-plus"></i> Добавить</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% 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="/pages">Статьи</a></li>
|
||||
<li class="breadcrumb-item active">Новая статья</li>
|
||||
</ol>
|
||||
{% endraw %}
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript">
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
page: {
|
||||
title: '',
|
||||
body: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
send: function () {
|
||||
/* Сохранить */
|
||||
let vm = this;
|
||||
/* editor.getValue('"body"', 'vm.page.body', type='tinymce') */
|
||||
axios.post(
|
||||
'/api',
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "page.add",
|
||||
"params": {
|
||||
"title": vm.page.title,
|
||||
"body": vm.page.body
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data) {
|
||||
window.location.href = '/page/' + response.data['result'].id;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -33,22 +33,15 @@
|
||||
</div>
|
||||
<!-- Конец: Панель сортировки -->
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
|
||||
|
||||
<div class="row" v-if="firstAlpha">
|
||||
<div class="col py-2 text-center">
|
||||
от <span class="text-danger" v-html="firstAlpha"></span> до <span class="text-danger" v-html="lastAlpha"></span>
|
||||
</div>
|
||||
</div>
|
||||
{% include 'pagination-curl.html' %}
|
||||
|
||||
{% include 'inc/pages.html' %}
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
|
||||
{% include 'pagination-curl.html' %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript" src="/static/components/pagination.js"></script>
|
||||
|
||||
<script>
|
||||
Object.assign(root.data, {
|
||||
|
||||
@@ -11,6 +11,11 @@ def pages(page):
|
||||
"""
|
||||
pagedata = {'title': 'Статьи - ' + app.config['TITLE']}
|
||||
|
||||
pages = models.db_session.query(
|
||||
models.Page
|
||||
).all()
|
||||
pagedata['pages'] = pages
|
||||
|
||||
pagedata['pagination'] = {
|
||||
"page": page,
|
||||
"per_page": app.config['ITEMS_ON_PAGE'],
|
||||
|
||||
@@ -73,5 +73,5 @@ def page_add():
|
||||
"""
|
||||
pagedata = {}
|
||||
pagedata['title'] = 'Новый документ - ' + app.config['TITLE']
|
||||
body = render_template('user/page_add.html', pagedata=pagedata)
|
||||
body = render_template('/private/skeleton.html', pagedata=pagedata)
|
||||
return body
|
||||
|
||||
@@ -1,101 +1,22 @@
|
||||
{% extends "skeleton.html" %}
|
||||
{% extends "/public/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>
|
||||
<a href="/tags">Назад</a>
|
||||
<h1>Тег {{ pagedata['tag'].name }}</h1>
|
||||
<hr />
|
||||
{% endraw %}
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
|
||||
{% include 'pagination-curl.html' %}
|
||||
|
||||
{% include '/inc/pages.html' %}
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
|
||||
{% include 'pagination-curl.html' %}
|
||||
|
||||
{% 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>
|
||||
</ol>
|
||||
{% endraw %}
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript" src="/static/components/pagination.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
Object.assign(root.data, {
|
||||
tag: {{ pagedata['tag']|tojson|safe }},
|
||||
raw_pages: [],
|
||||
pagination: {{ pagedata['pagination']|tojson|safe }},
|
||||
});
|
||||
Object.assign(root.methods, {
|
||||
getPages: function() {
|
||||
/* Получить список статей */
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "tag.pages",
|
||||
"params": {
|
||||
"id": vm.tag.id,
|
||||
"page": vm.pagination.page
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data) {
|
||||
vm.raw_pages = response.data['result'];
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
});
|
||||
root.created = function() {
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
[
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "tag.pages",
|
||||
"params": {
|
||||
"id": vm.tag.id,
|
||||
"page": vm.pagination.page
|
||||
},
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "tag.pages.count",
|
||||
"params": {},
|
||||
"id": 1
|
||||
}
|
||||
]
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data[0]) {
|
||||
vm.raw_pages = response.data[0]['result'];
|
||||
}
|
||||
if ('result' in response.data[1]) {
|
||||
vm.pagination.size = response.data[1]['result'];
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
Object.assign(root.computed, {
|
||||
pages: function() {
|
||||
let vm = this;
|
||||
return vm.raw_pages;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<ul>
|
||||
<li><a href="/">Домой</a></li>
|
||||
<li><a href="/tags">Список тегов</a></li>
|
||||
<li>{{ pagedata['tag'].name }}</li>
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,51 +1,18 @@
|
||||
{% extends "skeleton.html" %}
|
||||
{% extends "/public/skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
<h3>Список тегов</h3>
|
||||
<h1>Список тегов</h1>
|
||||
<hr />
|
||||
|
||||
{% raw %}
|
||||
<div class="row">
|
||||
<div class="col py-2">
|
||||
<div class="btn-group mr-2 mb-3" v-for="(tag, tagIdx) in tags">
|
||||
<a class="btn btn-outline-secondary" :href="'/tag/' + tag.id">{{ tag.name }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endraw %}
|
||||
<p>{% for tag in pagedata['tags'] %}
|
||||
<a href="/tag/{{ tag.id }}">{{ tag.name }}</a> /
|
||||
{% endfor %}</p>
|
||||
|
||||
{% 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>
|
||||
<li><a href="/">Домой</a></li>
|
||||
<li>Список тегов</li>
|
||||
</ol>
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript">
|
||||
Object.assign(root.data, {
|
||||
tags: [],
|
||||
});
|
||||
root.created = function() {
|
||||
/* Получить список тегов после загрузки страницы */
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": 'tags',
|
||||
"params": {},
|
||||
"id": 1
|
||||
}
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data) {
|
||||
vm.tags = response.data['result'];
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -4,7 +4,7 @@ __email__ = 'remizoffalex@mail.ru'
|
||||
|
||||
from flask import abort, render_template
|
||||
|
||||
from .. import app, models
|
||||
from .. import app, lib, models
|
||||
|
||||
|
||||
def tags():
|
||||
@@ -12,11 +12,14 @@ def tags():
|
||||
"""
|
||||
pagedata = {}
|
||||
pagedata['title'] = 'Список меток - ' + app.config['TITLE']
|
||||
pagedata['tags'] = models.db_session.query(
|
||||
models.Tag
|
||||
).all()
|
||||
body = render_template('guest/tags.html', pagedata=pagedata)
|
||||
return body
|
||||
|
||||
|
||||
def tag_id(id):
|
||||
def tag_id(id: int, page: int = 1):
|
||||
"""Метка
|
||||
"""
|
||||
pagedata = {}
|
||||
@@ -32,13 +35,28 @@ def tag_id(id):
|
||||
tag.name,
|
||||
app.config['TITLE']
|
||||
)
|
||||
pagedata['tag'] = tag.as_dict()
|
||||
pagedata['tag'] = tag
|
||||
|
||||
pagedata['pagination'] = {
|
||||
"page": 1,
|
||||
"per_page": app.config['ITEMS_ON_PAGE'],
|
||||
"size": 0
|
||||
}
|
||||
pages_idx = models.db_session.query(
|
||||
models.TagPage.page_id
|
||||
).filter(
|
||||
models.TagPage.tag_id==id
|
||||
)
|
||||
pages = models.db_session.query(
|
||||
models.Page
|
||||
).filter(
|
||||
models.Page.id.in_(pages_idx)
|
||||
).order_by(
|
||||
models.Page.title.asc()
|
||||
)
|
||||
|
||||
pagedata['pagination'] = lib.Pagination(
|
||||
page,
|
||||
app.config['ITEMS_ON_PAGE'],
|
||||
pages.count()
|
||||
)
|
||||
pagedata['pagination'].url = '/tag/{}/pages'.format(id)
|
||||
pagedata['pages'] = pages.all()
|
||||
|
||||
body = render_template('guest/tag.html', pagedata=pagedata)
|
||||
return body
|
||||
|
||||
@@ -31,12 +31,12 @@ def user_pages(id: int, page: int):
|
||||
|
||||
@app.route('/users', defaults={'page': 1})
|
||||
@app.route('/users/<int:page>')
|
||||
def users(page: int):
|
||||
def users_list(page: int):
|
||||
"""
|
||||
Список пользователей
|
||||
"""
|
||||
if lib.get_user():
|
||||
return views_user.users(page)
|
||||
return views_user.users_list(page)
|
||||
else:
|
||||
return views_guest.users(page)
|
||||
return views_guest.users_list(page)
|
||||
abort(404)
|
||||
|
||||
@@ -1,43 +1,21 @@
|
||||
{% extends "/public/skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
{% raw %}
|
||||
<h3>
|
||||
<a class="btn btn-outline-secondary" href="/users"><i class="fa fa-chevron-left"></i></a>
|
||||
{{ user.name }}</h3>
|
||||
<a href="/users">Назад</a>
|
||||
<h1>{{ pagedata['user'].name }}</h1>
|
||||
<hr />
|
||||
{% endraw %}
|
||||
|
||||
{% include 'user_menu.html' %}
|
||||
{% raw %}
|
||||
{% include 'guest/user_menu.html' %}
|
||||
|
||||
Зарегистрирован: {{ user.created }}
|
||||
|
||||
{% endraw %}
|
||||
<p>Зарегистрирован: {{ pagedata['user'].created }}
|
||||
|
||||
|
||||
{% 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="/user">Список пользователей</a></li>
|
||||
<li class="breadcrumb-item">{{ user.name }}</li>
|
||||
<ol>
|
||||
<li><a href="/">Домой</a></li>
|
||||
<li><a href="/user">Список пользователей</a></li>
|
||||
<li>{{ pagedata['user'].name }}</li>
|
||||
</ol>
|
||||
{% endraw %}
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript">
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
menuitem: null,
|
||||
user: {{ pagedata['user']|tojson|safe }},
|
||||
},
|
||||
methods: {
|
||||
},
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
|
||||
<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="'/user/' + user.id" v-else><i class="fa fa-bars"></i></a>
|
||||
|
||||
|
||||
<div class="btn btn-primary mb-2" v-if="menuitem==='pages'">Статьи</div>
|
||||
<a class="btn btn-outline-secondary mb-2" :href="'/user/' + user.id + '/pages'" v-else>Статьи</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<a href="/user/{{ pagedata['user'].id }}">{{ pagedata['user'].name }}</a> /
|
||||
<a href="/user/{{ pagedata['user'].id }}/pages">Статьи</a>
|
||||
</p>
|
||||
<hr />
|
||||
|
||||
@@ -1,119 +1,24 @@
|
||||
{% extends "skeleton.html" %}
|
||||
{% extends "/public/skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
{% raw %}
|
||||
<h3>
|
||||
<a class="btn btn-outline-secondary" href="/users"><i class="fa fa-chevron-left"></i></a>
|
||||
{{ user.name }}</h3>
|
||||
<a href="/users">Назад</a>
|
||||
<h1>{{ pagedata['user'].name }}</h1>
|
||||
<hr />
|
||||
{% endraw %}
|
||||
|
||||
{% include 'user_menu.html' %}
|
||||
{% include 'guest/user_menu.html' %}
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
|
||||
{% include 'pagination-curl.html' %}
|
||||
|
||||
{% include 'inc/pages.html' %}
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
|
||||
{% include 'pagination-curl.html' %}
|
||||
|
||||
{% 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="/user">Список пользователей</a></li>
|
||||
<li class="breadcrumb-item">{{ user.name }}</li>
|
||||
<ol>
|
||||
<li><a href="/">Домой</a></li>
|
||||
<li><a href="/user">Список пользователей</a></li>
|
||||
<li>{{ pagedata['user'].name }}</li>
|
||||
</ol>
|
||||
{% endraw %}
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript" src="/static/components/pagination.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
Object.assign(root.data, {
|
||||
menuitem: 'pages',
|
||||
user: {{ pagedata['user']|tojson|safe }},
|
||||
raw_pages: [],
|
||||
pagination: {{ pagedata['pagination']|tojson|safe }},
|
||||
});
|
||||
Object.assign(root.methods, {
|
||||
filterApply: function() {},
|
||||
filterPage: function(page) {
|
||||
let vm = this;
|
||||
if ( vm.filter.length<1 ) {
|
||||
return true;
|
||||
}
|
||||
if ( page.title.toLowerCase().includes(vm.filter.toLowerCase()) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
getPages: function() {
|
||||
/* Получить список статей */
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "pages",
|
||||
"params": {
|
||||
"page": vm.pagination.page
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data) {
|
||||
vm.raw_pages = response.data['result'];
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
});
|
||||
root.created = function() {
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
[
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "user.pages",
|
||||
"params": {
|
||||
"id": vm.user.id,
|
||||
"page": vm.pagination.page
|
||||
},
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "user.pages.count",
|
||||
"params": {
|
||||
"id": vm.user.id,
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
]
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data[0]) {
|
||||
vm.raw_pages = response.data[0]['result'];
|
||||
}
|
||||
if ('result' in response.data[1]) {
|
||||
vm.pagination.size = response.data[1]['result'];
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
computed: {
|
||||
pages: function() {
|
||||
/* Отфильтрованный список */
|
||||
let vm = this;
|
||||
var result = vm.raw_pages.filter(vm.filterPage);
|
||||
return result;
|
||||
},
|
||||
},
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -4,87 +4,17 @@
|
||||
<h3>Список пользователей</h3>
|
||||
<hr />
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getUsers"></pagination-component>
|
||||
{% include 'pagination-curl.html' %}
|
||||
|
||||
{% include '/inc/users.html' %}
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getUsers"></pagination-component>
|
||||
{% include 'pagination-curl.html' %}
|
||||
|
||||
{% 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>
|
||||
<ul>
|
||||
<li><a href="/">Домой</a></li>
|
||||
<li>Список пользователей</li>
|
||||
</ol>
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<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 %}
|
||||
|
||||
@@ -4,7 +4,7 @@ __email__ = 'remizoffalex@mail.ru'
|
||||
|
||||
from flask import abort, render_template
|
||||
|
||||
from .. import app, models
|
||||
from .. import app, lib, models
|
||||
|
||||
|
||||
def user_id(id):
|
||||
@@ -18,16 +18,15 @@ def user_id(id):
|
||||
).first()
|
||||
if user is None:
|
||||
abort(404)
|
||||
pagedata['user'] = user.as_dict()
|
||||
pagedata['user'] = user
|
||||
pagedata['title'] = '{} - {}'.format(user.name, app.config['TITLE'])
|
||||
body = render_template('/guest/user.html', pagedata=pagedata)
|
||||
return body
|
||||
|
||||
|
||||
def user_pages(id):
|
||||
def user_pages(id: int, page: int = 1):
|
||||
"""Список статей пользователя
|
||||
"""
|
||||
pagedata = {}
|
||||
user = models.db_session.query(
|
||||
models.User
|
||||
).filter(
|
||||
@@ -35,30 +34,49 @@ def user_pages(id):
|
||||
).first()
|
||||
if user is None:
|
||||
abort(404)
|
||||
pagedata = {}
|
||||
pagedata['user'] = user.as_dict()
|
||||
pagedata['title'] = '{} - {}'.format(user.name, app.config['TITLE'])
|
||||
|
||||
pagedata['pagination'] = {
|
||||
"page": 1,
|
||||
"per_page": app.config['ITEMS_ON_PAGE'],
|
||||
"size": 0
|
||||
}
|
||||
pages = models.db_session.query(
|
||||
models.Page
|
||||
).filter(
|
||||
models.Page.user_id == id
|
||||
).order_by(
|
||||
models.Page.title.asc()
|
||||
)
|
||||
|
||||
pagedata['pagination'] = lib.Pagination(
|
||||
page,
|
||||
app.config['ITEMS_ON_PAGE'],
|
||||
pages.count()
|
||||
)
|
||||
pagedata['pagination'].url = '/user/{}/pages'.format(user_id)
|
||||
pagedata['pages'] = pages.all()
|
||||
|
||||
body = render_template('/guest/user_pages.html', pagedata=pagedata)
|
||||
return body
|
||||
|
||||
|
||||
def users(page: int):
|
||||
def users_list(page: int = 1):
|
||||
"""Список пользователей
|
||||
"""
|
||||
pagedata = {}
|
||||
pagedata['title'] = 'Список пользователей - ' + app.config['TITLE']
|
||||
|
||||
pagedata['pagination'] = {
|
||||
"page": page,
|
||||
"per_page": app.config['ITEMS_ON_PAGE'],
|
||||
"size": 0
|
||||
}
|
||||
users = models.db_session.query(
|
||||
models.User
|
||||
).order_by(
|
||||
models.User.name.asc()
|
||||
)
|
||||
|
||||
pagedata['pagination'] = lib.Pagination(
|
||||
page,
|
||||
app.config['ITEMS_ON_PAGE'],
|
||||
users.count()
|
||||
)
|
||||
pagedata['pagination'].url = '/users'
|
||||
pagedata['users'] = users.all()
|
||||
|
||||
body = render_template('/guest/users.html', pagedata=pagedata)
|
||||
return body
|
||||
|
||||
@@ -48,7 +48,7 @@ def user_pages(id):
|
||||
return body
|
||||
|
||||
|
||||
def users(page: int):
|
||||
def users_list(page: int):
|
||||
"""Список пользователей
|
||||
"""
|
||||
pagedata = {}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
<div class="row mt-3 py-3 bg-light">
|
||||
<div class="col-md-1"></div>
|
||||
<div class="col-md-10">
|
||||
<p>
|
||||
© <a href="https://specialistoff.net/" target="_blank">RemiZOffAlex</a>
|
||||
</div>
|
||||
<div class="col-md-1"></div>
|
||||
</div>
|
||||
</p>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<table>
|
||||
<table border="1" cellpadding="1" width="100%">
|
||||
{% for page in pagedata['pages'] %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/page/{{ page.id }}">{{ page.title }}</a>
|
||||
<p><a href="/page/{{ page.id }}">{{ page.title }}</a></p>
|
||||
|
||||
{% for tagLink in page.tags %}
|
||||
<p>{% for tagLink in page.tags %}
|
||||
<a href="/tag/{{ tagLink.tag.id }}">{{ tagLink.tag.name }}</a>
|
||||
{% endfor %}
|
||||
{% endfor %}</p>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
{% raw %}
|
||||
<div class="row" v-for="(user, userIdx) in users">
|
||||
<div class="col py-2">
|
||||
<a :href="'/user/' + user.id">{{ user.name }}</a>
|
||||
<table border="1" cellpadding="1" width="100%">
|
||||
{% for user in pagedata['users'] %}
|
||||
<tr>
|
||||
<td>
|
||||
<p><a href="/user/{{ user.id }}">{{ user.name }}</a></p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col text-muted">
|
||||
<small>
|
||||
Создан: {{ user.created }}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
<p>{% for tagLink in user.tags %}
|
||||
<a href="/tag/{{ tagLink.tag.id }}">{{ tagLink.tag.name }}</a>
|
||||
{% endfor %}</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endraw %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
17
myapp/templates/pagination-curl.html
Normal file
17
myapp/templates/pagination-curl.html
Normal file
@@ -0,0 +1,17 @@
|
||||
{% if pagedata['pagination'].pages > 1 %}
|
||||
<table border="1">
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
{% for item in range(pagedata['pagination'].pages) %}
|
||||
{% if pagedata['pagination'].current==item+1 %}
|
||||
<a href="{{ pagedata['pagination'].url }}/{{item+1}}">[{{ item +1}}]</a>
|
||||
{% else %}
|
||||
<a href="{{ pagedata['pagination'].url }}/{{item+1}}">{{ item +1}}</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{% endif %}
|
||||
@@ -11,5 +11,4 @@ let routes = {};
|
||||
|
||||
{% include '/private/components/inc.j2' %}
|
||||
{% include '/private/domains/inc.j2' %}
|
||||
|
||||
{% include '/routes.js' %}
|
||||
{% include '/private/routes.js' %}
|
||||
|
||||
@@ -12,7 +12,11 @@ function Pages() {
|
||||
clickHandler: pages_get,
|
||||
order: 'asc',
|
||||
}),
|
||||
pages: [],
|
||||
raw_pages: [],
|
||||
get pages() {
|
||||
let result = data.raw_pages.filter(question_filter);
|
||||
return result;
|
||||
},
|
||||
pagination: Pagination({
|
||||
clickHandler: pages_get,
|
||||
prefix_url: '/pages'
|
||||
@@ -25,8 +29,18 @@ function Pages() {
|
||||
]);
|
||||
return result;
|
||||
};
|
||||
function page_filter(page) {
|
||||
let filter = data.filter.data;
|
||||
let value = filter.value;
|
||||
if (value.length < 1) {
|
||||
return true;
|
||||
}
|
||||
if (page.title.toLowerCase().includes(value.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
function pages_get() {
|
||||
let order_by = data.order_by.data;
|
||||
let pagination = data.pagination.data;
|
||||
m.request({
|
||||
url: '/api',
|
||||
@@ -55,7 +69,7 @@ function Pages() {
|
||||
}).then(
|
||||
function(response) {
|
||||
if ('result' in response[0]) {
|
||||
data.pages = response[0]['result'];
|
||||
data.raw_pages = response[0]['result'];
|
||||
}
|
||||
if ('result' in response[1]) {
|
||||
data.pagination.size = response[1]['result'];
|
||||
|
||||
@@ -11,5 +11,4 @@ let routes = {};
|
||||
|
||||
{% include '/public/components/inc.j2' %}
|
||||
{% include '/public/domains/inc.j2' %}
|
||||
|
||||
{% include '/routes.js' %}
|
||||
{% include '/public/routes.js' %}
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
<div class="row">
|
||||
<div class="col py-2">
|
||||
<p>
|
||||
<a href="/">Домой</a> /
|
||||
<a href="/pages">Статьи</a> /
|
||||
<a href="/tags">Метки</a> /
|
||||
<a href="/users">Пользователи</a>
|
||||
|
||||
<a class="btn btn-outline-secondary" href="/"><i class="fa fa-home"></i></a>
|
||||
<a class="btn btn-outline-secondary border-0" href="/pages">Статьи</a>
|
||||
<a class="btn btn-outline-secondary border-0" href="/tags">Метки</a>
|
||||
<a class="btn btn-outline-secondary border-0" href="/users">Пользователи</a>
|
||||
<a class="btn btn-outline-secondary border-0" href="/api/browse">API JSON-RPC</a>
|
||||
|
||||
<a class="btn btn-outline-success float-right" href="/login"><i class="fa fa-sign-in"></i></a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</p>
|
||||
|
||||
14
myapp/templates/public/routes.js
Normal file
14
myapp/templates/public/routes.js
Normal file
@@ -0,0 +1,14 @@
|
||||
m.route.prefix = '';
|
||||
function layout_decorator(controller) {
|
||||
return {
|
||||
render: function(vnode) {
|
||||
return m(Layout, m(controller, vnode.attrs))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
m.route(
|
||||
vroot,
|
||||
"/",
|
||||
routes
|
||||
);
|
||||
Reference in New Issue
Block a user