Skip to content

Commit

Permalink
added one chrome device example
Browse files Browse the repository at this point in the history
  • Loading branch information
myxxmikeyxx committed Jun 24, 2021
1 parent efc4a04 commit 7555359
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.clasp.json
/appsscript.json
/testing.json
!/testing.json
/Compare*.*
82 changes: 54 additions & 28 deletions Code.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@

var headers = ['etag', 'Org Unit Path', 'Serial Number', 'Platform Version', 'Device Id', 'Status', 'Last Enrollment Time',
'Firmware Version', 'Last Sync', 'OS Version', 'Boot Mode', 'Annotated Location', 'Notes', 'Annotated User', 'Mac Address', ''];
var specialauthId = '0B7-FEGXAo-DGVklteGtFT2trOFU';
var image1Id = '0B7-FEGXAo-DGZ2txTWFnZ05SVVU';
var image2Id = '0B7-FEGXAo-DGeTUydWNHTjVDUVE';
var image3Id = '0B7-FEGXAo-DGRFNxX054S3p4QUE';
var imageBase = 'https://drive.google.com/uc?export=download&id=';



function myFunction() {

Expand Down Expand Up @@ -47,15 +40,18 @@ function menuItem3() {
// SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
// .alert('You clicked the second menu item!');
listChomeDevices();
// setHeader();
// filterSheet();
setHeader();
filterSheet();
// moveColumns();
}

function menuItem4() {
// SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
// .alert('You clicked the second menu item!');
moveColumns();
// moveColumns();
testingListChomeDevices();
setHeader();
filterSheet();
}

function menuItem5() {
Expand Down Expand Up @@ -118,6 +114,8 @@ function clearSheet() {

sheet.setColumnWidths(1, headers.length, 200);

// sheet.insertRows(maxRow, (100-maxRow));

// Hides unneed columns
// // sheet.hideColumns(letterToColumn('A'));
// sheet.hideColumns(letterToColumn('D'));
Expand Down Expand Up @@ -159,6 +157,7 @@ function listChomeDevices() {
var sheet = ss.getSheets()[0];
var allDevices = [];
var maxRow = sheet.getMaxRows();
var maxColumn = sheet.getMaxColumns();
sheet.clearContents();
if (maxRow > 2) {
clearSheet();
Expand All @@ -181,28 +180,13 @@ function listChomeDevices() {
if (allDevices.length > maxRow) {
sheet.insertRows(maxRow, (allDevices.length - maxRow));
}

var rows = [],
data;

for (i = 0; i < allDevices.length; i++) {
data = allDevices[i];
rows.push([data.id, data.name]);
}

dataRange = sheet.getRange(1, 1, rows.length, 2);
dataRange.setValues(rows);

// var allDeviceInfo = [];
// for (var i = 0; i < allDevices.length; i++) {
// Browser.msgBox(allDevices[i]);
// }
// for (i = 0; i < devices.length; i++) {}
//Browser.msgBox(allDevices);
//setRowsData(sheet, allDevices);
// setRowsData(sheet, allDeviceInfo);
}
SpreadsheetApp.flush();
} catch (err) {
Browser.msgBox(err.message);
Browser.msgBox("Error: " + err.message);
}
}

Expand All @@ -221,3 +205,45 @@ function filterSheet() {
spreadsheet.getRange('B1:B' + maxRow).createFilter();
}


function testingListChomeDevices() {
try {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var allDevices = [];
var maxRow = sheet.getMaxRows();
var maxColumn = sheet.getMaxColumns();
sheet.clearContents();
if (maxRow > 2) {
clearSheet();
}
SpreadsheetApp.flush();

sheet.getRange(1, 1, 1, headers.length).setValues([headers]);
sheet.autoResizeColumn(headers.length);
SpreadsheetApp.flush();

var response = AdminDirectory.Chromeosdevices.list('my_customer', { maxResults: 1, projection: "FULL" });
Logger.log("Response: " + response);
Logger.log("Response Chrome Devices: " + response.chromeosdevices);
// allDevices = allDevices.concat(response.chromeosdevices);
allDevices.push(...response.chromeosdevices.pop());
setRowsData(sheet, allDevices);
// while (response.nextPageToken) {
// response = AdminDirectory.Chromeosdevices.list('my_customer', { maxResults: 100, projection: "FULL", pageToken: response.nextPageToken });
// // allDevices = allDevices.concat(response.chromeosdevices);
// allDevices.push(...response.chromeosdevices);
// }

if (allDevices.length > 0) {
if (allDevices.length > maxRow) {
sheet.insertRows(maxRow, (allDevices.length - maxRow));
}
setRowsData(sheet, allDevices);
}
SpreadsheetApp.flush();
} catch (err) {
Browser.msgBox("Error: " + err.message);
}
}

48 changes: 48 additions & 0 deletions testing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{"osVersion":"85.0.4183.84",
"diskVolumeReports":[
{"volumeInfo":[
{"storageTotal":"1995472896","volumeId":"/media/archive","storageFree":"1995472896"},
{"storageTotal":"12042240","volumeId":"/usr/share/oem","storageFree":"11681792"},
{"volumeId":"/media/removable","storageTotal":"1995472896","storageFree":"1995472896"}
]}],
"lastEnrollmentTime":"2021-01-25T18:05:14.392Z",
"bootMode":"Verified",
"annotatedUser":"gadmin4th@greensburg.k12.in.us",
"model":"Dell Chromebook 3100",
"systemRamTotal":"3990949888",
"platformVersion":"13310.59.0 (Official Build) stable-channel octopus",
"activeTimeRanges":[
{"date":"2021-01-25","activeTime":60000}
],
"macAddress":"dc41a992ba26",
"lastSync":"2021-01-25T19:15:56.586Z",
"cpuStatusReports":[
{"cpuUtilizationPercentageInfo":[24],
"reportTime":"2021-01-25T18:05:27.296Z"},
{"reportTime":"2021-01-25T18:06:27.267Z",
"cpuTemperatureInfo":[
{"label":"Core 1\n","temperature":37},
{"label":"Package id 0\n","temperature":37},
{"temperature":37,"label":"Core 0\n"},
{"label":"iwlwifi_1\n","temperature":29}]}],
"deviceId":"bf9b0a6d-be3e-4710-a921-98c24558c20e",
"kind":"admin#directory#chromeosdevice",
"tpmVersionInfo":{
"tpmModel":"1",
"firmwareVersion":"7921eab30ee34b3e",
"vendorSpecific":"784347206654504D",
"family":"322e3000",
"specLevel":"74",
"manufacturer":"43524f53"
},
"autoUpdateExpiration":"1780297200000",
"status":"ACTIVE",
"firmwareVersion":"Google_Fleex.11297.141.0",
"systemRamFreeReports":[
{"systemRamFreeInfo":["2581913600"],
"reportTime":"2021-01-25T18:05:27.296Z"}
],
"manufactureDate":"2020-12-11",
"orgUnitPath":"/Elementary Students/ElementaryChrome/4thGradeChrome",
"serialNumber":"F0TK393",
"etag":"\"ajuIDY2MlKKzrdUn942df2OCBNkpUIbNakI8lMkbmjA/FRfJivzNeYMenB01rPOqQADu5vA\""}

0 comments on commit 7555359

Please sign in to comment.