Browse Source

tags from database implemented

master
Senta Mandutz 5 years ago
parent
commit
e93526c639
4 changed files with 68 additions and 2 deletions
  1. 1
    0
      public/index.html
  2. 26
    0
      public/routes/createMessage.js
  3. 2
    0
      public/routes/tagData.js
  4. 39
    2
      server/dbs.js

+ 1
- 0
public/index.html View File

<script src="routes/profil.js"></script> <script src="routes/profil.js"></script>
<script src="routes/msgCard.js"></script> <script src="routes/msgCard.js"></script>
<script src="routes/messageData.js"></script> <script src="routes/messageData.js"></script>
<script src="routes/tagData.js"></script>
<script src="routes/profilCard.js"></script> <script src="routes/profilCard.js"></script>
<script src="routes/profilData.js"></script> <script src="routes/profilData.js"></script>
<script src="routes/login.js"></script> <script src="routes/login.js"></script>

+ 26
- 0
public/routes/createMessage.js View File

.indexOf(text.toLowerCase()) >= 0 .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 () { mounted: function () {
this.list_tags();
if ($(this).bootstrapMaterialDesign) if ($(this).bootstrapMaterialDesign)
$(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);
})
}

+ 2
- 0
public/routes/tagData.js View File

_taglist = [];
_tags = [];

+ 39
- 2
server/dbs.js View File

*/ */
//put: function(req, res) {}, //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 /* Initialize requirements
* - DB connection * - DB connection

Loading…
Cancel
Save