<div class="om-header-container"> | <div class="om-header-container"> | ||||
<div class="om-header"> | <div class="om-header"> | ||||
<a class="logo-img" href="index.html"><img src="img/app_icon.png" width=45px height=45px></a> | <a class="logo-img" href="index.html"><img src="img/app_icon.png" width=45px height=45px></a> | ||||
<form class="om-searchbar"> | |||||
<form class="om-searchbar" @submit.prevent="search()"> | |||||
<b-field> | <b-field> | ||||
<b-input | <b-input | ||||
type="search" | type="search" | ||||
v-model="searchtext" | |||||
icon="magnify" | icon="magnify" | ||||
placeholder="Suche..."> | placeholder="Suche..."> | ||||
</b-input> | </b-input> | ||||
var app = new Vue({ | var app = new Vue({ | ||||
router, | router, | ||||
el: '#api', | el: '#api', | ||||
data: { | |||||
data: function() { | |||||
return{ | |||||
searchtext: "ipsum", | |||||
}; | |||||
}, | }, | ||||
methods: { | methods: { | ||||
} | |||||
search: function() { | |||||
console.log("Searchtext: " +this.searchtext); | |||||
$.ajax({ | |||||
url: "api/msg/search/" + this.searchtext, | |||||
method: "GET" | |||||
}).done(jd => { | |||||
// NICHT SO wg. Vue: _messagelist = jd; | |||||
_messagelist.splice(0, _messagelist.length); | |||||
_messagelist.push.apply(_messagelist, jd); | |||||
//console.log("jd: "+jd); | |||||
for (var e in jd) { | |||||
if (!_messages[jd[e]]) { | |||||
get_insert_message(jd[e]); | |||||
} | |||||
} | |||||
}).fail(function(e, f, g) { | |||||
console.log("searching: err: " + e + f + g); | |||||
}) | |||||
} | |||||
}, | |||||
mounted: function () { | |||||
//this.search(); | |||||
}, | |||||
}); | }); | ||||
const search_data = []; | const search_data = []; | ||||
/* | /* | ||||
export.default { | export.default { |
// Wait until page loaded | // Wait until page loaded | ||||
window.addEventListener('load', () => { | window.addEventListener('load', () => { | ||||
if ('serviceWorker' in navigator) { | |||||
/*if ('serviceWorker' in navigator) { | |||||
// NOTE: ServiceWorker Registration | // NOTE: ServiceWorker Registration | ||||
return navigator.serviceWorker.register('serviceWorker.js', { | return navigator.serviceWorker.register('serviceWorker.js', { | ||||
scope: '/' | scope: '/' | ||||
} else { | } else { | ||||
console.log('[ServiceWorker] are not supported.'); | console.log('[ServiceWorker] are not supported.'); | ||||
return; | return; | ||||
} | |||||
}*/ | |||||
}); | }); | ||||
// NOTE: Set Bootstrap materialdesign | // NOTE: Set Bootstrap materialdesign |
}); | }); | ||||
}, | }, | ||||
}, | }, | ||||
"msg/search": {}, | |||||
"msg/search": { | |||||
params: ":phrase", | |||||
/* GET /api/msg/id/[massage-id] | |||||
* -> Message schema | |||||
* Get a particular message | |||||
*/ | |||||
get: function(req, res) { | |||||
model.Messages.find({$text: {$search: req.params.phrase}}) | |||||
.exec().then(results => { | |||||
//selects id from message: | |||||
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); | |||||
}); | |||||
}, | |||||
}, | |||||
"msg": { | "msg": { | ||||
/* POST /api/msg | /* POST /api/msg | ||||
* <- Message schema | * <- Message schema | ||||
_comment: "" }, | _comment: "" }, | ||||
//createtime: { type: Date, default: Date.now }, | //createtime: { type: Date, default: Date.now }, | ||||
}); | }); | ||||
messageSchema.index({ tag:'text' }); | |||||
messageSchema.index({ tag:'text', subject:'text', message:'text', user:'text' }); | |||||
model.Messages = common.mongoose.model('messages', messageSchema); | model.Messages = common.mongoose.model('messages', messageSchema); | ||||
model.Messages._list = [ "" ]; | model.Messages._list = [ "" ]; | ||||