Browse Source

Fix: tags were not visible on "home" page -> solved

master
Erik Römmelt 5 years ago
parent
commit
cad0230c47
2 changed files with 18 additions and 54 deletions
  1. 9
    2
      public/routes/createMessage.js
  2. 9
    52
      server/dbs.js

+ 9
- 2
public/routes/createMessage.js View File

var tagArray = [];
const data=[ const data=[
'#th', '#th',
'#efi', '#efi',


<b-field label="Tags"> <b-field label="Tags">
<b-taginput <b-taginput
id="tag"
v-model="selected" v-model="selected"
:data=taglist :data=taglist
autocomplete autocomplete
allow-new:false allow-new:false
icon="label" icon="label"
placeholder="#" placeholder="#"
@typing="getFilteredTags" id="tag">
@typing="getFilteredTags"
@input="saveTagsToArray">
</b-taginput> </b-taginput>
</b-field> </b-field>


}; };
}, },
methods: { methods: {
saveTagsToArray: function() {
tagArray = this.selected;
console.info(tagArray);
},
createMsg: function () { createMsg: function () {
var _subject = $("#subject").val(); var _subject = $("#subject").val();
var _message = $("#message").val(); var _message = $("#message").val();
var _tag = $("#tag").val();
var _tag = tagArray;
var _user = $("#user").val(); var _user = $("#user").val();
//console.log("Message Created: " + _tag + " " + _message + " " + _user); //console.log("Message Created: " + _tag + " " + _message + " " + _user);
$.ajax({ $.ajax({

+ 9
- 52
server/dbs.js View File

* Get ALL known message ids * Get ALL known message ids
*/ */
get: function(req, res) { get: function(req, res) {
model.Messages.find({}, {_id: true}).exec()
model.Messages.find({},{_id: true}).exec()
.then(results => { .then(results => {
//selects id from message: //selects id from message:
var parsed = []; var parsed = [];
for (var i in results) { for (var i in results) {
parsed.push (results[i]._id); parsed.push (results[i]._id);
} }
//var parsed = results.map (x => x._id);
res.send(parsed); res.send(parsed);
} ) } )
.catch(err => { .catch(err => {
* Get a particular message * Get a particular message
*/ */
get: function(req, res) { get: function(req, res) {
model.Messages.findById(req.params.id) .exec(function(err, results) {
model.Messages.findById(req.params.id) .exec(function(err, result) {
if (err) { if (err) {
console.log (err); console.log (err);
res.status(404).json(err); res.status(404).json(err);
} else { } else {
//console.log(JSON.stringify(results));
res.json(results);
//console.log(JSON.stringify(result));
res.json(result);
} }
}); });
}, },
if ( !(req.body.tags instanceof Array) ) { if ( !(req.body.tags instanceof Array) ) {
return res.status(400).json({ error: "bad request" }); return res.status(400).json({ error: "bad request" });
}*/ }*/
console.log("Subject: "+JSON.stringify(req.body));
//console.log("Subject: "+JSON.stringify(req.body));

model.Messages.create({ model.Messages.create({
subject: req.body.subject, subject: req.body.subject,
message: req.body.message, message: req.body.message,
user: req.body.user, user: req.body.user,
tags: req.body.tag
tag: req.body.tag
}, function(err, result) { }, function(err, result) {
if (err) { if (err) {
return res.status(401).json(err.message); return res.status(401).json(err.message);
_comment: "" }, _comment: "" },
user: { type: String, required: true, user: { type: String, required: true,
_comment: "" }, _comment: "" },
tags: { type: [String],
tag: { type: [String],
_comment: "" }, _comment: "" },
//createtime: { type: Date, default: Date.now }, //createtime: { type: Date, default: Date.now },
}); });
}; };





/* /*
app.get ('/api/ids', function (req, res) {
Message.find({},{id: true}) .exec () .then(results => {
//selects id from message:
var parsed = [];
for (var i in results) {
parsed.push (results[i].id);
}
//var parsed = results.map (x => x._id);
res.send(parsed);
} )
.catch(err => {
console.log (err);
res .status(500) .json (err);
});
});

app.get ("/api/msg/:id", function (req, res) {
Message.findOne ({_id: req.params.id}) .exec (function (err, results){
if (err) {
console.log (err);
res .status(404) .json (err);
} else {
console.log(JSON.stringify(results));
res.json(results);
}
});
});

/*app.get ("/api/msg/search/:phrase", function (req, res) {
app.get ("/api/msg/search/:phrase", function (req, res) {
Message.find ({$text: {$search: req.params.phrase}) .then (function (err, results){ Message.find ({$text: {$search: req.params.phrase}) .then (function (err, results){
if (err) { if (err) {
console.log (err); console.log (err);
}); });
}); });
*/ */
/*
app.post("/api/createMsg", function(req, res){
console.log("Subject: "+JSON.stringify(req.body));
var message = new Message( {subject: req.body.sub, message: req.body.mess, user: req.body.use, tag: req.body.ta } );

message.save(function(err,result){
if(err){
return res .status(401) .send(err.message);
}else{
res.json({message: "Message created!!"});
}
});
});
*/
module.exports = dbs; module.exports = dbs;

Loading…
Cancel
Save