-
Notifications
You must be signed in to change notification settings - Fork 28
/
search_service_note_content.js
48 lines (46 loc) · 1.2 KB
/
search_service_note_content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function searchServiceNoteContent (noteRegex, searchString) {
// Search the contents of service notes for specific regex content, matching a note regex title
//
// Examples:
// searchServiceNoteContent('Weak Cipher', '\\D\\D\\D-\\D.*')
//
// Usage: searchServiceNoteContent(title, search)
// Created by: Matt Burch
// Requires client-side updates: false
var projectId = Session.get('projectId')
var re = new RegExp(noteRegex, 'i')
var search = new RegExp(searchString, 'g')
var ciphers = []
var services = Services.find({
'projectId': projectId,
'notes': {
$elemMatch: {
'title': {
$regex: noteRegex,
$options: 'i'
}
}
}
}, {
notes: 1,
hostId: 1
}).fetch()
function unique(arr) {
var u = {}, a = [];
for(var i = 0, l = arr.length; i < l; ++i){
if(!u.hasOwnProperty(arr[i])) {
a.push(arr[i]);
u[arr[i]] = 1;
}
}
return a;
}
services.forEach(function (service) {
service.notes.forEach(function (note) {
if (re.test(note.title)) {
ciphers.push.apply(ciphers, note.content.match(search))
}
})
})
console.log(unique(ciphers).join("\n"))
}