### Hierarchy

- GoCloudStorage
  - GoOneDrive

Class for saving / loading GoJS Diagram models to / from Microsoft One Drive. As with all GoCloudStorage subclasses (with the exception of GoLocalStorage, any page using GoDropBox must be served on a web server.

Note: Makes use of OneDrive FilePicker for JavaScript v7.2. Any page using GoOneDrive must include a script tag with src set to https://js.live.net/v7.2/OneDrive.js.

## Index

### Constructors

- constructor

### Properties

- className
- clientId
- currentDiagramFile
- defaultModel
- iconsRelativeDirectory
- isAutoSaving
- managedDiagrams
- oauthToken
- oneDriveFilepicker
- serviceName
- ui

### Methods

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

## Constructors

### constructor

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

- #### Parameters

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

    An array of GoJS Diagrams whose model(s) will be saved to / loaded from OneDrive. Can also be a single Diagram.

  - ##### clientId: string

    The client ID of the application in use (given by Microsoft in Microsoft Dev Center)

  - ##### 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 GoOneDrive exists, in which the storage service brand icons can be found. The default value is "../goCloudStorageIcons/".

  #### Returns GoOneDrive

## 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.

### 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.

### oauthToken : string

- Get / set the global oauthToken. Only used to authorize requests in load, save, and remove when the oneDriveFilepicker property is not used. Not needed when the oneDriveFilePicker is used, as action-specific tokens (issued by the Microsoft-provided OneDrive Filepicker) are issued then. oauthToken is null after construction, but can be set or refreshed with calls to authorize.

### Read-only oneDriveFilepicker : any

- Get OneDrive Filepicker object. Used to display a Microsoft user's OneDrive files.

### 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>

- Get OAuth 2.0 token for Microsoft OneDrive API requests with a specific Microsoft account. Sets oauthToken.

  #### Parameters

  - ##### Optional refreshToken: boolean

    Whether to get a new access token (triggers a page redirect) (true) or try to find / use the one in the browser window URI (no redirect) (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 MS OneDrive filepath to save current diagram model to Path must be of the form: /drive/root:/{item-path}

  #### 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.

### generateGraphUrl

- generateGraphUrl(driveItem: Object, targetParentFolder: boolean, itemRelativeApiPath: boolean): string

- Generate and return a Microsoft Graph URL for a target item

  #### Parameters

  - ##### driveItem: Object

    The item to generate the URL for

  - ##### targetParentFolder: boolean

    Indicates whether to target the parent folder + filename instead of the item itself

  - ##### itemRelativeApiPath: boolean

    Indicates whether to append /content to the item URL

  #### Returns string

  Returns a Microsoft Graph URL for a target item

### getFile

- getFile(path: string, token?: string): Promise<Object>

- Get the OneDrive file reference object at a given path. Properties of particular note include:

  - name: The name of the file in OneDrive
  - id: The OneDrive-given file ID
  - parentReference
    - path: The path of the parent folder of the file at the provided path

  Note: Name, ID, and path are requisite for creating valid DiagramFiles. A path can be constructed by concatenating the parentReference.path with name. DiagramFiles optionally also contain parentReference and token values (both used exclusively by GoOneDrive and its methods).

  #### Parameters

  - ##### path: string

    A valid MS OneDrive filepath to save current diagram model to Path must be of the form: /drive/root:/{item-path}

  - ##### Optional token: string

    Optional: A token received by OneDrive filepicker (loadDiagramWithUI) to allow for its file to be loaded. If no token is given, use global oauthToken

  #### Returns Promise<Object>

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

### getUserInfo

- getUserInfo(): Promise<Object>

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

  - displayName
  - givenName
  - id
  - jobTitle
  - userPrincipalName (email)

  Note: If oauthToken is not valid or has expired, a page redirect to the Microsoft Account sign in will occur.

  #### Returns Promise<Object>

  Returns a Promise that resolves with information about the currently logged in Microsoft 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, token?: string): Promise<Object>

- Load the contents of a saved diagram from MS OneDrive to diagram model.

  #### Parameters

  - ##### path: string

    A valid Microsoft OneDrive filepath to load diagram model data from. Path syntax is `/drive/root:/{path-to-file}/{filename}`; i.e. `/drive/root:/Documents/example.diagram`

  - ##### Optional token: string

    A token received by OneDrive Filepicker (passed from loadWithUI) to allow for its file to be loaded. If no token is given, use global oauthToken

  #### Returns Promise<Object>

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

### loadWithUI

- loadWithUI(): Promise<Object>

- Load diagram model data from a given OneDrive-specific file path into managedDiagrams using the MS OneDrive filepicker.

  #### Returns Promise<Object>

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

### remove

- remove(path: string, token?: string): Promise<Object>

- Delete a diagram from a user's OneDrive at a given path.

  #### Parameters

  - ##### path: string

    A valid Microsoft OneDrive filepath to delete. Path syntax is `/drive/root:/{path-to-file}/{filename}`; i.e. `/drive/root:/Documents/example.diagram`

  - ##### Optional token: string

    A token received by OneDrive filepicker (passed from removeWithUI) to allow for its file to be deleted. If no token is given, use global oauthToken

  #### Returns Promise<Object>

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

### removeWithUI

- removeWithUI(): Promise<Object>

- Delete a diagram from a user's OneDrive using the OneDrive Filepicker.

  #### 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 Microsoft OneDrive. 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 OneDrive corresponding to currentDiagramFile.path with current managedDiagrams' model data.

  #### Parameters

  - ##### Optional path: string

    A valid MS OneDrive filepath to save current diagram model to. Path syntax is `/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 saved file.

### saveWithUI

- saveWithUI(): Promise<Object>

- Save the each managedDiagrams' model data to a user's One Drive account, using One Drive FilePicker.

  #### Returns Promise<Object>

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

### showUI

- showUI(): any

- Show the custom GoOneDrive save prompt ui.

  #### 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.