-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
76 lines (72 loc) · 1.91 KB
/
main.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
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
var app = angular.module("infodb", ["ngMessages", "ngMaterial"]);
app.config(function($mdThemingProvider) {
$mdThemingProvider.theme('default')
.primaryPalette("indigo")
.accentPalette("blue");
});
app.controller("main", function($scope, $http){
$scope.query = {
person: {},
movie: {
productionYearComp: "during"
},
dos: {
status: "idle",
doSearch: function(){
if(!this.name1 || !this.name2) return false;
$scope.query.dos.status = "loading";
$http.get("/api/getDOS.php", {
params: {
id1: this.name1.id,
id2: this.name2.id
}
})
.then(function(res){
if(!res.data.found){
$scope.query.dos.status = "not-found";
return false;
}
$scope.query.dos.status = "success";
var list = [];
for(var i = 0; i < res.data.celebrities.length; i++){
var entry = res.data.celebrities[i];
entry.type = "celebrity";
list[i * 2] = entry;
}
for(var i = 0; i < res.data.cinematographies.length; i++){
var entry = res.data.cinematographies[i];
entry.type = "cinematography";
list[i * 2 + 1] = entry;
}
$scope.query.dos.results = list;
$scope.query.dos.resultsMeta = {
sourceName: list[0].firstName + " " + list[0].lastName,
targetName: list[list.length - 1].firstName + " " + list[list.length - 1].lastName,
degrees: res.data.celebrities.length - 1
};
})
.catch(function(){
$scope.query.dos.status = "failed";
});
}
},
helpers: {
queryPersonId: function(name){
return $http.get("/api/getId.php", {
params: {type: "person", name: name}
})
.then(function(res){
return res.data;
});
},
goToInfo: function(type, id){
switch(type){
case "celebrity":
window.open("/info/person/?id=" + id, "_blank"); break;
case "cinematography":
window.open("/info/movie/?id=" + id, "_blank"); break;
}
}
}
};
});