Browse Source

everything i working

pull/1/head
Senta Mandutz 5 years ago
parent
commit
31f1add35d
4 changed files with 44 additions and 18 deletions
  1. 10
    0
      message.model.js
  2. 7
    7
      public/createMessage.js
  3. 1
    0
      public/home.js
  4. 26
    11
      server.js

+ 10
- 0
message.model.js View File

const mongoose = require('mongoose'); const mongoose = require('mongoose');


//const Schema = mongoose.Schema,
//ObjectId = Schema.ObjectId;

const MessageSchema = mongoose.Schema({ const MessageSchema = mongoose.Schema({
//_id: ObjectId,
/*id: {
type: String,
getter: function(val) { return this._id.toString(); },
unique: true
},*/
//id: {type: String, required: true},
subject: { type: String, required: true }, subject: { type: String, required: true },
message: { type: String, required: true }, message: { type: String, required: true },
user: { type: String, required: true }, user: { type: String, required: true },

+ 7
- 7
public/createMessage.js View File

<form class="new-msg-form" @submit.prevent=createMsg> <form class="new-msg-form" @submit.prevent=createMsg>
<div class="form-group bmd-form-group"> <div class="form-group bmd-form-group">
<label class="bmd-label-floating">Betreff</label> <label class="bmd-label-floating">Betreff</label>
<input type="text" class="form-control" id="subject">
<input type="text" class="form-control" id="subject" value="WICHTIG!">
</div> </div>
<div class="form-group bmd-form-group"> <div class="form-group bmd-form-group">
<label class="bmd-label-floating">Tags</label> <label class="bmd-label-floating">Tags</label>
<input type="text" class="form-control" id="tag">
<input type="text" class="form-control" id="tag" value="#efi">
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="bmd-label-floating">Nachricht</label> <label class="bmd-label-floating">Nachricht</label>
<textarea class="form-control" id="message" rows="5"></textarea>
<textarea class="form-control" id="message" rows="5">Nachricht</textarea>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="bmd-label-floating">User</label> <label class="bmd-label-floating">User</label>
<textarea class="form-control" id="user"></textarea>
<input type="text" class="form-control" id="user" value="Dito27">
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="checkbox">
var message=$("#message").val(); var message=$("#message").val();
var tag=$("#tag").val(); var tag=$("#tag").val();
var user=$("#user").val(); var user=$("#user").val();
console.log ("Message Created: "+id+" "+tag+" "+message+" "+user);
$.ajax ({ url: "/api/createMsg", data: {subject: subject, tag: tag, message: message, user: user}, method: "POST" }) .done (have_result) .fail (have_error);
console.log ("Message Created: "+tag+" "+message+" "+user);
$.ajax ({ url: "/api/createMsg", data: {sub: subject, mess: message, use: user, ta: tag}, method: "POST" }) .done (have_result) .fail (have_error);
function have_result (res) { function have_result (res) {
console.log (res); console.log (res);
} }
function have_error (err) { function have_error (err) {
console.log ("error:" + err.responseText);
console.log ("error: " + err.responseText);
console.log (err); console.log (err);
} }
}, },

+ 1
- 0
public/home.js View File

// NICHT SO wg. Vue: _messagelist = jd; // NICHT SO wg. Vue: _messagelist = jd;
_messagelist.splice(0, _messagelist.length); _messagelist.splice(0, _messagelist.length);
_messagelist.push.apply(_messagelist, jd); _messagelist.push.apply(_messagelist, jd);
console.log("jd: "+jd);
for (var e in jd) { for (var e in jd) {
if (!_messages[jd[e]]) { if (!_messages[jd[e]]) {
get_insert_message(jd[e]); get_insert_message(jd[e]);

+ 26
- 11
server.js View File



//require('./app/routes/message.route.js')(app); //require('./app/routes/message.route.js')(app);



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


function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

for (var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));

return text;
}

app.post("/api/createMsg", function(req, res){ app.post("/api/createMsg", function(req, res){
var message = new Message(req.body);
//x = mongoose.Types.ObjectId();
//y = x.toString();
//var z = makeid();
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){ message.save(function(err,result){
if(err)
return res .status(401) .send(err.message);

res.json({message: "Message created!!"});
if(err){
return res .status(401) .send(err.message);
}else{
res.json({message: "Message created!!"});
}
}); });
}); });



Loading…
Cancel
Save