notherbase-fs 1.2.14 → 1.2.15
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/controllers/item.js
CHANGED
|
@@ -16,12 +16,11 @@ router.get("/all", async function(req, res) {
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
router.get("/
|
|
19
|
+
router.get("/", async function(req, res) {
|
|
20
20
|
try {
|
|
21
|
-
let foundItem = await items.findOne({name: req.query.name});
|
|
21
|
+
let foundItem = await items.findOne({ name: req.query.name });
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
else res.status(200).send({ foundItem: foundItem });
|
|
23
|
+
res.status(200).send({ foundItem: foundItem });
|
|
25
24
|
}
|
|
26
25
|
catch(err) {
|
|
27
26
|
res.status(500).end();
|
|
@@ -29,11 +28,27 @@ router.get("/findOne", async function(req, res) {
|
|
|
29
28
|
}
|
|
30
29
|
});
|
|
31
30
|
|
|
32
|
-
router.
|
|
31
|
+
router.post("/", async function(req, res) {
|
|
33
32
|
try {
|
|
34
|
-
|
|
33
|
+
if (!req.body.id) {
|
|
34
|
+
await items.create({
|
|
35
|
+
name: req.body.name,
|
|
36
|
+
shortDescription: req.body.shortDescription,
|
|
37
|
+
fullDescription: req.body.fullDescription
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
let foundItem = await items.findById(req.body.id);
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
if (foundItem) {
|
|
44
|
+
foundItem.name = req.body.name;
|
|
45
|
+
foundItem.shortDescription = req.body.shortDescription;
|
|
46
|
+
foundItem.fullDescription = req.body.fullDescription;
|
|
47
|
+
await foundItem.save();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
res.status(200).end();
|
|
37
52
|
}
|
|
38
53
|
catch(err) {
|
|
39
54
|
res.status(500).end();
|
|
@@ -41,13 +56,9 @@ router.get("/", async function(req, res) {
|
|
|
41
56
|
}
|
|
42
57
|
});
|
|
43
58
|
|
|
44
|
-
router.post("/", async function(req, res) {
|
|
59
|
+
router.post("/delete", async function(req, res) {
|
|
45
60
|
try {
|
|
46
|
-
await items.
|
|
47
|
-
name: req.body.name,
|
|
48
|
-
shortDescription: req.body.shortDescription,
|
|
49
|
-
fullDescription: req.body.fullDescription
|
|
50
|
-
});
|
|
61
|
+
await items.findByIdAndDelete(req.body.id);
|
|
51
62
|
|
|
52
63
|
res.status(200).end();
|
|
53
64
|
}
|
|
@@ -57,5 +68,4 @@ router.post("/", async function(req, res) {
|
|
|
57
68
|
}
|
|
58
69
|
});
|
|
59
70
|
|
|
60
|
-
|
|
61
71
|
module.exports = router;
|
package/package.json
CHANGED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
class ItemFloor {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.items = [];
|
|
4
|
+
this.$itemList = $(".floor#items ul.items");
|
|
5
|
+
this.$items = $(".floor#items ul.items li");
|
|
6
|
+
|
|
7
|
+
this.$read = $(".floor#items .editor .read");
|
|
8
|
+
this.$readName = $(".floor#items .editor .read #name");
|
|
9
|
+
this.$readShort = $(".floor#items .editor .read #short");
|
|
10
|
+
this.$readFull = $(".floor#items .editor .read #full");
|
|
11
|
+
|
|
12
|
+
this.$edit = $(".floor#items .editor .edit");
|
|
13
|
+
this.$editName = $(".floor#items .editor .edit #name");
|
|
14
|
+
this.$editShort = $(".floor#items .editor .edit #short");
|
|
15
|
+
this.$editFull = $(".floor#items .editor .edit #full");
|
|
16
|
+
|
|
17
|
+
this.selected = -1;
|
|
18
|
+
this.state = "reading";
|
|
19
|
+
|
|
20
|
+
this.updateItems();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
hasValidSelection() {
|
|
24
|
+
return (this.selected > -1 && this.selected < this.items.length);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async updateItems() {
|
|
28
|
+
try {
|
|
29
|
+
await $.get(`/item/all`, (data) => {
|
|
30
|
+
this.items = data.foundItems;
|
|
31
|
+
this.renderItemList();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch(err) {
|
|
35
|
+
console.log(err);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
renderItemList() {
|
|
40
|
+
this.$itemList.empty();
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
43
|
+
$(".floor#items ul.items").append(`<li onClick="itemFloor.selectItem(${i})">${this.items[i].name}</li>`);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
this.$items = $(".floor#items ul.items li");
|
|
47
|
+
this.selectItem(this.selected);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
createNewItem() {
|
|
51
|
+
if (this.state === "reading") {
|
|
52
|
+
this.items.push({
|
|
53
|
+
_id: null,
|
|
54
|
+
name: "New Item",
|
|
55
|
+
shortDescription: "Short Description",
|
|
56
|
+
fullDescription: "Full Description"
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
this.renderItemList();
|
|
60
|
+
this.selectItem(this.items.length - 1);
|
|
61
|
+
this.editSelectedItem();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
selectItem(index) {
|
|
66
|
+
this.$items.removeClass("selected");
|
|
67
|
+
this.selected = index;
|
|
68
|
+
|
|
69
|
+
if (index > -1) {
|
|
70
|
+
$(this.$items[index]).addClass("selected");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.readSelectedItem();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
readSelectedItem() {
|
|
77
|
+
this.cancelEdit();
|
|
78
|
+
|
|
79
|
+
if (this.hasValidSelection()) {
|
|
80
|
+
this.$readName.text(this.items[this.selected].name);
|
|
81
|
+
this.$readShort.text(this.items[this.selected].shortDescription);
|
|
82
|
+
this.$readFull.text(this.items[this.selected].fullDescription);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
this.$readName.text("Please select an item from the list.");
|
|
86
|
+
this.$readShort.text("");
|
|
87
|
+
this.$readFull.text("");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
editSelectedItem() {
|
|
92
|
+
if (this.hasValidSelection()) {
|
|
93
|
+
if (this.state != "editing") {
|
|
94
|
+
this.$read.addClass("invisible");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.state = "editing";
|
|
98
|
+
this.$edit.removeClass("invisible");
|
|
99
|
+
|
|
100
|
+
this.$editName.val(this.items[this.selected].name);
|
|
101
|
+
this.$editShort.val(this.items[this.selected].shortDescription);
|
|
102
|
+
this.$editFull.val(this.items[this.selected].fullDescription);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async saveSelectedItem() {
|
|
107
|
+
if (this.state === "editing") {
|
|
108
|
+
try {
|
|
109
|
+
await $.post("/item", {
|
|
110
|
+
id: this.items[this.selected]._id,
|
|
111
|
+
name: this.$editName.val(),
|
|
112
|
+
shortDescription: this.$editShort.val(),
|
|
113
|
+
fullDescription: this.$editFull.val(),
|
|
114
|
+
}, () => {
|
|
115
|
+
this.items[this.selected].name = this.$editName.val();
|
|
116
|
+
this.items[this.selected].shortDescription = this.$editShort.val();
|
|
117
|
+
this.items[this.selected].fullDescription = this.$editFull.val();
|
|
118
|
+
this.cancelEdit();
|
|
119
|
+
this.updateItems();
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
catch(err) {
|
|
123
|
+
console.log(err);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
cancelEdit() {
|
|
129
|
+
if (this.state === "editing") {
|
|
130
|
+
this.$edit.addClass("invisible");
|
|
131
|
+
this.$read.removeClass("invisible");
|
|
132
|
+
this.state = "reading";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async deleteSelectedItem() {
|
|
137
|
+
if (this.state === "reading" && this.hasValidSelection()) {
|
|
138
|
+
try {
|
|
139
|
+
await $.post("/item/delete", {
|
|
140
|
+
id: this.items[this.selected]._id
|
|
141
|
+
}, () => {
|
|
142
|
+
this.selectItem(-1);
|
|
143
|
+
this.updateItems();
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
catch(err) {
|
|
147
|
+
console.log(err);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let itemFloor = new ItemFloor();
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
$(".floor button#toggle").on("click", function (e) {
|
|
161
|
+
$(e.target.parentElement).find(".content").toggleClass("invisible");
|
|
162
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--bgColor: rgb(37, 37, 37);
|
|
3
|
+
--bgColorBright: rgb(66, 66, 66);
|
|
4
|
+
--shadowColor: rgb(26, 26, 26);
|
|
5
|
+
--textColor: rgb(185, 135, 69);
|
|
6
|
+
--textColorBright: rgb(221, 181, 130);
|
|
7
|
+
--standardBorder: 1px solid var(--textColor);
|
|
8
|
+
--standardRadius: 5px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.floor#items ul.items {
|
|
12
|
+
width: 40%;
|
|
13
|
+
height: 800px;
|
|
14
|
+
border: var(--standardBorder);
|
|
15
|
+
padding: 5px;
|
|
16
|
+
margin: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.floor#items ul.items li {
|
|
20
|
+
list-style: none;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.floor#items ul.items li:hover {
|
|
25
|
+
background-color: var(--bgColorBright);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.floor#items ul.items li.selected {
|
|
29
|
+
background-color: var(--shadowColor);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.floor#items .editor {
|
|
33
|
+
width: 55%;
|
|
34
|
+
height: 800px;
|
|
35
|
+
border: var(--standardBorder);
|
|
36
|
+
padding: 10px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.floor#items .read h5 {
|
|
40
|
+
margin: 10px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.floor#items .read #name {
|
|
44
|
+
margin: 20px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.floor#items .read #short {
|
|
48
|
+
width: 100%;
|
|
49
|
+
height: 100px;
|
|
50
|
+
border: var(--standardBorder);
|
|
51
|
+
padding: 2px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.floor#items .read #full {
|
|
55
|
+
width: 100%;
|
|
56
|
+
height: 250px;
|
|
57
|
+
border: var(--standardBorder);
|
|
58
|
+
padding: 2px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.floor#items .edit h5 {
|
|
62
|
+
margin: 10px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
.floor {
|
|
67
|
+
width: 100%;
|
|
68
|
+
min-height: 50px;
|
|
69
|
+
border: 1px solid var(--shadowColor);
|
|
70
|
+
background-color: var(--bgColor);
|
|
71
|
+
padding: 10px;
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: flex-start;
|
|
74
|
+
justify-content: center;
|
|
75
|
+
flex-wrap: wrap;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.floor h2 {
|
|
79
|
+
width: 90%;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.floor button {
|
|
83
|
+
margin: 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.floor .content {
|
|
87
|
+
width: 100%;
|
|
88
|
+
display: flex;
|
|
89
|
+
align-items: flex-start;
|
|
90
|
+
justify-content: center;
|
|
91
|
+
flex-wrap: wrap;
|
|
92
|
+
}
|
|
@@ -11,6 +11,50 @@
|
|
|
11
11
|
|
|
12
12
|
<hr>
|
|
13
13
|
|
|
14
|
+
<section class="floor" id="items">
|
|
15
|
+
<h2>Items</h2>
|
|
16
|
+
<button id="toggle">Toggle</button>
|
|
17
|
+
|
|
18
|
+
<div class="content invisible">
|
|
19
|
+
<ul class="items">
|
|
20
|
+
|
|
21
|
+
</ul>
|
|
22
|
+
|
|
23
|
+
<div class="editor">
|
|
24
|
+
<div class="edit invisible">
|
|
25
|
+
<h5>Item Name:</h5>
|
|
26
|
+
<input type="text" id="name">
|
|
27
|
+
|
|
28
|
+
<h5>Short Item Description:</h5>
|
|
29
|
+
<textarea id="short" name="short" cols="30" rows="3"></textarea>
|
|
30
|
+
|
|
31
|
+
<h5>Full Item Description:</h5>
|
|
32
|
+
<textarea id="full" name="full" cols="30" rows="10"></textarea>
|
|
33
|
+
|
|
34
|
+
<button id="cancel" onclick="itemFloor.cancelEdit()">Cancel</button>
|
|
35
|
+
<button id="save" onclick="itemFloor.saveSelectedItem()">Save</button>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div class="read">
|
|
39
|
+
<h5 id="name">Item Name</h5>
|
|
40
|
+
|
|
41
|
+
<h5>Short Item Description:</h5>
|
|
42
|
+
<p id="short"></p>
|
|
43
|
+
|
|
44
|
+
<h5>Full Item Description:</h5>
|
|
45
|
+
<p id="full"></p>
|
|
46
|
+
|
|
47
|
+
<button id="new" onclick="itemFloor.createNewItem()">Create New</button>
|
|
48
|
+
<button id="edit" onclick="itemFloor.editSelectedItem()">Edit</button>
|
|
49
|
+
<button id="delete" onclick="itemFloor.deleteSelectedItem()">Delete</button>
|
|
50
|
+
<button id="refresh" onclick="itemFloor.updateItems()">Refresh List</button>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</section>
|
|
55
|
+
|
|
56
|
+
<hr>
|
|
57
|
+
|
|
14
58
|
<a href="/the-front" class="to">
|
|
15
59
|
Go to The Front
|
|
16
60
|
</a>
|