Add notes
This commit is contained in:
69
myapp/ns_note/templates/note.html
Normal file
69
myapp/ns_note/templates/note.html
Normal file
@@ -0,0 +1,69 @@
|
||||
{% extends "user/skeleton.html" %}
|
||||
{% block content %}
|
||||
{% raw %}
|
||||
|
||||
<h3>
|
||||
<a class="btn btn-outline-secondary" href="/notes"><i class="fa fa-chevron-left"></i></a>
|
||||
{{ note.title }}
|
||||
</h3>
|
||||
|
||||
<tags-component v-bind:tags="note.tags" v-bind:node="note.id" v-bind:url="'Note'"></tags-component>
|
||||
|
||||
<span v-html="note.body"></span>
|
||||
|
||||
<backtotop-component></backtotop-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="/notes">Заметки</a></li>
|
||||
<li class="breadcrumb-item active" v-html="note.title"></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/tags.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
note: {{ pagedata['note']|tojson|safe }},
|
||||
},
|
||||
methods: {
|
||||
noteDelete: function() {
|
||||
/* Удалить статью в корзину */
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": 'note.delete',
|
||||
"params": {
|
||||
"id": vm.note.id
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data) {
|
||||
window.location.href = '/notes';
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
showPanel: function(panel) {
|
||||
/* Показать/скрыть панель */
|
||||
panel.visible = !panel.visible;
|
||||
},
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
82
myapp/ns_note/templates/note_add.html
Normal file
82
myapp/ns_note/templates/note_add.html
Normal file
@@ -0,0 +1,82 @@
|
||||
{% extends "user/skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
|
||||
<h3>
|
||||
<a class="btn btn-outline-secondary" href="/notes"><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="note.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="note.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="/notes">Заметки</a></li>
|
||||
<li class="breadcrumb-item active">Новая заметка</li>
|
||||
</ol>
|
||||
{% endraw %}
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
{% import 'inc/editor.js' as editor %}
|
||||
{{ editor.plugin('tinymce') }}
|
||||
|
||||
<script type="text/javascript">
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
note: {
|
||||
title: '',
|
||||
body: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
send: function () {
|
||||
/* Сохранить */
|
||||
let vm = this;
|
||||
{{ editor.getValue('body', 'vm.note.body', type='tinymce') }}
|
||||
axios.post(
|
||||
'/api',
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "note.add",
|
||||
"params": {
|
||||
"title": vm.note.title,
|
||||
"body": vm.note.body
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data) {
|
||||
window.location.href = '/note/' + response.data['result'].id;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
{{ editor.tinymce('body') }}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
81
myapp/ns_note/templates/note_edit.html
Normal file
81
myapp/ns_note/templates/note_edit.html
Normal file
@@ -0,0 +1,81 @@
|
||||
{% extends "user/skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
<h3>
|
||||
<a class="btn btn-outline-secondary" :href="'/note/' + note.id"><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="note.title">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="body">Текст</label>
|
||||
<textarea class="form-control" cols="40" id="body" name="body" v-model="note.body" rows="8"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="row mt-3">
|
||||
<div class="col">
|
||||
<button type="button" class="btn btn-outline-success pull-right" v-on:click="send"><i class="fa fa-save-o"></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="/notes">Заметки</a></li>
|
||||
<li class="breadcrumb-item"><a :href="'/note/' + note.id" v-html="note.title"></a></li>
|
||||
<li class="breadcrumb-item active">Редактирование заметки</li>
|
||||
</ol>
|
||||
{% endraw %}
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
{% import 'inc/editor.js' as editor %}
|
||||
{{ editor.plugin('tinymce') }}
|
||||
|
||||
<script type="text/javascript">
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
note: {{ pagedata['note']|tojson|safe }}
|
||||
},
|
||||
methods: {
|
||||
send: function () {
|
||||
/* Сохранить */
|
||||
let vm = this;
|
||||
{{ editor.getValue('body', 'vm.note.body', type='tinymce') }}
|
||||
axios.post(
|
||||
'/api',
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "note.update",
|
||||
"params": {
|
||||
"id": vm.note.id,
|
||||
"title": vm.note.title,
|
||||
"body": vm.note.body
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data) {
|
||||
window.location.href = '/note/' + response.data['result'].id;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
mounted: function () {
|
||||
{{ editor.tinymce('body') }}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
157
myapp/ns_note/templates/notes.html
Normal file
157
myapp/ns_note/templates/notes.html
Normal file
@@ -0,0 +1,157 @@
|
||||
{% extends "user/skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
<h3>
|
||||
<div class="float-right">
|
||||
<a class="btn btn-outline-success" href="/note/add"><i class="fa fa-plus"></i></a>
|
||||
</div>
|
||||
<button type="button" class="btn btn-outline-secondary" v-on:click="showPanel(panels.filter)"><i class="fa fa-filter"></i></button>
|
||||
|
||||
Заметки
|
||||
</h3>
|
||||
<hr />
|
||||
|
||||
{% include 'inc/filter.html' %}
|
||||
|
||||
{% raw %}
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getNotes"></pagination-component>
|
||||
|
||||
<div class="row" v-for="(note, noteIdx) in filteredNotes">
|
||||
<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>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col small text-muted">
|
||||
Создано: {{ note.created }}
|
||||
Обновлено: {{ note.updated }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getNotes"></pagination-component>
|
||||
|
||||
<backtotop-component></backtotop-component>
|
||||
|
||||
{% 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>
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
filter: '',
|
||||
notes: [],
|
||||
pagination: {{ pagedata['pagination']|tojson|safe }},
|
||||
panels: {
|
||||
filter: {
|
||||
visible: false
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
arrayRemove: function(arr, value) {
|
||||
/* Удаление элемента из списка */
|
||||
return arr.filter(function(ele){
|
||||
return ele != value;
|
||||
});
|
||||
},
|
||||
filterApply: function() {},
|
||||
filterClear: function() {
|
||||
/* Очистить фильтр */
|
||||
let vm = this;
|
||||
vm.filter = '';
|
||||
},
|
||||
filterNote: function(note) {
|
||||
let vm = this;
|
||||
if ( vm.filter.length<1 ) {
|
||||
return true;
|
||||
}
|
||||
if ( note.title.toLowerCase().includes(vm.filter.toLowerCase()) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
getNotes: function() {
|
||||
/* Получить список заметок */
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "notes",
|
||||
"params": {
|
||||
"page": vm.pagination.page
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data) {
|
||||
vm.notes = response.data['result'];
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
showPanel: function(panel) {
|
||||
/* Показать/скрыть панель */
|
||||
panel.visible = !panel.visible;
|
||||
},
|
||||
},
|
||||
created: function() {
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
[
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "notes",
|
||||
"params": {
|
||||
"page": vm.pagination.page
|
||||
},
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "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: {
|
||||
filteredNotes: function() {
|
||||
/* Отфильтрованный список */
|
||||
let vm = this;
|
||||
var result = vm.notes.filter(vm.filterNote);
|
||||
return result;
|
||||
},
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user