### Hierarchy

- GoCloudStorage
  - GoLocalStorage

Class for saving / loading Diagram models to / from Local Storage. GoLocalStorage is the only GoCloudStorage subclass than can be used in a local page; that is, one not served by a web server.

Note: that this class will not work with browsers that do not have Local Storage support (like some old versions of Internet Explorer).

## Index

### Constructors

- constructor

### Properties

- className
- clientId
- currentDiagramFile
- defaultModel
- iconsRelativeDirectory
- isAutoSaving
- localStorage
- managedDiagrams
- serviceName
- ui

### Methods

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

## Constructors

### constructor

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

- #### Parameters

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

    An array of GoJS Diagrams whose model(s) will be saved to / loaded from Local Storage. 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 .toJson() on a GoJS Diagram's Model.

  - ##### Optional iconsRelativeDirectory: string

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

  #### Returns GoLocalStorage

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

### Read-only localStorage : Storage

- Get the browser window's Local Storage property.

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

- Check if Local Storage is supported by the current browser.

  #### Parameters

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

    This parameter can be ignored. It exists only to maintain GoCloudStorage system structure

  #### Returns Promise<Object>

  Returns a Promise that resolves with a boolean (true if local storage is supported, false if not)

### checkFileExists

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

- Check whether a file exists in LocalStorage at a given path.

  #### Parameters

  - ##### path: string

    A valid key corresponding to a saved diagram file in Local Storage

  #### Returns Promise<Object>

  Returns a Promise that resolves with a boolean stating whether a file exists in LocalStorage 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): Promise<Object>

- Get information about a diagram file saved to local storage. This data includes:

  - content: The content of the saved file (a string respresentation of a GoJS Diagram Model)
  - id: The key of the file in local storage
  - name: Same as id value
  - path: Same as id value

  Note: Id, name, and path are all provided (despite being the same). They are requisite for creating valid DiagramFiles.

  #### Parameters

  - ##### path: string

    A valid key corresponding to a saved diagram file in Local Storage

  #### Returns Promise<Object>

  Returns a Promise that resolves with information about a diagram file saved to local storage

### getUserInfo

- getUserInfo(): Promise<Object>

- Get information about the currently logged in user. This information varies from subclass to subclass. For more info, see:

  - GoLocalStorage.getUserInfo
  - GoDropBox.getUserInfo
  - GoGoogleDrive.getUserInfo
  - GoOneDrive.getUserInfo

  #### Returns Promise<Object>

  Returns a Promise that resolves with information about the currently logged in 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<never>

- Get the contents of a given file; load to managedDiagrams model.

  #### Parameters

  - ##### path: string

    A valid localstorage key to load diagram model data from

  #### Returns Promise<never>

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

### loadWithUI

- loadWithUI(): Promise<never>

- Get the contents of a given file; load to managedDiagrams model. Use the custom filepicker ui.

  #### Returns Promise<never>

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

### remove

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

- Delete a given diagram from Local Storage.

  #### Parameters

  - ##### path: string

    A valid localstorage key to delete diagram model data from

  #### Returns Promise<Object>

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

### removeWithUI

- removeWithUI(): Promise<Object>

- Delete a diagram from Local Storage using the custom filepicker menu 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 Local 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 key in Local Storage 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 string to save diagram model data to (becomes the key for the file in Local Storage)

  #### 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 Local Storage using the custom filepicker ui.

  #### Returns Promise<Object>

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

### showUI

- showUI(action: string, numAdditionalFiles?: number): any

- Show the custom Go Local Storage filepicker ui.

  #### Parameters

  - ##### action: string

    Clarify what action is being done after file selection. Must be one of the following:

    - New
    - Open
    - Save
    - Delete

  - ##### Optional numAdditionalFiles: number

    Optional: Number of files to show in UI, in addition to a static numerical 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 Local Storage.

  #### Returns any

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

Copyright © 1998-2018 by Northwoods Software Corporation.