### Hierarchy

- GoCloudStorage
  - GoGoogleDrive

Class for saving / loading GoJS Diagram models to / from Google Drive. Uses the Google Drive V3 API by use of a Google Client API object. As with all GoCloudStorage subclasses (with the exception of GoLocalStorage, any page using GoDropBox must be served on a web server.

Note: Any page using GoGoogleDrive must include a script tag with src set to https://apis.google.com/js/api.js.

## Index

### Constructors

- constructor

### Properties

- className
- clientId
- currentDiagramFile
- defaultModel
- gapiClient
- gapiPicker
- iconsRelativeDirectory
- isAutoSaving
- managedDiagrams
- pickerApiKey
- scope
- serviceName
- ui

### Methods

- authorize
- checkFileExists
- create
- createPicker
- getFile
- getUserInfo
- hideUI
- load
- loadWithUI
- remove
- removeWithUI
- save
- saveWithUI
- showUI

## Constructors

### constructor

- new GoGoogleDrive(managedDiagrams: Diagram | Diagram[], clientId: string, pickerApiKey: string, defaultModel?: string, iconsRelativeDirectory?: string): GoGoogleDrive

- #### Parameters

  - ##### managedDiagrams: Diagram | Diagram[]

    An array of GoJS Diagrams whose model(s) will be saved to / loaded from Google Drive.

  - ##### clientId: string

    The client ID of the Google application linked with this instance of GoGoogleDrive (given in Google Developers Console after registering a Google app)

  - ##### pickerApiKey: string

    The Google Picker API key. Once obtained, it can be found in the Google Developers Console

  - ##### Optional defaultModel: string

    String representation of the default model data for new diagrams. If this is null, default new diagrams will be empty. Usually a value given by calling .toJson() on a GoJS Diagram's Model.

  - ##### Optional iconsRelativeDirectory: string

    The directory path relative to the page in which this instance of GoGoogleDrive exists, in which the storage service brand icons can be found. The default value is "../goCloudStorageIcons/".

  #### Returns GoGoogleDrive

## Properties

### Read-only className : string

- Get the name of the class; i.e. "GoDropbox"

### Read-only clientId : string

- Get the clientId for the app using the cloud storage service. This is usually given by the cloud storage provider's dev console or similar. Set with a parameter during construction.

### currentDiagramFile : DiagramFile

- Get or set the currently open DiagramFile. By default, currentDiagramFile is set when a file is loaded from storage, saved to storage (if saved to a different path from the currentDiagramFile.path), or deleted from storage (if the deleted file is the currently open one). The default value is a DiagramFile with null id, name, and path values.

### defaultModel : string

- Get / set the defaultModel data for the app used by an instance of GoCloudStorage. defaultModel is used when creating new diagrams. See create.

### Read-only gapiClient : any

- Get Google API Client. The Google API Client is used in GoGoogleDrive to make many different requests to Google Drive, however, it can be used with other Google Libraries to achieve many purposes. To read more about what can be done with a Google API Client object, click here. gapiClient is set after a succesful authorization in authorize.

  gapiClient is really of type Object, not type any. However, the Google libraries are all written in JavaScript and do not provide d.ts files. As such, to avoid TypeScript compilation errors, both gapiClient and gapiPicker properties are declared as type any.

### Read-only gapiPicker : any

- Get Google Picker API Object. Used to show the Google filepicker when loading / deleting files, in the createPicker function. gapiPicker is set after a succesful authorization in authorize.

  gapiPicker is really of type Object, not type any. However, the Google libraries are all written in JavaScript and do not provide d.ts files. As such, to avoid TypeScript compilation errors, both gapiClient and gapiPicker properties are declared as type any.

### iconsRelativeDirectory : string

- Get / set iconsRelativeDirectory, the directory path relative to the page in which this instance of GoCloudStorage exists, in which the storage service brand icons can be found. The default value is "../goCloudStorageIcons/".

### isAutoSaving : boolean

- Get or set isAutoSaving property. If true, the managedDiagrams will be saved to storage after every Transaction (only if currentDiagramFile holds a non-null path value). Additionally, if isAutoSaving is true, users will be prompted to save newly created diagrams when created with create. The default value for isAutoSaving is `true`.

### managedDiagrams : Diagram[]

- Get / set the GoJS Diagrams associated with this instance of GoCloudStorage. Set with a parameter during construction.

### Read-only pickerApiKey : string

- Get the Google Picker API key associated with this instance of GoGoogleDrive. This is set with a parameter during construction. A Google Picker API key can be obtained by following the process detailed here, and it can be found in your Google Developers Console. The pickerApiKey is used only in createPicker.

### Read-only scope : string

- Get the scope for the application linked to this instance of GoGoogleDrive (via clientId). Scope tells the gapiClient what permissions it has in making requests. Read more on scope here. The default value is 'https://www.googleapis.com/auth/drive', set during construction. This can only be modified by changing the source code for GoGoogleDrive. As changing scope impacts gapiClient's permissions (and could break the usability of some or all functions of GoGoogleDrive), this is not recommended.

### Read-only serviceName : string

- Get the name of the cloud storage service being used; i.e. "Dropbox"

### Read-only ui : HTMLElement

- Get the UI element associated with this instance of GoCloudStorage. This is a custom filepicker window for GoDropBox and GoLocalStorage. It is a save prompt for GoOneDrive and GoGoogleDrive (both these classes use third party UI for storage navigation, provided by Microsoft and Google, respectively). The UI element is created during construction.

## Methods

### authorize

- authorize(refreshToken?: boolean): Promise<Object>

- Check if there is a signed in user who has authorized the application connected to this instance of GoGoogleDrive (via clientId. If not, prompt user to sign into their Google Account and authorize the application. On successful authorization, set gapiClient and gapiPicker.

  #### Parameters

  - ##### Default value refreshToken: boolean = false

    Whether to get a new token (change current Google User)(true) or attempt to fetch a token for the currently signed in Google User (false).

  #### Returns Promise<Object>

  Returns a Promise that resolves with a boolean stating whether authorization was succesful (true) or failed (false)

### checkFileExists

- checkFileExists(path: string): Promise<Object>

- Check whether a file exists at a given path

  #### Parameters

  - ##### path: string

    A valid GoogleDrive file ID -- not a path. Named 'path' only to preserve system nomenclature

  #### Returns Promise<Object>

  Returns a Promise that resolves with a boolean stating whether a file exists at a given path

### create

- create(path?: string): Promise<Object>

- Set each of managedDiagrams' .model to defaultModel (if defaultModel is null, each model will be set to a new GraphLinksModel by default). If isAutoSaving is true and no path parameter is supplied, users will be immediately prompted to save their new diagrams to cloud storage.

  #### Parameters

  - ##### Optional path: string

    If a valid filepath is supplied, save each of managedDiagrams' model data to this path. No UI of any sort appears. What is meant by "valid filepath" varies from subclass to subclass. Rules for valid filepaths by subclass:

    - GoLocalStorage: Just the filename (the key in local storage); i.e. `example.diagram`
    - GoDropBox: `/{path-to-file}/{filename}`; i.e. `/Public/example.diagram`
    - GoGoogleDrive: Use Google Drive-given file IDs. Parameter is still called 'path' in GoGoogleDrive methods to preserve system nomenclature.
    - GoOneDrive: `/drive/root:/{path-to-file}/{filename}`; i.e. `/drive/root:/Documents/example.diagram`

  #### Returns Promise<Object>

  Returns a Promise that resolves with a DiagramFile representing the newly created file.

### createPicker

- createPicker(cb: Function): void

- Launch Google Picker, a filepicker UI used to graphically select files in Google Drive to load or delete. This is accomplished with gapiPicker, which is set after succesful authorization, so this function may only be called after a successful call to authorize.

  #### Parameters

  - ##### cb: Function

    Callback function that takes the chosen file from the picker as a parameter

  #### Returns void

### getFile

- getFile(path: string): Promise<Object>

- Get the Google Drive file reference object at a given path. Fields include:

  - id: The Google Drive-given ID of the file at the provided path
  - name: The name of the file saved to Google Drive at the provided path
  - mimeType: For diagram files, this will always be `text/plain`
  - kind: This will usually be `drive#file`.

  Note: Name, ID, and path values are requisite for creating valid DiagramFiles. When creating a DiagramFile for a diagram saved to Google Drive, provide the same value for name and path properties.

  #### Parameters

  - ##### path: string

    A valid GoogleDrive file ID -- not a path. Named 'path' only to preserve system nomenclature

  #### Returns Promise<Object>

  Returns a Promise that resolves with a Google Drive file reference object at a given path

### getUserInfo

- getUserInfo(): Promise<Object>

- Get information about the currently logged in Google user. Some fields of particular note include:

  - displayName
  - emailAdrdress
  - kind

  #### Returns Promise<Object>

  Returns a Promise that resolves with information about the currently logged in Google user

### hideUI

- hideUI(isActionCanceled?: boolean): void

- Hide the ui element associated with this instance of GoCloudStorage. Used in some UI element onclicks.

  #### Parameters

  - ##### Default value isActionCanceled: boolean = false

    If action (save, delete, load) is canceled, resolve Promise (returned previously in showUI) with a 'Canceled' notification. Default value is false.

  #### Returns void

### load

- load(path: string): Promise<Object>

- Get the contents of a saved diagram from Google Drive using a given Google Drive file ID. No UI of any sort appears.

  #### Parameters

  - ##### path: string

    A valid GoogleDrive file ID -- not a path. Named 'path' only to preserve GoCloudStorage system nomenclature

  #### Returns Promise<Object>

  Returns a Promise that resolves with a DiagramFile representing the loaded file

### loadWithUI

- loadWithUI(): Promise<Object>

- Load the contents of a saved diagram from Google Drive using the Google Picker (see gapiPicker and createPicker).

  #### Returns Promise<Object>

  Returns a Promise that resolves with a DiagramFile representing the loaded file

### remove

- remove(path: string): Promise<Object>

- Delete a the diagram from a user's Google Drive with the given Google Drive file ID. No UI of any sort appears.

  #### Parameters

  - ##### path: string

    A valid GoogleDrive file ID -- not a path. Named 'path' only to preserve system nomenclature

  #### Returns Promise<Object>

  Returns a Promise that resolves with a DiagramFile representing the deleted file

### removeWithUI

- removeWithUI(): Promise<Object>

- Delete a selected diagram from a user's Google Drive using the Google Picker (see gapiPicker and createPicker).

  #### Returns Promise<Object>

  Returns a Promise that resolves with a DiagramFile representing the deleted file

### save

- save(path?: string): Promise<Object>

- Save managedDiagrams' model data to GoGoogleDrive. If path is supplied save to that path. If no path is supplied but currentDiagramFile has non-null, valid properties, update saved diagram file content at the path in GoGoogleDrive corresponding to currentDiagramFile.path with current managedDiagrams' model data. If no path is supplied and currentDiagramFile is null or has null properties, this calls saveWithUI.

  #### Parameters

  - ##### Optional path: string

    A name (not a path, not an id) to save this diagram file in Google Drive under. Named 'path' only to preserve system nomenclature

  #### Returns Promise<Object>

  Returns a Promise that resolves with a DiagramFile representing the saved file

### saveWithUI

- saveWithUI(): Promise<Object>

- Save the current managedDiagrams's model data to the current Google user's Google Drive using the custom ui save prompt.

  #### Returns Promise<Object>

  Returns a Promise that resolves with a DiagramFile representing the saved file

### showUI

- showUI(): any

- Show the custom GoGoogleDrive save prompt; a div with an HTML input element that accepts a file name to save the current managedDiagrams data to in Google Drive.

  #### Returns any

  Returns a Promise that resolves (in save, load, or remove) with a DiagramFile representing the saved/loaded/deleted file

Copyright © 1998-2018 by Northwoods Software Corporation.