-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
116 lines (109 loc) · 3.54 KB
/
controller.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
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
function AppController() {
var staq = new Staq()
var newFrame = m.prop('');
var showClosed = m.prop(false)
var showDebug = m.prop(false)
var lastMessage = m.prop('yo')
var googleUser = m.prop(null)
var gapiStore = m.prop(null)
var driveEnabled = m.prop(false)
// var store = new Store()
function handleSignInWithGoogleUser(gUser) {
console.log('handleSignInWithGoogleUser)')
if (!gapiStore()) {
lastMessage('initialization issue!?')
return
}
googleUser(gUser)
var profile = gUser.getBasicProfile()
if (profile) {
lastMessage('hello, ' + profile.getName())
} else {
lastMessage('hello, stranger')
}
m.redraw()
}
return {
staq: staq,
newFrame: newFrame,
showClosed: showClosed,
showDebug: showDebug,
lastMessage: lastMessage,
gapiStore: gapiStore,
driveEnabled: driveEnabled,
isSignedIn: function () {
return googleUser() !== null
},
enableSync: function () {
lastMessage('GDrive integration enabled')
m.redraw()
driveEnabled(true)
},
handleSignInWithGoogleUser: handleSignInWithGoogleUser,
handleSaveClick: function () {
lastMessage('nyi')
},
handlePush: function (e) {
try {
staq.push(newFrame())
newFrame('')
} catch (e) {
staq.error(e)
lastMessage(e)
}
},
handlePop: function (e) {
try {
staq.pop()
} catch (e) {
staq.error(e)
lastMessage(e)
}
},
handleShowClosedToggle: function (e) {
showClosed(!showClosed())
},
handleShowDebugToggle: function (e) {
showDebug(!showDebug())
},
handleSigninClick: function (e, immediate) {
if (immediate) {
gapiStore().signin2.render('signin', {
'scope': [
'profile',
'email',
'https://www.googleapis.com/auth/drive.metadata.readonly',
'https://www.googleapis.com/auth/drive.file',
].join(' '),
'theme': 'dark',
'onsuccess': function () {
handleSignInWithGoogleUser(gapiStore().auth2.getAuthInstance().currentUser.get())
lastMessage('trying to load drive api')
m.redraw()
gapiStore().client.load('drive', 'v3', function () {
lastMessage('loaded drive api')
m.redraw()
appInst.enableSync()
});
},
'onfailure': function () {
console.log('onfailure', arguments)
lastMessage('problem loading user')
},
})
}
},
handleSignoutClick: function (e) {
lastMessage('trying to sign out...')
var auth = gapiStore()
.auth2
.getAuthInstance();
auth.signOut()
.then(function () {
lastMessage('goodbye!')
googleUser(null)
m.redraw()
});
},
}
}