@lexho111/plainblog 0.5.27 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Article.js +73 -4
- package/Blog.js +348 -149
- package/Formatter.js +5 -12
- package/README.md +5 -1
- package/{blog → blog_test_empty.db} +0 -0
- package/blog_test_load.db +0 -0
- package/build-scripts.js +54 -0
- package/coverage/clover.xml +1043 -0
- package/coverage/coverage-final.json +20 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +161 -0
- package/coverage/lcov-report/package/Article.js.html +406 -0
- package/coverage/lcov-report/package/Blog.js.html +2635 -0
- package/coverage/lcov-report/package/Formatter.js.html +379 -0
- package/coverage/lcov-report/package/build-scripts.js.html +247 -0
- package/coverage/lcov-report/package/build-styles.js.html +367 -0
- package/coverage/lcov-report/package/index.html +191 -0
- package/coverage/lcov-report/package/model/APIModel.js.html +190 -0
- package/coverage/lcov-report/package/model/ArrayList.js.html +382 -0
- package/coverage/lcov-report/package/model/ArrayListHashMap.js.html +379 -0
- package/coverage/lcov-report/package/model/BinarySearchTree.js.html +856 -0
- package/coverage/lcov-report/package/model/BinarySearchTreeHashMap.js.html +346 -0
- package/coverage/lcov-report/package/model/DataModel.js.html +307 -0
- package/coverage/lcov-report/package/model/DatabaseModel.js.html +232 -0
- package/coverage/lcov-report/package/model/FileAdapter.js.html +394 -0
- package/coverage/lcov-report/package/model/FileList.js.html +244 -0
- package/coverage/lcov-report/package/model/FileModel.js.html +358 -0
- package/coverage/lcov-report/package/model/SequelizeAdapter.js.html +538 -0
- package/coverage/lcov-report/package/model/SqliteAdapter.js.html +247 -0
- package/coverage/lcov-report/package/model/datastructures/ArrayList.js.html +439 -0
- package/coverage/lcov-report/package/model/datastructures/ArrayListHashMap.js.html +196 -0
- package/coverage/lcov-report/package/model/datastructures/BinarySearchTree.js.html +913 -0
- package/coverage/lcov-report/package/model/datastructures/BinarySearchTreeHashMap.js.html +346 -0
- package/coverage/lcov-report/package/model/datastructures/FileList.js.html +244 -0
- package/coverage/lcov-report/package/model/datastructures/index.html +176 -0
- package/coverage/lcov-report/package/model/index.html +206 -0
- package/coverage/lcov-report/package/utilities.js.html +511 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +2063 -0
- package/index.js +25 -1
- package/model/DataModel.js +79 -0
- package/model/DatabaseModel.js +20 -8
- package/model/FileAdapter.js +43 -4
- package/model/FileModel.js +47 -9
- package/model/SequelizeAdapter.js +11 -3
- package/model/datastructures/ArrayList.js +118 -0
- package/model/datastructures/ArrayListHashMap.js +37 -0
- package/model/datastructures/ArrayListHashMap.js.bk +90 -0
- package/model/datastructures/BinarySearchTree.js +276 -0
- package/model/datastructures/BinarySearchTreeHashMap.js +89 -0
- package/model/datastructures/BinarySearchTreeTest.js +16 -0
- package/model/datastructures/FileList.js +53 -0
- package/package.json +11 -2
- package/postinstall.js +89 -0
- package/public/fetchData.js +0 -0
- package/public/scripts.min.js +2 -1
- package/public/styles.min.css +2 -2
- package/src/fetchData.js +150 -30
- package/src/styles.css +47 -0
- package/utilities.js +142 -0
package/Article.js
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
export default class Article {
|
|
2
|
-
constructor(title, content, createdAt) {
|
|
2
|
+
constructor(id, title, content, createdAt) {
|
|
3
|
+
this.id = id;
|
|
3
4
|
this.title = title;
|
|
4
5
|
this.content = content;
|
|
5
|
-
this.createdAt = createdAt;
|
|
6
|
+
this.createdAt = new Date(createdAt).getTime();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static createNew(title, content, createdAt = new Date()) {
|
|
10
|
+
const id = this.getNextID(); // Your existing ID generator
|
|
11
|
+
//const createdAt = new Date();
|
|
12
|
+
return new Article(id, title, content, createdAt);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static nextID = 100;
|
|
16
|
+
static getNextID() {
|
|
17
|
+
// TODO fix use nextID from BlogTreeSearch!
|
|
18
|
+
this.nextID++;
|
|
19
|
+
return Math.floor(Math.random() * 100000000);
|
|
6
20
|
}
|
|
7
21
|
|
|
8
22
|
getContent() {
|
|
9
23
|
return this.content;
|
|
10
24
|
}
|
|
11
25
|
|
|
26
|
+
getContentVeryShort() {
|
|
27
|
+
if (!this.content) return;
|
|
28
|
+
if (this.content.length < 50) return this.getContent();
|
|
29
|
+
let contentShort = this.content.substring(0, 50);
|
|
30
|
+
contentShort += "...";
|
|
31
|
+
return contentShort;
|
|
32
|
+
}
|
|
33
|
+
|
|
12
34
|
getContentShort() {
|
|
13
35
|
if (this.content.length < 400) return this.getContent();
|
|
14
36
|
let contentShort = this.content.substring(0, 400);
|
|
@@ -26,13 +48,60 @@ export default class Article {
|
|
|
26
48
|
return `${year}/${month}/${day} ${hours}:${minutes}`;
|
|
27
49
|
}
|
|
28
50
|
|
|
29
|
-
toHTML() {
|
|
51
|
+
toHTML(loggedin = false) {
|
|
52
|
+
if (this.content == null) return "";
|
|
30
53
|
const moreButton = this.content.length > 400 ? `<a href="#">more</a>` : "";
|
|
31
|
-
|
|
54
|
+
const buttons = loggedin
|
|
55
|
+
? `<div class="buttons"><div id="editButton${this.id}" class="button edit">edit</div><div id="deleteButton${this.id}" class="button delete">delete</div></div>`
|
|
56
|
+
: "";
|
|
57
|
+
const script = loggedin
|
|
58
|
+
? `<script>
|
|
59
|
+
if (typeof window.handleAction !== 'function') {
|
|
60
|
+
window.handleAction = function(action, id) {
|
|
61
|
+
if (action === 'delete') {
|
|
62
|
+
if (confirm("Delete this article?")) {
|
|
63
|
+
fetch("/api/articles?id=" + id, { method: "DELETE" })
|
|
64
|
+
.then(res => { if(res.ok) window.location.reload(); else alert("Error: " + res.statusText); });
|
|
65
|
+
}
|
|
66
|
+
} else if (action === 'edit') {
|
|
67
|
+
const title = prompt("New Title");
|
|
68
|
+
const content = prompt("New Content");
|
|
69
|
+
if (title && content) {
|
|
70
|
+
fetch("/api/articles?id=" + id, {
|
|
71
|
+
method: "PUT",
|
|
72
|
+
body: JSON.stringify({ title, content })
|
|
73
|
+
}).then(res => { if(res.ok) window.location.reload(); else alert("Error: " + res.statusText); });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function clickListener(button) {
|
|
79
|
+
const mybutton = document.getElementById(button);
|
|
80
|
+
const action = button.includes("edit") ? "edit" : "delete";
|
|
81
|
+
|
|
82
|
+
// Mouse/Touch support
|
|
83
|
+
mybutton.addEventListener('click', () => window.handleAction(action, ${this.id}));
|
|
84
|
+
|
|
85
|
+
// Keyboard support
|
|
86
|
+
mybutton.addEventListener('keydown', (event) => {
|
|
87
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
88
|
+
event.preventDefault(); // Prevents page scrolling on Space
|
|
89
|
+
window.handleAction(action, ${this.id});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
clickListener("editButton${this.id}");
|
|
94
|
+
clickListener("deleteButton${this.id}");
|
|
95
|
+
</script>`
|
|
96
|
+
: "";
|
|
97
|
+
// prettier-ignore
|
|
98
|
+
return `<article data-id="${this.id}" data-date="${this.createdAt}">
|
|
99
|
+
${buttons}
|
|
32
100
|
<h2>${this.title}</h2>
|
|
33
101
|
<span class="datetime">${this.getFormattedDate()}</span>
|
|
34
102
|
<p>${this.getContentShort()}</p>
|
|
35
103
|
${moreButton}
|
|
104
|
+
${script}
|
|
36
105
|
</article>`;
|
|
37
106
|
}
|
|
38
107
|
}
|