google classroom experiment
diff --git a/init.js b/init.js
index 6c402b0..73419a9 100644
--- a/init.js
+++ b/init.js
@@ -3,7 +3,8 @@
readableVer: "v0.9.1 (GM)",
trackSuffix: " (GM)",
showLetters: false,
- demo: false
+ demo: false,
+ gClassroom : false
};
dtps.changelog = function () {
fluid.cards.close(".card.focus")
@@ -485,7 +486,66 @@
}
}
}
-dtps.showClasses = function () {
+dtps.gClassroom = function() {
+ var authorizeButton = document.getElementById('authorize_button');
+ var signoutButton = document.getElementById('signout_button');
+
+ function handleClientLoad() {
+ gapi.load('client:auth2', initClient);
+ }
+
+ function initClient() {
+ gapi.client.init({
+ apiKey: 'AIzaSyB3l_RWC3UMgNDAjZ4wD_HD2NyrneL9H9g',
+ clientId: '117676227556-lrt444o80hgrli1nlcl4ij6cm2dbop8v.apps.googleusercontent.com',
+ discoveryDocs: ["https://www.googleapis.com/discovery/v1/apis/classroom/v1/rest"],
+ scope: "https://www.googleapis.com/auth/classroom.courses.readonly"
+ }).then(function () {
+ gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
+ updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
+ authorizeButton.onclick = handleAuthClick;
+ signoutButton.onclick = handleSignoutClick;
+ });
+ }
+ function updateSigninStatus(isSignedIn) {
+ if (isSignedIn) {
+ dtps.gClassroom = true;
+ $(".btn.google").show();
+ authorizeButton.style.display = 'none';
+ signoutButton.style.display = 'block';
+ listCourses();
+ } else {
+ dtps.gClassroom = false;
+ $(".btn.google").hide();
+ authorizeButton.style.display = 'block';
+ signoutButton.style.display = 'none';
+ }
+ }
+ function handleAuthClick(event) {
+ gapi.auth2.getAuthInstance().signIn();
+ }
+ function handleSignoutClick(event) {
+ gapi.auth2.getAuthInstance().signOut();
+ }
+ function listCourses() {
+ gapi.client.classroom.courses.list({
+ pageSize: 10
+ }).then(function(response) {
+ var courses = response.result.courses;
+ dtps.log('Courses:');
+
+ if (courses.length > 0) {
+ for (i = 0; i < courses.length; i++) {
+ var course = courses[i];
+ dtps.log(course.name)
+ }
+ } else {
+ dtps.log('No courses found.');
+ }
+ });
+ }
+}
+dtps.showClasses = function() {
var streamClass = "active"
if (dtps.selectedClass !== "stream") var streamClass = "";
jQuery(".sidebar").html(`<div onclick="dtps.selectedClass = 'stream';" class="class ` + streamClass + `">
@@ -555,7 +615,7 @@
<i class="material-icons">view_stream</i>
Stream
</button>
- <button onclick="dtps.selectedContent = 'google';" class="btn google sudo">
+ <button style="display:none;" onclick="dtps.selectedContent = 'google';" class="btn google sudo">
<i class="material-icons">experiment</i>
google_logo
</button>
@@ -596,6 +656,8 @@
<div class="label sudo"><i class="material-icons">code</i> Demo mode</div>
<br /><br />
<button onclick="dtps.changelog();" style="display:none;" class="btn changelog"><i class="material-icons">update</i>Changelog</button>
+ <button id="signout_button" style="display:none;" class="btn sudo"><i class="material-icons">experiment</i>google_logo Signout</button>
+ <button id="authorize_button" style="display:none;" class="btn sudo"><i class="material-icons">experiment</i>Link google_logo Classroom</button>
</div>
<div class="items">
<h4>` + dtps.user.first_name + ` ` + dtps.user.last_name + `</h4>