-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.html
269 lines (230 loc) · 9.92 KB
/
draw.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
259
260
261
262
263
264
265
266
267
268
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>:: AWSOMEDAY 2018 :: Seoul Summit</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="static/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Custom styles for this template -->
<link href="static/css/awsomeday.css" rel="stylesheet">
<!-- Fontawesome for vectorized icons -->
<script defer src="static/js/all.js"></script>
<!-- AWS SDK -->
<script src="static/js/aws-sdk-2.222.1.min.js"></script>
<!-- jQuery JavaScript -->
<script src="static/js/jquery-3.3.1.min.js"></script>
<script>
//TODO #1: Update <YUOR-REGION-CODE> to your actual region code. (ex:ap-northeast-2)
AWS.config.region = "<YUOR-REGION-CODE>";
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
//TODO #2: Update <YOUR-COGNITO-IDENTITY-POOL-ID> to your actual pool id.
IdentityPoolId: "<YOUR-COGNITO-IDENTITY-POOL-ID>"
});
//Winner draw function:
//The first 100 applicants will be selected from total the applicants,
//and one of them will be selected.
function draw() {
$("#gift").hide();
$("#spinner").show();
var resultName;
var resultPhone;
var resultUserAgent;
var docClient = new AWS.DynamoDB.DocumentClient();
var params = {
//TODO #3:
TableName: "awsomeday-03",
Select: "ALL_ATTRIBUTES",
FilterExpression : "answer = :val",
ExpressionAttributeValues : {":val" : true},
Limit : 100,
ScanIndexForward: "true"
};
docClient.scan(params, function(err, data) {
if (err) {
$("#gift").show();
$("#spinner").hide();
msgbox("Please try it again.");
} else {
var lists = "";
if(data.Items.length != 0)
for(var idx in data.Items) {
var value = data.Items[idx];
//alert(value.date);
lists = lists + idx+":"+value.date + ":"+value.name +"\n";
// Determine winner using random number generation within top 100 person.
var win = getRandomIntInclusive(0, idx);
resultName = data.Items[win].name;
resultPhone = data.Items[win].phoneNum;
resultUserAgent = data.Items[win].userAgent;
$("#resultValue").html(
"<div style='margin-left: 30px;'><table>" +
"<tr><td width='50%'><h2><i class='fas fa-user'></i> Name </h2> </td><td width='50%'><h2> : "+resultName+"</h2></td></tr>" +
"<tr><td width='50%'><h2><i class='fas fa-mobile-alt'></i> Last digits </h2></td><td width='50%'><h2> : "+resultPhone+"</h2></td></tr>" +
"</table>" +
"<div>" +
"<p style='color:gray;font-size:8px' class='align-center'> " + resultUserAgent +"</p>" +
"</div>" +
"<img class='img-responsive' style='width:90%' src='gift.png'>" +
"</div>"
);
setTimeout(function(){
$("#spinner").hide();
$("#draw").hide();
$("#congrast").show();
$("#result").show().fadeIn("slow");
},1000);
}
//No applicant..
else {
$("#gift").show();
$("#spinner").hide();
msgbox("There is no applicant.");
return;
}
}
});
}
//Random number generator
function getRandomIntInclusive(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
//customized bootbox.alert function
function msgbox(msg) {
bootbox.alert({
message: msg,
size: 'small'
}).find('.modal-content').css({
'margin-top': function (){
var w = $( window ).height();
var b = $(".modal-dialog").height();
// should not be (w-h)/2
var h = ((w-b)/2)-50;
return h+"px";
}
});
}
</script>
</head>
<body class="bg-dark">
<div class="container py-5">
<div class="row">
<div class="col-md-12">
<h2 class="text-center text-white mb-4"><i class="fab fa-aws"></i> <strong>AWS</strong>OME<strong>DAY</strong> 2018</h2>
<div class="row">
<div class="col-md-6 mx-auto">
<!-- form card login -->
<div class="card rounded">
<div class="card-header">
<h3 class="text-center mb-0 ">Quiz#1 : Drawing lots!</h3>
</div>
<div class="card-body">
<div id="gift" align="center">
<i class="fas fa-gift fa-10x"></i>
<p></p>
</div>
<div id="result" align="center" style="display: none;">
<p id="resultValue" align="left"></p>
</div>
<!-- Begin of Spinner (from : https://loading.io/ -->
<div id="spinner" style="display: none;" class="lds-css ng-scope" align="center"><div style="width:100%;height:100%" class="lds-radio"><div></div><div></div><div></div></div><style type="text/css">@keyframes lds-radio {
0% {
opacity: 0;
}
20% {
opacity: 1;
}
100% {
opacity: 1;
}
}
@-webkit-keyframes lds-radio {
0% {
opacity: 0;
}
20% {
opacity: 1;
}
100% {
opacity: 1;
}
}
.lds-radio {
position: relative;
}
.lds-radio div {
position: absolute;
}
.lds-radio div:nth-child(1) {
width: 44px;
height: 44px;
left: 34px;
top: 128px;
border-radius: 50%;
background: #1d3f72;
-webkit-animation: lds-radio 1s linear infinite;
animation: lds-radio 1s linear infinite;
}
.lds-radio div:nth-child(2) {
width: 66px;
height: 66px;
left: 56px;
top: 84px;
border-radius: 0 66px 0 0;
border: 20px solid #5699d2;
background: none;
-webkit-animation: lds-radio 1s linear infinite;
animation: lds-radio 1s linear infinite;
-webkit-animation-delay: 0.1s;
animation-delay: 0.1s;
border-bottom: 0;
border-left: 0;
}
.lds-radio div:nth-child(3) {
width: 110px;
height: 110px;
left: 56px;
top: 40px;
border-radius: 0 110px 0 0;
border: 20px solid #d8ebf9;
background: none;
-webkit-animation: lds-radio 1s linear infinite;
animation: lds-radio 1s linear infinite;
-webkit-animation-delay: 0.2s;
animation-delay: 0.2s;
border-bottom: 0;
border-left: 0;
}
.lds-radio {
width: 200px !important;
height: 200px !important;
-webkit-transform: translate(-100px, -100px) scale(1) translate(100px, 100px);
transform: translate(-100px, -100px) scale(1) translate(100px, 100px);
}
</style>
</div>
<!-- End of Spinner -->
<button class="btn btn-lg btn-dark btn-block" id="draw" type="button" onclick="draw();"><i class="fas fa-check"></i> DRAW</button>
<button class="btn btn-lg btn-dark btn-block" id="congrast" style="display: none;" type="button">Congratulations!</button>
</div>
<!--/card-block-->
</div>
<!-- /form card login -->
</div>
</div>
<!--/row-->
</div>
<!--/col-->
</div>
<!--/row-->
<p class="text-center text-white mb-4">Powered by Amazon <a href="https://aws.amazon.com/ko/s3/index.html" target="_blank">S3</a>, <a href="https://aws.amazon.com/ko/cognito/" target="_blank">Cognito</a> and <a href="https://aws.amazon.com/ko/dynamodb/index.html" target="_blank">DynamoDB</a></p>
</div>
<!--/container-->
<!-- Bootstrap core JavaScript -->
<script src="static/js/bootstrap.bundle.min.js"></script>
<!-- Bootbox -->
<script src="static/js/bootbox.min.js"></script>
</body>
</html>