Interface

IAssetLink

IAssetLink

The main API entry-point for accessing app/data state within Asset Link.

Properties:
Name Type Description
rootComponent VueComponentInstance

The root Vue component instance - sometimes needed for registering things like global dialogs.

connectionStatus IFarmOSConnectionStatus

The current network/farmOS connection status information.

eventBus EventBus

An async event bus used to signal certain key occurrences.

ui IAssetLinkUI

UI components/methods exposed for Asset Link plugins.

booted external:Promise

A Promise that is fulfilled once Asset Link has booted.

store external:localForage

A localForage instance that is used to store and retrieve data from IndexedDB.

vm IAssetLinkViewModel

A Vue reactive object containing some key state - including booting status of Asset Link and meta information about the instance of farmOS.

devToolsApi Object

A semi-private mechanism to interact with the browser dev tools.

plugins Array.<IAssetLinkPlugin>

The currently loaded plugins.

entitySource external:@orbit/memory.MemorySource

The Orbit.js MemorySource which is used to access/modify farmOS assets/logs/etc.

Will be undefined until Asset Link has booted.

remoteEntitySource external:@orbit/jsonapi.JSONAPISource

The Orbit.js JSONAPISource which is used to directly access/modify farmOS assets/logs/etc - unless you know what you are doing, use IAssetLink#entitySource instead.

Will be undefined until Asset Link has booted.

View Source assetlink-plugin-api/src/IAssetLink.js, line 3

Methods

# fetch(resource, options)

A decorated version of the fetch API which has some tricks up its sleeve.

  • Automatically gets CSRF tokens for certain HTTP methods that need them
  • Automatically tracks farmOS connection status
Parameters:
Name Type Description
resource String | URL

the URL of the resource you want to fetch

options Object

an object containing any custom settings that you want to apply to the request

See:

View Source assetlink-plugin-api/src/IAssetLink.js, line 27

# getAssetTypes()

Get a list of the asset_type entities.

View Source assetlink-plugin-api/src/IAssetLink.js, line 74

# getEntityModel(typeName)

Gets the model for an entity type given that the type name. e.g. "asset--plant"

Parameters:
Name Type Description
typeName String

A farmOS JSON:API type - e.g. "asset--plant"

View Source assetlink-plugin-api/src/IAssetLink.js, line 41

# getLogTypes()

Get a list of the log_type entities.

View Source assetlink-plugin-api/src/IAssetLink.js, line 81

# getOrCreateTaxonomyTermByName(termType, termName, options)

Get or create a taxonomy term by type and name.

Note that it is often preferable to use the '$relateByName' directive instead of explicitly getting or creating taxonomy terms because it reduces the likelihood of duplicate terms from multiple users working simultaneously offline. See the Farm Data Access tutorial for more about that directive.

Usage
const term = await assetLink.getOrCreateTaxonomyTermByName('taxonomy_term--plant_type', 'Beans');
Parameters:
Name Type Description
termType String

The type of taxonomy term to get or create. e.g. taxonomy_term--animal_type

termName String

The name of the taxonomy term to be retrieved or created.

options GetOrCreateTaxonomyTermByNameOptions

An object with options.

View Source assetlink-plugin-api/src/IAssetLink.js, line 123

# getSlots(context) → {Array.<RenderableDef>}

Get slots that match a given context.

Usage
<component
    v-for="slotDef in assetLink.getSlots({ type: 'page-slot', route: $route, pageName: 'my-page', asset })"
    :key="slotDef.id"
    :is="slotDef.component"
    v-bind="slotDef.props"></component>
Parameters:
Name Type Description
context Object

The context used to filter/render the slots. Must at least have the key type.

View Source assetlink-plugin-api/src/IAssetLink.js, line 184

The renderable slots already sorted by weight

Array.<RenderableDef>

# getTaxonomyTermByName(termType, termName)

Get a taxonomy term by type and name.

Parameters:
Name Type Description
termType String

The type of taxonomy term to get. e.g. taxonomy_term--animal_type

termName String

The name of the taxonomy term to be retrieved.

View Source assetlink-plugin-api/src/IAssetLink.js, line 95

# getTaxonomyVocabularies()

Get a list of the taxonomy_vocabulary entities.

View Source assetlink-plugin-api/src/IAssetLink.js, line 88

# getWidgetDecorators(context) → {Array.<RenderableDef>}

Get widget decorators that match a given context.

Note: It would be unusual to call this directly. Most use-cases should use the RenderWidget component which internally calls getWidgetDecorators and composes the resulting widget decorator renderable defs.

<render-widget
  name="asset-name"
  :context="{ asset }"
>{{ asset.attributes.name }}</render-widget>
Parameters:
Name Type Description
context Object

The context object usually assembled by the RenderWidget component. Must at least have the key widgetName.

View Source assetlink-plugin-api/src/IAssetLink.js, line 203

The renderable widget decorators already sorted by weight

Array.<RenderableDef>

# resolveEntity(entityType, entityRef, additionalFilters, limitedEntityBundles)

Get an entity by type and UUID or Drupal internal id.

Usage
const log = await assetLink.resolveEntity('log', 42);

console.log(log.attributes.name);
Parameters:
Name Type Description
entityType String

the type of the entity

entityRef String | Number

the ID/UUID of the entity

additionalFilters Array.<Object>

additional resolution criteria in Orbit.js filter format e.g. [{ attribute: 'is_location', op: 'equal', value: true }]

limitedEntityBundles Array.<String>

Limit the entity bundles that will be resolved from e.g. ['activity', 'observation']

View Source assetlink-plugin-api/src/IAssetLink.js, line 49

# searchEntities(searchRequest, searchPhase)

Central entity searching entry-point. Responsible for delegating to entity searching plugins.

Note: It would be unusual to call this directly. Most use-cases should use the EntitySearch or EntitySearch components which internally handles calling searchEntities and presenting the results.

Parameters:
Name Type Description
searchRequest Object

An object with varying structure produced by a search method plugin - passed through to IAssetLinkPlugin.searchEntities implementations.

searchPhase String

One of "local" or "remote" to request offline or online entity search results respectively.

View Source assetlink-plugin-api/src/IAssetLink.js, line 148