-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
78 lines (68 loc) · 2.53 KB
/
scripts.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
77
// JavaScript source code
var myApp = angular.module("myApp", ['angular.filter']);
myApp.controller('CalendarItemsCtrl', function ($scope, $http) {
$scope.CalendarItemsLeft = [];
$scope.CalendarItemsRight = [];
var req = new XMLHttpRequest();
var key = "AIzaSyDE_JvtqCn80h0oV0TlrXEYaeJbbHLo8Fo";
var id = "vkfojt5isnllkunl2itskbl2d0@group.calendar.google.com";
var timeNow = new Date();
//min end time
var timeMin = timeNow.toISOString();
var requrl = "https://www.googleapis.com/calendar/v3/calendars/" + id + "/events?timeMin=" + timeMin + "&orderBy=startTime&singleEvents=true" + "&key=" + key;
var counter = 1;
var previousStartDate;
$http({method: "GET", url: requrl}).success(
function (data, status, headers, config) {
data.items.forEach(function (item) {
var dateTime = new Date(item.start.dateTime);
var time = convertDateToTime(dateTime);
var date = weekday[dateTime.getDay()] + ", " + month[dateTime.getMonth()] + " " + dateTime.getDate();
if(previousStartDate === date) {
counter--;
}
previousStartDate = date;
var name = item.summary;
var event = time + " - " + name;
if(counter % 2 !== 0) {
$scope.CalendarItemsLeft.push({date: date, event: event});
}
else {
$scope.CalendarItemsRight.push({date: date, event: event});
}
counter++;
});
});
var weekday = new Array(7);
weekday[0] = "Sun";
weekday[1] = "Mon";
weekday[2] = "Tue";
weekday[3] = "Wed";
weekday[4] = "Thu";
weekday[5] = "Fri";
weekday[6] = "Sat";
var month = new Array();
month[0] = "Jan";
month[1] = "Feb";
month[2] = "Mar";
month[3] = "Apr";
month[4] = "May";
month[5] = "Jun";
month[6] = "Jul";
month[7] = "Aug";
month[8] = "Sept";
month[9] = "Oct";
month[10] = "Nov";
month[11] = "Dec";
function convertDateToTime(date){
var minutes = date.getMinutes();
var hours = date.getHours();
if(minutes < 10) {
minutes = "0" + minutes;
};
if(hours < 10) {
hours = "0" + hours;
}
return hours + ":" + minutes;
};
});