This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
controllers.js
76 lines (65 loc) · 3.13 KB
/
controllers.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
angular.module('demo', ["googleApi", "ngResource", "firebase", "ngRoute", "ui.bootstrap"])
.config(function(googleLoginProvider, $parseProvider) {
googleLoginProvider.configure({
clientId: '239511214798.apps.googleusercontent.com',
scopes: ["https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/calendar"]
});
$parseProvider.unwrapPromises(true);
})
.controller('DemoCtrl', function ($scope, $http, googleLogin, googleCalendar, $resource, angularFireAuth) {
$scope.sharedCalendarId = "[email protected]";
var ref = new Firebase("https://letsgitlunch.firebaseio.com/");
var githubMembers = $resource('https://api.github.com/orgs/:org/members');
var githubOrgs = $resource('https://api.github.com/users/:user/orgs');
$scope.login = function () {
googleLogin.login().then(function() {}, function() { console.error("failed login")});
};
angularFireAuth.initialize(ref, {scope: $scope, name: "githubUser"});
$scope.loginToGithub = function() {
angularFireAuth.login("github");
}
$scope.$on("angularFireAuth:login", function() {
$scope.organizations = githubOrgs.query({user: $scope.githubUser.login});
$scope.loggedIntoGithub = true;
});
$scope.loadMembers = function() {
$scope.members = githubMembers.query({org: this.selectedOrganization.login});
}
$scope.$on("google:authenticated", function(auth) {
$scope.loggedIntoGoogle = true;
});
$scope.$on("googleCalendar:loaded", function() {
googleCalendar.listCalendars().then(function(cals) {
$scope.calendars = cals;
});
});
$scope.loadCalendars = function() {
this.calendars = googleCalendar.listCalendars();
}
$scope.addEvent = function() {
randomMember = _.sample(this.members);
var self = this;
lunchStart = moment(self.lunchDate + " " + self.lunchTime);
lunchEnd = lunchStart.clone().add("hours", 1);
$http.get(randomMember.url).success(function(member) {
$scope.chosenMember = member;
var event = {
attendees: [{email: member.email}, {email: $scope.githubUser.email}],
summary: "Random Gaslight Lunch",
location: "Somewheres yummy",
description: member.name + " and " + $scope.githubUser.name,
start: { dateTime: lunchStart.toDate() },
end: { dateTime: lunchEnd.toDate() }
};
googleCalendar.createEvent({
calendarId: self.selectedCalendar.id,
sendNotifications: true,
resource: event
}).then(function(event) {
$scope.newEvent = event;
}, function(error) {
$scope.eventCreationError = error;
});
});
}
});