forked from CoInvestor/tech-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
174 lines (153 loc) · 4.41 KB
/
index.html
File metadata and controls
174 lines (153 loc) · 4.41 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html>
<head>
<title>CoInvestor Database</title>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<style type="text/css">
body {
color: black;
background-color:SlateBlue;
}
h1{
color:black;
background-color:white ;
text-align:center;
font-family: verdana;
border:2px solid Black;
}
table,td{
color:black;
background-color: white;
padding: 15px;
text-align:center;
border: 2px solid black;
}
td:hover{
color:SlateBlue;
}
th{
background-color:SlateBlue;
}
img{
display: block;
margin-left: auto;
margin-right: auto;
width: 40%;
}
</style>
</head>
<body>
<h1>CoInvestor Fund Managers</h1>
<img src = "Coinvestor-logo.jpg" alt="co-logo" width ="300" height ="200">
<br/>
<table id="table">
<tr>
<th>Name</th>
<th>Address</th>
<th>Website</th>
<th>Logo</th>
<th>Primary Sponsor Types</th>
<th>Other Sponsor Types</th>
</tr>
</table>
</body>
<script type="text/javascript">
console.log("Started!");
var Data;
// GET THE JSON DATA FROM THE API
$.getJSON('https://api.coinvestor.co.uk/v2/company/sponsor', function(data)
{
$.each(data['data'], function(key, s)
{
//console.log(s['links'].self);
//Get the indiviual companies data
$.getJSON(s['links'].self+'?include=communications,latestLogo,marketingDetail,primarySponsorType,otherSponsorTypes', function(innerData)
{
//SORT THROUGH THE DATA AND APPEND TO THE TABLE
// $.each(innerData, function(innerKey, S)
// {
//console.log(innerData);
var tr = "<tr>";
// Add Name
tr += "<td>"+innerData['data']['attributes'].name+"</td>"
// Add email address, website
for (var i = innerData['included'].length - 1; i >= 0; i--)
{
if (innerData['included'][i].type == "company_communication")
{
//email
tr += "<td><a href=\"mailto:"+innerData['included'][i]['attributes'].email+"\">"+innerData['included'][i]['attributes'].email+"</a></td>"
//website
tr += "<td><a href=\""+innerData['included'][i]['attributes'].website+"\">"+innerData['included'][i]['attributes'].website+"</td>"
}
}
// Add Logo
for (var i = innerData['included'].length - 1; i >= 0; i--)
{
if (innerData['included'][i].type == "file_manager")
{
//logo
tr += "<td><img width=\"50\" src=\""+innerData['included'][i]['attributes'].path+"\"></img></td>"
}
}
// Add Primary sponsor value
for (var i = innerData['included'].length - 1; i >= 0; i--)
{
if (innerData['included'][i].type == "sponsor_type")
{
if(innerData['included'][i].id == innerData['data']['relationships']['primarySponsorType']['data'].id)
{
//sponsor type
tr += "<td>"+innerData['included'][i]['attributes'].value+"</td>"
}
}
}
// Other Sponsors
var otherSponsors = "";
for (var i = innerData['included'].length - 1; i >= 0; i--)
{
if (innerData['included'][i].type == "sponsor_type")
{
if(innerData['included'][i].id != innerData['data']['relationships']['primarySponsorType']['data'].id)
{
//sponsor type
if (innerData['included'][i]['attributes'].value != "undefined")
otherSponsors += innerData['included'][i]['attributes'].value+", ";
}
}
}
tr += "<td>"+otherSponsors.slice(0, -2)+"</td>"+
"</tr>"
$(tr).appendTo("#table");
});
});
});
console.log("Finished");
</script>
</html>
<!-- https://api.coinvestor.co.uk/v2/company/sponsor/1?include=marketingDetail, primarySponsorType, communications, otherSponsorTypes -->
<!-- latestLogo
marketingDetail
primarySponsorType
communications
otherSponsorTypes
You would then access them via calling a URL like
Example
https://api.coinvestor.co.uk/v2/company/sponsor?include=communications -->
<!-- <body>
<h1> CoInvestor Fund Managers</h1>
<br>
<table id="table">
<tr>
<th>Name</th>
<th>Address</th>
<th>Website</th>
<th>Logo</th>
<th>Primary Sponsor Types</th>
<th>Other Sponsor Types</th>
</tr>
</table>
<br>
<br> -->