diff --git a/public/index.html b/public/index.html
index 92b3ca8..0c82b3e 100644
--- a/public/index.html
+++ b/public/index.html
@@ -84,6 +84,7 @@
+
diff --git a/public/routes/createMessage.js b/public/routes/createMessage.js
index 2ed475c..9f37a4b 100644
--- a/public/routes/createMessage.js
+++ b/public/routes/createMessage.js
@@ -88,9 +88,35 @@ const CreateMsgRouter = {
.indexOf(text.toLowerCase()) >= 0
})
},
+ list_tags: function () {
+ $.ajax({url: "api/tag/ids",method: "GET"})
+ .done(jd => {
+ // NICHT SO wg. Vue: _messagelist = jd;
+ _taglist.splice(0, _taglist.length);
+ _taglist.push.apply(_taglist, jd);
+ console.log("tag: jd: " + jd);
+ for (var e in jd) {
+ if (!_tags[jd[e]]) {
+ get_insert_tag(jd[e]);
+ }
+ }
+ }).fail(function (e, f, g) {
+ console.log("err: " + e + f + g);
+ });
+ }
},
mounted: function () {
+ this.list_tags();
if ($(this).bootstrapMaterialDesign)
$(this).bootstrapMaterialDesign();
},
};
+
+function get_insert_tag(id){
+ $.ajax({ url: "api/tag/"+id, method: "GET" }).done(function (tag) {
+ data.push(tag.name);
+ console.log("it worked!");
+ }).fail(function (e, f, g) {
+ console.log("cannot load " + id + ".json: " + e + f + g);
+ })
+}
diff --git a/public/routes/tagData.js b/public/routes/tagData.js
new file mode 100644
index 0000000..3ef34ad
--- /dev/null
+++ b/public/routes/tagData.js
@@ -0,0 +1,2 @@
+_taglist = [];
+_tags = [];
diff --git a/server/dbs.js b/server/dbs.js
index 9be9ebc..b882189 100644
--- a/server/dbs.js
+++ b/server/dbs.js
@@ -87,8 +87,45 @@ const dbs = {
*/
//put: function(req, res) {},
},
- "tag/ids": {},
- "tag": {},
+ "tag/ids": {
+ /* GET /api/tag/ids [no args]
+ * -> Array of tag schema object ids
+ * Get ALL known tag ids
+ */
+ get: function(req, res) {
+ model.Tags.find({},{_id: true}).exec()
+ .then(results => {
+ //selects id from tag:
+ var parsed = [];
+ for (var i in results) {
+ parsed.push (results[i]._id);
+ }
+ res.send(parsed);
+ } )
+ .catch(err => {
+ console.log (err);
+ res.status(500).json(err);
+ });
+ },
+ },
+ "tag": {
+ params: ":id",
+ /* GET /api/tag/[tag-id]
+ * -> Tag schema
+ * Get a particular tag
+ */
+ get: function(req, res) {
+ model.Tags.findById(req.params.id) .exec(function(err, result) {
+ if (err) {
+ console.log (err);
+ res.status(404).json(err);
+ } else {
+ //console.log(JSON.stringify(result));
+ res.json(result);
+ }
+ });
+ },
+ },
},
/* Initialize requirements
* - DB connection