Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GoOneDrive

This is part of GoCloudStorage and not part of the main GoJS library. Storage can be found in the GoJS kit under the projects folder. See the Storage intro page for more information.

Hierarchy

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

  • 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 Model.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

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

Methods

Override authorize

  • authorize(refreshToken?: boolean): Promise<boolean>
  • 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<boolean>

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

Override checkFileExists

  • checkFileExists(path: string): Promise<any>
  • 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<any>

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

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

Override getFile

  • getFile(path: string, token?: string): Promise<any>
  • 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<any>

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

Override getUserInfo

  • getUserInfo(): Promise<any>
  • 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<any>

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

Override load

  • load(path: string, token?: string): Promise<any>
  • 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<any>

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

Override loadWithUI

  • loadWithUI(): Promise<any>
  • Load diagram model data from a given OneDrive-specific file path into managedDiagrams using the MS OneDrive filepicker.

    Returns Promise<any>

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

Override remove

  • remove(path: string, token?: string): Promise<any>
  • 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<any>

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

Override removeWithUI

  • removeWithUI(): Promise<any>
  • Delete a diagram from a user's OneDrive using the OneDrive Filepicker.

    Returns Promise<any>

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

Override save

  • save(path?: string): Promise<any>
  • 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<any>

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

Override saveWithUI

  • saveWithUI(): Promise<any>

Override showUI

  • showUI(): Promise<any>
  • Show the custom GoOneDrive save prompt ui.

    Returns Promise<any>

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