Repository navigation
Expand file tree
/
Copy pathCalendarInsert.html
More file actions
409 lines (360 loc) · 10.4 KB
/
Copy pathCalendarInsert.html
File metadata and controls
409 lines (360 loc) · 10.4 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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<!DOCTYPE html>
<html>
<head>
<style>
#chartdiv {
width: 100%;
height: 500px;
}
</style>
<title>Google Calendar API Quickstart</title>
<meta charset='utf-8' />
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/pie.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<script type="text/javascript" src="jquery-1.min.js"></script>
<script type="text/javascript">
</script>
</head>
<body>
<p>Google Calendar API Quickstart</p>
<!--Add buttons to initiate auth sequence and sign out-->
<button id="authorize-button" style="display: none;">Authorize</button>
<button id="signout-button" style="display: none;">Sign Out</button>
<pre id="content"></pre>
<script type="text/javascript">
dts = new Array();
var eventArr = new Array();
var mapArr = new Array();
// Client ID and API key from the Developer Console
var CLIENT_ID = '78578465650-tg4bmqov9528gc8dq0878s56vouq09il.apps.googleusercontent.com';
// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = [ "https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest" ];
// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = "https://www.googleapis.com/auth/calendar";
var authorizeButton = document.getElementById('authorize-button');
var signoutButton = document.getElementById('signout-button');
/**
* On load, called to load the auth2 library and API client library.
*/
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
/**
* Initializes the API client library and sets up sign-in state
* listeners.
*/
function initClient() {
gapi.client
.init({
discoveryDocs : DISCOVERY_DOCS,
clientId : CLIENT_ID,
scope : SCOPES
})
.then(
function() {
// Listen for sign-in state changes.
gapi.auth2.getAuthInstance().isSignedIn
.listen(updateSigninStatus);
// Handle the initial sign-in state.
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn
.get());
authorizeButton.onclick = handleAuthClick;
signoutButton.onclick = handleSignoutClick;
});
}
/**
* Called when the signed in status changes, to update the UI
* appropriately. After a sign-in, the API is called.
*/
function updateSigninStatus(isSignedIn) {
if (isSignedIn) {
authorizeButton.style.display = 'none';
signoutButton.style.display = 'block';
//addEvents();
} else {
authorizeButton.style.display = 'block';
signoutButton.style.display = 'none';
}
}
/**
* Sign in the user upon button click.
*/
function handleAuthClick(event) {
gapi.auth2.getAuthInstance().signIn();
}
/**
* Sign out the user upon button click.
*/
function handleSignoutClick(event) {
gapi.auth2.getAuthInstance().signOut();
}
/**
* Append a pre element to the body containing the given message
* as its text node. Used to display the results of the API call.
*
* @param {string} message Text to be placed in pre element.
*/
function appendPre(message) {
var pre = document.getElementById('content');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
}
/**
* Insert events from outside file into the Google Calendar
*/
function addEvents() {
var event = {
'summary' : 'Insert Event into Calendar',
'location' : 'Software AG',
'description' : 'Inserting events from facebook',
'start' : {
'dateTime' : '2017-06-17T23:00:00+05:30',
'timeZone' : 'Asia/Calcutta'
},
'end' : {
'dateTime' : '2017-06-17T23:45:00+05:30',
'timeZone' : 'Asia/Calcutta'
},
'recurrence' : [ 'RRULE:FREQ=DAILY;COUNT=2' ],
'attendees' : [ {
'email' : 'nlkntsharma@gmail.com'
}, {
'email' : 'sprmmn@gmail.com'
} ],
'reminders' : {
'useDefault' : false,
'overrides' : [ {
'method' : 'email',
'minutes' : 24 * 60
}, {
'method' : 'popup',
'minutes' : 10
} ]
}
};
var request = gapi.client.calendar.events.insert({
'calendarId' : 'primary',
'resource' : event
});
request.execute(function(event) {
appendPre('Event created: ' + event.htmlLink);
});
}
function listUpcomingEvents() {
var days = document.getElementById("lastDays").value;
gapi.client.calendar.events.list({
'calendarId': 'primary',
'timeMin': (new Date(new Date().getDate() - parseInt(days))).toISOString(),
'timeMax' :(new Date).toISOString(),
'showDeleted': false,
'singleEvents': true,
'maxResults': 200,
'orderBy': 'startTime'
}).then(function(response) {
var events = response.result.items;
appendPre('Upcoming events:');
if (events.length > 0) {
for (i = 0; i < events.length; i++) {
var event = events[i];
eventArr.push(event);
var when = event.start.dateTime;
if (!when) {
when = event.start.date;
}
//appendPre(event.summary + ' (' + when + ')')
}
} else {
//appendPre('No upcoming events found.');
}
});
document.getElementById("whatToDo").style.visibility = "";
}
function timeSpentByEvents(){
mapArr = new Array();
for(i=0;i<eventArr.length;i++){
map = null;
for(j=0; j<mapArr.length;j++) {
if(mapArr[j].key == eventArr[i].summary) {
map = mapArr[j];
break;
}
}
if(map == null) {
map = new Object();
map.key = eventArr[i].summary;
map.value = 0;
mapArr.push(map);
}
startDate = new Date(eventArr[i].start.dateTime);
endDate = new Date(eventArr[i].end.dateTime);
map.value += (endDate - startDate) / (1000 * 60);
}
}
function display() {
document.getElementById('content').innerHTML = '';
document.getElementById("myTable").innerHTML = '<tr><td>Group</td><td>Minutes</td></tr>';
mapArr.sort(function(a,b){
if(isNaN(a.value)){
return 1;
}
if(isNaN(b.value)){
return -1;
}
return b.value - a.value;});
var chartObj = {};
var charts = [mapArr.length];
for(i=0; i<mapArr.length;i++) {
document.getElementById("myTable").insertRow(-1).innerHTML = '<td>' + mapArr[i].key +'</td><td>'+(isNaN(mapArr[i].value) ? 0 : mapArr[i].value) +'</td>';
if(!isNaN(mapArr[i].value)) {
obj = new Object();
obj.group = mapArr[i].key;
obj.minutes = mapArr[i].value;
charts[i] = obj;
}
}
chartArr = [{"coutry" : "India", "litres" : 200},{"coutry" : "India2", "litres" : 300},{"coutry" : "India3", "litres" : 400}];
var chart = AmCharts.makeChart( "chartdiv", {
"type": "pie",
"theme": "light",
"dataProvider": charts,
"valueField": "minutes",
"titleField": "group",
"balloon":{
"fixedPosition":true
},
"export": {
"enabled": true
}
} );
}
function timeSpentonPeople(){
mapArr = new Array();
for(i=0;i<eventArr.length;i++){
map = null;
for(j=0; j<mapArr.length;j++) {
if(mapArr[j].key == eventArr[i].creator.displayName) {
map = mapArr[j];
break;
}
}
if(map == null) {
map = new Object();
map.key = eventArr[i].creator.displayName;
map.value = 0;
mapArr.push(map);
}
startDate = new Date(eventArr[i].start.dateTime);
endDate = new Date(eventArr[i].end.dateTime);
map.value += (endDate - startDate) / (1000 * 60);
}
}
function timeSpentOnTopics(){
mapArr = new Array();
for(i=0;i<eventArr.length;i++){
map = null;
for(j=0; j<mapArr.length;j++) {
if(mapArr[j].key == eventArr[i].creator.displayName) {
map = mapArr[j];
break;
}
}
if(map == null) {
map = new Object();
map.key = eventArr[i].creator.displayName;
map.value = 0;
mapArr.push(map);
}
startDate = new Date(eventArr[i].start.dateTime);
endDate = new Date(eventArr[i].end.dateTime);
map.value += (endDate - startDate) / (1000 * 60);
}
}
function timeSpentOnDays(){
mapArr = new Array();
for(i=0;i<eventArr.length;i++){
map = null;
for(j=0; j<mapArr.length;j++) {
nd = new Date(eventArr[i].created);
day = getDayForNumber(nd.getDay());
if(mapArr[j].key == day) {
map = mapArr[j];
break;
}
}
if(map == null) {
map = new Object();
nd = new Date(eventArr[i].created);
day = nd.getDay();
day = getDayForNumber(day);
map.key = day;
map.value = 0;
mapArr.push(map);
}
startDate = new Date(eventArr[i].start.dateTime);
endDate = new Date(eventArr[i].end.dateTime);
map.value += (endDate - startDate) / (1000 * 60);
}
}
function getDayForNumber(day) {
switch(day) {
case 1:
return "Monday";
break;
case 2:
return "Tuseday";
break;
case 3:
return "Wednesday";
break;
case 4:
return "Thrusday";
break;
case 5:
return "Friday";
break;
case 6:
return "Saturday";
break;
default:
return "Sunday";
break;
}
return ""
}
/*function loadChar() {
var options = {
title: {
text: "Column Chart using jQuery Plugin"
},
animationEnabled: true,
data: [
{
type: "column", //change it to line, area, bar, pie, etc
dataPoints: dts;
}
]
};
$("#chartContainer").CanvasJSChart(options);
}*/
</script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
Last how many days : <input type="text" value="10" id="lastDays"/>
<input type="button" value="Get Events" onclick="listUpcomingEvents()"/>
<div id="whatToDo" style="visibility:hidden">
<input type="button" value="Time Spent by Events" onclick="timeSpentByEvents();display()" />
<input type="button" value="Time Spent on People" onclick="timeSpentonPeople();display()" />
<input type="button" value="Time Spent by Days" onclick="timeSpentOnDays();display()" />
</div>
<div>
<table id="myTable"></table>
</div>
<div id="chartdiv"></div>
</body>
</html>