-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (40 loc) · 1.76 KB
/
index.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
/** Defines an angular module to handle firebase data */
var app = angular.module('mainApp', ['firebase']);
app.controller('mainCtrl', ['$scope', '$firebaseArray',
function($scope, $firebaseArray) {
var postingsRef = firebase.database().ref('/postings');
var fieldsRef = firebase.database().ref('/fields');
$scope.postings = $firebaseArray(postingsRef);
$scope.fields = $firebaseArray(fieldsRef);
// returns a boolean representing whether to display the key/value pair for this key.
// will return true unless this key equals 'name' or 'description.'
$scope.displayFieldFn = function(key) {
return (key != 'name') && (key != 'description') && (key != 'url');
};
$scope.capitalizeFirstLetterFn = function(key) {
return key.charAt(0).toUpperCase() + key.slice(1);
}
$scope.searchCriteria = {};
$scope.submittedSearch = {};
$scope.updateSearchFn = function() {
$scope.submittedSearch = $scope.searchCriteria;
$scope.searchCriteria = {};
}
$scope.displayPostingFn = function(posting) {
var search = $scope.submittedSearch;
var keys = Object.keys(search);
// return true within the some when it shouldn't be shown.
return !keys.some((key) => {
var subkeys = Object.keys(search[key]);
// only happens when it is an input field.
if (subkeys[0] == 0) {
if (!posting[key].toLowerCase().includes(search[key].toLowerCase()))
return true;
}
else {
return !subkeys.includes(posting[key]);
}
});
}
}
]);