Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GoDropBox

Hierarchy

Class for saving / loading GoJS Diagram models to / from Dropbox. 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 GoDropBox must include a script tag with a reference to the Dropbox JS SDK.

Index

Constructors

constructor

  • new GoDropBox(managedDiagrams: Diagram | Diagram[], clientId: string, defaultModel?: string, iconsRelativeDirectory?: string): GoDropBox
  • Parameters

    • managedDiagrams: Diagram | Diagram[]

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

    • clientId: string

      The client ID of the application in use (given in Dropbox Developer's 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 GoDropBox exists, in which the storage service brand icons can be found. The default value is "../goCloudStorageIcons/".

    Returns GoDropBox

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 dropbox : 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.

menuPath : string

  • Get / set currently open Dropnpx path in custom filepicker ui. Default value is the empty string, which corresponds to the currently signed in user's Drobox account's root path. Set when a user clicks on a folder in the custom ui menu by invoking anchor onclick values. These onclick values are set when the Dropbox directory at the current menuPath is displayed with showUI.

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 Dropbox user who has authorized the application linked to this instance of GoDropBox (via clientId). If not, prompt user to sign in / authenticate their Dropbox account.

    Parameters

    • Default value refreshToken: boolean = false

      Whether to get a new acess 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 in user's Dropbox at a given path.

    Parameters

    • path: string

      A valid Dropbox filepath. Path syntax is /{path-to-file}/{filename}; i.e. /Public/example.diagram. Alternatively, this may be a valid Dropbox file ID.

    Returns Promise<Object>

    Returns a Promise that resolves with a boolean stating whether a file exists in user's Dropbox 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.

getFile

  • getFile(path: string): any
  • Get the Dropbox file reference object at a given path. Properties of particular note include:

    • name: The name of the file in DropBox
    • id: The DropBox-given file ID
    • path_diplay: A lower-case version of the path this file is stored at in DropBox
    • .tag: A tag denoting the type of this file. Common values are "file" and "folder".
      • Note: The first three elements in the above list are requisite for creating valid DiagramFiles.

    Parameters

    • path: string

      A valid Dropbox filepath. Path syntax is /{path-to-file}/{filename}; i.e. /Public/example.diagram. Alternatively, this may be a valid Dropbox file ID.

    Returns any

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

getUserInfo

  • getUserInfo(): Promise<Object>
  • Get information about the currently logged in Dropbox user. Some fields of particular note include:

    • country
    • email
    • account_id
    • name
      • abbreivated_name
      • display_name
      • given_name
      • surname

    Returns Promise<Object>

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

hideUI

  • hideUI(isActionCanceled?: boolean): void
  • Hide the custom GoDropBox filepicker ui; nullify menuPath.

    Parameters

    • Optional isActionCanceled: boolean

      If action (Save, Delete, Load) is cancelled, resolve the Promise returned in showUI with a 'Canceled' notification.

    Returns void

load

  • load(path: string): Promise<Object>
  • Load the contents of a saved diagram from Dropbox.

    Parameters

    • path: string

      A valid Dropbox filepath to load diagram model data from. Path syntax is /{path-to-file}/{filename}; i.e. /Public/example.diagram. Alternatively, this may be a valid Dropbox file ID.

    Returns Promise<Object>

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

loadWithUI

  • loadWithUI(): any
  • Load the contents of a saved diagram from Dropbox using the custom filepicker ui.

    Returns any

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

remove

  • remove(path: string): Promise<Object>
  • Delete a given diagram file from Dropbox.

    Parameters

    • path: string

      A valid Dropbox filepath to delete diagram model data from. Path syntax is /{path-to-file}/{filename}; i.e. /Public/example.diagram. Alternatively, this may be a valid Dropbox file ID.

    Returns Promise<Object>

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

removeWithUI

  • removeWithUI(): Promise<Object>
  • Delete a chosen diagram file from Dropbox using the custom filepicker ui.

    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 Dropbox. 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 Dropbox 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 valid Dropbox filepath to save current diagram model to. Path syntax is /{path-to-file}/{filename}; i.e. /Public/example.diagram. Alternatively, this may be a valid Dropbox file ID.

    Returns Promise<Object>

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

saveWithUI

  • saveWithUI(): Promise<Object>
  • Save the current managedDiagrams model data to Dropbox with the filepicker ui. Returns a Promise that resolves with a DiagramFile representing the saved file.

    Returns Promise<Object>

showUI

  • showUI(action: string, path?: string, numAdditionalFiles?: number): any
  • Display the custom GoDropBox filepicker ui. Note: This is no longer used for loadWithUI actions. These actions are handled with the official Dropbox Chooser API.

    Parameters

    • action: string

      Clarify what action is being done after file selection. Acceptable values:

      • Save
      • Delete
      • Load
    • Optional path: string

      The path in DropBox to look to for files and folders. The empty string directs to a Dropbox user's root directory. Path syntax is /{path}/{to}/{folder}/; i.e. /Public/.

    • Optional numAdditionalFiles: number

      Number of files to show in UI, in addition to a static property that can only be modified by changing source code. This prevents long wait times while the UI loads if there are a large number of diagram files stored in Dropbox.

    Returns any

    Returns a Promise which resolves (in save, load, or remove, after action is handled with a DiagramFile representing the saved/loaded/deleted file