-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
258 lines (236 loc) · 12.9 KB
/
index.html
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
.nav {
position:static;
top:0;
left:0;
width:100%;
min-height:30px;
background-color:#f3f3f3;
border-bottom: 1px solid #eee;
margin:0;
padding:0 0 0 30px;
}
.nav > li span {
width:30%;
min-width: 300px;
display: inline-block;
vertical-align: top;
}
.nav > li > a {
padding:0 20px;
line-height:24px;
display: block;
color:black;
text-decoration: none;
}
.nav > li:nth-child(2n+1) {
background-color: rgba(255,255,255,.8);
}
.nav > li:hover {
background-color: rgba(0,0,255,.2);
}
.nav > li.loaded span.elId {
font-weight:900;
text-transform: uppercase;
}.nav > li.LstatusT span.elId{
color:#00CC00;
}
.nav > li.LstatusF span.elId{
color:#CC0000;
}
.nav > li.long span.time {
color:#FF0000
}
.nav > li.error {
color:white;
background-color: red;
}
.heading {
text-align:center;
border-bottom:1px solid gray;
clear:both;
margin-top: 60px;
}
#results a:nth-child(2) {
float:right;
}
iframe {
border:none;
width:100%;
height: 1200px;
}
.FTAID {
font-weight:900;
}
.TAS {
background-color: rgba(255, 255, 100, .5);
}
</style>
</head>
<body>
<img id="dot" src="greydot.png" alt="dot" align="right">
<h3>Number of Successes:</h3>
<p id="Successes"></p>
<br>
<p>Create Leads are green if they have the according to the scheduled date correct status.</p>
<p>1: ComingUp, 2: Today, 3: Hanging</p>
<ol class="nav" id="nav"></ol>
<div id="results"></div>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
var Successes = 0;
var ID1 ='test1';
var ID2 ='test2';
var ID3 ='test3'
var Lengths = [171, 171, 171, 387, 0, 0, 0, 389, 389, 389, 389, 387, 387 ,387]
//Get the current Date.
var d = new Date();
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10) {dd='0'+dd}
if(mm<10) {mm='0'+mm}
today = yyyy+'-'+mm+'-'+dd+'T00:00:00';
function FText(p, index) {
var FTAID = $('<div class="FTAID"></div>').appendTo(p.$el);
var FTextArea = $('<textarea class="TAS" rows=8 cols=180></textarea>').appendTo(FTAID);
var FTextAll = 'User-Agent: Fiddler\nHost: devapidb.cloudapp.net:8863\nOrigin: Localhost\nContent-type: application/json\n'
var FTextO = p.METHOD+' '+p.url+' HTTP/1.1\n'
var FTextGD = p.METHOD+' '+p.url.slice(0, 50)+'PUT ID HERE'+p.url.slice( -28,-1)+' HTTP/1.1\n'
var text = '';
if (p.DATA) {
var DATA = JSON.stringify(p.DATA)
text = FTextO+FTextAll+'Content-Length: '+Lengths[index]+'\n'+DATA;
} else if(p.elId=='Get Lead1' || p.elId=='Get Lead2' || p.elId=='Get Lead3')
text= FTextGD+FTextAll
else if(p.elId=='Lead Delete1' || p.elId=='Lead Delete2' || p.elId=='Lead Delete3')
text= FTextGD+FTextAll+'Content-Length: '+Lengths[index]
else
text= FTextO+FTextAll+'Content-Length: '+Lengths[index]
FTextArea.val(text);
//select on click
$(".TAS").focus(function() {
var $this = $(this);
$this.select();
$this.mouseup(function() {
$this.unbind("mouseup");
return false; }); });
}
//Function to be executed for every object in data and data1.
function addOV(p, totalTime, index){
p.$el = $('<div id="'+p.elId+'"><h1 class="heading">'+p.elId+'</h1><a href="#">to top</a><div class="result"></div></div>');
$("#results").append(p.$el);
p.$link = $('<li class="LI"><a href="#'+ p.elId+'"><span class="elId">'+ p.elId +'</span>('+ p.url +')<span class="time">'+totalTime+'ms'+'</span></a></li>');
$("#nav").append(p.$link);
}
//Function to be executed if ajax call is not successful.
function FAIL(resp, status, msg, p){
p.$link.addClass('error');
var image = document.getElementById("dot");
image.src = "./reddot.png";
var fullContent = resp.responseText.replace(/\n/g, '').replace(/\>\s+\</g, '><');
var head = (fullContent.match(/\<head[^\>]*\>(.*)\<\/head\>/) || ['',''])[1];
var body = (fullContent.match(/\<body[^\>]*\>(.*)\<\/body\>/) || ['',''])[1];
var _bodyAttr = (fullContent.match(/\<body([^\>]*)\>/) || ['',''])[1];
var bodyAttr = {};
var iframe = $("<iframe>");
if (body === '') {
$('<h3></h3>').appendTo(p.$el).text(status + ": " + msg);
$("<pre></pre>").appendTo(p.$el).text(resp.responseText);
return
}
$(_bodyAttr.split(' ')).each(function(counter, x) {
if (x === "") return;
var part = x.split('=');
var key = part[0];
var value = part[1];
bodyAttr[key] = value.slice(1, value.length-1);
});
$('<h3></h3>').appendTo(p.$el).text(status + ": " + msg);
p.$el.append(iframe);
iframe.contents().find('head').html(head);
iframe.contents().find('body').attr(bodyAttr).html(body);
}
//Make p the class "loaded".
function addLoadedClass(p) {
p.$link.addClass('loaded');
Successes++;
document.getElementById("Successes").innerHTML=Successes+'/'+URLsInData;
if (Successes == URLsInData) {
var image = document.getElementById("dot");
image.src = "./greendot.png"}
}
//Show Leads in green if the Lead has the according to the scheduled date correct status, else in red.
function LeadStatus(LNum, expStatus, p, resp) {
if (p.elId == 'Create Lead'+LNum && resp.status == expStatus) {p.$link.addClass('LstatusT')}
else if(p.elId == 'Create Lead'+LNum) {p.$link.addClass('LstatusF')};
}
var data = [
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/?api_key=1234asdf23t523f5ya', 'elId': 'Create Lead1', 'ASYNC': false, 'METHOD': 'POST', 'DATA':{"Title": "Intersting Dev Project", "Description": "something about maps, payment and instagram for pets. Its going to drive conversion and customer retention", "Scheduled": "2015-01-01T01:01:01"}},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/?api_key=1234asdf23t523f5ya', 'elId': 'Create Lead2', 'ASYNC': false, 'METHOD': 'POST', 'DATA':{"Title": "Intersting Dev Project", "Description": "something about maps, payment and instagram for pets. Its going to drive conversion and customer retention", "Scheduled": today}},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/?api_key=1234asdf23t523f5ya', 'elId': 'Create Lead3', 'ASYNC': false, 'METHOD': 'POST', 'DATA':{"Title": "Intersting Dev Project", "Description": "something about maps, payment and instagram for pets. Its going to drive conversion and customer retention", "Scheduled": "2013-01-01T01:01:01"}},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/config/?api_key=1234asdf23t523f5ya', 'elId': 'Config', 'ASYNC': true, 'METHOD': 'GET'},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID1 + '/?api_key=1234asdf23t523f5ya', 'elId': 'Get Lead1', 'ASYNC': true, 'METHOD': 'GET'},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID2 + '/?api_key=1234asdf23t523f5ya', 'elId': 'Get Lead2', 'ASYNC': true, 'METHOD': 'GET'},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID3 + '/?api_key=1234asdf23t523f5ya', 'elId': 'Get Lead3', 'ASYNC': true, 'METHOD': 'GET'},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/?api_key=1234asdf23t523f5ya', 'elId': 'Edit Lead', 'ASYNC': true, 'METHOD': 'PUT', 'DATA': {"id":"leads/1","title":"Very Intersting Dev Project","created":"0001-01-01T00:00:00","phase":0,"status":0,"events":[{"id":"d08bce8d-4323-4a56-ba8b-f6a1df029e28","created":"2014-06-23T10:26:47","scheduled":"0001-01-01T00:00:00","type":0,"notes":"something about maps, payment and instagram for pets. Its going to drive conversion and customer retention","subject":null}],"contacts":null}},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/comingup?api_key=1234asdf23t523f5ya&limit=10&offset=0', 'elId': 'Coming up Leads', 'ASYNC': true, 'METHOD': 'GET', 'DATA': {"id":"leads/1","title":"Very Intersting Dev Project","created":"0001-01-01T00:00:00","phase":0,"status":0,"events":[{"id":"d08bce8d-4323-4a56-ba8b-f6a1df029e28","created":"2014-06-23T10:26:47","scheduled":"0001-01-01T00:00:00","type":0,"notes":"something about maps, payment and instagram for pets. Its going to drive conversion and customer retention","subject":null}],"contacts":null}},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/today?api_key=1234asdf23t523f5ya&limit=10&offset=0', 'elId': 'Todays Leads', 'ASYNC': true, 'METHOD': 'GET', 'DATA': {"id":"leads/1","title":"Very Intersting Dev Project","created":"0001-01-01T00:00:00","phase":0,"status":0,"events":[{"id":"d08bce8d-4323-4a56-ba8b-f6a1df029e28","created":"2014-06-23T10:26:47","scheduled":"0001-01-01T00:00:00","type":0,"notes":"something about maps, payment and instagram for pets. Its going to drive conversion and customer retention","subject":null}],"contacts":null}},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/hanging?api_key=1234asdf23t523f5ya&limit=10&offset=0', 'elId': 'Hanging Leads', 'ASYNC': true, 'METHOD': 'GET', 'DATA': {"id":"leads/1","title":"Very Intersting Dev Project","created":"0001-01-01T00:00:00","phase":0,"status":0,"events":[{"id":"d08bce8d-4323-4a56-ba8b-f6a1df029e28","created":"2014-06-23T10:26:47","scheduled":"0001-01-01T00:00:00","type":0,"notes":"something about maps, payment and instagram for pets. Its going to drive conversion and customer retention","subject":null}],"contacts":null}},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID1 + '/?api_key=1234asdf23t523f5ya', 'elId': 'Lead Delete1', 'ASYNC': true, 'METHOD': 'DELETE'},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID2 + '/?api_key=1234asdf23t523f5ya', 'elId': 'Lead Delete2', 'ASYNC': true, 'METHOD': 'DELETE'},
{'url':'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID3 + '/?api_key=1234asdf23t523f5ya', 'elId': 'Lead Delete3', 'ASYNC': true, 'METHOD': 'DELETE'}
];
//number of items with property 'url' in data
var URLsInData = 0
data.forEach(function(p){
if (p.url) {URLsInData++}
})
for (i=0; i < data.length; i++) {
(function(index) {
var p = data[index]
var ajaxTime = Date.now();
$.ajax({
url: p.url,
method: (p.METHOD),
type: 'json',
async: (p.ASYNC),
data: (p.DATA)
}).done(function(resp) {
if(!resp && p.elId != 'Lead Delete1' && p.elId != 'Lead Delete2' && p.elId != 'Lead Delete3')return;
var totalTime = Date.now()-ajaxTime;
console.log(totalTime);
addOV(p, totalTime, index);
if (totalTime > 500) {p.$link.addClass("long")}
if(p.elId == 'Create Lead1'){ID1 = resp.id;}
else if (p.elId == 'Create Lead2'){ID2 = resp.id}
else if (p.elId == 'Create Lead3'){ID3 = resp.id};
if (p.elId=='Create Lead1' || p.elId=='Create Lead2' || p.elId=='Create Lead3') {
LeadStatus(1, "ComingUp", p, resp)
LeadStatus(2, "Today", p, resp)
LeadStatus(3, "Hanging", p, resp)
};
addLoadedClass(p)
FText(p, index);
$("<pre></pre>").appendTo(p.$el).text(JSON.stringify(resp, undefined, 2));
if(p.elId == 'Create Lead3') {
data[i+2].url = 'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID1 + '/?api_key=1234asdf23t523f5ya'
data[i+3].url = 'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID2 + '/?api_key=1234asdf23t523f5ya'
data[i+4].url = 'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID3 + '/?api_key=1234asdf23t523f5ya'
data[i+9].url = 'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID1 + '/?api_key=1234asdf23t523f5ya'
data[i+10].url = 'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID2 + '/?api_key=1234asdf23t523f5ya'
data[i+11].url = 'http://devapidb.cloudapp.net:8863/0.0.1/web/leads/' + ID3 + '/?api_key=1234asdf23t523f5ya'
}
}).fail(function(resp, status, msg) {
FAIL(resp, status, msg, p);
});
})(i);
}
</script>
</body>
</html>