From 354084b86d1cbeeb6cf8af913e31835a286c0da0 Mon Sep 17 00:00:00 2001 From: ffehring Date: Thu, 27 Jun 2024 13:20:22 +0200 Subject: [PATCH] Changed: Remote: If response can not be parsed as json it is now delivered in one dataset with attribute "origresponse", to make it possible that components and manual requestors can work with that response value --- sites/lowlevelapi/dataaccess.html | 52 +++++++++++++++++-------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/sites/lowlevelapi/dataaccess.html b/sites/lowlevelapi/dataaccess.html index 1b5a319..3a9d498 100644 --- a/sites/lowlevelapi/dataaccess.html +++ b/sites/lowlevelapi/dataaccess.html @@ -35,7 +35,7 @@

Data access

Access data from component

If you need data, that is allready loaded by a component. You can access those data over the component object.
Be aware, that if you modify the content of a dataset, it will change the data in the component, too.

- +

 // Wait for component to be ready
 window.swac.reactions.addReaction(function (requestors) {
@@ -53,14 +53,18 @@ 

Access data from component

let set2 = mydatasets[2]; }, "present_example1");
- - - + + +

Load data with DataRequestor

You can access data by useing window.swac.Model.load(). The object given to Model.load() is a DataRequestor.
It can contain one of the sources configured in configuration - or global variable name or URL.

+ or global variable name or URL. +
SWAC tries to interpret the response as a list of datasets. + If that is possible, the datasets are delivered as array. +
If result cannot be interpreted as dataset(s) thet the value is + returned in a single set object with the single attribute "origresponse"


 // Get the model
 let Model = window.swac.Model;
@@ -96,8 +100,8 @@ 

Load data with DataRequestor

Load data with reference

You can access data by useing window.swac.Model.getFromReference(). - This gives you the opportunity to get data from references found in - another datasets.

+ This gives you the opportunity to get data from references found in + another datasets.


 // Get the model
 let Model = window.swac.Model;
@@ -131,7 +135,7 @@ 

Load data with reference

Add data to component (from reference)

You can load data from a reference directly into an component. - The component is than automatically observer of each dataset the source.

+ The component is than automatically observer of each dataset the source.


@@ -155,14 +159,14 @@ 

Add data to component (from javascript objects)

}]; req.swac_comp.addData('myCustomSource', datasets);
- +

Remove data from component

To remove all data from a component, simply use the removeAllData() or removeData(source) methods available on every component.

-

+            

 let req = document.getElementById('datapresent');
 req.swac_comp.removeAllData();
             
- +

Watch single sets

You can register own code to watch changes in datasets.


@@ -182,10 +186,10 @@ 

Watch single sets

// Done. You will be notified on data updates });
- +

Watch all sets

You can watch all sets you requested with your own code useing - model.loadData() or model.getFromReference()

+ model.loadData() or model.getFromReference()


 // Simple observer
@@ -215,12 +219,12 @@ 

Watch all sets

// Handle load error });
- + Useing the getFromReference the array of observers is the last parameter:

 let dataPromise = Model.getFromReference(reference,idAttr,attributeDefaults,attributeRenames,reloadInterval,observers);
 
- +

Save data

To save datasets, use the Model.save() method. If your dataset contains an id, the dataset will be updated, else it will be created.

@@ -268,7 +272,7 @@

Update data

// Request data (returns promise) Model.save(dataCapsule).then().catch();
- +

Delete data

Deleteing data is is the same way.


@@ -285,27 +289,27 @@ 

Delete data

// Request data (returns promise) Model.delete(dataCapsule).then().catch();
- +

Data creation

to create your own data that is automatic synchronising over differend components, create a WatchableSource and WatchableSets.

- +

Create a WatchableSource

A WatchableSource is observeable and auto observed by components, - that use date of that source.

- + that use date of that source.

+

 let ws = window.swac.Model.createWatchableSource({fromName: 'sourcename', requestId: 'sourcename?filter=id,es,1'});
             
- +

Create a WatchableSet

WatchableSets are observeable and inform the components they are - used in about changes of data values.

- + used in about changes of data values.

+

 let set = window.swac.Model.createWatchableSet(dataobject);
             
- +