Skip to content

stm functions

Tobias Paczian edited this page Mar 21, 2018 · 7 revisions

REST API repository

add_repository

stm.add_repository( { 'url': url, 'name': name, 'description': description, 'auth': false, 'isDefault': false } )

Adds a repository to the repository list. The url and name parameters are required and specify the base URL of the REST API and the identifier in the repository list respectively. The description is an optional descriptive string. The boolean auth defines whether data requests to the repository are sent with the stm.authHeader or not. If there is more than one repository, the isDefault parameter sets the default repository to be used if an identifier is omitted in the stm.get_objects method.


remove_repository

stm.remove_repostiory(name)

Removes the repository name from the repository list.


default_repository

stm.default_repository(name)

Sets the repository name to be the default.


get_objects

stm.get_objects( { 'repository': repository, 'type': type, 'id': id, 'options': options, 'method': 'GET', 'errorCallback': errorCallback } )

Retrieves data from a REST API. The only required parameter is type. The repository parameter is the name identifier in the repository list. It will default to the stm.default_repository. If there is only one repository in the list, it automatically becomes the default.

The id parameter specifies the data identifier to be retrieved. This is optional in the case of passing the options parameter to perform a query (which will return multiple datasets). The request method of the call can be set via the method parameter and defaults to GET. The optional errorCallback parameter expects a function which will be called if the API returns an error.

The function returns a promise that fulfills when the data has been added to stm.DataStore.

IndexedDB

readHardStorage

stm.readHardStorage(name)

Reads the IndexedDB name into stm.DataStore. If name is omitted it will default to stm. The function returns a promise that fulfills as soon as the data is available in the stm.DataStore.


existsHardStorage

stm.existsHardStorage(name)

Checks if the IndexedDB name exists. Returns a promise that fulfills if the check is completed and gets a boolean as a parameter that indicates if the database exists or not.


clearHardStorage

stm.clearHardStorage(name)

Deletes the IndexedDB name. Returns a promise that fulfills when the transaction has completed.


updateHardStorage

Import / Export

import_data

stm.import_data( {'data': data, 'merge': true, 'structure': 'list', 'id': id })

Imports data into the stm.DataStore structure. If merge is set to false or omitted, each data type in the structure data that already exists in stm.DataStore is erased before the data import. Otherwise the data is merged. New ids will be added, existing ids will be overwritten, old ids will remain.

The data object holds the data to be imported.


file_upload

stm.file_upload(event, callback_function, callback_parameters)

If set as the onchange function of a file input element this function allows the upload of data into stm.DataStore. event is the onchange event of the input. If you specify a callback_function, it will be called as soon as the import is complete, passing the optional callback_parameters.


dump

stm.dump(useDB, dbName, key)

Dumps the contents of stm.DataStore to a file. If useDB is set to true, the contents of the IndexedDB dbName will be dumped instead of stm.DataStore. dbName defaults to stm. If useDB is false, you can pass a single or an array of keys via the key parameter (scalar or array will be auto-detected). In this case only the specified object types will be dumped.


saveAs

stm.saveAs(data, filename, raw, prefix, returnAnchor)

Creates a save as file download dialog that allows the user to save the string data from memory to a file on disk. If raw is true, the data will not be changed. Otherwise it will be converted to Base64. To determine data-type pass a prefix, otherwise it will default to 'data:application/octet-stream;base64,'. The function creates an anchor that is appended to the DOM and clicked to trigger the download and removed from the DOM after that. If returnAnchor is set to true, the anchor will not be appended to the DOM but returned by the function as a string. The filename can be set via the filename parameter.


Data Management

delete_object

stm.delete_object(type, id)

Deletes the object with the identifier id from object type type from stm.DataStore.


delete_objects

stm.delete_objects(type, ids)

Deletes all objects with the identifiers in the array ids from object type type from stm.DataStore.


delete_object_type

stm.delete_object_type(type)

Deletes the object type type from stm.DataStore.

Clone this wiki locally