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

@@ -1,3 +1,4 @@
var tagArray = [];
const data=[
'#th',
'#efi',
@@ -18,13 +19,15 @@ const CreateMsgRouter = {

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

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

+ 9
- 52
server/dbs.js View File

@@ -17,14 +17,13 @@ const dbs = {
* Get ALL known message ids
*/
get: function(req, res) {
model.Messages.find({}, {_id: true}).exec()
model.Messages.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 => {
@@ -40,13 +39,13 @@ const dbs = {
* Get a particular message
*/
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) {
console.log (err);
res.status(404).json(err);
} else {
//console.log(JSON.stringify(results));
res.json(results);
//console.log(JSON.stringify(result));
res.json(result);
}
});
},
@@ -63,12 +62,13 @@ const dbs = {
if ( !(req.body.tags instanceof Array) ) {
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({
subject: req.body.subject,
message: req.body.message,
user: req.body.user,
tags: req.body.tag
tag: req.body.tag
}, function(err, result) {
if (err) {
return res.status(401).json(err.message);
@@ -122,7 +122,7 @@ const dbs = {
_comment: "" },
user: { type: String, required: true,
_comment: "" },
tags: { type: [String],
tag: { type: [String],
_comment: "" },
//createtime: { type: Date, default: Date.now },
});
@@ -163,37 +163,8 @@ const dbs = {
};



/*
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){
if (err) {
console.log (err);
@@ -205,18 +176,4 @@ app.get ("/api/msg/:id", function (req, res) {
});
});
*/
/*
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;

Loading…
Cancel
Save