forked from mrlynn/calhacks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontacts.html
More file actions
78 lines (71 loc) · 2.2 KB
/
contacts.html
File metadata and controls
78 lines (71 loc) · 2.2 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!-- Base Stitch Browser SDK -->
<script src='https://s3.amazonaws.com/stitch-sdks/js/bundles/4.0.14/stitch.js'></script>
<div class='results-bar'>
<p>Count of Results:</p>
<span id='num-results' class='results-bar__count'></span>
</div>
<div class='input-form'>
<label for='first_name'>First Name:</label>
<input class='form-control' name='first_name'>
<label for='last_name'>Last Name:</label>
<input class='form-control' name='last_name'>
<label for='email'>Email:</label>
<input class='form-control' name='email'>
<label for='ip_address'>IP Address:</label>
<input class='form-control' name='ip_address'>
</div>
<table class='table table-striped'>
<thead class='thead'>
<tr>
<th>Name</th>
<th>Email</th>
<th>Gender</th>
<th>IP Address</th>
</tr>
</thead>
<tbody id='contacts'></tbody>
</table>
<script lang=javascript>
const {
Stitch,
RemoteMongoClient,
UserPasswordCredential
} = stitch;
const stitchClient = Stitch.initializeDefaultAppClient('calhacks-ssiva');
login('Michael.lynn@mongodb.com', 'Password123').then(() => {
// Initialize a MongoDB Service Client
const mongodb = stitchClient.getServiceClient(
RemoteMongoClient.factory,
'mongodb-atlas'
);
// Get a hook to the employees collection
const contacts = mongodb.db('calhacks').collection('contacts');
return contacts.find({}, {
// limit: 3,
// sort: { 'salary': -1 }
})
.asArray();
})
.then(displayContacts)
function login(email, password) {
const credential = new UserPasswordCredential(email, password);
return stitchClient.auth.loginWithCredential(credential);
}
// Renders the the contacts' information in the table
function displayContacts(contacts) {
const contactsTableBody = document.getElementById('contacts');
const numResultsEl = document.getElementById('num-results');
const tableRows = contacts.map(contact => {
return `
<tr>
<td>${contact.first_name}, ${contact.last_name}</td>
<td>${contact.email}</td>
<td>${contact.gender}</td>
<td>${contact.ip_address}</td>
</tr>
`;
});
contactsTableBody.innerHTML = tableRows.join('');
numResultsEl.innerHTML = contacts.length;
}
</script>