Options
Public/Protected
  • Public
  • Public/Protected
  • All
Menu

GoJS API 文档

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

An abstract class for storing GoJS Models in various cloud storage services.

GoCloudStorage is never used on its own. Its subclasses can be used to manage diagram model storage programatically, or any subset of GoCloudStorage subclasses can be bundled and used graphically with the GoCloudStorageManager.

Note: With the exception of GoLocalStorage, all GoCloudStorage subclasses must be used in pages served on a web server.

Index

Constructors

constructor

  • new GoCloudStorage(managedDiagrams: Diagram | Array<Diagram>, defaultModel?: string, clientId?: string, iconsRelativeDirectory?: string): GoCloudStorage
  • Parameters

    • managedDiagrams: Diagram | Array<Diagram>

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

    • 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 clientId: string

      The client ID of the cloud storage application to use (given by the cloud storage service to developer). Not needed for all subclasses.

    • Optional iconsRelativeDirectory: string

      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/".

    Returns GoCloudStorage

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 : Array<Diagram>

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

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>
  • Explicitly authorize a currently-signed in user of the storage service to use the application associated with this instance of GoCloudStorage (via clientId. If no currently signed-in user exists, prompt user to sign into their account, then authorize that account.

    Note: Authorization does not occur (and is not possible or necessary) with GoLocalStorage. Instead, GoLocalStorage.authorize ensures localStorage exists in the browser.

    Parameters

    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 filepath. What is meant by this 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 boolean stating whether a file exists at a given path.

create

  • create(path?: string, saveBefore?: boolean): 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

      Optional. 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
    • Default value saveBefore: boolean = false

      Optional. If true, the user will be prompted to save their current diagram(s) before GoCloudStorage makes a new one. The default value is false.

    Returns Promise<Object>

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

getFile

  • getFile(path: string): Promise<Object>
  • Get the file at a given path in storage. The exact file data given varies from storage service to storage service, though all include name, path, id data. The exact syntax of these data fields may vary. See subclass-specific documentation for more details.

    Parameters

    • path: string

      A valid filepath. What is meant by this 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>

    Return a Promise that resolves with the file at a given path in storage(or null).

getUserInfo

  • getUserInfo(): Promise<Object>

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>
  • Load diagram model data from a given cloud storage-specific file path into managedDiagrams.

    Parameters

    • path: string

      A valid filepath. What is meant by this 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

loadWithUI

  • loadWithUI(): Promise<Object>
  • Load diagram model data from cloud storage into managedDiagrams using the ui for this class.

    Returns Promise<Object>

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

remove

  • remove(path: string): Promise<Object>
  • Remove a file containing diagram model data at a given cloud storage-specific file path.

    Parameters

    • path: string

      A valid filepath. What is meant by this 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 deleted file.

removeWithUI

  • removeWithUI(): Promise<Object>
  • Remove a given diagram from cloud storage using the ui for this class.

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

    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

    Parameters

    • Optional path: string

    Returns Promise<Object>

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

saveWithUI

  • saveWithUI(): Promise<Object>
  • Save the current diagram's model data to cloud storage with the ui for this class.

    Returns Promise<Object>

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

showUI

  • showUI(action: string): Promise<Object>
  • Show the ui element associated with this instance of GoCloudStorage.

    Parameters

    • action: string

      Clarify what action is being done after file selection. Acceptable values: Save, Delete, Load

    Returns Promise<Object>

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

加入 GoJS 交流群
GoJS 交流群 (769862113)