This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List files using DriveFileManager (#1587)
A significant part of this PR is also a refactor for the UnsupportedMethod error, and moving BigQuery-specific and Drive-specific methods in the GapiManager into their own nested classes. * added drive file manager * drive listing working * refactor GapiManager to split drive and bigquery apis * use object instead of constructor on UnsupportedMethod call * cleanup * rebase artifacts * sort files on folder,modified,name * pr comments * add reverted grantScope call
- Loading branch information
Showing
17 changed files
with
381 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
sources/web/datalab/polymer/modules/drive-file-manager/drive-file-manager.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!-- | ||
Copyright 2017 Google Inc. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under the License | ||
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
or implied. See the License for the specific language governing permissions and limitations under | ||
the License. | ||
--> | ||
|
||
<link rel="import" href="../api-manager-factory/api-manager-factory.html"> | ||
<link rel="import" href="../file-manager/file-manager.html"> | ||
<link rel="import" href="../gapi-manager/gapi-manager.html"> | ||
|
||
<script src="drive-file-manager.js"></script> |
108 changes: 108 additions & 0 deletions
108
sources/web/datalab/polymer/modules/drive-file-manager/drive-file-manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright 2017 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
/** | ||
* This file contains a collection of functions that call the Google Drive APIs, and are | ||
* wrapped in the ApiManager class. | ||
*/ | ||
|
||
class DriveFile extends DatalabFile { | ||
} | ||
|
||
/** | ||
* An Google Drive specific file manager. | ||
*/ | ||
class DriveFileManager implements FileManager { | ||
|
||
private static readonly _directoryMimeType = 'application/vnd.google-apps.folder'; | ||
|
||
private static _upstreamToDriveFile(file: gapi.client.drive.File) { | ||
const datalabFile: DriveFile = { | ||
icon: file.iconLink, | ||
id: new DatalabFileId(file.id, FileManagerType.DRIVE), | ||
name: file.name, | ||
status: DatalabFileStatus.IDLE, | ||
type: file.mimeType === DriveFileManager._directoryMimeType ? | ||
DatalabFileType.DIRECTORY : | ||
DatalabFileType.FILE, | ||
}; | ||
return datalabFile; | ||
} | ||
public get(_fileId: DatalabFileId): Promise<DatalabFile> { | ||
throw new UnsupportedMethod('get', this); | ||
} | ||
|
||
public getContent(_fileId: DatalabFileId, _asText?: boolean): Promise<DatalabContent> { | ||
throw new UnsupportedMethod('getContent', this); | ||
} | ||
|
||
public async getRootFile(): Promise<DatalabFile> { | ||
const upstreamFile = await GapiManager.drive.getRoot(); | ||
return DriveFileManager._upstreamToDriveFile(upstreamFile); | ||
} | ||
|
||
public saveText(_file: DatalabFile): Promise<DatalabFile> { | ||
throw new UnsupportedMethod('getRootFile', this); | ||
} | ||
|
||
public async list(fileId: DatalabFileId): Promise<DatalabFile[]> { | ||
const queryPredicates = [ | ||
'"' + fileId.path + '" in parents', | ||
'trashed = false', | ||
]; | ||
const fileFields = [ | ||
'createdTime', | ||
'iconLink', | ||
'id', | ||
'mimeType', | ||
'modifiedTime', | ||
'name', | ||
'parents', | ||
]; | ||
const orderModifiers = [ | ||
'folder', | ||
'modifiedTime', | ||
'name', | ||
]; | ||
const upstreamFiles = | ||
await GapiManager.drive.getFiles(fileFields, queryPredicates, orderModifiers); | ||
// TODO: Check which files are running from the SessionsManager and modify | ||
// their status accordingly. | ||
return upstreamFiles.map((file) => DriveFileManager._upstreamToDriveFile(file)); | ||
} | ||
|
||
public create(_fileType: DatalabFileType, _containerId?: DatalabFileId, _name?: string): Promise<DatalabFile> { | ||
throw new UnsupportedMethod('create', this); | ||
} | ||
|
||
public rename(_oldFileId: DatalabFileId, _newName: string, _newContainerId?: DatalabFileId): Promise<DatalabFile> { | ||
throw new UnsupportedMethod('rename', this); | ||
} | ||
|
||
public delete(_fileId: DatalabFileId): Promise<boolean> { | ||
throw new UnsupportedMethod('delete', this); | ||
} | ||
|
||
public copy(_file: DatalabFileId, _destinationDirectoryId: DatalabFileId): Promise<DatalabFile> { | ||
throw new UnsupportedMethod('copy', this); | ||
} | ||
|
||
public getEditorUrl(): Promise<string> { | ||
throw new UnsupportedMethod('getEditorUrl', this); | ||
} | ||
|
||
public getNotebookUrl(): Promise<string> { | ||
throw new UnsupportedMethod('getNotebookUrl', this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.